VirtualBox

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

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

video hw accel: bugfixes & perf improvements

File size: 37.2 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
967class VBoxVHWACommandElementProcessor
968{
969public:
970 VBoxVHWACommandElementProcessor(class VBoxConsoleView *aView);
971 ~VBoxVHWACommandElementProcessor();
972 void postCmd(VBOXVHWA_PIPECMD_TYPE aType, void * pvData);
973 class VBoxVHWACommandElement * detachCmdList(class VBoxVHWACommandElement * pFirst2Free, VBoxVHWACommandElement * pLast2Free);
974
975private:
976 RTCRITSECT mCritSect;
977 class VBoxVHWACommandProcessEvent *mpFirstEvent;
978 class VBoxVHWACommandProcessEvent *mpLastEvent;
979 class VBoxConsoleView *mView;
980 bool mbNewEvent;
981 VBoxVHWACommandElementStack mFreeElements;
982 VBoxVHWACommandElement mElementsBuffer[2048];
983};
984
985class VBoxVHWACommandsQueue
986{
987public:
988 void enqueue(PFNVBOXQGLFUNC pfn, void* pContext1, void* pContext2);
989
990 VBoxVHWACommandElement * detachList();
991
992 void freeList(VBoxVHWACommandElement * pList);
993
994private:
995 VBoxVHWACommandElementPipe mCmds;
996};
997
998class VBoxGLWidget : public QGLWidget
999{
1000public:
1001 VBoxGLWidget (class VBoxConsoleView *aView, QWidget *aParent);
1002 ~VBoxGLWidget();
1003
1004 ulong vboxPixelFormat() { return mPixelFormat; }
1005 bool vboxUsesGuestVRAM() { return mUsesGuestVRAM; }
1006
1007 uchar *vboxAddress() { return mDisplay.getVGA() ? mDisplay.getVGA()->address() : NULL; }
1008
1009#ifdef VBOX_WITH_VIDEOHWACCEL
1010 uchar *vboxVRAMAddressFromOffset(uint64_t offset);
1011 uint64_t vboxVRAMOffsetFromAddress(uchar* addr);
1012 uint64_t vboxVRAMOffset(VBoxVHWASurfaceBase * pSurf);
1013
1014 void vhwaSaveExec(struct SSMHANDLE * pSSM);
1015 int vhwaLoadExec(VHWACommandList * pCmdList, struct SSMHANDLE * pSSM, uint32_t u32Version);
1016
1017 int vhwaSurfaceCanCreate(struct _VBOXVHWACMD_SURF_CANCREATE *pCmd);
1018 int vhwaSurfaceCreate(struct _VBOXVHWACMD_SURF_CREATE *pCmd);
1019 int vhwaSurfaceDestroy(struct _VBOXVHWACMD_SURF_DESTROY *pCmd);
1020 int vhwaSurfaceLock(struct _VBOXVHWACMD_SURF_LOCK *pCmd);
1021 int vhwaSurfaceUnlock(struct _VBOXVHWACMD_SURF_UNLOCK *pCmd);
1022 int vhwaSurfaceBlt(struct _VBOXVHWACMD_SURF_BLT *pCmd);
1023 int vhwaSurfaceFlip(struct _VBOXVHWACMD_SURF_FLIP *pCmd);
1024 int vhwaSurfaceOverlayUpdate(struct _VBOXVHWACMD_SURF_OVERLAY_UPDATE *pCmf);
1025 int vhwaSurfaceOverlaySetPosition(struct _VBOXVHWACMD_SURF_OVERLAY_SETPOSITION *pCmd);
1026 int vhwaSurfaceColorkeySet(struct _VBOXVHWACMD_SURF_COLORKEY_SET *pCmd);
1027 int vhwaQueryInfo1(struct _VBOXVHWACMD_QUERYINFO1 *pCmd);
1028 int vhwaQueryInfo2(struct _VBOXVHWACMD_QUERYINFO2 *pCmd);
1029 int vhwaConstruct(struct _VBOXVHWACMD_HH_CONSTRUCT *pCmd);
1030
1031 bool hasSurfaces() const;
1032 bool hasVisibleOverlays();
1033 const QRect & overlaysRectUnion();
1034#endif
1035
1036 ulong vboxBitsPerPixel() { return mDisplay.getVGA()->bitsPerPixel(); }
1037 ulong vboxBytesPerLine() { return mDisplay.getVGA() ? mDisplay.getVGA()->bytesPerLine() : 0; }
1038 int vboxFbWidth() {return mDisplay.getVGA()->width(); }
1039 int vboxFbHeight() {return mDisplay.getVGA()->height(); }
1040 bool vboxIsInitialized() {return mDisplay.getVGA() != NULL; }
1041
1042// void vboxPaintEvent (QPaintEvent *pe) {vboxPerformGLOp(&VBoxGLWidget::vboxDoPaint, pe); }
1043 void vboxResizeEvent (class VBoxResizeEvent *re) {vboxPerformGLOp(&VBoxGLWidget::vboxDoResize, re); }
1044
1045 void vboxProcessVHWACommands(class VBoxVHWACommandElementProcessor * pPipe) {vboxPerformGLOp(&VBoxGLWidget::vboxDoProcessVHWACommands, pPipe);}
1046#ifdef VBOX_WITH_VIDEOHWACCEL
1047 void vboxVHWACmd (struct _VBOXVHWACMD * pCmd) {vboxPerformGLOp(&VBoxGLWidget::vboxDoVHWACmd, pCmd);}
1048#endif
1049 class VBoxVHWAGlProgramMngr * vboxVHWAGetGlProgramMngr() { return mpMngr; }
1050
1051 VBoxVHWASurfaceBase * vboxGetVGASurface() { return mDisplay.getVGA(); }
1052
1053 static void doSetupMatrix(const QSize & aSize, bool bInverted);
1054
1055 void vboxDoUpdateViewport(const QRect & aRect);
1056 void vboxDoUpdateRect(const QRect * pRect);
1057
1058 const QRect & vboxViewport() const {return mViewport;}
1059
1060 void performDisplay() { mDisplay.performDisplay(); }
1061protected:
1062
1063 void paintGL()
1064 {
1065 if(mpfnOp)
1066 {
1067 (this->*mpfnOp)(mOpContext);
1068 mpfnOp = NULL;
1069 }
1070// else
1071// {
1072 mDisplay.performDisplay();
1073// }
1074 }
1075
1076 void initializeGL();
1077
1078private:
1079 static void setupMatricies(const QSize &display);
1080 static void adjustViewport(const QSize &display, const QRect &viewport);
1081 void vboxDoResize(void *re);
1082// void vboxDoPaint(void *rec);
1083
1084
1085#ifdef VBOXQGL_DBG_SURF
1086 void vboxDoTestSurfaces(void *context);
1087#endif
1088#ifdef VBOX_WITH_VIDEOHWACCEL
1089 void vboxDoVHWACmdExec(void *cmd);
1090 void vboxDoVHWACmdAndFree(void *cmd);
1091 void vboxDoVHWACmd(void *cmd);
1092
1093 void vboxCheckUpdateAddress (VBoxVHWASurfaceBase * pSurface, uint64_t offset)
1094 {
1095 if (pSurface->addressAlocated())
1096 {
1097 uchar * addr = vboxVRAMAddressFromOffset(offset);
1098 if(addr)
1099 {
1100 pSurface->setAddress(addr);
1101 }
1102 }
1103 }
1104
1105 int vhwaSaveSurface(struct SSMHANDLE * pSSM, VBoxVHWASurfaceBase *pSurf, uint32_t surfCaps);
1106 int vhwaLoadSurface(VHWACommandList * pCmdList, struct SSMHANDLE * pSSM, uint32_t u32Version);
1107 int vhwaSaveOverlayData(struct SSMHANDLE * pSSM, VBoxVHWASurfaceBase *pSurf, bool bVisible);
1108 int vhwaLoadOverlayData(VHWACommandList * pCmdList, struct SSMHANDLE * pSSM, uint32_t u32Version);
1109 void vhwaDoSurfaceOverlayUpdate(VBoxVHWASurfaceBase *pDstSurf, VBoxVHWASurfaceBase *pSrcSurf, struct _VBOXVHWACMD_SURF_OVERLAY_UPDATE *pCmd);
1110#endif
1111 static const QGLFormat & vboxGLFormat();
1112
1113 VBoxVHWADisplay mDisplay;
1114
1115
1116 /* we do all opengl stuff in the paintGL context,
1117 * submit the operation to be performed
1118 * @todo: could be moved outside the updateGL */
1119 void vboxPerformGLOp(PFNVBOXQGLOP pfn, void* pContext)
1120 {
1121 mpfnOp = pfn;
1122 mOpContext = pContext;
1123 updateGL();
1124 }
1125
1126// /* posts op to UI thread */
1127// int vboxExecOpSynch(PFNVBOXQGLOP pfn, void* pContext);
1128// void vboxExecOnResize(PFNVBOXQGLOP pfn, void* pContext);
1129
1130 void vboxDoProcessVHWACommands(void *pContext);
1131
1132 class VBoxVHWACommandElement * processCmdList(class VBoxVHWACommandElement * pCmd);
1133
1134 VBoxVHWASurfaceBase* handle2Surface(uint32_t h)
1135 {
1136 VBoxVHWASurfaceBase* pSurf = (VBoxVHWASurfaceBase*)mSurfHandleTable.get(h);
1137 Assert(pSurf);
1138 return pSurf;
1139 }
1140
1141 VBoxVHWAHandleTable mSurfHandleTable;
1142
1143 PFNVBOXQGLOP mpfnOp;
1144 void *mOpContext;
1145
1146 ulong mPixelFormat;
1147 bool mUsesGuestVRAM;
1148// bool mbVGASurfCreated;
1149 QRect mViewport;
1150
1151 class VBoxConsoleView *mView;
1152
1153 VBoxVHWASurfList *mConstructingList;
1154 int32_t mcRemaining2Contruct;
1155
1156 /* this is used in saved state restore to postpone surface restoration
1157 * till the framebuffer size is restored */
1158 VHWACommandList mOnResizeCmdList;
1159
1160 class VBoxVHWAGlProgramMngr *mpMngr;
1161};
1162
1163
1164typedef enum
1165{
1166 VBOXFBOVERLAY_DONE = 1,
1167 VBOXFBOVERLAY_MODIFIED,
1168 VBOXFBOVERLAY_UNTOUCHED
1169} VBOXFBOVERLAY_RESUT;
1170
1171class VBoxQGLOverlay
1172{
1173public:
1174 VBoxQGLOverlay (class VBoxConsoleView *aView, class VBoxFrameBuffer * aContainer);
1175
1176 int onVHWACommand(struct _VBOXVHWACMD * pCommand);
1177
1178 void onVHWACommandEvent(QEvent * pEvent);
1179
1180 /**
1181 * to be called on NotifyUpdate framebuffer call
1182 * @return true if the request was processed & should not be forwarded to the framebuffer
1183 * false - otherwise */
1184 bool onNotifyUpdate (ULONG aX, ULONG aY,
1185 ULONG aW, ULONG aH);
1186
1187 VBOXFBOVERLAY_RESUT onPaintEvent (const QPaintEvent *pe, QRect *pRect);
1188 void onResizeEvent (const class VBoxResizeEvent *re);
1189 void onResizeEventPostprocess (const class VBoxResizeEvent *re);
1190
1191 void viewportResized(QResizeEvent * re)
1192 {
1193 vboxDoCheckUpdateViewport();
1194 mGlCurrent = false;
1195 }
1196
1197 void viewportScrolled(int dx, int dy)
1198 {
1199 vboxDoCheckUpdateViewport();
1200 mGlCurrent = false;
1201 }
1202
1203 static bool isAcceleration2DVideoAvailable();
1204
1205 /* not supposed to be called by clients */
1206 int vhwaLoadExec(struct SSMHANDLE * pSSM, uint32_t u32Version);
1207 void vhwaSaveExec(struct SSMHANDLE * pSSM);
1208private:
1209 int vhwaSurfaceUnlock(struct _VBOXVHWACMD_SURF_UNLOCK *pCmd);
1210
1211 void repaintMain();
1212 void repaintOverlay()
1213 {
1214 if(mNeedOverlayRepaint)
1215 {
1216 mNeedOverlayRepaint = false;
1217 performDisplayOverlay();
1218 }
1219 }
1220 void repaint()
1221 {
1222 repaintOverlay();
1223 repaintMain();
1224 }
1225
1226 void makeCurrent()
1227 {
1228 if(!mGlCurrent)
1229 {
1230 mGlCurrent = true;
1231 mpOverlayWidget->makeCurrent();
1232 }
1233 }
1234
1235 void performDisplayOverlay()
1236 {
1237 if(mOverlayVisible)
1238 {
1239#if 0
1240 mpOverlayWidget->updateGL();
1241#else
1242 makeCurrent();
1243 mpOverlayWidget->performDisplay();
1244 mpOverlayWidget->swapBuffers();
1245#endif
1246 }
1247 }
1248
1249// void vboxOpExit()
1250// {
1251// performDisplayOverlay();
1252// mGlCurrent = false;
1253// }
1254
1255
1256 void vboxSetGlOn(bool on);
1257 bool vboxGetGlOn() { return mGlOn; }
1258 bool vboxSynchGl();
1259 void vboxDoVHWACmdExec(void *cmd);
1260 void vboxShowOverlay(bool show);
1261 void vboxDoCheckUpdateViewport();
1262 void vboxDoVHWACmd(void *cmd);
1263 void addMainDirtyRect(const QRect & aRect);
1264// void vboxUpdateOverlayPosition(const QPoint & pos);
1265 void vboxCheckUpdateOverlay(const QRect & rect);
1266 VBoxVHWACommandElement * processCmdList(VBoxVHWACommandElement * pCmd);
1267
1268 int vhwaConstruct(struct _VBOXVHWACMD_HH_CONSTRUCT *pCmd);
1269
1270 VBoxGLWidget *mpOverlayWidget;
1271 class VBoxConsoleView *mView;
1272 class VBoxFrameBuffer *mContainer;
1273 bool mGlOn;
1274 bool mOverlayWidgetVisible;
1275 bool mOverlayVisible;
1276 bool mGlCurrent;
1277 bool mProcessingCommands;
1278 bool mNeedOverlayRepaint;
1279 QRect mOverlayViewport;
1280 VBoxVHWADirtyRect mMainDirtyRect;
1281
1282 VBoxVHWACommandElementProcessor mCmdPipe;
1283
1284 /* this is used in saved state restore to postpone surface restoration
1285 * till the framebuffer size is restored */
1286 VHWACommandList mOnResizeCmdList;
1287};
1288
1289
1290template <class T>
1291class VBoxOverlayFrameBuffer : public T
1292{
1293public:
1294 VBoxOverlayFrameBuffer (class VBoxConsoleView *aView)
1295 : T(aView),
1296 mOverlay(aView, this)
1297 {}
1298
1299
1300 STDMETHOD(ProcessVHWACommand)(BYTE *pCommand)
1301 {
1302 return mOverlay.onVHWACommand((struct _VBOXVHWACMD*)pCommand);
1303 }
1304
1305 void doProcessVHWACommand(QEvent * pEvent)
1306 {
1307 mOverlay.onVHWACommandEvent(pEvent);
1308 }
1309
1310 STDMETHOD(NotifyUpdate) (ULONG aX, ULONG aY,
1311 ULONG aW, ULONG aH)
1312 {
1313 if(mOverlay.onNotifyUpdate(aX, aY, aW, aH))
1314 return S_OK;
1315 return T::NotifyUpdate(aX, aY, aW, aH);
1316 }
1317
1318 void paintEvent (QPaintEvent *pe)
1319 {
1320 QRect rect;
1321 VBOXFBOVERLAY_RESUT res = mOverlay.onPaintEvent(pe, &rect);
1322 switch(res)
1323 {
1324 case VBOXFBOVERLAY_MODIFIED:
1325 {
1326 QPaintEvent modified(rect);
1327 T::paintEvent(&modified);
1328 } break;
1329 case VBOXFBOVERLAY_UNTOUCHED:
1330 T::paintEvent(pe);
1331 break;
1332 default:
1333 break;
1334 }
1335 }
1336
1337 void resizeEvent (VBoxResizeEvent *re)
1338 {
1339 mOverlay.onResizeEvent(re);
1340 T::resizeEvent(re);
1341 mOverlay.onResizeEventPostprocess(re);
1342 }
1343
1344 void viewportResized(QResizeEvent * re)
1345 {
1346 mOverlay.viewportResized(re);
1347 T::viewportResized(re);
1348 }
1349
1350 void viewportScrolled(int dx, int dy)
1351 {
1352 mOverlay.viewportScrolled(dx, dy);
1353 T::viewportScrolled(dx, dy);
1354 }
1355private:
1356 VBoxQGLOverlay mOverlay;
1357};
1358
1359#endif
1360
1361#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