ReactOS 0.4.16-dev-1537-g4e425b5
buffer.c
Go to the documentation of this file.
1/*
2 * uxtheme Double-buffered Drawing API
3 *
4 * Copyright (C) 2008 Reece H. Dunn
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21#include "uxthemep.h"
22#include <wine/heap.h>
23
25{
30 void *bits;
31};
32
34{
35 DeleteObject(buffer->bitmap);
36 DeleteDC(buffer->memorydc);
38}
39
41{
42 return handle;
43}
44
45/***********************************************************************
46 * BufferedPaintInit (UXTHEME.@)
47 */
49{
50 FIXME("Stub ()\n");
51 return S_OK;
52}
53
54/***********************************************************************
55 * BufferedPaintUnInit (UXTHEME.@)
56 */
58{
59 FIXME("Stub ()\n");
60 return S_OK;
61}
62
63/***********************************************************************
64 * BeginBufferedPaint (UXTHEME.@)
65 */
67 BP_BUFFERFORMAT format, BP_PAINTPARAMS *params, HDC *retdc)
68{
69#if (defined(_MSC_VER))
70 char bmibuf[FIELD_OFFSET(BITMAPINFO, bmiColors) + 256 * sizeof(RGBQUAD)];
71#else
72 char bmibuf[FIELD_OFFSET(BITMAPINFO, bmiColors[256])];
73#endif
74 BITMAPINFO *bmi = (BITMAPINFO *)bmibuf;
75 struct paintbuffer *buffer;
76
77 TRACE("(%p %s %d %p %p)\n", targetdc, wine_dbgstr_rect(rect), format,
78 params, retdc);
79
80 if (retdc)
81 *retdc = NULL;
82
83 if (!targetdc || IsRectEmpty(rect))
84 return NULL;
85
86 if (params)
87 FIXME("painting parameters are ignored\n");
88
89 buffer = heap_alloc(sizeof(*buffer));
90 buffer->targetdc = targetdc;
91 buffer->rect = *rect;
93
94 switch (format)
95 {
97 buffer->bitmap = CreateCompatibleBitmap(targetdc, rect->right - rect->left, rect->bottom - rect->top);
98 buffer->bits = NULL;
99 break;
100 case BPBF_DIB:
101 case BPBF_TOPDOWNDIB:
102 case BPBF_TOPDOWNMONODIB:
103 /* create DIB section */
104 memset(bmi, 0, sizeof(bmibuf));
105 bmi->bmiHeader.biSize = sizeof(bmi->bmiHeader);
106 bmi->bmiHeader.biHeight = format == BPBF_DIB ? rect->bottom - rect->top :
107 -(rect->bottom - rect->top);
108 bmi->bmiHeader.biWidth = rect->right - rect->left;
109 bmi->bmiHeader.biBitCount = format == BPBF_TOPDOWNMONODIB ? 1 : 32;
110 bmi->bmiHeader.biPlanes = 1;
112 buffer->bitmap = CreateDIBSection(buffer->memorydc, bmi, DIB_RGB_COLORS, &buffer->bits, NULL, 0);
113 break;
114 default:
115 WARN("Unknown buffer format %d\n", format);
116 buffer->bitmap = NULL;
118 return NULL;
119 }
120
121 if (!buffer->bitmap)
122 {
123 WARN("Failed to create buffer bitmap\n");
125 return NULL;
126 }
127
128 SetWindowOrgEx(buffer->memorydc, rect->left, rect->top, NULL);
129 IntersectClipRect(buffer->memorydc, rect->left, rect->top, rect->right, rect->bottom);
130 DeleteObject(SelectObject(buffer->memorydc, buffer->bitmap));
131
132 *retdc = buffer->memorydc;
133
134 return (HPAINTBUFFER)buffer;
135}
136
137
138/***********************************************************************
139 * EndBufferedPaint (UXTHEME.@)
140 */
142{
143 struct paintbuffer *buffer = get_buffer_obj(bufferhandle);
144
145 TRACE("(%p %d)\n", bufferhandle, update);
146
147 if (!buffer)
148 return E_INVALIDARG;
149
150 if (update)
151 {
152 if (!BitBlt(buffer->targetdc, buffer->rect.left, buffer->rect.top,
153 buffer->rect.right - buffer->rect.left, buffer->rect.bottom - buffer->rect.top,
154 buffer->memorydc, buffer->rect.left, buffer->rect.top, SRCCOPY))
155 {
156 WARN("BitBlt() failed\n");
157 }
158 }
159
161 return S_OK;
162}
163
164/***********************************************************************
165 * BufferedPaintClear (UXTHEME.@)
166 */
168{
169 FIXME("Stub (%p %p)\n", hBufferedPaint, prc);
170 return E_NOTIMPL;
171}
172
173/***********************************************************************
174 * BufferedPaintSetAlpha (UXTHEME.@)
175 */
177{
178 FIXME("Stub (%p %p %u)\n", hBufferedPaint, prc, alpha);
179 return E_NOTIMPL;
180}
181
182/***********************************************************************
183 * GetBufferedPaintBits (UXTHEME.@)
184 */
186{
187 struct paintbuffer *buffer = get_buffer_obj(bufferhandle);
188
189 TRACE("(%p %p %p)\n", buffer, bits, width);
190
191 if (!bits || !width)
192 return E_POINTER;
193
194 if (!buffer || !buffer->bits)
195 return E_FAIL;
196
197 *bits = buffer->bits;
198 *width = buffer->rect.right - buffer->rect.left;
199
200 return S_OK;
201}
202
203/***********************************************************************
204 * GetBufferedPaintDC (UXTHEME.@)
205 */
207{
208 struct paintbuffer *buffer = get_buffer_obj(bufferhandle);
209
210 TRACE("(%p)\n", buffer);
211
212 return buffer ? buffer->memorydc : NULL;
213}
214
215/***********************************************************************
216 * GetBufferedPaintTargetDC (UXTHEME.@)
217 */
219{
220 struct paintbuffer *buffer = get_buffer_obj(bufferhandle);
221
222 TRACE("(%p)\n", buffer);
223
224 return buffer ? buffer->targetdc : NULL;
225}
226
227/***********************************************************************
228 * GetBufferedPaintTargetRect (UXTHEME.@)
229 */
231{
232 struct paintbuffer *buffer = get_buffer_obj(bufferhandle);
233
234 TRACE("(%p %p)\n", buffer, rect);
235
236 if (!rect)
237 return E_POINTER;
238
239 if (!buffer)
240 return E_FAIL;
241
242 *rect = buffer->rect;
243 return S_OK;
244}
245
246/***********************************************************************
247 * BeginBufferedAnimation (UXTHEME.@)
248 */
249HANIMATIONBUFFER WINAPI BeginBufferedAnimation(HWND hwnd, HDC hdcTarget, const RECT *rcTarget,
250 BP_BUFFERFORMAT dwFormat, BP_PAINTPARAMS *pPaintParams,
251 BP_ANIMATIONPARAMS *pAnimationParams, HDC *phdcFrom,
252 HDC *phdcTo)
253{
254 FIXME("Stub (%p %p %p %u %p %p %p %p)\n", hwnd, hdcTarget, rcTarget, dwFormat,
255 pPaintParams, pAnimationParams, phdcFrom, phdcTo);
256
257 return NULL;
258}
259
260/***********************************************************************
261 * BufferedPaintRenderAnimation (UXTHEME.@)
262 */
264{
265 FIXME("Stub (%p %p)\n", hwnd, hdcTarget);
266
267 return FALSE;
268}
269
270/***********************************************************************
271 * BufferedPaintStopAllAnimations (UXTHEME.@)
272 */
274{
275 FIXME("Stub (%p)\n", hwnd);
276
277 return E_NOTIMPL;
278}
279
280/***********************************************************************
281 * EndBufferedAnimation (UXTHEME.@)
282 */
283HRESULT WINAPI EndBufferedAnimation(HANIMATIONBUFFER hbpAnimation, BOOL fUpdateTarget)
284{
285 FIXME("Stub (%p %u)\n", hbpAnimation, fUpdateTarget);
286
287 return E_NOTIMPL;
288}
HDC hdcTarget
Definition: PatBlt.c:13
static void * heap_alloc(size_t len)
Definition: appwiz.h:66
static BOOL heap_free(void *mem)
Definition: appwiz.h:76
static const char * wine_dbgstr_rect(const RECT *prc)
Definition: atltest.h:160
#define FIXME(fmt,...)
Definition: precomp.h:53
#define WARN(fmt,...)
Definition: precomp.h:61
#define E_INVALIDARG
Definition: ddrawi.h:101
#define E_NOTIMPL
Definition: ddrawi.h:99
#define E_FAIL
Definition: ddrawi.h:102
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
HDC WINAPI GetBufferedPaintDC(HPAINTBUFFER bufferhandle)
Definition: buffer.c:206
HRESULT WINAPI GetBufferedPaintBits(HPAINTBUFFER bufferhandle, RGBQUAD **bits, int *width)
Definition: buffer.c:185
HRESULT WINAPI EndBufferedAnimation(HANIMATIONBUFFER hbpAnimation, BOOL fUpdateTarget)
Definition: buffer.c:283
HRESULT WINAPI BufferedPaintSetAlpha(HPAINTBUFFER hBufferedPaint, const RECT *prc, BYTE alpha)
Definition: buffer.c:176
HRESULT WINAPI BufferedPaintUnInit(VOID)
Definition: buffer.c:57
HRESULT WINAPI BufferedPaintStopAllAnimations(HWND hwnd)
Definition: buffer.c:273
BOOL WINAPI BufferedPaintRenderAnimation(HWND hwnd, HDC hdcTarget)
Definition: buffer.c:263
static struct paintbuffer * get_buffer_obj(HPAINTBUFFER handle)
Definition: buffer.c:40
HRESULT WINAPI BufferedPaintClear(HPAINTBUFFER hBufferedPaint, const RECT *prc)
Definition: buffer.c:167
static void free_paintbuffer(struct paintbuffer *buffer)
Definition: buffer.c:33
HDC WINAPI GetBufferedPaintTargetDC(HPAINTBUFFER bufferhandle)
Definition: buffer.c:218
HRESULT WINAPI GetBufferedPaintTargetRect(HPAINTBUFFER bufferhandle, RECT *rect)
Definition: buffer.c:230
HRESULT WINAPI EndBufferedPaint(HPAINTBUFFER bufferhandle, BOOL update)
Definition: buffer.c:141
HPAINTBUFFER WINAPI BeginBufferedPaint(HDC targetdc, const RECT *rect, BP_BUFFERFORMAT format, BP_PAINTPARAMS *params, HDC *retdc)
Definition: buffer.c:66
HANIMATIONBUFFER WINAPI BeginBufferedAnimation(HWND hwnd, HDC hdcTarget, const RECT *rcTarget, BP_BUFFERFORMAT dwFormat, BP_PAINTPARAMS *pPaintParams, BP_ANIMATIONPARAMS *pAnimationParams, HDC *phdcFrom, HDC *phdcTo)
Definition: buffer.c:249
HRESULT WINAPI BufferedPaintInit(VOID)
Definition: buffer.c:48
static VOID BitBlt(_In_ ULONG Left, _In_ ULONG Top, _In_ ULONG Width, _In_ ULONG Height, _In_reads_bytes_(Delta *Height) PUCHAR Buffer, _In_ ULONG BitsPerPixel, _In_ ULONG Delta)
Definition: common.c:57
#define BI_RGB
Definition: precomp.h:56
ULONG RGBQUAD
Definition: precomp.h:59
unsigned int BOOL
Definition: ntddk_ex.h:94
pKey DeleteObject()
GLclampf GLclampf GLclampf alpha
Definition: gl.h:1740
GLint GLint GLsizei width
Definition: gl.h:1546
GLuint buffer
Definition: glext.h:5915
GLenum const GLfloat * params
Definition: glext.h:5645
GLenum GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * bits
Definition: glext.h:10929
#define S_OK
Definition: intsafe.h:52
static HBITMAP
Definition: button.c:44
static HDC
Definition: imagelist.c:88
static const RECT BP_BUFFERFORMAT
Definition: system.c:30
static HPAINTBUFFER(WINAPI *pBeginBufferedPaint)(HDC
_Out_ LPRECT prc
Definition: ntgdi.h:1658
#define memset(x, y, z)
Definition: compat.h:39
#define TRACE(s)
Definition: solgame.cpp:4
& rect
Definition: startmenu.cpp:1413
Definition: format.c:58
RECT rect
Definition: buffer.c:29
HDC targetdc
Definition: buffer.c:26
void * bits
Definition: buffer.c:30
HBITMAP bitmap
Definition: buffer.c:28
HDC memorydc
Definition: buffer.c:27
USHORT biBitCount
Definition: precomp.h:46
ULONG biCompression
Definition: precomp.h:47
BITMAPINFOHEADER bmiHeader
Definition: wingdi.h:1922
#define BPBF_COMPATIBLEBITMAP
Definition: treelist.c:133
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
HBITMAP WINAPI CreateDIBSection(HDC hDC, CONST BITMAPINFO *BitmapInfo, UINT Usage, VOID **Bits, HANDLE hSection, DWORD dwOffset)
Definition: bitmap.c:245
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023
#define WINAPI
Definition: msvc.h:6
#define E_POINTER
Definition: winerror.h:3481
#define DIB_RGB_COLORS
Definition: wingdi.h:367
BOOL WINAPI SetWindowOrgEx(_In_ HDC, _In_ int, _In_ int, _Out_opt_ LPPOINT)
Definition: coord.c:532
int WINAPI IntersectClipRect(_In_ HDC, _In_ int, _In_ int, _In_ int, _In_ int)
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1546
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
#define SRCCOPY
Definition: wingdi.h:333
HBITMAP WINAPI CreateCompatibleBitmap(_In_ HDC hdc, _In_ INT cx, _In_ INT cy)
BOOL WINAPI DeleteDC(_In_ HDC)
BOOL WINAPI IsRectEmpty(_In_ LPCRECT)
unsigned char BYTE
Definition: xxhash.c:193