VirtualBox

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

Last change on this file since 22836 was 22836, checked in by vboxsync, 16 years ago

video hw accel: bugfixes

File size: 38.5 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 void performDisplay(VBoxVHWASurfaceBase *pPrimary);
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; }
575
576private:
577 void doSetRectValuesInternal(const QRect & aTargRect, const QRect & aSrcRect, const QRect & aVisTargRect);
578
579 void setComplexList(VBoxVHWASurfList *aComplexList) { mComplexList = aComplexList; }
580 void initDisplay(VBoxVHWASurfaceBase *pPrimary);
581 void deleteDisplay();
582
583 GLuint createDisplay(VBoxVHWASurfaceBase *pPrimary);
584 void doDisplay(VBoxVHWASurfaceBase *pPrimary, VBoxVHWAGlProgramVHWA * pProgram, bool bBindDst);
585 void synchTexMem(const QRect * aRect);
586
587 int performBlt(const QRect * pDstRect, VBoxVHWASurfaceBase * pSrcSurface, const QRect * pSrcRect, const VBoxVHWAColorKey * pDstCKey, const VBoxVHWAColorKey * pSrcCKey, bool blt);
588
589 void doTex2FB(const QRect * pDstRect, const QRect * pSrcRect);
590 void doMultiTex2FB(const QRect * pDstRect, VBoxVHWATexture * pDstTex, const QRect * pSrcRect, int cSrcTex);
591 void doMultiTex2FB(const QRect * pDstRect, const QRect * pSrcRect, int cSrcTex);
592
593 QRect mRect; /* == Inv FB size */
594
595 QRect mSrcRect;
596 QRect mTargRect; /* == Vis FB size */
597
598 QRect mVisibleTargRect;
599 QRect mVisibleSrcRect;
600
601 GLuint mVisibleDisplay;
602
603 bool mVisibleDisplayInitialized;
604
605 uchar * mAddress;
606 VBoxVHWATexture *mpTex[3];
607
608 VBoxVHWAColorFormat mColorFormat;
609
610 VBoxVHWAColorKey *mpSrcBltCKey;
611 VBoxVHWAColorKey *mpDstBltCKey;
612 VBoxVHWAColorKey *mpSrcOverlayCKey;
613 VBoxVHWAColorKey *mpDstOverlayCKey;
614
615 VBoxVHWAColorKey *mpDefaultDstOverlayCKey;
616 VBoxVHWAColorKey *mpDefaultSrcOverlayCKey;
617
618 VBoxVHWAColorKey mSrcBltCKey;
619 VBoxVHWAColorKey mDstBltCKey;
620 VBoxVHWAColorKey mOverriddenSrcOverlayCKey;
621 VBoxVHWAColorKey mOverriddenDstOverlayCKey;
622 VBoxVHWAColorKey mDefaultDstOverlayCKey;
623 VBoxVHWAColorKey mDefaultSrcOverlayCKey;
624
625 int mLockCount;
626 /* memory buffer not reflected in fm and texture, e.g if memory buffer is replaced or in case of lock/unlock */
627 VBoxVHWADirtyRect mUpdateMem2TexRect;
628
629 bool mFreeAddress;
630
631 class VBoxVHWASurfList *mComplexList;
632
633 class VBoxGLWidget *mWidget;
634
635 uint32_t mHGHandle;
636
637#ifdef DEBUG
638public:
639 uint64_t cFlipsCurr;
640 uint64_t cFlipsTarg;
641#endif
642 friend class VBoxVHWASurfList;
643};
644
645typedef std::list <VBoxVHWASurfaceBase*> SurfList;
646typedef std::list <VBoxVHWASurfList*> OverlayList;
647typedef std::list <struct _VBOXVHWACMD *> VHWACommandList;
648
649class VBoxVHWASurfList
650{
651public:
652
653 VBoxVHWASurfList() : mCurrent(NULL) {}
654 void add(VBoxVHWASurfaceBase *pSurf)
655 {
656 VBoxVHWASurfList * pOld = pSurf->getComplexList();
657 if(pOld)
658 {
659 pOld->remove(pSurf);
660 }
661 mSurfaces.push_back(pSurf);
662 pSurf->setComplexList(this);
663 }
664
665 void clear()
666 {
667 for (SurfList::iterator it = mSurfaces.begin();
668 it != mSurfaces.end(); ++ it)
669 {
670 (*it)->setComplexList(NULL);
671 }
672 mSurfaces.clear();
673 mCurrent = NULL;
674 }
675
676 size_t size() const {return mSurfaces.size(); }
677
678 void remove(VBoxVHWASurfaceBase *pSurf)
679 {
680 mSurfaces.remove(pSurf);
681 pSurf->setComplexList(NULL);
682 if(mCurrent == pSurf)
683 mCurrent = NULL;
684 }
685
686 bool empty() { return mSurfaces.empty(); }
687
688 void setCurrentVisible(VBoxVHWASurfaceBase *pSurf)
689 {
690 mCurrent = pSurf;
691 }
692
693 VBoxVHWASurfaceBase * current() { return mCurrent; }
694 const SurfList & surfaces() const {return mSurfaces;}
695
696private:
697
698 SurfList mSurfaces;
699 VBoxVHWASurfaceBase* mCurrent;
700};
701
702class VBoxVHWADisplay
703{
704public:
705 VBoxVHWADisplay() :
706 mSurfVGA(NULL)
707// ,
708// mSurfPrimary(NULL)
709 {}
710
711 VBoxVHWASurfaceBase * setVGA(VBoxVHWASurfaceBase * pVga)
712 {
713 VBoxVHWASurfaceBase * old = mSurfVGA;
714 mSurfVGA = pVga;
715 mPrimary.clear();
716 if(pVga)
717 {
718 Assert(!pVga->getComplexList());
719 mPrimary.add(pVga);
720 mPrimary.setCurrentVisible(pVga);
721 }
722// mSurfPrimary = pVga;
723 mOverlays.clear();
724 return old;
725 }
726
727 VBoxVHWASurfaceBase * updateVGA(VBoxVHWASurfaceBase * pVga)
728 {
729 VBoxVHWASurfaceBase * old = mSurfVGA;
730 Assert(old);
731 mSurfVGA = pVga;
732 return old;
733 }
734
735 VBoxVHWASurfaceBase * getVGA() const
736 {
737 return mSurfVGA;
738 }
739
740 VBoxVHWASurfaceBase * getPrimary()
741 {
742 return mPrimary.current();
743 }
744
745 void addOverlay(VBoxVHWASurfList * pSurf)
746 {
747 mOverlays.push_back(pSurf);
748 }
749
750 void checkAddOverlay(VBoxVHWASurfList * pSurf)
751 {
752 if(!hasOverlay(pSurf))
753 addOverlay(pSurf);
754 }
755
756 bool hasOverlay(VBoxVHWASurfList * pSurf)
757 {
758 for (OverlayList::iterator it = mOverlays.begin();
759 it != mOverlays.end(); ++ it)
760 {
761 if((*it) == pSurf)
762 {
763 return true;
764 }
765 }
766 return false;
767 }
768
769 void removeOverlay(VBoxVHWASurfList * pSurf)
770 {
771 mOverlays.remove(pSurf);
772 }
773
774 void performDisplay()
775 {
776 VBoxVHWASurfaceBase * pPrimary = mPrimary.current();
777 pPrimary->performDisplay(NULL);
778
779 for (OverlayList::const_iterator it = mOverlays.begin();
780 it != mOverlays.end(); ++ it)
781 {
782 VBoxVHWASurfaceBase * pOverlay = (*it)->current();
783 if(pOverlay)
784 {
785 pOverlay->performDisplay(pPrimary);
786 }
787 }
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 void performDisplay() { mDisplay.performDisplay(); }
1064protected:
1065
1066 void paintGL()
1067 {
1068 if(mpfnOp)
1069 {
1070 (this->*mpfnOp)(mOpContext);
1071 mpfnOp = NULL;
1072 }
1073// else
1074// {
1075 mDisplay.performDisplay();
1076// }
1077 }
1078
1079 void initializeGL();
1080
1081private:
1082 static void setupMatricies(const QSize &display);
1083 static void adjustViewport(const QSize &display, const QRect &viewport);
1084 void vboxDoResize(void *re);
1085// void vboxDoPaint(void *rec);
1086
1087
1088#ifdef VBOXQGL_DBG_SURF
1089 void vboxDoTestSurfaces(void *context);
1090#endif
1091#ifdef VBOX_WITH_VIDEOHWACCEL
1092 void vboxDoVHWACmdExec(void *cmd);
1093 void vboxDoVHWACmdAndFree(void *cmd);
1094 void vboxDoVHWACmd(void *cmd);
1095
1096 void vboxCheckUpdateAddress (VBoxVHWASurfaceBase * pSurface, uint64_t offset)
1097 {
1098 if (pSurface->addressAlocated())
1099 {
1100 uchar * addr = vboxVRAMAddressFromOffset(offset);
1101 if(addr)
1102 {
1103 pSurface->setAddress(addr);
1104 }
1105 }
1106 }
1107
1108 int vhwaSaveSurface(struct SSMHANDLE * pSSM, VBoxVHWASurfaceBase *pSurf, uint32_t surfCaps);
1109 int vhwaLoadSurface(VHWACommandList * pCmdList, struct SSMHANDLE * pSSM, uint32_t u32Version);
1110 int vhwaSaveOverlayData(struct SSMHANDLE * pSSM, VBoxVHWASurfaceBase *pSurf, bool bVisible);
1111 int vhwaLoadOverlayData(VHWACommandList * pCmdList, struct SSMHANDLE * pSSM, uint32_t u32Version);
1112 void vhwaDoSurfaceOverlayUpdate(VBoxVHWASurfaceBase *pDstSurf, VBoxVHWASurfaceBase *pSrcSurf, struct _VBOXVHWACMD_SURF_OVERLAY_UPDATE *pCmd);
1113#endif
1114 static const QGLFormat & vboxGLFormat();
1115
1116 VBoxVHWADisplay mDisplay;
1117
1118
1119 /* we do all opengl stuff in the paintGL context,
1120 * submit the operation to be performed
1121 * @todo: could be moved outside the updateGL */
1122 void vboxPerformGLOp(PFNVBOXQGLOP pfn, void* pContext)
1123 {
1124 mpfnOp = pfn;
1125 mOpContext = pContext;
1126 updateGL();
1127 }
1128
1129// /* posts op to UI thread */
1130// int vboxExecOpSynch(PFNVBOXQGLOP pfn, void* pContext);
1131// void vboxExecOnResize(PFNVBOXQGLOP pfn, void* pContext);
1132
1133 void vboxDoProcessVHWACommands(void *pContext);
1134
1135 class VBoxVHWACommandElement * processCmdList(class VBoxVHWACommandElement * pCmd);
1136
1137 VBoxVHWASurfaceBase* handle2Surface(uint32_t h)
1138 {
1139 VBoxVHWASurfaceBase* pSurf = (VBoxVHWASurfaceBase*)mSurfHandleTable.get(h);
1140 Assert(pSurf);
1141 return pSurf;
1142 }
1143
1144 VBoxVHWAHandleTable mSurfHandleTable;
1145
1146 PFNVBOXQGLOP mpfnOp;
1147 void *mOpContext;
1148
1149 ulong mPixelFormat;
1150 bool mUsesGuestVRAM;
1151// bool mbVGASurfCreated;
1152 QRect mViewport;
1153
1154 class VBoxConsoleView *mView;
1155
1156 VBoxVHWASurfList *mConstructingList;
1157 int32_t mcRemaining2Contruct;
1158
1159 /* this is used in saved state restore to postpone surface restoration
1160 * till the framebuffer size is restored */
1161 VHWACommandList mOnResizeCmdList;
1162
1163 class VBoxVHWAGlProgramMngr *mpMngr;
1164};
1165
1166
1167typedef enum
1168{
1169 VBOXFBOVERLAY_DONE = 1,
1170 VBOXFBOVERLAY_MODIFIED,
1171 VBOXFBOVERLAY_UNTOUCHED
1172} VBOXFBOVERLAY_RESUT;
1173
1174class VBoxQGLOverlay
1175{
1176public:
1177 VBoxQGLOverlay (class VBoxConsoleView *aView, class VBoxFrameBuffer * aContainer);
1178
1179 int onVHWACommand(struct _VBOXVHWACMD * pCommand);
1180
1181 void onVHWACommandEvent(QEvent * pEvent);
1182
1183 /**
1184 * to be called on NotifyUpdate framebuffer call
1185 * @return true if the request was processed & should not be forwarded to the framebuffer
1186 * false - otherwise */
1187 bool onNotifyUpdate (ULONG aX, ULONG aY,
1188 ULONG aW, ULONG aH);
1189
1190 /**
1191 * to be called on RequestResize framebuffer call
1192 * @return true if the request was processed & should not be forwarded to the framebuffer
1193 * false - otherwise */
1194 bool onRequestResize (ULONG aScreenId, ULONG aPixelFormat,
1195 BYTE *aVRAM, ULONG aBitsPerPixel, ULONG aBytesPerLine,
1196 ULONG aWidth, ULONG aHeight,
1197 BOOL *aFinished)
1198 {
1199 mCmdPipe.completeCurrentEvent();
1200 return false;
1201 }
1202
1203 VBOXFBOVERLAY_RESUT onPaintEvent (const QPaintEvent *pe, QRect *pRect);
1204 void onResizeEvent (const class VBoxResizeEvent *re);
1205 void onResizeEventPostprocess (const class VBoxResizeEvent *re);
1206
1207 void viewportResized(QResizeEvent * re)
1208 {
1209 vboxDoCheckUpdateViewport();
1210 mGlCurrent = false;
1211 }
1212
1213 void viewportScrolled(int dx, int dy)
1214 {
1215 vboxDoCheckUpdateViewport();
1216 mGlCurrent = false;
1217 }
1218
1219 static bool isAcceleration2DVideoAvailable();
1220
1221 /* not supposed to be called by clients */
1222 int vhwaLoadExec(struct SSMHANDLE * pSSM, uint32_t u32Version);
1223 void vhwaSaveExec(struct SSMHANDLE * pSSM);
1224private:
1225 int vhwaSurfaceUnlock(struct _VBOXVHWACMD_SURF_UNLOCK *pCmd);
1226
1227 void repaintMain();
1228 void repaintOverlay()
1229 {
1230 if(mNeedOverlayRepaint)
1231 {
1232 mNeedOverlayRepaint = false;
1233 performDisplayOverlay();
1234 }
1235 }
1236 void repaint()
1237 {
1238 repaintOverlay();
1239 repaintMain();
1240 }
1241
1242 void makeCurrent()
1243 {
1244 if(!mGlCurrent)
1245 {
1246 mGlCurrent = true;
1247 mpOverlayWidget->makeCurrent();
1248 }
1249 }
1250
1251 void performDisplayOverlay()
1252 {
1253 if(mOverlayVisible)
1254 {
1255#if 0
1256 mpOverlayWidget->updateGL();
1257#else
1258 makeCurrent();
1259 mpOverlayWidget->performDisplay();
1260 mpOverlayWidget->swapBuffers();
1261#endif
1262 }
1263 }
1264
1265// void vboxOpExit()
1266// {
1267// performDisplayOverlay();
1268// mGlCurrent = false;
1269// }
1270
1271
1272 void vboxSetGlOn(bool on);
1273 bool vboxGetGlOn() { return mGlOn; }
1274 bool vboxSynchGl();
1275 void vboxDoVHWACmdExec(void *cmd);
1276 void vboxShowOverlay(bool show);
1277 void vboxDoCheckUpdateViewport();
1278 void vboxDoVHWACmd(void *cmd);
1279 void addMainDirtyRect(const QRect & aRect);
1280// void vboxUpdateOverlayPosition(const QPoint & pos);
1281 void vboxCheckUpdateOverlay(const QRect & rect);
1282 VBoxVHWACommandElement * processCmdList(VBoxVHWACommandElement * pCmd);
1283
1284 int vhwaConstruct(struct _VBOXVHWACMD_HH_CONSTRUCT *pCmd);
1285
1286 VBoxGLWidget *mpOverlayWidget;
1287 class VBoxConsoleView *mView;
1288 class VBoxFrameBuffer *mContainer;
1289 bool mGlOn;
1290 bool mOverlayWidgetVisible;
1291 bool mOverlayVisible;
1292 bool mGlCurrent;
1293 bool mProcessingCommands;
1294 bool mNeedOverlayRepaint;
1295 QRect mOverlayViewport;
1296 VBoxVHWADirtyRect mMainDirtyRect;
1297
1298 VBoxVHWACommandElementProcessor mCmdPipe;
1299
1300 /* this is used in saved state restore to postpone surface restoration
1301 * till the framebuffer size is restored */
1302 VHWACommandList mOnResizeCmdList;
1303};
1304
1305
1306template <class T>
1307class VBoxOverlayFrameBuffer : public T
1308{
1309public:
1310 VBoxOverlayFrameBuffer (class VBoxConsoleView *aView)
1311 : T(aView),
1312 mOverlay(aView, this)
1313 {}
1314
1315
1316 STDMETHOD(ProcessVHWACommand)(BYTE *pCommand)
1317 {
1318 return mOverlay.onVHWACommand((struct _VBOXVHWACMD*)pCommand);
1319 }
1320
1321 void doProcessVHWACommand(QEvent * pEvent)
1322 {
1323 mOverlay.onVHWACommandEvent(pEvent);
1324 }
1325
1326 STDMETHOD(RequestResize) (ULONG aScreenId, ULONG aPixelFormat,
1327 BYTE *aVRAM, ULONG aBitsPerPixel, ULONG aBytesPerLine,
1328 ULONG aWidth, ULONG aHeight,
1329 BOOL *aFinished)
1330 {
1331 if(mOverlay.onRequestResize (aScreenId, aPixelFormat,
1332 aVRAM, aBitsPerPixel, aBytesPerLine,
1333 aWidth, aHeight,
1334 aFinished))
1335 {
1336 return S_OK;
1337 }
1338 return T::RequestResize (aScreenId, aPixelFormat,
1339 aVRAM, aBitsPerPixel, aBytesPerLine,
1340 aWidth, aHeight,
1341 aFinished);
1342 }
1343
1344 STDMETHOD(NotifyUpdate) (ULONG aX, ULONG aY,
1345 ULONG aW, ULONG aH)
1346 {
1347 if(mOverlay.onNotifyUpdate(aX, aY, aW, aH))
1348 return S_OK;
1349 return T::NotifyUpdate(aX, aY, aW, aH);
1350 }
1351
1352 void paintEvent (QPaintEvent *pe)
1353 {
1354 QRect rect;
1355 VBOXFBOVERLAY_RESUT res = mOverlay.onPaintEvent(pe, &rect);
1356 switch(res)
1357 {
1358 case VBOXFBOVERLAY_MODIFIED:
1359 {
1360 QPaintEvent modified(rect);
1361 T::paintEvent(&modified);
1362 } break;
1363 case VBOXFBOVERLAY_UNTOUCHED:
1364 T::paintEvent(pe);
1365 break;
1366 default:
1367 break;
1368 }
1369 }
1370
1371 void resizeEvent (VBoxResizeEvent *re)
1372 {
1373 mOverlay.onResizeEvent(re);
1374 T::resizeEvent(re);
1375 mOverlay.onResizeEventPostprocess(re);
1376 }
1377
1378 void viewportResized(QResizeEvent * re)
1379 {
1380 mOverlay.viewportResized(re);
1381 T::viewportResized(re);
1382 }
1383
1384 void viewportScrolled(int dx, int dy)
1385 {
1386 mOverlay.viewportScrolled(dx, dy);
1387 T::viewportScrolled(dx, dy);
1388 }
1389private:
1390 VBoxQGLOverlay mOverlay;
1391};
1392
1393#endif
1394
1395#endif /* #ifndef __VBoxFBOverlay_h__ */
Note: See TracBrowser for help on using the repository browser.

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