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
27 #include "wine/debug.h"
28 #include "ddraw_private.h"
29 #include "ddraw/user.h"
30 #include "ddraw/hal.h"
31 #include "dsurface/main.h"
32 #include "dsurface/dib.h"
33 #include "dsurface/user.h"
34 #include "dsurface/hal.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(ddraw
);
38 static IDirectDrawSurface7Vtbl HAL_IDirectDrawSurface7_VTable
;
40 static HRESULT
HAL_DirectDrawSurface_create_surface(IDirectDrawSurfaceImpl
* This
,
43 HAL_PRIV_VAR(priv
, This
);
44 HAL_DDRAW_PRIV_VAR(ddpriv
, pDD
);
45 LPDDRAWI_DIRECTDRAW_GBL dd_gbl
= pDD
->local
.lpGbl
;
46 LPDDRAWI_DDRAWSURFACE_LCL local
= &This
->local
;
47 DDHAL_CREATESURFACEDATA data
;
51 data
.lpDDSurfaceDesc
= (LPDDSURFACEDESC
)&This
->surface_desc
;
52 data
.lplpSList
= &local
;
55 data
.CreateSurface
= dd_gbl
->lpDDCBtmp
->HALDD
.CreateSurface
;
56 hr
= data
.CreateSurface(&data
);
58 if (hr
== DDHAL_DRIVER_HANDLED
) {
59 if (This
->global
.fpVidMem
< 4) {
60 /* grab framebuffer data from current_mode */
61 priv
->hal
.fb_pitch
= dd_gbl
->vmiData
.lDisplayPitch
;
62 priv
->hal
.fb_vofs
= ddpriv
->hal
.next_vofs
;
63 priv
->hal
.fb_addr
= ((LPBYTE
)dd_gbl
->vmiData
.fpPrimary
) +
64 dd_gbl
->vmiData
.lDisplayPitch
* priv
->hal
.fb_vofs
;
65 TRACE("vofs=%ld, addr=%p\n", priv
->hal
.fb_vofs
, priv
->hal
.fb_addr
);
66 ddpriv
->hal
.next_vofs
+= This
->surface_desc
.dwHeight
;
68 This
->global
.fpVidMem
= (FLATPTR
)priv
->hal
.fb_addr
;
69 This
->global
.u4
.lPitch
= priv
->hal
.fb_pitch
;
71 This
->surface_desc
.lpSurface
= (LPVOID
)This
->global
.fpVidMem
;
72 This
->surface_desc
.dwFlags
|= DDSD_LPSURFACE
;
73 if (This
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_EXECUTEBUFFER
) {
74 This
->surface_desc
.u1
.dwLinearSize
= This
->global
.u4
.dwLinearSize
;
75 This
->surface_desc
.dwFlags
|= DDSD_LINEARSIZE
;
77 This
->surface_desc
.u1
.lPitch
= This
->global
.u4
.lPitch
;
78 This
->surface_desc
.dwFlags
|= DDSD_PITCH
;
81 else priv
->hal
.need_late
= TRUE
;
86 static inline BOOL
HAL_IsUser(IDirectDrawSurfaceImpl
* This
)
88 HAL_PRIV_VAR(priv
, This
);
89 if (This
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_TEXTURE
| DDSCAPS_EXECUTEBUFFER
))
91 if (priv
->hal
.fb_addr
)
97 HAL_DirectDrawSurface_Construct(IDirectDrawSurfaceImpl
* This
,
99 const DDSURFACEDESC2
* pDDSD
)
101 HAL_PRIV_VAR(priv
, This
);
102 LPDDRAWI_DIRECTDRAW_GBL dd_gbl
= pDD
->local
.lpGbl
;
105 TRACE("(%p,%p,%p)\n",This
,pDD
,pDDSD
);
107 /* copy surface_desc, we may want to modify it before DIB construction */
108 This
->surface_desc
= *pDDSD
;
110 /* the driver may want to dereference these pointers */
111 This
->local
.lpSurfMore
= &This
->more
;
112 This
->local
.lpGbl
= &This
->global
;
113 This
->gmore
= &This
->global_more
;
115 if (This
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
) {
116 hr
= HAL_DirectDrawSurface_create_surface(This
, pDD
);
117 if (FAILED(hr
)) return hr
;
119 hr
= DIB_DirectDrawSurface_Construct(This
, pDD
, &This
->surface_desc
);
120 if (FAILED(hr
)) return hr
;
122 else if (This
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_EXECUTEBUFFER
) {
123 FIXME("create execute buffer\n");
124 return DDERR_GENERIC
;
127 if (!(dd_gbl
->dwFlags
& DDRAWI_MODECHANGED
)) {
128 /* force a mode set (HALs like DGA may need it) */
129 hr
= HAL_DirectDraw_SetDisplayMode(ICOM_INTERFACE(pDD
, IDirectDraw7
),
130 pDD
->width
, pDD
->height
,
131 pDD
->pixelformat
.u1
.dwRGBBitCount
,
133 if (FAILED(hr
)) return hr
;
136 if (dd_gbl
->vmiData
.fpPrimary
) {
137 hr
= HAL_DirectDrawSurface_create_surface(This
, pDD
);
138 if (FAILED(hr
)) return hr
;
140 if (priv
->hal
.need_late
) {
141 /* this doesn't make sense... driver error? */
142 ERR("driver failed to create framebuffer surface\n");
143 return DDERR_GENERIC
;
146 hr
= DIB_DirectDrawSurface_Construct(This
, pDD
, &This
->surface_desc
);
147 if (FAILED(hr
)) return hr
;
149 /* no framebuffer, construct User-based primary */
150 hr
= User_DirectDrawSurface_Construct(This
, pDD
, pDDSD
);
151 if (FAILED(hr
)) return hr
;
153 /* must notify HAL *after* creating User-based primary */
154 /* (or use CreateSurfaceEx, which we don't yet) */
155 hr
= HAL_DirectDrawSurface_create_surface(This
, pDD
);
156 if (FAILED(hr
)) return hr
;
158 priv
->hal
.need_late
= FALSE
;
162 ICOM_INIT_INTERFACE(This
, IDirectDrawSurface7
,
163 HAL_IDirectDrawSurface7_VTable
);
165 This
->final_release
= HAL_DirectDrawSurface_final_release
;
166 This
->late_allocate
= HAL_DirectDrawSurface_late_allocate
;
167 This
->duplicate_surface
= HAL_DirectDrawSurface_duplicate_surface
;
169 This
->flip_data
= HAL_DirectDrawSurface_flip_data
;
170 This
->flip_update
= HAL_DirectDrawSurface_flip_update
;
172 This
->set_palette
= HAL_DirectDrawSurface_set_palette
;
174 This
->get_display_window
= HAL_DirectDrawSurface_get_display_window
;
180 HAL_DirectDrawSurface_Create(IDirectDrawImpl
*pDD
,
181 const DDSURFACEDESC2
*pDDSD
,
182 LPDIRECTDRAWSURFACE7
*ppSurf
,
185 IDirectDrawSurfaceImpl
* This
;
187 assert(pUnkOuter
== NULL
);
189 This
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
190 sizeof(*This
) + sizeof(HAL_DirectDrawSurfaceImpl
));
191 if (This
== NULL
) return E_OUTOFMEMORY
;
193 This
->private = (HAL_DirectDrawSurfaceImpl
*)(This
+1);
195 hr
= HAL_DirectDrawSurface_Construct(This
, pDD
, pDDSD
);
197 HeapFree(GetProcessHeap(), 0, This
);
199 *ppSurf
= ICOM_INTERFACE(This
, IDirectDrawSurface7
);
204 void HAL_DirectDrawSurface_final_release(IDirectDrawSurfaceImpl
* This
)
206 LPDDRAWI_DIRECTDRAW_GBL dd_gbl
= This
->more
.lpDD_lcl
->lpGbl
;
207 DDHAL_DESTROYSURFACEDATA data
;
209 /* destroy HAL surface */
211 data
.lpDDSurface
= &This
->local
;
213 data
.DestroySurface
= dd_gbl
->lpDDCBtmp
->HALDDSurface
.DestroySurface
;
214 data
.DestroySurface(&data
);
216 if (HAL_IsUser(This
)) {
217 User_DirectDrawSurface_final_release(This
);
219 DIB_DirectDrawSurface_final_release(This
);
223 HRESULT
HAL_DirectDrawSurface_late_allocate(IDirectDrawSurfaceImpl
* This
)
225 HAL_PRIV_VAR(priv
, This
);
226 if (priv
->hal
.need_late
) {
227 priv
->hal
.need_late
= FALSE
;
228 return HAL_DirectDrawSurface_create_surface(This
, This
->ddraw_owner
);
233 void HAL_DirectDrawSurface_set_palette(IDirectDrawSurfaceImpl
* This
,
234 IDirectDrawPaletteImpl
* pal
)
236 LPDDRAWI_DIRECTDRAW_GBL dd_gbl
= This
->more
.lpDD_lcl
->lpGbl
;
237 DDHAL_SETPALETTEDATA data
;
239 DIB_DirectDrawSurface_set_palette(This
, pal
);
241 data
.lpDDSurface
= &This
->local
;
242 data
.lpDDPalette
= (pal
!= NULL
? &pal
->global
: NULL
);
244 data
.Attach
= TRUE
; /* what's this? */
245 data
.SetPalette
= dd_gbl
->lpDDCBtmp
->HALDDSurface
.SetPalette
;
247 data
.SetPalette(&data
);
250 HRESULT
HAL_DirectDrawSurface_duplicate_surface(IDirectDrawSurfaceImpl
* This
,
251 LPDIRECTDRAWSURFACE7
* ppDup
)
253 return HAL_DirectDrawSurface_Create(This
->ddraw_owner
,
254 &This
->surface_desc
, ppDup
, NULL
);
257 void HAL_DirectDrawSurface_lock_update(IDirectDrawSurfaceImpl
* This
,
258 LPCRECT pRect
, DWORD dwFlags
)
260 LPDDRAWI_DIRECTDRAW_GBL dd_gbl
= This
->more
.lpDD_lcl
->lpGbl
;
264 data
.lpDDSurface
= &This
->local
;
266 data
.lpSurfData
= This
->surface_desc
.lpSurface
; /* FIXME: correct? */
268 data
.rArea
.top
= pRect
->top
;
269 data
.rArea
.bottom
= pRect
->bottom
;
270 data
.rArea
.left
= pRect
->left
;
271 data
.rArea
.right
= pRect
->right
;
272 data
.bHasRect
= TRUE
;
274 data
.bHasRect
= FALSE
;
276 data
.dwFlags
= dwFlags
;
278 data
.Lock
= dd_gbl
->lpDDCBtmp
->HALDDSurface
.Lock
;
279 if (data
.Lock
&& (data
.Lock(&data
) == DDHAL_DRIVER_HANDLED
))
282 if (HAL_IsUser(This
)) {
283 User_DirectDrawSurface_lock_update(This
, pRect
, dwFlags
);
285 Main_DirectDrawSurface_lock_update(This
, pRect
, dwFlags
);
289 void HAL_DirectDrawSurface_unlock_update(IDirectDrawSurfaceImpl
* This
,
292 LPDDRAWI_DIRECTDRAW_GBL dd_gbl
= This
->more
.lpDD_lcl
->lpGbl
;
293 DDHAL_UNLOCKDATA data
;
296 data
.lpDDSurface
= &This
->local
;
298 data
.Unlock
= dd_gbl
->lpDDCBtmp
->HALDDSurface
.Unlock
;
299 if (data
.Unlock
&& (data
.Unlock(&data
) == DDHAL_DRIVER_HANDLED
))
302 if (HAL_IsUser(This
)) {
303 User_DirectDrawSurface_unlock_update(This
, pRect
);
305 Main_DirectDrawSurface_unlock_update(This
, pRect
);
309 BOOL
HAL_DirectDrawSurface_flip_data(IDirectDrawSurfaceImpl
* front
,
310 IDirectDrawSurfaceImpl
* back
,
313 HAL_PRIV_VAR(front_priv
, front
);
314 HAL_PRIV_VAR(back_priv
, back
);
315 LPDDRAWI_DIRECTDRAW_GBL dd_gbl
= front
->more
.lpDD_lcl
->lpGbl
;
321 tmp
= front_priv
->hal
.fb_vofs
;
322 front_priv
->hal
.fb_vofs
= back_priv
->hal
.fb_vofs
;
323 back_priv
->hal
.fb_vofs
= tmp
;
327 tmp
= front_priv
->hal
.fb_addr
;
328 front_priv
->hal
.fb_addr
= back_priv
->hal
.fb_addr
;
329 back_priv
->hal
.fb_addr
= tmp
;
332 if (HAL_IsUser(front
)) {
333 ret
= User_DirectDrawSurface_flip_data(front
, back
, dwFlags
);
335 ret
= DIB_DirectDrawSurface_flip_data(front
, back
, dwFlags
);
338 TRACE("(%p,%p)\n",front
,back
);
340 data
.lpSurfCurr
= &front
->local
;
341 data
.lpSurfTarg
= &back
->local
;
342 data
.lpSurfCurrLeft
= NULL
;
343 data
.lpSurfTargLeft
= NULL
;
344 data
.dwFlags
= dwFlags
;
346 data
.Flip
= dd_gbl
->lpDDCBtmp
->HALDDSurface
.Flip
;
348 if (data
.Flip(&data
) == DDHAL_DRIVER_HANDLED
) ret
= FALSE
;
353 void HAL_DirectDrawSurface_flip_update(IDirectDrawSurfaceImpl
* This
, DWORD dwFlags
)
355 if (HAL_IsUser(This
)) {
356 User_DirectDrawSurface_flip_update(This
, dwFlags
);
360 HWND
HAL_DirectDrawSurface_get_display_window(IDirectDrawSurfaceImpl
* This
)
365 static IDirectDrawSurface7Vtbl HAL_IDirectDrawSurface7_VTable
=
367 Main_DirectDrawSurface_QueryInterface
,
368 Main_DirectDrawSurface_AddRef
,
369 Main_DirectDrawSurface_Release
,
370 Main_DirectDrawSurface_AddAttachedSurface
,
371 Main_DirectDrawSurface_AddOverlayDirtyRect
,
372 DIB_DirectDrawSurface_Blt
,
373 Main_DirectDrawSurface_BltBatch
,
374 DIB_DirectDrawSurface_BltFast
,
375 Main_DirectDrawSurface_DeleteAttachedSurface
,
376 Main_DirectDrawSurface_EnumAttachedSurfaces
,
377 Main_DirectDrawSurface_EnumOverlayZOrders
,
378 Main_DirectDrawSurface_Flip
,
379 Main_DirectDrawSurface_GetAttachedSurface
,
380 Main_DirectDrawSurface_GetBltStatus
,
381 Main_DirectDrawSurface_GetCaps
,
382 Main_DirectDrawSurface_GetClipper
,
383 Main_DirectDrawSurface_GetColorKey
,
384 Main_DirectDrawSurface_GetDC
,
385 Main_DirectDrawSurface_GetFlipStatus
,
386 Main_DirectDrawSurface_GetOverlayPosition
,
387 Main_DirectDrawSurface_GetPalette
,
388 Main_DirectDrawSurface_GetPixelFormat
,
389 Main_DirectDrawSurface_GetSurfaceDesc
,
390 Main_DirectDrawSurface_Initialize
,
391 Main_DirectDrawSurface_IsLost
,
392 Main_DirectDrawSurface_Lock
,
393 Main_DirectDrawSurface_ReleaseDC
,
394 DIB_DirectDrawSurface_Restore
,
395 Main_DirectDrawSurface_SetClipper
,
396 Main_DirectDrawSurface_SetColorKey
,
397 Main_DirectDrawSurface_SetOverlayPosition
,
398 Main_DirectDrawSurface_SetPalette
,
399 Main_DirectDrawSurface_Unlock
,
400 Main_DirectDrawSurface_UpdateOverlay
,
401 Main_DirectDrawSurface_UpdateOverlayDisplay
,
402 Main_DirectDrawSurface_UpdateOverlayZOrder
,
403 Main_DirectDrawSurface_GetDDInterface
,
404 Main_DirectDrawSurface_PageLock
,
405 Main_DirectDrawSurface_PageUnlock
,
406 DIB_DirectDrawSurface_SetSurfaceDesc
,
407 Main_DirectDrawSurface_SetPrivateData
,
408 Main_DirectDrawSurface_GetPrivateData
,
409 Main_DirectDrawSurface_FreePrivateData
,
410 Main_DirectDrawSurface_GetUniquenessValue
,
411 Main_DirectDrawSurface_ChangeUniquenessValue
,
412 Main_DirectDrawSurface_SetPriority
,
413 Main_DirectDrawSurface_GetPriority
,
414 Main_DirectDrawSurface_SetLOD
,
415 Main_DirectDrawSurface_GetLOD