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 #include "wine/debug.h"
26 #include "ddraw_private.h"
27 #include "ddraw/user.h"
28 #include "ddraw/hal.h"
29 #include "dsurface/main.h"
30 #include "dsurface/dib.h"
31 #include "dsurface/user.h"
32 #include "dsurface/hal.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(ddraw
);
36 static ICOM_VTABLE(IDirectDrawSurface7
) HAL_IDirectDrawSurface7_VTable
;
38 static HRESULT
HAL_DirectDrawSurface_create_surface(IDirectDrawSurfaceImpl
* This
,
41 HAL_PRIV_VAR(priv
, This
);
42 HAL_DDRAW_PRIV_VAR(ddpriv
, pDD
);
43 LPDDRAWI_DIRECTDRAW_GBL dd_gbl
= pDD
->local
.lpGbl
;
44 LPDDRAWI_DDRAWSURFACE_LCL local
= &This
->local
;
45 DDHAL_CREATESURFACEDATA data
;
49 data
.lpDDSurfaceDesc
= (LPDDSURFACEDESC
)&This
->surface_desc
;
50 data
.lplpSList
= &local
;
53 data
.CreateSurface
= dd_gbl
->lpDDCBtmp
->HALDD
.CreateSurface
;
54 hr
= data
.CreateSurface(&data
);
56 if (hr
== DDHAL_DRIVER_HANDLED
) {
57 if (This
->global
.fpVidMem
< 4) {
58 /* grab framebuffer data from current_mode */
59 priv
->hal
.fb_pitch
= dd_gbl
->vmiData
.lDisplayPitch
;
60 priv
->hal
.fb_vofs
= ddpriv
->hal
.next_vofs
;
61 priv
->hal
.fb_addr
= ((LPBYTE
)dd_gbl
->vmiData
.fpPrimary
) +
62 dd_gbl
->vmiData
.lDisplayPitch
* priv
->hal
.fb_vofs
;
63 TRACE("vofs=%ld, addr=%p\n", priv
->hal
.fb_vofs
, priv
->hal
.fb_addr
);
64 ddpriv
->hal
.next_vofs
+= This
->surface_desc
.dwHeight
;
66 This
->global
.fpVidMem
= (FLATPTR
)priv
->hal
.fb_addr
;
67 This
->global
.u4
.lPitch
= priv
->hal
.fb_pitch
;
69 This
->surface_desc
.lpSurface
= (LPVOID
)This
->global
.fpVidMem
;
70 This
->surface_desc
.dwFlags
|= DDSD_LPSURFACE
;
71 if (This
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_EXECUTEBUFFER
) {
72 This
->surface_desc
.u1
.dwLinearSize
= This
->global
.u4
.dwLinearSize
;
73 This
->surface_desc
.dwFlags
|= DDSD_LINEARSIZE
;
75 This
->surface_desc
.u1
.lPitch
= This
->global
.u4
.lPitch
;
76 This
->surface_desc
.dwFlags
|= DDSD_PITCH
;
79 else priv
->hal
.need_late
= TRUE
;
84 static inline BOOL
HAL_IsUser(IDirectDrawSurfaceImpl
* This
)
86 HAL_PRIV_VAR(priv
, This
);
87 if (This
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_TEXTURE
| DDSCAPS_EXECUTEBUFFER
))
89 if (priv
->hal
.fb_addr
)
95 HAL_DirectDrawSurface_Construct(IDirectDrawSurfaceImpl
* This
,
97 const DDSURFACEDESC2
* pDDSD
)
99 HAL_PRIV_VAR(priv
, This
);
100 LPDDRAWI_DIRECTDRAW_GBL dd_gbl
= pDD
->local
.lpGbl
;
103 TRACE("(%p,%p,%p)\n",This
,pDD
,pDDSD
);
105 /* copy surface_desc, we may want to modify it before DIB construction */
106 This
->surface_desc
= *pDDSD
;
108 /* the driver may want to dereference these pointers */
109 This
->local
.lpSurfMore
= &This
->more
;
110 This
->local
.lpGbl
= &This
->global
;
111 This
->gmore
= &This
->global_more
;
113 if (This
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
) {
114 hr
= HAL_DirectDrawSurface_create_surface(This
, pDD
);
115 if (FAILED(hr
)) return hr
;
117 hr
= DIB_DirectDrawSurface_Construct(This
, pDD
, &This
->surface_desc
);
118 if (FAILED(hr
)) return hr
;
120 else if (This
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_EXECUTEBUFFER
) {
121 FIXME("create execute buffer\n");
122 return DDERR_GENERIC
;
125 if (!(dd_gbl
->dwFlags
& DDRAWI_MODECHANGED
)) {
126 /* force a mode set (HALs like DGA may need it) */
127 hr
= HAL_DirectDraw_SetDisplayMode(ICOM_INTERFACE(pDD
, IDirectDraw7
),
128 pDD
->width
, pDD
->height
,
129 pDD
->pixelformat
.u1
.dwRGBBitCount
,
131 if (FAILED(hr
)) return hr
;
134 if (dd_gbl
->vmiData
.fpPrimary
) {
135 hr
= HAL_DirectDrawSurface_create_surface(This
, pDD
);
136 if (FAILED(hr
)) return hr
;
138 if (priv
->hal
.need_late
) {
139 /* this doesn't make sense... driver error? */
140 ERR("driver failed to create framebuffer surface\n");
141 return DDERR_GENERIC
;
144 hr
= DIB_DirectDrawSurface_Construct(This
, pDD
, &This
->surface_desc
);
145 if (FAILED(hr
)) return hr
;
147 /* no framebuffer, construct User-based primary */
148 hr
= User_DirectDrawSurface_Construct(This
, pDD
, pDDSD
);
149 if (FAILED(hr
)) return hr
;
151 /* must notify HAL *after* creating User-based primary */
152 /* (or use CreateSurfaceEx, which we don't yet) */
153 hr
= HAL_DirectDrawSurface_create_surface(This
, pDD
);
154 if (FAILED(hr
)) return hr
;
156 priv
->hal
.need_late
= FALSE
;
160 ICOM_INIT_INTERFACE(This
, IDirectDrawSurface7
,
161 HAL_IDirectDrawSurface7_VTable
);
163 This
->final_release
= HAL_DirectDrawSurface_final_release
;
164 This
->late_allocate
= HAL_DirectDrawSurface_late_allocate
;
165 This
->duplicate_surface
= HAL_DirectDrawSurface_duplicate_surface
;
167 This
->flip_data
= HAL_DirectDrawSurface_flip_data
;
168 This
->flip_update
= HAL_DirectDrawSurface_flip_update
;
170 This
->set_palette
= HAL_DirectDrawSurface_set_palette
;
172 This
->get_display_window
= HAL_DirectDrawSurface_get_display_window
;
178 HAL_DirectDrawSurface_Create(IDirectDrawImpl
*pDD
,
179 const DDSURFACEDESC2
*pDDSD
,
180 LPDIRECTDRAWSURFACE7
*ppSurf
,
183 IDirectDrawSurfaceImpl
* This
;
185 assert(pUnkOuter
== NULL
);
187 This
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
188 sizeof(*This
) + sizeof(HAL_DirectDrawSurfaceImpl
));
189 if (This
== NULL
) return E_OUTOFMEMORY
;
191 This
->private = (HAL_DirectDrawSurfaceImpl
*)(This
+1);
193 hr
= HAL_DirectDrawSurface_Construct(This
, pDD
, pDDSD
);
195 HeapFree(GetProcessHeap(), 0, This
);
197 *ppSurf
= ICOM_INTERFACE(This
, IDirectDrawSurface7
);
202 void HAL_DirectDrawSurface_final_release(IDirectDrawSurfaceImpl
* This
)
204 LPDDRAWI_DIRECTDRAW_GBL dd_gbl
= This
->more
.lpDD_lcl
->lpGbl
;
205 DDHAL_DESTROYSURFACEDATA data
;
207 /* destroy HAL surface */
209 data
.lpDDSurface
= &This
->local
;
211 data
.DestroySurface
= dd_gbl
->lpDDCBtmp
->HALDDSurface
.DestroySurface
;
212 data
.DestroySurface(&data
);
214 if (HAL_IsUser(This
)) {
215 User_DirectDrawSurface_final_release(This
);
217 DIB_DirectDrawSurface_final_release(This
);
221 HRESULT
HAL_DirectDrawSurface_late_allocate(IDirectDrawSurfaceImpl
* This
)
223 HAL_PRIV_VAR(priv
, This
);
224 if (priv
->hal
.need_late
) {
225 priv
->hal
.need_late
= FALSE
;
226 return HAL_DirectDrawSurface_create_surface(This
, This
->ddraw_owner
);
231 void HAL_DirectDrawSurface_set_palette(IDirectDrawSurfaceImpl
* This
,
232 IDirectDrawPaletteImpl
* pal
)
234 LPDDRAWI_DIRECTDRAW_GBL dd_gbl
= This
->more
.lpDD_lcl
->lpGbl
;
235 DDHAL_SETPALETTEDATA data
;
237 DIB_DirectDrawSurface_set_palette(This
, pal
);
239 data
.lpDDSurface
= &This
->local
;
240 data
.lpDDPalette
= (pal
!= NULL
? &pal
->global
: NULL
);
242 data
.Attach
= TRUE
; /* what's this? */
243 data
.SetPalette
= dd_gbl
->lpDDCBtmp
->HALDDSurface
.SetPalette
;
245 data
.SetPalette(&data
);
248 HRESULT
HAL_DirectDrawSurface_duplicate_surface(IDirectDrawSurfaceImpl
* This
,
249 LPDIRECTDRAWSURFACE7
* ppDup
)
251 return HAL_DirectDrawSurface_Create(This
->ddraw_owner
,
252 &This
->surface_desc
, ppDup
, NULL
);
255 void HAL_DirectDrawSurface_lock_update(IDirectDrawSurfaceImpl
* This
,
256 LPCRECT pRect
, DWORD dwFlags
)
258 LPDDRAWI_DIRECTDRAW_GBL dd_gbl
= This
->more
.lpDD_lcl
->lpGbl
;
262 data
.lpDDSurface
= &This
->local
;
264 data
.lpSurfData
= This
->surface_desc
.lpSurface
; /* FIXME: correct? */
266 data
.rArea
.top
= pRect
->top
;
267 data
.rArea
.bottom
= pRect
->bottom
;
268 data
.rArea
.left
= pRect
->left
;
269 data
.rArea
.right
= pRect
->right
;
270 data
.bHasRect
= TRUE
;
272 data
.bHasRect
= FALSE
;
274 data
.dwFlags
= dwFlags
;
276 data
.Lock
= dd_gbl
->lpDDCBtmp
->HALDDSurface
.Lock
;
277 if (data
.Lock
&& (data
.Lock(&data
) == DDHAL_DRIVER_HANDLED
))
280 if (HAL_IsUser(This
)) {
281 User_DirectDrawSurface_lock_update(This
, pRect
, dwFlags
);
283 Main_DirectDrawSurface_lock_update(This
, pRect
, dwFlags
);
287 void HAL_DirectDrawSurface_unlock_update(IDirectDrawSurfaceImpl
* This
,
290 LPDDRAWI_DIRECTDRAW_GBL dd_gbl
= This
->more
.lpDD_lcl
->lpGbl
;
291 DDHAL_UNLOCKDATA data
;
294 data
.lpDDSurface
= &This
->local
;
296 data
.Unlock
= dd_gbl
->lpDDCBtmp
->HALDDSurface
.Unlock
;
297 if (data
.Unlock
&& (data
.Unlock(&data
) == DDHAL_DRIVER_HANDLED
))
300 if (HAL_IsUser(This
)) {
301 User_DirectDrawSurface_unlock_update(This
, pRect
);
303 Main_DirectDrawSurface_unlock_update(This
, pRect
);
307 BOOL
HAL_DirectDrawSurface_flip_data(IDirectDrawSurfaceImpl
* front
,
308 IDirectDrawSurfaceImpl
* back
,
311 HAL_PRIV_VAR(front_priv
, front
);
312 HAL_PRIV_VAR(back_priv
, back
);
313 LPDDRAWI_DIRECTDRAW_GBL dd_gbl
= front
->more
.lpDD_lcl
->lpGbl
;
319 tmp
= front_priv
->hal
.fb_vofs
;
320 front_priv
->hal
.fb_vofs
= back_priv
->hal
.fb_vofs
;
321 back_priv
->hal
.fb_vofs
= tmp
;
325 tmp
= front_priv
->hal
.fb_addr
;
326 front_priv
->hal
.fb_addr
= back_priv
->hal
.fb_addr
;
327 back_priv
->hal
.fb_addr
= tmp
;
330 if (HAL_IsUser(front
)) {
331 ret
= User_DirectDrawSurface_flip_data(front
, back
, dwFlags
);
333 ret
= DIB_DirectDrawSurface_flip_data(front
, back
, dwFlags
);
336 TRACE("(%p,%p)\n",front
,back
);
338 data
.lpSurfCurr
= &front
->local
;
339 data
.lpSurfTarg
= &back
->local
;
340 data
.lpSurfCurrLeft
= NULL
;
341 data
.lpSurfTargLeft
= NULL
;
342 data
.dwFlags
= dwFlags
;
344 data
.Flip
= dd_gbl
->lpDDCBtmp
->HALDDSurface
.Flip
;
346 if (data
.Flip(&data
) == DDHAL_DRIVER_HANDLED
) ret
= FALSE
;
351 void HAL_DirectDrawSurface_flip_update(IDirectDrawSurfaceImpl
* This
, DWORD dwFlags
)
353 if (HAL_IsUser(This
)) {
354 User_DirectDrawSurface_flip_update(This
, dwFlags
);
358 HWND
HAL_DirectDrawSurface_get_display_window(IDirectDrawSurfaceImpl
* This
)
363 static ICOM_VTABLE(IDirectDrawSurface7
) HAL_IDirectDrawSurface7_VTable
=
365 Main_DirectDrawSurface_QueryInterface
,
366 Main_DirectDrawSurface_AddRef
,
367 Main_DirectDrawSurface_Release
,
368 Main_DirectDrawSurface_AddAttachedSurface
,
369 Main_DirectDrawSurface_AddOverlayDirtyRect
,
370 DIB_DirectDrawSurface_Blt
,
371 Main_DirectDrawSurface_BltBatch
,
372 DIB_DirectDrawSurface_BltFast
,
373 Main_DirectDrawSurface_DeleteAttachedSurface
,
374 Main_DirectDrawSurface_EnumAttachedSurfaces
,
375 Main_DirectDrawSurface_EnumOverlayZOrders
,
376 Main_DirectDrawSurface_Flip
,
377 Main_DirectDrawSurface_GetAttachedSurface
,
378 Main_DirectDrawSurface_GetBltStatus
,
379 Main_DirectDrawSurface_GetCaps
,
380 Main_DirectDrawSurface_GetClipper
,
381 Main_DirectDrawSurface_GetColorKey
,
382 Main_DirectDrawSurface_GetDC
,
383 Main_DirectDrawSurface_GetFlipStatus
,
384 Main_DirectDrawSurface_GetOverlayPosition
,
385 Main_DirectDrawSurface_GetPalette
,
386 Main_DirectDrawSurface_GetPixelFormat
,
387 Main_DirectDrawSurface_GetSurfaceDesc
,
388 Main_DirectDrawSurface_Initialize
,
389 Main_DirectDrawSurface_IsLost
,
390 Main_DirectDrawSurface_Lock
,
391 Main_DirectDrawSurface_ReleaseDC
,
392 DIB_DirectDrawSurface_Restore
,
393 Main_DirectDrawSurface_SetClipper
,
394 Main_DirectDrawSurface_SetColorKey
,
395 Main_DirectDrawSurface_SetOverlayPosition
,
396 Main_DirectDrawSurface_SetPalette
,
397 Main_DirectDrawSurface_Unlock
,
398 Main_DirectDrawSurface_UpdateOverlay
,
399 Main_DirectDrawSurface_UpdateOverlayDisplay
,
400 Main_DirectDrawSurface_UpdateOverlayZOrder
,
401 Main_DirectDrawSurface_GetDDInterface
,
402 Main_DirectDrawSurface_PageLock
,
403 Main_DirectDrawSurface_PageUnlock
,
404 DIB_DirectDrawSurface_SetSurfaceDesc
,
405 Main_DirectDrawSurface_SetPrivateData
,
406 Main_DirectDrawSurface_GetPrivateData
,
407 Main_DirectDrawSurface_FreePrivateData
,
408 Main_DirectDrawSurface_GetUniquenessValue
,
409 Main_DirectDrawSurface_ChangeUniquenessValue
,
410 Main_DirectDrawSurface_SetPriority
,
411 Main_DirectDrawSurface_GetPriority
,
412 Main_DirectDrawSurface_SetLOD
,
413 Main_DirectDrawSurface_GetLOD