VirtualBox

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

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

video hw accel: fix gl context & stretching issues

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

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