VirtualBox

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

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

Automated rebranding to Oracle copyright/license strings via filemuncher

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