YSTest  PreAlpha_b500_20140530
The YSLib Test Project
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
HostRenderer.cpp
浏览该文件的文档.
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 #include "Helper/YModules.h"
29 #include YFM_Helper_HostRenderer
30 #include YFM_Helper_Host // for Host::Environment;
31 //#include YFM_Helper_GUIApplication
32 
33 namespace YSLib
34 {
35 
36 using namespace Drawing;
37 
38 #if YF_Hosted
39 namespace Host
40 {
41 
42 RenderWindow::RenderWindow(HostRenderer& r, NativeWindowHandle h)
43  : Window(h), renderer(r)
44 {
45 # if YCL_Win32
46  MessageMap[WM_PAINT] += [this]{
47  GSurface<WindowRegionDeviceContext> sf(GetNativeHandle());
48 
49  renderer.get().UpdateToSurface(sf);
50  };
51 # endif
52 }
53 
54 void
56 {
57  auto& rd(GetRenderer());
58  auto& wgt(rd.GetWidgetRef());
59 
60  if(rd.Validate(wgt, wgt,
61  {rd.GetContext(), Point(), rd.GetInvalidatedArea()}))
62  rd.Update(rd.GetContext().GetBufferPtr());
63 }
64 
65 
66 WindowThread::~WindowThread()
67 {
68  const auto p_wnd_val(GetWindowPtr());
69 
70  YAssertNonnull(p_wnd_val);
71  try
72  {
73 # if !YCL_Android
74  try
75  {
76  p_wnd_val->Close();
77  }
78 # if YCL_Win32
79  catch(Win32Exception&)
80 # else
81  catch(Exception&) // XXX: Use proper platform-dependent type.
82 # endif
83  {}
84 # endif
85  // NOTE: If the thread has been already completed there is no effect.
86  if(thrd.joinable())
87  thrd.join();
88  }
89  catch(std::system_error& e)
90  {
91  YTraceDe(Warning, "Caught std::system_error: %s.", e.what());
92 
93  yunused(e);
94  }
95  catch(std::exception& e)
96  {
97  YTraceDe(Alert, "Caught std::exception[%s]: %s.", typeid(e).name(),
98  e.what());
99 
100  yunused(e);
101  }
102  catch(...)
103  {
104  YTraceDe(Alert, "Caught unknown exception.");
105  }
106  delete p_wnd_val;
107 }
108 
109 void
110 WindowThread::ThreadLoop(NativeWindowHandle h_wnd)
111 {
112  ThreadLoop(make_unique<Window>(h_wnd));
113 }
114 void
115 WindowThread::ThreadLoop(unique_ptr<Window> p)
116 {
117  YAssert(!p_wnd, "Duplicate window initialization detected.");
118  p_wnd = p.release();
119  YAssertNonnull(p_wnd);
120  WindowLoop(*p_wnd);
121 }
122 
123 void
124 WindowThread::WindowLoop(Window& wnd)
125 {
126 # if YF_Multithread
127  auto& env(wnd.GetHost());
128 
129  env.EnterWindowThread();
130 # endif
131 # if !YCL_Android
132  wnd.Show();
133 # endif
134  Environment::HostLoop();
135 # if YF_Multithread
136  env.LeaveWindowThread();
137 # endif
138 }
139 
140 
141 void
142 HostRenderer::SetSize(const Size& s)
143 {
145  rbuf.Resize(s);
146 }
147 
148 void
149 HostRenderer::Update(BitmapPtr buf)
150 {
151  YAssert(GetSizeOf(widget) == rbuf.GetSize(), "Mismatched size found.");
152 
153  if(const auto p_wnd = GetWindowPtr())
154  try
155  {
156 # if YCL_Android
157  const Rect cbounds(p_wnd->GetSize());
158 # else
159  const auto& cbounds(p_wnd->GetClientBounds());
160 # endif
161  auto bounds(cbounds);
162  auto& view(widget.get().GetView());
163  const auto& loc(view.GetLocation());
164 
165  if(!loc.IsZero())
166  {
167  bounds.GetPointRef() += loc;
168  view.SetLocation({});
169  rInvalidated = {{}, bounds.GetSize()};
170  Validate(widget, widget, {GetContext(), Point(), rInvalidated});
171  }
172  bounds.GetSizeRef() = view.GetSize();
173 # if !YCL_Android
174  if(bounds != cbounds)
175  p_wnd->SetClientBounds(bounds);
176 # endif
177  p_wnd->UpdateFrom(buf, rbuf);
178  }
179 # if YCL_Win32
180  catch(Win32Exception&)
181 # else
182  catch(Exception&) // XXX: Use proper platform-dependent type.
183 # endif
184  {}
185 }
186 
187 } // namespace Host;
188 #endif
189 
190 } // namespace YSLib;
191 
pt pt Y const IWidget &wgt const IWidget &wgt GetSizeOf
无效化:使相对于部件的子部件的指定区域在直接和间接的窗口缓冲区中无效。
Definition: ywidget.h:156
void Refresh(PaintEventArgs &&) override
刷新:按指定参数绘制界面并更新状态。
#define yunused(...)
标记未使用的表达式。
Definition: ydef.h:697
YF_API TLCIter Validate(TLCIter b, TLCIter e)
遍历记号列表,验证基本合法性:圆括号是否对应。
Definition: SContext.cpp:60
窗口背景。
Definition: ystyle.h:182
sizeof(AlphaType)*GetAreaOf(GetSize())) using CompactPixmap void SetSize(const Size &) override
重新设置缓冲区大小。
GBinaryGroup< SPos > Point
屏幕二维点(直角坐标表示)。
Definition: ygdibase.h:235
std::exception Exception
YSLib 异常基类。
Definition: yexcept.h:44
_tWidget & wgt
Definition: ywgtevt.h:596
yconstfn const string & name
Definition: Loader.h:110
#define YAssertNonnull(_expr)
Definition: cassert.h:81
::ANativeWindow * NativeWindowHandle
Definition: Android.h:50
#define YTraceDe(...)
YCLib 默认调试跟踪。
Definition: Debug.h:269
PixelType * BitmapPtr
Definition: Video.h:295
bounds & r
Definition: ydraw.h:220
#define YAssert(_expr, _msg)
Definition: cassert.h:73