1 /* DIBSection DirectDrawSurface driver
3 * Copyright 1997-2000 Marcus Meissner
4 * Copyright 1998-2000 Lionel Ulmer
5 * Copyright 2000-2001 TransGaming Technologies Inc.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #define NONAMELESSUNION
29 #define NONAMELESSSTRUCT
31 #include "wine/debug.h"
32 #include "ddraw_private.h"
33 #include "d3d_private.h"
34 #include "dsurface/main.h"
35 #include "dsurface/dib.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(ddraw
);
40 extern HBITMAP
DIB_CreateDIBSection( HDC hdc
, const BITMAPINFO
*bmi
, UINT usage
, VOID
**bits
,
41 HANDLE section
, DWORD offset
, DWORD ovr_pitch
);
43 static IDirectDrawSurface7Vtbl DIB_IDirectDrawSurface7_VTable
;
45 /* Return the width of a DIB bitmap in bytes. DIB bitmap data is 32-bit aligned. */
46 inline static int get_dib_width_bytes( int width
, int depth
)
52 case 1: words
= (width
+ 31) / 32; break;
53 case 4: words
= (width
+ 7) / 8; break;
54 case 8: words
= (width
+ 3) / 4; break;
56 case 16: words
= (width
+ 1) / 2; break;
57 case 24: words
= (width
* 3 + 3)/4; break;
59 WARN("(%d): Unsupported depth\n", depth
);
61 case 32: words
= width
; break;
67 static HRESULT
create_dib(IDirectDrawSurfaceImpl
* This
)
72 DIB_DirectDrawSurfaceImpl
* priv
= This
->private;
74 assert(This
->surface_desc
.lpSurface
!= NULL
);
76 switch (This
->surface_desc
.u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
)
80 /* Allocate extra space to store the RGB bit masks. */
81 b_info
= (BITMAPINFO
*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
82 sizeof(BITMAPINFOHEADER
)
87 b_info
= (BITMAPINFO
*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
88 sizeof(BITMAPINFOHEADER
));
92 /* Allocate extra space for a palette. */
93 b_info
= (BITMAPINFO
*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
94 sizeof(BITMAPINFOHEADER
)
96 * (1 << This
->surface_desc
.u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
));
100 b_info
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
101 b_info
->bmiHeader
.biWidth
= This
->surface_desc
.dwWidth
;
102 b_info
->bmiHeader
.biHeight
= -This
->surface_desc
.dwHeight
;
103 b_info
->bmiHeader
.biPlanes
= 1;
104 b_info
->bmiHeader
.biBitCount
= This
->surface_desc
.u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
;
106 if ((This
->surface_desc
.u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
!= 16)
107 && (This
->surface_desc
.u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
!= 32))
108 b_info
->bmiHeader
.biCompression
= BI_RGB
;
110 b_info
->bmiHeader
.biCompression
= BI_BITFIELDS
;
112 b_info
->bmiHeader
.biSizeImage
113 = (This
->surface_desc
.u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
/ 8)
114 * This
->surface_desc
.dwWidth
* This
->surface_desc
.dwHeight
;
116 b_info
->bmiHeader
.biXPelsPerMeter
= 0;
117 b_info
->bmiHeader
.biYPelsPerMeter
= 0;
118 b_info
->bmiHeader
.biClrUsed
= 0;
119 b_info
->bmiHeader
.biClrImportant
= 0;
121 if (!This
->surface_desc
.u1
.lPitch
) {
122 /* This can't happen, right? */
123 /* or use GDI_GetObj to get it from the created DIB? */
124 This
->surface_desc
.u1
.lPitch
= get_dib_width_bytes(b_info
->bmiHeader
.biWidth
, b_info
->bmiHeader
.biBitCount
);
125 This
->surface_desc
.dwFlags
|= DDSD_PITCH
;
128 switch (This
->surface_desc
.u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
)
133 DWORD
*masks
= (DWORD
*) &(b_info
->bmiColors
);
136 masks
[0] = This
->surface_desc
.u4
.ddpfPixelFormat
.u2
.dwRBitMask
;
137 masks
[1] = This
->surface_desc
.u4
.ddpfPixelFormat
.u3
.dwGBitMask
;
138 masks
[2] = This
->surface_desc
.u4
.ddpfPixelFormat
.u4
.dwBBitMask
;
144 usage
= DIB_RGB_COLORS
;
148 /* Don't know palette */
153 ddc
= CreateDCA("DISPLAY", NULL
, NULL
, NULL
);
156 HeapFree(GetProcessHeap(), 0, b_info
);
157 return HRESULT_FROM_WIN32(GetLastError());
161 = DIB_CreateDIBSection(ddc
, b_info
, usage
, &(priv
->dib
.bitmap_data
), 0,
162 (DWORD
)This
->surface_desc
.lpSurface
,
163 This
->surface_desc
.u1
.lPitch
);
165 if (!priv
->dib
.DIBsection
) {
166 ERR("CreateDIBSection failed!\n");
167 HeapFree(GetProcessHeap(), 0, b_info
);
168 return HRESULT_FROM_WIN32(GetLastError());
171 TRACE("DIBSection at : %p\n", priv
->dib
.bitmap_data
);
173 if (!This
->surface_desc
.lpSurface
) {
174 This
->surface_desc
.lpSurface
= priv
->dib
.bitmap_data
;
175 This
->surface_desc
.dwFlags
|= DDSD_LPSURFACE
;
178 HeapFree(GetProcessHeap(), 0, b_info
);
180 /* I don't think it's worth checking for this. */
181 if (priv
->dib
.bitmap_data
!= This
->surface_desc
.lpSurface
)
182 ERR("unexpected error creating DirectDrawSurface DIB section\n");
184 /* this seems like a good place to put the handle for HAL driver use */
185 This
->global_more
.hKernelSurface
= (ULONG_PTR
)priv
->dib
.DIBsection
;
190 void DIB_DirectDrawSurface_final_release(IDirectDrawSurfaceImpl
* This
)
192 DIB_DirectDrawSurfaceImpl
* priv
= This
->private;
194 DeleteObject(priv
->dib
.DIBsection
);
196 if (!priv
->dib
.client_memory
)
197 VirtualFree(This
->surface_desc
.lpSurface
, 0, MEM_RELEASE
);
199 Main_DirectDrawSurface_final_release(This
);
202 HRESULT
DIB_DirectDrawSurface_duplicate_surface(IDirectDrawSurfaceImpl
* This
,
203 LPDIRECTDRAWSURFACE7
* ppDup
)
205 return DIB_DirectDrawSurface_Create(This
->ddraw_owner
,
206 &This
->surface_desc
, ppDup
, NULL
);
209 HRESULT
DIB_DirectDrawSurface_Construct(IDirectDrawSurfaceImpl
*This
,
210 IDirectDrawImpl
*pDD
,
211 const DDSURFACEDESC2
*pDDSD
)
214 DIB_DirectDrawSurfaceImpl
* priv
= This
->private;
216 TRACE("(%p)->(%p,%p)\n",This
,pDD
,pDDSD
);
217 hr
= Main_DirectDrawSurface_Construct(This
, pDD
, pDDSD
);
218 if (FAILED(hr
)) return hr
;
220 ICOM_INIT_INTERFACE(This
, IDirectDrawSurface7
,
221 DIB_IDirectDrawSurface7_VTable
);
223 This
->final_release
= DIB_DirectDrawSurface_final_release
;
224 This
->duplicate_surface
= DIB_DirectDrawSurface_duplicate_surface
;
225 This
->flip_data
= DIB_DirectDrawSurface_flip_data
;
227 This
->get_dc
= DIB_DirectDrawSurface_get_dc
;
228 This
->release_dc
= DIB_DirectDrawSurface_release_dc
;
231 This
->set_palette
= DIB_DirectDrawSurface_set_palette
;
232 This
->update_palette
= DIB_DirectDrawSurface_update_palette
;
234 TRACE("(%ldx%ld, pitch=%ld)\n",
235 This
->surface_desc
.dwWidth
, This
->surface_desc
.dwHeight
,
236 This
->surface_desc
.u1
.lPitch
);
237 /* XXX load dwWidth and dwHeight from pDD if they are not specified? */
239 if (This
->surface_desc
.dwFlags
& DDSD_LPSURFACE
)
241 /* "Client memory": it is managed by the application. */
242 /* XXX What if lPitch is not set? Use dwWidth or fail? */
244 priv
->dib
.client_memory
= TRUE
;
248 if (!(This
->surface_desc
.dwFlags
& DDSD_PITCH
))
250 int pitch
= This
->surface_desc
.u1
.lPitch
;
252 pitch
+= 8 - (pitch
% 8);
254 /* XXX else: how should lPitch be verified? */
256 This
->surface_desc
.dwFlags
|= DDSD_PITCH
|DDSD_LPSURFACE
;
258 if (This
->surface_desc
.u4
.ddpfPixelFormat
.dwFlags
& DDPF_FOURCC
)
259 This
->surface_desc
.lpSurface
260 = VirtualAlloc(NULL
, This
->surface_desc
.u1
.dwLinearSize
, MEM_COMMIT
, PAGE_READWRITE
);
262 This
->surface_desc
.lpSurface
263 = VirtualAlloc(NULL
, This
->surface_desc
.u1
.lPitch
264 * This
->surface_desc
.dwHeight
+ 4, /* The + 4 here is for dumb games reading after the end of the surface
265 when reading the last byte / half using word access */
266 MEM_COMMIT
, PAGE_READWRITE
);
268 if (This
->surface_desc
.lpSurface
== NULL
)
270 Main_DirectDrawSurface_final_release(This
);
271 return HRESULT_FROM_WIN32(GetLastError());
274 priv
->dib
.client_memory
= FALSE
;
277 hr
= create_dib(This
);
280 if (!priv
->dib
.client_memory
)
281 VirtualFree(This
->surface_desc
.lpSurface
, 0, MEM_RELEASE
);
283 Main_DirectDrawSurface_final_release(This
);
292 HRESULT
DIB_DirectDrawSurface_Create(IDirectDrawImpl
*pDD
,
293 const DDSURFACEDESC2
*pDDSD
,
294 LPDIRECTDRAWSURFACE7
*ppSurf
,
297 IDirectDrawSurfaceImpl
* This
;
299 assert(pUnkOuter
== NULL
);
301 This
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
302 sizeof(*This
) + sizeof(DIB_DirectDrawSurfaceImpl
));
303 if (This
== NULL
) return E_OUTOFMEMORY
;
305 This
->private = (DIB_DirectDrawSurfaceImpl
*)(This
+1);
307 hr
= DIB_DirectDrawSurface_Construct(This
, pDD
, pDDSD
);
309 HeapFree(GetProcessHeap(), 0, This
);
311 *ppSurf
= ICOM_INTERFACE(This
, IDirectDrawSurface7
);
317 /* AddAttachedSurface: generic */
318 /* AddOverlayDirtyRect: generic, unimplemented */
320 static HRESULT
_Blt_ColorFill(
321 LPBYTE buf
, int width
, int height
, int bpp
, LONG lPitch
, DWORD color
328 #define COLORFILL_ROW(type) { \
329 type *d = (type *) buf; \
330 for (x = 0; x < width; x++) \
331 d[x] = (type) color; \
336 case 1: COLORFILL_ROW(BYTE
)
337 case 2: COLORFILL_ROW(WORD
)
338 case 3: { BYTE
*d
= (BYTE
*) buf
;
339 for (x
= 0; x
< width
; x
++,d
+=3) {
340 d
[0] = (color
) & 0xFF;
341 d
[1] = (color
>> 8) & 0xFF;
342 d
[2] = (color
>>16) & 0xFF;
345 case 4: COLORFILL_ROW(DWORD
)
347 FIXME("Color fill not implemented for bpp %d!\n", bpp
*8);
348 return DDERR_UNSUPPORTED
;
353 /* Now copy first row */
355 for (y
= 1; y
< height
; y
++) {
357 memcpy(buf
, first
, width
* bpp
);
362 static void ComputeShifts(DWORD mask
, DWORD
* lshift
, DWORD
* rshift
)
372 while(!(mask
& (1 << pos
)))
375 while(mask
& (1 << (pos
+bits
)))
382 /* This is used to factorize the decompression between the Blt and BltFast code */
383 static void DoDXTCDecompression(const DDSURFACEDESC2
*sdesc
, const DDSURFACEDESC2
*ddesc
)
390 if (!s3tc_initialized
) {
391 /* FIXME: We may fake this by rendering the texture into the framebuffer using OpenGL functions and reading back
392 * the framebuffer. This will be slow and somewhat ugly. */
393 FIXME("Manual S3TC decompression is not supported in native mode\n");
397 rm
= ddesc
->u4
.ddpfPixelFormat
.u2
.dwRBitMask
;
398 ComputeShifts(rm
, &rs
, &rb
);
399 gm
= ddesc
->u4
.ddpfPixelFormat
.u3
.dwGBitMask
;
400 ComputeShifts(gm
, &gs
, &gb
);
401 bm
= ddesc
->u4
.ddpfPixelFormat
.u4
.dwBBitMask
;
402 ComputeShifts(bm
, &bs
, &bb
);
403 am
= ddesc
->u4
.ddpfPixelFormat
.u5
.dwRGBAlphaBitMask
;
404 ComputeShifts(am
, &as
, &ab
);
405 if (sdesc
->u4
.ddpfPixelFormat
.dwFourCC
== MAKE_FOURCC('D','X','T','1')) {
406 int is16
= ddesc
->u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
== 16;
407 int pitch
= ddesc
->u1
.lPitch
;
408 int width
= ddesc
->dwWidth
;
409 int height
= ddesc
->dwHeight
;
411 char* dst
= (char*) ddesc
->lpSurface
;
412 char* src
= (char*) sdesc
->lpSurface
;
413 for (x
= 0; x
< width
; x
++)
414 for (y
=0; y
< height
; y
++) {
417 (*fetch_2d_texel_rgba_dxt1
)(width
, src
, x
, y
, data
);
419 pixel
|= ((data
[0] >> rb
) << rs
) & rm
;
420 pixel
|= ((data
[1] >> gb
) << gs
) & gm
;
421 pixel
|= ((data
[2] >> bb
) << bs
) & bm
;
422 pixel
|= ((data
[3] >> ab
) << as
) & am
;
424 *((WORD
*)(dst
+y
*pitch
+x
*(is16
?2:4))) = pixel
;
426 *((DWORD
*)(dst
+y
*pitch
+x
*(is16
?2:4))) = pixel
;
428 } else if (sdesc
->u4
.ddpfPixelFormat
.dwFourCC
== MAKE_FOURCC('D','X','T','3')) {
429 int is16
= ddesc
->u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
== 16;
430 int pitch
= ddesc
->u1
.lPitch
;
431 int width
= ddesc
->dwWidth
;
432 int height
= ddesc
->dwHeight
;
434 char* dst
= (char*) ddesc
->lpSurface
;
435 char* src
= (char*) sdesc
->lpSurface
;
436 for (x
= 0; x
< width
; x
++)
437 for (y
=0; y
< height
; y
++) {
440 (*fetch_2d_texel_rgba_dxt3
)(width
, src
, x
, y
, data
);
442 pixel
|= ((data
[0] >> rb
) << rs
) & rm
;
443 pixel
|= ((data
[1] >> gb
) << gs
) & gm
;
444 pixel
|= ((data
[2] >> bb
) << bs
) & bm
;
445 pixel
|= ((data
[3] >> ab
) << as
) & am
;
447 *((WORD
*)(dst
+y
*pitch
+x
*(is16
?2:4))) = pixel
;
449 *((DWORD
*)(dst
+y
*pitch
+x
*(is16
?2:4))) = pixel
;
451 } else if (sdesc
->u4
.ddpfPixelFormat
.dwFourCC
== MAKE_FOURCC('D','X','T','5')) {
452 int is16
= ddesc
->u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
== 16;
453 int pitch
= ddesc
->u1
.lPitch
;
454 int width
= ddesc
->dwWidth
;
455 int height
= ddesc
->dwHeight
;
457 char* dst
= (char*) ddesc
->lpSurface
;
458 char* src
= (char*) sdesc
->lpSurface
;
459 for (x
= 0; x
< width
; x
++)
460 for (y
=0; y
< height
; y
++) {
463 (*fetch_2d_texel_rgba_dxt5
)(width
, src
, x
, y
, data
);
465 pixel
|= ((data
[0] >> rb
) << rs
) & rm
;
466 pixel
|= ((data
[1] >> gb
) << gs
) & gm
;
467 pixel
|= ((data
[2] >> bb
) << bs
) & bm
;
468 pixel
|= ((data
[3] >> ab
) << as
) & am
;
470 *((WORD
*)(dst
+y
*pitch
+x
*(is16
?2:4))) = pixel
;
472 *((DWORD
*)(dst
+y
*pitch
+x
*(is16
?2:4))) = pixel
;
475 #if 0 /* Usefull for debugging */
480 sprintf(texname
, "dxt_%d.pnm", idx
++);
481 f
= fopen(texname
,"w");
482 DDRAW_dump_surface_to_disk(This
, f
, 1);
489 DIB_DirectDrawSurface_Blt(LPDIRECTDRAWSURFACE7 iface
, LPRECT rdst
,
490 LPDIRECTDRAWSURFACE7 src
, LPRECT rsrc
,
491 DWORD dwFlags
, LPDDBLTFX lpbltfx
)
493 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
495 DDSURFACEDESC2 ddesc
,sdesc
;
497 int bpp
, srcheight
, srcwidth
, dstheight
, dstwidth
, width
;
501 TRACE("(%p)->(%p,%p,%p,%08lx,%p)\n", This
,rdst
,src
,rsrc
,dwFlags
,lpbltfx
);
503 if (TRACE_ON(ddraw
)) {
504 if (rdst
) TRACE("\tdestrect :%ldx%ld-%ldx%ld\n",rdst
->left
,rdst
->top
,rdst
->right
,rdst
->bottom
);
505 if (rsrc
) TRACE("\tsrcrect :%ldx%ld-%ldx%ld\n",rsrc
->left
,rsrc
->top
,rsrc
->right
,rsrc
->bottom
);
507 DDRAW_dump_DDBLT(dwFlags
);
508 if (dwFlags
& DDBLT_DDFX
) {
510 DDRAW_dump_DDBLTFX(lpbltfx
->dwDDFX
);
514 /* First, check if the possible override function handles this case */
515 if (This
->aux_blt
!= NULL
) {
516 if (This
->aux_blt(This
, rdst
, src
, rsrc
, dwFlags
, lpbltfx
) == DD_OK
) return DD_OK
;
519 DD_STRUCT_INIT(&ddesc
);
520 DD_STRUCT_INIT(&sdesc
);
522 sdesc
.dwSize
= sizeof(sdesc
);
523 if (src
) IDirectDrawSurface7_Lock(src
, NULL
, &sdesc
, DDLOCK_READONLY
, 0);
524 ddesc
.dwSize
= sizeof(ddesc
);
525 IDirectDrawSurface7_Lock(iface
,NULL
,&ddesc
,DDLOCK_WRITEONLY
,0);
527 if ((sdesc
.u4
.ddpfPixelFormat
.dwFlags
& DDPF_FOURCC
) &&
528 (ddesc
.u4
.ddpfPixelFormat
.dwFlags
& DDPF_FOURCC
)) {
529 if (sdesc
.u4
.ddpfPixelFormat
.dwFourCC
!= sdesc
.u4
.ddpfPixelFormat
.dwFourCC
) {
530 FIXME("FOURCC->FOURCC copy only supported for the same type of surface\n");
531 ret
= DDERR_INVALIDPIXELFORMAT
;
534 memcpy(ddesc
.lpSurface
, sdesc
.lpSurface
, ddesc
.u1
.dwLinearSize
);
538 if ((sdesc
.u4
.ddpfPixelFormat
.dwFlags
& DDPF_FOURCC
) &&
539 (!(ddesc
.u4
.ddpfPixelFormat
.dwFlags
& DDPF_FOURCC
))) {
540 DoDXTCDecompression(&sdesc
, &ddesc
);
545 memcpy(&xdst
,rdst
,sizeof(xdst
));
548 xdst
.bottom
= ddesc
.dwHeight
;
550 xdst
.right
= ddesc
.dwWidth
;
554 memcpy(&xsrc
,rsrc
,sizeof(xsrc
));
558 xsrc
.bottom
= sdesc
.dwHeight
;
560 xsrc
.right
= sdesc
.dwWidth
;
562 memset(&xsrc
,0,sizeof(xsrc
));
566 /* First check for the validity of source / destination rectangles. This was
567 verified using a test application + by MSDN.
570 ((xsrc
.bottom
> sdesc
.dwHeight
) || (xsrc
.bottom
< 0) ||
571 (xsrc
.top
> sdesc
.dwHeight
) || (xsrc
.top
< 0) ||
572 (xsrc
.left
> sdesc
.dwWidth
) || (xsrc
.left
< 0) ||
573 (xsrc
.right
> sdesc
.dwWidth
) || (xsrc
.right
< 0) ||
574 (xsrc
.right
< xsrc
.left
) || (xsrc
.bottom
< xsrc
.top
))) {
575 WARN("Application gave us bad source rectangle for Blt.\n");
576 return DDERR_INVALIDRECT
;
578 /* For the Destination rect, it can be out of bounds on the condition that a clipper
579 is set for the given surface.
581 if ((This
->clipper
== NULL
) &&
582 ((xdst
.bottom
> ddesc
.dwHeight
) || (xdst
.bottom
< 0) ||
583 (xdst
.top
> ddesc
.dwHeight
) || (xdst
.top
< 0) ||
584 (xdst
.left
> ddesc
.dwWidth
) || (xdst
.left
< 0) ||
585 (xdst
.right
> ddesc
.dwWidth
) || (xdst
.right
< 0) ||
586 (xdst
.right
< xdst
.left
) || (xdst
.bottom
< xdst
.top
))) {
587 WARN("Application gave us bad destination rectangle for Blt without a clipper set.\n");
588 return DDERR_INVALIDRECT
;
591 /* Now handle negative values in the rectangles. Warning: only supported for now
592 in the 'simple' cases (ie not in any stretching / rotation cases).
594 First, the case where nothing is to be done.
596 if (((xdst
.bottom
<= 0) || (xdst
.right
<= 0) || (xdst
.top
>= (int) ddesc
.dwHeight
) || (xdst
.left
>= (int) ddesc
.dwWidth
)) ||
598 ((xsrc
.bottom
<= 0) || (xsrc
.right
<= 0) || (xsrc
.top
>= (int) sdesc
.dwHeight
) || (xsrc
.left
>= (int) sdesc
.dwWidth
))))
600 TRACE("Nothing to be done !\n");
604 /* The easy case : the source-less blits.... */
607 RECT temp_rect
; /* No idea if intersect rect can be the same as one of the source rect */
611 full_rect
.right
= ddesc
.dwWidth
;
612 full_rect
.bottom
= ddesc
.dwHeight
;
613 IntersectRect(&temp_rect
, &full_rect
, &xdst
);
616 /* Only handle clipping on the destination rectangle */
617 int clip_horiz
= (xdst
.left
< 0) || (xdst
.right
> (int) ddesc
.dwWidth
);
618 int clip_vert
= (xdst
.top
< 0) || (xdst
.bottom
> (int) ddesc
.dwHeight
);
619 if (clip_vert
|| clip_horiz
) {
620 /* Now check if this is a special case or not... */
621 if ((((xdst
.bottom
- xdst
.top
) != (xsrc
.bottom
- xsrc
.top
)) && clip_vert
) ||
622 (((xdst
.right
- xdst
.left
) != (xsrc
.right
- xsrc
.left
)) && clip_horiz
) ||
623 (dwFlags
& DDBLT_DDFX
)) {
624 WARN("Out of screen rectangle in special case. Not handled right now.\n");
629 if (xdst
.left
< 0) { xsrc
.left
-= xdst
.left
; xdst
.left
= 0; }
630 if (xdst
.right
> ddesc
.dwWidth
) { xsrc
.right
-= (xdst
.right
- (int) ddesc
.dwWidth
); xdst
.right
= (int) ddesc
.dwWidth
; }
633 if (xdst
.top
< 0) { xsrc
.top
-= xdst
.top
; xdst
.top
= 0; }
634 if (xdst
.bottom
> ddesc
.dwHeight
) { xsrc
.bottom
-= (xdst
.bottom
- (int) ddesc
.dwHeight
); xdst
.bottom
= (int) ddesc
.dwHeight
; }
636 /* And check if after clipping something is still to be done... */
637 if ((xdst
.bottom
<= 0) || (xdst
.right
<= 0) || (xdst
.top
>= (int) ddesc
.dwHeight
) || (xdst
.left
>= (int) ddesc
.dwWidth
) ||
638 (xsrc
.bottom
<= 0) || (xsrc
.right
<= 0) || (xsrc
.top
>= (int) sdesc
.dwHeight
) || (xsrc
.left
>= (int) sdesc
.dwWidth
)) {
639 TRACE("Nothing to be done after clipping !\n");
645 bpp
= GET_BPP(ddesc
);
646 srcheight
= xsrc
.bottom
- xsrc
.top
;
647 srcwidth
= xsrc
.right
- xsrc
.left
;
648 dstheight
= xdst
.bottom
- xdst
.top
;
649 dstwidth
= xdst
.right
- xdst
.left
;
650 width
= (xdst
.right
- xdst
.left
) * bpp
;
652 assert(width
<= ddesc
.u1
.lPitch
);
654 dbuf
= (BYTE
*)ddesc
.lpSurface
+(xdst
.top
*ddesc
.u1
.lPitch
)+(xdst
.left
*bpp
);
656 if (dwFlags
& (DDBLT_WAIT
|DDBLT_ASYNC
))
658 static BOOL displayed
= FALSE
;
661 FIXME("dwFlags DDBLT_WAIT and/or DDBLT_ASYNC: can't handle right now.\n");
664 dwFlags
&= ~(DDBLT_WAIT
|DDBLT_ASYNC
);
667 /* First, all the 'source-less' blits */
668 if (dwFlags
& DDBLT_COLORFILL
) {
669 ret
= _Blt_ColorFill(dbuf
, dstwidth
, dstheight
, bpp
,
670 ddesc
.u1
.lPitch
, lpbltfx
->u5
.dwFillColor
);
671 dwFlags
&= ~DDBLT_COLORFILL
;
674 if (dwFlags
& DDBLT_DEPTHFILL
)
675 FIXME("DDBLT_DEPTHFILL needs to be implemented!\n");
676 if (dwFlags
& DDBLT_ROP
) {
677 /* Catch some degenerate cases here */
678 switch(lpbltfx
->dwROP
) {
680 ret
= _Blt_ColorFill(dbuf
,dstwidth
,dstheight
,bpp
,ddesc
.u1
.lPitch
,0);
682 case 0xAA0029: /* No-op */
685 ret
= _Blt_ColorFill(dbuf
,dstwidth
,dstheight
,bpp
,ddesc
.u1
.lPitch
,~0);
687 case SRCCOPY
: /* well, we do that below ? */
690 FIXME("Unsupported raster op: %08lx Pattern: %p\n", lpbltfx
->dwROP
, lpbltfx
->u5
.lpDDSPattern
);
693 dwFlags
&= ~DDBLT_ROP
;
695 if (dwFlags
& DDBLT_DDROPS
) {
696 FIXME("\tDdraw Raster Ops: %08lx Pattern: %p\n", lpbltfx
->dwDDROP
, lpbltfx
->u5
.lpDDSPattern
);
698 /* Now the 'with source' blits */
701 int sx
, xinc
, sy
, yinc
;
703 if (!dstwidth
|| !dstheight
) /* hmm... stupid program ? */
705 sbase
= (BYTE
*)sdesc
.lpSurface
+(xsrc
.top
*sdesc
.u1
.lPitch
)+xsrc
.left
*bpp
;
706 xinc
= (srcwidth
<< 16) / dstwidth
;
707 yinc
= (srcheight
<< 16) / dstheight
;
710 /* No effects, we can cheat here */
711 if (dstwidth
== srcwidth
) {
712 if (dstheight
== srcheight
) {
713 /* No stretching in either direction. This needs to be as
714 * fast as possible */
717 /* check for overlapping surfaces */
718 if (src
!= iface
|| xdst
.top
< xsrc
.top
||
719 xdst
.right
<= xsrc
.left
|| xsrc
.right
<= xdst
.left
)
721 /* no overlap, or dst above src, so copy from top downwards */
722 for (y
= 0; y
< dstheight
; y
++)
724 memcpy(dbuf
, sbuf
, width
);
725 sbuf
+= sdesc
.u1
.lPitch
;
726 dbuf
+= ddesc
.u1
.lPitch
;
729 else if (xdst
.top
> xsrc
.top
) /* copy from bottom upwards */
731 sbuf
+= (sdesc
.u1
.lPitch
*dstheight
);
732 dbuf
+= (ddesc
.u1
.lPitch
*dstheight
);
733 for (y
= 0; y
< dstheight
; y
++)
735 sbuf
-= sdesc
.u1
.lPitch
;
736 dbuf
-= ddesc
.u1
.lPitch
;
737 memcpy(dbuf
, sbuf
, width
);
740 else /* src and dst overlapping on the same line, use memmove */
742 for (y
= 0; y
< dstheight
; y
++)
744 memmove(dbuf
, sbuf
, width
);
745 sbuf
+= sdesc
.u1
.lPitch
;
746 dbuf
+= ddesc
.u1
.lPitch
;
750 /* Stretching in Y direction only */
751 for (y
= sy
= 0; y
< dstheight
; y
++, sy
+= yinc
) {
752 sbuf
= sbase
+ (sy
>> 16) * sdesc
.u1
.lPitch
;
753 memcpy(dbuf
, sbuf
, width
);
754 dbuf
+= ddesc
.u1
.lPitch
;
758 /* Stretching in X direction */
760 for (y
= sy
= 0; y
< dstheight
; y
++, sy
+= yinc
) {
761 sbuf
= sbase
+ (sy
>> 16) * sdesc
.u1
.lPitch
;
763 if ((sy
>> 16) == (last_sy
>> 16)) {
764 /* this sourcerow is the same as last sourcerow -
765 * copy already stretched row
767 memcpy(dbuf
, dbuf
- ddesc
.u1
.lPitch
, width
);
769 #define STRETCH_ROW(type) { \
770 type *s = (type *) sbuf, *d = (type *) dbuf; \
771 for (x = sx = 0; x < dstwidth; x++, sx += xinc) \
772 d[x] = s[sx >> 16]; \
776 case 1: STRETCH_ROW(BYTE
)
777 case 2: STRETCH_ROW(WORD
)
778 case 4: STRETCH_ROW(DWORD
)
781 for (x
= sx
= 0; x
< dstwidth
; x
++, sx
+= xinc
) {
785 pixel
= s
[0]|(s
[1]<<8)|(s
[2]<<16);
786 d
[0] = (pixel
)&0xff;
787 d
[1] = (pixel
>> 8)&0xff;
788 d
[2] = (pixel
>>16)&0xff;
794 FIXME("Stretched blit not implemented for bpp %d!\n", bpp
*8);
795 ret
= DDERR_UNSUPPORTED
;
800 dbuf
+= ddesc
.u1
.lPitch
;
805 LONG dstyinc
= ddesc
.u1
.lPitch
, dstxinc
= bpp
;
806 DWORD keylow
= 0, keyhigh
= 0;
807 if (dwFlags
& (DDBLT_KEYSRC
| DDBLT_KEYDEST
| DDBLT_KEYSRCOVERRIDE
| DDBLT_KEYDESTOVERRIDE
)) {
809 if (dwFlags
& DDBLT_KEYSRC
) {
810 keylow
= sdesc
.ddckCKSrcBlt
.dwColorSpaceLowValue
;
811 keyhigh
= sdesc
.ddckCKSrcBlt
.dwColorSpaceHighValue
;
812 } else if (dwFlags
& DDBLT_KEYDEST
){
813 keylow
= ddesc
.ddckCKDestBlt
.dwColorSpaceLowValue
;
814 keyhigh
= ddesc
.ddckCKDestBlt
.dwColorSpaceHighValue
;
815 } else if (dwFlags
& DDBLT_KEYSRCOVERRIDE
) {
816 keylow
= lpbltfx
->ddckSrcColorkey
.dwColorSpaceLowValue
;
817 keyhigh
= lpbltfx
->ddckSrcColorkey
.dwColorSpaceHighValue
;
819 keylow
= lpbltfx
->ddckDestColorkey
.dwColorSpaceLowValue
;
820 keyhigh
= lpbltfx
->ddckDestColorkey
.dwColorSpaceHighValue
;
822 dwFlags
&= ~(DDBLT_KEYSRC
| DDBLT_KEYDEST
| DDBLT_KEYSRCOVERRIDE
| DDBLT_KEYDESTOVERRIDE
);
825 if (dwFlags
& DDBLT_DDFX
) {
826 LPBYTE dTopLeft
, dTopRight
, dBottomLeft
, dBottomRight
, tmp
;
829 dTopRight
= dbuf
+((dstwidth
-1)*bpp
);
830 dBottomLeft
= dTopLeft
+((dstheight
-1)*ddesc
.u1
.lPitch
);
831 dBottomRight
= dBottomLeft
+((dstwidth
-1)*bpp
);
833 if (lpbltfx
->dwDDFX
& DDBLTFX_ARITHSTRETCHY
){
834 /* I don't think we need to do anything about this flag */
835 WARN("dwflags=DDBLT_DDFX nothing done for DDBLTFX_ARITHSTRETCHY\n");
837 if (lpbltfx
->dwDDFX
& DDBLTFX_MIRRORLEFTRIGHT
) {
839 dTopRight
= dTopLeft
;
842 dBottomRight
= dBottomLeft
;
844 dstxinc
= dstxinc
*-1;
846 if (lpbltfx
->dwDDFX
& DDBLTFX_MIRRORUPDOWN
) {
848 dTopLeft
= dBottomLeft
;
851 dTopRight
= dBottomRight
;
853 dstyinc
= dstyinc
*-1;
855 if (lpbltfx
->dwDDFX
& DDBLTFX_NOTEARING
) {
856 /* I don't think we need to do anything about this flag */
857 WARN("dwflags=DDBLT_DDFX nothing done for DDBLTFX_NOTEARING\n");
859 if (lpbltfx
->dwDDFX
& DDBLTFX_ROTATE180
) {
861 dBottomRight
= dTopLeft
;
864 dBottomLeft
= dTopRight
;
866 dstxinc
= dstxinc
* -1;
867 dstyinc
= dstyinc
* -1;
869 if (lpbltfx
->dwDDFX
& DDBLTFX_ROTATE270
) {
871 dTopLeft
= dBottomLeft
;
872 dBottomLeft
= dBottomRight
;
873 dBottomRight
= dTopRight
;
878 dstxinc
= dstxinc
* -1;
880 if (lpbltfx
->dwDDFX
& DDBLTFX_ROTATE90
) {
882 dTopLeft
= dTopRight
;
883 dTopRight
= dBottomRight
;
884 dBottomRight
= dBottomLeft
;
889 dstyinc
= dstyinc
* -1;
891 if (lpbltfx
->dwDDFX
& DDBLTFX_ZBUFFERBASEDEST
) {
892 /* I don't think we need to do anything about this flag */
893 WARN("dwflags=DDBLT_DDFX nothing done for DDBLTFX_ZBUFFERBASEDEST\n");
896 dwFlags
&= ~(DDBLT_DDFX
);
899 #define COPY_COLORKEY_FX(type) { \
900 type *s, *d = (type *) dbuf, *dx, tmp; \
901 for (y = sy = 0; y < dstheight; y++, sy += yinc) { \
902 s = (type*)(sbase + (sy >> 16) * sdesc.u1.lPitch); \
904 for (x = sx = 0; x < dstwidth; x++, sx += xinc) { \
906 if (tmp < keylow || tmp > keyhigh) dx[0] = tmp; \
907 dx = (type*)(((LPBYTE)dx)+dstxinc); \
909 d = (type*)(((LPBYTE)d)+dstyinc); \
914 case 1: COPY_COLORKEY_FX(BYTE
)
915 case 2: COPY_COLORKEY_FX(WORD
)
916 case 4: COPY_COLORKEY_FX(DWORD
)
917 case 3: {LPBYTE s
,d
= dbuf
, dx
;
918 for (y
= sy
= 0; y
< dstheight
; y
++, sy
+= yinc
) {
919 sbuf
= sbase
+ (sy
>> 16) * sdesc
.u1
.lPitch
;
921 for (x
= sx
= 0; x
< dstwidth
; x
++, sx
+= xinc
) {
924 pixel
= s
[0]|(s
[1]<<8)|(s
[2]<<16);
925 if (pixel
< keylow
|| pixel
> keyhigh
){
926 dx
[0] = (pixel
)&0xff;
927 dx
[1] = (pixel
>> 8)&0xff;
928 dx
[2] = (pixel
>>16)&0xff;
936 FIXME("%s color-keyed blit not implemented for bpp %d!\n",
937 (dwFlags
& DDBLT_KEYSRC
) ? "Source" : "Destination", bpp
*8);
938 ret
= DDERR_UNSUPPORTED
;
940 #undef COPY_COLORKEY_FX
946 if (dwFlags
&& FIXME_ON(ddraw
)) {
947 FIXME("\tUnsupported flags: ");
948 DDRAW_dump_DDBLT(dwFlags
);
952 IDirectDrawSurface7_Unlock(iface
,NULL
);
953 if (src
) IDirectDrawSurface7_Unlock(src
,NULL
);
957 /* BltBatch: generic, unimplemented */
960 DIB_DirectDrawSurface_BltFast(LPDIRECTDRAWSURFACE7 iface
, DWORD dstx
,
961 DWORD dsty
, LPDIRECTDRAWSURFACE7 src
,
962 LPRECT rsrc
, DWORD trans
)
964 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
966 DDSURFACEDESC2 ddesc
,sdesc
;
970 RECT lock_src
, lock_dst
;
972 if (TRACE_ON(ddraw
)) {
973 TRACE("(%p)->(%ld,%ld,%p,%p,%08lx)\n",
974 This
,dstx
,dsty
,src
,rsrc
,trans
978 DDRAW_dump_DDBLTFAST(trans
);
980 TRACE("\tsrcrect: %ldx%ld-%ldx%ld\n",rsrc
->left
,rsrc
->top
,rsrc
->right
,rsrc
->bottom
);
982 TRACE(" srcrect: NULL\n");
985 /* First, check if the possible override function handles this case */
986 if (This
->aux_bltfast
!= NULL
) {
987 if (This
->aux_bltfast(This
, dstx
, dsty
, src
, rsrc
, trans
) == DD_OK
) return DD_OK
;
990 /* Get the surface description without locking to first compute the width / height */
991 ddesc
= This
->surface_desc
;
992 sdesc
= (ICOM_OBJECT(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, src
))->surface_desc
;
995 WARN("rsrc is NULL!\n");
997 rsrc
->left
= rsrc
->top
= 0;
998 rsrc
->right
= sdesc
.dwWidth
;
999 rsrc
->bottom
= sdesc
.dwHeight
;
1002 h
=rsrc
->bottom
-rsrc
->top
;
1003 if (h
>ddesc
.dwHeight
-dsty
) h
=ddesc
.dwHeight
-dsty
;
1004 if (h
>sdesc
.dwHeight
-rsrc
->top
) h
=sdesc
.dwHeight
-rsrc
->top
;
1005 if (h
<=0) return DDERR_INVALIDRECT
;
1007 w
=rsrc
->right
-rsrc
->left
;
1008 if (w
>ddesc
.dwWidth
-dstx
) w
=ddesc
.dwWidth
-dstx
;
1009 if (w
>sdesc
.dwWidth
-rsrc
->left
) w
=sdesc
.dwWidth
-rsrc
->left
;
1010 if (w
<=0) return DDERR_INVALIDRECT
;
1012 /* Now compute the locking rectangle... */
1013 lock_src
.left
= rsrc
->left
;
1014 lock_src
.top
= rsrc
->top
;
1015 lock_src
.right
= lock_src
.left
+ w
;
1016 lock_src
.bottom
= lock_src
.top
+ h
;
1018 lock_dst
.left
= dstx
;
1019 lock_dst
.top
= dsty
;
1020 lock_dst
.right
= dstx
+ w
;
1021 lock_dst
.bottom
= dsty
+ h
;
1023 /* We need to lock the surfaces, or we won't get refreshes when done. */
1024 sdesc
.dwSize
= sizeof(sdesc
);
1025 IDirectDrawSurface7_Lock(src
, &lock_src
, &sdesc
, DDLOCK_READONLY
, 0);
1026 ddesc
.dwSize
= sizeof(ddesc
);
1027 IDirectDrawSurface7_Lock(iface
, &lock_dst
, &ddesc
, DDLOCK_WRITEONLY
, 0);
1029 /* Handle first the FOURCC surfaces... */
1030 if ((sdesc
.u4
.ddpfPixelFormat
.dwFlags
& DDPF_FOURCC
) && (ddesc
.u4
.ddpfPixelFormat
.dwFlags
& DDPF_FOURCC
)) {
1032 FIXME("trans arg not supported when a FOURCC surface is involved\n");
1034 FIXME("offset for destination surface is not supported\n");
1035 if (sdesc
.u4
.ddpfPixelFormat
.dwFourCC
!= sdesc
.u4
.ddpfPixelFormat
.dwFourCC
) {
1036 FIXME("FOURCC->FOURCC copy only supported for the same type of surface\n");
1037 ret
= DDERR_INVALIDPIXELFORMAT
;
1040 memcpy(ddesc
.lpSurface
, sdesc
.lpSurface
, ddesc
.u1
.dwLinearSize
);
1043 if ((sdesc
.u4
.ddpfPixelFormat
.dwFlags
& DDPF_FOURCC
) &&
1044 (!(ddesc
.u4
.ddpfPixelFormat
.dwFlags
& DDPF_FOURCC
))) {
1045 DoDXTCDecompression(&sdesc
, &ddesc
);
1049 bpp
= GET_BPP(This
->surface_desc
);
1050 sbuf
= (BYTE
*) sdesc
.lpSurface
;
1051 dbuf
= (BYTE
*) ddesc
.lpSurface
;
1053 if (trans
& (DDBLTFAST_SRCCOLORKEY
| DDBLTFAST_DESTCOLORKEY
)) {
1054 DWORD keylow
, keyhigh
;
1055 if (trans
& DDBLTFAST_SRCCOLORKEY
) {
1056 keylow
= sdesc
.ddckCKSrcBlt
.dwColorSpaceLowValue
;
1057 keyhigh
= sdesc
.ddckCKSrcBlt
.dwColorSpaceHighValue
;
1059 /* I'm not sure if this is correct */
1060 FIXME("DDBLTFAST_DESTCOLORKEY not fully supported yet.\n");
1061 keylow
= ddesc
.ddckCKDestBlt
.dwColorSpaceLowValue
;
1062 keyhigh
= ddesc
.ddckCKDestBlt
.dwColorSpaceHighValue
;
1065 #define COPYBOX_COLORKEY(type) { \
1067 s = (type *) sdesc.lpSurface; \
1068 d = (type *) ddesc.lpSurface; \
1069 for (y = 0; y < h; y++) { \
1070 for (x = 0; x < w; x++) { \
1072 if (tmp < keylow || tmp > keyhigh) d[x] = tmp; \
1074 s = (type *)((BYTE *)s + sdesc.u1.lPitch); \
1075 d = (type *)((BYTE *)d + ddesc.u1.lPitch); \
1081 case 1: COPYBOX_COLORKEY(BYTE
)
1082 case 2: COPYBOX_COLORKEY(WORD
)
1083 case 4: COPYBOX_COLORKEY(DWORD
)
1088 s
= (BYTE
*) sdesc
.lpSurface
;
1089 d
= (BYTE
*) ddesc
.lpSurface
;
1090 for (y
= 0; y
< h
; y
++) {
1091 for (x
= 0; x
< w
* 3; x
+= 3) {
1092 tmp
= (DWORD
)s
[x
] + ((DWORD
)s
[x
+ 1] << 8) + ((DWORD
)s
[x
+ 2] << 16);
1093 if (tmp
< keylow
|| tmp
> keyhigh
) {
1094 d
[x
+ 0] = s
[x
+ 0];
1095 d
[x
+ 1] = s
[x
+ 1];
1096 d
[x
+ 2] = s
[x
+ 2];
1099 s
+= sdesc
.u1
.lPitch
;
1100 d
+= ddesc
.u1
.lPitch
;
1105 FIXME("Source color key blitting not supported for bpp %d\n",bpp
*8);
1106 ret
= DDERR_UNSUPPORTED
;
1109 #undef COPYBOX_COLORKEY
1111 int width
= w
* bpp
;
1113 for (y
= 0; y
< h
; y
++) {
1114 memcpy(dbuf
, sbuf
, width
);
1115 sbuf
+= sdesc
.u1
.lPitch
;
1116 dbuf
+= ddesc
.u1
.lPitch
;
1121 IDirectDrawSurface7_Unlock(iface
, &lock_dst
);
1122 IDirectDrawSurface7_Unlock(src
, &lock_src
);
1126 /* ChangeUniquenessValue: generic */
1127 /* DeleteAttachedSurface: generic */
1128 /* EnumAttachedSurfaces: generic */
1129 /* EnumOverlayZOrders: generic, unimplemented */
1131 BOOL
DIB_DirectDrawSurface_flip_data(IDirectDrawSurfaceImpl
* front
,
1132 IDirectDrawSurfaceImpl
* back
,
1135 DIB_DirectDrawSurfaceImpl
* front_priv
= front
->private;
1136 DIB_DirectDrawSurfaceImpl
* back_priv
= back
->private;
1138 TRACE("(%p,%p)\n",front
,back
);
1142 tmp
= front_priv
->dib
.DIBsection
;
1143 front_priv
->dib
.DIBsection
= back_priv
->dib
.DIBsection
;
1144 back_priv
->dib
.DIBsection
= tmp
;
1149 tmp
= front_priv
->dib
.bitmap_data
;
1150 front_priv
->dib
.bitmap_data
= back_priv
->dib
.bitmap_data
;
1151 back_priv
->dib
.bitmap_data
= tmp
;
1153 tmp
= front
->surface_desc
.lpSurface
;
1154 front
->surface_desc
.lpSurface
= back
->surface_desc
.lpSurface
;
1155 back
->surface_desc
.lpSurface
= tmp
;
1158 /* client_memory should not be different, but just in case */
1161 tmp
= front_priv
->dib
.client_memory
;
1162 front_priv
->dib
.client_memory
= back_priv
->dib
.client_memory
;
1163 back_priv
->dib
.client_memory
= tmp
;
1166 return Main_DirectDrawSurface_flip_data(front
, back
, dwFlags
);
1170 /* FreePrivateData: generic */
1171 /* GetAttachedSurface: generic */
1172 /* GetBltStatus: generic */
1173 /* GetCaps: generic (Returns the caps from This->surface_desc.) */
1174 /* GetClipper: generic */
1175 /* GetColorKey: generic */
1177 HRESULT
DIB_DirectDrawSurface_alloc_dc(IDirectDrawSurfaceImpl
* This
, HDC
* phDC
)
1179 DIB_PRIV_VAR(priv
, This
);
1182 TRACE("Grabbing a DC for surface: %p\n", This
);
1184 hDC
= CreateCompatibleDC(0);
1185 priv
->dib
.holdbitmap
= SelectObject(hDC
, priv
->dib
.DIBsection
);
1187 SelectPalette(hDC
, This
->palette
->hpal
, FALSE
);
1194 HRESULT
DIB_DirectDrawSurface_free_dc(IDirectDrawSurfaceImpl
* This
, HDC hDC
)
1196 DIB_PRIV_VAR(priv
, This
);
1198 TRACE("Releasing DC for surface: %p\n", This
);
1200 SelectObject(hDC
, priv
->dib
.holdbitmap
);
1206 HRESULT
DIB_DirectDrawSurface_get_dc(IDirectDrawSurfaceImpl
* This
, HDC
* phDC
)
1208 return DIB_DirectDrawSurface_alloc_dc(This
, phDC
);
1211 HRESULT
DIB_DirectDrawSurface_release_dc(IDirectDrawSurfaceImpl
* This
, HDC hDC
)
1213 return DIB_DirectDrawSurface_free_dc(This
, hDC
);
1216 /* GetDDInterface: generic */
1217 /* GetFlipStatus: generic */
1218 /* GetLOD: generic */
1219 /* GetOverlayPosition: generic */
1220 /* GetPalette: generic */
1221 /* GetPixelFormat: generic */
1222 /* GetPriority: generic */
1223 /* GetPrivateData: generic */
1224 /* GetSurfaceDesc: generic */
1225 /* GetUniquenessValue: generic */
1226 /* Initialize: generic */
1227 /* IsLost: generic */
1228 /* Lock: generic with callback? */
1229 /* PageLock: generic */
1230 /* PageUnlock: generic */
1233 DIB_DirectDrawSurface_Restore(LPDIRECTDRAWSURFACE7 iface
)
1235 TRACE("(%p)\n",iface
);
1236 return DD_OK
; /* ??? */
1239 /* SetClipper: generic */
1240 /* SetColorKey: generic */
1241 /* SetLOD: generic */
1242 /* SetOverlayPosition: generic */
1244 void DIB_DirectDrawSurface_set_palette(IDirectDrawSurfaceImpl
* This
,
1245 IDirectDrawPaletteImpl
* pal
)
1248 if (This
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
1249 This
->update_palette(This
, pal
,
1250 0, pal
->palNumEntries
,
1254 void DIB_DirectDrawSurface_update_palette(IDirectDrawSurfaceImpl
* This
,
1255 IDirectDrawPaletteImpl
* pal
,
1256 DWORD dwStart
, DWORD dwCount
,
1257 LPPALETTEENTRY palent
)
1263 TRACE("updating primary palette\n");
1264 for (n
=0; n
<dwCount
; n
++) {
1265 col
[n
].rgbRed
= palent
[n
].peRed
;
1266 col
[n
].rgbGreen
= palent
[n
].peGreen
;
1267 col
[n
].rgbBlue
= palent
[n
].peBlue
;
1268 col
[n
].rgbReserved
= 0;
1270 This
->get_dc(This
, &dc
);
1271 SetDIBColorTable(dc
, dwStart
, dwCount
, col
);
1272 This
->release_dc(This
, dc
);
1274 /* Propagate change to backbuffers if there are any */
1275 /* Basically this is a modification of the Flip code to find the backbuffer */
1276 /* and duplicate the palette update there as well */
1277 if ((This
->surface_desc
.ddsCaps
.dwCaps
&(DDSCAPS_FLIP
|DDSCAPS_FRONTBUFFER
))
1278 == (DDSCAPS_FLIP
|DDSCAPS_FRONTBUFFER
))
1280 static DDSCAPS2 back_caps
= { DDSCAPS_BACKBUFFER
};
1281 LPDIRECTDRAWSURFACE7 tgt
;
1283 HRESULT hr
= IDirectDrawSurface7_GetAttachedSurface(ICOM_INTERFACE(This
,IDirectDrawSurface7
),
1287 IDirectDrawSurfaceImpl
* target
= ICOM_OBJECT(IDirectDrawSurfaceImpl
,
1288 IDirectDrawSurface7
,tgt
);
1289 IDirectDrawSurface7_Release(tgt
);
1290 target
->get_dc(target
, &dc
);
1291 SetDIBColorTable(dc
, dwStart
, dwCount
, col
);
1292 target
->release_dc(target
, dc
);
1297 /* SetPalette: generic */
1298 /* SetPriority: generic */
1299 /* SetPrivateData: generic */
1302 DIB_DirectDrawSurface_SetSurfaceDesc(LPDIRECTDRAWSURFACE7 iface
,
1303 LPDDSURFACEDESC2 pDDSD
, DWORD dwFlags
)
1305 IDirectDrawSurfaceImpl
*This
= (IDirectDrawSurfaceImpl
*)iface
;
1306 DIB_PRIV_VAR(priv
, This
);
1308 DWORD flags
= pDDSD
->dwFlags
;
1310 if (TRACE_ON(ddraw
)) {
1311 TRACE("(%p)->(%p,%08lx)\n",iface
,pDDSD
,dwFlags
);
1312 DDRAW_dump_surface_desc(pDDSD
);
1315 if (pDDSD
->dwFlags
& DDSD_PIXELFORMAT
) {
1316 flags
&= ~DDSD_PIXELFORMAT
;
1317 if (flags
& DDSD_LPSURFACE
) {
1318 This
->surface_desc
.u4
.ddpfPixelFormat
= pDDSD
->u4
.ddpfPixelFormat
;
1320 FIXME("Change of pixel format without surface re-allocation is not supported !\n");
1323 if (pDDSD
->dwFlags
& DDSD_LPSURFACE
) {
1324 HBITMAP oldbmp
= priv
->dib
.DIBsection
;
1325 LPVOID oldsurf
= This
->surface_desc
.lpSurface
;
1326 BOOL oldc
= priv
->dib
.client_memory
;
1328 flags
&= ~DDSD_LPSURFACE
;
1330 TRACE("new lpSurface=%p\n",pDDSD
->lpSurface
);
1331 This
->surface_desc
.lpSurface
= pDDSD
->lpSurface
;
1332 priv
->dib
.client_memory
= TRUE
;
1334 hr
= create_dib(This
);
1337 priv
->dib
.DIBsection
= oldbmp
;
1338 This
->surface_desc
.lpSurface
= oldsurf
;
1339 priv
->dib
.client_memory
= oldc
;
1343 DeleteObject(oldbmp
);
1346 VirtualFree(oldsurf
, 0, MEM_RELEASE
);
1349 WARN("Unhandled flags : %08lx\n", flags
);
1354 /* Unlock: ???, need callback */
1355 /* UpdateOverlay: generic */
1356 /* UpdateOverlayDisplay: generic */
1357 /* UpdateOverlayZOrder: generic */
1359 static IDirectDrawSurface7Vtbl DIB_IDirectDrawSurface7_VTable
=
1361 Main_DirectDrawSurface_QueryInterface
,
1362 Main_DirectDrawSurface_AddRef
,
1363 Main_DirectDrawSurface_Release
,
1364 Main_DirectDrawSurface_AddAttachedSurface
,
1365 Main_DirectDrawSurface_AddOverlayDirtyRect
,
1366 DIB_DirectDrawSurface_Blt
,
1367 Main_DirectDrawSurface_BltBatch
,
1368 DIB_DirectDrawSurface_BltFast
,
1369 Main_DirectDrawSurface_DeleteAttachedSurface
,
1370 Main_DirectDrawSurface_EnumAttachedSurfaces
,
1371 Main_DirectDrawSurface_EnumOverlayZOrders
,
1372 Main_DirectDrawSurface_Flip
,
1373 Main_DirectDrawSurface_GetAttachedSurface
,
1374 Main_DirectDrawSurface_GetBltStatus
,
1375 Main_DirectDrawSurface_GetCaps
,
1376 Main_DirectDrawSurface_GetClipper
,
1377 Main_DirectDrawSurface_GetColorKey
,
1378 Main_DirectDrawSurface_GetDC
,
1379 Main_DirectDrawSurface_GetFlipStatus
,
1380 Main_DirectDrawSurface_GetOverlayPosition
,
1381 Main_DirectDrawSurface_GetPalette
,
1382 Main_DirectDrawSurface_GetPixelFormat
,
1383 Main_DirectDrawSurface_GetSurfaceDesc
,
1384 Main_DirectDrawSurface_Initialize
,
1385 Main_DirectDrawSurface_IsLost
,
1386 Main_DirectDrawSurface_Lock
,
1387 Main_DirectDrawSurface_ReleaseDC
,
1388 DIB_DirectDrawSurface_Restore
,
1389 Main_DirectDrawSurface_SetClipper
,
1390 Main_DirectDrawSurface_SetColorKey
,
1391 Main_DirectDrawSurface_SetOverlayPosition
,
1392 Main_DirectDrawSurface_SetPalette
,
1393 Main_DirectDrawSurface_Unlock
,
1394 Main_DirectDrawSurface_UpdateOverlay
,
1395 Main_DirectDrawSurface_UpdateOverlayDisplay
,
1396 Main_DirectDrawSurface_UpdateOverlayZOrder
,
1397 Main_DirectDrawSurface_GetDDInterface
,
1398 Main_DirectDrawSurface_PageLock
,
1399 Main_DirectDrawSurface_PageUnlock
,
1400 DIB_DirectDrawSurface_SetSurfaceDesc
,
1401 Main_DirectDrawSurface_SetPrivateData
,
1402 Main_DirectDrawSurface_GetPrivateData
,
1403 Main_DirectDrawSurface_FreePrivateData
,
1404 Main_DirectDrawSurface_GetUniquenessValue
,
1405 Main_DirectDrawSurface_ChangeUniquenessValue
,
1406 Main_DirectDrawSurface_SetPriority
,
1407 Main_DirectDrawSurface_GetPriority
,
1408 Main_DirectDrawSurface_SetLOD
,
1409 Main_DirectDrawSurface_GetLOD