1 | /*
|
---|
2 | * 2D Surface implementation without OpenGL
|
---|
3 | *
|
---|
4 | * Copyright 1997-2000 Marcus Meissner
|
---|
5 | * Copyright 1998-2000 Lionel Ulmer
|
---|
6 | * Copyright 2000-2001 TransGaming Technologies Inc.
|
---|
7 | * Copyright 2002-2005 Jason Edmeades
|
---|
8 | * Copyright 2002-2003 Raphael Junqueira
|
---|
9 | * Copyright 2004 Christian Costa
|
---|
10 | * Copyright 2005 Oliver Stieber
|
---|
11 | * Copyright 2006-2008 Stefan Dösinger
|
---|
12 | *
|
---|
13 | * This library is free software; you can redistribute it and/or
|
---|
14 | * modify it under the terms of the GNU Lesser General Public
|
---|
15 | * License as published by the Free Software Foundation; either
|
---|
16 | * version 2.1 of the License, or (at your option) any later version.
|
---|
17 | *
|
---|
18 | * This library is distributed in the hope that it will be useful,
|
---|
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
21 | * Lesser General Public License for more details.
|
---|
22 | *
|
---|
23 | * You should have received a copy of the GNU Lesser General Public
|
---|
24 | * License along with this library; if not, write to the Free Software
|
---|
25 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
---|
26 | */
|
---|
27 |
|
---|
28 | /*
|
---|
29 | * Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
|
---|
30 | * other than GPL or LGPL is available it will apply instead, Sun elects to use only
|
---|
31 | * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
|
---|
32 | * a choice of LGPL license versions is made available with the language indicating
|
---|
33 | * that LGPLv2 or any later version may be used, or where a choice of which version
|
---|
34 | * of the LGPL is applied is otherwise unspecified.
|
---|
35 | */
|
---|
36 |
|
---|
37 | #include "config.h"
|
---|
38 | #include "wine/port.h"
|
---|
39 | #include "wined3d_private.h"
|
---|
40 |
|
---|
41 | #include <stdio.h>
|
---|
42 |
|
---|
43 | /* Use the d3d_surface debug channel to have one channel for all surfaces */
|
---|
44 | WINE_DEFAULT_DEBUG_CHANNEL(d3d_surface);
|
---|
45 |
|
---|
46 | void surface_gdi_cleanup(IWineD3DSurfaceImpl *This)
|
---|
47 | {
|
---|
48 | TRACE("(%p) : Cleaning up.\n", This);
|
---|
49 |
|
---|
50 | if (This->Flags & SFLAG_DIBSECTION)
|
---|
51 | {
|
---|
52 | /* Release the DC. */
|
---|
53 | SelectObject(This->hDC, This->dib.holdbitmap);
|
---|
54 | DeleteDC(This->hDC);
|
---|
55 | /* Release the DIB section. */
|
---|
56 | DeleteObject(This->dib.DIBsection);
|
---|
57 | This->dib.bitmap_data = NULL;
|
---|
58 | This->resource.allocatedMemory = NULL;
|
---|
59 | }
|
---|
60 |
|
---|
61 | if (This->Flags & SFLAG_USERPTR) IWineD3DSurface_SetMem((IWineD3DSurface *)This, NULL);
|
---|
62 | if (This->overlay_dest) list_remove(&This->overlay_entry);
|
---|
63 |
|
---|
64 | HeapFree(GetProcessHeap(), 0, This->palette9);
|
---|
65 |
|
---|
66 | resource_cleanup((IWineD3DResource *)This);
|
---|
67 | }
|
---|
68 |
|
---|
69 | /*****************************************************************************
|
---|
70 | * IWineD3DSurface::Release, GDI version
|
---|
71 | *
|
---|
72 | * In general a normal COM Release method, but the GDI version doesn't have
|
---|
73 | * to destroy all the GL things.
|
---|
74 | *
|
---|
75 | *****************************************************************************/
|
---|
76 | static ULONG WINAPI IWineGDISurfaceImpl_Release(IWineD3DSurface *iface) {
|
---|
77 | IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
|
---|
78 | ULONG ref = InterlockedDecrement(&This->resource.ref);
|
---|
79 | TRACE("(%p) : Releasing from %d\n", This, ref + 1);
|
---|
80 |
|
---|
81 | if (!ref)
|
---|
82 | {
|
---|
83 | surface_gdi_cleanup(This);
|
---|
84 |
|
---|
85 | TRACE("(%p) Released.\n", This);
|
---|
86 | HeapFree(GetProcessHeap(), 0, This);
|
---|
87 | }
|
---|
88 |
|
---|
89 | return ref;
|
---|
90 | }
|
---|
91 |
|
---|
92 | /*****************************************************************************
|
---|
93 | * IWineD3DSurface::PreLoad, GDI version
|
---|
94 | *
|
---|
95 | * This call is unsupported on GDI surfaces, if it's called something went
|
---|
96 | * wrong in the parent library. Write an informative warning
|
---|
97 | *
|
---|
98 | *****************************************************************************/
|
---|
99 | static void WINAPI
|
---|
100 | IWineGDISurfaceImpl_PreLoad(IWineD3DSurface *iface)
|
---|
101 | {
|
---|
102 | ERR("(%p): PreLoad is not supported on X11 surfaces!\n", iface);
|
---|
103 | ERR("(%p): Most likely the parent library did something wrong.\n", iface);
|
---|
104 | ERR("(%p): Please report to wine-devel\n", iface);
|
---|
105 | }
|
---|
106 |
|
---|
107 | /*****************************************************************************
|
---|
108 | * IWineD3DSurface::UnLoad, GDI version
|
---|
109 | *
|
---|
110 | * This call is unsupported on GDI surfaces, if it's called something went
|
---|
111 | * wrong in the parent library. Write an informative warning.
|
---|
112 | *
|
---|
113 | *****************************************************************************/
|
---|
114 | static void WINAPI IWineGDISurfaceImpl_UnLoad(IWineD3DSurface *iface)
|
---|
115 | {
|
---|
116 | ERR("(%p): UnLoad is not supported on X11 surfaces!\n", iface);
|
---|
117 | ERR("(%p): Most likely the parent library did something wrong.\n", iface);
|
---|
118 | ERR("(%p): Please report to wine-devel\n", iface);
|
---|
119 | }
|
---|
120 |
|
---|
121 | /*****************************************************************************
|
---|
122 | * IWineD3DSurface::LockRect, GDI version
|
---|
123 | *
|
---|
124 | * Locks the surface and returns a pointer to the surface memory
|
---|
125 | *
|
---|
126 | * Params:
|
---|
127 | * pLockedRect: Address to return the locking info at
|
---|
128 | * pRect: Rectangle to lock
|
---|
129 | * Flags: Some flags
|
---|
130 | *
|
---|
131 | * Returns:
|
---|
132 | * WINED3D_OK on success
|
---|
133 | * WINED3DERR_INVALIDCALL on errors
|
---|
134 | *
|
---|
135 | *****************************************************************************/
|
---|
136 | static HRESULT WINAPI
|
---|
137 | IWineGDISurfaceImpl_LockRect(IWineD3DSurface *iface,
|
---|
138 | WINED3DLOCKED_RECT* pLockedRect,
|
---|
139 | CONST RECT* pRect,
|
---|
140 | DWORD Flags)
|
---|
141 | {
|
---|
142 | IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
|
---|
143 |
|
---|
144 | /* Already locked? */
|
---|
145 | if(This->Flags & SFLAG_LOCKED)
|
---|
146 | {
|
---|
147 | WARN("(%p) Surface already locked\n", This);
|
---|
148 | /* What should I return here? */
|
---|
149 | return WINED3DERR_INVALIDCALL;
|
---|
150 | }
|
---|
151 | This->Flags |= SFLAG_LOCKED;
|
---|
152 |
|
---|
153 | if(!This->resource.allocatedMemory) {
|
---|
154 | /* This happens on gdi surfaces if the application set a user pointer and resets it.
|
---|
155 | * Recreate the DIB section
|
---|
156 | */
|
---|
157 | IWineD3DBaseSurfaceImpl_CreateDIBSection(iface);
|
---|
158 | This->resource.allocatedMemory = This->dib.bitmap_data;
|
---|
159 | }
|
---|
160 |
|
---|
161 | return IWineD3DBaseSurfaceImpl_LockRect(iface, pLockedRect, pRect, Flags);
|
---|
162 | }
|
---|
163 |
|
---|
164 | /*****************************************************************************
|
---|
165 | * IWineD3DSurface::UnlockRect, GDI version
|
---|
166 | *
|
---|
167 | * Unlocks a surface. This implementation doesn't do much, except updating
|
---|
168 | * the window if the front buffer is unlocked
|
---|
169 | *
|
---|
170 | * Returns:
|
---|
171 | * WINED3D_OK on success
|
---|
172 | * WINED3DERR_INVALIDCALL on failure
|
---|
173 | *
|
---|
174 | *****************************************************************************/
|
---|
175 | static HRESULT WINAPI
|
---|
176 | IWineGDISurfaceImpl_UnlockRect(IWineD3DSurface *iface)
|
---|
177 | {
|
---|
178 | IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
|
---|
179 | IWineD3DSwapChainImpl *swapchain = NULL;
|
---|
180 | TRACE("(%p)\n", This);
|
---|
181 |
|
---|
182 | if (!(This->Flags & SFLAG_LOCKED))
|
---|
183 | {
|
---|
184 | WARN("trying to Unlock an unlocked surf@%p\n", This);
|
---|
185 | return WINEDDERR_NOTLOCKED;
|
---|
186 | }
|
---|
187 |
|
---|
188 | /* Can be useful for debugging */
|
---|
189 | #if 0
|
---|
190 | {
|
---|
191 | static unsigned int gen = 0;
|
---|
192 | char buffer[4096];
|
---|
193 | ++gen;
|
---|
194 | if ((gen % 10) == 0) {
|
---|
195 | snprintf(buffer, sizeof(buffer), "/tmp/surface%p_type%u_level%u_%u.ppm",
|
---|
196 | This, This->texture_target, This->texture_level, gen);
|
---|
197 | IWineD3DSurfaceImpl_SaveSnapshot(iface, buffer);
|
---|
198 | }
|
---|
199 | /*
|
---|
200 | * debugging crash code
|
---|
201 | if (gen == 250) {
|
---|
202 | void** test = NULL;
|
---|
203 | *test = 0;
|
---|
204 | }
|
---|
205 | */
|
---|
206 | }
|
---|
207 | #endif
|
---|
208 |
|
---|
209 | /* Tell the swapchain to update the screen */
|
---|
210 | if (SUCCEEDED(IWineD3DSurface_GetContainer(iface, &IID_IWineD3DSwapChain, (void **)&swapchain)))
|
---|
211 | {
|
---|
212 | if(iface == swapchain->frontBuffer)
|
---|
213 | {
|
---|
214 | x11_copy_to_screen(swapchain, &This->lockedRect);
|
---|
215 | }
|
---|
216 | IWineD3DSwapChain_Release((IWineD3DSwapChain *) swapchain);
|
---|
217 | }
|
---|
218 |
|
---|
219 | This->Flags &= ~SFLAG_LOCKED;
|
---|
220 | memset(&This->lockedRect, 0, sizeof(RECT));
|
---|
221 | return WINED3D_OK;
|
---|
222 | }
|
---|
223 |
|
---|
224 | /*****************************************************************************
|
---|
225 | * IWineD3DSurface::Flip, GDI version
|
---|
226 | *
|
---|
227 | * Flips 2 flipping enabled surfaces. Determining the 2 targets is done by
|
---|
228 | * the parent library. This implementation changes the data pointers of the
|
---|
229 | * surfaces and copies the new front buffer content to the screen
|
---|
230 | *
|
---|
231 | * Params:
|
---|
232 | * override: Flipping target(e.g. back buffer)
|
---|
233 | *
|
---|
234 | * Returns:
|
---|
235 | * WINED3D_OK on success
|
---|
236 | *
|
---|
237 | *****************************************************************************/
|
---|
238 | static HRESULT WINAPI
|
---|
239 | IWineGDISurfaceImpl_Flip(IWineD3DSurface *iface,
|
---|
240 | IWineD3DSurface *override,
|
---|
241 | DWORD Flags)
|
---|
242 | {
|
---|
243 | IWineD3DSwapChainImpl *swapchain = NULL;
|
---|
244 | HRESULT hr;
|
---|
245 |
|
---|
246 | if(FAILED(IWineD3DSurface_GetContainer(iface, &IID_IWineD3DSwapChain, (void **)&swapchain)))
|
---|
247 | {
|
---|
248 | ERR("Flipped surface is not on a swapchain\n");
|
---|
249 | return WINEDDERR_NOTFLIPPABLE;
|
---|
250 | }
|
---|
251 |
|
---|
252 | hr = IWineD3DSwapChain_Present((IWineD3DSwapChain *)swapchain,
|
---|
253 | NULL, NULL, swapchain->win_handle, NULL, 0);
|
---|
254 | IWineD3DSwapChain_Release((IWineD3DSwapChain *) swapchain);
|
---|
255 | return hr;
|
---|
256 | }
|
---|
257 |
|
---|
258 | /*****************************************************************************
|
---|
259 | * IWineD3DSurface::LoadTexture, GDI version
|
---|
260 | *
|
---|
261 | * This is mutually unsupported by GDI surfaces
|
---|
262 | *
|
---|
263 | * Returns:
|
---|
264 | * D3DERR_INVALIDCALL
|
---|
265 | *
|
---|
266 | *****************************************************************************/
|
---|
267 | static HRESULT WINAPI
|
---|
268 | IWineGDISurfaceImpl_LoadTexture(IWineD3DSurface *iface, BOOL srgb_mode)
|
---|
269 | {
|
---|
270 | ERR("Unsupported on X11 surfaces\n");
|
---|
271 | return WINED3DERR_INVALIDCALL;
|
---|
272 | }
|
---|
273 |
|
---|
274 | /*****************************************************************************
|
---|
275 | * IWineD3DSurface::SaveSnapshot, GDI version
|
---|
276 | *
|
---|
277 | * This method writes the surface's contents to the in tga format to the
|
---|
278 | * file specified in filename.
|
---|
279 | *
|
---|
280 | * Params:
|
---|
281 | * filename: File to write to
|
---|
282 | *
|
---|
283 | * Returns:
|
---|
284 | * WINED3DERR_INVALIDCALL if the file couldn't be opened
|
---|
285 | * WINED3D_OK on success
|
---|
286 | *
|
---|
287 | *****************************************************************************/
|
---|
288 | static int get_shift(DWORD color_mask) {
|
---|
289 | int shift = 0;
|
---|
290 | while (color_mask > 0xFF) {
|
---|
291 | color_mask >>= 1;
|
---|
292 | shift += 1;
|
---|
293 | }
|
---|
294 | while ((color_mask & 0x80) == 0) {
|
---|
295 | color_mask <<= 1;
|
---|
296 | shift -= 1;
|
---|
297 | }
|
---|
298 | return shift;
|
---|
299 | }
|
---|
300 |
|
---|
301 |
|
---|
302 | static HRESULT WINAPI
|
---|
303 | IWineGDISurfaceImpl_SaveSnapshot(IWineD3DSurface *iface,
|
---|
304 | const char* filename)
|
---|
305 | {
|
---|
306 | FILE* f = NULL;
|
---|
307 | UINT y = 0, x = 0;
|
---|
308 | IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
|
---|
309 | const struct wined3d_format_desc *format_desc = This->resource.format_desc;
|
---|
310 | static char *output = NULL;
|
---|
311 | static UINT size = 0;
|
---|
312 |
|
---|
313 | if (This->pow2Width > size) {
|
---|
314 | output = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, This->pow2Width * 3);
|
---|
315 | size = This->pow2Width;
|
---|
316 | }
|
---|
317 |
|
---|
318 |
|
---|
319 | f = fopen(filename, "w+");
|
---|
320 | if (NULL == f) {
|
---|
321 | ERR("opening of %s failed with\n", filename);
|
---|
322 | return WINED3DERR_INVALIDCALL;
|
---|
323 | }
|
---|
324 | fprintf(f, "P6\n%d %d\n255\n", This->pow2Width, This->pow2Height);
|
---|
325 |
|
---|
326 | if (This->resource.format_desc->format == WINED3DFMT_P8_UINT)
|
---|
327 | {
|
---|
328 | unsigned char table[256][3];
|
---|
329 | int i;
|
---|
330 |
|
---|
331 | if (This->palette == NULL) {
|
---|
332 | fclose(f);
|
---|
333 | return WINED3DERR_INVALIDCALL;
|
---|
334 | }
|
---|
335 | for (i = 0; i < 256; i++) {
|
---|
336 | table[i][0] = This->palette->palents[i].peRed;
|
---|
337 | table[i][1] = This->palette->palents[i].peGreen;
|
---|
338 | table[i][2] = This->palette->palents[i].peBlue;
|
---|
339 | }
|
---|
340 | for (y = 0; y < This->pow2Height; y++) {
|
---|
341 | unsigned char *src = This->resource.allocatedMemory + (y * 1 * IWineD3DSurface_GetPitch(iface));
|
---|
342 | for (x = 0; x < This->pow2Width; x++) {
|
---|
343 | unsigned char color = *src;
|
---|
344 | src += 1;
|
---|
345 |
|
---|
346 | output[3 * x + 0] = table[color][0];
|
---|
347 | output[3 * x + 1] = table[color][1];
|
---|
348 | output[3 * x + 2] = table[color][2];
|
---|
349 | }
|
---|
350 | fwrite(output, 3 * This->pow2Width, 1, f);
|
---|
351 | }
|
---|
352 | } else {
|
---|
353 | int red_shift, green_shift, blue_shift, pix_width, alpha_shift;
|
---|
354 |
|
---|
355 | pix_width = format_desc->byte_count;
|
---|
356 |
|
---|
357 | red_shift = get_shift(format_desc->red_mask);
|
---|
358 | green_shift = get_shift(format_desc->green_mask);
|
---|
359 | blue_shift = get_shift(format_desc->blue_mask);
|
---|
360 | alpha_shift = get_shift(format_desc->alpha_mask);
|
---|
361 |
|
---|
362 | for (y = 0; y < This->pow2Height; y++) {
|
---|
363 | const unsigned char *src = This->resource.allocatedMemory + (y * 1 * IWineD3DSurface_GetPitch(iface));
|
---|
364 | for (x = 0; x < This->pow2Width; x++) {
|
---|
365 | unsigned int color;
|
---|
366 | unsigned int comp;
|
---|
367 | int i;
|
---|
368 |
|
---|
369 | color = 0;
|
---|
370 | for (i = 0; i < pix_width; i++) {
|
---|
371 | color |= src[i] << (8 * i);
|
---|
372 | }
|
---|
373 | src += 1 * pix_width;
|
---|
374 |
|
---|
375 | comp = color & format_desc->red_mask;
|
---|
376 | output[3 * x + 0] = red_shift > 0 ? comp >> red_shift : comp << -red_shift;
|
---|
377 | comp = color & format_desc->green_mask;
|
---|
378 | output[3 * x + 1] = green_shift > 0 ? comp >> green_shift : comp << -green_shift;
|
---|
379 | comp = color & format_desc->alpha_mask;
|
---|
380 | output[3 * x + 2] = alpha_shift > 0 ? comp >> alpha_shift : comp << -alpha_shift;
|
---|
381 | }
|
---|
382 | fwrite(output, 3 * This->pow2Width, 1, f);
|
---|
383 | }
|
---|
384 | }
|
---|
385 | fclose(f);
|
---|
386 | return WINED3D_OK;
|
---|
387 | }
|
---|
388 |
|
---|
389 | static HRESULT WINAPI IWineGDISurfaceImpl_GetDC(IWineD3DSurface *iface, HDC *pHDC) {
|
---|
390 | IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
|
---|
391 | WINED3DLOCKED_RECT lock;
|
---|
392 | HRESULT hr;
|
---|
393 | RGBQUAD col[256];
|
---|
394 |
|
---|
395 | TRACE("(%p)->(%p)\n",This,pHDC);
|
---|
396 |
|
---|
397 | if(!(This->Flags & SFLAG_DIBSECTION))
|
---|
398 | {
|
---|
399 | WARN("DC not supported on this surface\n");
|
---|
400 | return WINED3DERR_INVALIDCALL;
|
---|
401 | }
|
---|
402 |
|
---|
403 | if(This->Flags & SFLAG_USERPTR) {
|
---|
404 | ERR("Not supported on surfaces with an application-provided surfaces\n");
|
---|
405 | return WINEDDERR_NODC;
|
---|
406 | }
|
---|
407 |
|
---|
408 | /* Give more detailed info for ddraw */
|
---|
409 | if (This->Flags & SFLAG_DCINUSE)
|
---|
410 | return WINEDDERR_DCALREADYCREATED;
|
---|
411 |
|
---|
412 | /* Can't GetDC if the surface is locked */
|
---|
413 | if (This->Flags & SFLAG_LOCKED)
|
---|
414 | return WINED3DERR_INVALIDCALL;
|
---|
415 |
|
---|
416 | memset(&lock, 0, sizeof(lock)); /* To be sure */
|
---|
417 |
|
---|
418 | /* Should have a DIB section already */
|
---|
419 |
|
---|
420 | /* Lock the surface */
|
---|
421 | hr = IWineD3DSurface_LockRect(iface,
|
---|
422 | &lock,
|
---|
423 | NULL,
|
---|
424 | 0);
|
---|
425 | if(FAILED(hr)) {
|
---|
426 | ERR("IWineD3DSurface_LockRect failed with hr = %08x\n", hr);
|
---|
427 | /* keep the dib section */
|
---|
428 | return hr;
|
---|
429 | }
|
---|
430 |
|
---|
431 | if (This->resource.format_desc->format == WINED3DFMT_P8_UINT
|
---|
432 | || This->resource.format_desc->format == WINED3DFMT_P8_UINT_A8_UNORM)
|
---|
433 | {
|
---|
434 | unsigned int n;
|
---|
435 | const PALETTEENTRY *pal = NULL;
|
---|
436 |
|
---|
437 | if(This->palette) {
|
---|
438 | pal = This->palette->palents;
|
---|
439 | } else {
|
---|
440 | IWineD3DSurfaceImpl *dds_primary;
|
---|
441 | IWineD3DSwapChainImpl *swapchain;
|
---|
442 | swapchain = (IWineD3DSwapChainImpl *)This->resource.device->swapchains[0];
|
---|
443 | dds_primary = (IWineD3DSurfaceImpl *)swapchain->frontBuffer;
|
---|
444 | if (dds_primary && dds_primary->palette)
|
---|
445 | pal = dds_primary->palette->palents;
|
---|
446 | }
|
---|
447 |
|
---|
448 | if (pal) {
|
---|
449 | for (n=0; n<256; n++) {
|
---|
450 | col[n].rgbRed = pal[n].peRed;
|
---|
451 | col[n].rgbGreen = pal[n].peGreen;
|
---|
452 | col[n].rgbBlue = pal[n].peBlue;
|
---|
453 | col[n].rgbReserved = 0;
|
---|
454 | }
|
---|
455 | SetDIBColorTable(This->hDC, 0, 256, col);
|
---|
456 | }
|
---|
457 | }
|
---|
458 |
|
---|
459 | *pHDC = This->hDC;
|
---|
460 | TRACE("returning %p\n",*pHDC);
|
---|
461 | This->Flags |= SFLAG_DCINUSE;
|
---|
462 |
|
---|
463 | return WINED3D_OK;
|
---|
464 | }
|
---|
465 |
|
---|
466 | static HRESULT WINAPI IWineGDISurfaceImpl_ReleaseDC(IWineD3DSurface *iface, HDC hDC) {
|
---|
467 | IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
|
---|
468 |
|
---|
469 | TRACE("(%p)->(%p)\n",This,hDC);
|
---|
470 |
|
---|
471 | if (!(This->Flags & SFLAG_DCINUSE))
|
---|
472 | return WINEDDERR_NODC;
|
---|
473 |
|
---|
474 | if (This->hDC !=hDC) {
|
---|
475 | WARN("Application tries to release an invalid DC(%p), surface dc is %p\n", hDC, This->hDC);
|
---|
476 | return WINEDDERR_NODC;
|
---|
477 | }
|
---|
478 |
|
---|
479 | /* we locked first, so unlock now */
|
---|
480 | IWineD3DSurface_UnlockRect(iface);
|
---|
481 |
|
---|
482 | This->Flags &= ~SFLAG_DCINUSE;
|
---|
483 |
|
---|
484 | return WINED3D_OK;
|
---|
485 | }
|
---|
486 |
|
---|
487 | static HRESULT WINAPI IWineGDISurfaceImpl_RealizePalette(IWineD3DSurface *iface) {
|
---|
488 | IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *) iface;
|
---|
489 | RGBQUAD col[256];
|
---|
490 | IWineD3DPaletteImpl *pal = This->palette;
|
---|
491 | unsigned int n;
|
---|
492 | IWineD3DSwapChainImpl *swapchain;
|
---|
493 | TRACE("(%p)\n", This);
|
---|
494 |
|
---|
495 | if (!pal) return WINED3D_OK;
|
---|
496 |
|
---|
497 | if(This->Flags & SFLAG_DIBSECTION) {
|
---|
498 | TRACE("(%p): Updating the hdc's palette\n", This);
|
---|
499 | for (n=0; n<256; n++) {
|
---|
500 | col[n].rgbRed = pal->palents[n].peRed;
|
---|
501 | col[n].rgbGreen = pal->palents[n].peGreen;
|
---|
502 | col[n].rgbBlue = pal->palents[n].peBlue;
|
---|
503 | col[n].rgbReserved = 0;
|
---|
504 | }
|
---|
505 | SetDIBColorTable(This->hDC, 0, 256, col);
|
---|
506 | }
|
---|
507 |
|
---|
508 | /* Update the image because of the palette change. Some games like e.g Red Alert
|
---|
509 | call SetEntries a lot to implement fading. */
|
---|
510 | /* Tell the swapchain to update the screen */
|
---|
511 | if (SUCCEEDED(IWineD3DSurface_GetContainer(iface, &IID_IWineD3DSwapChain, (void **)&swapchain)))
|
---|
512 | {
|
---|
513 | if(iface == swapchain->frontBuffer)
|
---|
514 | {
|
---|
515 | x11_copy_to_screen(swapchain, NULL);
|
---|
516 | }
|
---|
517 | IWineD3DSwapChain_Release((IWineD3DSwapChain *) swapchain);
|
---|
518 | }
|
---|
519 |
|
---|
520 | return WINED3D_OK;
|
---|
521 | }
|
---|
522 |
|
---|
523 | /*****************************************************************************
|
---|
524 | * IWineD3DSurface::PrivateSetup, GDI version
|
---|
525 | *
|
---|
526 | * Initializes the GDI surface, aka creates the DIB section we render to
|
---|
527 | * The DIB section creation is done by calling GetDC, which will create the
|
---|
528 | * section and releasing the dc to allow the app to use it. The dib section
|
---|
529 | * will stay until the surface is released
|
---|
530 | *
|
---|
531 | * GDI surfaces do not need to be a power of 2 in size, so the pow2 sizes
|
---|
532 | * are set to the real sizes to save memory. The NONPOW2 flag is unset to
|
---|
533 | * avoid confusion in the shared surface code.
|
---|
534 | *
|
---|
535 | * Returns:
|
---|
536 | * WINED3D_OK on success
|
---|
537 | * The return values of called methods on failure
|
---|
538 | *
|
---|
539 | *****************************************************************************/
|
---|
540 | static HRESULT WINAPI
|
---|
541 | IWineGDISurfaceImpl_PrivateSetup(IWineD3DSurface *iface)
|
---|
542 | {
|
---|
543 | IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *) iface;
|
---|
544 | HRESULT hr;
|
---|
545 |
|
---|
546 | if(This->resource.usage & WINED3DUSAGE_OVERLAY)
|
---|
547 | {
|
---|
548 | ERR("(%p) Overlays not yet supported by GDI surfaces\n", This);
|
---|
549 | return WINED3DERR_INVALIDCALL;
|
---|
550 | }
|
---|
551 |
|
---|
552 | /* Sysmem textures have memory already allocated -
|
---|
553 | * release it, this avoids an unnecessary memcpy
|
---|
554 | */
|
---|
555 | hr = IWineD3DBaseSurfaceImpl_CreateDIBSection(iface);
|
---|
556 | if(SUCCEEDED(hr))
|
---|
557 | {
|
---|
558 | HeapFree(GetProcessHeap(), 0, This->resource.heapMemory);
|
---|
559 | This->resource.heapMemory = NULL;
|
---|
560 | This->resource.allocatedMemory = This->dib.bitmap_data;
|
---|
561 | }
|
---|
562 |
|
---|
563 | /* We don't mind the nonpow2 stuff in GDI */
|
---|
564 | This->pow2Width = This->currentDesc.Width;
|
---|
565 | This->pow2Height = This->currentDesc.Height;
|
---|
566 |
|
---|
567 | return WINED3D_OK;
|
---|
568 | }
|
---|
569 |
|
---|
570 | static HRESULT WINAPI IWineGDISurfaceImpl_SetMem(IWineD3DSurface *iface, void *Mem) {
|
---|
571 | IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *) iface;
|
---|
572 |
|
---|
573 | /* Render targets depend on their hdc, and we can't create an hdc on a user pointer */
|
---|
574 | if(This->resource.usage & WINED3DUSAGE_RENDERTARGET) {
|
---|
575 | ERR("Not supported on render targets\n");
|
---|
576 | return WINED3DERR_INVALIDCALL;
|
---|
577 | }
|
---|
578 |
|
---|
579 | if(This->Flags & (SFLAG_LOCKED | SFLAG_DCINUSE)) {
|
---|
580 | WARN("Surface is locked or the HDC is in use\n");
|
---|
581 | return WINED3DERR_INVALIDCALL;
|
---|
582 | }
|
---|
583 |
|
---|
584 | if(Mem && Mem != This->resource.allocatedMemory) {
|
---|
585 | void *release = NULL;
|
---|
586 |
|
---|
587 | /* Do I have to copy the old surface content? */
|
---|
588 | if(This->Flags & SFLAG_DIBSECTION) {
|
---|
589 | /* Release the DC. No need to hold the critical section for the update
|
---|
590 | * Thread because this thread runs only on front buffers, but this method
|
---|
591 | * fails for render targets in the check above.
|
---|
592 | */
|
---|
593 | SelectObject(This->hDC, This->dib.holdbitmap);
|
---|
594 | DeleteDC(This->hDC);
|
---|
595 | /* Release the DIB section */
|
---|
596 | DeleteObject(This->dib.DIBsection);
|
---|
597 | This->dib.bitmap_data = NULL;
|
---|
598 | This->resource.allocatedMemory = NULL;
|
---|
599 | This->hDC = NULL;
|
---|
600 | This->Flags &= ~SFLAG_DIBSECTION;
|
---|
601 | } else if(!(This->Flags & SFLAG_USERPTR)) {
|
---|
602 | release = This->resource.allocatedMemory;
|
---|
603 | }
|
---|
604 | This->resource.allocatedMemory = Mem;
|
---|
605 | This->Flags |= SFLAG_USERPTR | SFLAG_INSYSMEM;
|
---|
606 |
|
---|
607 | /* Now free the old memory if any */
|
---|
608 | HeapFree(GetProcessHeap(), 0, release);
|
---|
609 | } else if(This->Flags & SFLAG_USERPTR) {
|
---|
610 | /* LockRect and GetDC will re-create the dib section and allocated memory */
|
---|
611 | This->resource.allocatedMemory = NULL;
|
---|
612 | This->Flags &= ~SFLAG_USERPTR;
|
---|
613 | }
|
---|
614 | return WINED3D_OK;
|
---|
615 | }
|
---|
616 |
|
---|
617 | /***************************
|
---|
618 | *
|
---|
619 | ***************************/
|
---|
620 | static void WINAPI IWineGDISurfaceImpl_ModifyLocation(IWineD3DSurface *iface, DWORD flag, BOOL persistent) {
|
---|
621 | TRACE("(%p)->(%s, %s)\n", iface,
|
---|
622 | flag == SFLAG_INSYSMEM ? "SFLAG_INSYSMEM" : flag == SFLAG_INDRAWABLE ? "SFLAG_INDRAWABLE" : "SFLAG_INTEXTURE",
|
---|
623 | persistent ? "TRUE" : "FALSE");
|
---|
624 | /* GDI surfaces can be in system memory only */
|
---|
625 | if(flag != SFLAG_INSYSMEM) {
|
---|
626 | ERR("GDI Surface requested in gl %s memory\n", flag == SFLAG_INDRAWABLE ? "drawable" : "texture");
|
---|
627 | }
|
---|
628 | }
|
---|
629 |
|
---|
630 | static HRESULT WINAPI IWineGDISurfaceImpl_LoadLocation(IWineD3DSurface *iface, DWORD flag, const RECT *rect) {
|
---|
631 | if(flag != SFLAG_INSYSMEM) {
|
---|
632 | ERR("GDI Surface requested to be copied to gl %s\n", flag == SFLAG_INTEXTURE ? "texture" : "drawable");
|
---|
633 | } else {
|
---|
634 | TRACE("Surface requested in surface memory\n");
|
---|
635 | }
|
---|
636 | return WINED3D_OK;
|
---|
637 | }
|
---|
638 |
|
---|
639 | static WINED3DSURFTYPE WINAPI IWineGDISurfaceImpl_GetImplType(IWineD3DSurface *iface) {
|
---|
640 | return SURFACE_GDI;
|
---|
641 | }
|
---|
642 |
|
---|
643 | static HRESULT WINAPI IWineGDISurfaceImpl_DrawOverlay(IWineD3DSurface *iface) {
|
---|
644 | FIXME("GDI surfaces can't draw overlays yet\n");
|
---|
645 | return E_FAIL;
|
---|
646 | }
|
---|
647 |
|
---|
648 | /* FIXME: This vtable should not use any IWineD3DSurface* implementation functions,
|
---|
649 | * only IWineD3DBaseSurface and IWineGDISurface ones.
|
---|
650 | */
|
---|
651 | const IWineD3DSurfaceVtbl IWineGDISurface_Vtbl =
|
---|
652 | {
|
---|
653 | /* IUnknown */
|
---|
654 | IWineD3DBaseSurfaceImpl_QueryInterface,
|
---|
655 | IWineD3DBaseSurfaceImpl_AddRef,
|
---|
656 | IWineGDISurfaceImpl_Release,
|
---|
657 | /* IWineD3DResource */
|
---|
658 | IWineD3DBaseSurfaceImpl_GetParent,
|
---|
659 | IWineD3DBaseSurfaceImpl_SetPrivateData,
|
---|
660 | IWineD3DBaseSurfaceImpl_GetPrivateData,
|
---|
661 | IWineD3DBaseSurfaceImpl_FreePrivateData,
|
---|
662 | IWineD3DBaseSurfaceImpl_SetPriority,
|
---|
663 | IWineD3DBaseSurfaceImpl_GetPriority,
|
---|
664 | IWineGDISurfaceImpl_PreLoad,
|
---|
665 | IWineGDISurfaceImpl_UnLoad,
|
---|
666 | IWineD3DBaseSurfaceImpl_GetType,
|
---|
667 | /* IWineD3DSurface */
|
---|
668 | IWineD3DBaseSurfaceImpl_GetContainer,
|
---|
669 | IWineD3DBaseSurfaceImpl_GetDesc,
|
---|
670 | IWineGDISurfaceImpl_LockRect,
|
---|
671 | IWineGDISurfaceImpl_UnlockRect,
|
---|
672 | IWineGDISurfaceImpl_GetDC,
|
---|
673 | IWineGDISurfaceImpl_ReleaseDC,
|
---|
674 | IWineGDISurfaceImpl_Flip,
|
---|
675 | IWineD3DBaseSurfaceImpl_Blt,
|
---|
676 | IWineD3DBaseSurfaceImpl_GetBltStatus,
|
---|
677 | IWineD3DBaseSurfaceImpl_GetFlipStatus,
|
---|
678 | IWineD3DBaseSurfaceImpl_IsLost,
|
---|
679 | IWineD3DBaseSurfaceImpl_Restore,
|
---|
680 | IWineD3DBaseSurfaceImpl_BltFast,
|
---|
681 | IWineD3DBaseSurfaceImpl_GetPalette,
|
---|
682 | IWineD3DBaseSurfaceImpl_SetPalette,
|
---|
683 | IWineGDISurfaceImpl_RealizePalette,
|
---|
684 | IWineD3DBaseSurfaceImpl_SetColorKey,
|
---|
685 | IWineD3DBaseSurfaceImpl_GetPitch,
|
---|
686 | IWineGDISurfaceImpl_SetMem,
|
---|
687 | IWineD3DBaseSurfaceImpl_SetOverlayPosition,
|
---|
688 | IWineD3DBaseSurfaceImpl_GetOverlayPosition,
|
---|
689 | IWineD3DBaseSurfaceImpl_UpdateOverlayZOrder,
|
---|
690 | IWineD3DBaseSurfaceImpl_UpdateOverlay,
|
---|
691 | IWineD3DBaseSurfaceImpl_SetClipper,
|
---|
692 | IWineD3DBaseSurfaceImpl_GetClipper,
|
---|
693 | /* Internal use: */
|
---|
694 | IWineGDISurfaceImpl_LoadTexture,
|
---|
695 | IWineD3DBaseSurfaceImpl_BindTexture,
|
---|
696 | IWineGDISurfaceImpl_SaveSnapshot,
|
---|
697 | IWineD3DBaseSurfaceImpl_SetContainer,
|
---|
698 | IWineD3DBaseSurfaceImpl_GetData,
|
---|
699 | IWineD3DBaseSurfaceImpl_SetFormat,
|
---|
700 | IWineGDISurfaceImpl_PrivateSetup,
|
---|
701 | IWineGDISurfaceImpl_ModifyLocation,
|
---|
702 | IWineGDISurfaceImpl_LoadLocation,
|
---|
703 | IWineGDISurfaceImpl_GetImplType,
|
---|
704 | IWineGDISurfaceImpl_DrawOverlay
|
---|
705 | };
|
---|