VirtualBox

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

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

wddm: more impl

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