1 | /** @file
|
---|
2 | *
|
---|
3 | * VBox frontends: Qt GUI ("VirtualBox"):
|
---|
4 | * VBoxFrameBuffer Overly classes declarations
|
---|
5 | */
|
---|
6 |
|
---|
7 | /*
|
---|
8 | * Copyright (C) 2006-2007 Oracle Corporation
|
---|
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 | #ifndef __VBoxFBOverlay_h__
|
---|
19 | #define __VBoxFBOverlay_h__
|
---|
20 | #if defined (VBOX_GUI_USE_QGL) || defined(VBOX_WITH_VIDEOHWACCEL)
|
---|
21 |
|
---|
22 | //#define VBOXQGL_PROF_BASE 1
|
---|
23 | //#define VBOXQGL_DBG_SURF 1
|
---|
24 |
|
---|
25 | //#define VBOXVHWADBG_RENDERCHECK
|
---|
26 |
|
---|
27 | #include "COMDefs.h"
|
---|
28 | #include <QGLWidget>
|
---|
29 | #include <iprt/assert.h>
|
---|
30 | #include <iprt/critsect.h>
|
---|
31 | #include <iprt/asm.h>
|
---|
32 | #include <iprt/err.h>
|
---|
33 |
|
---|
34 | #include <VBox/VBoxGL2D.h>
|
---|
35 | #include "VBoxFBOverlayCommon.h"
|
---|
36 |
|
---|
37 | #define VBOXVHWA_ALLOW_PRIMARY_AND_OVERLAY_ONLY 1
|
---|
38 |
|
---|
39 | #ifdef DEBUG_misha
|
---|
40 | # define VBOXVHWA_PROFILE_FPS
|
---|
41 | #endif
|
---|
42 |
|
---|
43 | #ifdef DEBUG
|
---|
44 | class VBoxVHWADbgTimer
|
---|
45 | {
|
---|
46 | public:
|
---|
47 | VBoxVHWADbgTimer(uint32_t cPeriods);
|
---|
48 | ~VBoxVHWADbgTimer();
|
---|
49 | void frame();
|
---|
50 | uint64_t everagePeriod() {return mPeriodSum / mcPeriods; }
|
---|
51 | double fps() {return ((double)1000000000.0) / everagePeriod(); }
|
---|
52 | uint64_t frames() {return mcFrames; }
|
---|
53 | private:
|
---|
54 | uint64_t mPeriodSum;
|
---|
55 | uint64_t *mpaPeriods;
|
---|
56 | uint64_t mPrevTime;
|
---|
57 | uint64_t mcFrames;
|
---|
58 | uint32_t mcPeriods;
|
---|
59 | uint32_t miPeriod;
|
---|
60 | };
|
---|
61 |
|
---|
62 | #endif
|
---|
63 |
|
---|
64 | class VBoxVHWASettings
|
---|
65 | {
|
---|
66 | public:
|
---|
67 | VBoxVHWASettings (CSession &session);
|
---|
68 |
|
---|
69 | int fourccEnabledCount() const { return mFourccEnabledCount; }
|
---|
70 | const uint32_t * fourccEnabledList() const { return mFourccEnabledList; }
|
---|
71 |
|
---|
72 | bool isStretchLinearEnabled() const { return mStretchLinearEnabled; }
|
---|
73 |
|
---|
74 | static int calcIntersection (int c1, const uint32_t *a1, int c2, const uint32_t *a2, int cOut, uint32_t *aOut);
|
---|
75 |
|
---|
76 | int getIntersection (const VBoxVHWAInfo &aInfo, int cOut, uint32_t *aOut)
|
---|
77 | {
|
---|
78 | return calcIntersection (mFourccEnabledCount, mFourccEnabledList, aInfo.getFourccSupportedCount(), aInfo.getFourccSupportedList(), cOut, aOut);
|
---|
79 | }
|
---|
80 |
|
---|
81 | bool isSupported(const VBoxVHWAInfo &aInfo, uint32_t format)
|
---|
82 | {
|
---|
83 | return calcIntersection (mFourccEnabledCount, mFourccEnabledList, 1, &format, 0, NULL)
|
---|
84 | && calcIntersection (aInfo.getFourccSupportedCount(), aInfo.getFourccSupportedList(), 1, &format, 0, NULL);
|
---|
85 | }
|
---|
86 | private:
|
---|
87 | uint32_t mFourccEnabledList[VBOXVHWA_NUMFOURCC];
|
---|
88 | int mFourccEnabledCount;
|
---|
89 | bool mStretchLinearEnabled;
|
---|
90 | };
|
---|
91 |
|
---|
92 | class VBoxVHWADirtyRect
|
---|
93 | {
|
---|
94 | public:
|
---|
95 | VBoxVHWADirtyRect() :
|
---|
96 | mIsClear(true)
|
---|
97 | {}
|
---|
98 |
|
---|
99 | VBoxVHWADirtyRect(const QRect & aRect)
|
---|
100 | {
|
---|
101 | if(aRect.isEmpty())
|
---|
102 | {
|
---|
103 | mIsClear = false;
|
---|
104 | mRect = aRect;
|
---|
105 | }
|
---|
106 | else
|
---|
107 | {
|
---|
108 | mIsClear = true;
|
---|
109 | }
|
---|
110 | }
|
---|
111 |
|
---|
112 | bool isClear() const { return mIsClear; }
|
---|
113 |
|
---|
114 | void add(const QRect & aRect)
|
---|
115 | {
|
---|
116 | if(aRect.isEmpty())
|
---|
117 | return;
|
---|
118 |
|
---|
119 | mRect = mIsClear ? aRect : mRect.united(aRect);
|
---|
120 | mIsClear = false;
|
---|
121 | }
|
---|
122 |
|
---|
123 | void add(const VBoxVHWADirtyRect & aRect)
|
---|
124 | {
|
---|
125 | if(aRect.isClear())
|
---|
126 | return;
|
---|
127 | add(aRect.rect());
|
---|
128 | }
|
---|
129 |
|
---|
130 | void set(const QRect & aRect)
|
---|
131 | {
|
---|
132 | if(aRect.isEmpty())
|
---|
133 | {
|
---|
134 | mIsClear = true;
|
---|
135 | }
|
---|
136 | else
|
---|
137 | {
|
---|
138 | mRect = aRect;
|
---|
139 | mIsClear = false;
|
---|
140 | }
|
---|
141 | }
|
---|
142 |
|
---|
143 | void clear() { mIsClear = true; }
|
---|
144 |
|
---|
145 | const QRect & rect() const {return mRect;}
|
---|
146 |
|
---|
147 | const QRect & toRect()
|
---|
148 | {
|
---|
149 | if(isClear())
|
---|
150 | {
|
---|
151 | mRect.setCoords(0, 0, -1, -1);
|
---|
152 | }
|
---|
153 | return mRect;
|
---|
154 | }
|
---|
155 |
|
---|
156 | bool intersects(const QRect & aRect) const {return mIsClear ? false : mRect.intersects(aRect);}
|
---|
157 |
|
---|
158 | bool intersects(const VBoxVHWADirtyRect & aRect) const {return mIsClear ? false : aRect.intersects(mRect);}
|
---|
159 |
|
---|
160 | QRect united(const QRect & aRect) const {return mIsClear ? aRect : aRect.united(mRect);}
|
---|
161 |
|
---|
162 | bool contains(const QRect & aRect) const {return mIsClear ? false : aRect.contains(mRect);}
|
---|
163 |
|
---|
164 | void subst(const VBoxVHWADirtyRect & aRect) { if(!mIsClear && aRect.contains(mRect)) clear(); }
|
---|
165 |
|
---|
166 | private:
|
---|
167 | QRect mRect;
|
---|
168 | bool mIsClear;
|
---|
169 | };
|
---|
170 |
|
---|
171 | class VBoxVHWAColorKey
|
---|
172 | {
|
---|
173 | public:
|
---|
174 | VBoxVHWAColorKey() :
|
---|
175 | mUpper(0),
|
---|
176 | mLower(0)
|
---|
177 | {}
|
---|
178 |
|
---|
179 | VBoxVHWAColorKey(uint32_t aUpper, uint32_t aLower) :
|
---|
180 | mUpper(aUpper),
|
---|
181 | mLower(aLower)
|
---|
182 | {}
|
---|
183 |
|
---|
184 | uint32_t upper() const {return mUpper; }
|
---|
185 | uint32_t lower() const {return mLower; }
|
---|
186 |
|
---|
187 | bool operator==(const VBoxVHWAColorKey & other) const { return mUpper == other.mUpper && mLower == other.mLower; }
|
---|
188 | bool operator!=(const VBoxVHWAColorKey & other) const { return !(*this == other); }
|
---|
189 | private:
|
---|
190 | uint32_t mUpper;
|
---|
191 | uint32_t mLower;
|
---|
192 | };
|
---|
193 |
|
---|
194 | class VBoxVHWAColorComponent
|
---|
195 | {
|
---|
196 | public:
|
---|
197 | VBoxVHWAColorComponent() :
|
---|
198 | mMask(0),
|
---|
199 | mRange(0),
|
---|
200 | mOffset(32),
|
---|
201 | mcBits(0)
|
---|
202 | {}
|
---|
203 |
|
---|
204 | VBoxVHWAColorComponent(uint32_t aMask);
|
---|
205 |
|
---|
206 | uint32_t mask() const { return mMask; }
|
---|
207 | uint32_t range() const { return mRange; }
|
---|
208 | uint32_t offset() const { return mOffset; }
|
---|
209 | uint32_t cBits() const { return mcBits; }
|
---|
210 | uint32_t colorVal(uint32_t col) const { return (col & mMask) >> mOffset; }
|
---|
211 | float colorValNorm(uint32_t col) const { return ((float)colorVal(col))/mRange; }
|
---|
212 | private:
|
---|
213 | uint32_t mMask;
|
---|
214 | uint32_t mRange;
|
---|
215 | uint32_t mOffset;
|
---|
216 | uint32_t mcBits;
|
---|
217 | };
|
---|
218 |
|
---|
219 | class VBoxVHWAColorFormat
|
---|
220 | {
|
---|
221 | public:
|
---|
222 |
|
---|
223 | VBoxVHWAColorFormat(uint32_t bitsPerPixel, uint32_t r, uint32_t g, uint32_t b);
|
---|
224 | VBoxVHWAColorFormat(uint32_t fourcc);
|
---|
225 | VBoxVHWAColorFormat() :
|
---|
226 | mBitsPerPixel(0) /* needed for isValid() to work */
|
---|
227 | {}
|
---|
228 | GLint internalFormat() const {return mInternalFormat; }
|
---|
229 | GLenum format() const {return mFormat; }
|
---|
230 | GLenum type() const {return mType; }
|
---|
231 | bool isValid() const {return mBitsPerPixel != 0; }
|
---|
232 | uint32_t fourcc() const {return mDataFormat;}
|
---|
233 | uint32_t bitsPerPixel() const { return mBitsPerPixel; }
|
---|
234 | uint32_t bitsPerPixelTex() const { return mBitsPerPixelTex; }
|
---|
235 | void pixel2Normalized(uint32_t pix, float *r, float *g, float *b) const;
|
---|
236 | uint32_t widthCompression() const {return mWidthCompression;}
|
---|
237 | uint32_t heightCompression() const {return mHeightCompression;}
|
---|
238 | const VBoxVHWAColorComponent& r() const {return mR;}
|
---|
239 | const VBoxVHWAColorComponent& g() const {return mG;}
|
---|
240 | const VBoxVHWAColorComponent& b() const {return mB;}
|
---|
241 | const VBoxVHWAColorComponent& a() const {return mA;}
|
---|
242 |
|
---|
243 | bool equals (const VBoxVHWAColorFormat & other) const;
|
---|
244 |
|
---|
245 | ulong toVBoxPixelFormat() const
|
---|
246 | {
|
---|
247 | if (!mDataFormat)
|
---|
248 | {
|
---|
249 | /* RGB data */
|
---|
250 | switch (mFormat)
|
---|
251 | {
|
---|
252 | case GL_BGRA_EXT:
|
---|
253 | return FramebufferPixelFormat_FOURCC_RGB;
|
---|
254 | }
|
---|
255 | }
|
---|
256 | return FramebufferPixelFormat_Opaque;
|
---|
257 | }
|
---|
258 |
|
---|
259 | private:
|
---|
260 | void init(uint32_t bitsPerPixel, uint32_t r, uint32_t g, uint32_t b);
|
---|
261 | void init(uint32_t fourcc);
|
---|
262 |
|
---|
263 | GLint mInternalFormat;
|
---|
264 | GLenum mFormat;
|
---|
265 | GLenum mType;
|
---|
266 | uint32_t mDataFormat;
|
---|
267 |
|
---|
268 | uint32_t mBitsPerPixel;
|
---|
269 | uint32_t mBitsPerPixelTex;
|
---|
270 | uint32_t mWidthCompression;
|
---|
271 | uint32_t mHeightCompression;
|
---|
272 | VBoxVHWAColorComponent mR;
|
---|
273 | VBoxVHWAColorComponent mG;
|
---|
274 | VBoxVHWAColorComponent mB;
|
---|
275 | VBoxVHWAColorComponent mA;
|
---|
276 | };
|
---|
277 |
|
---|
278 | class VBoxVHWATexture
|
---|
279 | {
|
---|
280 | public:
|
---|
281 | VBoxVHWATexture() :
|
---|
282 | mAddress(NULL),
|
---|
283 | mTexture(0),
|
---|
284 | mBytesPerPixel(0),
|
---|
285 | mBytesPerPixelTex(0),
|
---|
286 | mBytesPerLine(0),
|
---|
287 | mScaleFuncttion(GL_NEAREST)
|
---|
288 | {}
|
---|
289 | VBoxVHWATexture(const QRect & aRect, const VBoxVHWAColorFormat &aFormat, uint32_t bytesPerLine, GLint scaleFuncttion);
|
---|
290 | virtual ~VBoxVHWATexture();
|
---|
291 | virtual void init(uchar *pvMem);
|
---|
292 | void setAddress(uchar *pvMem) {mAddress = pvMem;}
|
---|
293 | void update(const QRect * pRect) { doUpdate(mAddress, pRect);}
|
---|
294 | void bind() {glBindTexture(texTarget(), mTexture);}
|
---|
295 |
|
---|
296 | virtual void texCoord(int x, int y);
|
---|
297 | virtual void multiTexCoord(GLenum texUnit, int x, int y);
|
---|
298 |
|
---|
299 | const QRect & texRect() {return mTexRect;}
|
---|
300 | const QRect & rect() {return mRect;}
|
---|
301 | uchar * address(){ return mAddress; }
|
---|
302 | uint32_t rectSizeTex(const QRect * pRect) {return pRect->width() * pRect->height() * mBytesPerPixelTex;}
|
---|
303 | uchar * pointAddress(int x, int y)
|
---|
304 | {
|
---|
305 | x = toXTex(x);
|
---|
306 | y = toYTex(y);
|
---|
307 | return pointAddressTex(x, y);
|
---|
308 | }
|
---|
309 | uint32_t pointOffsetTex(int x, int y) { return y*mBytesPerLine + x*mBytesPerPixelTex; }
|
---|
310 | uchar * pointAddressTex(int x, int y) { return mAddress + pointOffsetTex(x, y); }
|
---|
311 | int toXTex(int x) {return x/mColorFormat.widthCompression();}
|
---|
312 | int toYTex(int y) {return y/mColorFormat.heightCompression();}
|
---|
313 | ulong memSize(){ return mBytesPerLine * mRect.height(); }
|
---|
314 | uint32_t bytesPerLine() {return mBytesPerLine; }
|
---|
315 | #ifdef DEBUG_misha
|
---|
316 | void dbgDump();
|
---|
317 | #endif
|
---|
318 |
|
---|
319 | protected:
|
---|
320 | virtual void doUpdate(uchar * pAddress, const QRect * pRect);
|
---|
321 | virtual void initParams();
|
---|
322 | virtual void load();
|
---|
323 | virtual GLenum texTarget() {return GL_TEXTURE_2D; }
|
---|
324 | GLuint texture() {return mTexture;}
|
---|
325 |
|
---|
326 | QRect mTexRect; /* texture size */
|
---|
327 | QRect mRect; /* img size */
|
---|
328 | uchar * mAddress;
|
---|
329 | GLuint mTexture;
|
---|
330 | uint32_t mBytesPerPixel;
|
---|
331 | uint32_t mBytesPerPixelTex;
|
---|
332 | uint32_t mBytesPerLine;
|
---|
333 | VBoxVHWAColorFormat mColorFormat;
|
---|
334 | GLint mScaleFuncttion;
|
---|
335 | private:
|
---|
336 | void uninit();
|
---|
337 |
|
---|
338 | friend class VBoxVHWAFBO;
|
---|
339 | };
|
---|
340 |
|
---|
341 | class VBoxVHWATextureNP2 : public VBoxVHWATexture
|
---|
342 | {
|
---|
343 | public:
|
---|
344 | VBoxVHWATextureNP2() : VBoxVHWATexture() {}
|
---|
345 | VBoxVHWATextureNP2(const QRect & aRect, const VBoxVHWAColorFormat &aFormat, uint32_t bytesPerLine, GLint scaleFuncttion) :
|
---|
346 | VBoxVHWATexture(aRect, aFormat, bytesPerLine, scaleFuncttion){
|
---|
347 | mTexRect = QRect(0, 0, aRect.width()/aFormat.widthCompression(), aRect.height()/aFormat.heightCompression());
|
---|
348 | }
|
---|
349 | };
|
---|
350 |
|
---|
351 | class VBoxVHWATextureNP2Rect : public VBoxVHWATextureNP2
|
---|
352 | {
|
---|
353 | public:
|
---|
354 | VBoxVHWATextureNP2Rect() : VBoxVHWATextureNP2() {}
|
---|
355 | VBoxVHWATextureNP2Rect(const QRect & aRect, const VBoxVHWAColorFormat &aFormat, uint32_t bytesPerLine, GLint scaleFuncttion) :
|
---|
356 | VBoxVHWATextureNP2(aRect, aFormat, bytesPerLine, scaleFuncttion){}
|
---|
357 |
|
---|
358 | virtual void texCoord(int x, int y);
|
---|
359 | virtual void multiTexCoord(GLenum texUnit, int x, int y);
|
---|
360 | protected:
|
---|
361 | virtual GLenum texTarget();
|
---|
362 | };
|
---|
363 |
|
---|
364 | class VBoxVHWATextureNP2RectPBO : public VBoxVHWATextureNP2Rect
|
---|
365 | {
|
---|
366 | public:
|
---|
367 | VBoxVHWATextureNP2RectPBO() :
|
---|
368 | VBoxVHWATextureNP2Rect(),
|
---|
369 | mPBO(0)
|
---|
370 | {}
|
---|
371 | VBoxVHWATextureNP2RectPBO(const QRect & aRect, const VBoxVHWAColorFormat &aFormat, uint32_t bytesPerLine, GLint scaleFuncttion) :
|
---|
372 | VBoxVHWATextureNP2Rect(aRect, aFormat, bytesPerLine, scaleFuncttion),
|
---|
373 | mPBO(0)
|
---|
374 | {}
|
---|
375 |
|
---|
376 | virtual ~VBoxVHWATextureNP2RectPBO();
|
---|
377 |
|
---|
378 | virtual void init(uchar *pvMem);
|
---|
379 | protected:
|
---|
380 | virtual void load();
|
---|
381 | virtual void doUpdate(uchar * pAddress, const QRect * pRect);
|
---|
382 | GLuint mPBO;
|
---|
383 | };
|
---|
384 |
|
---|
385 | class VBoxVHWATextureNP2RectPBOMapped : public VBoxVHWATextureNP2RectPBO
|
---|
386 | {
|
---|
387 | public:
|
---|
388 | VBoxVHWATextureNP2RectPBOMapped() :
|
---|
389 | VBoxVHWATextureNP2RectPBO(),
|
---|
390 | mpMappedAllignedBuffer(NULL),
|
---|
391 | mcbAllignedBufferSize(0),
|
---|
392 | mcbOffset(0)
|
---|
393 | {}
|
---|
394 | VBoxVHWATextureNP2RectPBOMapped(const QRect & aRect, const VBoxVHWAColorFormat &aFormat, uint32_t bytesPerLine, GLint scaleFuncttion) :
|
---|
395 | VBoxVHWATextureNP2RectPBO(aRect, aFormat, bytesPerLine, scaleFuncttion),
|
---|
396 | mpMappedAllignedBuffer(NULL),
|
---|
397 | mcbOffset(0)
|
---|
398 | {
|
---|
399 | mcbAllignedBufferSize = alignSize((size_t)memSize());
|
---|
400 | mcbActualBufferSize = mcbAllignedBufferSize + 0x1fff;
|
---|
401 | }
|
---|
402 |
|
---|
403 | uchar* mapAlignedBuffer();
|
---|
404 | void unmapBuffer();
|
---|
405 | size_t alignedBufferSize() { return mcbAllignedBufferSize; }
|
---|
406 |
|
---|
407 | static size_t alignSize(size_t size)
|
---|
408 | {
|
---|
409 | size_t alSize = size & ~((size_t)0xfff);
|
---|
410 | return alSize == size ? alSize : alSize + 0x1000;
|
---|
411 | }
|
---|
412 |
|
---|
413 | static void* alignBuffer(void* pvMem) { return (void*)(((uintptr_t)pvMem) & ~((uintptr_t)0xfff)); }
|
---|
414 | static size_t calcOffset(void* pvBase, void* pvOffset) { return (size_t)(((uintptr_t)pvBase) - ((uintptr_t)pvOffset)); }
|
---|
415 | protected:
|
---|
416 | virtual void load();
|
---|
417 | virtual void doUpdate(uchar * pAddress, const QRect * pRect);
|
---|
418 | private:
|
---|
419 | uchar* mpMappedAllignedBuffer;
|
---|
420 | size_t mcbAllignedBufferSize;
|
---|
421 | size_t mcbOffset;
|
---|
422 | size_t mcbActualBufferSize;
|
---|
423 | };
|
---|
424 |
|
---|
425 | #define VBOXVHWAIMG_PBO 0x00000001U
|
---|
426 | #define VBOXVHWAIMG_PBOIMG 0x00000002U
|
---|
427 | #define VBOXVHWAIMG_FBO 0x00000004U
|
---|
428 | #define VBOXVHWAIMG_LINEAR 0x00000008U
|
---|
429 | typedef uint32_t VBOXVHWAIMG_TYPE;
|
---|
430 |
|
---|
431 | class VBoxVHWATextureImage
|
---|
432 | {
|
---|
433 | public:
|
---|
434 | VBoxVHWATextureImage(const QRect &size, const VBoxVHWAColorFormat &format, class VBoxVHWAGlProgramMngr * aMgr, VBOXVHWAIMG_TYPE flags);
|
---|
435 |
|
---|
436 | virtual ~VBoxVHWATextureImage()
|
---|
437 | {
|
---|
438 | for(uint i = 0; i < mcTex; i++)
|
---|
439 | {
|
---|
440 | delete mpTex[i];
|
---|
441 | }
|
---|
442 | }
|
---|
443 |
|
---|
444 | virtual void init(uchar *pvMem)
|
---|
445 | {
|
---|
446 | for(uint32_t i = 0; i < mcTex; i++)
|
---|
447 | {
|
---|
448 | mpTex[i]->init(pvMem);
|
---|
449 | pvMem += mpTex[i]->memSize();
|
---|
450 | }
|
---|
451 | }
|
---|
452 |
|
---|
453 | virtual void update(const QRect * pRect)
|
---|
454 | {
|
---|
455 | mpTex[0]->update(pRect);
|
---|
456 | if(mColorFormat.fourcc() == FOURCC_YV12)
|
---|
457 | {
|
---|
458 | if(pRect)
|
---|
459 | {
|
---|
460 | QRect rect(pRect->x()/2, pRect->y()/2,
|
---|
461 | pRect->width()/2, pRect->height()/2);
|
---|
462 | mpTex[1]->update(&rect);
|
---|
463 | mpTex[2]->update(&rect);
|
---|
464 | }
|
---|
465 | else
|
---|
466 | {
|
---|
467 | mpTex[1]->update(NULL);
|
---|
468 | mpTex[2]->update(NULL);
|
---|
469 | }
|
---|
470 | }
|
---|
471 | }
|
---|
472 |
|
---|
473 | virtual void display(VBoxVHWATextureImage *pDst, const QRect * pDstRect, const QRect * pSrcRect,
|
---|
474 | const VBoxVHWAColorKey * pDstCKey, const VBoxVHWAColorKey * pSrcCKey, bool bNotIntersected);
|
---|
475 |
|
---|
476 |
|
---|
477 | virtual void display();
|
---|
478 |
|
---|
479 | void deleteDisplay();
|
---|
480 |
|
---|
481 | int initDisplay(VBoxVHWATextureImage *pDst,
|
---|
482 | const QRect * pDstRect, const QRect * pSrcRect,
|
---|
483 | const VBoxVHWAColorKey * pDstCKey, const VBoxVHWAColorKey * pSrcCKey, bool bNotIntersected);
|
---|
484 |
|
---|
485 | bool displayInitialized() { return !!mVisibleDisplay;}
|
---|
486 |
|
---|
487 | virtual void setAddress(uchar *pvMem)
|
---|
488 | {
|
---|
489 | for(uint32_t i = 0; i < mcTex; i++)
|
---|
490 | {
|
---|
491 | mpTex[i]->setAddress(pvMem);
|
---|
492 | pvMem += mpTex[i]->memSize();
|
---|
493 | }
|
---|
494 | }
|
---|
495 |
|
---|
496 | const QRect &rect()
|
---|
497 | {
|
---|
498 | return mpTex[0]->rect();
|
---|
499 | }
|
---|
500 |
|
---|
501 | size_t memSize()
|
---|
502 | {
|
---|
503 | size_t size = 0;
|
---|
504 | for(uint32_t i = 0; i < mcTex; i++)
|
---|
505 | {
|
---|
506 | size+=mpTex[i]->memSize();
|
---|
507 | }
|
---|
508 | return size;
|
---|
509 | }
|
---|
510 |
|
---|
511 | uint32_t bytesPerLine() { return mpTex[0]->bytesPerLine(); }
|
---|
512 |
|
---|
513 | const VBoxVHWAColorFormat &pixelFormat() { return mColorFormat; }
|
---|
514 |
|
---|
515 | uint32_t numComponents() {return mcTex;}
|
---|
516 |
|
---|
517 | VBoxVHWATexture* component(uint32_t i) {return mpTex[i]; }
|
---|
518 |
|
---|
519 | const VBoxVHWATextureImage *dst() { return mpDst;}
|
---|
520 | const QRect& dstRect() { return mDstRect; }
|
---|
521 | const QRect& srcRect() { return mSrcRect; }
|
---|
522 | const VBoxVHWAColorKey* dstCKey() { return mpDstCKey; }
|
---|
523 | const VBoxVHWAColorKey* srcCKey() { return mpSrcCKey; }
|
---|
524 | bool notIntersectedMode() { return mbNotIntersected; }
|
---|
525 |
|
---|
526 | static uint32_t calcBytesPerLine(const VBoxVHWAColorFormat & format, int width);
|
---|
527 | static uint32_t calcMemSize(const VBoxVHWAColorFormat & format, int width, int height);
|
---|
528 |
|
---|
529 | #ifdef DEBUG_misha
|
---|
530 | void dbgDump();
|
---|
531 | #endif
|
---|
532 |
|
---|
533 | protected:
|
---|
534 | static int setCKey(class VBoxVHWAGlProgramVHWA * pProgram, const VBoxVHWAColorFormat * pFormat, const VBoxVHWAColorKey * pCKey, bool bDst);
|
---|
535 |
|
---|
536 | static bool matchCKeys(const VBoxVHWAColorKey * pCKey1, const VBoxVHWAColorKey * pCKey2)
|
---|
537 | {
|
---|
538 | return (pCKey1 == NULL && pCKey2 == NULL)
|
---|
539 | || (*pCKey1 == *pCKey2);
|
---|
540 | }
|
---|
541 |
|
---|
542 | void runDisplay(VBoxVHWATextureImage *pDst, const QRect * pDstRect, const QRect * pSrcRect)
|
---|
543 | {
|
---|
544 | bind(pDst);
|
---|
545 |
|
---|
546 | draw(pDst, pDstRect, pSrcRect);
|
---|
547 | }
|
---|
548 |
|
---|
549 | virtual void draw(VBoxVHWATextureImage *pDst, const QRect * pDstRect, const QRect * pSrcRect);
|
---|
550 |
|
---|
551 | virtual uint32_t texCoord(GLenum tex, int x, int y)
|
---|
552 | {
|
---|
553 | uint32_t c = 1;
|
---|
554 | mpTex[0]->multiTexCoord(tex, x, y);
|
---|
555 | if(mColorFormat.fourcc() == FOURCC_YV12)
|
---|
556 | {
|
---|
557 | int x2 = x/2;
|
---|
558 | int y2 = y/2;
|
---|
559 | mpTex[1]->multiTexCoord(tex + 1, x2, y2);
|
---|
560 | ++c;
|
---|
561 | }
|
---|
562 | return c;
|
---|
563 | }
|
---|
564 |
|
---|
565 | virtual void bind(VBoxVHWATextureImage * pPrimary);
|
---|
566 |
|
---|
567 | virtual uint32_t calcProgramType(VBoxVHWATextureImage *pDst, const VBoxVHWAColorKey * pDstCKey, const VBoxVHWAColorKey * pSrcCKey, bool bNotIntersected);
|
---|
568 |
|
---|
569 | virtual class VBoxVHWAGlProgramVHWA * calcProgram(VBoxVHWATextureImage *pDst, const VBoxVHWAColorKey * pDstCKey, const VBoxVHWAColorKey * pSrcCKey, bool bNotIntersected);
|
---|
570 |
|
---|
571 | virtual int createDisplay(VBoxVHWATextureImage *pDst, const QRect * pDstRect, const QRect * pSrcRect,
|
---|
572 | const VBoxVHWAColorKey * pDstCKey, const VBoxVHWAColorKey * pSrcCKey, bool bNotIntersected,
|
---|
573 | GLuint *pDisplay, class VBoxVHWAGlProgramVHWA ** ppProgram);
|
---|
574 |
|
---|
575 | int createSetDisplay(VBoxVHWATextureImage *pDst, const QRect * pDstRect, const QRect * pSrcRect,
|
---|
576 | const VBoxVHWAColorKey * pDstCKey, const VBoxVHWAColorKey * pSrcCKey, bool bNotIntersected);
|
---|
577 |
|
---|
578 | virtual int createDisplayList(VBoxVHWATextureImage *pDst, const QRect * pDstRect, const QRect * pSrcRect,
|
---|
579 | const VBoxVHWAColorKey * pDstCKey, const VBoxVHWAColorKey * pSrcCKey, bool bNotIntersected,
|
---|
580 | GLuint *pDisplay);
|
---|
581 |
|
---|
582 | virtual void deleteDisplayList();
|
---|
583 |
|
---|
584 | virtual void updateCKeys(VBoxVHWATextureImage * pDst, class VBoxVHWAGlProgramVHWA * pProgram, const VBoxVHWAColorKey * pDstCKey, const VBoxVHWAColorKey * pSrcCKey);
|
---|
585 | virtual void updateSetCKeys(const VBoxVHWAColorKey * pDstCKey, const VBoxVHWAColorKey * pSrcCKey);
|
---|
586 |
|
---|
587 | void internalSetDstCKey(const VBoxVHWAColorKey * pDstCKey);
|
---|
588 | void internalSetSrcCKey(const VBoxVHWAColorKey * pSrcCKey);
|
---|
589 |
|
---|
590 | VBoxVHWATexture *mpTex[3];
|
---|
591 | uint32_t mcTex;
|
---|
592 | GLuint mVisibleDisplay;
|
---|
593 | class VBoxVHWAGlProgramVHWA * mpProgram;
|
---|
594 | class VBoxVHWAGlProgramMngr * mProgramMngr;
|
---|
595 | VBoxVHWAColorFormat mColorFormat;
|
---|
596 |
|
---|
597 | /* display info */
|
---|
598 | VBoxVHWATextureImage *mpDst;
|
---|
599 | QRect mDstRect;
|
---|
600 | QRect mSrcRect;
|
---|
601 | VBoxVHWAColorKey * mpDstCKey;
|
---|
602 | VBoxVHWAColorKey * mpSrcCKey;
|
---|
603 | VBoxVHWAColorKey mDstCKey;
|
---|
604 | VBoxVHWAColorKey mSrcCKey;
|
---|
605 | bool mbNotIntersected;
|
---|
606 | };
|
---|
607 |
|
---|
608 | class VBoxVHWATextureImagePBO : public VBoxVHWATextureImage
|
---|
609 | {
|
---|
610 | public:
|
---|
611 | VBoxVHWATextureImagePBO(const QRect &size, const VBoxVHWAColorFormat &format, class VBoxVHWAGlProgramMngr * aMgr, VBOXVHWAIMG_TYPE flags) :
|
---|
612 | VBoxVHWATextureImage(size, format, aMgr, flags & (~VBOXVHWAIMG_PBO)),
|
---|
613 | mPBO(0)
|
---|
614 | {
|
---|
615 | }
|
---|
616 |
|
---|
617 | virtual ~VBoxVHWATextureImagePBO()
|
---|
618 | {
|
---|
619 | if(mPBO)
|
---|
620 | {
|
---|
621 | VBOXQGL_CHECKERR(
|
---|
622 | vboxglDeleteBuffers(1, &mPBO);
|
---|
623 | );
|
---|
624 | }
|
---|
625 | }
|
---|
626 |
|
---|
627 | virtual void init(uchar *pvMem)
|
---|
628 | {
|
---|
629 | VBoxVHWATextureImage::init(pvMem);
|
---|
630 |
|
---|
631 | VBOXQGL_CHECKERR(
|
---|
632 | vboxglGenBuffers(1, &mPBO);
|
---|
633 | );
|
---|
634 | mAddress = pvMem;
|
---|
635 |
|
---|
636 | VBOXQGL_CHECKERR(
|
---|
637 | vboxglBindBuffer(GL_PIXEL_UNPACK_BUFFER, mPBO);
|
---|
638 | );
|
---|
639 |
|
---|
640 | VBOXQGL_CHECKERR(
|
---|
641 | vboxglBufferData(GL_PIXEL_UNPACK_BUFFER, memSize(), NULL, GL_STREAM_DRAW);
|
---|
642 | );
|
---|
643 |
|
---|
644 | GLvoid *buf = vboxglMapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_WRITE_ONLY);
|
---|
645 | Assert(buf);
|
---|
646 | if(buf)
|
---|
647 | {
|
---|
648 | memcpy(buf, mAddress, memSize());
|
---|
649 |
|
---|
650 | bool unmapped = vboxglUnmapBuffer(GL_PIXEL_UNPACK_BUFFER);
|
---|
651 | Assert(unmapped); NOREF(unmapped);
|
---|
652 | }
|
---|
653 |
|
---|
654 | vboxglBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
|
---|
655 |
|
---|
656 | }
|
---|
657 |
|
---|
658 | virtual void update(const QRect * pRect)
|
---|
659 | {
|
---|
660 | VBOXQGL_CHECKERR(
|
---|
661 | vboxglBindBuffer(GL_PIXEL_UNPACK_BUFFER, mPBO);
|
---|
662 | );
|
---|
663 |
|
---|
664 | GLvoid *buf;
|
---|
665 |
|
---|
666 | VBOXQGL_CHECKERR(
|
---|
667 | buf = vboxglMapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_WRITE_ONLY);
|
---|
668 | );
|
---|
669 | Assert(buf);
|
---|
670 | if(buf)
|
---|
671 | {
|
---|
672 | #ifdef VBOXVHWADBG_RENDERCHECK
|
---|
673 | uint32_t * pBuf32 = (uint32_t*)buf;
|
---|
674 | uchar * pBuf8 = (uchar*)buf;
|
---|
675 | for(uint32_t i = 0; i < mcTex; i++)
|
---|
676 | {
|
---|
677 | uint32_t dbgSetVal = 0x40404040 * (i+1);
|
---|
678 | for(uint32_t k = 0; k < mpTex[i]->memSize()/sizeof(pBuf32[0]); k++)
|
---|
679 | {
|
---|
680 | pBuf32[k] = dbgSetVal;
|
---|
681 | }
|
---|
682 |
|
---|
683 | pBuf8 += mpTex[i]->memSize();
|
---|
684 | pBuf32 = (uint32_t *)pBuf8;
|
---|
685 | }
|
---|
686 | #else
|
---|
687 | memcpy(buf, mAddress, memSize());
|
---|
688 | #endif
|
---|
689 |
|
---|
690 | bool unmapped;
|
---|
691 | VBOXQGL_CHECKERR(
|
---|
692 | unmapped = vboxglUnmapBuffer(GL_PIXEL_UNPACK_BUFFER);
|
---|
693 | );
|
---|
694 |
|
---|
695 | Assert(unmapped); NOREF(unmapped);
|
---|
696 |
|
---|
697 | VBoxVHWATextureImage::setAddress(0);
|
---|
698 |
|
---|
699 | VBoxVHWATextureImage::update(NULL);
|
---|
700 |
|
---|
701 | VBoxVHWATextureImage::setAddress(mAddress);
|
---|
702 |
|
---|
703 | vboxglBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
|
---|
704 | }
|
---|
705 | else
|
---|
706 | {
|
---|
707 | VBOXQGLLOGREL(("failed to map PBO, trying fallback to non-PBO approach\n"));
|
---|
708 |
|
---|
709 | VBoxVHWATextureImage::setAddress(mAddress);
|
---|
710 |
|
---|
711 | VBoxVHWATextureImage::update(pRect);
|
---|
712 | }
|
---|
713 | }
|
---|
714 |
|
---|
715 | virtual void setAddress(uchar *pvMem)
|
---|
716 | {
|
---|
717 | mAddress = pvMem;
|
---|
718 | }
|
---|
719 | private:
|
---|
720 | GLuint mPBO;
|
---|
721 | uchar* mAddress;
|
---|
722 | };
|
---|
723 |
|
---|
724 | class VBoxVHWAHandleTable
|
---|
725 | {
|
---|
726 | public:
|
---|
727 | VBoxVHWAHandleTable(uint32_t initialSize);
|
---|
728 | ~VBoxVHWAHandleTable();
|
---|
729 | uint32_t put(void * data);
|
---|
730 | bool mapPut(uint32_t h, void * data);
|
---|
731 | void* get(uint32_t h);
|
---|
732 | void* remove(uint32_t h);
|
---|
733 | private:
|
---|
734 | void doPut(uint32_t h, void * data);
|
---|
735 | void doRemove(uint32_t h);
|
---|
736 | void** mTable;
|
---|
737 | uint32_t mcSize;
|
---|
738 | uint32_t mcUsage;
|
---|
739 | uint32_t mCursor;
|
---|
740 | };
|
---|
741 |
|
---|
742 | /* data flow:
|
---|
743 | * I. NON-Yinverted surface:
|
---|
744 | * 1.direct memory update (paint, lock/unlock):
|
---|
745 | * mem->tex->fb
|
---|
746 | * 2.blt
|
---|
747 | * srcTex->invFB->tex->fb
|
---|
748 | * |->mem
|
---|
749 | *
|
---|
750 | * II. Yinverted surface:
|
---|
751 | * 1.direct memory update (paint, lock/unlock):
|
---|
752 | * mem->tex->fb
|
---|
753 | * 2.blt
|
---|
754 | * srcTex->fb->tex
|
---|
755 | * |->mem
|
---|
756 | *
|
---|
757 | * III. flip support:
|
---|
758 | * 1. Yinverted<->NON-YInverted conversion :
|
---|
759 | * mem->tex-(rotate model view, force LAZY complete fb update)->invFB->tex
|
---|
760 | * fb-->| |->mem
|
---|
761 | * */
|
---|
762 | class VBoxVHWASurfaceBase
|
---|
763 | {
|
---|
764 | public:
|
---|
765 | VBoxVHWASurfaceBase (class VBoxVHWAImage *pImage,
|
---|
766 | const QSize & aSize,
|
---|
767 | const QRect & aTargRect,
|
---|
768 | const QRect & aSrcRect,
|
---|
769 | const QRect & aVisTargRect,
|
---|
770 | VBoxVHWAColorFormat & aColorFormat,
|
---|
771 | VBoxVHWAColorKey * pSrcBltCKey, VBoxVHWAColorKey * pDstBltCKey,
|
---|
772 | VBoxVHWAColorKey * pSrcOverlayCKey, VBoxVHWAColorKey * pDstOverlayCKey,
|
---|
773 | VBOXVHWAIMG_TYPE aImgFlags);
|
---|
774 |
|
---|
775 | virtual ~VBoxVHWASurfaceBase();
|
---|
776 |
|
---|
777 | void init (VBoxVHWASurfaceBase * pPrimary, uchar *pvMem);
|
---|
778 |
|
---|
779 | void uninit();
|
---|
780 |
|
---|
781 | static void globalInit();
|
---|
782 |
|
---|
783 | int lock (const QRect * pRect, uint32_t flags);
|
---|
784 |
|
---|
785 | int unlock();
|
---|
786 |
|
---|
787 | void updatedMem (const QRect * aRect);
|
---|
788 |
|
---|
789 | bool performDisplay (VBoxVHWASurfaceBase *pPrimary, bool bForce);
|
---|
790 |
|
---|
791 | void setRects (const QRect & aTargRect, const QRect & aSrcRect);
|
---|
792 | void setTargRectPosition (const QPoint & aPoint);
|
---|
793 |
|
---|
794 | void updateVisibility (VBoxVHWASurfaceBase *pPrimary, const QRect & aVisibleTargRect, bool bNotIntersected, bool bForce);
|
---|
795 |
|
---|
796 | static ulong calcBytesPerPixel (GLenum format, GLenum type);
|
---|
797 |
|
---|
798 | static GLsizei makePowerOf2 (GLsizei val);
|
---|
799 |
|
---|
800 | bool addressAlocated() const { return mFreeAddress; }
|
---|
801 | uchar * address() { return mAddress; }
|
---|
802 |
|
---|
803 | ulong memSize();
|
---|
804 |
|
---|
805 | ulong width() const { return mRect.width(); }
|
---|
806 | ulong height() const { return mRect.height(); }
|
---|
807 | const QSize size() const {return mRect.size();}
|
---|
808 |
|
---|
809 | uint32_t fourcc() const {return mImage->pixelFormat().fourcc(); }
|
---|
810 |
|
---|
811 | ulong bitsPerPixel() const { return mImage->pixelFormat().bitsPerPixel(); }
|
---|
812 | ulong bytesPerLine() const { return mImage->bytesPerLine(); }
|
---|
813 |
|
---|
814 | const VBoxVHWAColorKey * dstBltCKey() const { return mpDstBltCKey; }
|
---|
815 | const VBoxVHWAColorKey * srcBltCKey() const { return mpSrcBltCKey; }
|
---|
816 | const VBoxVHWAColorKey * dstOverlayCKey() const { return mpDstOverlayCKey; }
|
---|
817 | const VBoxVHWAColorKey * defaultSrcOverlayCKey() const { return mpDefaultSrcOverlayCKey; }
|
---|
818 | const VBoxVHWAColorKey * defaultDstOverlayCKey() const { return mpDefaultDstOverlayCKey; }
|
---|
819 | const VBoxVHWAColorKey * srcOverlayCKey() const { return mpSrcOverlayCKey; }
|
---|
820 | void resetDefaultSrcOverlayCKey() { mpSrcOverlayCKey = mpDefaultSrcOverlayCKey; }
|
---|
821 | void resetDefaultDstOverlayCKey() { mpDstOverlayCKey = mpDefaultDstOverlayCKey; }
|
---|
822 |
|
---|
823 | void setDstBltCKey (const VBoxVHWAColorKey * ckey)
|
---|
824 | {
|
---|
825 | if(ckey)
|
---|
826 | {
|
---|
827 | mDstBltCKey = *ckey;
|
---|
828 | mpDstBltCKey = &mDstBltCKey;
|
---|
829 | }
|
---|
830 | else
|
---|
831 | {
|
---|
832 | mpDstBltCKey = NULL;
|
---|
833 | }
|
---|
834 | }
|
---|
835 |
|
---|
836 | void setSrcBltCKey (const VBoxVHWAColorKey * ckey)
|
---|
837 | {
|
---|
838 | if(ckey)
|
---|
839 | {
|
---|
840 | mSrcBltCKey = *ckey;
|
---|
841 | mpSrcBltCKey = &mSrcBltCKey;
|
---|
842 | }
|
---|
843 | else
|
---|
844 | {
|
---|
845 | mpSrcBltCKey = NULL;
|
---|
846 | }
|
---|
847 | }
|
---|
848 |
|
---|
849 | void setDefaultDstOverlayCKey (const VBoxVHWAColorKey * ckey)
|
---|
850 | {
|
---|
851 | if(ckey)
|
---|
852 | {
|
---|
853 | mDefaultDstOverlayCKey = *ckey;
|
---|
854 | mpDefaultDstOverlayCKey = &mDefaultDstOverlayCKey;
|
---|
855 | }
|
---|
856 | else
|
---|
857 | {
|
---|
858 | mpDefaultDstOverlayCKey = NULL;
|
---|
859 | }
|
---|
860 | }
|
---|
861 |
|
---|
862 | void setDefaultSrcOverlayCKey (const VBoxVHWAColorKey * ckey)
|
---|
863 | {
|
---|
864 | if(ckey)
|
---|
865 | {
|
---|
866 | mDefaultSrcOverlayCKey = *ckey;
|
---|
867 | mpDefaultSrcOverlayCKey = &mDefaultSrcOverlayCKey;
|
---|
868 | }
|
---|
869 | else
|
---|
870 | {
|
---|
871 | mpDefaultSrcOverlayCKey = NULL;
|
---|
872 | }
|
---|
873 | }
|
---|
874 |
|
---|
875 | void setOverriddenDstOverlayCKey (const VBoxVHWAColorKey * ckey)
|
---|
876 | {
|
---|
877 | if(ckey)
|
---|
878 | {
|
---|
879 | mOverriddenDstOverlayCKey = *ckey;
|
---|
880 | mpDstOverlayCKey = &mOverriddenDstOverlayCKey;
|
---|
881 | }
|
---|
882 | else
|
---|
883 | {
|
---|
884 | mpDstOverlayCKey = NULL;
|
---|
885 | }
|
---|
886 | }
|
---|
887 |
|
---|
888 | void setOverriddenSrcOverlayCKey (const VBoxVHWAColorKey * ckey)
|
---|
889 | {
|
---|
890 | if(ckey)
|
---|
891 | {
|
---|
892 | mOverriddenSrcOverlayCKey = *ckey;
|
---|
893 | mpSrcOverlayCKey = &mOverriddenSrcOverlayCKey;
|
---|
894 | }
|
---|
895 | else
|
---|
896 | {
|
---|
897 | mpSrcOverlayCKey = NULL;
|
---|
898 | }
|
---|
899 | }
|
---|
900 |
|
---|
901 | const VBoxVHWAColorKey * getActiveSrcOverlayCKey()
|
---|
902 | {
|
---|
903 | return mpSrcOverlayCKey;
|
---|
904 | }
|
---|
905 |
|
---|
906 | const VBoxVHWAColorKey * getActiveDstOverlayCKey (VBoxVHWASurfaceBase * pPrimary)
|
---|
907 | {
|
---|
908 | return mpDstOverlayCKey ? mpDefaultDstOverlayCKey : (pPrimary ? pPrimary->mpDstOverlayCKey : NULL);
|
---|
909 | }
|
---|
910 |
|
---|
911 | const VBoxVHWAColorFormat & pixelFormat() const { return mImage->pixelFormat(); }
|
---|
912 |
|
---|
913 | void setAddress(uchar * addr);
|
---|
914 |
|
---|
915 | const QRect& rect() const {return mRect;}
|
---|
916 | const QRect& srcRect() const {return mSrcRect; }
|
---|
917 | const QRect& targRect() const {return mTargRect; }
|
---|
918 | class VBoxVHWASurfList * getComplexList() {return mComplexList; }
|
---|
919 |
|
---|
920 | class VBoxVHWAGlProgramMngr * getGlProgramMngr();
|
---|
921 |
|
---|
922 | uint32_t handle() const {return mHGHandle;}
|
---|
923 | void setHandle(uint32_t h) {mHGHandle = h;}
|
---|
924 |
|
---|
925 | const VBoxVHWADirtyRect & getDirtyRect() { return mUpdateMem2TexRect; }
|
---|
926 |
|
---|
927 | VBoxVHWASurfaceBase * primary() { return mpPrimary; }
|
---|
928 | void setPrimary(VBoxVHWASurfaceBase *apPrimary) { mpPrimary = apPrimary; }
|
---|
929 | private:
|
---|
930 | void setRectValues (const QRect & aTargRect, const QRect & aSrcRect);
|
---|
931 | void setVisibleRectValues (const QRect & aVisTargRect);
|
---|
932 |
|
---|
933 | void setComplexList (VBoxVHWASurfList *aComplexList) { mComplexList = aComplexList; }
|
---|
934 | void initDisplay();
|
---|
935 |
|
---|
936 | bool synchTexMem (const QRect * aRect);
|
---|
937 |
|
---|
938 | int performBlt (const QRect * pDstRect, VBoxVHWASurfaceBase * pSrcSurface, const QRect * pSrcRect, const VBoxVHWAColorKey * pDstCKey, const VBoxVHWAColorKey * pSrcCKey, bool blt);
|
---|
939 |
|
---|
940 | QRect mRect; /* == Inv FB size */
|
---|
941 |
|
---|
942 | QRect mSrcRect;
|
---|
943 | QRect mTargRect; /* == Vis FB size */
|
---|
944 |
|
---|
945 | QRect mVisibleTargRect;
|
---|
946 | QRect mVisibleSrcRect;
|
---|
947 |
|
---|
948 | class VBoxVHWATextureImage * mImage;
|
---|
949 |
|
---|
950 | uchar * mAddress;
|
---|
951 |
|
---|
952 | VBoxVHWAColorKey *mpSrcBltCKey;
|
---|
953 | VBoxVHWAColorKey *mpDstBltCKey;
|
---|
954 | VBoxVHWAColorKey *mpSrcOverlayCKey;
|
---|
955 | VBoxVHWAColorKey *mpDstOverlayCKey;
|
---|
956 |
|
---|
957 | VBoxVHWAColorKey *mpDefaultDstOverlayCKey;
|
---|
958 | VBoxVHWAColorKey *mpDefaultSrcOverlayCKey;
|
---|
959 |
|
---|
960 | VBoxVHWAColorKey mSrcBltCKey;
|
---|
961 | VBoxVHWAColorKey mDstBltCKey;
|
---|
962 | VBoxVHWAColorKey mOverriddenSrcOverlayCKey;
|
---|
963 | VBoxVHWAColorKey mOverriddenDstOverlayCKey;
|
---|
964 | VBoxVHWAColorKey mDefaultDstOverlayCKey;
|
---|
965 | VBoxVHWAColorKey mDefaultSrcOverlayCKey;
|
---|
966 |
|
---|
967 | int mLockCount;
|
---|
968 | /* memory buffer not reflected in fm and texture, e.g if memory buffer is replaced or in case of lock/unlock */
|
---|
969 | VBoxVHWADirtyRect mUpdateMem2TexRect;
|
---|
970 |
|
---|
971 | bool mFreeAddress;
|
---|
972 | bool mbNotIntersected;
|
---|
973 |
|
---|
974 | class VBoxVHWASurfList *mComplexList;
|
---|
975 |
|
---|
976 | VBoxVHWASurfaceBase *mpPrimary;
|
---|
977 |
|
---|
978 | uint32_t mHGHandle;
|
---|
979 |
|
---|
980 | class VBoxVHWAImage *mpImage;
|
---|
981 |
|
---|
982 | #ifdef DEBUG
|
---|
983 | public:
|
---|
984 | uint64_t cFlipsCurr;
|
---|
985 | uint64_t cFlipsTarg;
|
---|
986 | #endif
|
---|
987 | friend class VBoxVHWASurfList;
|
---|
988 | };
|
---|
989 |
|
---|
990 | typedef std::list <VBoxVHWASurfaceBase*> SurfList;
|
---|
991 | typedef std::list <VBoxVHWASurfList*> OverlayList;
|
---|
992 | typedef std::list <struct VBOXVHWACMD *> VHWACommandList;
|
---|
993 |
|
---|
994 | class VBoxVHWASurfList
|
---|
995 | {
|
---|
996 | public:
|
---|
997 |
|
---|
998 | VBoxVHWASurfList() : mCurrent(NULL) {}
|
---|
999 | void add(VBoxVHWASurfaceBase *pSurf)
|
---|
1000 | {
|
---|
1001 | VBoxVHWASurfList * pOld = pSurf->getComplexList();
|
---|
1002 | if(pOld)
|
---|
1003 | {
|
---|
1004 | pOld->remove(pSurf);
|
---|
1005 | }
|
---|
1006 | mSurfaces.push_back(pSurf);
|
---|
1007 | pSurf->setComplexList(this);
|
---|
1008 | }
|
---|
1009 |
|
---|
1010 | void clear()
|
---|
1011 | {
|
---|
1012 | for (SurfList::iterator it = mSurfaces.begin();
|
---|
1013 | it != mSurfaces.end(); ++ it)
|
---|
1014 | {
|
---|
1015 | (*it)->setComplexList(NULL);
|
---|
1016 | }
|
---|
1017 | mSurfaces.clear();
|
---|
1018 | mCurrent = NULL;
|
---|
1019 | }
|
---|
1020 |
|
---|
1021 | size_t size() const {return mSurfaces.size(); }
|
---|
1022 |
|
---|
1023 | void remove(VBoxVHWASurfaceBase *pSurf)
|
---|
1024 | {
|
---|
1025 | mSurfaces.remove(pSurf);
|
---|
1026 | pSurf->setComplexList(NULL);
|
---|
1027 | if(mCurrent == pSurf)
|
---|
1028 | mCurrent = NULL;
|
---|
1029 | }
|
---|
1030 |
|
---|
1031 | bool empty() { return mSurfaces.empty(); }
|
---|
1032 |
|
---|
1033 | void setCurrentVisible(VBoxVHWASurfaceBase *pSurf)
|
---|
1034 | {
|
---|
1035 | mCurrent = pSurf;
|
---|
1036 | }
|
---|
1037 |
|
---|
1038 | VBoxVHWASurfaceBase * current() { return mCurrent; }
|
---|
1039 | const SurfList & surfaces() const {return mSurfaces;}
|
---|
1040 |
|
---|
1041 | private:
|
---|
1042 |
|
---|
1043 | SurfList mSurfaces;
|
---|
1044 | VBoxVHWASurfaceBase* mCurrent;
|
---|
1045 | };
|
---|
1046 |
|
---|
1047 | class VBoxVHWADisplay
|
---|
1048 | {
|
---|
1049 | public:
|
---|
1050 | VBoxVHWADisplay() :
|
---|
1051 | mSurfVGA(NULL),
|
---|
1052 | mbDisplayPrimary(true)
|
---|
1053 | // ,
|
---|
1054 | // mSurfPrimary(NULL)
|
---|
1055 | {}
|
---|
1056 |
|
---|
1057 | VBoxVHWASurfaceBase * setVGA(VBoxVHWASurfaceBase * pVga)
|
---|
1058 | {
|
---|
1059 | VBoxVHWASurfaceBase * old = mSurfVGA;
|
---|
1060 | mSurfVGA = pVga;
|
---|
1061 | mPrimary.clear();
|
---|
1062 | if(pVga)
|
---|
1063 | {
|
---|
1064 | Assert(!pVga->getComplexList());
|
---|
1065 | mPrimary.add(pVga);
|
---|
1066 | mPrimary.setCurrentVisible(pVga);
|
---|
1067 | }
|
---|
1068 | mOverlays.clear();
|
---|
1069 | return old;
|
---|
1070 | }
|
---|
1071 |
|
---|
1072 | VBoxVHWASurfaceBase * updateVGA(VBoxVHWASurfaceBase * pVga)
|
---|
1073 | {
|
---|
1074 | VBoxVHWASurfaceBase * old = mSurfVGA;
|
---|
1075 | Assert(old);
|
---|
1076 | mSurfVGA = pVga;
|
---|
1077 | return old;
|
---|
1078 | }
|
---|
1079 |
|
---|
1080 | VBoxVHWASurfaceBase * getVGA() const
|
---|
1081 | {
|
---|
1082 | return mSurfVGA;
|
---|
1083 | }
|
---|
1084 |
|
---|
1085 | VBoxVHWASurfaceBase * getPrimary()
|
---|
1086 | {
|
---|
1087 | return mPrimary.current();
|
---|
1088 | }
|
---|
1089 |
|
---|
1090 | void addOverlay(VBoxVHWASurfList * pSurf)
|
---|
1091 | {
|
---|
1092 | mOverlays.push_back(pSurf);
|
---|
1093 | }
|
---|
1094 |
|
---|
1095 | void checkAddOverlay(VBoxVHWASurfList * pSurf)
|
---|
1096 | {
|
---|
1097 | if(!hasOverlay(pSurf))
|
---|
1098 | addOverlay(pSurf);
|
---|
1099 | }
|
---|
1100 |
|
---|
1101 | bool hasOverlay(VBoxVHWASurfList * pSurf)
|
---|
1102 | {
|
---|
1103 | for (OverlayList::iterator it = mOverlays.begin();
|
---|
1104 | it != mOverlays.end(); ++ it)
|
---|
1105 | {
|
---|
1106 | if((*it) == pSurf)
|
---|
1107 | {
|
---|
1108 | return true;
|
---|
1109 | }
|
---|
1110 | }
|
---|
1111 | return false;
|
---|
1112 | }
|
---|
1113 |
|
---|
1114 | void removeOverlay(VBoxVHWASurfList * pSurf)
|
---|
1115 | {
|
---|
1116 | mOverlays.remove(pSurf);
|
---|
1117 | }
|
---|
1118 |
|
---|
1119 | bool performDisplay(bool bForce)
|
---|
1120 | {
|
---|
1121 | VBoxVHWASurfaceBase * pPrimary = mPrimary.current();
|
---|
1122 |
|
---|
1123 | if(mbDisplayPrimary)
|
---|
1124 | {
|
---|
1125 | #ifdef DEBUG_misha
|
---|
1126 | /* should only display overlay now */
|
---|
1127 | AssertBreakpoint();
|
---|
1128 | #endif
|
---|
1129 | bForce |= pPrimary->performDisplay(NULL, bForce);
|
---|
1130 | }
|
---|
1131 |
|
---|
1132 | for (OverlayList::const_iterator it = mOverlays.begin();
|
---|
1133 | it != mOverlays.end(); ++ it)
|
---|
1134 | {
|
---|
1135 | VBoxVHWASurfaceBase * pOverlay = (*it)->current();
|
---|
1136 | if(pOverlay)
|
---|
1137 | {
|
---|
1138 | bForce |= pOverlay->performDisplay(pPrimary, bForce);
|
---|
1139 | }
|
---|
1140 | }
|
---|
1141 | return bForce;
|
---|
1142 | }
|
---|
1143 |
|
---|
1144 | bool isPrimary(VBoxVHWASurfaceBase * pSurf) { return pSurf->getComplexList() == &mPrimary; }
|
---|
1145 |
|
---|
1146 | void setDisplayPrimary(bool bDisplay) { mbDisplayPrimary = bDisplay; }
|
---|
1147 |
|
---|
1148 | const OverlayList & overlays() const {return mOverlays;}
|
---|
1149 | const VBoxVHWASurfList & primaries() const { return mPrimary; }
|
---|
1150 |
|
---|
1151 | private:
|
---|
1152 | VBoxVHWASurfaceBase *mSurfVGA;
|
---|
1153 | VBoxVHWASurfList mPrimary;
|
---|
1154 |
|
---|
1155 | OverlayList mOverlays;
|
---|
1156 |
|
---|
1157 | bool mbDisplayPrimary;
|
---|
1158 | };
|
---|
1159 |
|
---|
1160 | typedef void (*PFNVBOXQGLFUNC)(void*, void*);
|
---|
1161 |
|
---|
1162 | typedef enum
|
---|
1163 | {
|
---|
1164 | VBOXVHWA_PIPECMD_PAINT = 1,
|
---|
1165 | VBOXVHWA_PIPECMD_VHWA,
|
---|
1166 | VBOXVHWA_PIPECMD_FUNC
|
---|
1167 | }VBOXVHWA_PIPECMD_TYPE;
|
---|
1168 |
|
---|
1169 | typedef struct VBOXVHWAFUNCCALLBACKINFO
|
---|
1170 | {
|
---|
1171 | PFNVBOXQGLFUNC pfnCallback;
|
---|
1172 | void * pContext1;
|
---|
1173 | void * pContext2;
|
---|
1174 | }VBOXVHWAFUNCCALLBACKINFO;
|
---|
1175 |
|
---|
1176 | class VBoxVHWACommandElement
|
---|
1177 | {
|
---|
1178 | public:
|
---|
1179 | VBoxVHWACommandElement() :
|
---|
1180 | bNewEvent(false)
|
---|
1181 | {}
|
---|
1182 |
|
---|
1183 | void setVHWACmd(struct VBOXVHWACMD * pCmd)
|
---|
1184 | {
|
---|
1185 | mType = VBOXVHWA_PIPECMD_VHWA;
|
---|
1186 | u.mpCmd = pCmd;
|
---|
1187 | }
|
---|
1188 |
|
---|
1189 | void setPaintCmd(const QRect & aRect)
|
---|
1190 | {
|
---|
1191 | mType = VBOXVHWA_PIPECMD_PAINT;
|
---|
1192 | mRect = aRect;
|
---|
1193 | }
|
---|
1194 |
|
---|
1195 | void setFunc(const VBOXVHWAFUNCCALLBACKINFO & aOp)
|
---|
1196 | {
|
---|
1197 | mType = VBOXVHWA_PIPECMD_FUNC;
|
---|
1198 | u.mFuncCallback = aOp;
|
---|
1199 | }
|
---|
1200 |
|
---|
1201 | void setData(VBOXVHWA_PIPECMD_TYPE aType, void * pvData)
|
---|
1202 | {
|
---|
1203 | switch(aType)
|
---|
1204 | {
|
---|
1205 | case VBOXVHWA_PIPECMD_PAINT:
|
---|
1206 | setPaintCmd(*((QRect*)pvData));
|
---|
1207 | break;
|
---|
1208 | case VBOXVHWA_PIPECMD_VHWA:
|
---|
1209 | setVHWACmd((struct VBOXVHWACMD *)pvData);
|
---|
1210 | break;
|
---|
1211 | case VBOXVHWA_PIPECMD_FUNC:
|
---|
1212 | setFunc(*((VBOXVHWAFUNCCALLBACKINFO *)pvData));
|
---|
1213 | break;
|
---|
1214 | default:
|
---|
1215 | Assert(0);
|
---|
1216 | break;
|
---|
1217 | }
|
---|
1218 | }
|
---|
1219 |
|
---|
1220 | void setNewEvent(bool bNew) {bNewEvent = bNew;}
|
---|
1221 | bool isNewEvent() const { return bNewEvent; }
|
---|
1222 |
|
---|
1223 | VBOXVHWA_PIPECMD_TYPE type() const {return mType;}
|
---|
1224 | const QRect & rect() const {return mRect;}
|
---|
1225 | struct VBOXVHWACMD * vhwaCmd() const {return u.mpCmd;}
|
---|
1226 | const VBOXVHWAFUNCCALLBACKINFO & func() const {return u.mFuncCallback; }
|
---|
1227 |
|
---|
1228 | VBoxVHWACommandElement * mpNext;
|
---|
1229 | private:
|
---|
1230 | VBOXVHWA_PIPECMD_TYPE mType;
|
---|
1231 | union
|
---|
1232 | {
|
---|
1233 | struct VBOXVHWACMD * mpCmd;
|
---|
1234 | VBOXVHWAFUNCCALLBACKINFO mFuncCallback;
|
---|
1235 | }u;
|
---|
1236 | QRect mRect;
|
---|
1237 | bool bNewEvent;
|
---|
1238 | };
|
---|
1239 |
|
---|
1240 | class VBoxVHWACommandElementPipe
|
---|
1241 | {
|
---|
1242 | public:
|
---|
1243 | VBoxVHWACommandElementPipe() :
|
---|
1244 | mpFirst(NULL),
|
---|
1245 | mpLast(NULL)
|
---|
1246 | {}
|
---|
1247 |
|
---|
1248 | void put(VBoxVHWACommandElement *pCmd)
|
---|
1249 | {
|
---|
1250 | if (mpLast)
|
---|
1251 | {
|
---|
1252 | Assert(mpFirst);
|
---|
1253 | mpLast->mpNext = pCmd;
|
---|
1254 | mpLast = pCmd;
|
---|
1255 | }
|
---|
1256 | else
|
---|
1257 | {
|
---|
1258 | Assert(!mpFirst);
|
---|
1259 | mpFirst = pCmd;
|
---|
1260 | mpLast = pCmd;
|
---|
1261 | }
|
---|
1262 | pCmd->mpNext= NULL;
|
---|
1263 |
|
---|
1264 | }
|
---|
1265 |
|
---|
1266 | void setFrom(VBoxVHWACommandElementPipe *pOther)
|
---|
1267 | {
|
---|
1268 | mpFirst = pOther->detachList(&mpLast);
|
---|
1269 | }
|
---|
1270 |
|
---|
1271 | void set(VBoxVHWACommandElement *pFirst, VBoxVHWACommandElement *pLast)
|
---|
1272 | {
|
---|
1273 | mpFirst = pFirst;
|
---|
1274 | mpLast = pLast;
|
---|
1275 | if (mpLast)
|
---|
1276 | mpLast->mpNext = NULL;
|
---|
1277 | }
|
---|
1278 |
|
---|
1279 | void prepend(VBoxVHWACommandElement *pFirst, VBoxVHWACommandElement *pLast)
|
---|
1280 | {
|
---|
1281 | if (!mpFirst)
|
---|
1282 | set(pFirst, pLast);
|
---|
1283 | else if (pLast)
|
---|
1284 | {
|
---|
1285 | pLast->mpNext = mpFirst;
|
---|
1286 | mpFirst = pFirst;
|
---|
1287 | }
|
---|
1288 | }
|
---|
1289 |
|
---|
1290 | void prependFrom(VBoxVHWACommandElementPipe *pOther)
|
---|
1291 | {
|
---|
1292 | VBoxVHWACommandElement *pFirst;
|
---|
1293 | VBoxVHWACommandElement *pLast;
|
---|
1294 | pFirst = pOther->detachList(&pLast);
|
---|
1295 | prepend(pFirst, pLast);
|
---|
1296 | }
|
---|
1297 |
|
---|
1298 | void append(VBoxVHWACommandElement *pFirst, VBoxVHWACommandElement *pLast)
|
---|
1299 | {
|
---|
1300 | if (!mpLast)
|
---|
1301 | set(pFirst, pLast);
|
---|
1302 | else if (pLast)
|
---|
1303 | {
|
---|
1304 | mpLast->mpNext = pFirst;
|
---|
1305 | mpLast = pLast;
|
---|
1306 | pLast->mpNext = NULL;
|
---|
1307 | }
|
---|
1308 | }
|
---|
1309 |
|
---|
1310 | VBoxVHWACommandElement * detachList(VBoxVHWACommandElement **ppLast)
|
---|
1311 | {
|
---|
1312 | if (mpLast)
|
---|
1313 | {
|
---|
1314 | VBoxVHWACommandElement * pHead = mpFirst;
|
---|
1315 | if (ppLast)
|
---|
1316 | *ppLast = mpLast;
|
---|
1317 | mpFirst = NULL;
|
---|
1318 | mpLast = NULL;
|
---|
1319 | return pHead;
|
---|
1320 | }
|
---|
1321 | if (ppLast)
|
---|
1322 | *ppLast = NULL;
|
---|
1323 | return NULL;
|
---|
1324 | }
|
---|
1325 |
|
---|
1326 |
|
---|
1327 |
|
---|
1328 | const VBoxVHWACommandElement * contentsRo (const VBoxVHWACommandElement **ppLast) const
|
---|
1329 | {
|
---|
1330 | if (ppLast)
|
---|
1331 | *ppLast = mpLast;
|
---|
1332 | return mpFirst;
|
---|
1333 | }
|
---|
1334 |
|
---|
1335 | bool isEmpty() const { return !mpLast; }
|
---|
1336 |
|
---|
1337 | private:
|
---|
1338 | VBoxVHWACommandElement *mpFirst;
|
---|
1339 | VBoxVHWACommandElement *mpLast;
|
---|
1340 | };
|
---|
1341 |
|
---|
1342 | class VBoxVHWACommandElementStack
|
---|
1343 | {
|
---|
1344 | public:
|
---|
1345 | VBoxVHWACommandElementStack() :
|
---|
1346 | mpFirst(NULL) {}
|
---|
1347 |
|
---|
1348 | void push(VBoxVHWACommandElement *pCmd)
|
---|
1349 | {
|
---|
1350 | pCmd->mpNext = mpFirst;
|
---|
1351 | mpFirst = pCmd;
|
---|
1352 | }
|
---|
1353 |
|
---|
1354 | void pusha(VBoxVHWACommandElement *pFirst, VBoxVHWACommandElement *pLast)
|
---|
1355 | {
|
---|
1356 | pLast->mpNext = mpFirst;
|
---|
1357 | mpFirst = pFirst;
|
---|
1358 | }
|
---|
1359 |
|
---|
1360 | VBoxVHWACommandElement * pop()
|
---|
1361 | {
|
---|
1362 | if(mpFirst)
|
---|
1363 | {
|
---|
1364 | VBoxVHWACommandElement * ret = mpFirst;
|
---|
1365 | mpFirst = ret->mpNext;
|
---|
1366 | return ret;
|
---|
1367 | }
|
---|
1368 | return NULL;
|
---|
1369 | }
|
---|
1370 | private:
|
---|
1371 | VBoxVHWACommandElement *mpFirst;
|
---|
1372 | };
|
---|
1373 |
|
---|
1374 | class VBoxVHWARefCounter
|
---|
1375 | {
|
---|
1376 | #define VBOXVHWA_INIFITE_WAITCOUNT (~0U)
|
---|
1377 | public:
|
---|
1378 | VBoxVHWARefCounter() : m_cRefs(0) {}
|
---|
1379 | VBoxVHWARefCounter(uint32_t cRefs) : m_cRefs(cRefs) {}
|
---|
1380 | void inc() { ASMAtomicIncU32(&m_cRefs); }
|
---|
1381 | uint32_t dec()
|
---|
1382 | {
|
---|
1383 | uint32_t cRefs = ASMAtomicDecU32(&m_cRefs);
|
---|
1384 | Assert(cRefs < UINT32_MAX / 2);
|
---|
1385 | return cRefs;
|
---|
1386 | }
|
---|
1387 |
|
---|
1388 | uint32_t refs() { return ASMAtomicReadU32(&m_cRefs); }
|
---|
1389 |
|
---|
1390 | int wait0(RTMSINTERVAL ms = 1000, uint32_t cWaits = VBOXVHWA_INIFITE_WAITCOUNT)
|
---|
1391 | {
|
---|
1392 | int rc = VINF_SUCCESS;
|
---|
1393 | do
|
---|
1394 | {
|
---|
1395 | if (!refs())
|
---|
1396 | break;
|
---|
1397 | if (!cWaits)
|
---|
1398 | {
|
---|
1399 | rc = VERR_TIMEOUT;
|
---|
1400 | break;
|
---|
1401 | }
|
---|
1402 | if (cWaits != VBOXVHWA_INIFITE_WAITCOUNT)
|
---|
1403 | --cWaits;
|
---|
1404 | rc = RTThreadSleep(ms);
|
---|
1405 | AssertRC(rc);
|
---|
1406 | if (!RT_SUCCESS(rc))
|
---|
1407 | break;
|
---|
1408 | } while(1);
|
---|
1409 | return rc;
|
---|
1410 | }
|
---|
1411 | private:
|
---|
1412 | volatile uint32_t m_cRefs;
|
---|
1413 | };
|
---|
1414 |
|
---|
1415 | #define VBOXVHWACMDPIPEC_NEWEVENT 0x00000001
|
---|
1416 | #define VBOXVHWACMDPIPEC_COMPLETEEVENT 0x00000002
|
---|
1417 | class VBoxVHWACommandElementProcessor
|
---|
1418 | {
|
---|
1419 | public:
|
---|
1420 | VBoxVHWACommandElementProcessor(QObject *pNotifyObject);
|
---|
1421 | ~VBoxVHWACommandElementProcessor();
|
---|
1422 | void postCmd(VBOXVHWA_PIPECMD_TYPE aType, void * pvData, uint32_t flags);
|
---|
1423 | bool completeCurrentEvent();
|
---|
1424 | class VBoxVHWACommandElement * detachCmdList(class VBoxVHWACommandElement ** ppLast,
|
---|
1425 | class VBoxVHWACommandElement * pFirst2Free, VBoxVHWACommandElement * pLast2Free);
|
---|
1426 | void putBack(class VBoxVHWACommandElement * pFirst2Put, VBoxVHWACommandElement * pLast2Put,
|
---|
1427 | class VBoxVHWACommandElement * pFirst2Free, VBoxVHWACommandElement * pLast2Free);
|
---|
1428 | void reset(class VBoxVHWACommandElement ** ppHead, class VBoxVHWACommandElement ** ppTail);
|
---|
1429 | void setNotifyObject(QObject *pNotifyObject);
|
---|
1430 | int loadExec (struct SSMHANDLE * pSSM, uint32_t u32Version, void *pvVRAM);
|
---|
1431 | void saveExec (struct SSMHANDLE * pSSM, void *pvVRAM);
|
---|
1432 | void disable();
|
---|
1433 | void enable();
|
---|
1434 | void lock();
|
---|
1435 | void unlock();
|
---|
1436 | #ifdef DEBUG_misha
|
---|
1437 | void checkConsistence(uint32_t cEvents2Submit = 0, const VBoxVHWACommandElementPipe *pPipe = NULL);
|
---|
1438 | #endif
|
---|
1439 | private:
|
---|
1440 | RTCRITSECT mCritSect;
|
---|
1441 | VBoxVHWACommandElementPipe m_CmdPipe;
|
---|
1442 | QObject *m_pNotifyObject;
|
---|
1443 | VBoxVHWARefCounter m_NotifyObjectRefs;
|
---|
1444 | bool mbNewEvent;
|
---|
1445 | bool mbProcessingList;
|
---|
1446 | uint32_t mcDisabled;
|
---|
1447 | VBoxVHWACommandElementStack mFreeElements;
|
---|
1448 | VBoxVHWACommandElement mElementsBuffer[2048];
|
---|
1449 | };
|
---|
1450 |
|
---|
1451 | /* added to workaround this ** [VBox|UI] duplication */
|
---|
1452 | class VBoxFBSizeInfo
|
---|
1453 | {
|
---|
1454 | public:
|
---|
1455 | VBoxFBSizeInfo() {}
|
---|
1456 | template<class T> VBoxFBSizeInfo(T * fb) :
|
---|
1457 | mPixelFormat(fb->pixelFormat()), mVRAM(fb->address()), mBitsPerPixel(fb->bitsPerPixel()),
|
---|
1458 | mBytesPerLine(fb->bytesPerLine()), mWidth(fb->width()), mHeight(fb->height()),
|
---|
1459 | mUsesGuestVram(fb->usesGuestVRAM()) {}
|
---|
1460 |
|
---|
1461 | VBoxFBSizeInfo(ulong aPixelFormat, uchar *aVRAM,
|
---|
1462 | ulong aBitsPerPixel, ulong aBytesPerLine,
|
---|
1463 | ulong aWidth, ulong aHeight,
|
---|
1464 | bool bUsesGuestVram) :
|
---|
1465 | mPixelFormat (aPixelFormat), mVRAM (aVRAM), mBitsPerPixel (aBitsPerPixel),
|
---|
1466 | mBytesPerLine (aBytesPerLine), mWidth (aWidth), mHeight (aHeight),
|
---|
1467 | mUsesGuestVram(bUsesGuestVram) {}
|
---|
1468 | ulong pixelFormat() const { return mPixelFormat; }
|
---|
1469 | uchar *VRAM() const { return mVRAM; }
|
---|
1470 | ulong bitsPerPixel() const { return mBitsPerPixel; }
|
---|
1471 | ulong bytesPerLine() const { return mBytesPerLine; }
|
---|
1472 | ulong width() const { return mWidth; }
|
---|
1473 | ulong height() const { return mHeight; }
|
---|
1474 | bool usesGuestVram() const {return mUsesGuestVram;}
|
---|
1475 |
|
---|
1476 | private:
|
---|
1477 | ulong mPixelFormat;
|
---|
1478 | uchar *mVRAM;
|
---|
1479 | ulong mBitsPerPixel;
|
---|
1480 | ulong mBytesPerLine;
|
---|
1481 | ulong mWidth;
|
---|
1482 | ulong mHeight;
|
---|
1483 | bool mUsesGuestVram;
|
---|
1484 | };
|
---|
1485 |
|
---|
1486 | class VBoxVHWAImage
|
---|
1487 | {
|
---|
1488 | public:
|
---|
1489 | VBoxVHWAImage ();
|
---|
1490 | ~VBoxVHWAImage();
|
---|
1491 |
|
---|
1492 | int init(VBoxVHWASettings *aSettings);
|
---|
1493 | #ifdef VBOX_WITH_VIDEOHWACCEL
|
---|
1494 | uchar *vboxVRAMAddressFromOffset(uint64_t offset);
|
---|
1495 | uint64_t vboxVRAMOffsetFromAddress(uchar* addr);
|
---|
1496 | uint64_t vboxVRAMOffset(VBoxVHWASurfaceBase * pSurf);
|
---|
1497 |
|
---|
1498 | void vhwaSaveExec(struct SSMHANDLE * pSSM);
|
---|
1499 | static void vhwaSaveExecVoid(struct SSMHANDLE * pSSM);
|
---|
1500 | static int vhwaLoadExec(VHWACommandList * pCmdList, struct SSMHANDLE * pSSM, uint32_t u32Version);
|
---|
1501 |
|
---|
1502 | int vhwaSurfaceCanCreate(struct VBOXVHWACMD_SURF_CANCREATE *pCmd);
|
---|
1503 | int vhwaSurfaceCreate(struct VBOXVHWACMD_SURF_CREATE *pCmd);
|
---|
1504 | #ifdef VBOX_WITH_WDDM
|
---|
1505 | int vhwaSurfaceGetInfo(struct VBOXVHWACMD_SURF_GETINFO *pCmd);
|
---|
1506 | #endif
|
---|
1507 | int vhwaSurfaceDestroy(struct VBOXVHWACMD_SURF_DESTROY *pCmd);
|
---|
1508 | int vhwaSurfaceLock(struct VBOXVHWACMD_SURF_LOCK *pCmd);
|
---|
1509 | int vhwaSurfaceUnlock(struct VBOXVHWACMD_SURF_UNLOCK *pCmd);
|
---|
1510 | int vhwaSurfaceBlt(struct VBOXVHWACMD_SURF_BLT *pCmd);
|
---|
1511 | int vhwaSurfaceFlip(struct VBOXVHWACMD_SURF_FLIP *pCmd);
|
---|
1512 | int vhwaSurfaceColorFill(struct VBOXVHWACMD_SURF_COLORFILL *pCmd);
|
---|
1513 | int vhwaSurfaceOverlayUpdate(struct VBOXVHWACMD_SURF_OVERLAY_UPDATE *pCmf);
|
---|
1514 | int vhwaSurfaceOverlaySetPosition(struct VBOXVHWACMD_SURF_OVERLAY_SETPOSITION *pCmd);
|
---|
1515 | int vhwaSurfaceColorkeySet(struct VBOXVHWACMD_SURF_COLORKEY_SET *pCmd);
|
---|
1516 | int vhwaQueryInfo1(struct VBOXVHWACMD_QUERYINFO1 *pCmd);
|
---|
1517 | int vhwaQueryInfo2(struct VBOXVHWACMD_QUERYINFO2 *pCmd);
|
---|
1518 | int vhwaConstruct(struct VBOXVHWACMD_HH_CONSTRUCT *pCmd);
|
---|
1519 |
|
---|
1520 | void *vramBase() { return mpvVRAM; }
|
---|
1521 | uint32_t vramSize() { return mcbVRAM; }
|
---|
1522 |
|
---|
1523 | bool hasSurfaces() const;
|
---|
1524 | bool hasVisibleOverlays();
|
---|
1525 | QRect overlaysRectUnion();
|
---|
1526 | QRect overlaysRectIntersection();
|
---|
1527 | #endif
|
---|
1528 |
|
---|
1529 | static const QGLFormat & vboxGLFormat();
|
---|
1530 |
|
---|
1531 | int reset(VHWACommandList * pCmdList);
|
---|
1532 |
|
---|
1533 | int vboxFbWidth() {return mDisplay.getVGA()->width(); }
|
---|
1534 | int vboxFbHeight() {return mDisplay.getVGA()->height(); }
|
---|
1535 | bool isInitialized() {return mDisplay.getVGA() != NULL; }
|
---|
1536 |
|
---|
1537 | void resize(const VBoxFBSizeInfo & size);
|
---|
1538 |
|
---|
1539 | class VBoxVHWAGlProgramMngr * vboxVHWAGetGlProgramMngr() { return mpMngr; }
|
---|
1540 |
|
---|
1541 | VBoxVHWASurfaceBase * vgaSurface() { return mDisplay.getVGA(); }
|
---|
1542 |
|
---|
1543 | #ifdef VBOXVHWA_OLD_COORD
|
---|
1544 | static void doSetupMatrix(const QSize & aSize, bool bInverted);
|
---|
1545 | #endif
|
---|
1546 |
|
---|
1547 | void vboxDoUpdateViewport(const QRect & aRect);
|
---|
1548 | void vboxDoUpdateRect(const QRect * pRect);
|
---|
1549 |
|
---|
1550 | const QRect & vboxViewport() const {return mViewport;}
|
---|
1551 |
|
---|
1552 | #ifdef VBOXVHWA_PROFILE_FPS
|
---|
1553 | void reportNewFrame() { mbNewFrame = true; }
|
---|
1554 | #endif
|
---|
1555 |
|
---|
1556 | bool performDisplay(bool bForce)
|
---|
1557 | {
|
---|
1558 | bForce = mDisplay.performDisplay(bForce | mRepaintNeeded);
|
---|
1559 |
|
---|
1560 | #ifdef VBOXVHWA_PROFILE_FPS
|
---|
1561 | if(mbNewFrame)
|
---|
1562 | {
|
---|
1563 | mFPSCounter.frame();
|
---|
1564 | double fps = mFPSCounter.fps();
|
---|
1565 | if(!(mFPSCounter.frames() % 31))
|
---|
1566 | {
|
---|
1567 | printf("fps: %f\n", fps);
|
---|
1568 | }
|
---|
1569 | mbNewFrame = false;
|
---|
1570 | }
|
---|
1571 | #endif
|
---|
1572 | return bForce;
|
---|
1573 | }
|
---|
1574 |
|
---|
1575 | static void pushSettingsAndSetupViewport(const QSize &display, const QRect &viewport)
|
---|
1576 | {
|
---|
1577 | glPushAttrib(GL_ALL_ATTRIB_BITS);
|
---|
1578 | glMatrixMode(GL_PROJECTION);
|
---|
1579 | glPushMatrix();
|
---|
1580 | setupMatricies(display, false);
|
---|
1581 | adjustViewport(display, viewport);
|
---|
1582 | }
|
---|
1583 |
|
---|
1584 | static void popSettingsAfterSetupViewport()
|
---|
1585 | {
|
---|
1586 | glPopAttrib();
|
---|
1587 | glMatrixMode(GL_PROJECTION);
|
---|
1588 | glPopMatrix();
|
---|
1589 | glMatrixMode(GL_MODELVIEW);
|
---|
1590 | }
|
---|
1591 |
|
---|
1592 | private:
|
---|
1593 | static void setupMatricies(const QSize &display, bool bInvert);
|
---|
1594 | static void adjustViewport(const QSize &display, const QRect &viewport);
|
---|
1595 |
|
---|
1596 |
|
---|
1597 | #ifdef VBOXQGL_DBG_SURF
|
---|
1598 | void vboxDoTestSurfaces(void *context);
|
---|
1599 | #endif
|
---|
1600 | #ifdef VBOX_WITH_VIDEOHWACCEL
|
---|
1601 |
|
---|
1602 | void vboxCheckUpdateAddress(VBoxVHWASurfaceBase * pSurface, uint64_t offset)
|
---|
1603 | {
|
---|
1604 | if (pSurface->addressAlocated())
|
---|
1605 | {
|
---|
1606 | Assert(!mDisplay.isPrimary(pSurface));
|
---|
1607 | uchar * addr = vboxVRAMAddressFromOffset(offset);
|
---|
1608 | if (addr)
|
---|
1609 | {
|
---|
1610 | pSurface->setAddress(addr);
|
---|
1611 | }
|
---|
1612 | }
|
---|
1613 | }
|
---|
1614 |
|
---|
1615 | int vhwaSaveSurface(struct SSMHANDLE * pSSM, VBoxVHWASurfaceBase *pSurf, uint32_t surfCaps);
|
---|
1616 | static int vhwaLoadSurface(VHWACommandList * pCmdList, struct SSMHANDLE * pSSM, uint32_t cBackBuffers, uint32_t u32Version);
|
---|
1617 | int vhwaSaveOverlayData(struct SSMHANDLE * pSSM, VBoxVHWASurfaceBase *pSurf, bool bVisible);
|
---|
1618 | static int vhwaLoadOverlayData(VHWACommandList * pCmdList, struct SSMHANDLE * pSSM, uint32_t u32Version);
|
---|
1619 | static int vhwaLoadVHWAEnable(VHWACommandList * pCmdList);
|
---|
1620 |
|
---|
1621 | void vhwaDoSurfaceOverlayUpdate(VBoxVHWASurfaceBase *pDstSurf, VBoxVHWASurfaceBase *pSrcSurf, struct VBOXVHWACMD_SURF_OVERLAY_UPDATE *pCmd);
|
---|
1622 | #endif
|
---|
1623 |
|
---|
1624 | VBoxVHWADisplay mDisplay;
|
---|
1625 |
|
---|
1626 | VBoxVHWASurfaceBase* handle2Surface(uint32_t h)
|
---|
1627 | {
|
---|
1628 | VBoxVHWASurfaceBase* pSurf = (VBoxVHWASurfaceBase*)mSurfHandleTable.get(h);
|
---|
1629 | Assert(pSurf);
|
---|
1630 | return pSurf;
|
---|
1631 | }
|
---|
1632 |
|
---|
1633 | VBoxVHWAHandleTable mSurfHandleTable;
|
---|
1634 |
|
---|
1635 | bool mRepaintNeeded;
|
---|
1636 |
|
---|
1637 | QRect mViewport;
|
---|
1638 |
|
---|
1639 | VBoxVHWASurfList *mConstructingList;
|
---|
1640 | int32_t mcRemaining2Contruct;
|
---|
1641 |
|
---|
1642 | class VBoxVHWAGlProgramMngr *mpMngr;
|
---|
1643 |
|
---|
1644 | VBoxVHWASettings *mSettings;
|
---|
1645 |
|
---|
1646 | void *mpvVRAM;
|
---|
1647 | uint32_t mcbVRAM;
|
---|
1648 |
|
---|
1649 | #ifdef VBOXVHWA_PROFILE_FPS
|
---|
1650 | VBoxVHWADbgTimer mFPSCounter;
|
---|
1651 | bool mbNewFrame;
|
---|
1652 | #endif
|
---|
1653 | };
|
---|
1654 |
|
---|
1655 | class VBoxGLWgt : public QGLWidget
|
---|
1656 | {
|
---|
1657 | public:
|
---|
1658 | VBoxGLWgt(VBoxVHWAImage * pImage,
|
---|
1659 | QWidget* parent, const QGLWidget* shareWidget);
|
---|
1660 |
|
---|
1661 | protected:
|
---|
1662 | void paintGL()
|
---|
1663 | {
|
---|
1664 | mpImage->performDisplay(true);
|
---|
1665 | }
|
---|
1666 | private:
|
---|
1667 | VBoxVHWAImage * mpImage;
|
---|
1668 | };
|
---|
1669 |
|
---|
1670 | class VBoxVHWAFBO
|
---|
1671 | {
|
---|
1672 | public:
|
---|
1673 | VBoxVHWAFBO() :
|
---|
1674 | mFBO(0)
|
---|
1675 | {}
|
---|
1676 |
|
---|
1677 | ~VBoxVHWAFBO()
|
---|
1678 | {
|
---|
1679 | if(mFBO)
|
---|
1680 | {
|
---|
1681 | vboxglDeleteFramebuffers(1, &mFBO);
|
---|
1682 | }
|
---|
1683 | }
|
---|
1684 |
|
---|
1685 | void init()
|
---|
1686 | {
|
---|
1687 | VBOXQGL_CHECKERR(
|
---|
1688 | vboxglGenFramebuffers(1, &mFBO);
|
---|
1689 | );
|
---|
1690 | }
|
---|
1691 |
|
---|
1692 | void bind()
|
---|
1693 | {
|
---|
1694 | VBOXQGL_CHECKERR(
|
---|
1695 | vboxglBindFramebuffer(GL_FRAMEBUFFER, mFBO);
|
---|
1696 | );
|
---|
1697 | }
|
---|
1698 |
|
---|
1699 | void unbind()
|
---|
1700 | {
|
---|
1701 | VBOXQGL_CHECKERR(
|
---|
1702 | vboxglBindFramebuffer(GL_FRAMEBUFFER, 0);
|
---|
1703 | );
|
---|
1704 | }
|
---|
1705 |
|
---|
1706 | void attachBound(VBoxVHWATexture *pTex)
|
---|
1707 | {
|
---|
1708 | VBOXQGL_CHECKERR(
|
---|
1709 | vboxglFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, pTex->texTarget(), pTex->texture(), 0);
|
---|
1710 | );
|
---|
1711 | }
|
---|
1712 |
|
---|
1713 | private:
|
---|
1714 | GLuint mFBO;
|
---|
1715 | };
|
---|
1716 |
|
---|
1717 | template <class T>
|
---|
1718 | class VBoxVHWATextureImageFBO : public T
|
---|
1719 | {
|
---|
1720 | public:
|
---|
1721 | VBoxVHWATextureImageFBO(const QRect &size, const VBoxVHWAColorFormat &format, class VBoxVHWAGlProgramMngr * aMgr, VBOXVHWAIMG_TYPE flags) :
|
---|
1722 | T(size, format, aMgr, flags & (~(VBOXVHWAIMG_FBO | VBOXVHWAIMG_LINEAR))),
|
---|
1723 | mFBOTex(size, VBoxVHWAColorFormat(32, 0xff0000, 0xff00, 0xff), aMgr, (flags & (~VBOXVHWAIMG_FBO))),
|
---|
1724 | mpvFBOTexMem(NULL)
|
---|
1725 | {
|
---|
1726 | }
|
---|
1727 |
|
---|
1728 | virtual ~VBoxVHWATextureImageFBO()
|
---|
1729 | {
|
---|
1730 | if(mpvFBOTexMem)
|
---|
1731 | free(mpvFBOTexMem);
|
---|
1732 | }
|
---|
1733 |
|
---|
1734 | virtual void init(uchar *pvMem)
|
---|
1735 | {
|
---|
1736 | mFBO.init();
|
---|
1737 | mpvFBOTexMem = (uchar*)malloc(mFBOTex.memSize());
|
---|
1738 | mFBOTex.init(mpvFBOTexMem);
|
---|
1739 | T::init(pvMem);
|
---|
1740 | mFBO.bind();
|
---|
1741 | mFBO.attachBound(mFBOTex.component(0));
|
---|
1742 | mFBO.unbind();
|
---|
1743 | }
|
---|
1744 |
|
---|
1745 | virtual int createDisplay(VBoxVHWATextureImage *pDst, const QRect * pDstRect, const QRect * pSrcRect,
|
---|
1746 | const VBoxVHWAColorKey * pDstCKey, const VBoxVHWAColorKey * pSrcCKey, bool bNotIntersected,
|
---|
1747 | GLuint *pDisplay, class VBoxVHWAGlProgramVHWA ** ppProgram)
|
---|
1748 | {
|
---|
1749 | T::createDisplay(NULL, &mFBOTex.rect(), &rect(),
|
---|
1750 | NULL, NULL, false,
|
---|
1751 | pDisplay, ppProgram);
|
---|
1752 |
|
---|
1753 | return mFBOTex.initDisplay(pDst, pDstRect, pSrcRect,
|
---|
1754 | pDstCKey, pSrcCKey, bNotIntersected);
|
---|
1755 | }
|
---|
1756 |
|
---|
1757 | virtual void update(const QRect * pRect)
|
---|
1758 | {
|
---|
1759 | T::update(pRect);
|
---|
1760 |
|
---|
1761 | VBoxVHWAImage::pushSettingsAndSetupViewport(rect().size(), rect());
|
---|
1762 | mFBO.bind();
|
---|
1763 | T::display();
|
---|
1764 | mFBO.unbind();
|
---|
1765 | VBoxVHWAImage::popSettingsAfterSetupViewport();
|
---|
1766 | }
|
---|
1767 |
|
---|
1768 | virtual void display(VBoxVHWATextureImage *pDst, const QRect * pDstRect, const QRect * pSrcRect,
|
---|
1769 | const VBoxVHWAColorKey * pDstCKey, const VBoxVHWAColorKey * pSrcCKey, bool bNotIntersected)
|
---|
1770 | {
|
---|
1771 | mFBOTex.display(pDst, pDstRect, pSrcRect, pDstCKey, pSrcCKey, bNotIntersected);
|
---|
1772 | }
|
---|
1773 |
|
---|
1774 | virtual void display()
|
---|
1775 | {
|
---|
1776 | mFBOTex.display();
|
---|
1777 | }
|
---|
1778 |
|
---|
1779 | const QRect &rect() { return T::rect(); }
|
---|
1780 | private:
|
---|
1781 | VBoxVHWAFBO mFBO;
|
---|
1782 | VBoxVHWATextureImage mFBOTex;
|
---|
1783 | uchar * mpvFBOTexMem;
|
---|
1784 | };
|
---|
1785 |
|
---|
1786 | class VBoxQGLOverlay
|
---|
1787 | {
|
---|
1788 | public:
|
---|
1789 | VBoxQGLOverlay(QWidget *pViewport, QObject *pPostEventObject, CSession * aSession, uint32_t id);
|
---|
1790 | ~VBoxQGLOverlay()
|
---|
1791 | {
|
---|
1792 | if (mpShareWgt)
|
---|
1793 | delete mpShareWgt;
|
---|
1794 | }
|
---|
1795 |
|
---|
1796 | void updateAttachment(QWidget *pViewport, QObject *pPostEventObject);
|
---|
1797 |
|
---|
1798 | int onVHWACommand (struct VBOXVHWACMD * pCommand);
|
---|
1799 |
|
---|
1800 | void onVHWACommandEvent (QEvent * pEvent);
|
---|
1801 |
|
---|
1802 | /**
|
---|
1803 | * to be called on NotifyUpdate framebuffer call
|
---|
1804 | * @return true if the request was processed & should not be forwarded to the framebuffer
|
---|
1805 | * false - otherwise */
|
---|
1806 | bool onNotifyUpdate (ULONG aX, ULONG aY,
|
---|
1807 | ULONG aW, ULONG aH);
|
---|
1808 |
|
---|
1809 | /**
|
---|
1810 | * to be called on RequestResize framebuffer call
|
---|
1811 | * @return true if the request was processed & should not be forwarded to the framebuffer
|
---|
1812 | * false - otherwise */
|
---|
1813 | bool onRequestResize (ULONG aScreenId, ULONG uPixelFormat,
|
---|
1814 | BYTE * pVRAM, ULONG uBitsPerPixel, ULONG uBytesPerLine,
|
---|
1815 | ULONG uWidth, ULONG uHeight,
|
---|
1816 | HRESULT *pResult,
|
---|
1817 | BOOL * pbFinished)
|
---|
1818 | {
|
---|
1819 | Q_UNUSED(aScreenId);
|
---|
1820 | Q_UNUSED(uPixelFormat);
|
---|
1821 | Q_UNUSED(pVRAM);
|
---|
1822 | Q_UNUSED(uBitsPerPixel);
|
---|
1823 | Q_UNUSED(uBytesPerLine);
|
---|
1824 | Q_UNUSED(uWidth);
|
---|
1825 | Q_UNUSED(uHeight);
|
---|
1826 | Q_UNUSED(pbFinished);
|
---|
1827 |
|
---|
1828 | if (mCmdPipe.completeCurrentEvent())
|
---|
1829 | return false;
|
---|
1830 |
|
---|
1831 | /* TODO: more graceful resize handling */
|
---|
1832 | *pResult = E_FAIL;
|
---|
1833 |
|
---|
1834 | return true;
|
---|
1835 | }
|
---|
1836 |
|
---|
1837 | void onResizeEventPostprocess (const VBoxFBSizeInfo &re, const QPoint & topLeft);
|
---|
1838 |
|
---|
1839 | void onViewportResized (QResizeEvent * /*re*/)
|
---|
1840 | {
|
---|
1841 | vboxDoCheckUpdateViewport();
|
---|
1842 | mGlCurrent = false;
|
---|
1843 | }
|
---|
1844 |
|
---|
1845 | void onViewportScrolled (const QPoint & newTopLeft)
|
---|
1846 | {
|
---|
1847 | mContentsTopLeft = newTopLeft;
|
---|
1848 | vboxDoCheckUpdateViewport();
|
---|
1849 | mGlCurrent = false;
|
---|
1850 | }
|
---|
1851 |
|
---|
1852 | static bool isAcceleration2DVideoAvailable();
|
---|
1853 |
|
---|
1854 | /** additional video memory required for the best 2D support performance
|
---|
1855 | * total amount of VRAM required is thus calculated as requiredVideoMemory + required2DOffscreenVideoMemory */
|
---|
1856 | static quint64 required2DOffscreenVideoMemory();
|
---|
1857 |
|
---|
1858 | /* not supposed to be called by clients */
|
---|
1859 | int vhwaLoadExec (struct SSMHANDLE * pSSM, uint32_t u32Version);
|
---|
1860 | void vhwaSaveExec (struct SSMHANDLE * pSSM);
|
---|
1861 | private:
|
---|
1862 | int vhwaSurfaceUnlock (struct VBOXVHWACMD_SURF_UNLOCK *pCmd);
|
---|
1863 |
|
---|
1864 | void repaintMain();
|
---|
1865 | void repaintOverlay()
|
---|
1866 | {
|
---|
1867 | if(mNeedOverlayRepaint)
|
---|
1868 | {
|
---|
1869 | mNeedOverlayRepaint = false;
|
---|
1870 | performDisplayOverlay();
|
---|
1871 | }
|
---|
1872 | if(mNeedSetVisible)
|
---|
1873 | {
|
---|
1874 | mNeedSetVisible = false;
|
---|
1875 | mpOverlayWgt->setVisible (true);
|
---|
1876 | }
|
---|
1877 | }
|
---|
1878 | void repaint()
|
---|
1879 | {
|
---|
1880 | repaintOverlay();
|
---|
1881 | repaintMain();
|
---|
1882 | }
|
---|
1883 |
|
---|
1884 | void makeCurrent()
|
---|
1885 | {
|
---|
1886 | if (!mGlCurrent)
|
---|
1887 | {
|
---|
1888 | mGlCurrent = true;
|
---|
1889 | mpOverlayWgt->makeCurrent();
|
---|
1890 | }
|
---|
1891 | }
|
---|
1892 |
|
---|
1893 | void performDisplayOverlay()
|
---|
1894 | {
|
---|
1895 | if (mOverlayVisible)
|
---|
1896 | {
|
---|
1897 | makeCurrent();
|
---|
1898 | if (mOverlayImage.performDisplay(false))
|
---|
1899 | mpOverlayWgt->swapBuffers();
|
---|
1900 | }
|
---|
1901 | }
|
---|
1902 |
|
---|
1903 | void vboxSetGlOn (bool on);
|
---|
1904 | bool vboxGetGlOn() { return mGlOn; }
|
---|
1905 | bool vboxSynchGl();
|
---|
1906 | void vboxDoVHWACmdExec(void *cmd);
|
---|
1907 | void vboxShowOverlay (bool show);
|
---|
1908 | void vboxDoCheckUpdateViewport();
|
---|
1909 | void vboxDoVHWACmd (void *cmd);
|
---|
1910 | void addMainDirtyRect (const QRect & aRect);
|
---|
1911 | void vboxCheckUpdateOverlay (const QRect & rect);
|
---|
1912 | VBoxVHWACommandElement * processCmdList (VBoxVHWACommandElement * pCmd, bool bFirst);
|
---|
1913 |
|
---|
1914 | int vhwaConstruct (struct VBOXVHWACMD_HH_CONSTRUCT *pCmd);
|
---|
1915 |
|
---|
1916 | int reset();
|
---|
1917 |
|
---|
1918 | int resetGl();
|
---|
1919 |
|
---|
1920 | void initGl();
|
---|
1921 |
|
---|
1922 | VBoxGLWgt *mpOverlayWgt;
|
---|
1923 | VBoxVHWAImage mOverlayImage;
|
---|
1924 | QWidget *mpViewport;
|
---|
1925 | bool mGlOn;
|
---|
1926 | bool mOverlayWidgetVisible;
|
---|
1927 | bool mOverlayVisible;
|
---|
1928 | bool mGlCurrent;
|
---|
1929 | bool mProcessingCommands;
|
---|
1930 | bool mNeedOverlayRepaint;
|
---|
1931 | bool mNeedSetVisible;
|
---|
1932 | QRect mOverlayViewport;
|
---|
1933 | VBoxVHWADirtyRect mMainDirtyRect;
|
---|
1934 |
|
---|
1935 | VBoxVHWACommandElementProcessor mCmdPipe;
|
---|
1936 |
|
---|
1937 | /* this is used in saved state restore to postpone surface restoration
|
---|
1938 | * till the framebuffer size is restored */
|
---|
1939 | VHWACommandList mOnResizeCmdList;
|
---|
1940 |
|
---|
1941 | VBoxVHWASettings mSettings;
|
---|
1942 | CSession * mpSession;
|
---|
1943 |
|
---|
1944 | VBoxFBSizeInfo mSizeInfo;
|
---|
1945 | VBoxFBSizeInfo mPostponedResize;
|
---|
1946 | QPoint mContentsTopLeft;
|
---|
1947 |
|
---|
1948 | QGLWidget *mpShareWgt;
|
---|
1949 |
|
---|
1950 | uint32_t m_id;
|
---|
1951 | };
|
---|
1952 |
|
---|
1953 | /* these two additional class V, class R are to workaround the [VBox|UI] duplication,
|
---|
1954 | * @todo: remove them once VBox stuff is removed */
|
---|
1955 | template <class T, class V, class R>
|
---|
1956 | class VBoxOverlayFrameBuffer : public T
|
---|
1957 | {
|
---|
1958 | public:
|
---|
1959 | VBoxOverlayFrameBuffer (V *pView, CSession * aSession, uint32_t id)
|
---|
1960 | : T (pView),
|
---|
1961 | mOverlay(pView->viewport(), pView, aSession, id),
|
---|
1962 | mpView (pView)
|
---|
1963 | {
|
---|
1964 | /* sync with framebuffer */
|
---|
1965 | mOverlay.onResizeEventPostprocess (VBoxFBSizeInfo(this), QPoint(mpView->contentsX(), mpView->contentsY()));
|
---|
1966 | }
|
---|
1967 |
|
---|
1968 | STDMETHOD(ProcessVHWACommand)(BYTE *pCommand)
|
---|
1969 | {
|
---|
1970 | return mOverlay.onVHWACommand ((struct VBOXVHWACMD*)pCommand);
|
---|
1971 | }
|
---|
1972 |
|
---|
1973 | void doProcessVHWACommand (QEvent * pEvent)
|
---|
1974 | {
|
---|
1975 | mOverlay.onVHWACommandEvent (pEvent);
|
---|
1976 | }
|
---|
1977 |
|
---|
1978 | STDMETHOD(RequestResize) (ULONG aScreenId, ULONG aPixelFormat,
|
---|
1979 | BYTE *aVRAM, ULONG aBitsPerPixel, ULONG aBytesPerLine,
|
---|
1980 | ULONG aWidth, ULONG aHeight,
|
---|
1981 | BOOL *aFinished)
|
---|
1982 | {
|
---|
1983 | HRESULT result;
|
---|
1984 | if (mOverlay.onRequestResize (aScreenId, aPixelFormat,
|
---|
1985 | aVRAM, aBitsPerPixel, aBytesPerLine,
|
---|
1986 | aWidth, aHeight,
|
---|
1987 | &result,
|
---|
1988 | aFinished))
|
---|
1989 | {
|
---|
1990 | return result;
|
---|
1991 | }
|
---|
1992 | return T::RequestResize (aScreenId, aPixelFormat,
|
---|
1993 | aVRAM, aBitsPerPixel, aBytesPerLine,
|
---|
1994 | aWidth, aHeight,
|
---|
1995 | aFinished);
|
---|
1996 | }
|
---|
1997 |
|
---|
1998 | STDMETHOD(NotifyUpdate) (ULONG aX, ULONG aY,
|
---|
1999 | ULONG aW, ULONG aH)
|
---|
2000 | {
|
---|
2001 | if (mOverlay.onNotifyUpdate (aX, aY, aW, aH))
|
---|
2002 | return S_OK;
|
---|
2003 | return T::NotifyUpdate (aX, aY, aW, aH);
|
---|
2004 | }
|
---|
2005 |
|
---|
2006 | STDMETHOD(VideoModeSupported) (ULONG uWidth, ULONG uHeight, ULONG uBPP,
|
---|
2007 | BOOL *pbSupported)
|
---|
2008 | {
|
---|
2009 | /* TODO: tmp workaround: the lock should be moved to the calling code??
|
---|
2010 | * otherwise we may end up calling a null View */
|
---|
2011 | /* Todo: can we call VideoModeSupported with the lock held?
|
---|
2012 | * if not we can introduce a ref counting for the mpView usage
|
---|
2013 | * to ensure it stays alive till we need it*/
|
---|
2014 | HRESULT hr = T::Lock();
|
---|
2015 | HRESULT retHr = S_OK;
|
---|
2016 | Assert(hr == S_OK);
|
---|
2017 | if (SUCCEEDED(hr))
|
---|
2018 | {
|
---|
2019 | if (mpView)
|
---|
2020 | retHr = T::VideoModeSupported(uWidth, uHeight, uBPP, pbSupported);
|
---|
2021 | hr = T::Unlock();
|
---|
2022 | Assert(hr == S_OK);
|
---|
2023 | }
|
---|
2024 | return retHr;
|
---|
2025 | }
|
---|
2026 |
|
---|
2027 | void resizeEvent (R *re)
|
---|
2028 | {
|
---|
2029 | T::resizeEvent (re);
|
---|
2030 | mOverlay.onResizeEventPostprocess (VBoxFBSizeInfo(this),
|
---|
2031 | QPoint(mpView->contentsX(), mpView->contentsY()));
|
---|
2032 | }
|
---|
2033 |
|
---|
2034 | void viewportResized (QResizeEvent * re)
|
---|
2035 | {
|
---|
2036 | mOverlay.onViewportResized (re);
|
---|
2037 | T::viewportResized (re);
|
---|
2038 | }
|
---|
2039 |
|
---|
2040 | void viewportScrolled (int dx, int dy)
|
---|
2041 | {
|
---|
2042 | mOverlay.onViewportScrolled (QPoint(mpView->contentsX(), mpView->contentsY()));
|
---|
2043 | T::viewportScrolled (dx, dy);
|
---|
2044 | }
|
---|
2045 |
|
---|
2046 | void setView(V * pView)
|
---|
2047 | {
|
---|
2048 | /* lock to ensure we do not collide with the EMT thread passing commands to us */
|
---|
2049 | HRESULT hr = T::Lock();
|
---|
2050 | Assert(hr == S_OK);
|
---|
2051 | if (SUCCEEDED(hr))
|
---|
2052 | {
|
---|
2053 | T::setView(pView);
|
---|
2054 | mpView = pView;
|
---|
2055 | mOverlay.updateAttachment(pView ? pView->viewport() : NULL, pView);
|
---|
2056 | hr = T::Unlock();
|
---|
2057 | Assert(hr == S_OK);
|
---|
2058 | }
|
---|
2059 | }
|
---|
2060 | private:
|
---|
2061 | VBoxQGLOverlay mOverlay;
|
---|
2062 | V *mpView;
|
---|
2063 | };
|
---|
2064 |
|
---|
2065 | #endif
|
---|
2066 |
|
---|
2067 | #endif /* #ifndef __VBoxFBOverlay_h__ */
|
---|