VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/include/VBoxFrameBuffer.h@ 22215

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

video hw accel: basics for saved state support

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 43.7 KB
Line 
1/** @file
2 *
3 * VBox frontends: Qt GUI ("VirtualBox"):
4 * VBoxFrameBuffer class and subclasses 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
23#ifndef ___VBoxFrameBuffer_h___
24#define ___VBoxFrameBuffer_h___
25//#define VBOXQGL_PROF_BASE 1
26//#define VBOXQGL_DBG_SURF 1
27#include "COMDefs.h"
28#include <iprt/critsect.h>
29
30/* Qt includes */
31#include <QImage>
32#include <QPixmap>
33#include <QMutex>
34#include <QPaintEvent>
35#include <QMoveEvent>
36#if defined (VBOX_GUI_USE_QGL)
37#include <QGLWidget>
38#endif
39
40#if defined (VBOX_GUI_USE_SDL)
41#include <SDL.h>
42#include <signal.h>
43#endif
44
45#if defined (Q_WS_WIN) && defined (VBOX_GUI_USE_DDRAW)
46// VBox/cdefs.h defines these:
47#undef LOWORD
48#undef HIWORD
49#undef LOBYTE
50#undef HIBYTE
51#include <ddraw.h>
52#endif
53
54class VBoxConsoleView;
55
56/////////////////////////////////////////////////////////////////////////////
57
58/**
59 * Frame buffer resize event.
60 */
61class VBoxResizeEvent : public QEvent
62{
63public:
64
65 VBoxResizeEvent (ulong aPixelFormat, uchar *aVRAM,
66 ulong aBitsPerPixel, ulong aBytesPerLine,
67 ulong aWidth, ulong aHeight) :
68 QEvent ((QEvent::Type) VBoxDefs::ResizeEventType),
69 mPixelFormat (aPixelFormat), mVRAM (aVRAM), mBitsPerPixel (aBitsPerPixel),
70 mBytesPerLine (aBytesPerLine), mWidth (aWidth), mHeight (aHeight) {}
71 ulong pixelFormat() { return mPixelFormat; }
72 uchar *VRAM() { return mVRAM; }
73 ulong bitsPerPixel() { return mBitsPerPixel; }
74 ulong bytesPerLine() { return mBytesPerLine; }
75 ulong width() { return mWidth; }
76 ulong height() { return mHeight; }
77
78private:
79
80 ulong mPixelFormat;
81 uchar *mVRAM;
82 ulong mBitsPerPixel;
83 ulong mBytesPerLine;
84 ulong mWidth;
85 ulong mHeight;
86};
87
88/**
89 * Frame buffer repaint event.
90 */
91class VBoxRepaintEvent : public QEvent
92{
93public:
94 VBoxRepaintEvent (int x, int y, int w, int h) :
95 QEvent ((QEvent::Type) VBoxDefs::RepaintEventType),
96 ex (x), ey (y), ew (w), eh (h)
97 {}
98 int x() { return ex; }
99 int y() { return ey; }
100 int width() { return ew; }
101 int height() { return eh; }
102private:
103 int ex, ey, ew, eh;
104};
105
106/**
107 * Frame buffer set region event.
108 */
109class VBoxSetRegionEvent : public QEvent
110{
111public:
112 VBoxSetRegionEvent (const QRegion &aReg)
113 : QEvent ((QEvent::Type) VBoxDefs::SetRegionEventType)
114 , mReg (aReg) {}
115 QRegion region() { return mReg; }
116private:
117 QRegion mReg;
118};
119
120#ifdef VBOX_GUI_USE_QGL
121typedef enum
122{
123 VBOXVHWA_PIPECMD_PAINT = 1,
124 VBOXVHWA_PIPECMD_VHWA,
125
126}VBOXVHWA_PIPECMD_TYPE;
127class VBoxVHWACommandElement
128{
129public:
130 void setVHWACmd(struct _VBOXVHWACMD * pCmd)
131 {
132 mType = VBOXVHWA_PIPECMD_VHWA;
133 mpCmd = pCmd;
134 }
135
136 void setPaintCmd(const QRect & aRect)
137 {
138 mType = VBOXVHWA_PIPECMD_PAINT;
139 mRect = aRect;
140 }
141
142 void setData(VBOXVHWA_PIPECMD_TYPE aType, void * pvData)
143 {
144 switch(aType)
145 {
146 case VBOXVHWA_PIPECMD_PAINT:
147 setPaintCmd(*((QRect*)pvData));
148 break;
149 case VBOXVHWA_PIPECMD_VHWA:
150 setVHWACmd((struct _VBOXVHWACMD *)pvData);
151 break;
152 }
153 }
154
155 VBOXVHWA_PIPECMD_TYPE type() const {return mType;}
156 const QRect & rect() const {return mRect;}
157 struct _VBOXVHWACMD * vhwaCmd() const {return mpCmd;}
158
159private:
160 VBoxVHWACommandElement * mpNext;
161 VBOXVHWA_PIPECMD_TYPE mType;
162 struct _VBOXVHWACMD * mpCmd;
163 QRect mRect;
164
165 friend class VBoxVHWACommandElementPipe;
166 friend class VBoxVHWACommandElementStack;
167 friend class VBoxGLWidget;
168};
169
170class VBoxVHWACommandElementPipe
171{
172public:
173 VBoxVHWACommandElementPipe() :
174 mpFirst(NULL),
175 mpLast(NULL)
176 {}
177
178 void put(VBoxVHWACommandElement *pCmd)
179 {
180 if(mpLast)
181 {
182 Assert(mpFirst);
183 mpLast->mpNext = pCmd;
184 mpLast = pCmd;
185 }
186 else
187 {
188 Assert(!mpFirst);
189 mpFirst = pCmd;
190 mpLast = pCmd;
191 }
192 pCmd->mpNext= NULL;
193
194 }
195
196 VBoxVHWACommandElement * detachList()
197 {
198 if(mpLast)
199 {
200 VBoxVHWACommandElement * pHead = mpFirst;
201 mpFirst = NULL;
202 mpLast = NULL;
203 return pHead;
204 }
205 return NULL;
206 }
207private:
208 VBoxVHWACommandElement *mpFirst;
209 VBoxVHWACommandElement *mpLast;
210};
211
212class VBoxVHWACommandElementStack
213{
214public:
215 VBoxVHWACommandElementStack() :
216 mpFirst(NULL) {}
217
218 void push(VBoxVHWACommandElement *pCmd)
219 {
220 pCmd->mpNext = mpFirst;
221 mpFirst = pCmd;
222 }
223
224 void pusha(VBoxVHWACommandElement *pFirst, VBoxVHWACommandElement *pLast)
225 {
226 pLast->mpNext = mpFirst;
227 mpFirst = pFirst;
228 }
229
230 VBoxVHWACommandElement * pop()
231 {
232 if(mpFirst)
233 {
234 VBoxVHWACommandElement * ret = mpFirst;
235 mpFirst = ret->mpNext;
236 return ret;
237 }
238 return NULL;
239 }
240private:
241 VBoxVHWACommandElement *mpFirst;
242};
243
244class VBoxVHWACommandProcessEvent : public QEvent
245{
246public:
247 VBoxVHWACommandProcessEvent (VBoxVHWACommandElement *pEl)
248 : QEvent ((QEvent::Type) VBoxDefs::VHWACommandProcessType)
249 {
250 mCmdPipe.put(pEl);
251 }
252 VBoxVHWACommandElementPipe & pipe() { return mCmdPipe; }
253private:
254 VBoxVHWACommandElementPipe mCmdPipe;
255 VBoxVHWACommandProcessEvent *mpNext;
256
257 friend class VBoxGLWidget;
258};
259
260#endif
261
262/////////////////////////////////////////////////////////////////////////////
263
264/**
265 * Common IFramebuffer implementation for all methods used by GUI to maintain
266 * the VM display video memory.
267 *
268 * Note that although this class can be called from multiple threads
269 * (in particular, the GUI thread and EMT) it doesn't protect access to every
270 * data field using its mutex lock. This is because all synchronization between
271 * the GUI and the EMT thread is supposed to be done using the
272 * IFramebuffer::NotifyUpdate() and IFramebuffer::RequestResize() methods
273 * (in particular, the \a aFinished parameter of these methods is responsible
274 * for the synchronization). These methods are always called on EMT and
275 * therefore always follow one another but never in parallel.
276 *
277 * Using this object's mutex lock (exposed also in IFramebuffer::Lock() and
278 * IFramebuffer::Unlock() implementations) usually makes sense only if some
279 * third-party thread (i.e. other than GUI or EMT) needs to make sure that
280 * *no* VM display update or resize event can occur while it is accessing
281 * IFramebuffer properties or the underlying display memory storage area.
282 *
283 * See IFramebuffer documentation for more info.
284 */
285
286class VBoxFrameBuffer : VBOX_SCRIPTABLE_IMPL(IFramebuffer)
287{
288public:
289
290 VBoxFrameBuffer (VBoxConsoleView *aView);
291 virtual ~VBoxFrameBuffer();
292
293 NS_DECL_ISUPPORTS
294
295#if defined (Q_OS_WIN32)
296
297 STDMETHOD_(ULONG, AddRef)()
298 {
299 return ::InterlockedIncrement (&refcnt);
300 }
301
302 STDMETHOD_(ULONG, Release)()
303 {
304 long cnt = ::InterlockedDecrement (&refcnt);
305 if (cnt == 0)
306 delete this;
307 return cnt;
308 }
309#endif
310 VBOX_SCRIPTABLE_DISPATCH_IMPL(IFramebuffer)
311
312 // IFramebuffer COM methods
313 STDMETHOD(COMGETTER(Address)) (BYTE **aAddress);
314 STDMETHOD(COMGETTER(Width)) (ULONG *aWidth);
315 STDMETHOD(COMGETTER(Height)) (ULONG *aHeight);
316 STDMETHOD(COMGETTER(BitsPerPixel)) (ULONG *aBitsPerPixel);
317 STDMETHOD(COMGETTER(BytesPerLine)) (ULONG *aBytesPerLine);
318 STDMETHOD(COMGETTER(PixelFormat)) (ULONG *aPixelFormat);
319 STDMETHOD(COMGETTER(UsesGuestVRAM)) (BOOL *aUsesGuestVRAM);
320 STDMETHOD(COMGETTER(HeightReduction)) (ULONG *aHeightReduction);
321 STDMETHOD(COMGETTER(Overlay)) (IFramebufferOverlay **aOverlay);
322 STDMETHOD(COMGETTER(WinId)) (ULONG64 *winId);
323
324 STDMETHOD(Lock)();
325 STDMETHOD(Unlock)();
326
327 STDMETHOD(RequestResize) (ULONG aScreenId, ULONG aPixelFormat,
328 BYTE *aVRAM, ULONG aBitsPerPixel, ULONG aBytesPerLine,
329 ULONG aWidth, ULONG aHeight,
330 BOOL *aFinished);
331
332 STDMETHOD(VideoModeSupported) (ULONG aWidth, ULONG aHeight, ULONG aBPP,
333 BOOL *aSupported);
334
335 STDMETHOD(GetVisibleRegion)(BYTE *aRectangles, ULONG aCount, ULONG *aCountCopied);
336 STDMETHOD(SetVisibleRegion)(BYTE *aRectangles, ULONG aCount);
337
338 STDMETHOD(ProcessVHWACommand)(BYTE *pCommand);
339
340 ulong width() { return mWdt; }
341 ulong height() { return mHgt; }
342
343 virtual ulong pixelFormat()
344 {
345 return FramebufferPixelFormat_FOURCC_RGB;
346 }
347
348 virtual bool usesGuestVRAM()
349 {
350 return false;
351 }
352
353 void lock() { RTCritSectEnter(&mCritSect); }
354 void unlock() { RTCritSectLeave(&mCritSect); }
355
356 virtual uchar *address() = 0;
357 virtual ulong bitsPerPixel() = 0;
358 virtual ulong bytesPerLine() = 0;
359
360 /**
361 * Called on the GUI thread (from VBoxConsoleView) when some part of the
362 * VM display viewport needs to be repainted on the host screen.
363 */
364 virtual void paintEvent (QPaintEvent *pe) = 0;
365
366 /**
367 * Called on the GUI thread (from VBoxConsoleView) after it gets a
368 * VBoxResizeEvent posted from the RequestResize() method implementation.
369 */
370 virtual void resizeEvent (VBoxResizeEvent *re)
371 {
372 mWdt = re->width();
373 mHgt = re->height();
374 }
375
376 /**
377 * Called on the GUI thread (from VBoxConsoleView) when the VM console
378 * window is moved.
379 */
380 virtual void moveEvent (QMoveEvent * /*me*/ ) {}
381
382#ifdef VBOX_GUI_USE_QGL
383 /* this method is called from the GUI thread
384 * to perform the actual Video HW Acceleration command processing */
385 virtual void doProcessVHWACommand(VBoxVHWACommandProcessEvent * pEvent);
386#endif
387
388protected:
389
390 VBoxConsoleView *mView;
391 RTCRITSECT mCritSect;
392 int mWdt;
393 int mHgt;
394 uint64_t mWinId;
395
396#if defined (Q_OS_WIN32)
397private:
398 long refcnt;
399#endif
400};
401
402/////////////////////////////////////////////////////////////////////////////
403
404#if defined (VBOX_GUI_USE_QIMAGE)
405
406class VBoxQImageFrameBuffer : public VBoxFrameBuffer
407{
408public:
409
410 VBoxQImageFrameBuffer (VBoxConsoleView *aView);
411
412 STDMETHOD(NotifyUpdate) (ULONG aX, ULONG aY,
413 ULONG aW, ULONG aH);
414
415 ulong pixelFormat() { return mPixelFormat; }
416 bool usesGuestVRAM() { return mUsesGuestVRAM; }
417
418 uchar *address() { return mImg.bits(); }
419 ulong bitsPerPixel() { return mImg.depth(); }
420 ulong bytesPerLine() { return mImg.bytesPerLine(); }
421
422 void paintEvent (QPaintEvent *pe);
423 void resizeEvent (VBoxResizeEvent *re);
424
425private:
426
427 QPixmap mPM;
428 QImage mImg;
429 ulong mPixelFormat;
430 bool mUsesGuestVRAM;
431};
432
433#endif
434
435/////////////////////////////////////////////////////////////////////////////
436
437#if defined (VBOX_GUI_USE_QGL)
438
439#ifdef DEBUG
440#include "iprt/stream.h"
441#define VBOXQGLLOG(_m) RTPrintf _m
442#else
443#define VBOXQGLLOG(_m)
444#endif
445#define VBOXQGLLOG_ENTER(_m)
446//do{VBOXQGLLOG(("==>[%s]:", __FUNCTION__)); VBOXQGLLOG(_m);}while(0)
447#define VBOXQGLLOG_EXIT(_m)
448//do{VBOXQGLLOG(("<==[%s]:", __FUNCTION__)); VBOXQGLLOG(_m);}while(0)
449#ifdef DEBUG
450#define VBOXQGL_ASSERTNOERR() \
451 do { GLenum err = glGetError(); \
452 if(err != GL_NO_ERROR) VBOXQGLLOG(("gl error ocured (0x%x)\n", err)); \
453 Assert(err == GL_NO_ERROR); \
454 }while(0)
455
456#define VBOXQGL_CHECKERR(_op) \
457 do { \
458 glGetError(); \
459 _op \
460 VBOXQGL_ASSERTNOERR(); \
461 }while(0)
462#else
463#define VBOXQGL_ASSERTNOERR() \
464 do {}while(0)
465
466#define VBOXQGL_CHECKERR(_op) \
467 do { \
468 _op \
469 }while(0)
470#endif
471
472#ifdef DEBUG
473#include <iprt/time.h>
474
475#define VBOXGETTIME() RTTimeNanoTS()
476
477#define VBOXPRINTDIF(_nano, _m) do{\
478 uint64_t cur = VBOXGETTIME(); \
479 VBOXQGLLOG(_m); \
480 VBOXQGLLOG(("(%Lu)\n", cur - (_nano))); \
481 }while(0)
482
483class VBoxVHWADbgTimeCounter
484{
485public:
486 VBoxVHWADbgTimeCounter(const char* msg) {mTime = VBOXGETTIME(); mMsg=msg;}
487 ~VBoxVHWADbgTimeCounter() {VBOXPRINTDIF(mTime, (mMsg));}
488private:
489 uint64_t mTime;
490 const char* mMsg;
491};
492
493#define VBOXQGLLOG_METHODTIME(_m) VBoxVHWADbgTimeCounter _dbgTimeCounter(_m)
494#else
495#define VBOXQGLLOG_METHODTIME(_m)
496#endif
497
498#define VBOXQGLLOG_QRECT(_p, _pr, _s) do{\
499 VBOXQGLLOG((_p " x(%d), y(%d), w(%d), h(%d)" _s, (_pr)->x(), (_pr)->y(), (_pr)->width(), (_pr)->height()));\
500 }while(0)
501
502#define VBOXQGLLOG_CKEY(_p, _pck, _s) do{\
503 VBOXQGLLOG((_p " l(0x%x), u(0x%x)" _s, (_pck)->lower(), (_pck)->upper()));\
504 }while(0)
505
506class VBoxVHWADirtyRect
507{
508public:
509 VBoxVHWADirtyRect() :
510 mIsClear(true)
511 {}
512
513 VBoxVHWADirtyRect(const QRect & aRect)
514 {
515 if(aRect.isEmpty())
516 {
517 mIsClear = false;
518 mRect = aRect;
519 }
520 else
521 {
522 mIsClear = true;
523 }
524 }
525
526 bool isClear() const { return mIsClear; }
527
528 void add(const QRect & aRect)
529 {
530 if(aRect.isEmpty())
531 return;
532
533 mRect = mIsClear ? aRect : mRect.united(aRect);
534 mIsClear = false;
535 }
536
537 void add(const VBoxVHWADirtyRect & aRect)
538 {
539 if(aRect.isClear())
540 return;
541 add(aRect.rect());
542 }
543
544 void set(const QRect & aRect)
545 {
546 if(aRect.isEmpty())
547 {
548 mIsClear = true;
549 }
550 else
551 {
552 mRect = aRect;
553 mIsClear = false;
554 }
555 }
556
557 void clear() { mIsClear = true; }
558
559 const QRect & rect() const {return mRect;}
560
561 bool intersects(const QRect & aRect) const {return mIsClear ? false : mRect.intersects(aRect);}
562
563 bool intersects(const VBoxVHWADirtyRect & aRect) const {return mIsClear ? false : aRect.intersects(mRect);}
564
565 QRect united(const QRect & aRect) const {return mIsClear ? aRect : aRect.united(mRect);}
566
567 bool contains(const QRect & aRect) const {return mIsClear ? false : aRect.contains(mRect);}
568
569 void subst(const VBoxVHWADirtyRect & aRect) { if(!mIsClear && aRect.contains(mRect)) clear(); }
570
571private:
572 QRect mRect;
573 bool mIsClear;
574};
575
576class VBoxVHWAColorKey
577{
578public:
579 VBoxVHWAColorKey() :
580 mUpper(0),
581 mLower(0)
582 {}
583
584 VBoxVHWAColorKey(uint32_t aUpper, uint32_t aLower) :
585 mUpper(aUpper),
586 mLower(aLower)
587 {}
588
589 uint32_t upper() const {return mUpper; }
590 uint32_t lower() const {return mLower; }
591
592 bool operator==(const VBoxVHWAColorKey & other) const { return mUpper == other.mUpper && mLower == other.mLower; }
593private:
594 uint32_t mUpper;
595 uint32_t mLower;
596};
597
598class VBoxVHWAColorComponent
599{
600public:
601 VBoxVHWAColorComponent() :
602 mMask(0),
603 mRange(0),
604 mOffset(32),
605 mcBits(0)
606 {}
607
608 VBoxVHWAColorComponent(uint32_t aMask);
609
610 uint32_t mask() const { return mMask; }
611 uint32_t range() const { return mRange; }
612 uint32_t offset() const { return mOffset; }
613 uint32_t cBits() const { return mcBits; }
614 uint32_t colorVal(uint32_t col) const { return (col & mMask) >> mOffset; }
615 float colorValNorm(uint32_t col) const { return ((float)colorVal(col))/mRange; }
616private:
617 uint32_t mMask;
618 uint32_t mRange;
619 uint32_t mOffset;
620 uint32_t mcBits;
621};
622
623class VBoxVHWAColorFormat
624{
625public:
626
627// VBoxVHWAColorFormat(GLint aInternalFormat, GLenum aFormat, GLenum aType, uint32_t aDataFormat);
628 VBoxVHWAColorFormat(uint32_t bitsPerPixel, uint32_t r, uint32_t g, uint32_t b);
629 VBoxVHWAColorFormat(uint32_t fourcc);
630 VBoxVHWAColorFormat(){}
631 GLint internalFormat() const {return mInternalFormat; }
632 GLenum format() const {return mFormat; }
633 GLenum type() const {return mType; }
634 bool isValid() const {return mBitsPerPixel != 0; }
635 uint32_t fourcc() const {return mDataFormat;}
636 uint32_t bitsPerPixel() const { return mBitsPerPixel; }
637 uint32_t bitsPerPixelTex() const { return mBitsPerPixelTex; }
638// uint32_t bitsPerPixelDd() const { return mBitsPerPixelDd; }
639 void pixel2Normalized(uint32_t pix, float *r, float *g, float *b) const;
640 uint32_t widthCompression() const {return mWidthCompression;}
641 uint32_t heightCompression() const {return mHeightCompression;}
642 const VBoxVHWAColorComponent& r() const {return mR;}
643 const VBoxVHWAColorComponent& g() const {return mG;}
644 const VBoxVHWAColorComponent& b() const {return mB;}
645 const VBoxVHWAColorComponent& a() const {return mA;}
646
647private:
648 void VBoxVHWAColorFormat::init(uint32_t bitsPerPixel, uint32_t r, uint32_t g, uint32_t b);
649 void VBoxVHWAColorFormat::init(uint32_t fourcc);
650
651 GLint mInternalFormat;
652 GLenum mFormat;
653 GLenum mType;
654 uint32_t mDataFormat;
655
656 uint32_t mBitsPerPixel;
657 uint32_t mBitsPerPixelTex;
658// uint32_t mBitsPerPixelDd;
659 uint32_t mWidthCompression;
660 uint32_t mHeightCompression;
661 VBoxVHWAColorComponent mR;
662 VBoxVHWAColorComponent mG;
663 VBoxVHWAColorComponent mB;
664 VBoxVHWAColorComponent mA;
665};
666
667class VBoxVHWATexture
668{
669public:
670 VBoxVHWATexture() {}
671 VBoxVHWATexture(const QRect * pRect, const VBoxVHWAColorFormat *pFormat);
672 virtual ~VBoxVHWATexture();
673 virtual void init(uchar *pvMem);
674 void setAddress(uchar *pvMem) {mAddress = pvMem;}
675 void update(const QRect * pRect) { doUpdate(mAddress, pRect);}
676 void bind() {glBindTexture(texTarget(), mTexture);}
677
678 virtual void texCoord(int x, int y);
679 virtual void multiTexCoord(GLenum texUnit, int x, int y);
680
681// GLuint texture() {return mTexture;}
682 const QRect & texRect() {return mTexRect;}
683 const QRect & rect() {return mRect;}
684 uchar * address(){ return mAddress; }
685 uint32_t rectSizeTex(const QRect * pRect) {return pRect->width() * pRect->height() * mBytesPerPixelTex;}
686 uchar * pointAddress(int x, int y)
687 {
688 x = toXTex(x);
689 y = toYTex(y);
690 return pointAddressTex(x, y);
691 }
692 uint32_t pointOffsetTex(int x, int y) { return y*mBytesPerLine + x*mBytesPerPixelTex; }
693 uchar * pointAddressTex(int x, int y) { return mAddress + pointOffsetTex(x, y); }
694 int toXTex(int x) {return x/mColorFormat.widthCompression();}
695 int toYTex(int y) {return y/mColorFormat.heightCompression();}
696 ulong memSize(){ return mBytesPerLine * mRect.height(); }
697 uint32_t bytesPerLine() {return mBytesPerLine; }
698
699protected:
700 virtual void doUpdate(uchar * pAddress, const QRect * pRect);
701 virtual void initParams();
702 virtual void load();
703 virtual GLenum texTarget() {return GL_TEXTURE_2D; }
704
705
706 QRect mTexRect; /* texture size */
707 QRect mRect; /* img size */
708 uchar * mAddress;
709 GLuint mTexture;
710 uint32_t mBytesPerPixel;
711 uint32_t mBytesPerPixelTex;
712 uint32_t mBytesPerLine;
713 VBoxVHWAColorFormat mColorFormat;
714private:
715 void uninit();
716};
717
718class VBoxVHWATextureNP2 : public VBoxVHWATexture
719{
720public:
721 VBoxVHWATextureNP2() : VBoxVHWATexture() {}
722 VBoxVHWATextureNP2(const QRect * pRect, const VBoxVHWAColorFormat *pFormat) :
723 VBoxVHWATexture(pRect, pFormat){
724 mTexRect = QRect(0, 0, pRect->width()/pFormat->widthCompression(), pRect->height()/pFormat->heightCompression());
725 }
726};
727
728class VBoxVHWATextureNP2Rect : public VBoxVHWATextureNP2
729{
730public:
731 VBoxVHWATextureNP2Rect() : VBoxVHWATextureNP2() {}
732 VBoxVHWATextureNP2Rect(const QRect * pRect, const VBoxVHWAColorFormat *pFormat) :
733 VBoxVHWATextureNP2(pRect, pFormat){}
734
735 virtual void texCoord(int x, int y);
736 virtual void multiTexCoord(GLenum texUnit, int x, int y);
737protected:
738 virtual GLenum texTarget();
739};
740
741class VBoxVHWATextureNP2RectPBO : public VBoxVHWATextureNP2Rect
742{
743public:
744 VBoxVHWATextureNP2RectPBO() : VBoxVHWATextureNP2Rect() {}
745 VBoxVHWATextureNP2RectPBO(const QRect * pRect, const VBoxVHWAColorFormat *pFormat) :
746 VBoxVHWATextureNP2Rect(pRect, pFormat){}
747 virtual ~VBoxVHWATextureNP2RectPBO();
748
749 virtual void init(uchar *pvMem);
750protected:
751 virtual void load();
752 virtual void doUpdate(uchar * pAddress, const QRect * pRect);
753private:
754 void updateBuffer(uchar * pBuf, const QRect * pRect);
755 GLuint mPBO;
756};
757
758/* data flow:
759 * I. NON-Yinverted surface:
760 * 1.direct memory update (paint, lock/unlock):
761 * mem->tex->fb
762 * 2.blt
763 * srcTex->invFB->tex->fb
764 * |->mem
765 *
766 * II. Yinverted surface:
767 * 1.direct memory update (paint, lock/unlock):
768 * mem->tex->fb
769 * 2.blt
770 * srcTex->fb->tex
771 * |->mem
772 *
773 * III. flip support:
774 * 1. Yinverted<->NON-YInverted conversion :
775 * mem->tex-(rotate model view, force LAZY complete fb update)->invFB->tex
776 * fb-->| |->mem
777 * */
778class VBoxVHWASurfaceBase
779{
780public:
781 VBoxVHWASurfaceBase(
782 class VBoxGLWidget *mWidget,
783#if 0
784 class VBoxVHWAGlContextState *aState,
785 bool aIsYInverted,
786#endif
787 const QSize * aSize, const QSize * aTargetSize,
788 VBoxVHWAColorFormat & aColorFormat,
789 VBoxVHWAColorKey * pSrcBltCKey, VBoxVHWAColorKey * pDstBltCKey,
790 VBoxVHWAColorKey * pSrcOverlayCKey, VBoxVHWAColorKey * pDstOverlayCKey,
791 bool bVGA);
792
793 virtual ~VBoxVHWASurfaceBase();
794
795 void init(VBoxVHWASurfaceBase * pPrimary, uchar *pvMem);
796 void setupMatricies(VBoxVHWASurfaceBase *pPrimary);
797
798 void uninit();
799
800 static void globalInit();
801
802// int blt(const QRect * aDstRect, VBoxVHWASurfaceBase * aSrtSurface, const QRect * aSrcRect, const VBoxVHWAColorKey * pDstCKeyOverride, const VBoxVHWAColorKey * pSrcCKeyOverride);
803// int overlay(VBoxVHWASurfaceBase * aOverlaySurface);
804
805 int lock(const QRect * pRect, uint32_t flags);
806
807 int unlock();
808
809 void updatedMem(const QRect * aRect);
810
811 void performDisplay(VBoxVHWASurfaceBase *pPrimary);
812
813 void setRects(VBoxVHWASurfaceBase *pPrimary, const QRect * aTargRect, const QRect * aSrcRect);
814 void setTargetRectPosition(VBoxVHWASurfaceBase *pPrimary, const QPoint * aPoint);
815
816 static ulong calcBytesPerPixel(GLenum format, GLenum type);
817
818 static GLsizei makePowerOf2(GLsizei val);
819
820 bool addressAlocated() const { return mFreeAddress; }
821 uchar * address(){ return mAddress; }
822
823 ulong memSize();
824
825 ulong width() { return mRect.width(); }
826 ulong height() { return mRect.height(); }
827
828 GLenum format() {return mColorFormat.format(); }
829 GLint internalFormat() { return mColorFormat.internalFormat(); }
830 GLenum type() { return mColorFormat.type(); }
831 uint32_t fourcc() {return mColorFormat.fourcc(); }
832
833// ulong bytesPerPixel() { return mpTex[0]->bytesPerPixel(); }
834 ulong bitsPerPixel() { return mColorFormat.bitsPerPixel(); }
835// ulong bitsPerPixelDd() { return mColorFormat.bitsPerPixelDd(); }
836 ulong bytesPerLine() { return mpTex[0]->bytesPerLine(); }
837
838 const VBoxVHWAColorKey * dstBltCKey() const { return mpDstBltCKey; }
839 const VBoxVHWAColorKey * srcBltCKey() const { return mpSrcBltCKey; }
840 const VBoxVHWAColorKey * dstOverlayCKey() const { return mpDstOverlayCKey; }
841 const VBoxVHWAColorKey * defaultSrcOverlayCKey() const { return mpDefaultSrcOverlayCKey; }
842 const VBoxVHWAColorKey * defaultDstOverlayCKey() const { return mpDefaultDstOverlayCKey; }
843 const VBoxVHWAColorKey * srcOverlayCKey() const { return mpSrcOverlayCKey; }
844 void resetDefaultSrcOverlayCKey() { mpSrcOverlayCKey = mpDefaultSrcOverlayCKey; }
845 void resetDefaultDstOverlayCKey() { mpDstOverlayCKey = mpDefaultDstOverlayCKey; }
846
847 void setDstBltCKey(const VBoxVHWAColorKey * ckey)
848 {
849 if(ckey)
850 {
851 mDstBltCKey = *ckey;
852 mpDstBltCKey = &mDstBltCKey;
853 }
854 else
855 {
856 mpDstBltCKey = NULL;
857 }
858 }
859
860 void setSrcBltCKey(const VBoxVHWAColorKey * ckey)
861 {
862 if(ckey)
863 {
864 mSrcBltCKey = *ckey;
865 mpSrcBltCKey = &mSrcBltCKey;
866 }
867 else
868 {
869 mpSrcBltCKey = NULL;
870 }
871 }
872
873 void setDefaultDstOverlayCKey(const VBoxVHWAColorKey * ckey)
874 {
875 if(ckey)
876 {
877 mDefaultDstOverlayCKey = *ckey;
878 mpDefaultDstOverlayCKey = &mDefaultDstOverlayCKey;
879 }
880 else
881 {
882 mpDefaultDstOverlayCKey = NULL;
883 }
884 }
885
886 void setDefaultSrcOverlayCKey(const VBoxVHWAColorKey * ckey)
887 {
888 if(ckey)
889 {
890 mDefaultSrcOverlayCKey = *ckey;
891 mpDefaultSrcOverlayCKey = &mDefaultSrcOverlayCKey;
892 }
893 else
894 {
895 mpDefaultSrcOverlayCKey = NULL;
896 }
897 }
898
899 void setOverriddenDstOverlayCKey(const VBoxVHWAColorKey * ckey)
900 {
901 if(ckey)
902 {
903 mOverriddenDstOverlayCKey = *ckey;
904 mpDstOverlayCKey = &mOverriddenDstOverlayCKey;
905 }
906 else
907 {
908 mpDstOverlayCKey = NULL;
909 }
910 }
911
912 void setOverriddenSrcOverlayCKey(const VBoxVHWAColorKey * ckey)
913 {
914 if(ckey)
915 {
916 mOverriddenSrcOverlayCKey = *ckey;
917 mpSrcOverlayCKey = &mOverriddenSrcOverlayCKey;
918 }
919 else
920 {
921 mpSrcOverlayCKey = NULL;
922 }
923 }
924
925 const VBoxVHWAColorKey * getActiveSrcOverlayCKey()
926 {
927 return mpSrcOverlayCKey;
928 }
929
930 const VBoxVHWAColorKey * getActiveDstOverlayCKey(VBoxVHWASurfaceBase * pPrimary)
931 {
932 return mpDstOverlayCKey ? mpDefaultDstOverlayCKey : pPrimary->mpDstOverlayCKey;
933 }
934
935 const VBoxVHWAColorFormat & colorFormat() {return mColorFormat; }
936
937 /* clients should treat the returned texture as read-only */
938// GLuint textureSynched(const QRect * aRect) { /*synchTex(aRect); */synchTexMem(aRect); return mTexture; }
939
940 void setAddress(uchar * addr);
941
942 const QRect& rect() {return mRect;}
943// const QRect& texRect() {return mTexRect;}
944
945// /* surface currently being displayed in a flip chain */
946// virtual bool isPrimary() = 0;
947// /* surface representing the main framebuffer. */
948// virtual bool isMainFramebuffer() = 0;
949#if 0
950 virtual void makeCurrent() = 0;
951 virtual void makeYInvertedCurrent() = 0;
952 bool isYInverted() {return mIsYInverted; }
953
954 bool isHidden() {return mIsYInverted; }
955 void setHidden(bool hidden)
956 {
957 if(hidden == mIsYInverted)
958 return;
959
960 invert();
961 }
962 int invert();
963
964 bool isFrontBuffer() {return !mIsYInverted; }
965#endif
966
967 class VBoxVHWASurfList * getComplexList() {return mComplexList; }
968
969 class VBoxVHWAGlProgramMngr * getGlProgramMngr();
970 static int setCKey(class VBoxVHWAGlProgramVHWA * pProgram, const VBoxVHWAColorFormat * pFormat, const VBoxVHWAColorKey * pCKey, bool bDst);
971private:
972 void setComplexList(VBoxVHWASurfList *aComplexList) { mComplexList = aComplexList; }
973 void initDisplay(VBoxVHWASurfaceBase *pPrimary);
974 void deleteDisplay();
975// void initDisplay(bool bInverted);
976// void deleteDisplay(bool bInverted);
977 GLuint createDisplay(VBoxVHWASurfaceBase *pPrimary
978#if 0
979 bool bInverted
980#endif
981 );
982 void doDisplay(VBoxVHWASurfaceBase *pPrimary, VBoxVHWAGlProgramVHWA * pProgram, bool bBindDst);
983 void synchTexMem(const QRect * aRect);
984#if 0
985 void synchTex(const QRect * aRect);
986 void synchTexFB(const QRect * aRect);
987 void synchMem(const QRect * aRect);
988 void synchFB(const QRect * aRect);
989 void synch(const QRect * aRect);
990#endif
991 int performBlt(const QRect * pDstRect, VBoxVHWASurfaceBase * pSrcSurface, const QRect * pSrcRect, const VBoxVHWAColorKey * pDstCKey, const VBoxVHWAColorKey * pSrcCKey, bool blt);
992
993// void doTex2FB(const QRect * aRect);
994 void doTex2FB(const QRect * pDstRect, const QRect * pSrcRect);
995 void doMultiTex2FB(const QRect * pDstRect, VBoxVHWATexture * pDstTex, const QRect * pSrcRect, int cSrcTex);
996 void doMultiTex2FB(const QRect * pDstRect, const QRect * pSrcRect, int cSrcTex);
997// void doMultiTex2FB(GLenum tex, const QRect * pDstRect, const QRect * pSrcRect);
998
999 void doSetupMatrix(const QSize * pSize , bool bInverted);
1000
1001 QRect mRect; /* == Inv FB size */
1002// QRect mTexRect; /* texture size */
1003
1004 QRect mSrcRect;
1005 QRect mTargRect; /* == Vis FB size */
1006 QRect mTargSize;
1007#if 0
1008 GLuint mYInvertedDisplay;
1009#endif
1010 GLuint mVisibleDisplay;
1011#if 0
1012 bool mYInvertedDisplayInitialized;
1013#endif
1014 bool mVisibleDisplayInitialized;
1015
1016 uchar * mAddress;
1017 VBoxVHWATexture *mpTex[3];
1018
1019 VBoxVHWAColorFormat mColorFormat;
1020
1021 VBoxVHWAColorKey *mpSrcBltCKey;
1022 VBoxVHWAColorKey *mpDstBltCKey;
1023 VBoxVHWAColorKey *mpSrcOverlayCKey;
1024 VBoxVHWAColorKey *mpDstOverlayCKey;
1025
1026 VBoxVHWAColorKey *mpDefaultDstOverlayCKey;
1027 VBoxVHWAColorKey *mpDefaultSrcOverlayCKey;
1028
1029 VBoxVHWAColorKey mSrcBltCKey;
1030 VBoxVHWAColorKey mDstBltCKey;
1031 VBoxVHWAColorKey mOverriddenSrcOverlayCKey;
1032 VBoxVHWAColorKey mOverriddenDstOverlayCKey;
1033 VBoxVHWAColorKey mDefaultDstOverlayCKey;
1034 VBoxVHWAColorKey mDefaultSrcOverlayCKey;
1035
1036 int mLockCount;
1037 /* memory buffer not reflected in fm and texture, e.g if memory buffer is replaced or in case of lock/unlock */
1038 VBoxVHWADirtyRect mUpdateMem2TexRect;
1039#if 0
1040 /* memory buffer not reflected in fm and texture, e.g if memory buffer is replaced or in case of lock/unlock */
1041 VBoxVHWADirtyRect mUpdateTex2FBRect;
1042 /*in case of blit we blit from another surface's texture, so our current texture gets durty */
1043 VBoxVHWADirtyRect mUpdateFB2TexRect;
1044 /*in case of blit the memory buffer does not get updated until we need it, e.g. for paint or lock operations */
1045 VBoxVHWADirtyRect mUpdateFB2MemRect;
1046#endif
1047
1048 bool mFreeAddress;
1049#if 0
1050 bool mIsYInverted;
1051#endif
1052
1053 class VBoxVHWASurfList *mComplexList;
1054
1055 class VBoxGLWidget *mWidget;
1056
1057protected:
1058#if 0
1059 virtual void init(uchar *pvMem, bool bInverted);
1060 class VBoxVHWAGlContextState *mState;
1061#endif
1062
1063 friend class VBoxVHWASurfList;
1064#ifdef DEBUG
1065public:
1066 uint64_t cFlipsCurr;
1067 uint64_t cFlipsTarg;
1068#endif
1069};
1070
1071typedef std::list <VBoxVHWASurfaceBase*> SurfList;
1072typedef std::list <VBoxVHWASurfList*> OverlayList;
1073
1074class VBoxVHWASurfList
1075{
1076public:
1077
1078 VBoxVHWASurfList() : mCurrent(NULL) {}
1079 void add(VBoxVHWASurfaceBase *pSurf)
1080 {
1081 VBoxVHWASurfList * pOld = pSurf->getComplexList();
1082 if(pOld)
1083 {
1084 pOld->remove(pSurf);
1085 }
1086 mSurfaces.push_back(pSurf);
1087 pSurf->setComplexList(this);
1088 }
1089
1090 void clear()
1091 {
1092 for (SurfList::iterator it = mSurfaces.begin();
1093 it != mSurfaces.end(); ++ it)
1094 {
1095 (*it)->setComplexList(NULL);
1096 }
1097 mSurfaces.clear();
1098 mCurrent = NULL;
1099 }
1100
1101 void remove(VBoxVHWASurfaceBase *pSurf)
1102 {
1103 mSurfaces.remove(pSurf);
1104 pSurf->setComplexList(NULL);
1105 if(mCurrent == pSurf)
1106 mCurrent = NULL;
1107 }
1108
1109 bool empty() { return mSurfaces.empty(); }
1110
1111 void setCurrentVisible(VBoxVHWASurfaceBase *pSurf)
1112 {
1113 mCurrent = pSurf;
1114 }
1115
1116 VBoxVHWASurfaceBase * current() { return mCurrent; }
1117 const SurfList & surfaces() const {return mSurfaces;}
1118
1119private:
1120
1121 SurfList mSurfaces;
1122 VBoxVHWASurfaceBase* mCurrent;
1123};
1124
1125class VBoxVHWADisplay
1126{
1127public:
1128 VBoxVHWADisplay() :
1129 mSurfVGA(NULL)
1130// ,
1131// mSurfPrimary(NULL)
1132 {}
1133
1134 VBoxVHWASurfaceBase * setVGA(VBoxVHWASurfaceBase * pVga)
1135 {
1136 VBoxVHWASurfaceBase * old = mSurfVGA;
1137 mSurfVGA = pVga;
1138 mPrimary.clear();
1139 if(pVga)
1140 {
1141 mPrimary.add(pVga);
1142 mPrimary.setCurrentVisible(pVga);
1143 }
1144// mSurfPrimary = pVga;
1145 mOverlays.clear();
1146 return old;
1147 }
1148
1149 VBoxVHWASurfaceBase * getVGA()
1150 {
1151 return mSurfVGA;
1152 }
1153
1154 VBoxVHWASurfaceBase * getPrimary()
1155 {
1156 return mPrimary.current();
1157 }
1158//
1159// void setPrimary(VBoxVHWASurfList * pSurf)
1160// {
1161// mSurfPrimary = pSurf;
1162// }
1163
1164 void addOverlay(VBoxVHWASurfList * pSurf)
1165 {
1166 mOverlays.push_back(pSurf);
1167 }
1168
1169 void checkAddOverlay(VBoxVHWASurfList * pSurf)
1170 {
1171 if(!hasOverlay(pSurf))
1172 addOverlay(pSurf);
1173 }
1174
1175 bool hasOverlay(VBoxVHWASurfList * pSurf)
1176 {
1177 for (OverlayList::iterator it = mOverlays.begin();
1178 it != mOverlays.end(); ++ it)
1179 {
1180 if((*it) == pSurf)
1181 {
1182 return true;
1183 }
1184 }
1185 return false;
1186 }
1187
1188 void removeOverlay(VBoxVHWASurfList * pSurf)
1189 {
1190 mOverlays.remove(pSurf);
1191 }
1192
1193 void performDisplay()
1194 {
1195 VBoxVHWASurfaceBase * pPrimary = mPrimary.current();
1196 pPrimary->performDisplay(NULL);
1197
1198 for (OverlayList::const_iterator it = mOverlays.begin();
1199 it != mOverlays.end(); ++ it)
1200 {
1201 VBoxVHWASurfaceBase * pOverlay = (*it)->current();
1202 if(pOverlay)
1203 {
1204 pOverlay->performDisplay(pPrimary);
1205 }
1206 }
1207 }
1208
1209 const OverlayList & overlays() const {return mOverlays;}
1210
1211private:
1212 VBoxVHWASurfaceBase *mSurfVGA;
1213 VBoxVHWASurfList mPrimary;
1214
1215 OverlayList mOverlays;
1216};
1217
1218class VBoxGLWidget : public QGLWidget
1219{
1220public:
1221 VBoxGLWidget (VBoxConsoleView *aView, QWidget *aParent);
1222 ~VBoxGLWidget();
1223
1224 ulong vboxPixelFormat() { return mPixelFormat; }
1225 bool vboxUsesGuestVRAM() { return mUsesGuestVRAM; }
1226
1227 uchar *vboxAddress() { return mDisplay.getVGA() ? mDisplay.getVGA()->address() : NULL; }
1228
1229#ifdef VBOX_WITH_VIDEOHWACCEL
1230 uchar *vboxVRAMAddressFromOffset(uint64_t offset);
1231
1232 void vhwaSaveExec(struct SSMHANDLE * pSSM);
1233 int vhwaLoadExec(struct SSMHANDLE * pSSM, uint32_t u32Version);
1234#endif
1235
1236 ulong vboxBitsPerPixel() { return mDisplay.getVGA()->bitsPerPixel(); }
1237 ulong vboxBytesPerLine() { return mDisplay.getVGA() ? mDisplay.getVGA()->bytesPerLine() : NULL; }
1238
1239typedef void (VBoxGLWidget::*PFNVBOXQGLOP)(void* );
1240
1241 void vboxPaintEvent (QPaintEvent *pe) {vboxPerformGLOp(&VBoxGLWidget::vboxDoPaint, pe);}
1242 void vboxResizeEvent (VBoxResizeEvent *re) {vboxPerformGLOp(&VBoxGLWidget::vboxDoResize, re);}
1243
1244 void vboxProcessVHWACommands(VBoxVHWACommandProcessEvent * pEvent) {vboxPerformGLOp(&VBoxGLWidget::vboxDoProcessVHWACommands, pEvent);}
1245#ifdef VBOX_WITH_VIDEOHWACCEL
1246 void vboxVHWACmd (struct _VBOXVHWACMD * pCmd) {vboxPerformGLOp(&VBoxGLWidget::vboxDoVHWACmd, pCmd);}
1247#endif
1248 class VBoxVHWAGlProgramMngr * vboxVHWAGetGlProgramMngr() { return mpMngr; }
1249
1250 VBoxVHWASurfaceBase * vboxGetVGASurface() { return mDisplay.getVGA(); }
1251
1252 void postCmd(VBOXVHWA_PIPECMD_TYPE aType, void * pvData);
1253protected:
1254
1255 void paintGL()
1256 {
1257 if(mpfnOp)
1258 {
1259 (this->*mpfnOp)(mOpContext);
1260 mpfnOp = NULL;
1261 }
1262 else
1263 {
1264 mDisplay.performDisplay();
1265 }
1266 }
1267
1268 void initializeGL();
1269private:
1270 void vboxDoResize(void *re);
1271 void vboxDoPaint(void *rec);
1272
1273 void vboxDoUpdateRect(const QRect * pRect);
1274#ifdef VBOXQGL_DBG_SURF
1275 void vboxDoTestSurfaces(void *context);
1276#endif
1277#ifdef VBOX_WITH_VIDEOHWACCEL
1278 void vboxDoVHWACmd(void *cmd);
1279 void vboxCheckUpdateAddress (VBoxVHWASurfaceBase * pSurface, uint64_t offset)
1280 {
1281#ifndef VBOXQGL_DBG_SURF
1282 if(offset == 0xffffffffffffffffL)
1283 {
1284 return;
1285 }
1286#endif
1287 if (pSurface->addressAlocated())
1288 {
1289 uchar * addr = vboxVRAMAddressFromOffset(offset);
1290 if(addr)
1291 {
1292 pSurface->setAddress(addr);
1293 }
1294 }
1295 }
1296 int vhwaSurfaceCanCreate(struct _VBOXVHWACMD_SURF_CANCREATE *pCmd);
1297 int vhwaSurfaceCreate(struct _VBOXVHWACMD_SURF_CREATE *pCmd);
1298 int vhwaSurfaceDestroy(struct _VBOXVHWACMD_SURF_DESTROY *pCmd);
1299 int vhwaSurfaceLock(struct _VBOXVHWACMD_SURF_LOCK *pCmd);
1300 int vhwaSurfaceUnlock(struct _VBOXVHWACMD_SURF_UNLOCK *pCmd);
1301 int vhwaSurfaceBlt(struct _VBOXVHWACMD_SURF_BLT *pCmd);
1302 int vhwaSurfaceFlip(struct _VBOXVHWACMD_SURF_FLIP *pCmd);
1303 int vhwaSurfaceOverlayUpdate(struct _VBOXVHWACMD_SURF_OVERLAY_UPDATE *pCmf);
1304 int vhwaSurfaceOverlaySetPosition(struct _VBOXVHWACMD_SURF_OVERLAY_SETPOSITION *pCmd);
1305 int vhwaSurfaceColorkeySet(struct _VBOXVHWACMD_SURF_COLORKEY_SET *pCmd);
1306 int vhwaQueryInfo1(struct _VBOXVHWACMD_QUERYINFO1 *pCmd);
1307 int vhwaQueryInfo2(struct _VBOXVHWACMD_QUERYINFO2 *pCmd);
1308 int vhwaConstruct(struct _VBOXVHWACMD_HH_CONSTRUCT *pCmd);
1309
1310 int vhwaSaveSurface(struct SSMHANDLE * pSSM, VBoxVHWASurfaceBase *pSurf, uint32_t surfCaps);
1311 int vhwaLoadSurface(struct SSMHANDLE * pSSM, uint32_t u32Version);
1312 int vhwaSaveOverlayData(struct SSMHANDLE * pSSM, VBoxVHWASurfaceBase *pSurf);
1313 int vhwaLoadOverlayData(struct SSMHANDLE * pSSM, uint32_t u32Version);
1314
1315 void vhwaDoSurfaceOverlayUpdate(VBoxVHWASurfaceBase *pDstSurf, VBoxVHWASurfaceBase *pSrcSurf, struct _VBOXVHWACMD_SURF_OVERLAY_UPDATE *pCmd);
1316#endif
1317 static const QGLFormat & vboxGLFormat();
1318
1319 VBoxVHWADisplay mDisplay;
1320
1321
1322 /* we do all opengl stuff in the paintGL context,
1323 * submit the operation to be performed
1324 * @todo: could be moved outside the updateGL */
1325 void vboxPerformGLOp(PFNVBOXQGLOP pfn, void* pContext) {mpfnOp = pfn; mOpContext = pContext; updateGL();}
1326
1327 void cmdPipeInit();
1328 void cmdPipeDelete();
1329 void vboxDoProcessVHWACommands(void *pContext);
1330
1331 VBoxVHWACommandElement * detachCmdList(VBoxVHWACommandElement * pFirst2Free, VBoxVHWACommandElement * pLast2Free);
1332 VBoxVHWACommandElement * processCmdList(VBoxVHWACommandElement * pCmd);
1333
1334 PFNVBOXQGLOP mpfnOp;
1335 void *mOpContext;
1336
1337 ulong mPixelFormat;
1338 bool mUsesGuestVRAM;
1339 bool mVGASurfCreated;
1340
1341 RTCRITSECT mCritSect;
1342 VBoxVHWACommandProcessEvent *mpFirstEvent;
1343 VBoxVHWACommandProcessEvent *mpLastEvent;
1344 bool mbNewEvent;
1345 VBoxVHWACommandElementStack mFreeElements;
1346 VBoxVHWACommandElement mElementsBuffer[2048];
1347
1348 VBoxConsoleView *mView;
1349
1350 VBoxVHWASurfList *mConstructingList;
1351 int32_t mcRemaining2Contruct;
1352
1353 class VBoxVHWAGlProgramMngr *mpMngr;
1354};
1355
1356
1357class VBoxQGLFrameBuffer : public VBoxFrameBuffer
1358{
1359public:
1360
1361 VBoxQGLFrameBuffer (VBoxConsoleView *aView);
1362
1363 STDMETHOD(NotifyUpdate) (ULONG aX, ULONG aY,
1364 ULONG aW, ULONG aH);
1365#ifdef VBOXQGL_PROF_BASE
1366 STDMETHOD(RequestResize) (ULONG aScreenId, ULONG aPixelFormat,
1367 BYTE *aVRAM, ULONG aBitsPerPixel, ULONG aBytesPerLine,
1368 ULONG aWidth, ULONG aHeight,
1369 BOOL *aFinished);
1370#endif
1371
1372#ifdef VBOX_WITH_VIDEOHWACCEL
1373 STDMETHOD(ProcessVHWACommand)(BYTE *pCommand);
1374
1375
1376 static bool isAcceleration2DVideoAvailable();
1377#endif
1378
1379 ulong pixelFormat() { return vboxWidget()->vboxPixelFormat(); }
1380 bool usesGuestVRAM() { return vboxWidget()->vboxUsesGuestVRAM(); }
1381
1382 uchar *address() { return vboxWidget()->vboxAddress(); }
1383 ulong bitsPerPixel() { return vboxWidget()->vboxBitsPerPixel(); }
1384 ulong bytesPerLine() { return vboxWidget()->vboxBytesPerLine(); }
1385
1386 void paintEvent (QPaintEvent *pe);
1387 void resizeEvent (VBoxResizeEvent *re);
1388 void doProcessVHWACommand(VBoxVHWACommandProcessEvent * pEvent);
1389
1390private:
1391// void vboxMakeCurrent();
1392 VBoxGLWidget * vboxWidget();
1393};
1394
1395
1396#endif
1397
1398/////////////////////////////////////////////////////////////////////////////
1399
1400#if defined (VBOX_GUI_USE_SDL)
1401
1402class VBoxSDLFrameBuffer : public VBoxFrameBuffer
1403{
1404public:
1405
1406 VBoxSDLFrameBuffer (VBoxConsoleView *aView);
1407 virtual ~VBoxSDLFrameBuffer();
1408
1409 STDMETHOD(NotifyUpdate) (ULONG aX, ULONG aY,
1410 ULONG aW, ULONG aH);
1411
1412 uchar *address()
1413 {
1414 SDL_Surface *surf = mSurfVRAM ? mSurfVRAM : mScreen;
1415 return surf ? (uchar *) (uintptr_t) surf->pixels : 0;
1416 }
1417
1418 ulong bitsPerPixel()
1419 {
1420 SDL_Surface *surf = mSurfVRAM ? mSurfVRAM : mScreen;
1421 return surf ? surf->format->BitsPerPixel : 0;
1422 }
1423
1424 ulong bytesPerLine()
1425 {
1426 SDL_Surface *surf = mSurfVRAM ? mSurfVRAM : mScreen;
1427 return surf ? surf->pitch : 0;
1428 }
1429
1430 ulong pixelFormat()
1431 {
1432 return mPixelFormat;
1433 }
1434
1435 bool usesGuestVRAM()
1436 {
1437 return mSurfVRAM != NULL;
1438 }
1439
1440 void paintEvent (QPaintEvent *pe);
1441 void resizeEvent (VBoxResizeEvent *re);
1442
1443private:
1444
1445 SDL_Surface *mScreen;
1446 SDL_Surface *mSurfVRAM;
1447
1448 ulong mPixelFormat;
1449};
1450
1451#endif
1452
1453/////////////////////////////////////////////////////////////////////////////
1454
1455#if defined (VBOX_GUI_USE_DDRAW)
1456
1457class VBoxDDRAWFrameBuffer : public VBoxFrameBuffer
1458{
1459public:
1460
1461 VBoxDDRAWFrameBuffer (VBoxConsoleView *aView);
1462 virtual ~VBoxDDRAWFrameBuffer();
1463
1464 STDMETHOD(NotifyUpdate) (ULONG aX, ULONG aY,
1465 ULONG aW, ULONG aH);
1466
1467 uchar *address() { return (uchar *) mSurfaceDesc.lpSurface; }
1468 ulong bitsPerPixel() { return mSurfaceDesc.ddpfPixelFormat.dwRGBBitCount; }
1469 ulong bytesPerLine() { return (ulong) mSurfaceDesc.lPitch; }
1470
1471 ulong pixelFormat() { return mPixelFormat; };
1472
1473 bool usesGuestVRAM() { return mUsesGuestVRAM; }
1474
1475 void paintEvent (QPaintEvent *pe);
1476 void resizeEvent (VBoxResizeEvent *re);
1477 void moveEvent (QMoveEvent *me);
1478
1479private:
1480
1481 void releaseObjects();
1482
1483 bool createSurface (ULONG aPixelFormat, uchar *pvVRAM,
1484 ULONG aBitsPerPixel, ULONG aBytesPerLine,
1485 ULONG aWidth, ULONG aHeight);
1486 void deleteSurface();
1487 void drawRect (ULONG x, ULONG y, ULONG w, ULONG h);
1488 void getWindowPosition (void);
1489
1490 LPDIRECTDRAW7 mDDRAW;
1491 LPDIRECTDRAWCLIPPER mClipper;
1492 LPDIRECTDRAWSURFACE7 mSurface;
1493 DDSURFACEDESC2 mSurfaceDesc;
1494 LPDIRECTDRAWSURFACE7 mPrimarySurface;
1495
1496 ulong mPixelFormat;
1497
1498 bool mUsesGuestVRAM;
1499
1500 int mWndX;
1501 int mWndY;
1502
1503 bool mSynchronousUpdates;
1504};
1505
1506#endif
1507
1508/////////////////////////////////////////////////////////////////////////////
1509
1510#if defined (Q_WS_MAC) && defined (VBOX_GUI_USE_QUARTZ2D)
1511
1512#include <Carbon/Carbon.h>
1513
1514class VBoxQuartz2DFrameBuffer : public VBoxFrameBuffer
1515{
1516public:
1517
1518 VBoxQuartz2DFrameBuffer (VBoxConsoleView *aView);
1519 virtual ~VBoxQuartz2DFrameBuffer ();
1520
1521 STDMETHOD (NotifyUpdate) (ULONG aX, ULONG aY,
1522 ULONG aW, ULONG aH);
1523 STDMETHOD (SetVisibleRegion) (BYTE *aRectangles, ULONG aCount);
1524
1525 uchar *address() { return mDataAddress; }
1526 ulong bitsPerPixel() { return CGImageGetBitsPerPixel (mImage); }
1527 ulong bytesPerLine() { return CGImageGetBytesPerRow (mImage); }
1528 ulong pixelFormat() { return mPixelFormat; };
1529 bool usesGuestVRAM() { return mBitmapData == NULL; }
1530
1531 const CGImageRef imageRef() const { return mImage; }
1532
1533 void paintEvent (QPaintEvent *pe);
1534 void resizeEvent (VBoxResizeEvent *re);
1535
1536private:
1537
1538 void clean();
1539
1540 uchar *mDataAddress;
1541 void *mBitmapData;
1542 ulong mPixelFormat;
1543 CGImageRef mImage;
1544 typedef struct
1545 {
1546 /** The size of this structure expressed in rcts entries. */
1547 ULONG allocated;
1548 /** The number of entries in the rcts array. */
1549 ULONG used;
1550 /** Variable sized array of the rectangle that makes up the region. */
1551 CGRect rcts[1];
1552 } RegionRects;
1553 /** The current valid region, all access is by atomic cmpxchg or atomic xchg.
1554 *
1555 * The protocol for updating and using this has to take into account that
1556 * the producer (SetVisibleRegion) and consumer (paintEvent) are running
1557 * on different threads. Therefore the producer will create a new RegionRects
1558 * structure before atomically replace the existing one. While the consumer
1559 * will read the value by atomically replace it by NULL, and then when its
1560 * done try restore it by cmpxchg. If the producer has already put a new
1561 * region there, it will be discarded (see mRegionUnused).
1562 */
1563 RegionRects volatile *mRegion;
1564 /** For keeping the unused region and thus avoid some RTMemAlloc/RTMemFree calls.
1565 * This is operated with atomic cmpxchg and atomic xchg. */
1566 RegionRects volatile *mRegionUnused;
1567};
1568
1569#endif /* Q_WS_MAC && VBOX_GUI_USE_QUARTZ2D */
1570
1571#endif // !___VBoxFrameBuffer_h___
Note: See TracBrowser for help on using the repository browser.

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