YSTest: AndroidScreen.cpp 源文件

YSTest PreAlpha_b700_20160611 The YSLib Test Project

- 首页
- 相关页面
- 模块
- 命名空间
- 类
- 文件

- 文件列表
- 文件成员

AndroidScreen.cpp
浏览该文件的文档.
1 /*
2 © 2014-2015 FrankHB.
3
4 This file is part of the YSLib project, and may only be used,
5 modified, and distributed under the terms of the YSLib project
6 license, LICENSE.TXT. By continuing to use, modify, or distribute
7 this file you indicate that you have read the license and
8 understand and accept it fully.
9 */
10
29 #include "AndroidScreen.h"
30 #include YFM_YSLib_UI_YComponent // for to_string;
31
32 namespace YSLib
33 {
34
35 #if YCL_Android
36
37 using namespace Drawing;
38
39 namespace Devices
40 {
41
42 AndroidScreen::AndroidScreen(::ANativeWindow& wnd,
43 const Drawing::Size& scr_size)
44 : AndroidScreen(wnd, [&wnd]() -> Size{
45 // XXX: Surface might be 1x1.
46 // See http://grokbase.com/t/gg/android-ndk/123ks0p3n1/resizing-nativeactivity-and-opengl-surfaces .
47 // See http://www.klayge.org/2013/01/23/%E5%9C%A8android%E6%A8%A1%E6%8B%9F%E5%99%A8%E4%B8%8A%E7%9A%84%E4%B8%80%E4%BA%9B%E5%B0%8F%E9%99%B7%E9%98%B1/ .
48 // TODO: Use direct window size query when API level >= 14.
49 const auto& size(Host::WindowReference(&wnd).GetSize());
50
51 if(size.Width > 1)
52 return size;
53
54 ::ANativeWindow_Buffer abuf;
55
56 if(YB_UNLIKELY(::ANativeWindow_lock(&wnd, &abuf, {}) != 0))
57 throw LoggedEvent("Failed call ::ANativeWindow_lock"
58 " @ AndroidScreen::AndroidScreen.");
59 ::ANativeWindow_unlockAndPost(&wnd);
60 return {CheckPositiveScalar<SDst>(abuf.width, "width"),
61 CheckPositiveScalar<SDst>(abuf.height, "height")};
62 }(), scr_size)
63 {}
64 AndroidScreen::AndroidScreen(::ANativeWindow& wnd, const Drawing::Size& size,
65 const Drawing::Size& scr_size)
66 : Screen(size),
67 window_ref(wnd)
68 {
69 YTraceDe(Informative, "Screen created, size = %s.",
70 to_string(size).c_str());
71 SetNativeBufferSize(scr_size);
72 }
73
74 void
75 AndroidScreen::SetNativeBufferSize(const Size& s)
76 {
77 ::ANativeWindow_setBuffersGeometry(&GetWindowRef(), s.Width, s.Height,
78 WINDOW_FORMAT_RGBA_8888);
79 }
80
81 void
82 AndroidScreen::SetSize(const Size& s)
83 {
84 GraphicDevice::SetSize(s);
85 SetNativeBufferSize(s);
86 }
87
88 void
89 AndroidScreen::Update(ConstBitmapPtr p_buf) ynothrow
90 {
91 const Size& s(GetSize());
92
93 platform_ex::UpdateContentTo(&GetWindowRef(), s, ConstGraphics(p_buf, s));
94 }
95
96 } // namespace Devices;
97
98 #endif
99
100 } // namespace YSLib;
101
ystdex::to_string
std::string to_string(const std::thread::id &)
转换 thread::id 为字符串表示。
ynothrow
#define ynothrow
YSLib 无异常抛出保证：若支持 noexcept 关键字， 指定特定的 noexcept 异常规范。
Definition: ydef.h:740
platform::Descriptions::Informative
Definition: YCommon.h:159
YSLib
YSLib 命名空间。
Definition: AndroidHost.h:45
AndroidScreen.h
Android 屏幕。
YSLib::Drawing::ConstBitmapPtr
const Pixel * ConstBitmapPtr
Definition: YGraphics.h:44
YTraceDe
#define YTraceDe(...)
YCLib 默认调试跟踪。
Definition: Debug.h:305
YB_UNLIKELY
#define YB_UNLIKELY(_expr)
分支预测提示。
Definition: ydef.h:438
ystdex::size
auto size(const _tRange &c) -> decltype(c.size())
类容器访问。
Definition: range.hpp:233
Drawing
NPL::c_str
YF_API const char src c_str())) YF_API void InstallDirectory(const string &
安装目录：复制目录树。
YSLib::Drawing::ConstGraphics
GGraphics< ConstBitmapPtr > ConstGraphics
Definition: YGraphics.h:160
CHRLib::s
_tDst const _tSrc * s
Definition: CharacterProcessing.h:140