YSTest: HostRenderer.h 源文件

YSTest PreAlpha_b800_20170810 The YSLib Test Project

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

- 文件列表
- 文件成员

HostRenderer.h
浏览该文件的文档.
1 /*
2 © 2013-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
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, ystdex::unimplemented;
33 #if YF_Multithread == 1
34 # include <thread>
35 #endif
36 #include YFM_YSLib_UI_YRenderer // for UI::BufferedRenderer;
37 #include YFM_YSLib_UI_YWidget // for UI::GetSizeOf;
38 #include YFM_Helper_ScreenBuffer // for ScreenRegionBuffer;
39
40 namespace YSLib
41 {
42
43 #if YF_Hosted
44 namespace Host
45 {
46
51 class YF_API RenderWindow : public Window
52 {
53 private:
55 lref<HostRenderer> renderer;
56
57 public:
58 RenderWindow(HostRenderer&, NativeWindowHandle);
60 RenderWindow(HostRenderer& rd, Host::WindowReference wnd_ref)
61 : RenderWindow(rd, wnd_ref.GetNativeHandle())
62 {}
63
64 DefGetter(const ynothrow, HostRenderer&, Renderer, renderer)
65
66
71 void
72 Refresh() override;
73 };
74
75
83 class YF_API WindowThread : private OwnershipTag<Window>
84 {
85 public:
87 using Guard = ystdex::any;
89 using GuardGenerator = std::function<Guard(Window&)>;
90
91 private:
97 atomic<Window*> p_window{{}};
98 std::thread thrd;
99
100 public:
105 GuardGenerator GenerateGuard{};
106
107 template<typename... _tParams>
108 WindowThread(_tParams&&... args)
109 : WindowThread({}, yforward(args)...)
110 {}
112 template<typename... _tParams>
113 WindowThread(GuardGenerator guard_gen, _tParams&&... args)
114 : thrd(&WindowThread::ThreadFunc<_tParams...>, this, yforward(args)...),
115 GenerateGuard(guard_gen)
116 {}
118 DefDelMoveCtor(WindowThread)
123 ~WindowThread();
124
129 DefGetter(const ynothrow, observer_ptr<Window>, WindowPtr,
130 make_observer(static_cast<Window*>(p_window)))
131
132
138 static Guard
139 DefaultGenerateGuard(Window&);
140
141 private:
143 template<typename _func, typename... _tParams>
144 void
145 ThreadFunc(_func&& f, _tParams&&... args) ynothrow
146 {
147 FilterExceptions([&, this]{
148 // XXX: Blocked. 'yforward' cause G++ 5.2 crash: segmentation
149 // fault.
150 ThreadLoop(ystdex::invoke(std::forward<_func&&>(f),
151 std::forward<_tParams&&>(args)...));
152 });
153 }
154
156 void
157 ThreadLoop(NativeWindowHandle);
159 PDefH(void, ThreadLoop, WindowReference wnd_ref)
160 ImplRet(ThreadLoop(wnd_ref.GetNativeHandle()))
161 void
162 ThreadLoop(unique_ptr<Window>);
163
164 public:
165 static void
166 WindowLoop(Window&);
167
168 private:
170 static void
171 WindowLoop(Window&, GuardGenerator);
172 };
173
174
181 class YF_API HostRenderer : public UI::BufferedRenderer
182 {
183 private:
185 lref<UI::IWidget> widget;
187 ScreenRegionBuffer rbuf;
188 WindowThread thrd;
189
190 public:
195 bool RootMode = {};
196
201 template<typename... _tParams>
202 HostRenderer(UI::IWidget& wgt, _tParams&&... args)
203 : HostRenderer(ystdex::identity<RenderWindow>(), wgt, yforward(args)...)
204 {}
206
207 template<class _tWindow, typename... _tParams>
209 HostRenderer(ystdex::identity<_tWindow>, UI::IWidget& wgt,
210 _tParams&&... args)
211 : HostRenderer(ystdex::empty_base<WindowThread>(), wgt,
212 std::mem_fn(&HostRenderer::MakeRenderWindow<
213 _tWindow, ystdex::decay_t<_tParams>...>), this, yforward(args)...)
214 {}
216 template<class _tWindow, typename... _tParams>
217 HostRenderer(ystdex::identity<_tWindow>, UI::IWidget& wgt,
218 WindowThread::GuardGenerator guard_gen, _tParams&&... args)
219 : HostRenderer(ystdex::empty_base<WindowThread>(), wgt, guard_gen,
220 std::mem_fn(&HostRenderer::MakeRenderWindow<_tWindow,
221 ystdex::decay_t<_tParams>...>), this, yforward(args)...)
222 {}
224 template<typename... _tParams>
225 HostRenderer(int, UI::IWidget& wgt, _tParams&&... args)
226 : HostRenderer(0, ystdex::identity<RenderWindow>(), wgt,
227 yforward(args)...)
228 {}
230 template<class _tWindow, typename... _tParams>
231 HostRenderer(int, ystdex::identity<_tWindow>, UI::IWidget& wgt,
232 _tParams&&... args)
233 : HostRenderer(ystdex::empty_base<WindowThread>(), wgt,
234 std::mem_fn(&HostRenderer::MakeRenderWindowEx<
235 _tWindow, ystdex::decay_t<_tParams>...>), this, yforward(args)...)
236 {}
238 template<class _tWindow, typename... _tParams>
239 HostRenderer(int, ystdex::identity<_tWindow>, UI::IWidget& wgt,
240 WindowThread::GuardGenerator guard_gen, _tParams&&... args)
241 : HostRenderer(ystdex::empty_base<WindowThread>(), wgt, guard_gen,
242 std::mem_fn(&HostRenderer::MakeRenderWindowEx<_tWindow,
243 ystdex::decay_t<_tParams>...>), this, yforward(args)...)
244 {}
246
253 ~HostRenderer();
254
255 private:
257 template<typename... _tParams>
258 HostRenderer(ystdex::empty_base<WindowThread>, UI::IWidget& wgt,
259 _tParams&&... args)
260 : BufferedRenderer(),
261 widget(wgt), rbuf(GetSizeOf(wgt)), thrd(yforward(args)...)
262 {
263 InitWidgetView();
264 }
265
266 public:
267 DefDeMoveCtor(HostRenderer)
268
269
270 DefGetter(ynothrow, ScreenRegionBuffer&, BufferRef, rbuf)
271 DefGetter(const ynothrow, UI::IWidget&, WidgetRef, widget.get())
273 DefGetterMem(const ynothrow, observer_ptr<Window>, WindowPtr, thrd)
274
281 void
282 SetSize(const Drawing::Size&) override;
283
292 bool
293 AdjustSize();
294
295 private:
304 void
305 InitWidgetView();
306
307 public:
313 template<class _tWindow, typename _func, typename... _tParams>
314 unique_ptr<Window>
315 MakeRenderWindow(_func&& f, _tParams&&... args)
316 {
317 return make_unique<_tWindow>(*this, yforward(f)(yforward(args)...));
318 }
319
320 template<class _tWindow, typename _func, typename... _tParams>
321 unique_ptr<Window>
322 MakeRenderWindowEx(_func&& f, _tParams&&... args)
323 {
324 return make_unique<_tWindow>(*this, yforward(f)(), yforward(args)...);
325 }
327
334 void
335 RefreshForWidget();
336
348 YB_NONNULL(1) void
349 Update(Drawing::ConstBitmapPtr, const Drawing::Rect&);
350
352 template<typename _type>
353 void
354 UpdateToSurface(_type& sf)
355 {
356 sf.Update(Deref(rbuf.Lock()));
357 }
358
359 #if YCL_Win32
360 template<typename _type, typename... _tParams>
362 void
363 UpdateBoundsToSurface(_type& sf, _tParams&&... args)
364 {
365 sf.UpdateBounds(Deref(rbuf.Lock()), yforward(args)...);
366 }
367 #endif
368
373 Window&
374 Wait();
375
377 YB_NORETURN PDefH(HostRenderer*, clone, ) const override
378 ImplThrow(ystdex::unimplemented("HostRenderer::clone unimplemented."))
379 // DefClone(const override, HostRenderer)
380 };
381
382 } // namespace Host;
383 #endif
384
385 } // namespace YSLib;
386
387 #endif
388
YSLib
YSLib 命名空间。
Definition: AndroidHost.h:45
UI
ystdex::make_observer
observer_ptr< _type > make_observer(_type *p)
Definition: pointer.hpp:326
platform::Deref
yconstfn auto Deref(_type &&p) -> decltype(*p)
断言并解引用非空指针。
Definition: Debug.h:451
ystdex::identity
恒等元函数。
Definition: type_traits.hpp:999
CHRLib::f
f(d, s)
YSLib::UI::wgt
IWidget & wgt
Definition: YControl.h:112
DefDeMoveCtor
#define DefDeMoveCtor(_t)
Definition: YBaseMacro.h:167
CHRLib::args
_tParams && args
Definition: CharacterProcessing.h:538
NPL::Guard
ystdex::any Guard
作用域守护类型。
Definition: NPLA.h:958
YSLib::PDefH
PDefH(Environment &, FetchEnvironment,) ImplRet(FetchGlobalInstance().GetEnvironmentRef()) inline PDefH(GUIHost &
取单一环境对象引用。
ystdex::any
基于类型擦除的动态泛型对象。
Definition: any.h:845
YSLib::FilterExceptions
bool FilterExceptions(_func f, const char *desc={}, RecordLevel lv=Alert, ExceptionTracer trace=ExtractAndTrace) ynothrow
调用函数并过滤宿主异常。
Definition: YException.h:203
ystdex::cpp2014::decay_t
typename decay< _type >::type decay_t
Definition: type_traits.hpp:340
ystdex
特性测试宏。
Definition: ydef.h:822
DefGetterMem
#define DefGetterMem(_q, _t, _n, _m)
Definition: YBaseMacro.h:247
ystdex::any_ops::clone
Definition: any.h:233
YF_API
#define YF_API
Definition: Platform.h:56
Drawing
YSLib::ynothrow
YB_PURE const _type size_t n ynothrow
Definition: YCoreUtilities.h:168
YSLib::UI::Styles::Window
窗口背景。
Definition: YStyle.h:311
YModules.h
YSLib::YB_NONNULL
YF_API YB_NONNULL(1, 2) ValueNode LoadNPLA1File(const char *disp
载入 NPLA1 配置文件。
std
Definition: memory.hpp:1183
YSLib::ImplRet
ImplRet(FetchGlobalInstance().GetGUIHostRef()) YF_API void Execute(GUIApplication &
执行程序主消息循环。
DefGetter
#define DefGetter(_q, _t, _n,...)
Definition: YBaseMacro.h:241
ystdex::empty_base
空基类模板。
Definition: ydef.h:928
YB_NORETURN
#define YB_NORETURN
指定无返回值函数。
Definition: ydef.h:504
yforward
#define yforward(_expr)
根据参数类型使用 std::forward 传递对应参数。
Definition: ydef.h:995
ystdex::invoke
result_of_t< _fCallable &&(_tParams &&...)> invoke(_fCallable &&f, _tParams &&...args)
调用可调用对象。
Definition: functional.hpp:339
DefDelMoveCtor
#define DefDelMoveCtor(_t)
Definition: YBaseMacro.h:169
YSLib::UI::GetSizeOf
pt pt Y const IWidget &wgt const IWidget &wgt GetSizeOf
无效化：使相对部件的子部件的指定区域在直接和间接的窗口缓冲区中无效。
Definition: YWidget.h:161
ImplThrow
#define ImplThrow(...)
Definition: YBaseMacro.h:105
YSLib::Drawing::ConstBitmapPtr
const Pixel * ConstBitmapPtr
Definition: YGraphics.h:44
ystdex::details::get
get())
Definition: cast.hpp:102