YSTest: AndroidScreen.cpp 源文件

YSTest PreAlpha_b900_20201012 The YSLib Test Project

AndroidScreen.cpp
浏览该文件的文档.
1 /*
2 © 2014-2016 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" // for Informative, CheckPositive, to_string;
30
31 namespace YSLib
32 {
33
34 #if YCL_Android
35
36 using namespace Drawing;
37
38 namespace Devices
39 {
40
41 AndroidScreen::AndroidScreen(::ANativeWindow& wnd,
42 const Drawing::Size& scr_size)
43 : AndroidScreen(wnd, [&wnd]() -> Size{
44 // XXX: Surface might be 1x1.
45 // See http://grokbase.com/t/gg/android-ndk/123ks0p3n1/resizing-nativeactivity-and-opengl-surfaces.
46 // 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/.
47 // TODO: Use direct window size query when API level >= 14.
48 const auto& size(Host::WindowReference(&wnd).GetSize());
49
50 if(size.Width > 1)
51 return size;
52
53 ::ANativeWindow_Buffer abuf;
54
55 if(YB_UNLIKELY(::ANativeWindow_lock(&wnd, &abuf, {}) != 0))
56 throw LoggedEvent("Failed call ::ANativeWindow_lock"
57 " @ AndroidScreen::AndroidScreen.");
58 ::ANativeWindow_unlockAndPost(&wnd);
59 return {CheckPositive<SDst>(abuf.width, "width"),
60 CheckPositive<SDst>(abuf.height, "height")};
61 }(), scr_size)
62 {}
63 AndroidScreen::AndroidScreen(::ANativeWindow& wnd, const Size& size,
64 const Size& scr_size)
65 : Screen(size),
66 window_ref(wnd)
67 {
68 YTraceDe(Informative, "Screen created, size = %s.",
69 to_string(size).c_str());
70 SetNativeBufferSize(scr_size);
71 }
72
73 void
74 AndroidScreen::SetNativeBufferSize(const Size& s)
75 {
76 ::ANativeWindow_setBuffersGeometry(&GetWindowRef(), s.Width, s.Height,
77 WINDOW_FORMAT_RGBA_8888);
78 }
79
80 void
81 AndroidScreen::SetSize(const Size& s)
82 {
83 GraphicDevice::SetSize(s);
84 SetNativeBufferSize(s);
85 }
86
87 void
88 AndroidScreen::Update(ConstBitmapPtr p_buf) ynothrow
89 {
90 const Size& s(GetSize());
91
92 platform_ex::UpdateContentTo(&GetWindowRef(), s, ConstGraphics(p_buf, s));
93 }
94
95 } // namespace Devices;
96
97 #endif
98
99 } // namespace YSLib;
100
size
size_t size
Definition: memory_resource.cpp:295
YSLib::Drawing::ConstGraphics
GGraphics< ConstBitmapPtr > ConstGraphics
Definition: YGraphics.h:160
platform::Descriptions::Informative
@ Informative
Definition: YCommon.h:185
YSLib::Drawing::GetSize
dst GetSize()
YTraceDe
#define YTraceDe(...)
YCLib 默认调试跟踪。
Definition: Debug.h:407
ystdex::to_string
std::string to_string(const std::thread::id &)
转换 thread::id 为字符串表示。
YSLib
YSLib 命名空间。
Definition: AndroidHost.h:46
CHRLib::s
_tDst const _tSrc * s
Definition: CharacterProcessing.h:143
NPL::c_str
YF_API const char src c_str())) YF_API void InstallDirectory(const string &
安装目录：复制目录树。
Definition: Dependency.h:140
YSLib::Drawing::ConstBitmapPtr
const Pixel * ConstBitmapPtr
Definition: YGraphics.h:44
YB_UNLIKELY
#define YB_UNLIKELY(_expr)
分支预测提示。
Definition: ydef.h:828
ynothrow
#define ynothrow
YSLib 无异常抛出保证：若支持 noexcept 关键字， 指定特定的 noexcept 异常规范。
Definition: ydef.h:1199
AndroidScreen.h
Android 屏幕。