VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/include/VBoxFBOverlay.h@ 22855

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

video hw accel: annoying warnings

File size: 38.8 KB
Line 
1/** @file
2 *
3 * VBox frontends: Qt GUI ("VirtualBox"):
4 * VBoxFrameBuffer Overly classes declarations
5 */
6
7/*
8 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
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 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
19 * Clara, CA 95054 USA or visit http://www.sun.com if you need
20 * additional information or have any questions.
21 */
22#ifndef __VBoxFBOverlay_h__
23#define __VBoxFBOverlay_h__
24#if defined (VBOX_GUI_USE_QGL)
25#include "COMDefs.h"
26#include <QGLWidget>
27#include <iprt/assert.h>
28#include <iprt/critsect.h>
29
30#ifdef DEBUG
31#include "iprt/stream.h"
32#define VBOXQGLLOG(_m) RTPrintf _m
33#define VBOXQGLLOGREL(_m) do { RTPrintf _m ; LogRel( _m ); } while(0)
34#else
35#define VBOXQGLLOG(_m)
36#define VBOXQGLLOGREL(_m) LogRel( _m )
37#endif
38#define VBOXQGLLOG_ENTER(_m)
39//do{VBOXQGLLOG(("==>[%s]:", __FUNCTION__)); VBOXQGLLOG(_m);}while(0)
40#define VBOXQGLLOG_EXIT(_m)
41//do{VBOXQGLLOG(("<==[%s]:", __FUNCTION__)); VBOXQGLLOG(_m);}while(0)
42#ifdef DEBUG
43#define VBOXQGL_ASSERTNOERR() \
44 do { GLenum err = glGetError(); \
45 if(err != GL_NO_ERROR) VBOXQGLLOG(("gl error ocured (0x%x)\n", err)); \
46 Assert(err == GL_NO_ERROR); \
47 }while(0)
48
49#define VBOXQGL_CHECKERR(_op) \
50 do { \
51 glGetError(); \
52 _op \
53 VBOXQGL_ASSERTNOERR(); \
54 }while(0)
55#else
56#define VBOXQGL_ASSERTNOERR() \
57 do {}while(0)
58
59#define VBOXQGL_CHECKERR(_op) \
60 do { \
61 _op \
62 }while(0)
63#endif
64
65#ifdef DEBUG
66#include <iprt/time.h>
67
68#define VBOXGETTIME() RTTimeNanoTS()
69
70#define VBOXPRINTDIF(_nano, _m) do{\
71 uint64_t cur = VBOXGETTIME(); \
72 VBOXQGLLOG(_m); \
73 VBOXQGLLOG(("(%Lu)\n", cur - (_nano))); \
74 }while(0)
75
76class VBoxVHWADbgTimeCounter
77{
78public:
79 VBoxVHWADbgTimeCounter(const char* msg) {mTime = VBOXGETTIME(); mMsg=msg;}
80 ~VBoxVHWADbgTimeCounter() {VBOXPRINTDIF(mTime, (mMsg));}
81private:
82 uint64_t mTime;
83 const char* mMsg;
84};
85
86#define VBOXQGLLOG_METHODTIME(_m) VBoxVHWADbgTimeCounter _dbgTimeCounter(_m)
87#else
88#define VBOXQGLLOG_METHODTIME(_m)
89#endif
90
91#define VBOXQGLLOG_QRECT(_p, _pr, _s) do{\
92 VBOXQGLLOG((_p " x(%d), y(%d), w(%d), h(%d)" _s, (_pr)->x(), (_pr)->y(), (_pr)->width(), (_pr)->height()));\
93 }while(0)
94
95#define VBOXQGLLOG_CKEY(_p, _pck, _s) do{\
96 VBOXQGLLOG((_p " l(0x%x), u(0x%x)" _s, (_pck)->lower(), (_pck)->upper()));\
97 }while(0)
98
99class VBoxVHWADirtyRect
100{
101public:
102 VBoxVHWADirtyRect() :
103 mIsClear(true)
104 {}
105
106 VBoxVHWADirtyRect(const QRect & aRect)
107 {
108 if(aRect.isEmpty())
109 {
110 mIsClear = false;
111 mRect = aRect;
112 }
113 else
114 {
115 mIsClear = true;
116 }
117 }
118
119 bool isClear() const { return mIsClear; }
120
121 void add(const QRect & aRect)
122 {
123 if(aRect.isEmpty())
124 return;
125
126 mRect = mIsClear ? aRect : mRect.united(aRect);
127 mIsClear = false;
128 }
129
130 void add(const VBoxVHWADirtyRect & aRect)
131 {
132 if(aRect.isClear())
133 return;
134 add(aRect.rect());
135 }
136
137 void set(const QRect & aRect)
138 {
139 if(aRect.isEmpty())
140 {
141 mIsClear = true;
142 }
143 else
144 {
145 mRect = aRect;
146 mIsClear = false;
147 }
148 }
149
150 void clear() { mIsClear = true; }
151
152 const QRect & rect() const {return mRect;}
153
154 const QRect & toRect()
155 {
156 if(isClear())
157 {
158 mRect.setCoords(0, 0, -1, -1);
159 }
160 return mRect;
161 }
162
163 bool intersects(const QRect & aRect) const {return mIsClear ? false : mRect.intersects(aRect);}
164
165 bool intersects(const VBoxVHWADirtyRect & aRect) const {return mIsClear ? false : aRect.intersects(mRect);}
166
167 QRect united(const QRect & aRect) const {return mIsClear ? aRect : aRect.united(mRect);}
168
169 bool contains(const QRect & aRect) const {return mIsClear ? false : aRect.contains(mRect);}
170
171 void subst(const VBoxVHWADirtyRect & aRect) { if(!mIsClear && aRect.contains(mRect)) clear(); }
172
173private:
174 QRect mRect;
175 bool mIsClear;
176};
177
178class VBoxVHWAColorKey
179{
180public:
181 VBoxVHWAColorKey() :
182 mUpper(0),
183 mLower(0)
184 {}
185
186 VBoxVHWAColorKey(uint32_t aUpper, uint32_t aLower) :
187 mUpper(aUpper),
188 mLower(aLower)
189 {}
190
191 uint32_t upper() const {return mUpper; }
192 uint32_t lower() const {return mLower; }
193
194 bool operator==(const VBoxVHWAColorKey & other) const { return mUpper == other.mUpper && mLower == other.mLower; }
195private:
196 uint32_t mUpper;
197 uint32_t mLower;
198};
199
200class VBoxVHWAColorComponent
201{
202public:
203 VBoxVHWAColorComponent() :
204 mMask(0),
205 mRange(0),
206 mOffset(32),
207 mcBits(0)
208 {}
209
210 VBoxVHWAColorComponent(uint32_t aMask);
211
212 uint32_t mask() const { return mMask; }
213 uint32_t range() const { return mRange; }
214 uint32_t offset() const { return mOffset; }
215 uint32_t cBits() const { return mcBits; }
216 uint32_t colorVal(uint32_t col) const { return (col & mMask) >> mOffset; }
217 float colorValNorm(uint32_t col) const { return ((float)colorVal(col))/mRange; }
218private:
219 uint32_t mMask;
220 uint32_t mRange;
221 uint32_t mOffset;
222 uint32_t mcBits;
223};
224
225class VBoxVHWAColorFormat
226{
227public:
228
229// VBoxVHWAColorFormat(GLint aInternalFormat, GLenum aFormat, GLenum aType, uint32_t aDataFormat);
230 VBoxVHWAColorFormat(uint32_t bitsPerPixel, uint32_t r, uint32_t g, uint32_t b);
231 VBoxVHWAColorFormat(uint32_t fourcc);
232 VBoxVHWAColorFormat(){}
233 GLint internalFormat() const {return mInternalFormat; }
234 GLenum format() const {return mFormat; }
235 GLenum type() const {return mType; }
236 bool isValid() const {return mBitsPerPixel != 0; }
237 uint32_t fourcc() const {return mDataFormat;}
238 uint32_t bitsPerPixel() const { return mBitsPerPixel; }
239 uint32_t bitsPerPixelTex() const { return mBitsPerPixelTex; }
240// uint32_t bitsPerPixelDd() const { return mBitsPerPixelDd; }
241 void pixel2Normalized(uint32_t pix, float *r, float *g, float *b) const;
242 uint32_t widthCompression() const {return mWidthCompression;}
243 uint32_t heightCompression() const {return mHeightCompression;}
244 const VBoxVHWAColorComponent& r() const {return mR;}
245 const VBoxVHWAColorComponent& g() const {return mG;}
246 const VBoxVHWAColorComponent& b() const {return mB;}
247 const VBoxVHWAColorComponent& a() const {return mA;}
248
249 bool equals (const VBoxVHWAColorFormat & other) const;
250
251private:
252 void init(uint32_t bitsPerPixel, uint32_t r, uint32_t g, uint32_t b);
253 void init(uint32_t fourcc);
254
255 GLint mInternalFormat;
256 GLenum mFormat;
257 GLenum mType;
258 uint32_t mDataFormat;
259
260 uint32_t mBitsPerPixel;
261 uint32_t mBitsPerPixelTex;
262// uint32_t mBitsPerPixelDd;
263 uint32_t mWidthCompression;
264 uint32_t mHeightCompression;
265 VBoxVHWAColorComponent mR;
266 VBoxVHWAColorComponent mG;
267 VBoxVHWAColorComponent mB;
268 VBoxVHWAColorComponent mA;
269};
270
271class VBoxVHWATexture
272{
273public:
274 VBoxVHWATexture() {}
275 VBoxVHWATexture(const QRect & aRect, const VBoxVHWAColorFormat &aFormat);
276 virtual ~VBoxVHWATexture();
277 virtual void init(uchar *pvMem);
278 void setAddress(uchar *pvMem) {mAddress = pvMem;}
279 void update(const QRect * pRect) { doUpdate(mAddress, pRect);}
280 void bind() {glBindTexture(texTarget(), mTexture);}
281
282 virtual void texCoord(int x, int y);
283 virtual void multiTexCoord(GLenum texUnit, int x, int y);
284
285// GLuint texture() {return mTexture;}
286 const QRect & texRect() {return mTexRect;}
287 const QRect & rect() {return mRect;}
288 uchar * address(){ return mAddress; }
289 uint32_t rectSizeTex(const QRect * pRect) {return pRect->width() * pRect->height() * mBytesPerPixelTex;}
290 uchar * pointAddress(int x, int y)
291 {
292 x = toXTex(x);
293 y = toYTex(y);
294 return pointAddressTex(x, y);
295 }
296 uint32_t pointOffsetTex(int x, int y) { return y*mBytesPerLine + x*mBytesPerPixelTex; }
297 uchar * pointAddressTex(int x, int y) { return mAddress + pointOffsetTex(x, y); }
298 int toXTex(int x) {return x/mColorFormat.widthCompression();}
299 int toYTex(int y) {return y/mColorFormat.heightCompression();}
300 ulong memSize(){ return mBytesPerLine * mRect.height(); }
301 uint32_t bytesPerLine() {return mBytesPerLine; }
302
303protected:
304 virtual void doUpdate(uchar * pAddress, const QRect * pRect);
305 virtual void initParams();
306 virtual void load();
307 virtual GLenum texTarget() {return GL_TEXTURE_2D; }
308
309
310 QRect mTexRect; /* texture size */
311 QRect mRect; /* img size */
312 uchar * mAddress;
313 GLuint mTexture;
314 uint32_t mBytesPerPixel;
315 uint32_t mBytesPerPixelTex;
316 uint32_t mBytesPerLine;
317 VBoxVHWAColorFormat mColorFormat;
318private:
319 void uninit();
320};
321
322class VBoxVHWATextureNP2 : public VBoxVHWATexture
323{
324public:
325 VBoxVHWATextureNP2() : VBoxVHWATexture() {}
326 VBoxVHWATextureNP2(const QRect & aRect, const VBoxVHWAColorFormat &aFormat) :
327 VBoxVHWATexture(aRect, aFormat){
328 mTexRect = QRect(0, 0, aRect.width()/aFormat.widthCompression(), aRect.height()/aFormat.heightCompression());
329 }
330};
331
332class VBoxVHWATextureNP2Rect : public VBoxVHWATextureNP2
333{
334public:
335 VBoxVHWATextureNP2Rect() : VBoxVHWATextureNP2() {}
336 VBoxVHWATextureNP2Rect(const QRect & aRect, const VBoxVHWAColorFormat &aFormat) :
337 VBoxVHWATextureNP2(aRect, aFormat){}
338
339 virtual void texCoord(int x, int y);
340 virtual void multiTexCoord(GLenum texUnit, int x, int y);
341protected:
342 virtual GLenum texTarget();
343};
344
345class VBoxVHWATextureNP2RectPBO : public VBoxVHWATextureNP2Rect
346{
347public:
348 VBoxVHWATextureNP2RectPBO() : VBoxVHWATextureNP2Rect() {}
349 VBoxVHWATextureNP2RectPBO(const QRect & aRect, const VBoxVHWAColorFormat &aFormat) :
350 VBoxVHWATextureNP2Rect(aRect, aFormat){}
351 virtual ~VBoxVHWATextureNP2RectPBO();
352
353 virtual void init(uchar *pvMem);
354protected:
355 virtual void load();
356 virtual void doUpdate(uchar * pAddress, const QRect * pRect);
357private:
358 GLuint mPBO;
359};
360
361class VBoxVHWAHandleTable
362{
363public:
364 VBoxVHWAHandleTable(uint32_t initialSize);
365 ~VBoxVHWAHandleTable();
366 uint32_t put(void * data);
367 bool mapPut(uint32_t h, void * data);
368 void* get(uint32_t h);
369 void* remove(uint32_t h);
370private:
371 void doPut(uint32_t h, void * data);
372 void doRemove(uint32_t h);
373 void** mTable;
374 uint32_t mcSize;
375 uint32_t mcUsage;
376 uint32_t mCursor;
377};
378
379/* data flow:
380 * I. NON-Yinverted surface:
381 * 1.direct memory update (paint, lock/unlock):
382 * mem->tex->fb
383 * 2.blt
384 * srcTex->invFB->tex->fb
385 * |->mem
386 *
387 * II. Yinverted surface:
388 * 1.direct memory update (paint, lock/unlock):
389 * mem->tex->fb
390 * 2.blt
391 * srcTex->fb->tex
392 * |->mem
393 *
394 * III. flip support:
395 * 1. Yinverted<->NON-YInverted conversion :
396 * mem->tex-(rotate model view, force LAZY complete fb update)->invFB->tex
397 * fb-->| |->mem
398 * */
399class VBoxVHWASurfaceBase
400{
401public:
402 VBoxVHWASurfaceBase(
403 class VBoxGLWidget *mWidget,
404#if 0
405 class VBoxVHWAGlContextState *aState,
406 bool aIsYInverted,
407#endif
408 const QSize & aSize,
409 const QRect & aTargRect,
410 const QRect & aSrcRect,
411 const QRect & aVisTargRect,
412 VBoxVHWAColorFormat & aColorFormat,
413 VBoxVHWAColorKey * pSrcBltCKey, VBoxVHWAColorKey * pDstBltCKey,
414 VBoxVHWAColorKey * pSrcOverlayCKey, VBoxVHWAColorKey * pDstOverlayCKey,
415 bool bVGA);
416
417 virtual ~VBoxVHWASurfaceBase();
418
419 void init(VBoxVHWASurfaceBase * pPrimary, uchar *pvMem);
420
421 void uninit();
422
423 static void globalInit();
424
425// int blt(const QRect * aDstRect, VBoxVHWASurfaceBase * aSrtSurface, const QRect * aSrcRect, const VBoxVHWAColorKey * pDstCKeyOverride, const VBoxVHWAColorKey * pSrcCKeyOverride);
426
427 int lock(const QRect * pRect, uint32_t flags);
428
429 int unlock();
430
431 void updatedMem(const QRect * aRect);
432
433 bool performDisplay(VBoxVHWASurfaceBase *pPrimary, bool bForce);
434
435 void setRects(VBoxVHWASurfaceBase *pPrimary, const QRect & aTargRect, const QRect & aSrcRect, const QRect & aVisibleTargRect, bool bForceReinit);
436 void setTargRectPosition(VBoxVHWASurfaceBase *pPrimary, const QPoint & aPoint, const QRect & aVisibleTargRect);
437 void updateVisibleTargRect(VBoxVHWASurfaceBase *pPrimary, const QRect & aVisibleTargRect);
438
439 static ulong calcBytesPerPixel(GLenum format, GLenum type);
440
441 static GLsizei makePowerOf2(GLsizei val);
442
443 bool addressAlocated() const { return mFreeAddress; }
444 uchar * address(){ return mAddress; }
445
446 ulong memSize();
447
448 ulong width() { return mRect.width(); }
449 ulong height() { return mRect.height(); }
450 const QSize size() {return mRect.size();}
451
452 GLenum format() {return mColorFormat.format(); }
453 GLint internalFormat() { return mColorFormat.internalFormat(); }
454 GLenum type() { return mColorFormat.type(); }
455 uint32_t fourcc() {return mColorFormat.fourcc(); }
456
457// ulong bytesPerPixel() { return mpTex[0]->bytesPerPixel(); }
458 ulong bitsPerPixel() { return mColorFormat.bitsPerPixel(); }
459// ulong bitsPerPixelDd() { return mColorFormat.bitsPerPixelDd(); }
460 ulong bytesPerLine() { return mpTex[0]->bytesPerLine(); }
461
462 const VBoxVHWAColorKey * dstBltCKey() const { return mpDstBltCKey; }
463 const VBoxVHWAColorKey * srcBltCKey() const { return mpSrcBltCKey; }
464 const VBoxVHWAColorKey * dstOverlayCKey() const { return mpDstOverlayCKey; }
465 const VBoxVHWAColorKey * defaultSrcOverlayCKey() const { return mpDefaultSrcOverlayCKey; }
466 const VBoxVHWAColorKey * defaultDstOverlayCKey() const { return mpDefaultDstOverlayCKey; }
467 const VBoxVHWAColorKey * srcOverlayCKey() const { return mpSrcOverlayCKey; }
468 void resetDefaultSrcOverlayCKey() { mpSrcOverlayCKey = mpDefaultSrcOverlayCKey; }
469 void resetDefaultDstOverlayCKey() { mpDstOverlayCKey = mpDefaultDstOverlayCKey; }
470
471 void setDstBltCKey(const VBoxVHWAColorKey * ckey)
472 {
473 if(ckey)
474 {
475 mDstBltCKey = *ckey;
476 mpDstBltCKey = &mDstBltCKey;
477 }
478 else
479 {
480 mpDstBltCKey = NULL;
481 }
482 }
483
484 void setSrcBltCKey(const VBoxVHWAColorKey * ckey)
485 {
486 if(ckey)
487 {
488 mSrcBltCKey = *ckey;
489 mpSrcBltCKey = &mSrcBltCKey;
490 }
491 else
492 {
493 mpSrcBltCKey = NULL;
494 }
495 }
496
497 void setDefaultDstOverlayCKey(const VBoxVHWAColorKey * ckey)
498 {
499 if(ckey)
500 {
501 mDefaultDstOverlayCKey = *ckey;
502 mpDefaultDstOverlayCKey = &mDefaultDstOverlayCKey;
503 }
504 else
505 {
506 mpDefaultDstOverlayCKey = NULL;
507 }
508 }
509
510 void setDefaultSrcOverlayCKey(const VBoxVHWAColorKey * ckey)
511 {
512 if(ckey)
513 {
514 mDefaultSrcOverlayCKey = *ckey;
515 mpDefaultSrcOverlayCKey = &mDefaultSrcOverlayCKey;
516 }
517 else
518 {
519 mpDefaultSrcOverlayCKey = NULL;
520 }
521 }
522
523 void setOverriddenDstOverlayCKey(const VBoxVHWAColorKey * ckey)
524 {
525 if(ckey)
526 {
527 mOverriddenDstOverlayCKey = *ckey;
528 mpDstOverlayCKey = &mOverriddenDstOverlayCKey;
529 }
530 else
531 {
532 mpDstOverlayCKey = NULL;
533 }
534 }
535
536 void setOverriddenSrcOverlayCKey(const VBoxVHWAColorKey * ckey)
537 {
538 if(ckey)
539 {
540 mOverriddenSrcOverlayCKey = *ckey;
541 mpSrcOverlayCKey = &mOverriddenSrcOverlayCKey;
542 }
543 else
544 {
545 mpSrcOverlayCKey = NULL;
546 }
547 }
548
549 const VBoxVHWAColorKey * getActiveSrcOverlayCKey()
550 {
551 return mpSrcOverlayCKey;
552 }
553
554 const VBoxVHWAColorKey * getActiveDstOverlayCKey(VBoxVHWASurfaceBase * pPrimary)
555 {
556 return mpDstOverlayCKey ? mpDefaultDstOverlayCKey : pPrimary->mpDstOverlayCKey;
557 }
558
559 const VBoxVHWAColorFormat & colorFormat() {return mColorFormat; }
560
561 void setAddress(uchar * addr);
562
563 const QRect& rect() const {return mRect;}
564 const QRect& srcRect() const {return mSrcRect; }
565 const QRect& targRect() const {return mTargRect; }
566 class VBoxVHWASurfList * getComplexList() {return mComplexList; }
567
568 class VBoxVHWAGlProgramMngr * getGlProgramMngr();
569 static int setCKey(class VBoxVHWAGlProgramVHWA * pProgram, const VBoxVHWAColorFormat * pFormat, const VBoxVHWAColorKey * pCKey, bool bDst);
570
571 uint32_t handle() const {return mHGHandle;}
572 void setHandle(uint32_t h) {mHGHandle = h;}
573
574 const VBoxVHWADirtyRect & getDirtyRect() { return mUpdateMem2TexRect; }
575private:
576 void doSetRectValuesInternal(const QRect & aTargRect, const QRect & aSrcRect, const QRect & aVisTargRect);
577
578 void setComplexList(VBoxVHWASurfList *aComplexList) { mComplexList = aComplexList; }
579 void initDisplay(VBoxVHWASurfaceBase *pPrimary);
580 void deleteDisplay();
581
582 GLuint createDisplay(VBoxVHWASurfaceBase *pPrimary);
583 void doDisplay(VBoxVHWASurfaceBase *pPrimary, VBoxVHWAGlProgramVHWA * pProgram, bool bBindDst);
584 bool synchTexMem(const QRect * aRect);
585
586 int performBlt(const QRect * pDstRect, VBoxVHWASurfaceBase * pSrcSurface, const QRect * pSrcRect, const VBoxVHWAColorKey * pDstCKey, const VBoxVHWAColorKey * pSrcCKey, bool blt);
587
588 void doTex2FB(const QRect * pDstRect, const QRect * pSrcRect);
589 void doMultiTex2FB(const QRect * pDstRect, VBoxVHWATexture * pDstTex, const QRect * pSrcRect, int cSrcTex);
590 void doMultiTex2FB(const QRect * pDstRect, const QRect * pSrcRect, int cSrcTex);
591
592 QRect mRect; /* == Inv FB size */
593
594 QRect mSrcRect;
595 QRect mTargRect; /* == Vis FB size */
596
597 QRect mVisibleTargRect;
598 QRect mVisibleSrcRect;
599
600 GLuint mVisibleDisplay;
601
602 bool mVisibleDisplayInitialized;
603
604 uchar * mAddress;
605 VBoxVHWATexture *mpTex[3];
606
607 VBoxVHWAColorFormat mColorFormat;
608
609 VBoxVHWAColorKey *mpSrcBltCKey;
610 VBoxVHWAColorKey *mpDstBltCKey;
611 VBoxVHWAColorKey *mpSrcOverlayCKey;
612 VBoxVHWAColorKey *mpDstOverlayCKey;
613
614 VBoxVHWAColorKey *mpDefaultDstOverlayCKey;
615 VBoxVHWAColorKey *mpDefaultSrcOverlayCKey;
616
617 VBoxVHWAColorKey mSrcBltCKey;
618 VBoxVHWAColorKey mDstBltCKey;
619 VBoxVHWAColorKey mOverriddenSrcOverlayCKey;
620 VBoxVHWAColorKey mOverriddenDstOverlayCKey;
621 VBoxVHWAColorKey mDefaultDstOverlayCKey;
622 VBoxVHWAColorKey mDefaultSrcOverlayCKey;
623
624 int mLockCount;
625 /* memory buffer not reflected in fm and texture, e.g if memory buffer is replaced or in case of lock/unlock */
626 VBoxVHWADirtyRect mUpdateMem2TexRect;
627
628 bool mFreeAddress;
629
630 class VBoxVHWASurfList *mComplexList;
631
632 class VBoxGLWidget *mWidget;
633
634 uint32_t mHGHandle;
635
636#ifdef DEBUG
637public:
638 uint64_t cFlipsCurr;
639 uint64_t cFlipsTarg;
640#endif
641 friend class VBoxVHWASurfList;
642};
643
644typedef std::list <VBoxVHWASurfaceBase*> SurfList;
645typedef std::list <VBoxVHWASurfList*> OverlayList;
646typedef std::list <struct _VBOXVHWACMD *> VHWACommandList;
647
648class VBoxVHWASurfList
649{
650public:
651
652 VBoxVHWASurfList() : mCurrent(NULL) {}
653 void add(VBoxVHWASurfaceBase *pSurf)
654 {
655 VBoxVHWASurfList * pOld = pSurf->getComplexList();
656 if(pOld)
657 {
658 pOld->remove(pSurf);
659 }
660 mSurfaces.push_back(pSurf);
661 pSurf->setComplexList(this);
662 }
663
664 void clear()
665 {
666 for (SurfList::iterator it = mSurfaces.begin();
667 it != mSurfaces.end(); ++ it)
668 {
669 (*it)->setComplexList(NULL);
670 }
671 mSurfaces.clear();
672 mCurrent = NULL;
673 }
674
675 size_t size() const {return mSurfaces.size(); }
676
677 void remove(VBoxVHWASurfaceBase *pSurf)
678 {
679 mSurfaces.remove(pSurf);
680 pSurf->setComplexList(NULL);
681 if(mCurrent == pSurf)
682 mCurrent = NULL;
683 }
684
685 bool empty() { return mSurfaces.empty(); }
686
687 void setCurrentVisible(VBoxVHWASurfaceBase *pSurf)
688 {
689 mCurrent = pSurf;
690 }
691
692 VBoxVHWASurfaceBase * current() { return mCurrent; }
693 const SurfList & surfaces() const {return mSurfaces;}
694
695private:
696
697 SurfList mSurfaces;
698 VBoxVHWASurfaceBase* mCurrent;
699};
700
701class VBoxVHWADisplay
702{
703public:
704 VBoxVHWADisplay() :
705 mSurfVGA(NULL)
706// ,
707// mSurfPrimary(NULL)
708 {}
709
710 VBoxVHWASurfaceBase * setVGA(VBoxVHWASurfaceBase * pVga)
711 {
712 VBoxVHWASurfaceBase * old = mSurfVGA;
713 mSurfVGA = pVga;
714 mPrimary.clear();
715 if(pVga)
716 {
717 Assert(!pVga->getComplexList());
718 mPrimary.add(pVga);
719 mPrimary.setCurrentVisible(pVga);
720 }
721// mSurfPrimary = pVga;
722 mOverlays.clear();
723 return old;
724 }
725
726 VBoxVHWASurfaceBase * updateVGA(VBoxVHWASurfaceBase * pVga)
727 {
728 VBoxVHWASurfaceBase * old = mSurfVGA;
729 Assert(old);
730 mSurfVGA = pVga;
731 return old;
732 }
733
734 VBoxVHWASurfaceBase * getVGA() const
735 {
736 return mSurfVGA;
737 }
738
739 VBoxVHWASurfaceBase * getPrimary()
740 {
741 return mPrimary.current();
742 }
743
744 void addOverlay(VBoxVHWASurfList * pSurf)
745 {
746 mOverlays.push_back(pSurf);
747 }
748
749 void checkAddOverlay(VBoxVHWASurfList * pSurf)
750 {
751 if(!hasOverlay(pSurf))
752 addOverlay(pSurf);
753 }
754
755 bool hasOverlay(VBoxVHWASurfList * pSurf)
756 {
757 for (OverlayList::iterator it = mOverlays.begin();
758 it != mOverlays.end(); ++ it)
759 {
760 if((*it) == pSurf)
761 {
762 return true;
763 }
764 }
765 return false;
766 }
767
768 void removeOverlay(VBoxVHWASurfList * pSurf)
769 {
770 mOverlays.remove(pSurf);
771 }
772
773 bool performDisplay(bool bForce)
774 {
775 VBoxVHWASurfaceBase * pPrimary = mPrimary.current();
776 bForce |= pPrimary->performDisplay(NULL, bForce);
777
778 for (OverlayList::const_iterator it = mOverlays.begin();
779 it != mOverlays.end(); ++ it)
780 {
781 VBoxVHWASurfaceBase * pOverlay = (*it)->current();
782 if(pOverlay)
783 {
784 bForce |= pOverlay->performDisplay(pPrimary, bForce);
785 }
786 }
787 return bForce;
788 }
789
790 const OverlayList & overlays() const {return mOverlays;}
791 const VBoxVHWASurfList & primaries() const { return mPrimary; }
792
793private:
794 VBoxVHWASurfaceBase *mSurfVGA;
795 VBoxVHWASurfList mPrimary;
796
797 OverlayList mOverlays;
798};
799
800typedef void (VBoxGLWidget::*PFNVBOXQGLOP)(void* );
801
802typedef void (*PFNVBOXQGLFUNC)(void*, void*);
803
804typedef enum
805{
806 VBOXVHWA_PIPECMD_PAINT = 1,
807 VBOXVHWA_PIPECMD_VHWA,
808 VBOXVHWA_PIPECMD_OP,
809 VBOXVHWA_PIPECMD_FUNC,
810}VBOXVHWA_PIPECMD_TYPE;
811
812typedef struct VBOXVHWACALLBACKINFO
813{
814 VBoxGLWidget *pThis;
815 PFNVBOXQGLOP pfnCallback;
816 void * pContext;
817}VBOXVHWACALLBACKINFO;
818
819typedef struct VBOXVHWAFUNCCALLBACKINFO
820{
821 PFNVBOXQGLFUNC pfnCallback;
822 void * pContext1;
823 void * pContext2;
824}VBOXVHWAFUNCCALLBACKINFO;
825
826class VBoxVHWACommandElement
827{
828public:
829 void setVHWACmd(struct _VBOXVHWACMD * pCmd)
830 {
831 mType = VBOXVHWA_PIPECMD_VHWA;
832 u.mpCmd = pCmd;
833 }
834
835 void setPaintCmd(const QRect & aRect)
836 {
837 mType = VBOXVHWA_PIPECMD_PAINT;
838 mRect = aRect;
839 }
840
841 void setOp(const VBOXVHWACALLBACKINFO & aOp)
842 {
843 mType = VBOXVHWA_PIPECMD_OP;
844 u.mCallback = aOp;
845 }
846
847 void setFunc(const VBOXVHWAFUNCCALLBACKINFO & aOp)
848 {
849 mType = VBOXVHWA_PIPECMD_FUNC;
850 u.mFuncCallback = aOp;
851 }
852
853 void setData(VBOXVHWA_PIPECMD_TYPE aType, void * pvData)
854 {
855 switch(aType)
856 {
857 case VBOXVHWA_PIPECMD_PAINT:
858 setPaintCmd(*((QRect*)pvData));
859 break;
860 case VBOXVHWA_PIPECMD_VHWA:
861 setVHWACmd((struct _VBOXVHWACMD *)pvData);
862 break;
863 case VBOXVHWA_PIPECMD_OP:
864 setOp(*((VBOXVHWACALLBACKINFO *)pvData));
865 break;
866 case VBOXVHWA_PIPECMD_FUNC:
867 setFunc(*((VBOXVHWAFUNCCALLBACKINFO *)pvData));
868 break;
869 default:
870 Assert(0);
871 break;
872 }
873 }
874
875 VBOXVHWA_PIPECMD_TYPE type() const {return mType;}
876 const QRect & rect() const {return mRect;}
877 struct _VBOXVHWACMD * vhwaCmd() const {return u.mpCmd;}
878 const VBOXVHWACALLBACKINFO & op() const {return u.mCallback; }
879 const VBOXVHWAFUNCCALLBACKINFO & func() const {return u.mFuncCallback; }
880
881 VBoxVHWACommandElement * mpNext;
882private:
883 VBOXVHWA_PIPECMD_TYPE mType;
884 union
885 {
886 struct _VBOXVHWACMD * mpCmd;
887 VBOXVHWACALLBACKINFO mCallback;
888 VBOXVHWAFUNCCALLBACKINFO mFuncCallback;
889 }u;
890 QRect mRect;
891};
892
893class VBoxVHWACommandElementPipe
894{
895public:
896 VBoxVHWACommandElementPipe() :
897 mpFirst(NULL),
898 mpLast(NULL)
899 {}
900
901 void put(VBoxVHWACommandElement *pCmd)
902 {
903 if(mpLast)
904 {
905 Assert(mpFirst);
906 mpLast->mpNext = pCmd;
907 mpLast = pCmd;
908 }
909 else
910 {
911 Assert(!mpFirst);
912 mpFirst = pCmd;
913 mpLast = pCmd;
914 }
915 pCmd->mpNext= NULL;
916
917 }
918
919 VBoxVHWACommandElement * detachList()
920 {
921 if(mpLast)
922 {
923 VBoxVHWACommandElement * pHead = mpFirst;
924 mpFirst = NULL;
925 mpLast = NULL;
926 return pHead;
927 }
928 return NULL;
929 }
930private:
931 VBoxVHWACommandElement *mpFirst;
932 VBoxVHWACommandElement *mpLast;
933};
934
935class VBoxVHWACommandElementStack
936{
937public:
938 VBoxVHWACommandElementStack() :
939 mpFirst(NULL) {}
940
941 void push(VBoxVHWACommandElement *pCmd)
942 {
943 pCmd->mpNext = mpFirst;
944 mpFirst = pCmd;
945 }
946
947 void pusha(VBoxVHWACommandElement *pFirst, VBoxVHWACommandElement *pLast)
948 {
949 pLast->mpNext = mpFirst;
950 mpFirst = pFirst;
951 }
952
953 VBoxVHWACommandElement * pop()
954 {
955 if(mpFirst)
956 {
957 VBoxVHWACommandElement * ret = mpFirst;
958 mpFirst = ret->mpNext;
959 return ret;
960 }
961 return NULL;
962 }
963private:
964 VBoxVHWACommandElement *mpFirst;
965};
966
967#define VBOXVHWACMDPIPEC_NEWEVENT 0x00000001
968#define VBOXVHWACMDPIPEC_COMPLETEEVENT 0x00000002
969class VBoxVHWACommandElementProcessor
970{
971public:
972 VBoxVHWACommandElementProcessor(class VBoxConsoleView *aView);
973 ~VBoxVHWACommandElementProcessor();
974 void postCmd(VBOXVHWA_PIPECMD_TYPE aType, void * pvData, uint32_t flags);
975 void completeCurrentEvent();
976 class VBoxVHWACommandElement * detachCmdList(class VBoxVHWACommandElement * pFirst2Free, VBoxVHWACommandElement * pLast2Free);
977
978private:
979 RTCRITSECT mCritSect;
980 class VBoxVHWACommandProcessEvent *mpFirstEvent;
981 class VBoxVHWACommandProcessEvent *mpLastEvent;
982 class VBoxConsoleView *mView;
983 bool mbNewEvent;
984 VBoxVHWACommandElementStack mFreeElements;
985 VBoxVHWACommandElement mElementsBuffer[2048];
986};
987
988class VBoxVHWACommandsQueue
989{
990public:
991 void enqueue(PFNVBOXQGLFUNC pfn, void* pContext1, void* pContext2);
992
993 VBoxVHWACommandElement * detachList();
994
995 void freeList(VBoxVHWACommandElement * pList);
996
997private:
998 VBoxVHWACommandElementPipe mCmds;
999};
1000
1001class VBoxGLWidget : public QGLWidget
1002{
1003public:
1004 VBoxGLWidget (class VBoxConsoleView *aView, QWidget *aParent);
1005 ~VBoxGLWidget();
1006
1007 ulong vboxPixelFormat() { return mPixelFormat; }
1008 bool vboxUsesGuestVRAM() { return mUsesGuestVRAM; }
1009
1010 uchar *vboxAddress() { return mDisplay.getVGA() ? mDisplay.getVGA()->address() : NULL; }
1011
1012#ifdef VBOX_WITH_VIDEOHWACCEL
1013 uchar *vboxVRAMAddressFromOffset(uint64_t offset);
1014 uint64_t vboxVRAMOffsetFromAddress(uchar* addr);
1015 uint64_t vboxVRAMOffset(VBoxVHWASurfaceBase * pSurf);
1016
1017 void vhwaSaveExec(struct SSMHANDLE * pSSM);
1018 int vhwaLoadExec(VHWACommandList * pCmdList, struct SSMHANDLE * pSSM, uint32_t u32Version);
1019
1020 int vhwaSurfaceCanCreate(struct _VBOXVHWACMD_SURF_CANCREATE *pCmd);
1021 int vhwaSurfaceCreate(struct _VBOXVHWACMD_SURF_CREATE *pCmd);
1022 int vhwaSurfaceDestroy(struct _VBOXVHWACMD_SURF_DESTROY *pCmd);
1023 int vhwaSurfaceLock(struct _VBOXVHWACMD_SURF_LOCK *pCmd);
1024 int vhwaSurfaceUnlock(struct _VBOXVHWACMD_SURF_UNLOCK *pCmd);
1025 int vhwaSurfaceBlt(struct _VBOXVHWACMD_SURF_BLT *pCmd);
1026 int vhwaSurfaceFlip(struct _VBOXVHWACMD_SURF_FLIP *pCmd);
1027 int vhwaSurfaceOverlayUpdate(struct _VBOXVHWACMD_SURF_OVERLAY_UPDATE *pCmf);
1028 int vhwaSurfaceOverlaySetPosition(struct _VBOXVHWACMD_SURF_OVERLAY_SETPOSITION *pCmd);
1029 int vhwaSurfaceColorkeySet(struct _VBOXVHWACMD_SURF_COLORKEY_SET *pCmd);
1030 int vhwaQueryInfo1(struct _VBOXVHWACMD_QUERYINFO1 *pCmd);
1031 int vhwaQueryInfo2(struct _VBOXVHWACMD_QUERYINFO2 *pCmd);
1032 int vhwaConstruct(struct _VBOXVHWACMD_HH_CONSTRUCT *pCmd);
1033
1034 bool hasSurfaces() const;
1035 bool hasVisibleOverlays();
1036 const QRect & overlaysRectUnion();
1037#endif
1038
1039 ulong vboxBitsPerPixel() { return mDisplay.getVGA()->bitsPerPixel(); }
1040 ulong vboxBytesPerLine() { return mDisplay.getVGA() ? mDisplay.getVGA()->bytesPerLine() : 0; }
1041 int vboxFbWidth() {return mDisplay.getVGA()->width(); }
1042 int vboxFbHeight() {return mDisplay.getVGA()->height(); }
1043 bool vboxIsInitialized() {return mDisplay.getVGA() != NULL; }
1044
1045// void vboxPaintEvent (QPaintEvent *pe) {vboxPerformGLOp(&VBoxGLWidget::vboxDoPaint, pe); }
1046 void vboxResizeEvent (class VBoxResizeEvent *re) {vboxPerformGLOp(&VBoxGLWidget::vboxDoResize, re); }
1047
1048 void vboxProcessVHWACommands(class VBoxVHWACommandElementProcessor * pPipe) {vboxPerformGLOp(&VBoxGLWidget::vboxDoProcessVHWACommands, pPipe);}
1049#ifdef VBOX_WITH_VIDEOHWACCEL
1050 void vboxVHWACmd (struct _VBOXVHWACMD * pCmd) {vboxPerformGLOp(&VBoxGLWidget::vboxDoVHWACmd, pCmd);}
1051#endif
1052 class VBoxVHWAGlProgramMngr * vboxVHWAGetGlProgramMngr() { return mpMngr; }
1053
1054 VBoxVHWASurfaceBase * vboxGetVGASurface() { return mDisplay.getVGA(); }
1055
1056 static void doSetupMatrix(const QSize & aSize, bool bInverted);
1057
1058 void vboxDoUpdateViewport(const QRect & aRect);
1059 void vboxDoUpdateRect(const QRect * pRect);
1060
1061 const QRect & vboxViewport() const {return mViewport;}
1062
1063 bool performDisplayAndSwap(bool bForce)
1064 {
1065 bForce = mDisplay.performDisplay(bForce | mRepaintNeeded);
1066 if(bForce)
1067 {
1068 swapBuffers();
1069 }
1070 return bForce;
1071 }
1072protected:
1073
1074 void paintGL()
1075 {
1076 if(mpfnOp)
1077 {
1078 (this->*mpfnOp)(mOpContext);
1079 mpfnOp = NULL;
1080 }
1081// else
1082// {
1083 mDisplay.performDisplay(true);
1084// }
1085 }
1086
1087 void initializeGL();
1088
1089private:
1090 static void setupMatricies(const QSize &display);
1091 static void adjustViewport(const QSize &display, const QRect &viewport);
1092 void vboxDoResize(void *re);
1093// void vboxDoPaint(void *rec);
1094
1095
1096#ifdef VBOXQGL_DBG_SURF
1097 void vboxDoTestSurfaces(void *context);
1098#endif
1099#ifdef VBOX_WITH_VIDEOHWACCEL
1100 void vboxDoVHWACmdExec(void *cmd);
1101 void vboxDoVHWACmdAndFree(void *cmd);
1102 void vboxDoVHWACmd(void *cmd);
1103
1104 void vboxCheckUpdateAddress (VBoxVHWASurfaceBase * pSurface, uint64_t offset)
1105 {
1106 if (pSurface->addressAlocated())
1107 {
1108 uchar * addr = vboxVRAMAddressFromOffset(offset);
1109 if(addr)
1110 {
1111 pSurface->setAddress(addr);
1112 }
1113 }
1114 }
1115
1116 int vhwaSaveSurface(struct SSMHANDLE * pSSM, VBoxVHWASurfaceBase *pSurf, uint32_t surfCaps);
1117 int vhwaLoadSurface(VHWACommandList * pCmdList, struct SSMHANDLE * pSSM, uint32_t u32Version);
1118 int vhwaSaveOverlayData(struct SSMHANDLE * pSSM, VBoxVHWASurfaceBase *pSurf, bool bVisible);
1119 int vhwaLoadOverlayData(VHWACommandList * pCmdList, struct SSMHANDLE * pSSM, uint32_t u32Version);
1120 void vhwaDoSurfaceOverlayUpdate(VBoxVHWASurfaceBase *pDstSurf, VBoxVHWASurfaceBase *pSrcSurf, struct _VBOXVHWACMD_SURF_OVERLAY_UPDATE *pCmd);
1121#endif
1122 static const QGLFormat & vboxGLFormat();
1123
1124 VBoxVHWADisplay mDisplay;
1125
1126
1127 /* we do all opengl stuff in the paintGL context,
1128 * submit the operation to be performed
1129 * @todo: could be moved outside the updateGL */
1130 void vboxPerformGLOp(PFNVBOXQGLOP pfn, void* pContext)
1131 {
1132 mpfnOp = pfn;
1133 mOpContext = pContext;
1134 updateGL();
1135 }
1136
1137// /* posts op to UI thread */
1138// int vboxExecOpSynch(PFNVBOXQGLOP pfn, void* pContext);
1139// void vboxExecOnResize(PFNVBOXQGLOP pfn, void* pContext);
1140
1141 void vboxDoProcessVHWACommands(void *pContext);
1142
1143 class VBoxVHWACommandElement * processCmdList(class VBoxVHWACommandElement * pCmd);
1144
1145 VBoxVHWASurfaceBase* handle2Surface(uint32_t h)
1146 {
1147 VBoxVHWASurfaceBase* pSurf = (VBoxVHWASurfaceBase*)mSurfHandleTable.get(h);
1148 Assert(pSurf);
1149 return pSurf;
1150 }
1151
1152 VBoxVHWAHandleTable mSurfHandleTable;
1153
1154 PFNVBOXQGLOP mpfnOp;
1155 void *mOpContext;
1156
1157 ulong mPixelFormat;
1158 bool mUsesGuestVRAM;
1159
1160 bool mRepaintNeeded;
1161
1162// bool mbVGASurfCreated;
1163 QRect mViewport;
1164
1165 class VBoxConsoleView *mView;
1166
1167 VBoxVHWASurfList *mConstructingList;
1168 int32_t mcRemaining2Contruct;
1169
1170 /* this is used in saved state restore to postpone surface restoration
1171 * till the framebuffer size is restored */
1172 VHWACommandList mOnResizeCmdList;
1173
1174 class VBoxVHWAGlProgramMngr *mpMngr;
1175};
1176
1177
1178//typedef enum
1179//{
1180// VBOXFBOVERLAY_DONE = 1,
1181// VBOXFBOVERLAY_MODIFIED,
1182// VBOXFBOVERLAY_UNTOUCHED
1183//} VBOXFBOVERLAY_RESUT;
1184
1185class VBoxQGLOverlay
1186{
1187public:
1188 VBoxQGLOverlay (class VBoxConsoleView *aView, class VBoxFrameBuffer * aContainer);
1189
1190 int onVHWACommand(struct _VBOXVHWACMD * pCommand);
1191
1192 void onVHWACommandEvent(QEvent * pEvent);
1193
1194 /**
1195 * to be called on NotifyUpdate framebuffer call
1196 * @return true if the request was processed & should not be forwarded to the framebuffer
1197 * false - otherwise */
1198 bool onNotifyUpdate (ULONG aX, ULONG aY,
1199 ULONG aW, ULONG aH);
1200
1201 /**
1202 * to be called on RequestResize framebuffer call
1203 * @return true if the request was processed & should not be forwarded to the framebuffer
1204 * false - otherwise */
1205 bool onRequestResize (ULONG /*aScreenId*/, ULONG /*aPixelFormat*/,
1206 BYTE * /*aVRAM*/, ULONG /*aBitsPerPixel*/, ULONG /*aBytesPerLine*/,
1207 ULONG /*aWidth*/, ULONG /*aHeight*/,
1208 BOOL * /*aFinished*/)
1209 {
1210 mCmdPipe.completeCurrentEvent();
1211 return false;
1212 }
1213
1214// VBOXFBOVERLAY_RESUT onPaintEvent (const QPaintEvent *pe, QRect *pRect);
1215
1216 void onResizeEvent (const class VBoxResizeEvent *re);
1217 void onResizeEventPostprocess (const class VBoxResizeEvent *re);
1218
1219 void onViewportResized(QResizeEvent * /*re*/)
1220 {
1221 vboxDoCheckUpdateViewport();
1222 mGlCurrent = false;
1223 }
1224
1225 void onViewportScrolled(int /*dx*/, int /*dy*/)
1226 {
1227 vboxDoCheckUpdateViewport();
1228 mGlCurrent = false;
1229 }
1230
1231 static bool isAcceleration2DVideoAvailable();
1232
1233 /* not supposed to be called by clients */
1234 int vhwaLoadExec(struct SSMHANDLE * pSSM, uint32_t u32Version);
1235 void vhwaSaveExec(struct SSMHANDLE * pSSM);
1236private:
1237 int vhwaSurfaceUnlock(struct _VBOXVHWACMD_SURF_UNLOCK *pCmd);
1238
1239 void repaintMain();
1240 void repaintOverlay()
1241 {
1242 if(mNeedOverlayRepaint)
1243 {
1244 mNeedOverlayRepaint = false;
1245 performDisplayOverlay();
1246 }
1247 }
1248 void repaint()
1249 {
1250 repaintOverlay();
1251 repaintMain();
1252 }
1253
1254 void makeCurrent()
1255 {
1256 if(!mGlCurrent)
1257 {
1258 mGlCurrent = true;
1259 mpOverlayWidget->makeCurrent();
1260 }
1261 }
1262
1263 void performDisplayOverlay()
1264 {
1265 if(mOverlayVisible)
1266 {
1267#if 0
1268 mpOverlayWidget->updateGL();
1269#else
1270 makeCurrent();
1271 mpOverlayWidget->performDisplayAndSwap(false);
1272#endif
1273 }
1274 }
1275
1276// void vboxOpExit()
1277// {
1278// performDisplayOverlay();
1279// mGlCurrent = false;
1280// }
1281
1282
1283 void vboxSetGlOn(bool on);
1284 bool vboxGetGlOn() { return mGlOn; }
1285 bool vboxSynchGl();
1286 void vboxDoVHWACmdExec(void *cmd);
1287 void vboxShowOverlay(bool show);
1288 void vboxDoCheckUpdateViewport();
1289 void vboxDoVHWACmd(void *cmd);
1290 void addMainDirtyRect(const QRect & aRect);
1291// void vboxUpdateOverlayPosition(const QPoint & pos);
1292 void vboxCheckUpdateOverlay(const QRect & rect);
1293 VBoxVHWACommandElement * processCmdList(VBoxVHWACommandElement * pCmd);
1294
1295 int vhwaConstruct(struct _VBOXVHWACMD_HH_CONSTRUCT *pCmd);
1296
1297 VBoxGLWidget *mpOverlayWidget;
1298 class VBoxConsoleView *mView;
1299 class VBoxFrameBuffer *mContainer;
1300 bool mGlOn;
1301 bool mOverlayWidgetVisible;
1302 bool mOverlayVisible;
1303 bool mGlCurrent;
1304 bool mProcessingCommands;
1305 bool mNeedOverlayRepaint;
1306 QRect mOverlayViewport;
1307 VBoxVHWADirtyRect mMainDirtyRect;
1308
1309 VBoxVHWACommandElementProcessor mCmdPipe;
1310
1311 /* this is used in saved state restore to postpone surface restoration
1312 * till the framebuffer size is restored */
1313 VHWACommandList mOnResizeCmdList;
1314};
1315
1316
1317template <class T>
1318class VBoxOverlayFrameBuffer : public T
1319{
1320public:
1321 VBoxOverlayFrameBuffer (class VBoxConsoleView *aView)
1322 : T(aView),
1323 mOverlay(aView, this)
1324 {}
1325
1326
1327 STDMETHOD(ProcessVHWACommand)(BYTE *pCommand)
1328 {
1329 return mOverlay.onVHWACommand((struct _VBOXVHWACMD*)pCommand);
1330 }
1331
1332 void doProcessVHWACommand(QEvent * pEvent)
1333 {
1334 mOverlay.onVHWACommandEvent(pEvent);
1335 }
1336
1337 STDMETHOD(RequestResize) (ULONG aScreenId, ULONG aPixelFormat,
1338 BYTE *aVRAM, ULONG aBitsPerPixel, ULONG aBytesPerLine,
1339 ULONG aWidth, ULONG aHeight,
1340 BOOL *aFinished)
1341 {
1342 if(mOverlay.onRequestResize (aScreenId, aPixelFormat,
1343 aVRAM, aBitsPerPixel, aBytesPerLine,
1344 aWidth, aHeight,
1345 aFinished))
1346 {
1347 return S_OK;
1348 }
1349 return T::RequestResize (aScreenId, aPixelFormat,
1350 aVRAM, aBitsPerPixel, aBytesPerLine,
1351 aWidth, aHeight,
1352 aFinished);
1353 }
1354
1355 STDMETHOD(NotifyUpdate) (ULONG aX, ULONG aY,
1356 ULONG aW, ULONG aH)
1357 {
1358 if(mOverlay.onNotifyUpdate(aX, aY, aW, aH))
1359 return S_OK;
1360 return T::NotifyUpdate(aX, aY, aW, aH);
1361 }
1362
1363// void paintEvent (QPaintEvent *pe)
1364// {
1365// QRect rect;
1366// VBOXFBOVERLAY_RESUT res = mOverlay.onPaintEvent(pe, &rect);
1367// switch(res)
1368// {
1369// case VBOXFBOVERLAY_MODIFIED:
1370// {
1371// QPaintEvent modified(rect);
1372// T::paintEvent(&modified);
1373// } break;
1374// case VBOXFBOVERLAY_UNTOUCHED:
1375// T::paintEvent(pe);
1376// break;
1377// default:
1378// break;
1379// }
1380// }
1381
1382 void resizeEvent (VBoxResizeEvent *re)
1383 {
1384 mOverlay.onResizeEvent(re);
1385 T::resizeEvent(re);
1386 mOverlay.onResizeEventPostprocess(re);
1387 }
1388
1389 void viewportResized(QResizeEvent * re)
1390 {
1391 mOverlay.onViewportResized(re);
1392 T::viewportResized(re);
1393 }
1394
1395 void viewportScrolled(int dx, int dy)
1396 {
1397 mOverlay.onViewportScrolled(dx, dy);
1398 T::viewportScrolled(dx, dy);
1399 }
1400private:
1401 VBoxQGLOverlay mOverlay;
1402};
1403
1404#endif
1405
1406#endif /* #ifndef __VBoxFBOverlay_h__ */
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