push ad05fa8ea86b4a1581adad6c24ad723042d385d2
[wine/hacks.git] / dlls / wined3d / surface_gdi.c
bloba5ca3db6ff6f2e1bb68e256cd6951c49ea9d916a
1 /*
2 * 2D Surface implementation without OpenGL
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
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.
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.
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
28 #include "config.h"
29 #include "wine/port.h"
30 #include "wined3d_private.h"
32 #include <assert.h>
33 #include <stdio.h>
35 /* Use the d3d_surface debug channel to have one channel for all surfaces */
36 WINE_DEFAULT_DEBUG_CHANNEL(d3d_surface);
37 WINE_DECLARE_DEBUG_CHANNEL(fps);
39 /*****************************************************************************
40 * x11_copy_to_screen
42 * Helper function that blts the front buffer contents to the target window
44 * Params:
45 * This: Surface to copy from
46 * rc: Rectangle to copy
48 *****************************************************************************/
49 static void
50 x11_copy_to_screen(IWineD3DSurfaceImpl *This,
51 LPRECT rc)
53 if(This->resource.usage & WINED3DUSAGE_RENDERTARGET)
55 POINT offset = {0,0};
56 HWND hDisplayWnd;
57 HDC hDisplayDC;
58 HDC hSurfaceDC = 0;
59 RECT drawrect;
60 TRACE("(%p)->(%p): Copying to screen\n", This, rc);
62 hSurfaceDC = This->hDC;
64 hDisplayWnd = This->resource.wineD3DDevice->ddraw_window;
65 hDisplayDC = GetDCEx(hDisplayWnd, 0, DCX_CLIPSIBLINGS|DCX_CACHE);
66 if(rc)
68 TRACE(" copying rect (%d,%d)->(%d,%d), offset (%d,%d)\n",
69 rc->left, rc->top, rc->right, rc->bottom, offset.x, offset.y);
72 /* Front buffer coordinates are screen coordinates. Map them to the destination
73 * window if not fullscreened
75 if(!This->resource.wineD3DDevice->ddraw_fullscreen) {
76 ClientToScreen(hDisplayWnd, &offset);
78 #if 0
79 /* FIXME: this doesn't work... if users really want to run
80 * X in 8bpp, then we need to call directly into display.drv
81 * (or Wine's equivalent), and force a private colormap
82 * without default entries. */
83 if (This->palette) {
84 SelectPalette(hDisplayDC, This->palette->hpal, FALSE);
85 RealizePalette(hDisplayDC); /* sends messages => deadlocks */
87 #endif
88 drawrect.left = 0;
89 drawrect.right = This->currentDesc.Width;
90 drawrect.top = 0;
91 drawrect.bottom = This->currentDesc.Height;
93 #if 0
94 /* TODO: Support clippers */
95 if (This->clipper)
97 RECT xrc;
98 HWND hwnd = ((IWineD3DClipperImpl *) This->clipper)->hWnd;
99 if (hwnd && GetClientRect(hwnd,&xrc))
101 OffsetRect(&xrc,offset.x,offset.y);
102 IntersectRect(&drawrect,&drawrect,&xrc);
105 #endif
106 if (rc)
108 IntersectRect(&drawrect,&drawrect,rc);
110 else
112 /* Only use this if the caller did not pass a rectangle, since
113 * due to double locking this could be the wrong one ...
115 if (This->lockedRect.left != This->lockedRect.right)
117 IntersectRect(&drawrect,&drawrect,&This->lockedRect);
121 BitBlt(hDisplayDC,
122 drawrect.left-offset.x, drawrect.top-offset.y,
123 drawrect.right-drawrect.left, drawrect.bottom-drawrect.top,
124 hSurfaceDC,
125 drawrect.left, drawrect.top,
126 SRCCOPY);
127 ReleaseDC(hDisplayWnd, hDisplayDC);
131 /*****************************************************************************
132 * IWineD3DSurface::Release, GDI version
134 * In general a normal COM Release method, but the GDI version doesn't have
135 * to destroy all the GL things.
137 *****************************************************************************/
138 ULONG WINAPI IWineGDISurfaceImpl_Release(IWineD3DSurface *iface) {
139 IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
140 ULONG ref = InterlockedDecrement(&This->resource.ref);
141 TRACE("(%p) : Releasing from %d\n", This, ref + 1);
142 if (ref == 0) {
143 IWineD3DDeviceImpl *device = (IWineD3DDeviceImpl *) This->resource.wineD3DDevice;
144 TRACE("(%p) : cleaning up\n", This);
146 if(This->Flags & SFLAG_DIBSECTION) {
147 /* Release the DC */
148 SelectObject(This->hDC, This->dib.holdbitmap);
149 DeleteDC(This->hDC);
150 /* Release the DIB section */
151 DeleteObject(This->dib.DIBsection);
152 This->dib.bitmap_data = NULL;
153 This->resource.allocatedMemory = NULL;
155 if(This->Flags & SFLAG_USERPTR) IWineD3DSurface_SetMem(iface, NULL);
157 HeapFree(GetProcessHeap(), 0, This->palette9);
159 IWineD3DResourceImpl_CleanUp((IWineD3DResource *)iface);
160 if(iface == device->ddraw_primary)
161 device->ddraw_primary = NULL;
163 TRACE("(%p) Released\n", This);
164 HeapFree(GetProcessHeap(), 0, This);
167 return ref;
170 /*****************************************************************************
171 * IWineD3DSurface::PreLoad, GDI version
173 * This call is unsupported on GDI surfaces, if it's called something went
174 * wrong in the parent library. Write an informative warning
176 *****************************************************************************/
177 static void WINAPI
178 IWineGDISurfaceImpl_PreLoad(IWineD3DSurface *iface)
180 ERR("(%p): PreLoad is not supported on X11 surfaces!\n", iface);
181 ERR("(%p): Most likely the parent library did something wrong.\n", iface);
182 ERR("(%p): Please report to wine-devel\n", iface);
185 /*****************************************************************************
186 * IWineD3DSurface::LockRect, GDI version
188 * Locks the surface and returns a pointer to the surface memory
190 * Params:
191 * pLockedRect: Address to return the locking info at
192 * pRect: Rectangle to lock
193 * Flags: Some flags
195 * Returns:
196 * WINED3D_OK on success
197 * WINED3DERR_INVALIDCALL on errors
199 *****************************************************************************/
200 static HRESULT WINAPI
201 IWineGDISurfaceImpl_LockRect(IWineD3DSurface *iface,
202 WINED3DLOCKED_RECT* pLockedRect,
203 CONST RECT* pRect,
204 DWORD Flags)
206 IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
208 if(!This->resource.allocatedMemory) {
209 /* This happens on gdi surfaces if the application set a user pointer and resets it.
210 * Recreate the DIB section
212 IWineD3DBaseSurfaceImpl_CreateDIBSection(iface);
213 This->resource.allocatedMemory = This->dib.bitmap_data;
216 return IWineD3DBaseSurfaceImpl_LockRect(iface, pLockedRect, pRect, Flags);
219 /*****************************************************************************
220 * IWineD3DSurface::UnlockRect, GDI version
222 * Unlocks a surface. This implementation doesn't do much, except updating
223 * the window if the front buffer is unlocked
225 * Returns:
226 * WINED3D_OK on success
227 * WINED3DERR_INVALIDCALL on failure
229 *****************************************************************************/
230 static HRESULT WINAPI
231 IWineGDISurfaceImpl_UnlockRect(IWineD3DSurface *iface)
233 IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
234 IWineD3DDeviceImpl *dev = (IWineD3DDeviceImpl *) This->resource.wineD3DDevice;
235 TRACE("(%p)\n", This);
237 if (!(This->Flags & SFLAG_LOCKED))
239 WARN("trying to Unlock an unlocked surf@%p\n", This);
240 return WINED3DERR_INVALIDCALL;
243 /* Can be useful for debugging */
244 #if 0
246 static unsigned int gen = 0;
247 char buffer[4096];
248 ++gen;
249 if ((gen % 10) == 0) {
250 snprintf(buffer, sizeof(buffer), "/tmp/surface%p_type%u_level%u_%u.ppm", This, This->glDescription.target, This->glDescription.level, gen);
251 IWineD3DSurfaceImpl_SaveSnapshot(iface, buffer);
254 * debugging crash code
255 if (gen == 250) {
256 void** test = NULL;
257 *test = 0;
261 #endif
263 /* Update the screen */
264 if(This == (IWineD3DSurfaceImpl *) dev->ddraw_primary)
266 x11_copy_to_screen(This, &This->lockedRect);
269 This->Flags &= ~SFLAG_LOCKED;
270 memset(&This->lockedRect, 0, sizeof(RECT));
271 return WINED3D_OK;
274 /*****************************************************************************
275 * IWineD3DSurface::Flip, GDI version
277 * Flips 2 flipping enabled surfaces. Determining the 2 targets is done by
278 * the parent library. This implementation changes the data pointers of the
279 * surfaces and copies the new front buffer content to the screen
281 * Params:
282 * override: Flipping target(e.g. back buffer)
284 * Returns:
285 * WINED3D_OK on success
287 *****************************************************************************/
288 static HRESULT WINAPI
289 IWineGDISurfaceImpl_Flip(IWineD3DSurface *iface,
290 IWineD3DSurface *override,
291 DWORD Flags)
293 IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *) iface;
294 IWineD3DSurfaceImpl *Target = (IWineD3DSurfaceImpl *) override;
295 TRACE("(%p)->(%p,%x)\n", This, override, Flags);
297 TRACE("(%p) Flipping to surface %p\n", This, Target);
299 if(Target == NULL)
301 ERR("(%p): Can't flip without a target\n", This);
302 return WINED3DERR_INVALIDCALL;
305 /* Flip the DC */
307 HDC tmp;
308 tmp = This->hDC;
309 This->hDC = Target->hDC;
310 Target->hDC = tmp;
313 /* Flip the DIBsection */
315 HBITMAP tmp;
316 tmp = This->dib.DIBsection;
317 This->dib.DIBsection = Target->dib.DIBsection;
318 Target->dib.DIBsection = tmp;
321 /* Flip the surface data */
323 void* tmp;
325 tmp = This->dib.bitmap_data;
326 This->dib.bitmap_data = Target->dib.bitmap_data;
327 Target->dib.bitmap_data = tmp;
329 tmp = This->resource.allocatedMemory;
330 This->resource.allocatedMemory = Target->resource.allocatedMemory;
331 Target->resource.allocatedMemory = tmp;
333 if(This->resource.heapMemory) {
334 ERR("GDI Surface %p has heap memory allocated\n", This);
336 if(Target->resource.heapMemory) {
337 ERR("GDI Surface %p has heap memory allocated\n", Target);
341 /* client_memory should not be different, but just in case */
343 BOOL tmp;
344 tmp = This->dib.client_memory;
345 This->dib.client_memory = Target->dib.client_memory;
346 Target->dib.client_memory = tmp;
349 /* Useful for debugging */
350 #if 0
352 static unsigned int gen = 0;
353 char buffer[4096];
354 ++gen;
355 if ((gen % 10) == 0) {
356 snprintf(buffer, sizeof(buffer), "/tmp/surface%p_type%u_level%u_%u.ppm", This, This->glDescription.target, This->glDescription.level, gen);
357 IWineD3DSurfaceImpl_SaveSnapshot(iface, buffer);
360 * debugging crash code
361 if (gen == 250) {
362 void** test = NULL;
363 *test = 0;
367 #endif
369 /* Update the screen */
370 x11_copy_to_screen(This, NULL);
372 /* FPS support */
373 if (TRACE_ON(fps))
375 static long prev_time, frames;
377 DWORD time = GetTickCount();
378 frames++;
379 /* every 1.5 seconds */
380 if (time - prev_time > 1500) {
381 TRACE_(fps)("@ approx %.2ffps\n", 1000.0*frames/(time - prev_time));
382 prev_time = time;
383 frames = 0;
387 return WINED3D_OK;
390 /*****************************************************************************
391 * IWineD3DSurface::LoadTexture, GDI version
393 * This is mutually unsupported by GDI surfaces
395 * Returns:
396 * D3DERR_INVALIDCALL
398 *****************************************************************************/
399 HRESULT WINAPI
400 IWineGDISurfaceImpl_LoadTexture(IWineD3DSurface *iface, BOOL srgb_mode)
402 ERR("Unsupported on X11 surfaces\n");
403 return WINED3DERR_INVALIDCALL;
406 /*****************************************************************************
407 * IWineD3DSurface::SaveSnapshot, GDI version
409 * This method writes the surface's contents to the in tga format to the
410 * file specified in filename.
412 * Params:
413 * filename: File to write to
415 * Returns:
416 * WINED3DERR_INVALIDCALL if the file couldn't be opened
417 * WINED3D_OK on success
419 *****************************************************************************/
420 static int get_shift(DWORD color_mask) {
421 int shift = 0;
422 while (color_mask > 0xFF) {
423 color_mask >>= 1;
424 shift += 1;
426 while ((color_mask & 0x80) == 0) {
427 color_mask <<= 1;
428 shift -= 1;
430 return shift;
434 HRESULT WINAPI
435 IWineGDISurfaceImpl_SaveSnapshot(IWineD3DSurface *iface,
436 const char* filename)
438 FILE* f = NULL;
439 UINT y = 0, x = 0;
440 IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
441 static char *output = NULL;
442 static int size = 0;
443 const StaticPixelFormatDesc *formatEntry = getFormatDescEntry(This->resource.format, NULL, NULL);
445 if (This->pow2Width > size) {
446 output = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, This->pow2Width * 3);
447 size = This->pow2Width;
451 f = fopen(filename, "w+");
452 if (NULL == f) {
453 ERR("opening of %s failed with\n", filename);
454 return WINED3DERR_INVALIDCALL;
456 fprintf(f, "P6\n%d %d\n255\n", This->pow2Width, This->pow2Height);
458 if (This->resource.format == WINED3DFMT_P8) {
459 unsigned char table[256][3];
460 int i;
462 if (This->palette == NULL) {
463 fclose(f);
464 return WINED3DERR_INVALIDCALL;
466 for (i = 0; i < 256; i++) {
467 table[i][0] = This->palette->palents[i].peRed;
468 table[i][1] = This->palette->palents[i].peGreen;
469 table[i][2] = This->palette->palents[i].peBlue;
471 for (y = 0; y < This->pow2Height; y++) {
472 unsigned char *src = (unsigned char *) This->resource.allocatedMemory + (y * 1 * IWineD3DSurface_GetPitch(iface));
473 for (x = 0; x < This->pow2Width; x++) {
474 unsigned char color = *src;
475 src += 1;
477 output[3 * x + 0] = table[color][0];
478 output[3 * x + 1] = table[color][1];
479 output[3 * x + 2] = table[color][2];
481 fwrite(output, 3 * This->pow2Width, 1, f);
483 } else {
484 int red_shift, green_shift, blue_shift, pix_width;
486 pix_width = This->bytesPerPixel;
488 red_shift = get_shift(formatEntry->redMask);
489 green_shift = get_shift(formatEntry->greenMask);
490 blue_shift = get_shift(formatEntry->blueMask);
492 for (y = 0; y < This->pow2Height; y++) {
493 unsigned char *src = (unsigned char *) This->resource.allocatedMemory + (y * 1 * IWineD3DSurface_GetPitch(iface));
494 for (x = 0; x < This->pow2Width; x++) {
495 unsigned int color;
496 unsigned int comp;
497 int i;
499 color = 0;
500 for (i = 0; i < pix_width; i++) {
501 color |= src[i] << (8 * i);
503 src += 1 * pix_width;
505 comp = color & formatEntry->redMask;
506 output[3 * x + 0] = red_shift > 0 ? comp >> red_shift : comp << -red_shift;
507 comp = color & formatEntry->greenMask;
508 output[3 * x + 1] = green_shift > 0 ? comp >> green_shift : comp << -green_shift;
509 comp = color & formatEntry->blueMask;
510 output[3 * x + 2] = blue_shift > 0 ? comp >> blue_shift : comp << -blue_shift;
512 fwrite(output, 3 * This->pow2Width, 1, f);
515 fclose(f);
516 return WINED3D_OK;
519 HRESULT WINAPI IWineGDISurfaceImpl_GetDC(IWineD3DSurface *iface, HDC *pHDC) {
520 IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
521 WINED3DLOCKED_RECT lock;
522 HRESULT hr;
523 RGBQUAD col[256];
525 TRACE("(%p)->(%p)\n",This,pHDC);
527 if(This->Flags & SFLAG_USERPTR) {
528 ERR("Not supported on surfaces with an application-provided surfaces\n");
529 return WINEDDERR_NODC;
532 /* Give more detailed info for ddraw */
533 if (This->Flags & SFLAG_DCINUSE)
534 return WINEDDERR_DCALREADYCREATED;
536 /* Can't GetDC if the surface is locked */
537 if (This->Flags & SFLAG_LOCKED)
538 return WINED3DERR_INVALIDCALL;
540 memset(&lock, 0, sizeof(lock)); /* To be sure */
542 /* Should have a DIB section already */
544 /* Lock the surface */
545 hr = IWineD3DSurface_LockRect(iface,
546 &lock,
547 NULL,
549 if(FAILED(hr)) {
550 ERR("IWineD3DSurface_LockRect failed with hr = %08x\n", hr);
551 /* keep the dib section */
552 return hr;
555 if(This->resource.format == WINED3DFMT_P8 ||
556 This->resource.format == WINED3DFMT_A8P8) {
557 unsigned int n;
558 if(This->palette) {
559 PALETTEENTRY ent[256];
561 GetPaletteEntries(This->palette->hpal, 0, 256, ent);
562 for (n=0; n<256; n++) {
563 col[n].rgbRed = ent[n].peRed;
564 col[n].rgbGreen = ent[n].peGreen;
565 col[n].rgbBlue = ent[n].peBlue;
566 col[n].rgbReserved = 0;
568 } else {
569 IWineD3DDeviceImpl *device = This->resource.wineD3DDevice;
571 for (n=0; n<256; n++) {
572 col[n].rgbRed = device->palettes[device->currentPalette][n].peRed;
573 col[n].rgbGreen = device->palettes[device->currentPalette][n].peGreen;
574 col[n].rgbBlue = device->palettes[device->currentPalette][n].peBlue;
575 col[n].rgbReserved = 0;
579 SetDIBColorTable(This->hDC, 0, 256, col);
582 *pHDC = This->hDC;
583 TRACE("returning %p\n",*pHDC);
584 This->Flags |= SFLAG_DCINUSE;
586 return WINED3D_OK;
589 HRESULT WINAPI IWineGDISurfaceImpl_ReleaseDC(IWineD3DSurface *iface, HDC hDC) {
590 IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
592 TRACE("(%p)->(%p)\n",This,hDC);
594 if (!(This->Flags & SFLAG_DCINUSE))
595 return WINED3DERR_INVALIDCALL;
597 if (This->hDC !=hDC) {
598 WARN("Application tries to release an invalid DC(%p), surface dc is %p\n", hDC, This->hDC);
599 return WINED3DERR_INVALIDCALL;
602 /* we locked first, so unlock now */
603 IWineD3DSurface_UnlockRect(iface);
605 This->Flags &= ~SFLAG_DCINUSE;
607 return WINED3D_OK;
610 /*****************************************************************************
611 * IWineD3DSurface::PrivateSetup, GDI version
613 * Initializes the GDI surface, aka creates the DIB section we render to
614 * The DIB section creation is done by calling GetDC, which will create the
615 * section and releasing the dc to allow the app to use it. The dib section
616 * will stay until the surface is released
618 * GDI surfaces do not need to be a power of 2 in size, so the pow2 sizes
619 * are set to the real sizes to save memory. The NONPOW2 flag is unset to
620 * avoid confusion in the shared surface code.
622 * Returns:
623 * WINED3D_OK on success
624 * The return values of called methods on failure
626 *****************************************************************************/
627 HRESULT WINAPI
628 IWineGDISurfaceImpl_PrivateSetup(IWineD3DSurface *iface)
630 IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *) iface;
632 if(This->resource.usage & WINED3DUSAGE_OVERLAY)
634 ERR("(%p) Overlays not yet supported by GDI surfaces\n", This);
635 return WINED3DERR_INVALIDCALL;
637 /* Sysmem textures have memory already allocated -
638 * release it, this avoids an unnecessary memcpy
640 HeapFree(GetProcessHeap(), 0, This->resource.heapMemory);
641 This->resource.allocatedMemory = NULL;
642 This->resource.heapMemory = NULL;
644 /* We don't mind the nonpow2 stuff in GDI */
645 This->pow2Width = This->currentDesc.Width;
646 This->pow2Height = This->currentDesc.Height;
648 IWineD3DBaseSurfaceImpl_CreateDIBSection(iface);
649 This->resource.allocatedMemory = This->dib.bitmap_data;
651 return WINED3D_OK;
654 void WINAPI IWineGDISurfaceImpl_SetGlTextureDesc(IWineD3DSurface *iface, UINT textureName, int target) {
655 IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
657 /* Ignore 0 textureName and target. D3D textures can be created with gdi surfaces as plain
658 * containers, but they're useless until the app creates a d3d device from a d3d point of
659 * view, it's not an implementation limitation. This avoids false warnings when the texture
660 * is destroyed and sets the description back to 0/0
662 if(textureName != 0 || target != 0) {
663 FIXME("(%p) : Should not be called on a GDI surface. textureName %u, target %i\n", This, textureName, target);
664 DebugBreak();
668 void WINAPI IWineGDISurfaceImpl_GetGlDesc(IWineD3DSurface *iface, glDescriptor **glDescription) {
669 IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
670 FIXME("(%p) : Should not be called on a GDI surface\n", This);
671 *glDescription = NULL;
674 HRESULT WINAPI IWineGDISurfaceImpl_AddDirtyRect(IWineD3DSurface *iface, CONST RECT* pDirtyRect) {
675 /* GDI surface data can only be in one location, the system memory dib section. So they are
676 * always clean by definition.
678 TRACE("No dirtification in GDI surfaces\n");
679 return WINED3D_OK;
682 HRESULT WINAPI IWineGDISurfaceImpl_SetMem(IWineD3DSurface *iface, void *Mem) {
683 IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *) iface;
685 /* Render targets depend on their hdc, and we can't create an hdc on a user pointer */
686 if(This->resource.usage & WINED3DUSAGE_RENDERTARGET) {
687 ERR("Not supported on render targets\n");
688 return WINED3DERR_INVALIDCALL;
691 if(This->Flags & (SFLAG_LOCKED | SFLAG_DCINUSE)) {
692 WARN("Surface is locked or the HDC is in use\n");
693 return WINED3DERR_INVALIDCALL;
696 if(Mem && Mem != This->resource.allocatedMemory) {
697 void *release = NULL;
699 /* Do I have to copy the old surface content? */
700 if(This->Flags & SFLAG_DIBSECTION) {
701 /* Release the DC. No need to hold the critical section for the update
702 * Thread because this thread runs only on front buffers, but this method
703 * fails for render targets in the check above.
705 SelectObject(This->hDC, This->dib.holdbitmap);
706 DeleteDC(This->hDC);
707 /* Release the DIB section */
708 DeleteObject(This->dib.DIBsection);
709 This->dib.bitmap_data = NULL;
710 This->resource.allocatedMemory = NULL;
711 This->hDC = NULL;
712 This->Flags &= ~SFLAG_DIBSECTION;
713 } else if(!(This->Flags & SFLAG_USERPTR)) {
714 release = This->resource.allocatedMemory;
716 This->resource.allocatedMemory = Mem;
717 This->Flags |= SFLAG_USERPTR | SFLAG_INSYSMEM;
719 /* Now free the old memory if any */
720 HeapFree(GetProcessHeap(), 0, release);
721 } else if(This->Flags & SFLAG_USERPTR) {
722 /* Lockrect and GetDC will re-create the dib section and allocated memory */
723 This->resource.allocatedMemory = NULL;
724 This->Flags &= ~SFLAG_USERPTR;
726 return WINED3D_OK;
729 /***************************
731 ***************************/
732 static void WINAPI IWineGDISurfaceImpl_ModifyLocation(IWineD3DSurface *iface, DWORD flag, BOOL persistent) {
733 TRACE("(%p)->(%s, %s)\n", iface,
734 flag == SFLAG_INSYSMEM ? "SFLAG_INSYSMEM" : flag == SFLAG_INDRAWABLE ? "SFLAG_INDRAWABLE" : "SFLAG_INTEXTURE",
735 persistent ? "TRUE" : "FALSE");
736 /* GDI surfaces can be in system memory only */
737 if(flag != SFLAG_INSYSMEM) {
738 ERR("GDI Surface requested in gl %s memory\n", flag == SFLAG_INDRAWABLE ? "drawable" : "texture");
742 static HRESULT WINAPI IWineGDISurfaceImpl_LoadLocation(IWineD3DSurface *iface, DWORD flag, const RECT *rect) {
743 if(flag != SFLAG_INSYSMEM) {
744 ERR("GDI Surface requested to be copied to gl %s\n", flag == SFLAG_INTEXTURE ? "texture" : "drawable");
745 } else {
746 TRACE("Surface requested in surface memory\n");
748 return WINED3D_OK;
751 /* FIXME: This vtable should not use any IWineD3DSurface* implementation functions,
752 * only IWineD3DBaseSurface and IWineGDISurface ones.
754 const IWineD3DSurfaceVtbl IWineGDISurface_Vtbl =
756 /* IUnknown */
757 IWineD3DBaseSurfaceImpl_QueryInterface,
758 IWineD3DBaseSurfaceImpl_AddRef,
759 IWineGDISurfaceImpl_Release,
760 /* IWineD3DResource */
761 IWineD3DBaseSurfaceImpl_GetParent,
762 IWineD3DBaseSurfaceImpl_GetDevice,
763 IWineD3DBaseSurfaceImpl_SetPrivateData,
764 IWineD3DBaseSurfaceImpl_GetPrivateData,
765 IWineD3DBaseSurfaceImpl_FreePrivateData,
766 IWineD3DBaseSurfaceImpl_SetPriority,
767 IWineD3DBaseSurfaceImpl_GetPriority,
768 IWineGDISurfaceImpl_PreLoad,
769 IWineD3DBaseSurfaceImpl_GetType,
770 /* IWineD3DSurface */
771 IWineD3DBaseSurfaceImpl_GetContainer,
772 IWineD3DBaseSurfaceImpl_GetDesc,
773 IWineGDISurfaceImpl_LockRect,
774 IWineGDISurfaceImpl_UnlockRect,
775 IWineGDISurfaceImpl_GetDC,
776 IWineGDISurfaceImpl_ReleaseDC,
777 IWineGDISurfaceImpl_Flip,
778 IWineD3DBaseSurfaceImpl_Blt,
779 IWineD3DBaseSurfaceImpl_GetBltStatus,
780 IWineD3DBaseSurfaceImpl_GetFlipStatus,
781 IWineD3DBaseSurfaceImpl_IsLost,
782 IWineD3DBaseSurfaceImpl_Restore,
783 IWineD3DBaseSurfaceImpl_BltFast,
784 IWineD3DBaseSurfaceImpl_GetPalette,
785 IWineD3DBaseSurfaceImpl_SetPalette,
786 IWineD3DBaseSurfaceImpl_RealizePalette,
787 IWineD3DBaseSurfaceImpl_SetColorKey,
788 IWineD3DBaseSurfaceImpl_GetPitch,
789 IWineGDISurfaceImpl_SetMem,
790 IWineD3DBaseSurfaceImpl_SetOverlayPosition,
791 IWineD3DBaseSurfaceImpl_GetOverlayPosition,
792 IWineD3DBaseSurfaceImpl_UpdateOverlayZOrder,
793 IWineD3DBaseSurfaceImpl_UpdateOverlay,
794 IWineD3DBaseSurfaceImpl_SetClipper,
795 IWineD3DBaseSurfaceImpl_GetClipper,
796 /* Internal use: */
797 IWineGDISurfaceImpl_AddDirtyRect,
798 IWineGDISurfaceImpl_LoadTexture,
799 IWineGDISurfaceImpl_SaveSnapshot,
800 IWineD3DBaseSurfaceImpl_SetContainer,
801 IWineGDISurfaceImpl_SetGlTextureDesc,
802 IWineGDISurfaceImpl_GetGlDesc,
803 IWineD3DSurfaceImpl_GetData,
804 IWineD3DBaseSurfaceImpl_SetFormat,
805 IWineGDISurfaceImpl_PrivateSetup,
806 IWineGDISurfaceImpl_ModifyLocation,
807 IWineGDISurfaceImpl_LoadLocation