1 | /* $Id: VBoxDispDDraw.cpp 37423 2011-06-12 18:37:56Z vboxsync $ */
|
---|
2 |
|
---|
3 | /** @file
|
---|
4 | * VBox XPDM Display driver, DirectDraw callbacks
|
---|
5 | */
|
---|
6 |
|
---|
7 | /*
|
---|
8 | * Copyright (C) 2011 Oracle Corporation
|
---|
9 | *
|
---|
10 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
11 | * available from http://www.virtualbox.org. This file is free software;
|
---|
12 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
13 | * General Public License (GPL) as published by the Free Software
|
---|
14 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
15 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
16 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
17 | */
|
---|
18 |
|
---|
19 | #include "VBoxDisp.h"
|
---|
20 | #include "VBoxDispDDraw.h"
|
---|
21 | #include "VBoxDispMini.h"
|
---|
22 | #include <iprt/asm.h>
|
---|
23 |
|
---|
24 | /* Called to check if our driver can create surface with requested attributes */
|
---|
25 | DWORD APIENTRY VBoxDispDDCanCreateSurface(PDD_CANCREATESURFACEDATA lpCanCreateSurface)
|
---|
26 | {
|
---|
27 | PVBOXDISPDEV pDev = (PVBOXDISPDEV) lpCanCreateSurface->lpDD->dhpdev;
|
---|
28 | LOGF_ENTER();
|
---|
29 |
|
---|
30 | PDD_SURFACEDESC lpDDS = lpCanCreateSurface->lpDDSurfaceDesc;
|
---|
31 |
|
---|
32 | #ifdef VBOX_WITH_VIDEOHWACCEL
|
---|
33 | if(pDev->vhwa.bEnabled)
|
---|
34 | {
|
---|
35 | VBOXVHWACMD* pCmd;
|
---|
36 |
|
---|
37 | uint32_t unsupportedSCaps = VBoxDispVHWAUnsupportedDDSCAPS(lpDDS->ddsCaps.dwCaps);
|
---|
38 | if(unsupportedSCaps)
|
---|
39 | {
|
---|
40 | WARN(("unsupported ddscaps: %#x", unsupportedSCaps));
|
---|
41 | lpCanCreateSurface->ddRVal = DDERR_INVALIDCAPS;
|
---|
42 | return DDHAL_DRIVER_HANDLED;
|
---|
43 | }
|
---|
44 |
|
---|
45 | unsupportedSCaps = VBoxDispVHWAUnsupportedDDPFS(lpDDS->ddpfPixelFormat.dwFlags);
|
---|
46 | if(unsupportedSCaps)
|
---|
47 | {
|
---|
48 | WARN(("unsupported pixel format: %#x", unsupportedSCaps));
|
---|
49 | lpCanCreateSurface->ddRVal = DDERR_INVALIDPIXELFORMAT;
|
---|
50 | return DDHAL_DRIVER_HANDLED;
|
---|
51 | }
|
---|
52 |
|
---|
53 | pCmd = VBoxDispVHWACommandCreate(pDev, VBOXVHWACMD_TYPE_SURF_CANCREATE, sizeof(VBOXVHWACMD_SURF_CANCREATE));
|
---|
54 | if(pCmd)
|
---|
55 | {
|
---|
56 | int rc;
|
---|
57 | VBOXVHWACMD_SURF_CANCREATE *pBody = VBOXVHWACMD_BODY(pCmd, VBOXVHWACMD_SURF_CANCREATE);
|
---|
58 | memset(pBody, 0, sizeof(VBOXVHWACMD_SURF_CANCREATE));
|
---|
59 |
|
---|
60 | rc = VBoxDispVHWAFromDDSURFACEDESC(&pBody->SurfInfo, lpDDS);
|
---|
61 | pBody->u.in.bIsDifferentPixelFormat = lpCanCreateSurface->bIsDifferentPixelFormat;
|
---|
62 |
|
---|
63 | VBoxDispVHWACommandSubmit(pDev, pCmd);
|
---|
64 |
|
---|
65 | if (RT_SUCCESS(pCmd->rc))
|
---|
66 | {
|
---|
67 | if(pBody->u.out.ErrInfo)
|
---|
68 | {
|
---|
69 | lpCanCreateSurface->ddRVal = DDERR_GENERIC;
|
---|
70 | }
|
---|
71 | else
|
---|
72 | {
|
---|
73 | WARN(("pBody->u.out.ErrInfo = %#x", pBody->u.out.ErrInfo));
|
---|
74 | lpCanCreateSurface->ddRVal = DD_OK;
|
---|
75 | }
|
---|
76 | }
|
---|
77 | else
|
---|
78 | {
|
---|
79 | WARN(("VBoxDispVHWACommandSubmit failed with rc=%#x", rc));
|
---|
80 | lpCanCreateSurface->ddRVal = DDERR_GENERIC;
|
---|
81 | }
|
---|
82 | VBoxDispVHWACommandRelease(pDev, pCmd);
|
---|
83 | }
|
---|
84 | else
|
---|
85 | {
|
---|
86 | WARN(("VBoxDispVHWACommandCreate failed!"));
|
---|
87 | lpCanCreateSurface->ddRVal = DDERR_GENERIC;
|
---|
88 | }
|
---|
89 | return DDHAL_DRIVER_HANDLED;
|
---|
90 | }
|
---|
91 | #endif /*VBOX_WITH_VIDEOHWACCEL*/
|
---|
92 |
|
---|
93 | if (lpDDS->ddsCaps.dwCaps & DDSCAPS_ZBUFFER)
|
---|
94 | {
|
---|
95 | LOG(("No Z-Bufer support"));
|
---|
96 | lpCanCreateSurface->ddRVal = DDERR_UNSUPPORTED;
|
---|
97 | return DDHAL_DRIVER_HANDLED;
|
---|
98 | }
|
---|
99 | if (lpDDS->ddsCaps.dwCaps & DDSCAPS_TEXTURE)
|
---|
100 | {
|
---|
101 | LOG(("No texture support"));
|
---|
102 | lpCanCreateSurface->ddRVal = DDERR_UNSUPPORTED;
|
---|
103 | return DDHAL_DRIVER_HANDLED;
|
---|
104 | }
|
---|
105 | if (lpCanCreateSurface->bIsDifferentPixelFormat && (lpDDS->ddpfPixelFormat.dwFlags & DDPF_FOURCC))
|
---|
106 | {
|
---|
107 | LOG(("FOURCC not supported"));
|
---|
108 | lpCanCreateSurface->ddRVal = DDERR_UNSUPPORTED;
|
---|
109 | return DDHAL_DRIVER_HANDLED;
|
---|
110 | }
|
---|
111 |
|
---|
112 | lpCanCreateSurface->ddRVal = DD_OK;
|
---|
113 | LOGF_LEAVE();
|
---|
114 | return DDHAL_DRIVER_HANDLED;
|
---|
115 | }
|
---|
116 |
|
---|
117 | /* Called to create DirectDraw surface.
|
---|
118 | * Note: we always return DDHAL_DRIVER_NOTHANDLED, which asks DirectDraw memory manager
|
---|
119 | * to perform actual memory allocation in our DDraw heap.
|
---|
120 | */
|
---|
121 | DWORD APIENTRY VBoxDispDDCreateSurface(PDD_CREATESURFACEDATA lpCreateSurface)
|
---|
122 | {
|
---|
123 | PVBOXDISPDEV pDev = (PVBOXDISPDEV) lpCreateSurface->lpDD->dhpdev;
|
---|
124 | LOGF_ENTER();
|
---|
125 |
|
---|
126 | PDD_SURFACE_LOCAL pSurf = lpCreateSurface->lplpSList[0];
|
---|
127 |
|
---|
128 | if (pSurf->ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
|
---|
129 | {
|
---|
130 | LOG(("primary surface"));
|
---|
131 | pSurf->lpGbl->fpVidMem = 0;
|
---|
132 | }
|
---|
133 | else
|
---|
134 | {
|
---|
135 | LOG(("non primary surface"));
|
---|
136 | pSurf->lpGbl->fpVidMem = DDHAL_PLEASEALLOC_BLOCKSIZE;
|
---|
137 | }
|
---|
138 | pSurf->lpGbl->dwReserved1 = 0;
|
---|
139 |
|
---|
140 | #ifdef VBOX_WITH_VIDEOHWACCEL
|
---|
141 | if(pDev->vhwa.bEnabled)
|
---|
142 | {
|
---|
143 | VBOXVHWACMD* pCmd;
|
---|
144 |
|
---|
145 | pCmd = VBoxDispVHWACommandCreate(pDev, VBOXVHWACMD_TYPE_SURF_CREATE, sizeof(VBOXVHWACMD_SURF_CREATE));
|
---|
146 | if (pCmd)
|
---|
147 | {
|
---|
148 | VBOXVHWACMD_SURF_CREATE *pBody = VBOXVHWACMD_BODY(pCmd, VBOXVHWACMD_SURF_CREATE);
|
---|
149 | PVBOXVHWASURFDESC pDesc;
|
---|
150 | int rc;
|
---|
151 |
|
---|
152 | memset(pBody, 0, sizeof(VBOXVHWACMD_SURF_CREATE));
|
---|
153 | rc = VBoxDispVHWAFromDDSURFACEDESC(&pBody->SurfInfo, lpCreateSurface->lpDDSurfaceDesc);
|
---|
154 | VBOX_WARNRC(rc);
|
---|
155 |
|
---|
156 | pBody->SurfInfo.surfCaps = VBoxDispVHWAFromDDSCAPS(pSurf->ddsCaps.dwCaps);
|
---|
157 | pBody->SurfInfo.flags |= DDSD_CAPS;
|
---|
158 |
|
---|
159 | pBody->SurfInfo.height = pSurf->lpGbl->wHeight;
|
---|
160 | pBody->SurfInfo.width = pSurf->lpGbl->wWidth;
|
---|
161 | pBody->SurfInfo.flags |= DDSD_HEIGHT | DDSD_WIDTH;
|
---|
162 |
|
---|
163 | VBoxDispVHWAFromDDPIXELFORMAT(&pBody->SurfInfo.PixelFormat, &pSurf->lpGbl->ddpfSurface);
|
---|
164 | pBody->SurfInfo.flags |= VBOXVHWA_SD_PIXELFORMAT;
|
---|
165 |
|
---|
166 | if (pSurf->ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
|
---|
167 | {
|
---|
168 | pBody->SurfInfo.offSurface = VBoxDispVHWAVramOffsetFromPDEV(pDev, 0);
|
---|
169 | }
|
---|
170 | else
|
---|
171 | {
|
---|
172 | pBody->SurfInfo.offSurface = VBOXVHWA_OFFSET64_VOID;
|
---|
173 | }
|
---|
174 |
|
---|
175 | pDesc = VBoxDispVHWASurfDescAlloc();
|
---|
176 | if (pDesc)
|
---|
177 | {
|
---|
178 | VBoxDispVHWACommandSubmit(pDev, pCmd);
|
---|
179 | if (RT_SUCCESS(pCmd->rc))
|
---|
180 | {
|
---|
181 | uint32_t surfSizeX = pBody->SurfInfo.sizeX;
|
---|
182 | uint32_t surfSizeY = pBody->SurfInfo.sizeY;
|
---|
183 | pDesc->hHostHandle = pBody->SurfInfo.hSurf;
|
---|
184 |
|
---|
185 | if(!!(pSurf->ddsCaps.dwCaps & DDSCAPS_OVERLAY)
|
---|
186 | && !!(pSurf->ddsCaps.dwCaps & DDSCAPS_VISIBLE))
|
---|
187 | {
|
---|
188 | pDesc->bVisible = true;
|
---|
189 | }
|
---|
190 |
|
---|
191 | pSurf->lpGbl->dwBlockSizeX = pBody->SurfInfo.sizeX;
|
---|
192 | pSurf->lpGbl->dwBlockSizeY = pBody->SurfInfo.sizeY;
|
---|
193 | pSurf->lpGbl->lPitch = pBody->SurfInfo.pitch;
|
---|
194 |
|
---|
195 | lpCreateSurface->lpDDSurfaceDesc->lPitch = pSurf->lpGbl->lPitch;
|
---|
196 | lpCreateSurface->lpDDSurfaceDesc->dwFlags |= DDSD_PITCH;
|
---|
197 |
|
---|
198 |
|
---|
199 | /*@todo: it's probably a memory leak, because DDDestroySurface wouldn't be called for
|
---|
200 | * primary surfaces.
|
---|
201 | */
|
---|
202 | pSurf->lpGbl->dwReserved1 = (ULONG_PTR)pDesc;
|
---|
203 | }
|
---|
204 | else
|
---|
205 | {
|
---|
206 | WARN(("VBoxDispVHWACommandSubmit failed with rc=%#x", rc));
|
---|
207 | VBoxDispVHWASurfDescFree(pDesc);
|
---|
208 | }
|
---|
209 | }
|
---|
210 | else
|
---|
211 | {
|
---|
212 | WARN(("VBoxDispVHWASurfDescAlloc failed"));
|
---|
213 | }
|
---|
214 | VBoxDispVHWACommandRelease(pDev, pCmd);
|
---|
215 | }
|
---|
216 | else
|
---|
217 | {
|
---|
218 | WARN(("VBoxDispVHWACommandCreate failed"));
|
---|
219 | }
|
---|
220 | return DDHAL_DRIVER_NOTHANDLED;
|
---|
221 | }
|
---|
222 | #endif /*VBOX_WITH_VIDEOHWACCEL*/
|
---|
223 |
|
---|
224 | LPDDSURFACEDESC pDesc = lpCreateSurface->lpDDSurfaceDesc;
|
---|
225 |
|
---|
226 | if (pDesc->ddpfPixelFormat.dwFlags & DDPF_PALETTEINDEXED4)
|
---|
227 | {
|
---|
228 | pSurf->lpGbl->lPitch = RT_ALIGN_T(pSurf->lpGbl->wWidth/2, 32, LONG);
|
---|
229 | }
|
---|
230 | else
|
---|
231 | if (pDesc->ddpfPixelFormat.dwFlags & DDPF_PALETTEINDEXED8)
|
---|
232 | {
|
---|
233 | pSurf->lpGbl->lPitch = RT_ALIGN_T(pSurf->lpGbl->wWidth, 32, LONG);
|
---|
234 | }
|
---|
235 | else
|
---|
236 | {
|
---|
237 | pSurf->lpGbl->lPitch = pSurf->lpGbl->wWidth*(pDesc->ddpfPixelFormat.dwRGBBitCount/8);
|
---|
238 | }
|
---|
239 |
|
---|
240 | pSurf->lpGbl->dwBlockSizeX = pSurf->lpGbl->lPitch;
|
---|
241 | pSurf->lpGbl->dwBlockSizeY = pSurf->lpGbl->wHeight;
|
---|
242 |
|
---|
243 | pDesc->lPitch = pSurf->lpGbl->lPitch;
|
---|
244 | pDesc->dwFlags |= DDSD_PITCH;
|
---|
245 |
|
---|
246 | LOGF_LEAVE();
|
---|
247 | return DDHAL_DRIVER_NOTHANDLED;
|
---|
248 | }
|
---|
249 |
|
---|
250 | /* Called to destroy DirectDraw surface,
|
---|
251 | * in particular we should free vhwa resources allocated on VBoxDispDDCreateSurface.
|
---|
252 | * Note: we're always returning DDHAL_DRIVER_NOTHANDLED because we rely on DirectDraw memory manager.
|
---|
253 | */
|
---|
254 | DWORD APIENTRY VBoxDispDDDestroySurface(PDD_DESTROYSURFACEDATA lpDestroySurface)
|
---|
255 | {
|
---|
256 | PVBOXDISPDEV pDev = (PVBOXDISPDEV) lpDestroySurface->lpDD->dhpdev;
|
---|
257 | LOGF_ENTER();
|
---|
258 |
|
---|
259 | lpDestroySurface->ddRVal = DD_OK;
|
---|
260 |
|
---|
261 | #ifdef VBOX_WITH_VIDEOHWACCEL
|
---|
262 | if (pDev->vhwa.bEnabled)
|
---|
263 | {
|
---|
264 | VBOXVHWACMD* pCmd;
|
---|
265 |
|
---|
266 | pCmd = VBoxDispVHWACommandCreate(pDev, VBOXVHWACMD_TYPE_SURF_DESTROY, sizeof(VBOXVHWACMD_SURF_DESTROY));
|
---|
267 | if (pCmd)
|
---|
268 | {
|
---|
269 | VBOXVHWACMD_SURF_DESTROY *pBody = VBOXVHWACMD_BODY(pCmd, VBOXVHWACMD_SURF_DESTROY);
|
---|
270 | PVBOXVHWASURFDESC pDesc = (PVBOXVHWASURFDESC)lpDestroySurface->lpDDSurface->lpGbl->dwReserved1;
|
---|
271 |
|
---|
272 | if (pDesc)
|
---|
273 | {
|
---|
274 | memset(pBody, 0, sizeof(VBOXVHWACMD_SURF_DESTROY));
|
---|
275 | pBody->u.in.hSurf = pDesc->hHostHandle;
|
---|
276 |
|
---|
277 | /* we're not interested in completion, just send the command */
|
---|
278 | VBoxDispVHWACommandSubmitAsynchAndComplete(pDev, pCmd);
|
---|
279 |
|
---|
280 | VBoxDispVHWASurfDescFree(pDesc);
|
---|
281 |
|
---|
282 | lpDestroySurface->lpDDSurface->lpGbl->dwReserved1 = (ULONG_PTR)NULL;
|
---|
283 | }
|
---|
284 | else
|
---|
285 | {
|
---|
286 | WARN(("!pDesc, memory overwrite somewhere?"));
|
---|
287 | lpDestroySurface->ddRVal = DDERR_GENERIC;
|
---|
288 | }
|
---|
289 | }
|
---|
290 | else
|
---|
291 | {
|
---|
292 | WARN(("VBoxDispVHWACommandCreate failed!"));
|
---|
293 | lpDestroySurface->ddRVal = DDERR_GENERIC;
|
---|
294 | }
|
---|
295 | }
|
---|
296 | else
|
---|
297 | #endif /*VBOX_WITH_VIDEOHWACCEL*/
|
---|
298 |
|
---|
299 | LOGF_LEAVE();
|
---|
300 | return DDHAL_DRIVER_NOTHANDLED;
|
---|
301 | }
|
---|
302 |
|
---|
303 | /* Called before first DDLock/after last DDUnlock to map/unmap surface memory from given process address space
|
---|
304 | * We go easy way and map whole framebuffer and offscreen DirectDraw heap every time.
|
---|
305 | */
|
---|
306 | DWORD APIENTRY VBoxDispDDMapMemory(PDD_MAPMEMORYDATA lpMapMemory)
|
---|
307 | {
|
---|
308 | PVBOXDISPDEV pDev = (PVBOXDISPDEV) lpMapMemory->lpDD->dhpdev;
|
---|
309 | VIDEO_SHARE_MEMORY smem;
|
---|
310 | int rc;
|
---|
311 | LOGF_ENTER();
|
---|
312 |
|
---|
313 | lpMapMemory->ddRVal = DDERR_GENERIC;
|
---|
314 |
|
---|
315 | memset(&smem, 0, sizeof(smem));
|
---|
316 | smem.ProcessHandle = lpMapMemory->hProcess;
|
---|
317 |
|
---|
318 | if (lpMapMemory->bMap)
|
---|
319 | {
|
---|
320 | VIDEO_SHARE_MEMORY_INFORMATION smemInfo;
|
---|
321 |
|
---|
322 | smem.ViewSize = pDev->layout.offDDrawHeap + pDev->layout.cbDDrawHeap;
|
---|
323 |
|
---|
324 | rc = VBoxDispMPShareVideoMemory(pDev->hDriver, &smem, &smemInfo);
|
---|
325 | VBOX_WARNRC_RETV(rc, DDHAL_DRIVER_HANDLED);
|
---|
326 |
|
---|
327 | lpMapMemory->fpProcess = (FLATPTR) smemInfo.VirtualAddress;
|
---|
328 | }
|
---|
329 | else
|
---|
330 | {
|
---|
331 | smem.RequestedVirtualAddress = (PVOID) lpMapMemory->fpProcess;
|
---|
332 |
|
---|
333 | rc = VBoxDispMPUnshareVideoMemory(pDev->hDriver, &smem);
|
---|
334 | VBOX_WARNRC_RETV(rc, DDHAL_DRIVER_HANDLED);
|
---|
335 | }
|
---|
336 |
|
---|
337 |
|
---|
338 | lpMapMemory->ddRVal = DD_OK;
|
---|
339 | LOGF_LEAVE();
|
---|
340 | return DDHAL_DRIVER_HANDLED;
|
---|
341 | }
|
---|
342 |
|
---|
343 | /* Lock specified area of surface */
|
---|
344 | DWORD APIENTRY VBoxDispDDLock(PDD_LOCKDATA lpLock)
|
---|
345 | {
|
---|
346 | PVBOXDISPDEV pDev = (PVBOXDISPDEV) lpLock->lpDD->dhpdev;
|
---|
347 | LOGF_ENTER();
|
---|
348 |
|
---|
349 | DD_SURFACE_LOCAL* pSurf = lpLock->lpDDSurface;
|
---|
350 |
|
---|
351 | lpLock->ddRVal = DD_OK;
|
---|
352 |
|
---|
353 | #ifdef VBOX_WITH_VIDEOHWACCEL
|
---|
354 | if(pDev->vhwa.bEnabled)
|
---|
355 | {
|
---|
356 | PVBOXVHWASURFDESC pDesc = (PVBOXVHWASURFDESC) pSurf->lpGbl->dwReserved1;
|
---|
357 | RECTL tmpRect, *pRect;
|
---|
358 |
|
---|
359 | if (!pDesc)
|
---|
360 | {
|
---|
361 | WARN(("!pDesc, memory overwrite somewhere?"));
|
---|
362 | lpLock->ddRVal = DDERR_GENERIC;
|
---|
363 | return DDHAL_DRIVER_HANDLED;
|
---|
364 | }
|
---|
365 |
|
---|
366 | /* Check if host is still processing drawing commands */
|
---|
367 | if (ASMAtomicUoReadU32(&pDesc->cPendingBltsSrc)
|
---|
368 | || ASMAtomicUoReadU32(&pDesc->cPendingFlipsCurr)
|
---|
369 | || ASMAtomicUoReadU32(&pDesc->cPendingBltsDst)
|
---|
370 | || ASMAtomicUoReadU32(&pDesc->cPendingFlipsTarg))
|
---|
371 | {
|
---|
372 | VBoxDispVHWACommandCheckHostCmds(pDev);
|
---|
373 | if(ASMAtomicUoReadU32(&pDesc->cPendingBltsSrc)
|
---|
374 | || ASMAtomicUoReadU32(&pDesc->cPendingFlipsCurr)
|
---|
375 | || ASMAtomicUoReadU32(&pDesc->cPendingBltsDst)
|
---|
376 | || ASMAtomicUoReadU32(&pDesc->cPendingFlipsTarg))
|
---|
377 | {
|
---|
378 | lpLock->ddRVal = DDERR_WASSTILLDRAWING;
|
---|
379 | return DDHAL_DRIVER_HANDLED;
|
---|
380 | }
|
---|
381 | }
|
---|
382 |
|
---|
383 | if (lpLock->bHasRect)
|
---|
384 | {
|
---|
385 | pRect = &lpLock->rArea;
|
---|
386 | }
|
---|
387 | else
|
---|
388 | {
|
---|
389 | tmpRect.left = 0;
|
---|
390 | tmpRect.top = 0;
|
---|
391 | tmpRect.right = pSurf->lpGbl->wWidth-1;
|
---|
392 | tmpRect.bottom = pSurf->lpGbl->wHeight-1;
|
---|
393 | pRect = &tmpRect;
|
---|
394 | }
|
---|
395 |
|
---|
396 | if (lpLock->dwFlags & DDLOCK_DISCARDCONTENTS)
|
---|
397 | {
|
---|
398 | VBoxDispVHWARegionTrySubstitute(&pDesc->NonupdatedMemRegion, pRect);
|
---|
399 | VBoxDispVHWARegionAdd(&pDesc->UpdatedMemRegion, pRect);
|
---|
400 | }
|
---|
401 | else if (!VBoxDispVHWARegionIntersects(&pDesc->NonupdatedMemRegion, pRect))
|
---|
402 | {
|
---|
403 | VBoxDispVHWARegionAdd(&pDesc->UpdatedMemRegion, pRect);
|
---|
404 | }
|
---|
405 | else
|
---|
406 | {
|
---|
407 | VBOXVHWACMD *pCmd;
|
---|
408 | pCmd = VBoxDispVHWACommandCreate(pDev, VBOXVHWACMD_TYPE_SURF_LOCK, sizeof(VBOXVHWACMD_SURF_LOCK));
|
---|
409 |
|
---|
410 | if (pCmd)
|
---|
411 | {
|
---|
412 | VBOXVHWACMD_SURF_LOCK *pBody = VBOXVHWACMD_BODY(pCmd, VBOXVHWACMD_SURF_LOCK);
|
---|
413 | memset(pBody, 0, sizeof(VBOXVHWACMD_SURF_LOCK));
|
---|
414 |
|
---|
415 | pBody->u.in.offSurface = VBoxDispVHWAVramOffsetFromPDEV(pDev, pSurf->lpGbl->fpVidMem);
|
---|
416 |
|
---|
417 | VBoxDispVHWAFromRECTL(&pBody->u.in.rect, &pDesc->NonupdatedMemRegion.Rect);
|
---|
418 | pBody->u.in.rectValid = 1;
|
---|
419 |
|
---|
420 | pBody->u.in.hSurf = pDesc->hHostHandle;
|
---|
421 |
|
---|
422 | /* wait for the surface to be locked and memory buffer updated */
|
---|
423 | VBoxDispVHWACommandSubmit(pDev, pCmd);
|
---|
424 | VBOX_WARNRC(pCmd->rc);
|
---|
425 | VBoxDispVHWACommandRelease(pDev, pCmd);
|
---|
426 | VBoxDispVHWARegionClear(&pDesc->NonupdatedMemRegion);
|
---|
427 | }
|
---|
428 | else
|
---|
429 | {
|
---|
430 | WARN(("VBoxDispVHWACommandCreate failed!"));
|
---|
431 | lpLock->ddRVal = DDERR_GENERIC;
|
---|
432 | }
|
---|
433 | }
|
---|
434 |
|
---|
435 | return DDHAL_DRIVER_NOTHANDLED;
|
---|
436 | }
|
---|
437 | #endif /*VBOX_WITH_VIDEOHWACCEL*/
|
---|
438 |
|
---|
439 | /* We only care about primary surface as we'd have to report dirty rectangles to the host in the DDUnlock*/
|
---|
440 | if (pSurf->ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
|
---|
441 | {
|
---|
442 | pDev->ddpsLock.bLocked = TRUE;
|
---|
443 |
|
---|
444 | if (lpLock->bHasRect)
|
---|
445 | {
|
---|
446 | pDev->ddpsLock.rect = lpLock->rArea;
|
---|
447 | }
|
---|
448 | else
|
---|
449 | {
|
---|
450 | pDev->ddpsLock.rect.left = 0;
|
---|
451 | pDev->ddpsLock.rect.top = 0;
|
---|
452 | pDev->ddpsLock.rect.right = pDev->mode.ulWidth;
|
---|
453 | pDev->ddpsLock.rect.bottom = pDev->mode.ulHeight;
|
---|
454 | }
|
---|
455 | }
|
---|
456 |
|
---|
457 | LOGF_LEAVE();
|
---|
458 | return DDHAL_DRIVER_NOTHANDLED;
|
---|
459 | }
|
---|
460 |
|
---|
461 | /* Unlock previously locked surface */
|
---|
462 | DWORD APIENTRY VBoxDispDDUnlock(PDD_UNLOCKDATA lpUnlock)
|
---|
463 | {
|
---|
464 | PVBOXDISPDEV pDev = (PVBOXDISPDEV) lpUnlock->lpDD->dhpdev;
|
---|
465 | LOGF_ENTER();
|
---|
466 |
|
---|
467 | DD_SURFACE_LOCAL *pSurf = lpUnlock->lpDDSurface;
|
---|
468 |
|
---|
469 | lpUnlock->ddRVal = DD_OK;
|
---|
470 |
|
---|
471 | #ifdef VBOX_WITH_VIDEOHWACCEL
|
---|
472 | if(pDev->vhwa.bEnabled)
|
---|
473 | {
|
---|
474 | PVBOXVHWASURFDESC pDesc = (PVBOXVHWASURFDESC) pSurf->lpGbl->dwReserved1;
|
---|
475 |
|
---|
476 | if (!pDesc)
|
---|
477 | {
|
---|
478 | WARN(("!pDesc, memory overwrite somewhere?"));
|
---|
479 | lpUnlock->ddRVal = DDERR_GENERIC;
|
---|
480 | return DDHAL_DRIVER_HANDLED;
|
---|
481 | }
|
---|
482 |
|
---|
483 | if((pSurf->ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE) && pDesc->UpdatedMemRegion.bValid
|
---|
484 | && VBoxVBVABufferBeginUpdate(&pDev->vbvaCtx, &pDev->hgsmi.ctx))
|
---|
485 | {
|
---|
486 | vbvaReportDirtyRect(pDev, &pDesc->UpdatedMemRegion.Rect);
|
---|
487 |
|
---|
488 | if (pDev->vbvaCtx.pVBVA->hostFlags.u32HostEvents & VBOX_VIDEO_INFO_HOST_EVENTS_F_VRDP_RESET)
|
---|
489 | {
|
---|
490 | vrdpReset(pDev);
|
---|
491 | pDev->vbvaCtx.pVBVA->hostFlags.u32HostEvents &= ~VBOX_VIDEO_INFO_HOST_EVENTS_F_VRDP_RESET;
|
---|
492 | }
|
---|
493 |
|
---|
494 | if (pDev->vbvaCtx.pVBVA->hostFlags.u32HostEvents & VBVA_F_MODE_VRDP)
|
---|
495 | {
|
---|
496 | vrdpReportDirtyRect(pDev, &pDesc->UpdatedMemRegion.Rect);
|
---|
497 | }
|
---|
498 |
|
---|
499 | VBoxVBVABufferEndUpdate(&pDev->vbvaCtx);
|
---|
500 | }
|
---|
501 | else if ((pSurf->ddsCaps.dwCaps & DDSCAPS_VISIBLE)
|
---|
502 | || ((pSurf->ddsCaps.dwCaps & DDSCAPS_OVERLAY) && pDesc->bVisible))
|
---|
503 | {
|
---|
504 | VBOXVHWACMD *pCmd;
|
---|
505 | pCmd = VBoxDispVHWACommandCreate (pDev, VBOXVHWACMD_TYPE_SURF_UNLOCK, sizeof(VBOXVHWACMD_SURF_UNLOCK));
|
---|
506 |
|
---|
507 | if(pCmd)
|
---|
508 | {
|
---|
509 | VBOXVHWACMD_SURF_UNLOCK *pBody = VBOXVHWACMD_BODY(pCmd, VBOXVHWACMD_SURF_UNLOCK);
|
---|
510 | memset(pBody, 0, sizeof(VBOXVHWACMD_SURF_UNLOCK));
|
---|
511 |
|
---|
512 | pBody->u.in.hSurf = pDesc->hHostHandle;
|
---|
513 | if(pDesc->UpdatedMemRegion.bValid)
|
---|
514 | {
|
---|
515 | pBody->u.in.xUpdatedMemValid = 1;
|
---|
516 | VBoxDispVHWAFromRECTL(&pBody->u.in.xUpdatedMemRect, &pDesc->UpdatedMemRegion.Rect);
|
---|
517 | VBoxDispVHWARegionClear(&pDesc->UpdatedMemRegion);
|
---|
518 | }
|
---|
519 |
|
---|
520 | VBoxDispVHWACommandSubmitAsynchAndComplete(pDev, pCmd);
|
---|
521 | }
|
---|
522 | else
|
---|
523 | {
|
---|
524 | WARN(("VBoxDispVHWACommandCreate failed!"));
|
---|
525 | lpUnlock->ddRVal = DDERR_GENERIC;
|
---|
526 | }
|
---|
527 |
|
---|
528 | }
|
---|
529 |
|
---|
530 | return DDHAL_DRIVER_NOTHANDLED;
|
---|
531 | }
|
---|
532 | #endif /*VBOX_WITH_VIDEOHWACCEL*/
|
---|
533 |
|
---|
534 | if (pDev->ddpsLock.bLocked)
|
---|
535 | {
|
---|
536 | pDev->ddpsLock.bLocked = FALSE;
|
---|
537 |
|
---|
538 | if (pDev->hgsmi.bSupported && VBoxVBVABufferBeginUpdate(&pDev->vbvaCtx, &pDev->hgsmi.ctx))
|
---|
539 | {
|
---|
540 | vbvaReportDirtyRect(pDev, &pDev->ddpsLock.rect);
|
---|
541 |
|
---|
542 | if (pDev->vbvaCtx.pVBVA->hostFlags.u32HostEvents & VBOX_VIDEO_INFO_HOST_EVENTS_F_VRDP_RESET)
|
---|
543 | {
|
---|
544 | vrdpReset(pDev);
|
---|
545 | pDev->vbvaCtx.pVBVA->hostFlags.u32HostEvents &= ~VBOX_VIDEO_INFO_HOST_EVENTS_F_VRDP_RESET;
|
---|
546 | }
|
---|
547 |
|
---|
548 | if (pDev->vbvaCtx.pVBVA->hostFlags.u32HostEvents & VBVA_F_MODE_VRDP)
|
---|
549 | {
|
---|
550 | vrdpReportDirtyRect(pDev, &pDev->ddpsLock.rect);
|
---|
551 | }
|
---|
552 |
|
---|
553 | VBoxVBVABufferEndUpdate(&pDev->vbvaCtx);
|
---|
554 | }
|
---|
555 | }
|
---|
556 |
|
---|
557 | LOGF_LEAVE();
|
---|
558 | return DDHAL_DRIVER_NOTHANDLED;
|
---|
559 | }
|
---|