1 /* DirectDrawSurface HAL driver
3 * Copyright 2001 TransGaming Technologies Inc.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #define NONAMELESSUNION
26 #define NONAMELESSSTRUCT
30 #include "wine/debug.h"
31 #include "ddraw_private.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(ddraw
);
35 static const IDirectDrawSurface7Vtbl HAL_IDirectDrawSurface7_VTable
;
37 static HRESULT
HAL_DirectDrawSurface_create_surface(IDirectDrawSurfaceImpl
* This
,
40 HAL_PRIV_VAR(priv
, This
);
41 HAL_DDRAW_PRIV_VAR(ddpriv
, pDD
);
42 LPDDRAWI_DIRECTDRAW_GBL dd_gbl
= pDD
->local
.lpGbl
;
43 LPDDRAWI_DDRAWSURFACE_LCL local
= &This
->local
;
44 DDHAL_CREATESURFACEDATA data
;
48 data
.lpDDSurfaceDesc
= (LPDDSURFACEDESC
)&This
->surface_desc
;
49 data
.lplpSList
= &local
;
52 data
.CreateSurface
= dd_gbl
->lpDDCBtmp
->HALDD
.CreateSurface
;
53 hr
= data
.CreateSurface(&data
);
55 if (hr
== DDHAL_DRIVER_HANDLED
) {
56 if (This
->global
.fpVidMem
< 4) {
57 /* grab framebuffer data from current_mode */
58 priv
->hal
.fb_pitch
= dd_gbl
->vmiData
.lDisplayPitch
;
59 priv
->hal
.fb_vofs
= ddpriv
->hal
.next_vofs
;
60 priv
->hal
.fb_addr
= ((LPBYTE
)dd_gbl
->vmiData
.fpPrimary
) +
61 dd_gbl
->vmiData
.lDisplayPitch
* priv
->hal
.fb_vofs
;
62 TRACE("vofs=%ld, addr=%p\n", priv
->hal
.fb_vofs
, priv
->hal
.fb_addr
);
63 ddpriv
->hal
.next_vofs
+= This
->surface_desc
.dwHeight
;
65 This
->global
.fpVidMem
= (FLATPTR
)priv
->hal
.fb_addr
;
66 This
->global
.u4
.lPitch
= priv
->hal
.fb_pitch
;
68 This
->surface_desc
.lpSurface
= (LPVOID
)This
->global
.fpVidMem
;
69 This
->surface_desc
.dwFlags
|= DDSD_LPSURFACE
;
70 if (This
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_EXECUTEBUFFER
) {
71 This
->surface_desc
.u1
.dwLinearSize
= This
->global
.u4
.dwLinearSize
;
72 This
->surface_desc
.dwFlags
|= DDSD_LINEARSIZE
;
74 This
->surface_desc
.u1
.lPitch
= This
->global
.u4
.lPitch
;
75 This
->surface_desc
.dwFlags
|= DDSD_PITCH
;
78 else priv
->hal
.need_late
= TRUE
;
83 static inline BOOL
HAL_IsUser(IDirectDrawSurfaceImpl
* This
)
85 HAL_PRIV_VAR(priv
, This
);
86 if (This
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_TEXTURE
| DDSCAPS_EXECUTEBUFFER
))
88 if (priv
->hal
.fb_addr
)
94 HAL_DirectDrawSurface_Construct(IDirectDrawSurfaceImpl
* This
,
96 const DDSURFACEDESC2
* pDDSD
)
98 HAL_PRIV_VAR(priv
, This
);
99 LPDDRAWI_DIRECTDRAW_GBL dd_gbl
= pDD
->local
.lpGbl
;
102 TRACE("(%p,%p,%p)\n",This
,pDD
,pDDSD
);
104 /* copy surface_desc, we may want to modify it before DIB construction */
105 This
->surface_desc
= *pDDSD
;
107 /* the driver may want to dereference these pointers */
108 This
->local
.lpSurfMore
= &This
->more
;
109 This
->local
.lpGbl
= &This
->global
;
110 This
->gmore
= &This
->global_more
;
112 if (This
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
) {
113 hr
= HAL_DirectDrawSurface_create_surface(This
, pDD
);
114 if (FAILED(hr
)) return hr
;
116 hr
= DIB_DirectDrawSurface_Construct(This
, pDD
, &This
->surface_desc
);
117 if (FAILED(hr
)) return hr
;
119 else if (This
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_EXECUTEBUFFER
) {
120 FIXME("create execute buffer\n");
121 return DDERR_GENERIC
;
124 if (!(dd_gbl
->dwFlags
& DDRAWI_MODECHANGED
)) {
125 /* force a mode set (HALs like DGA may need it) */
126 hr
= HAL_DirectDraw_SetDisplayMode(ICOM_INTERFACE(pDD
, IDirectDraw7
),
127 pDD
->width
, pDD
->height
,
128 pDD
->pixelformat
.u1
.dwRGBBitCount
,
130 if (FAILED(hr
)) return hr
;
133 if (dd_gbl
->vmiData
.fpPrimary
) {
134 hr
= HAL_DirectDrawSurface_create_surface(This
, pDD
);
135 if (FAILED(hr
)) return hr
;
137 if (priv
->hal
.need_late
) {
138 /* this doesn't make sense... driver error? */
139 ERR("driver failed to create framebuffer surface\n");
140 return DDERR_GENERIC
;
143 hr
= DIB_DirectDrawSurface_Construct(This
, pDD
, &This
->surface_desc
);
144 if (FAILED(hr
)) return hr
;
146 /* no framebuffer, construct User-based primary */
147 hr
= User_DirectDrawSurface_Construct(This
, pDD
, pDDSD
);
148 if (FAILED(hr
)) return hr
;
150 /* must notify HAL *after* creating User-based primary */
151 /* (or use CreateSurfaceEx, which we don't yet) */
152 hr
= HAL_DirectDrawSurface_create_surface(This
, pDD
);
153 if (FAILED(hr
)) return hr
;
155 priv
->hal
.need_late
= FALSE
;
159 ICOM_INIT_INTERFACE(This
, IDirectDrawSurface7
,
160 HAL_IDirectDrawSurface7_VTable
);
162 This
->final_release
= HAL_DirectDrawSurface_final_release
;
163 This
->late_allocate
= HAL_DirectDrawSurface_late_allocate
;
164 This
->duplicate_surface
= HAL_DirectDrawSurface_duplicate_surface
;
166 This
->flip_data
= HAL_DirectDrawSurface_flip_data
;
167 This
->flip_update
= HAL_DirectDrawSurface_flip_update
;
169 This
->set_palette
= HAL_DirectDrawSurface_set_palette
;
171 This
->get_display_window
= HAL_DirectDrawSurface_get_display_window
;
177 HAL_DirectDrawSurface_Create(IDirectDrawImpl
*pDD
,
178 const DDSURFACEDESC2
*pDDSD
,
179 LPDIRECTDRAWSURFACE7
*ppSurf
,
182 IDirectDrawSurfaceImpl
* This
;
184 assert(pUnkOuter
== NULL
);
186 This
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
187 sizeof(*This
) + sizeof(HAL_DirectDrawSurfaceImpl
));
188 if (This
== NULL
) return E_OUTOFMEMORY
;
190 This
->private = (HAL_DirectDrawSurfaceImpl
*)(This
+1);
192 hr
= HAL_DirectDrawSurface_Construct(This
, pDD
, pDDSD
);
194 HeapFree(GetProcessHeap(), 0, This
);
196 *ppSurf
= ICOM_INTERFACE(This
, IDirectDrawSurface7
);
201 void HAL_DirectDrawSurface_final_release(IDirectDrawSurfaceImpl
* This
)
203 LPDDRAWI_DIRECTDRAW_GBL dd_gbl
= This
->more
.lpDD_lcl
->lpGbl
;
204 DDHAL_DESTROYSURFACEDATA data
;
206 /* destroy HAL surface */
208 data
.lpDDSurface
= &This
->local
;
210 data
.DestroySurface
= dd_gbl
->lpDDCBtmp
->HALDDSurface
.DestroySurface
;
211 data
.DestroySurface(&data
);
213 if (HAL_IsUser(This
)) {
214 User_DirectDrawSurface_final_release(This
);
216 DIB_DirectDrawSurface_final_release(This
);
220 HRESULT
HAL_DirectDrawSurface_late_allocate(IDirectDrawSurfaceImpl
* This
)
222 HAL_PRIV_VAR(priv
, This
);
223 if (priv
->hal
.need_late
) {
224 priv
->hal
.need_late
= FALSE
;
225 return HAL_DirectDrawSurface_create_surface(This
, This
->ddraw_owner
);
230 void HAL_DirectDrawSurface_set_palette(IDirectDrawSurfaceImpl
* This
,
231 IDirectDrawPaletteImpl
* pal
)
233 LPDDRAWI_DIRECTDRAW_GBL dd_gbl
= This
->more
.lpDD_lcl
->lpGbl
;
234 DDHAL_SETPALETTEDATA data
;
236 DIB_DirectDrawSurface_set_palette(This
, pal
);
238 data
.lpDDSurface
= &This
->local
;
239 data
.lpDDPalette
= (pal
!= NULL
? &pal
->global
: NULL
);
241 data
.Attach
= TRUE
; /* what's this? */
242 data
.SetPalette
= dd_gbl
->lpDDCBtmp
->HALDDSurface
.SetPalette
;
244 data
.SetPalette(&data
);
247 HRESULT
HAL_DirectDrawSurface_duplicate_surface(IDirectDrawSurfaceImpl
* This
,
248 LPDIRECTDRAWSURFACE7
* ppDup
)
250 return HAL_DirectDrawSurface_Create(This
->ddraw_owner
,
251 &This
->surface_desc
, ppDup
, NULL
);
254 void HAL_DirectDrawSurface_lock_update(IDirectDrawSurfaceImpl
* This
,
255 LPCRECT pRect
, DWORD dwFlags
)
257 LPDDRAWI_DIRECTDRAW_GBL dd_gbl
= This
->more
.lpDD_lcl
->lpGbl
;
261 data
.lpDDSurface
= &This
->local
;
263 data
.lpSurfData
= This
->surface_desc
.lpSurface
; /* FIXME: correct? */
265 data
.rArea
.top
= pRect
->top
;
266 data
.rArea
.bottom
= pRect
->bottom
;
267 data
.rArea
.left
= pRect
->left
;
268 data
.rArea
.right
= pRect
->right
;
269 data
.bHasRect
= TRUE
;
271 data
.bHasRect
= FALSE
;
273 data
.dwFlags
= dwFlags
;
275 data
.Lock
= dd_gbl
->lpDDCBtmp
->HALDDSurface
.Lock
;
276 if (data
.Lock
&& (data
.Lock(&data
) == DDHAL_DRIVER_HANDLED
))
279 if (HAL_IsUser(This
)) {
280 User_DirectDrawSurface_lock_update(This
, pRect
, dwFlags
);
282 Main_DirectDrawSurface_lock_update(This
, pRect
, dwFlags
);
286 void HAL_DirectDrawSurface_unlock_update(IDirectDrawSurfaceImpl
* This
,
289 LPDDRAWI_DIRECTDRAW_GBL dd_gbl
= This
->more
.lpDD_lcl
->lpGbl
;
290 DDHAL_UNLOCKDATA data
;
293 data
.lpDDSurface
= &This
->local
;
295 data
.Unlock
= dd_gbl
->lpDDCBtmp
->HALDDSurface
.Unlock
;
296 if (data
.Unlock
&& (data
.Unlock(&data
) == DDHAL_DRIVER_HANDLED
))
299 if (HAL_IsUser(This
)) {
300 User_DirectDrawSurface_unlock_update(This
, pRect
);
302 Main_DirectDrawSurface_unlock_update(This
, pRect
);
306 BOOL
HAL_DirectDrawSurface_flip_data(IDirectDrawSurfaceImpl
* front
,
307 IDirectDrawSurfaceImpl
* back
,
310 HAL_PRIV_VAR(front_priv
, front
);
311 HAL_PRIV_VAR(back_priv
, back
);
312 LPDDRAWI_DIRECTDRAW_GBL dd_gbl
= front
->more
.lpDD_lcl
->lpGbl
;
318 tmp
= front_priv
->hal
.fb_vofs
;
319 front_priv
->hal
.fb_vofs
= back_priv
->hal
.fb_vofs
;
320 back_priv
->hal
.fb_vofs
= tmp
;
324 tmp
= front_priv
->hal
.fb_addr
;
325 front_priv
->hal
.fb_addr
= back_priv
->hal
.fb_addr
;
326 back_priv
->hal
.fb_addr
= tmp
;
329 if (HAL_IsUser(front
)) {
330 ret
= User_DirectDrawSurface_flip_data(front
, back
, dwFlags
);
332 ret
= DIB_DirectDrawSurface_flip_data(front
, back
, dwFlags
);
335 TRACE("(%p,%p)\n",front
,back
);
337 data
.lpSurfCurr
= &front
->local
;
338 data
.lpSurfTarg
= &back
->local
;
339 data
.lpSurfCurrLeft
= NULL
;
340 data
.lpSurfTargLeft
= NULL
;
341 data
.dwFlags
= dwFlags
;
343 data
.Flip
= dd_gbl
->lpDDCBtmp
->HALDDSurface
.Flip
;
345 if (data
.Flip(&data
) == DDHAL_DRIVER_HANDLED
) ret
= FALSE
;
350 void HAL_DirectDrawSurface_flip_update(IDirectDrawSurfaceImpl
* This
, DWORD dwFlags
)
352 if (HAL_IsUser(This
)) {
353 User_DirectDrawSurface_flip_update(This
, dwFlags
);
357 HWND
HAL_DirectDrawSurface_get_display_window(IDirectDrawSurfaceImpl
* This
)
362 static const IDirectDrawSurface7Vtbl HAL_IDirectDrawSurface7_VTable
=
364 Main_DirectDrawSurface_QueryInterface
,
365 Main_DirectDrawSurface_AddRef
,
366 Main_DirectDrawSurface_Release
,
367 Main_DirectDrawSurface_AddAttachedSurface
,
368 Main_DirectDrawSurface_AddOverlayDirtyRect
,
369 DIB_DirectDrawSurface_Blt
,
370 Main_DirectDrawSurface_BltBatch
,
371 DIB_DirectDrawSurface_BltFast
,
372 Main_DirectDrawSurface_DeleteAttachedSurface
,
373 Main_DirectDrawSurface_EnumAttachedSurfaces
,
374 Main_DirectDrawSurface_EnumOverlayZOrders
,
375 Main_DirectDrawSurface_Flip
,
376 Main_DirectDrawSurface_GetAttachedSurface
,
377 Main_DirectDrawSurface_GetBltStatus
,
378 Main_DirectDrawSurface_GetCaps
,
379 Main_DirectDrawSurface_GetClipper
,
380 Main_DirectDrawSurface_GetColorKey
,
381 Main_DirectDrawSurface_GetDC
,
382 Main_DirectDrawSurface_GetFlipStatus
,
383 Main_DirectDrawSurface_GetOverlayPosition
,
384 Main_DirectDrawSurface_GetPalette
,
385 Main_DirectDrawSurface_GetPixelFormat
,
386 Main_DirectDrawSurface_GetSurfaceDesc
,
387 Main_DirectDrawSurface_Initialize
,
388 Main_DirectDrawSurface_IsLost
,
389 Main_DirectDrawSurface_Lock
,
390 Main_DirectDrawSurface_ReleaseDC
,
391 DIB_DirectDrawSurface_Restore
,
392 Main_DirectDrawSurface_SetClipper
,
393 Main_DirectDrawSurface_SetColorKey
,
394 Main_DirectDrawSurface_SetOverlayPosition
,
395 Main_DirectDrawSurface_SetPalette
,
396 Main_DirectDrawSurface_Unlock
,
397 Main_DirectDrawSurface_UpdateOverlay
,
398 Main_DirectDrawSurface_UpdateOverlayDisplay
,
399 Main_DirectDrawSurface_UpdateOverlayZOrder
,
400 Main_DirectDrawSurface_GetDDInterface
,
401 Main_DirectDrawSurface_PageLock
,
402 Main_DirectDrawSurface_PageUnlock
,
403 DIB_DirectDrawSurface_SetSurfaceDesc
,
404 Main_DirectDrawSurface_SetPrivateData
,
405 Main_DirectDrawSurface_GetPrivateData
,
406 Main_DirectDrawSurface_FreePrivateData
,
407 Main_DirectDrawSurface_GetUniquenessValue
,
408 Main_DirectDrawSurface_ChangeUniquenessValue
,
409 Main_DirectDrawSurface_SetPriority
,
410 Main_DirectDrawSurface_GetPriority
,
411 Main_DirectDrawSurface_SetLOD
,
412 Main_DirectDrawSurface_GetLOD