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"
32 #include "ddraw/user.h"
33 #include "ddraw/hal.h"
34 #include "dsurface/main.h"
35 #include "dsurface/dib.h"
36 #include "dsurface/user.h"
37 #include "dsurface/hal.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
41 static const IDirectDrawSurface7Vtbl HAL_IDirectDrawSurface7_VTable;
43 static HRESULT HAL_DirectDrawSurface_create_surface(IDirectDrawSurfaceImpl* This,
46 HAL_PRIV_VAR(priv, This);
47 HAL_DDRAW_PRIV_VAR(ddpriv, pDD);
48 LPDDRAWI_DIRECTDRAW_GBL dd_gbl = pDD->local.lpGbl;
49 LPDDRAWI_DDRAWSURFACE_LCL local = &This->local;
50 DDHAL_CREATESURFACEDATA data;
54 data.lpDDSurfaceDesc = (LPDDSURFACEDESC)&This->surface_desc;
55 data.lplpSList = &local;
58 data.CreateSurface = dd_gbl->lpDDCBtmp->HALDD.CreateSurface;
59 hr = data.CreateSurface(&data);
61 if (hr == DDHAL_DRIVER_HANDLED) {
62 if (This->global.fpVidMem < 4) {
63 /* grab framebuffer data from current_mode */
64 priv->hal.fb_pitch = dd_gbl->vmiData.lDisplayPitch;
65 priv->hal.fb_vofs = ddpriv->hal.next_vofs;
66 priv->hal.fb_addr = ((LPBYTE)dd_gbl->vmiData.fpPrimary) +
67 dd_gbl->vmiData.lDisplayPitch * priv->hal.fb_vofs;
68 TRACE("vofs=%ld, addr=%p\n", priv->hal.fb_vofs, priv->hal.fb_addr);
69 ddpriv->hal.next_vofs += This->surface_desc.dwHeight;
71 This->global.fpVidMem = (FLATPTR)priv->hal.fb_addr;
72 This->global.u4.lPitch = priv->hal.fb_pitch;
74 This->surface_desc.lpSurface = (LPVOID)This->global.fpVidMem;
75 This->surface_desc.dwFlags |= DDSD_LPSURFACE;
76 if (This->surface_desc.ddsCaps.dwCaps & DDSCAPS_EXECUTEBUFFER) {
77 This->surface_desc.u1.dwLinearSize = This->global.u4.dwLinearSize;
78 This->surface_desc.dwFlags |= DDSD_LINEARSIZE;
80 This->surface_desc.u1.lPitch = This->global.u4.lPitch;
81 This->surface_desc.dwFlags |= DDSD_PITCH;
84 else priv->hal.need_late = TRUE;
89 static inline BOOL HAL_IsUser(IDirectDrawSurfaceImpl* This)
91 HAL_PRIV_VAR(priv, This);
92 if (This->surface_desc.ddsCaps.dwCaps & (DDSCAPS_TEXTURE | DDSCAPS_EXECUTEBUFFER))
94 if (priv->hal.fb_addr)
100 HAL_DirectDrawSurface_Construct(IDirectDrawSurfaceImpl* This,
101 IDirectDrawImpl* pDD,
102 const DDSURFACEDESC2* pDDSD)
104 HAL_PRIV_VAR(priv, This);
105 LPDDRAWI_DIRECTDRAW_GBL dd_gbl = pDD->local.lpGbl;
108 TRACE("(%p,%p,%p)\n",This,pDD,pDDSD);
110 /* copy surface_desc, we may want to modify it before DIB construction */
111 This->surface_desc = *pDDSD;
113 /* the driver may want to dereference these pointers */
114 This->local.lpSurfMore = &This->more;
115 This->local.lpGbl = &This->global;
116 This->gmore = &This->global_more;
118 if (This->surface_desc.ddsCaps.dwCaps & DDSCAPS_TEXTURE) {
119 hr = HAL_DirectDrawSurface_create_surface(This, pDD);
120 if (FAILED(hr)) return hr;
122 hr = DIB_DirectDrawSurface_Construct(This, pDD, &This->surface_desc);
123 if (FAILED(hr)) return hr;
125 else if (This->surface_desc.ddsCaps.dwCaps & DDSCAPS_EXECUTEBUFFER) {
126 FIXME("create execute buffer\n");
127 return DDERR_GENERIC;
130 if (!(dd_gbl->dwFlags & DDRAWI_MODECHANGED)) {
131 /* force a mode set (HALs like DGA may need it) */
132 hr = HAL_DirectDraw_SetDisplayMode(ICOM_INTERFACE(pDD, IDirectDraw7),
133 pDD->width, pDD->height,
134 pDD->pixelformat.u1.dwRGBBitCount,
136 if (FAILED(hr)) return hr;
139 if (dd_gbl->vmiData.fpPrimary) {
140 hr = HAL_DirectDrawSurface_create_surface(This, pDD);
141 if (FAILED(hr)) return hr;
143 if (priv->hal.need_late) {
144 /* this doesn't make sense... driver error? */
145 ERR("driver failed to create framebuffer surface\n");
146 return DDERR_GENERIC;
149 hr = DIB_DirectDrawSurface_Construct(This, pDD, &This->surface_desc);
150 if (FAILED(hr)) return hr;
152 /* no framebuffer, construct User-based primary */
153 hr = User_DirectDrawSurface_Construct(This, pDD, pDDSD);
154 if (FAILED(hr)) return hr;
156 /* must notify HAL *after* creating User-based primary */
157 /* (or use CreateSurfaceEx, which we don't yet) */
158 hr = HAL_DirectDrawSurface_create_surface(This, pDD);
159 if (FAILED(hr)) return hr;
161 priv->hal.need_late = FALSE;
165 ICOM_INIT_INTERFACE(This, IDirectDrawSurface7,
166 HAL_IDirectDrawSurface7_VTable);
168 This->final_release = HAL_DirectDrawSurface_final_release;
169 This->late_allocate = HAL_DirectDrawSurface_late_allocate;
170 This->duplicate_surface = HAL_DirectDrawSurface_duplicate_surface;
172 This->flip_data = HAL_DirectDrawSurface_flip_data;
173 This->flip_update = HAL_DirectDrawSurface_flip_update;
175 This->set_palette = HAL_DirectDrawSurface_set_palette;
177 This->get_display_window = HAL_DirectDrawSurface_get_display_window;
183 HAL_DirectDrawSurface_Create(IDirectDrawImpl *pDD,
184 const DDSURFACEDESC2 *pDDSD,
185 LPDIRECTDRAWSURFACE7 *ppSurf,
188 IDirectDrawSurfaceImpl* This;
190 assert(pUnkOuter == NULL);
192 This = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
193 sizeof(*This) + sizeof(HAL_DirectDrawSurfaceImpl));
194 if (This == NULL) return E_OUTOFMEMORY;
196 This->private = (HAL_DirectDrawSurfaceImpl*)(This+1);
198 hr = HAL_DirectDrawSurface_Construct(This, pDD, pDDSD);
200 HeapFree(GetProcessHeap(), 0, This);
202 *ppSurf = ICOM_INTERFACE(This, IDirectDrawSurface7);
207 void HAL_DirectDrawSurface_final_release(IDirectDrawSurfaceImpl* This)
209 LPDDRAWI_DIRECTDRAW_GBL dd_gbl = This->more.lpDD_lcl->lpGbl;
210 DDHAL_DESTROYSURFACEDATA data;
212 /* destroy HAL surface */
214 data.lpDDSurface = &This->local;
216 data.DestroySurface = dd_gbl->lpDDCBtmp->HALDDSurface.DestroySurface;
217 data.DestroySurface(&data);
219 if (HAL_IsUser(This)) {
220 User_DirectDrawSurface_final_release(This);
222 DIB_DirectDrawSurface_final_release(This);
226 HRESULT HAL_DirectDrawSurface_late_allocate(IDirectDrawSurfaceImpl* This)
228 HAL_PRIV_VAR(priv, This);
229 if (priv->hal.need_late) {
230 priv->hal.need_late = FALSE;
231 return HAL_DirectDrawSurface_create_surface(This, This->ddraw_owner);
236 void HAL_DirectDrawSurface_set_palette(IDirectDrawSurfaceImpl* This,
237 IDirectDrawPaletteImpl* pal)
239 LPDDRAWI_DIRECTDRAW_GBL dd_gbl = This->more.lpDD_lcl->lpGbl;
240 DDHAL_SETPALETTEDATA data;
242 DIB_DirectDrawSurface_set_palette(This, pal);
244 data.lpDDSurface = &This->local;
245 data.lpDDPalette = (pal != NULL ? &pal->global : NULL);
247 data.Attach = TRUE; /* what's this? */
248 data.SetPalette = dd_gbl->lpDDCBtmp->HALDDSurface.SetPalette;
250 data.SetPalette(&data);
253 HRESULT HAL_DirectDrawSurface_duplicate_surface(IDirectDrawSurfaceImpl* This,
254 LPDIRECTDRAWSURFACE7* ppDup)
256 return HAL_DirectDrawSurface_Create(This->ddraw_owner,
257 &This->surface_desc, ppDup, NULL);
260 void HAL_DirectDrawSurface_lock_update(IDirectDrawSurfaceImpl* This,
261 LPCRECT pRect, DWORD dwFlags)
263 LPDDRAWI_DIRECTDRAW_GBL dd_gbl = This->more.lpDD_lcl->lpGbl;
267 data.lpDDSurface = &This->local;
269 data.lpSurfData = This->surface_desc.lpSurface; /* FIXME: correct? */
271 data.rArea.top = pRect->top;
272 data.rArea.bottom = pRect->bottom;
273 data.rArea.left = pRect->left;
274 data.rArea.right = pRect->right;
275 data.bHasRect = TRUE;
277 data.bHasRect = FALSE;
279 data.dwFlags = dwFlags;
281 data.Lock = dd_gbl->lpDDCBtmp->HALDDSurface.Lock;
282 if (data.Lock && (data.Lock(&data) == DDHAL_DRIVER_HANDLED))
285 if (HAL_IsUser(This)) {
286 User_DirectDrawSurface_lock_update(This, pRect, dwFlags);
288 Main_DirectDrawSurface_lock_update(This, pRect, dwFlags);
292 void HAL_DirectDrawSurface_unlock_update(IDirectDrawSurfaceImpl* This,
295 LPDDRAWI_DIRECTDRAW_GBL dd_gbl = This->more.lpDD_lcl->lpGbl;
296 DDHAL_UNLOCKDATA data;
299 data.lpDDSurface = &This->local;
301 data.Unlock = dd_gbl->lpDDCBtmp->HALDDSurface.Unlock;
302 if (data.Unlock && (data.Unlock(&data) == DDHAL_DRIVER_HANDLED))
305 if (HAL_IsUser(This)) {
306 User_DirectDrawSurface_unlock_update(This, pRect);
308 Main_DirectDrawSurface_unlock_update(This, pRect);
312 BOOL HAL_DirectDrawSurface_flip_data(IDirectDrawSurfaceImpl* front,
313 IDirectDrawSurfaceImpl* back,
316 HAL_PRIV_VAR(front_priv, front);
317 HAL_PRIV_VAR(back_priv, back);
318 LPDDRAWI_DIRECTDRAW_GBL dd_gbl = front->more.lpDD_lcl->lpGbl;
324 tmp = front_priv->hal.fb_vofs;
325 front_priv->hal.fb_vofs = back_priv->hal.fb_vofs;
326 back_priv->hal.fb_vofs = tmp;
330 tmp = front_priv->hal.fb_addr;
331 front_priv->hal.fb_addr = back_priv->hal.fb_addr;
332 back_priv->hal.fb_addr = tmp;
335 if (HAL_IsUser(front)) {
336 ret = User_DirectDrawSurface_flip_data(front, back, dwFlags);
338 ret = DIB_DirectDrawSurface_flip_data(front, back, dwFlags);
341 TRACE("(%p,%p)\n",front,back);
343 data.lpSurfCurr = &front->local;
344 data.lpSurfTarg = &back->local;
345 data.lpSurfCurrLeft = NULL;
346 data.lpSurfTargLeft = NULL;
347 data.dwFlags = dwFlags;
349 data.Flip = dd_gbl->lpDDCBtmp->HALDDSurface.Flip;
351 if (data.Flip(&data) == DDHAL_DRIVER_HANDLED) ret = FALSE;
356 void HAL_DirectDrawSurface_flip_update(IDirectDrawSurfaceImpl* This, DWORD dwFlags)
358 if (HAL_IsUser(This)) {
359 User_DirectDrawSurface_flip_update(This, dwFlags);
363 HWND HAL_DirectDrawSurface_get_display_window(IDirectDrawSurfaceImpl* This)
368 static const IDirectDrawSurface7Vtbl HAL_IDirectDrawSurface7_VTable =
370 Main_DirectDrawSurface_QueryInterface,
371 Main_DirectDrawSurface_AddRef,
372 Main_DirectDrawSurface_Release,
373 Main_DirectDrawSurface_AddAttachedSurface,
374 Main_DirectDrawSurface_AddOverlayDirtyRect,
375 DIB_DirectDrawSurface_Blt,
376 Main_DirectDrawSurface_BltBatch,
377 DIB_DirectDrawSurface_BltFast,
378 Main_DirectDrawSurface_DeleteAttachedSurface,
379 Main_DirectDrawSurface_EnumAttachedSurfaces,
380 Main_DirectDrawSurface_EnumOverlayZOrders,
381 Main_DirectDrawSurface_Flip,
382 Main_DirectDrawSurface_GetAttachedSurface,
383 Main_DirectDrawSurface_GetBltStatus,
384 Main_DirectDrawSurface_GetCaps,
385 Main_DirectDrawSurface_GetClipper,
386 Main_DirectDrawSurface_GetColorKey,
387 Main_DirectDrawSurface_GetDC,
388 Main_DirectDrawSurface_GetFlipStatus,
389 Main_DirectDrawSurface_GetOverlayPosition,
390 Main_DirectDrawSurface_GetPalette,
391 Main_DirectDrawSurface_GetPixelFormat,
392 Main_DirectDrawSurface_GetSurfaceDesc,
393 Main_DirectDrawSurface_Initialize,
394 Main_DirectDrawSurface_IsLost,
395 Main_DirectDrawSurface_Lock,
396 Main_DirectDrawSurface_ReleaseDC,
397 DIB_DirectDrawSurface_Restore,
398 Main_DirectDrawSurface_SetClipper,
399 Main_DirectDrawSurface_SetColorKey,
400 Main_DirectDrawSurface_SetOverlayPosition,
401 Main_DirectDrawSurface_SetPalette,
402 Main_DirectDrawSurface_Unlock,
403 Main_DirectDrawSurface_UpdateOverlay,
404 Main_DirectDrawSurface_UpdateOverlayDisplay,
405 Main_DirectDrawSurface_UpdateOverlayZOrder,
406 Main_DirectDrawSurface_GetDDInterface,
407 Main_DirectDrawSurface_PageLock,
408 Main_DirectDrawSurface_PageUnlock,
409 DIB_DirectDrawSurface_SetSurfaceDesc,
410 Main_DirectDrawSurface_SetPrivateData,
411 Main_DirectDrawSurface_GetPrivateData,
412 Main_DirectDrawSurface_FreePrivateData,
413 Main_DirectDrawSurface_GetUniquenessValue,
414 Main_DirectDrawSurface_ChangeUniquenessValue,
415 Main_DirectDrawSurface_SetPriority,
416 Main_DirectDrawSurface_GetPriority,
417 Main_DirectDrawSurface_SetLOD,
418 Main_DirectDrawSurface_GetLOD