YSTest: HostRenderer.h 源文件

YSTest PreAlpha_b500_20140530 The YSLib Test Project

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

- 文件列表
- 文件成员

全部 类 命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义 组 页
HostRenderer.h
浏览该文件的文档.
1 /*
2 © 2013-2014 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
28 #ifndef INC_Helper_HostRenderer_h_
29 #define INC_Helper_HostRenderer_h_ 1
30
31 #include "YModules.h"
32 #include YFM_Helper_HostWindow // for Host::Window;
33 #if YF_Multithread == 1
34 # include <atomic>
35 # include <thread>
36 #endif
37 #include YFM_YSLib_UI_YRenderer
38 #include YFM_YSLib_UI_YWidget // for UI::GetSizeOf;
39 #include YFM_Helper_ScreenBuffer // for ScreenRegionBuffer;
40
41 namespace YSLib
42 {
43
44 #if YF_Hosted
45 namespace Host
46 {
47
52 class YF_API RenderWindow : public Window
53 {
54 private:
55 std::reference_wrapper<HostRenderer> renderer;
56
57 public:
58 RenderWindow(HostRenderer&, NativeWindowHandle);
59
60 DefGetter(const ynothrow, HostRenderer&, Renderer, renderer)
61
62
63 void
64 Refresh() override;
65 };
66
67
72 class YF_API WindowThread : private OwnershipTag<Window>
73 {
74 private:
80 std::atomic<Window*> p_wnd;
81 std::thread thrd;
82
83 public:
84 template<typename... _tParams>
85 WindowThread(_tParams&&... args)
86 : p_wnd(), thrd(std::mem_fn(&WindowThread::ThreadFunc<ystdex::decay_t<
87 _tParams>...>), this, ystdex::decay_copy(args)...)
88 {}
90 DefDelMoveCtor(WindowThread)
91 ~WindowThread();
92
94 DefGetter(const ynothrow, Window*, WindowPtr, p_wnd)
95
96 private:
97 template<typename _fCallable, typename... _tParams>
98 void
99 ThreadFunc(_fCallable&& f, _tParams&&... args)
100 {
101 ThreadLoop(yforward(f)(yforward(args)...));
102 }
103
105 void
106 ThreadLoop(NativeWindowHandle);
107 void
108 ThreadLoop(unique_ptr<Window>);
109
110 public:
111 static void
112 WindowLoop(Window&);
113 };
114
115
121 class YF_API HostRenderer : public UI::BufferedRenderer
122 {
123 private:
124 std::reference_wrapper<UI::IWidget> widget;
126 ScreenRegionBuffer rbuf;
127 WindowThread thrd;
128
129 public:
131 template<typename... _tParams>
132 HostRenderer(UI::IWidget& wgt, _tParams&&... args)
133 : HostRenderer(ystdex::identity<RenderWindow>(), wgt, yforward(args)...)
134 {}
136
137 template<class _tWindow, typename... _tParams>
138 HostRenderer(ystdex::identity<_tWindow>, UI::IWidget& wgt,
139 _tParams&&... args)
140 : BufferedRenderer(),
141 widget(wgt), rbuf(GetSizeOf(wgt)),
142 thrd(std::mem_fn(&HostRenderer::MakeRenderWindow<_tWindow,
143 ystdex::decay_t<_tParams>...>), this, ystdex::decay_copy(args)...)
144 {}
145 template<typename... _tParams>
146 HostRenderer(int, UI::IWidget& wgt, _tParams&&... args)
147 : HostRenderer(0, ystdex::identity<RenderWindow>(), wgt,
148 yforward(args)...)
149 {}
150 template<class _tWindow, typename... _tParams>
151 HostRenderer(int, ystdex::identity<_tWindow>, UI::IWidget& wgt,
152 _tParams&&... args)
153 : BufferedRenderer(),
154 widget(wgt), rbuf(GetSizeOf(wgt)),
155 thrd(std::mem_fn(&HostRenderer::MakeRenderWindowEx<_tWindow,
156 ystdex::decay_t<_tParams>...>), this, ystdex::decay_copy(args)...)
157 {}
159 DefDeMoveCtor(HostRenderer)
160
161 DefGetter(const ynothrow, UI::IWidget&, WidgetRef, widget.get())
162 DefGetterMem(const ynothrow, Window*, WindowPtr, thrd)
163
164 void
165 SetSize(const Drawing::Size&) override;
166
168 YB_NORETURN PDefH(HostRenderer*, clone, ) const override
169 ImplExpr(
170 throw ystdex::unimplemented("HostRenderer::clone unimplemented."));
171 // DefClone(const override, HostRenderer)
172
174
175 template<class _tWindow, typename _fCallable, typename... _tParams>
176 unique_ptr<Window>
177 MakeRenderWindow(_fCallable&& f, _tParams&&... args)
178 {
179 return make_unique<_tWindow>(*this, yforward(f)(yforward(args)...));
180 }
181
182 template<class _tWindow, typename _fCallable, typename... _tParams>
183 unique_ptr<Window>
184 MakeRenderWindowEx(_fCallable&& f, _tParams&&... args)
185 {
186 return make_unique<_tWindow>(*this, yforward(f)(), yforward(args)...);
187 }
189
198 void
199 Update(Drawing::BitmapPtr);
200
202 template<typename _type>
203 void
204 UpdateToSurface(_type& sf)
205 {
206 sf.Update(rbuf);
207 }
208 };
209
210 } // namespace Host;
211 #endif
212
213 } // namespace YSLib;
214
215 #endif
216
YSLib::UI::GetSizeOf
pt pt Y const IWidget &wgt const IWidget &wgt GetSizeOf
无效化：使相对于部件的子部件的指定区域在直接和间接的窗口缓冲区中无效。
Definition: ywidget.h:156
YSLib::UI::Refresh
void Refresh(PaintEventArgs &&) override
刷新：按指定参数绘制界面并更新状态。
YSLib::UI::args
yconstfn const string _tParams && args
Definition: Loader.h:111
YF_API
#define YF_API
Definition: Platform.h:64
ystdex::decay_t
typename decay< _type >::type decay_t
Definition: type_op.hpp:271
yforward
#define yforward(_expr)
根据参数类型使用 std::forward 传递对应参数。
Definition: ydef.h:722
DefGetter
#define DefGetter(_q, _t, _n,...)
Definition: YBaseMacro.h:180
ystdex::identity
恒等元函数。
Definition: type_op.hpp:643
YSLib::UI::Styles::Window
窗口背景。
Definition: ystyle.h:182
YSLib::Drawing::SetSize
sizeof(AlphaType)*GetAreaOf(GetSize())) using CompactPixmap void SetSize(const Size &) override
重新设置缓冲区大小。
DefDeMoveCtor
#define DefDeMoveCtor(_t)
Definition: YBaseMacro.h:141
ImplExpr
#define ImplExpr(...)
Definition: YBaseMacro.h:93
YSLib::UI::wgt
_tWidget & wgt
Definition: ywgtevt.h:596
ynothrow
#define ynothrow
YSLib 无异常抛出保证：若支持 noexcept 关键字， 指定特定的 noexcept 异常规范。
Definition: ydef.h:514
YSLib::UI::f
_tWidget _fCallable && f
Definition: ywgtevt.h:597
platform_ex::NativeWindowHandle
::ANativeWindow * NativeWindowHandle
Definition: Android.h:50
YB_NORETURN
#define YB_NORETURN
指定无返回值函数。
Definition: ydef.h:311
YModules.h
platform::BitmapPtr
PixelType * BitmapPtr
Definition: Video.h:295
DefGetterMem
#define DefGetterMem(_q, _t, _n, _m)
Definition: YBaseMacro.h:185
platform_ex::Android::ScreenRegionBuffer
ScreenRegionBuffer(const YSLib::Drawing::Size &, YSLib::SDst)
构造：使用指定的缓冲区大小和像素跨距。 像素跨距小于缓冲区大小。
ystdex::any_ops::clone
Definition: any.h:310
DefDelMoveCtor
#define DefDelMoveCtor(_t)
Definition: YBaseMacro.h:143
ystdex::decay_copy
decay_t< _type > decay_copy(_type &&arg)
退化复制。
Definition: utility.hpp:168