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