VirtualBox

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

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

video hw accel: overlay update fixes

File size: 38.7 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; }
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 bool 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 bool performDisplay(bool bForce)
775 {
776 VBoxVHWASurfaceBase * pPrimary = mPrimary.current();
777 bForce |= pPrimary->performDisplay(NULL, bForce);
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 bForce |= pOverlay->performDisplay(pPrimary, bForce);
786 }
787 }
788 return bForce;
789 }
790
791 const OverlayList & overlays() const {return mOverlays;}
792 const VBoxVHWASurfList & primaries() const { return mPrimary; }
793
794private:
795 VBoxVHWASurfaceBase *mSurfVGA;
796 VBoxVHWASurfList mPrimary;
797
798 OverlayList mOverlays;
799};
800
801typedef void (VBoxGLWidget::*PFNVBOXQGLOP)(void* );
802
803typedef void (*PFNVBOXQGLFUNC)(void*, void*);
804
805typedef enum
806{
807 VBOXVHWA_PIPECMD_PAINT = 1,
808 VBOXVHWA_PIPECMD_VHWA,
809 VBOXVHWA_PIPECMD_OP,
810 VBOXVHWA_PIPECMD_FUNC,
811}VBOXVHWA_PIPECMD_TYPE;
812
813typedef struct VBOXVHWACALLBACKINFO
814{
815 VBoxGLWidget *pThis;
816 PFNVBOXQGLOP pfnCallback;
817 void * pContext;
818}VBOXVHWACALLBACKINFO;
819
820typedef struct VBOXVHWAFUNCCALLBACKINFO
821{
822 PFNVBOXQGLFUNC pfnCallback;
823 void * pContext1;
824 void * pContext2;
825}VBOXVHWAFUNCCALLBACKINFO;
826
827class VBoxVHWACommandElement
828{
829public:
830 void setVHWACmd(struct _VBOXVHWACMD * pCmd)
831 {
832 mType = VBOXVHWA_PIPECMD_VHWA;
833 u.mpCmd = pCmd;
834 }
835
836 void setPaintCmd(const QRect & aRect)
837 {
838 mType = VBOXVHWA_PIPECMD_PAINT;
839 mRect = aRect;
840 }
841
842 void setOp(const VBOXVHWACALLBACKINFO & aOp)
843 {
844 mType = VBOXVHWA_PIPECMD_OP;
845 u.mCallback = aOp;
846 }
847
848 void setFunc(const VBOXVHWAFUNCCALLBACKINFO & aOp)
849 {
850 mType = VBOXVHWA_PIPECMD_FUNC;
851 u.mFuncCallback = aOp;
852 }
853
854 void setData(VBOXVHWA_PIPECMD_TYPE aType, void * pvData)
855 {
856 switch(aType)
857 {
858 case VBOXVHWA_PIPECMD_PAINT:
859 setPaintCmd(*((QRect*)pvData));
860 break;
861 case VBOXVHWA_PIPECMD_VHWA:
862 setVHWACmd((struct _VBOXVHWACMD *)pvData);
863 break;
864 case VBOXVHWA_PIPECMD_OP:
865 setOp(*((VBOXVHWACALLBACKINFO *)pvData));
866 break;
867 case VBOXVHWA_PIPECMD_FUNC:
868 setFunc(*((VBOXVHWAFUNCCALLBACKINFO *)pvData));
869 break;
870 default:
871 Assert(0);
872 break;
873 }
874 }
875
876 VBOXVHWA_PIPECMD_TYPE type() const {return mType;}
877 const QRect & rect() const {return mRect;}
878 struct _VBOXVHWACMD * vhwaCmd() const {return u.mpCmd;}
879 const VBOXVHWACALLBACKINFO & op() const {return u.mCallback; }
880 const VBOXVHWAFUNCCALLBACKINFO & func() const {return u.mFuncCallback; }
881
882 VBoxVHWACommandElement * mpNext;
883private:
884 VBOXVHWA_PIPECMD_TYPE mType;
885 union
886 {
887 struct _VBOXVHWACMD * mpCmd;
888 VBOXVHWACALLBACKINFO mCallback;
889 VBOXVHWAFUNCCALLBACKINFO mFuncCallback;
890 }u;
891 QRect mRect;
892};
893
894class VBoxVHWACommandElementPipe
895{
896public:
897 VBoxVHWACommandElementPipe() :
898 mpFirst(NULL),
899 mpLast(NULL)
900 {}
901
902 void put(VBoxVHWACommandElement *pCmd)
903 {
904 if(mpLast)
905 {
906 Assert(mpFirst);
907 mpLast->mpNext = pCmd;
908 mpLast = pCmd;
909 }
910 else
911 {
912 Assert(!mpFirst);
913 mpFirst = pCmd;
914 mpLast = pCmd;
915 }
916 pCmd->mpNext= NULL;
917
918 }
919
920 VBoxVHWACommandElement * detachList()
921 {
922 if(mpLast)
923 {
924 VBoxVHWACommandElement * pHead = mpFirst;
925 mpFirst = NULL;
926 mpLast = NULL;
927 return pHead;
928 }
929 return NULL;
930 }
931private:
932 VBoxVHWACommandElement *mpFirst;
933 VBoxVHWACommandElement *mpLast;
934};
935
936class VBoxVHWACommandElementStack
937{
938public:
939 VBoxVHWACommandElementStack() :
940 mpFirst(NULL) {}
941
942 void push(VBoxVHWACommandElement *pCmd)
943 {
944 pCmd->mpNext = mpFirst;
945 mpFirst = pCmd;
946 }
947
948 void pusha(VBoxVHWACommandElement *pFirst, VBoxVHWACommandElement *pLast)
949 {
950 pLast->mpNext = mpFirst;
951 mpFirst = pFirst;
952 }
953
954 VBoxVHWACommandElement * pop()
955 {
956 if(mpFirst)
957 {
958 VBoxVHWACommandElement * ret = mpFirst;
959 mpFirst = ret->mpNext;
960 return ret;
961 }
962 return NULL;
963 }
964private:
965 VBoxVHWACommandElement *mpFirst;
966};
967
968#define VBOXVHWACMDPIPEC_NEWEVENT 0x00000001
969#define VBOXVHWACMDPIPEC_COMPLETEEVENT 0x00000002
970class VBoxVHWACommandElementProcessor
971{
972public:
973 VBoxVHWACommandElementProcessor(class VBoxConsoleView *aView);
974 ~VBoxVHWACommandElementProcessor();
975 void postCmd(VBOXVHWA_PIPECMD_TYPE aType, void * pvData, uint32_t flags);
976 void completeCurrentEvent();
977 class VBoxVHWACommandElement * detachCmdList(class VBoxVHWACommandElement * pFirst2Free, VBoxVHWACommandElement * pLast2Free);
978
979private:
980 RTCRITSECT mCritSect;
981 class VBoxVHWACommandProcessEvent *mpFirstEvent;
982 class VBoxVHWACommandProcessEvent *mpLastEvent;
983 class VBoxConsoleView *mView;
984 bool mbNewEvent;
985 VBoxVHWACommandElementStack mFreeElements;
986 VBoxVHWACommandElement mElementsBuffer[2048];
987};
988
989class VBoxVHWACommandsQueue
990{
991public:
992 void enqueue(PFNVBOXQGLFUNC pfn, void* pContext1, void* pContext2);
993
994 VBoxVHWACommandElement * detachList();
995
996 void freeList(VBoxVHWACommandElement * pList);
997
998private:
999 VBoxVHWACommandElementPipe mCmds;
1000};
1001
1002class VBoxGLWidget : public QGLWidget
1003{
1004public:
1005 VBoxGLWidget (class VBoxConsoleView *aView, QWidget *aParent);
1006 ~VBoxGLWidget();
1007
1008 ulong vboxPixelFormat() { return mPixelFormat; }
1009 bool vboxUsesGuestVRAM() { return mUsesGuestVRAM; }
1010
1011 uchar *vboxAddress() { return mDisplay.getVGA() ? mDisplay.getVGA()->address() : NULL; }
1012
1013#ifdef VBOX_WITH_VIDEOHWACCEL
1014 uchar *vboxVRAMAddressFromOffset(uint64_t offset);
1015 uint64_t vboxVRAMOffsetFromAddress(uchar* addr);
1016 uint64_t vboxVRAMOffset(VBoxVHWASurfaceBase * pSurf);
1017
1018 void vhwaSaveExec(struct SSMHANDLE * pSSM);
1019 int vhwaLoadExec(VHWACommandList * pCmdList, struct SSMHANDLE * pSSM, uint32_t u32Version);
1020
1021 int vhwaSurfaceCanCreate(struct _VBOXVHWACMD_SURF_CANCREATE *pCmd);
1022 int vhwaSurfaceCreate(struct _VBOXVHWACMD_SURF_CREATE *pCmd);
1023 int vhwaSurfaceDestroy(struct _VBOXVHWACMD_SURF_DESTROY *pCmd);
1024 int vhwaSurfaceLock(struct _VBOXVHWACMD_SURF_LOCK *pCmd);
1025 int vhwaSurfaceUnlock(struct _VBOXVHWACMD_SURF_UNLOCK *pCmd);
1026 int vhwaSurfaceBlt(struct _VBOXVHWACMD_SURF_BLT *pCmd);
1027 int vhwaSurfaceFlip(struct _VBOXVHWACMD_SURF_FLIP *pCmd);
1028 int vhwaSurfaceOverlayUpdate(struct _VBOXVHWACMD_SURF_OVERLAY_UPDATE *pCmf);
1029 int vhwaSurfaceOverlaySetPosition(struct _VBOXVHWACMD_SURF_OVERLAY_SETPOSITION *pCmd);
1030 int vhwaSurfaceColorkeySet(struct _VBOXVHWACMD_SURF_COLORKEY_SET *pCmd);
1031 int vhwaQueryInfo1(struct _VBOXVHWACMD_QUERYINFO1 *pCmd);
1032 int vhwaQueryInfo2(struct _VBOXVHWACMD_QUERYINFO2 *pCmd);
1033 int vhwaConstruct(struct _VBOXVHWACMD_HH_CONSTRUCT *pCmd);
1034
1035 bool hasSurfaces() const;
1036 bool hasVisibleOverlays();
1037 const QRect & overlaysRectUnion();
1038#endif
1039
1040 ulong vboxBitsPerPixel() { return mDisplay.getVGA()->bitsPerPixel(); }
1041 ulong vboxBytesPerLine() { return mDisplay.getVGA() ? mDisplay.getVGA()->bytesPerLine() : 0; }
1042 int vboxFbWidth() {return mDisplay.getVGA()->width(); }
1043 int vboxFbHeight() {return mDisplay.getVGA()->height(); }
1044 bool vboxIsInitialized() {return mDisplay.getVGA() != NULL; }
1045
1046// void vboxPaintEvent (QPaintEvent *pe) {vboxPerformGLOp(&VBoxGLWidget::vboxDoPaint, pe); }
1047 void vboxResizeEvent (class VBoxResizeEvent *re) {vboxPerformGLOp(&VBoxGLWidget::vboxDoResize, re); }
1048
1049 void vboxProcessVHWACommands(class VBoxVHWACommandElementProcessor * pPipe) {vboxPerformGLOp(&VBoxGLWidget::vboxDoProcessVHWACommands, pPipe);}
1050#ifdef VBOX_WITH_VIDEOHWACCEL
1051 void vboxVHWACmd (struct _VBOXVHWACMD * pCmd) {vboxPerformGLOp(&VBoxGLWidget::vboxDoVHWACmd, pCmd);}
1052#endif
1053 class VBoxVHWAGlProgramMngr * vboxVHWAGetGlProgramMngr() { return mpMngr; }
1054
1055 VBoxVHWASurfaceBase * vboxGetVGASurface() { return mDisplay.getVGA(); }
1056
1057 static void doSetupMatrix(const QSize & aSize, bool bInverted);
1058
1059 void vboxDoUpdateViewport(const QRect & aRect);
1060 void vboxDoUpdateRect(const QRect * pRect);
1061
1062 const QRect & vboxViewport() const {return mViewport;}
1063
1064 bool performDisplay(bool bForce) { return mDisplay.performDisplay(bForce); }
1065protected:
1066
1067 void paintGL()
1068 {
1069 if(mpfnOp)
1070 {
1071 (this->*mpfnOp)(mOpContext);
1072 mpfnOp = NULL;
1073 }
1074// else
1075// {
1076 mDisplay.performDisplay(true);
1077// }
1078 }
1079
1080 void initializeGL();
1081
1082private:
1083 static void setupMatricies(const QSize &display);
1084 static void adjustViewport(const QSize &display, const QRect &viewport);
1085 void vboxDoResize(void *re);
1086// void vboxDoPaint(void *rec);
1087
1088
1089#ifdef VBOXQGL_DBG_SURF
1090 void vboxDoTestSurfaces(void *context);
1091#endif
1092#ifdef VBOX_WITH_VIDEOHWACCEL
1093 void vboxDoVHWACmdExec(void *cmd);
1094 void vboxDoVHWACmdAndFree(void *cmd);
1095 void vboxDoVHWACmd(void *cmd);
1096
1097 void vboxCheckUpdateAddress (VBoxVHWASurfaceBase * pSurface, uint64_t offset)
1098 {
1099 if (pSurface->addressAlocated())
1100 {
1101 uchar * addr = vboxVRAMAddressFromOffset(offset);
1102 if(addr)
1103 {
1104 pSurface->setAddress(addr);
1105 }
1106 }
1107 }
1108
1109 int vhwaSaveSurface(struct SSMHANDLE * pSSM, VBoxVHWASurfaceBase *pSurf, uint32_t surfCaps);
1110 int vhwaLoadSurface(VHWACommandList * pCmdList, struct SSMHANDLE * pSSM, uint32_t u32Version);
1111 int vhwaSaveOverlayData(struct SSMHANDLE * pSSM, VBoxVHWASurfaceBase *pSurf, bool bVisible);
1112 int vhwaLoadOverlayData(VHWACommandList * pCmdList, struct SSMHANDLE * pSSM, uint32_t u32Version);
1113 void vhwaDoSurfaceOverlayUpdate(VBoxVHWASurfaceBase *pDstSurf, VBoxVHWASurfaceBase *pSrcSurf, struct _VBOXVHWACMD_SURF_OVERLAY_UPDATE *pCmd);
1114#endif
1115 static const QGLFormat & vboxGLFormat();
1116
1117 VBoxVHWADisplay mDisplay;
1118
1119
1120 /* we do all opengl stuff in the paintGL context,
1121 * submit the operation to be performed
1122 * @todo: could be moved outside the updateGL */
1123 void vboxPerformGLOp(PFNVBOXQGLOP pfn, void* pContext)
1124 {
1125 mpfnOp = pfn;
1126 mOpContext = pContext;
1127 updateGL();
1128 }
1129
1130// /* posts op to UI thread */
1131// int vboxExecOpSynch(PFNVBOXQGLOP pfn, void* pContext);
1132// void vboxExecOnResize(PFNVBOXQGLOP pfn, void* pContext);
1133
1134 void vboxDoProcessVHWACommands(void *pContext);
1135
1136 class VBoxVHWACommandElement * processCmdList(class VBoxVHWACommandElement * pCmd);
1137
1138 VBoxVHWASurfaceBase* handle2Surface(uint32_t h)
1139 {
1140 VBoxVHWASurfaceBase* pSurf = (VBoxVHWASurfaceBase*)mSurfHandleTable.get(h);
1141 Assert(pSurf);
1142 return pSurf;
1143 }
1144
1145 VBoxVHWAHandleTable mSurfHandleTable;
1146
1147 PFNVBOXQGLOP mpfnOp;
1148 void *mOpContext;
1149
1150 ulong mPixelFormat;
1151 bool mUsesGuestVRAM;
1152// bool mbVGASurfCreated;
1153 QRect mViewport;
1154
1155 class VBoxConsoleView *mView;
1156
1157 VBoxVHWASurfList *mConstructingList;
1158 int32_t mcRemaining2Contruct;
1159
1160 /* this is used in saved state restore to postpone surface restoration
1161 * till the framebuffer size is restored */
1162 VHWACommandList mOnResizeCmdList;
1163
1164 class VBoxVHWAGlProgramMngr *mpMngr;
1165};
1166
1167
1168//typedef enum
1169//{
1170// VBOXFBOVERLAY_DONE = 1,
1171// VBOXFBOVERLAY_MODIFIED,
1172// VBOXFBOVERLAY_UNTOUCHED
1173//} VBOXFBOVERLAY_RESUT;
1174
1175class VBoxQGLOverlay
1176{
1177public:
1178 VBoxQGLOverlay (class VBoxConsoleView *aView, class VBoxFrameBuffer * aContainer);
1179
1180 int onVHWACommand(struct _VBOXVHWACMD * pCommand);
1181
1182 void onVHWACommandEvent(QEvent * pEvent);
1183
1184 /**
1185 * to be called on NotifyUpdate framebuffer call
1186 * @return true if the request was processed & should not be forwarded to the framebuffer
1187 * false - otherwise */
1188 bool onNotifyUpdate (ULONG aX, ULONG aY,
1189 ULONG aW, ULONG aH);
1190
1191 /**
1192 * to be called on RequestResize framebuffer call
1193 * @return true if the request was processed & should not be forwarded to the framebuffer
1194 * false - otherwise */
1195 bool onRequestResize (ULONG aScreenId, ULONG aPixelFormat,
1196 BYTE *aVRAM, ULONG aBitsPerPixel, ULONG aBytesPerLine,
1197 ULONG aWidth, ULONG aHeight,
1198 BOOL *aFinished)
1199 {
1200 mCmdPipe.completeCurrentEvent();
1201 return false;
1202 }
1203
1204// VBOXFBOVERLAY_RESUT onPaintEvent (const QPaintEvent *pe, QRect *pRect);
1205
1206 void onResizeEvent (const class VBoxResizeEvent *re);
1207 void onResizeEventPostprocess (const class VBoxResizeEvent *re);
1208
1209 void onViewportResized(QResizeEvent * re)
1210 {
1211 vboxDoCheckUpdateViewport();
1212 mGlCurrent = false;
1213 }
1214
1215 void onViewportScrolled(int dx, int dy)
1216 {
1217 vboxDoCheckUpdateViewport();
1218 mGlCurrent = false;
1219 }
1220
1221 static bool isAcceleration2DVideoAvailable();
1222
1223 /* not supposed to be called by clients */
1224 int vhwaLoadExec(struct SSMHANDLE * pSSM, uint32_t u32Version);
1225 void vhwaSaveExec(struct SSMHANDLE * pSSM);
1226private:
1227 int vhwaSurfaceUnlock(struct _VBOXVHWACMD_SURF_UNLOCK *pCmd);
1228
1229 void repaintMain();
1230 void repaintOverlay()
1231 {
1232 if(mNeedOverlayRepaint)
1233 {
1234 mNeedOverlayRepaint = false;
1235 performDisplayOverlay();
1236 }
1237 }
1238 void repaint()
1239 {
1240 repaintOverlay();
1241 repaintMain();
1242 }
1243
1244 void makeCurrent()
1245 {
1246 if(!mGlCurrent)
1247 {
1248 mGlCurrent = true;
1249 mpOverlayWidget->makeCurrent();
1250 }
1251 }
1252
1253 void performDisplayOverlay()
1254 {
1255 if(mOverlayVisible)
1256 {
1257#if 0
1258 mpOverlayWidget->updateGL();
1259#else
1260 makeCurrent();
1261 mpOverlayWidget->performDisplay(false);
1262 mpOverlayWidget->swapBuffers();
1263#endif
1264 }
1265 }
1266
1267// void vboxOpExit()
1268// {
1269// performDisplayOverlay();
1270// mGlCurrent = false;
1271// }
1272
1273
1274 void vboxSetGlOn(bool on);
1275 bool vboxGetGlOn() { return mGlOn; }
1276 bool vboxSynchGl();
1277 void vboxDoVHWACmdExec(void *cmd);
1278 void vboxShowOverlay(bool show);
1279 void vboxDoCheckUpdateViewport();
1280 void vboxDoVHWACmd(void *cmd);
1281 void addMainDirtyRect(const QRect & aRect);
1282// void vboxUpdateOverlayPosition(const QPoint & pos);
1283 void vboxCheckUpdateOverlay(const QRect & rect);
1284 VBoxVHWACommandElement * processCmdList(VBoxVHWACommandElement * pCmd);
1285
1286 int vhwaConstruct(struct _VBOXVHWACMD_HH_CONSTRUCT *pCmd);
1287
1288 VBoxGLWidget *mpOverlayWidget;
1289 class VBoxConsoleView *mView;
1290 class VBoxFrameBuffer *mContainer;
1291 bool mGlOn;
1292 bool mOverlayWidgetVisible;
1293 bool mOverlayVisible;
1294 bool mGlCurrent;
1295 bool mProcessingCommands;
1296 bool mNeedOverlayRepaint;
1297 QRect mOverlayViewport;
1298 VBoxVHWADirtyRect mMainDirtyRect;
1299
1300 VBoxVHWACommandElementProcessor mCmdPipe;
1301
1302 /* this is used in saved state restore to postpone surface restoration
1303 * till the framebuffer size is restored */
1304 VHWACommandList mOnResizeCmdList;
1305};
1306
1307
1308template <class T>
1309class VBoxOverlayFrameBuffer : public T
1310{
1311public:
1312 VBoxOverlayFrameBuffer (class VBoxConsoleView *aView)
1313 : T(aView),
1314 mOverlay(aView, this)
1315 {}
1316
1317
1318 STDMETHOD(ProcessVHWACommand)(BYTE *pCommand)
1319 {
1320 return mOverlay.onVHWACommand((struct _VBOXVHWACMD*)pCommand);
1321 }
1322
1323 void doProcessVHWACommand(QEvent * pEvent)
1324 {
1325 mOverlay.onVHWACommandEvent(pEvent);
1326 }
1327
1328 STDMETHOD(RequestResize) (ULONG aScreenId, ULONG aPixelFormat,
1329 BYTE *aVRAM, ULONG aBitsPerPixel, ULONG aBytesPerLine,
1330 ULONG aWidth, ULONG aHeight,
1331 BOOL *aFinished)
1332 {
1333 if(mOverlay.onRequestResize (aScreenId, aPixelFormat,
1334 aVRAM, aBitsPerPixel, aBytesPerLine,
1335 aWidth, aHeight,
1336 aFinished))
1337 {
1338 return S_OK;
1339 }
1340 return T::RequestResize (aScreenId, aPixelFormat,
1341 aVRAM, aBitsPerPixel, aBytesPerLine,
1342 aWidth, aHeight,
1343 aFinished);
1344 }
1345
1346 STDMETHOD(NotifyUpdate) (ULONG aX, ULONG aY,
1347 ULONG aW, ULONG aH)
1348 {
1349 if(mOverlay.onNotifyUpdate(aX, aY, aW, aH))
1350 return S_OK;
1351 return T::NotifyUpdate(aX, aY, aW, aH);
1352 }
1353
1354// void paintEvent (QPaintEvent *pe)
1355// {
1356// QRect rect;
1357// VBOXFBOVERLAY_RESUT res = mOverlay.onPaintEvent(pe, &rect);
1358// switch(res)
1359// {
1360// case VBOXFBOVERLAY_MODIFIED:
1361// {
1362// QPaintEvent modified(rect);
1363// T::paintEvent(&modified);
1364// } break;
1365// case VBOXFBOVERLAY_UNTOUCHED:
1366// T::paintEvent(pe);
1367// break;
1368// default:
1369// break;
1370// }
1371// }
1372
1373 void resizeEvent (VBoxResizeEvent *re)
1374 {
1375 mOverlay.onResizeEvent(re);
1376 T::resizeEvent(re);
1377 mOverlay.onResizeEventPostprocess(re);
1378 }
1379
1380 void viewportResized(QResizeEvent * re)
1381 {
1382 mOverlay.onViewportResized(re);
1383 T::viewportResized(re);
1384 }
1385
1386 void viewportScrolled(int dx, int dy)
1387 {
1388 mOverlay.onViewportScrolled(dx, dy);
1389 T::viewportScrolled(dx, dy);
1390 }
1391private:
1392 VBoxQGLOverlay mOverlay;
1393};
1394
1395#endif
1396
1397#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