VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/Graphics/Display/vhwa.c@ 24646

Last change on this file since 24646 was 24646, checked in by vboxsync, 15 years ago

2d accel:

  1. performmance: avoid separate drawing of primary surface texture
  2. profiling: fps counter
  3. saved state restore fix
  4. make vhwa command constants values match ddraw contstants
  5. guest driver: set proper ddRVal in DdUnlock
  6. guest driver: return proper value in DdDestroySurface
File size: 14.3 KB
Line 
1/* $Id$ */
2/** @file
3 * VBoxGuest -- VirtualBox Win 2000/XP guest display driver
4 *
5 * Video HW Acceleration support functions.
6 */
7
8/*
9 * Copyright (C) 2009 Sun Microsystems, Inc.
10 *
11 * This file is part of VirtualBox Open Source Edition (OSE), as
12 * available from http://www.virtualbox.org. This file is free software;
13 * you can redistribute it and/or modify it under the terms of the GNU
14 * General Public License (GPL) as published by the Free Software
15 * Foundation, in version 2 as it comes in the "COPYING" file of the
16 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
17 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
18 *
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
20 * Clara, CA 95054 USA or visit http://www.sun.com if you need
21 * additional information or have any questions.
22 */
23#include "driver.h"
24#include "dd.h"
25#undef CO_E_NOTINITIALIZED
26#include <winerror.h>
27#include <iprt/asm.h>
28
29#define MEMTAG 'AWHV'
30PVBOXVHWASURFDESC vboxVHWASurfDescAlloc()
31{
32 return EngAllocMem(FL_NONPAGED_MEMORY | FL_ZERO_MEMORY, sizeof(VBOXVHWASURFDESC), MEMTAG);
33}
34
35void vboxVHWASurfDescFree(PVBOXVHWASURFDESC pDesc)
36{
37 EngFreeMem(pDesc);
38}
39
40#define VBOX_DD(_f) DD##_f
41#define VBOX_VHWA(_f) VBOXVHWA_##_f
42#define VBOX_DD2VHWA(_out, _in, _f) do {if((_in) & VBOX_DD(_f)) _out |= VBOX_VHWA(_f); }while(0)
43#define VBOX_DD_VHWA_PAIR(_v) {VBOX_DD(_v), VBOX_VHWA(_v)}
44#define VBOX_DD_DUMMY_PAIR(_v) {VBOX_DD(_v), 0}
45
46#define VBOXVHWA_SUPPORTED_CAPS ( \
47 VBOXVHWA_CAPS_BLT \
48 | VBOXVHWA_CAPS_BLTCOLORFILL \
49 | VBOXVHWA_CAPS_BLTFOURCC \
50 | VBOXVHWA_CAPS_BLTSTRETCH \
51 | VBOXVHWA_CAPS_BLTQUEUE \
52 | VBOXVHWA_CAPS_OVERLAY \
53 | VBOXVHWA_CAPS_OVERLAYFOURCC \
54 | VBOXVHWA_CAPS_OVERLAYSTRETCH \
55 | VBOXVHWA_CAPS_OVERLAYCANTCLIP \
56 | VBOXVHWA_CAPS_COLORKEY \
57 | VBOXVHWA_CAPS_COLORKEYHWASSIST \
58 )
59
60#define VBOXVHWA_SUPPORTED_SCAPS ( \
61 VBOXVHWA_SCAPS_BACKBUFFER \
62 | VBOXVHWA_SCAPS_COMPLEX \
63 | VBOXVHWA_SCAPS_FLIP \
64 | VBOXVHWA_SCAPS_FRONTBUFFER \
65 | VBOXVHWA_SCAPS_OFFSCREENPLAIN \
66 | VBOXVHWA_SCAPS_OVERLAY \
67 | VBOXVHWA_SCAPS_PRIMARYSURFACE \
68 | VBOXVHWA_SCAPS_SYSTEMMEMORY \
69 | VBOXVHWA_SCAPS_VIDEOMEMORY \
70 | VBOXVHWA_SCAPS_VISIBLE \
71 | VBOXVHWA_SCAPS_LOCALVIDMEM \
72 )
73
74#define VBOXVHWA_SUPPORTED_SCAPS2 ( \
75 VBOXVHWA_CAPS2_CANRENDERWINDOWED \
76 | VBOXVHWA_CAPS2_WIDESURFACES \
77 | VBOXVHWA_CAPS2_COPYFOURCC \
78 )
79
80#define VBOXVHWA_SUPPORTED_PF ( \
81 VBOXVHWA_PF_RGB \
82 | VBOXVHWA_PF_RGBTOYUV \
83 | VBOXVHWA_PF_YUV \
84 | VBOXVHWA_PF_FOURCC \
85 )
86
87#define VBOXVHWA_SUPPORTED_SD ( \
88 VBOXVHWA_SD_BACKBUFFERCOUNT \
89 | VBOXVHWA_SD_CAPS \
90 | VBOXVHWA_SD_CKDESTBLT \
91 | VBOXVHWA_SD_CKDESTOVERLAY \
92 | VBOXVHWA_SD_CKSRCBLT \
93 | VBOXVHWA_SD_CKSRCOVERLAY \
94 | VBOXVHWA_SD_HEIGHT \
95 | VBOXVHWA_SD_PITCH \
96 | VBOXVHWA_SD_PIXELFORMAT \
97 | VBOXVHWA_SD_WIDTH \
98 )
99
100#define VBOXVHWA_SUPPORTED_CKEYCAPS ( \
101 VBOXVHWA_CKEYCAPS_DESTBLT \
102 | VBOXVHWA_CKEYCAPS_DESTBLTCLRSPACE \
103 | VBOXVHWA_CKEYCAPS_DESTBLTCLRSPACEYUV \
104 | VBOXVHWA_CKEYCAPS_DESTBLTYUV \
105 | VBOXVHWA_CKEYCAPS_DESTOVERLAY \
106 | VBOXVHWA_CKEYCAPS_DESTOVERLAYCLRSPACE \
107 | VBOXVHWA_CKEYCAPS_DESTOVERLAYCLRSPACEYUV \
108 | VBOXVHWA_CKEYCAPS_DESTOVERLAYONEACTIVE \
109 | VBOXVHWA_CKEYCAPS_DESTOVERLAYYUV \
110 | VBOXVHWA_CKEYCAPS_SRCBLT \
111 | VBOXVHWA_CKEYCAPS_SRCBLTCLRSPACE \
112 | VBOXVHWA_CKEYCAPS_SRCBLTCLRSPACEYUV \
113 | VBOXVHWA_CKEYCAPS_SRCBLTYUV \
114 | VBOXVHWA_CKEYCAPS_SRCOVERLAY \
115 | VBOXVHWA_CKEYCAPS_SRCOVERLAYCLRSPACE \
116 | VBOXVHWA_CKEYCAPS_SRCOVERLAYCLRSPACEYUV \
117 | VBOXVHWA_CKEYCAPS_SRCOVERLAYONEACTIVE \
118 | VBOXVHWA_CKEYCAPS_SRCOVERLAYYUV \
119 | VBOXVHWA_CKEYCAPS_NOCOSTOVERLAY \
120 )
121
122#define VBOXVHWA_SUPPORTED_CKEY ( \
123 VBOXVHWA_CKEY_COLORSPACE \
124 | VBOXVHWA_CKEY_DESTBLT \
125 | VBOXVHWA_CKEY_DESTOVERLAY \
126 | VBOXVHWA_CKEY_SRCBLT \
127 | VBOXVHWA_CKEY_SRCOVERLAY \
128 )
129
130#define VBOXVHWA_SUPPORTED_OVER ( \
131 VBOXVHWA_OVER_DDFX \
132 | VBOXVHWA_OVER_HIDE \
133 | VBOXVHWA_OVER_KEYDEST \
134 | VBOXVHWA_OVER_KEYDESTOVERRIDE \
135 | VBOXVHWA_OVER_KEYSRC \
136 | VBOXVHWA_OVER_KEYSRCOVERRIDE \
137 | VBOXVHWA_OVER_SHOW \
138 )
139
140void vboxVHWAInit()
141{
142}
143
144void vboxVHWATerm()
145{
146}
147
148uint32_t vboxVHWAUnsupportedDDCAPS(uint32_t caps)
149{
150 return caps & (~VBOXVHWA_SUPPORTED_CAPS);
151}
152
153uint32_t vboxVHWAUnsupportedDDSCAPS(uint32_t caps)
154{
155 return caps & (~VBOXVHWA_SUPPORTED_SCAPS);
156}
157
158uint32_t vboxVHWAUnsupportedDDPFS(uint32_t caps)
159{
160 return caps & (~VBOXVHWA_SUPPORTED_PF);
161}
162
163uint32_t vboxVHWAUnsupportedDSS(uint32_t caps)
164{
165 return caps & (~VBOXVHWA_SUPPORTED_SD);
166}
167
168uint32_t vboxVHWAUnsupportedDDCEYCAPS(uint32_t caps)
169{
170 return caps & (~VBOXVHWA_SUPPORTED_CKEYCAPS);
171}
172
173uint32_t vboxVHWASupportedDDCEYCAPS(uint32_t caps)
174{
175 return caps & (VBOXVHWA_SUPPORTED_CKEYCAPS);
176}
177
178
179uint32_t vboxVHWASupportedDDCAPS(uint32_t caps)
180{
181 return caps & (VBOXVHWA_SUPPORTED_CAPS);
182}
183
184uint32_t vboxVHWASupportedDDSCAPS(uint32_t caps)
185{
186 return caps & (VBOXVHWA_SUPPORTED_SCAPS);
187}
188
189uint32_t vboxVHWASupportedDDPFS(uint32_t caps)
190{
191 return caps & (VBOXVHWA_SUPPORTED_PF);
192}
193
194uint32_t vboxVHWASupportedDSS(uint32_t caps)
195{
196 return caps & (VBOXVHWA_SUPPORTED_SD);
197}
198
199uint32_t vboxVHWASupportedOVERs(uint32_t caps)
200{
201 return caps & (VBOXVHWA_SUPPORTED_OVER);
202}
203
204uint32_t vboxVHWAUnsupportedOVERs(uint32_t caps)
205{
206 return caps & (~VBOXVHWA_SUPPORTED_OVER);
207}
208
209uint32_t vboxVHWASupportedCKEYs(uint32_t caps)
210{
211 return caps & (VBOXVHWA_SUPPORTED_CKEY);
212}
213
214uint32_t vboxVHWAUnsupportedCKEYs(uint32_t caps)
215{
216 return caps & (~VBOXVHWA_SUPPORTED_CKEY);
217}
218
219uint32_t vboxVHWAFromDDOVERs(uint32_t caps) { return caps; }
220uint32_t vboxVHWAToDDOVERs(uint32_t caps) { return caps; }
221uint32_t vboxVHWAFromDDCKEYs(uint32_t caps) { return caps; }
222uint32_t vboxVHWAToDDCKEYs(uint32_t caps) { return caps; }
223
224void vboxVHWAFromDDOVERLAYFX(VBOXVHWA_OVERLAYFX *pVHWAOverlay, DDOVERLAYFX *pDdOverlay)
225{
226 //TODO: fxFlags
227 vboxVHWAFromDDCOLORKEY(&pVHWAOverlay->DstCK, &pDdOverlay->dckDestColorkey);
228 vboxVHWAFromDDCOLORKEY(&pVHWAOverlay->SrcCK, &pDdOverlay->dckSrcColorkey);
229}
230
231uint32_t vboxVHWAFromDDCAPS(uint32_t caps)
232{
233 return caps;
234}
235
236uint32_t vboxVHWAToDDCAPS(uint32_t caps)
237{
238 return caps;
239}
240
241uint32_t vboxVHWAFromDDCAPS2(uint32_t caps)
242{
243 return caps;
244}
245
246uint32_t vboxVHWAToDDCAPS2(uint32_t caps)
247{
248 return caps;
249}
250
251uint32_t vboxVHWAFromDDSCAPS(uint32_t caps)
252{
253 return caps;
254}
255
256uint32_t vboxVHWAToDDSCAPS(uint32_t caps)
257{
258 return caps;
259}
260
261uint32_t vboxVHWAFromDDPFS(uint32_t caps)
262{
263 return caps;
264}
265
266uint32_t vboxVHWAToDDPFS(uint32_t caps)
267{
268 return caps;
269}
270
271uint32_t vboxVHWAFromDDCKEYCAPS(uint32_t caps)
272{
273 return caps;
274}
275
276uint32_t vboxVHWAToDDCKEYCAPS(uint32_t caps)
277{
278 return caps;
279}
280
281uint32_t vboxVHWAToDDBLTs(uint32_t caps)
282{
283 return caps;
284}
285
286uint32_t vboxVHWAFromDDBLTs(uint32_t caps)
287{
288 return caps;
289}
290
291void vboxVHWAFromDDBLTFX(VBOXVHWA_BLTFX *pVHWABlt, DDBLTFX *pDdBlt)
292{
293// pVHWABlt->flags;
294// uint32_t rop;
295// uint32_t rotationOp;
296// uint32_t rotation;
297
298 pVHWABlt->fillColor = pDdBlt->dwFillColor;
299
300 vboxVHWAFromDDCOLORKEY(&pVHWABlt->DstCK, &pDdBlt->ddckDestColorkey);
301 vboxVHWAFromDDCOLORKEY(&pVHWABlt->SrcCK, &pDdBlt->ddckSrcColorkey);
302}
303
304int vboxVHWAFromDDPIXELFORMAT(VBOXVHWA_PIXELFORMAT *pVHWAFormat, DDPIXELFORMAT *pDdFormat)
305{
306 uint32_t unsup = vboxVHWAUnsupportedDDPFS(pDdFormat->dwFlags);
307 Assert(!unsup);
308 if(unsup)
309 return VERR_GENERAL_FAILURE;
310
311 pVHWAFormat->flags = vboxVHWAFromDDPFS(pDdFormat->dwFlags);
312 pVHWAFormat->fourCC = pDdFormat->dwFourCC;
313 pVHWAFormat->c.rgbBitCount = pDdFormat->dwRGBBitCount;
314 pVHWAFormat->m1.rgbRBitMask = pDdFormat->dwRBitMask;
315 pVHWAFormat->m2.rgbGBitMask = pDdFormat->dwGBitMask;
316 pVHWAFormat->m3.rgbBBitMask = pDdFormat->dwBBitMask;
317 return VINF_SUCCESS;
318}
319
320void vboxVHWAFromDDCOLORKEY(VBOXVHWA_COLORKEY *pVHWACKey, DDCOLORKEY *pDdCKey)
321{
322 pVHWACKey->low = pDdCKey->dwColorSpaceLowValue;
323 pVHWACKey->high = pDdCKey->dwColorSpaceHighValue;
324}
325
326int vboxVHWAFromDDSURFACEDESC(VBOXVHWA_SURFACEDESC *pVHWADesc, DDSURFACEDESC *pDdDesc)
327{
328 uint32_t unsupds = vboxVHWAUnsupportedDSS(pDdDesc->dwFlags);
329 Assert(!unsupds);
330 if(unsupds)
331 return VERR_GENERAL_FAILURE;
332
333 pVHWADesc->flags = 0;
334
335 if(pDdDesc->dwFlags & DDSD_BACKBUFFERCOUNT)
336 {
337 pVHWADesc->flags |= VBOXVHWA_SD_BACKBUFFERCOUNT;
338 pVHWADesc->cBackBuffers = pDdDesc->dwBackBufferCount;
339 }
340 if(pDdDesc->dwFlags & DDSD_CAPS)
341 {
342 uint32_t unsup = vboxVHWAUnsupportedDDSCAPS(pDdDesc->ddsCaps.dwCaps);
343 Assert(!unsup);
344 if(unsup)
345 return VERR_GENERAL_FAILURE;
346 pVHWADesc->flags |= VBOXVHWA_SD_CAPS;
347 pVHWADesc->surfCaps = vboxVHWAFromDDSCAPS(pDdDesc->ddsCaps.dwCaps);
348 }
349 if(pDdDesc->dwFlags & DDSD_CKDESTBLT)
350 {
351 pVHWADesc->flags |= VBOXVHWA_SD_CKDESTBLT;
352 vboxVHWAFromDDCOLORKEY(&pVHWADesc->DstBltCK, &pDdDesc->ddckCKDestBlt);
353 }
354 if(pDdDesc->dwFlags & DDSD_CKDESTOVERLAY)
355 {
356 pVHWADesc->flags |= VBOXVHWA_SD_CKDESTOVERLAY;
357 vboxVHWAFromDDCOLORKEY(&pVHWADesc->DstOverlayCK, &pDdDesc->ddckCKDestOverlay);
358 }
359 if(pDdDesc->dwFlags & DDSD_CKSRCBLT)
360 {
361 pVHWADesc->flags |= VBOXVHWA_SD_CKSRCBLT;
362 vboxVHWAFromDDCOLORKEY(&pVHWADesc->SrcBltCK, &pDdDesc->ddckCKSrcBlt);
363 }
364 if(pDdDesc->dwFlags & DDSD_CKSRCOVERLAY)
365 {
366 pVHWADesc->flags |= VBOXVHWA_SD_CKSRCOVERLAY;
367 vboxVHWAFromDDCOLORKEY(&pVHWADesc->SrcOverlayCK, &pDdDesc->ddckCKSrcOverlay);
368 }
369 if(pDdDesc->dwFlags & DDSD_HEIGHT)
370 {
371 pVHWADesc->flags |= VBOXVHWA_SD_HEIGHT;
372 pVHWADesc->height = pDdDesc->dwHeight;
373 }
374 if(pDdDesc->dwFlags & DDSD_WIDTH)
375 {
376 pVHWADesc->flags |= VBOXVHWA_SD_WIDTH;
377 pVHWADesc->width = pDdDesc->dwWidth;
378 }
379 if(pDdDesc->dwFlags & DDSD_PITCH)
380 {
381 pVHWADesc->flags |= VBOXVHWA_SD_PITCH;
382 pVHWADesc->pitch = pDdDesc->lPitch;
383 }
384 if(pDdDesc->dwFlags & DDSD_PIXELFORMAT)
385 {
386 int rc = vboxVHWAFromDDPIXELFORMAT(&pVHWADesc->PixelFormat, &pDdDesc->ddpfPixelFormat);
387 if(RT_FAILURE(rc))
388 return rc;
389 pVHWADesc->flags |= VBOXVHWA_SD_PIXELFORMAT;
390 }
391 return VINF_SUCCESS;
392}
393
394void vboxVHWAFromRECTL(VBOXVHWA_RECTL *pDst, RECTL *pSrc)
395{
396// Assert(pSrc->left <= pSrc->right);
397// Assert(pSrc->top <= pSrc->bottom);
398 pDst->left = pSrc->left;
399 pDst->top = pSrc->top;
400 pDst->right = pSrc->right;
401 pDst->bottom = pSrc->bottom;
402}
403
404#define MIN(_a, _b) (_a) < (_b) ? (_a) : (_b)
405#define MAX(_a, _b) (_a) > (_b) ? (_a) : (_b)
406
407void vboxVHWARectUnited(RECTL * pDst, RECTL * pRect1, RECTL * pRect2)
408{
409 pDst->left = MIN(pRect1->left, pRect2->left);
410 pDst->top = MIN(pRect1->top, pRect2->top);
411 pDst->right = MAX(pRect1->right, pRect2->right);
412 pDst->bottom = MAX(pRect1->bottom, pRect2->bottom);
413}
414
415bool vboxVHWARectIsEmpty(RECTL * pRect)
416{
417 return pRect->left == pRect->right-1 && pRect->top == pRect->bottom-1;
418}
419
420bool vboxVHWARectIntersect(RECTL * pRect1, RECTL * pRect2)
421{
422 return !((pRect1->left < pRect2->left && pRect1->right < pRect2->left)
423 || (pRect2->left < pRect1->left && pRect2->right < pRect1->left)
424 || (pRect1->top < pRect2->top && pRect1->bottom < pRect2->top)
425 || (pRect2->top < pRect1->top && pRect2->bottom < pRect1->top));
426}
427
428bool vboxVHWARectInclude(RECTL * pRect1, RECTL * pRect2)
429{
430 return ((pRect1->left <= pRect2->left && pRect1->right >= pRect2->right)
431 && (pRect1->top <= pRect2->top && pRect1->bottom >= pRect2->bottom));
432}
433
434
435bool vboxVHWARegionIntersects(PVBOXVHWAREGION pReg, RECTL * pRect)
436{
437 if(!pReg->bValid)
438 return false;
439 return vboxVHWARectIntersect(&pReg->Rect, pRect);
440}
441
442bool vboxVHWARegionIncludes(PVBOXVHWAREGION pReg, RECTL * pRect)
443{
444 if(!pReg->bValid)
445 return false;
446 return vboxVHWARectInclude(&pReg->Rect, pRect);
447}
448
449bool vboxVHWARegionIncluded(PVBOXVHWAREGION pReg, RECTL * pRect)
450{
451 if(!pReg->bValid)
452 return true;
453 return vboxVHWARectInclude(pRect, &pReg->Rect);
454}
455
456void vboxVHWARegionSet(PVBOXVHWAREGION pReg, RECTL * pRect)
457{
458 if(vboxVHWARectIsEmpty(pRect))
459 {
460 pReg->bValid = false;
461 }
462 else
463 {
464 pReg->Rect = *pRect;
465 pReg->bValid = true;
466 }
467}
468
469void vboxVHWARegionAdd(PVBOXVHWAREGION pReg, RECTL * pRect)
470{
471 if(vboxVHWARectIsEmpty(pRect))
472 {
473 return;
474 }
475 else if(!pReg->bValid)
476 {
477 vboxVHWARegionSet(pReg, pRect);
478 }
479 else
480 {
481 vboxVHWARectUnited(&pReg->Rect, &pReg->Rect, pRect);
482 }
483}
484
485void vboxVHWARegionInit(PVBOXVHWAREGION pReg)
486{
487 pReg->bValid = false;
488}
489
490void vboxVHWARegionClear(PVBOXVHWAREGION pReg)
491{
492 pReg->bValid = false;
493}
494
495bool vboxVHWARegionValid(PVBOXVHWAREGION pReg)
496{
497 return pReg->bValid;
498}
499
500void vboxVHWARegionTrySubstitute(PVBOXVHWAREGION pReg, const RECTL *pRect)
501{
502 if(!pReg->bValid)
503 return;
504
505 if(pReg->Rect.left >= pRect->left && pReg->Rect.right <= pRect->right)
506 {
507 LONG t = MAX(pReg->Rect.top, pRect->top);
508 LONG b = MIN(pReg->Rect.bottom, pRect->bottom);
509 if(t < b)
510 {
511 pReg->Rect.top = t;
512 pReg->Rect.bottom = b;
513 }
514 else
515 {
516 pReg->bValid = false;
517 }
518 }
519 else if(pReg->Rect.top >= pRect->top && pReg->Rect.bottom <= pRect->bottom)
520 {
521 LONG l = MAX(pReg->Rect.left, pRect->left);
522 LONG r = MIN(pReg->Rect.right, pRect->right);
523 if(l < r)
524 {
525 pReg->Rect.left = l;
526 pReg->Rect.right = r;
527 }
528 else
529 {
530 pReg->bValid = false;
531 }
532 }
533}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette