YSTest: ScreenBuffer.h 源文件

YSTest PreAlpha_b400_20130424 The YSLib Test Project

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

- 文件列表
- 文件成员

全部 类 命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义 组 页
ScreenBuffer.h
浏览该文件的文档.
1 ﻿/*
2 Copyright by FrankHB 2013.
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_ScreenBuffer_h_
29 #define Inc_Helper_ScreenBuffer_h_ 1
30
31 #include "YSLib/Core/ygdibase.h"
32 #include "YCLib/NativeAPI.h"
33 #if YCL_MULTITHREAD == 1
34 # include <mutex>
35 #endif
36
37 YSL_BEGIN
38
39 #if YCL_HOSTED
40 YSL_BEGIN_NAMESPACE(Host)
41 # if YCL_MINGW32
42
47 class ScreenBuffer
48 {
49 private:
51 Drawing::Size size;
52
53 protected:
54 Drawing::BitmapPtr pBuffer;
55 ::HBITMAP hBitmap;
56
57 public:
58 ScreenBuffer(const Drawing::Size&);
60 ScreenBuffer(ScreenBuffer&&) ynothrow;
61 ~ScreenBuffer();
62
64
65 DefGetter(const ynothrow, Drawing::BitmapPtr, BufferPtr, pBuffer)
66 DefGetter(const ynothrow, ::HBITMAP, NativeHandle, hBitmap)
67 DefGetter(const ynothrow, const Drawing::Size&, Size, size)
68
73 void
74 UpdateFrom(Drawing::BitmapPtr) ynothrow;
76 };
77
78
80 class ScreenRegionBuffer : private ScreenBuffer
81 {
82 private:
83 std::mutex mtx;
84
85 public:
86 ScreenRegionBuffer(const Drawing::Size& s)
87 : ScreenBuffer(s), mtx()
88 {}
89
90 using ScreenBuffer::GetBufferPtr;
91 using ScreenBuffer::GetNativeHandle;
92 using ScreenBuffer::GetSize;
93 DefGetter(ynothrow, ScreenBuffer&, ScreenBufferRef, *this)
94
95 void
96 UpdateFrom(Drawing::BitmapPtr) ynothrow;
97
98 void
99 UpdateTo(::HWND, const Drawing::Point& = {}) ynothrow;
100 };
101
102
104
105
109 class WindowMemorySurface
110 {
111 private:
112 ::HDC h_owner_dc, h_mem_dc;
113
114 public:
115 WindowMemorySurface(::HDC h_dc)
116 : h_owner_dc(h_dc), h_mem_dc(::CreateCompatibleDC(h_dc))
117 {}
118 ~WindowMemorySurface()
119 {
120 ::DeleteDC(h_mem_dc);
121 }
122
123 DefGetter(const ynothrow, ::HDC, OwnerHandle, h_owner_dc)
124 DefGetter(const ynothrow, ::HDC, NativeHandle, h_mem_dc)
125
127 void
128 Update(ScreenBuffer&, const Drawing::Point& = {}) ynothrow;
130 void
131 Update(ScreenRegionBuffer& rbuf, const Drawing::Point& pt = {}) ynothrow
132 {
133 Update(rbuf.GetScreenBufferRef(), pt);
134 }
135 };
136
137
138 class WindowDeviceContextBase
139 {
140 protected:
141 ::HWND hWindow;
142 ::HDC hDC;
143
144 WindowDeviceContextBase(::HWND h_wnd, ::HDC h_dc)
145 : hWindow(h_wnd), hDC(h_dc)
146 {}
147 DefEmptyDtor(WindowDeviceContextBase)
148
149 public:
150 DefGetter(const ynothrow, ::HDC, DeviceContextHandle, hDC)
151 DefGetter(const ynothrow, ::HWND, WindowHandle, hWindow)
152 };
153
154
159 class WindowDeviceContext : public WindowDeviceContextBase
160 {
161 protected:
162 WindowDeviceContext(::HWND h_wnd)
163 : WindowDeviceContextBase(h_wnd, ::GetDC(h_wnd))
164 {}
165 ~WindowDeviceContext()
166 {
167 ::ReleaseDC(hWindow, hDC);
168 }
169 };
170
171
176 class WindowRegionDeviceContext : public WindowDeviceContextBase
177 {
178 private:
179 ::PAINTSTRUCT ps;
180
181 protected:
182 WindowRegionDeviceContext(::HWND h_wnd)
183 : WindowDeviceContextBase(h_wnd, ::BeginPaint(h_wnd, &ps))
184 {}
185 ~WindowRegionDeviceContext()
186 {
187 ::EndPaint(hWindow, &ps);
188 }
189 };
190
191
193 template<typename _type = WindowDeviceContext>
194 class GSurface : public _type, public WindowMemorySurface
195 {
196 public:
197 GSurface(::HWND h_wnd)
198 : _type(h_wnd), WindowMemorySurface(::GetDC(h_wnd))
199 {}
200 };
202
203 # endif
204 YSL_END_NAMESPACE(Host)
205 #endif
206
207 YSL_END
208
209 #endif
210