VirtualBox

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

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

video hw accel: more saved state support

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 43.3 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.215389.xyz. 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 VBOXVHWA_PIPECMD_OP,
126}VBOXVHWA_PIPECMD_TYPE;
127
128typedef DECLCALLBACK(void) FNVBOXVHWACALLBACK(void * pContext);
129typedef FNVBOXVHWACALLBACK *PFNVBOXVHWACALLBACK;
130
131typedef struct VBOXVHWACALLBACKINFO
132{
133 PFNVBOXVHWACALLBACK pfnCallback;
134 void * pContext;
135}VBOXVHWACALLBACKINFO;
136class VBoxVHWACommandElement
137{
138public:
139 void setVHWACmd(struct _VBOXVHWACMD * pCmd)
140 {
141 mType = VBOXVHWA_PIPECMD_VHWA;
142 u.mpCmd = pCmd;
143 }
144
145 void setPaintCmd(const QRect & aRect)
146 {
147 mType = VBOXVHWA_PIPECMD_PAINT;
148 mRect = aRect;
149 }
150
151 void setOp(const VBOXVHWACALLBACKINFO & aOp)
152 {
153 mType = VBOXVHWA_PIPECMD_OP;
154 u.mCallback = aOp;
155 }
156
157 void setData(VBOXVHWA_PIPECMD_TYPE aType, void * pvData)
158 {
159 switch(aType)
160 {
161 case VBOXVHWA_PIPECMD_PAINT:
162 setPaintCmd(*((QRect*)pvData));
163 break;
164 case VBOXVHWA_PIPECMD_VHWA:
165 setVHWACmd((struct _VBOXVHWACMD *)pvData);
166 break;
167 case VBOXVHWA_PIPECMD_OP:
168 setOp(*((VBOXVHWACALLBACKINFO *)pvData));
169 break;
170 default:
171 Assert(0);
172 break;
173 }
174 }
175
176 VBOXVHWA_PIPECMD_TYPE type() const {return mType;}
177 const QRect & rect() const {return mRect;}
178 struct _VBOXVHWACMD * vhwaCmd() const {return u.mpCmd;}
179
180private:
181 VBoxVHWACommandElement * mpNext;
182 VBOXVHWA_PIPECMD_TYPE mType;
183 union
184 {
185 struct _VBOXVHWACMD * mpCmd;
186 VBOXVHWACALLBACKINFO mCallback;
187 }u;
188 QRect mRect;
189
190 friend class VBoxVHWACommandElementPipe;
191 friend class VBoxVHWACommandElementStack;
192 friend class VBoxGLWidget;
193};
194
195class VBoxVHWACommandElementPipe
196{
197public:
198 VBoxVHWACommandElementPipe() :
199 mpFirst(NULL),
200 mpLast(NULL)
201 {}
202
203 void put(VBoxVHWACommandElement *pCmd)
204 {
205 if(mpLast)
206 {
207 Assert(mpFirst);
208 mpLast->mpNext = pCmd;
209 mpLast = pCmd;
210 }
211 else
212 {
213 Assert(!mpFirst);
214 mpFirst = pCmd;
215 mpLast = pCmd;
216 }
217 pCmd->mpNext= NULL;
218
219 }
220
221 VBoxVHWACommandElement * detachList()
222 {
223 if(mpLast)
224 {
225 VBoxVHWACommandElement * pHead = mpFirst;
226 mpFirst = NULL;
227 mpLast = NULL;
228 return pHead;
229 }
230 return NULL;
231 }
232private:
233 VBoxVHWACommandElement *mpFirst;
234 VBoxVHWACommandElement *mpLast;
235};
236
237class VBoxVHWACommandElementStack
238{
239public:
240 VBoxVHWACommandElementStack() :
241 mpFirst(NULL) {}
242
243 void push(VBoxVHWACommandElement *pCmd)
244 {
245 pCmd->mpNext = mpFirst;
246 mpFirst = pCmd;
247 }
248
249 void pusha(VBoxVHWACommandElement *pFirst, VBoxVHWACommandElement *pLast)
250 {
251 pLast->mpNext = mpFirst;
252 mpFirst = pFirst;
253 }
254
255 VBoxVHWACommandElement * pop()
256 {
257 if(mpFirst)
258 {
259 VBoxVHWACommandElement * ret = mpFirst;
260 mpFirst = ret->mpNext;
261 return ret;
262 }
263 return NULL;
264 }
265private:
266 VBoxVHWACommandElement *mpFirst;
267};
268
269class VBoxVHWACommandProcessEvent : public QEvent
270{
271public:
272 VBoxVHWACommandProcessEvent (VBoxVHWACommandElement *pEl)
273 : QEvent ((QEvent::Type) VBoxDefs::VHWACommandProcessType)
274 {
275 mCmdPipe.put(pEl);
276 }
277 VBoxVHWACommandElementPipe & pipe() { return mCmdPipe; }
278private:
279 VBoxVHWACommandElementPipe mCmdPipe;
280 VBoxVHWACommandProcessEvent *mpNext;
281
282 friend class VBoxGLWidget;
283};
284
285#endif
286
287/////////////////////////////////////////////////////////////////////////////
288
289/**
290 * Common IFramebuffer implementation for all methods used by GUI to maintain
291 * the VM display video memory.
292 *
293 * Note that although this class can be called from multiple threads
294 * (in particular, the GUI thread and EMT) it doesn't protect access to every
295 * data field using its mutex lock. This is because all synchronization between
296 * the GUI and the EMT thread is supposed to be done using the
297 * IFramebuffer::NotifyUpdate() and IFramebuffer::RequestResize() methods
298 * (in particular, the \a aFinished parameter of these methods is responsible
299 * for the synchronization). These methods are always called on EMT and
300 * therefore always follow one another but never in parallel.
301 *
302 * Using this object's mutex lock (exposed also in IFramebuffer::Lock() and
303 * IFramebuffer::Unlock() implementations) usually makes sense only if some
304 * third-party thread (i.e. other than GUI or EMT) needs to make sure that
305 * *no* VM display update or resize event can occur while it is accessing
306 * IFramebuffer properties or the underlying display memory storage area.
307 *
308 * See IFramebuffer documentation for more info.
309 */
310
311class VBoxFrameBuffer : VBOX_SCRIPTABLE_IMPL(IFramebuffer)
312{
313public:
314
315 VBoxFrameBuffer (VBoxConsoleView *aView);
316 virtual ~VBoxFrameBuffer();
317
318 NS_DECL_ISUPPORTS
319
320#if defined (Q_OS_WIN32)
321
322 STDMETHOD_(ULONG, AddRef)()
323 {
324 return ::InterlockedIncrement (&refcnt);
325 }
326
327 STDMETHOD_(ULONG, Release)()
328 {
329 long cnt = ::InterlockedDecrement (&refcnt);
330 if (cnt == 0)
331 delete this;
332 return cnt;
333 }
334#endif
335 VBOX_SCRIPTABLE_DISPATCH_IMPL(IFramebuffer)
336
337 // IFramebuffer COM methods
338 STDMETHOD(COMGETTER(Address)) (BYTE **aAddress);
339 STDMETHOD(COMGETTER(Width)) (ULONG *aWidth);
340 STDMETHOD(COMGETTER(Height)) (ULONG *aHeight);
341 STDMETHOD(COMGETTER(BitsPerPixel)) (ULONG *aBitsPerPixel);
342 STDMETHOD(COMGETTER(BytesPerLine)) (ULONG *aBytesPerLine);
343 STDMETHOD(COMGETTER(PixelFormat)) (ULONG *aPixelFormat);
344 STDMETHOD(COMGETTER(UsesGuestVRAM)) (BOOL *aUsesGuestVRAM);
345 STDMETHOD(COMGETTER(HeightReduction)) (ULONG *aHeightReduction);
346 STDMETHOD(COMGETTER(Overlay)) (IFramebufferOverlay **aOverlay);
347 STDMETHOD(COMGETTER(WinId)) (ULONG64 *winId);
348
349 STDMETHOD(Lock)();
350 STDMETHOD(Unlock)();
351
352 STDMETHOD(RequestResize) (ULONG aScreenId, ULONG aPixelFormat,
353 BYTE *aVRAM, ULONG aBitsPerPixel, ULONG aBytesPerLine,
354 ULONG aWidth, ULONG aHeight,
355 BOOL *aFinished);
356
357 STDMETHOD(VideoModeSupported) (ULONG aWidth, ULONG aHeight, ULONG aBPP,
358 BOOL *aSupported);
359
360 STDMETHOD(GetVisibleRegion)(BYTE *aRectangles, ULONG aCount, ULONG *aCountCopied);
361 STDMETHOD(SetVisibleRegion)(BYTE *aRectangles, ULONG aCount);
362
363 STDMETHOD(ProcessVHWACommand)(BYTE *pCommand);
364
365 ulong width() { return mWdt; }
366 ulong height() { return mHgt; }
367
368 virtual ulong pixelFormat()
369 {
370 return FramebufferPixelFormat_FOURCC_RGB;
371 }
372
373 virtual bool usesGuestVRAM()
374 {
375 return false;
376 }
377
378 void lock() { RTCritSectEnter(&mCritSect); }
379 void unlock() { RTCritSectLeave(&mCritSect); }
380
381 virtual uchar *address() = 0;
382 virtual ulong bitsPerPixel() = 0;
383 virtual ulong bytesPerLine() = 0;
384
385 /**
386 * Called on the GUI thread (from VBoxConsoleView) when some part of the
387 * VM display viewport needs to be repainted on the host screen.
388 */
389 virtual void paintEvent (QPaintEvent *pe) = 0;
390
391 /**
392 * Called on the GUI thread (from VBoxConsoleView) after it gets a
393 * VBoxResizeEvent posted from the RequestResize() method implementation.
394 */
395 virtual void resizeEvent (VBoxResizeEvent *re)
396 {
397 mWdt = re->width();
398 mHgt = re->height();
399 }
400
401 /**
402 * Called on the GUI thread (from VBoxConsoleView) when the VM console
403 * window is moved.
404 */
405 virtual void moveEvent (QMoveEvent * /*me*/ ) {}
406
407#ifdef VBOX_GUI_USE_QGL
408 /* this method is called from the GUI thread
409 * to perform the actual Video HW Acceleration command processing */
410 virtual void doProcessVHWACommand(VBoxVHWACommandProcessEvent * pEvent);
411#endif
412
413protected:
414
415 VBoxConsoleView *mView;
416 RTCRITSECT mCritSect;
417 int mWdt;
418 int mHgt;
419 uint64_t mWinId;
420
421#if defined (Q_OS_WIN32)
422private:
423 long refcnt;
424#endif
425};
426
427/////////////////////////////////////////////////////////////////////////////
428
429#if defined (VBOX_GUI_USE_QIMAGE)
430
431class VBoxQImageFrameBuffer : public VBoxFrameBuffer
432{
433public:
434
435 VBoxQImageFrameBuffer (VBoxConsoleView *aView);
436
437 STDMETHOD(NotifyUpdate) (ULONG aX, ULONG aY,
438 ULONG aW, ULONG aH);
439
440 ulong pixelFormat() { return mPixelFormat; }
441 bool usesGuestVRAM() { return mUsesGuestVRAM; }
442
443 uchar *address() { return mImg.bits(); }
444 ulong bitsPerPixel() { return mImg.depth(); }
445 ulong bytesPerLine() { return mImg.bytesPerLine(); }
446
447 void paintEvent (QPaintEvent *pe);
448 void resizeEvent (VBoxResizeEvent *re);
449
450private:
451
452 QPixmap mPM;
453 QImage mImg;
454 ulong mPixelFormat;
455 bool mUsesGuestVRAM;
456};
457
458#endif
459
460/////////////////////////////////////////////////////////////////////////////
461
462#if defined (VBOX_GUI_USE_QGL)
463
464#ifdef DEBUG
465#include "iprt/stream.h"
466#define VBOXQGLLOG(_m) RTPrintf _m
467#else
468#define VBOXQGLLOG(_m)
469#endif
470#define VBOXQGLLOG_ENTER(_m)
471//do{VBOXQGLLOG(("==>[%s]:", __FUNCTION__)); VBOXQGLLOG(_m);}while(0)
472#define VBOXQGLLOG_EXIT(_m)
473//do{VBOXQGLLOG(("<==[%s]:", __FUNCTION__)); VBOXQGLLOG(_m);}while(0)
474#ifdef DEBUG
475#define VBOXQGL_ASSERTNOERR() \
476 do { GLenum err = glGetError(); \
477 if(err != GL_NO_ERROR) VBOXQGLLOG(("gl error ocured (0x%x)\n", err)); \
478 Assert(err == GL_NO_ERROR); \
479 }while(0)
480
481#define VBOXQGL_CHECKERR(_op) \
482 do { \
483 glGetError(); \
484 _op \
485 VBOXQGL_ASSERTNOERR(); \
486 }while(0)
487#else
488#define VBOXQGL_ASSERTNOERR() \
489 do {}while(0)
490
491#define VBOXQGL_CHECKERR(_op) \
492 do { \
493 _op \
494 }while(0)
495#endif
496
497#ifdef DEBUG
498#include <iprt/time.h>
499
500#define VBOXGETTIME() RTTimeNanoTS()
501
502#define VBOXPRINTDIF(_nano, _m) do{\
503 uint64_t cur = VBOXGETTIME(); \
504 VBOXQGLLOG(_m); \
505 VBOXQGLLOG(("(%Lu)\n", cur - (_nano))); \
506 }while(0)
507
508class VBoxVHWADbgTimeCounter
509{
510public:
511 VBoxVHWADbgTimeCounter(const char* msg) {mTime = VBOXGETTIME(); mMsg=msg;}
512 ~VBoxVHWADbgTimeCounter() {VBOXPRINTDIF(mTime, (mMsg));}
513private:
514 uint64_t mTime;
515 const char* mMsg;
516};
517
518#define VBOXQGLLOG_METHODTIME(_m) VBoxVHWADbgTimeCounter _dbgTimeCounter(_m)
519#else
520#define VBOXQGLLOG_METHODTIME(_m)
521#endif
522
523#define VBOXQGLLOG_QRECT(_p, _pr, _s) do{\
524 VBOXQGLLOG((_p " x(%d), y(%d), w(%d), h(%d)" _s, (_pr)->x(), (_pr)->y(), (_pr)->width(), (_pr)->height()));\
525 }while(0)
526
527#define VBOXQGLLOG_CKEY(_p, _pck, _s) do{\
528 VBOXQGLLOG((_p " l(0x%x), u(0x%x)" _s, (_pck)->lower(), (_pck)->upper()));\
529 }while(0)
530
531class VBoxVHWADirtyRect
532{
533public:
534 VBoxVHWADirtyRect() :
535 mIsClear(true)
536 {}
537
538 VBoxVHWADirtyRect(const QRect & aRect)
539 {
540 if(aRect.isEmpty())
541 {
542 mIsClear = false;
543 mRect = aRect;
544 }
545 else
546 {
547 mIsClear = true;
548 }
549 }
550
551 bool isClear() const { return mIsClear; }
552
553 void add(const QRect & aRect)
554 {
555 if(aRect.isEmpty())
556 return;
557
558 mRect = mIsClear ? aRect : mRect.united(aRect);
559 mIsClear = false;
560 }
561
562 void add(const VBoxVHWADirtyRect & aRect)
563 {
564 if(aRect.isClear())
565 return;
566 add(aRect.rect());
567 }
568
569 void set(const QRect & aRect)
570 {
571 if(aRect.isEmpty())
572 {
573 mIsClear = true;
574 }
575 else
576 {
577 mRect = aRect;
578 mIsClear = false;
579 }
580 }
581
582 void clear() { mIsClear = true; }
583
584 const QRect & rect() const {return mRect;}
585
586 bool intersects(const QRect & aRect) const {return mIsClear ? false : mRect.intersects(aRect);}
587
588 bool intersects(const VBoxVHWADirtyRect & aRect) const {return mIsClear ? false : aRect.intersects(mRect);}
589
590 QRect united(const QRect & aRect) const {return mIsClear ? aRect : aRect.united(mRect);}
591
592 bool contains(const QRect & aRect) const {return mIsClear ? false : aRect.contains(mRect);}
593
594 void subst(const VBoxVHWADirtyRect & aRect) { if(!mIsClear && aRect.contains(mRect)) clear(); }
595
596private:
597 QRect mRect;
598 bool mIsClear;
599};
600
601class VBoxVHWAColorKey
602{
603public:
604 VBoxVHWAColorKey() :
605 mUpper(0),
606 mLower(0)
607 {}
608
609 VBoxVHWAColorKey(uint32_t aUpper, uint32_t aLower) :
610 mUpper(aUpper),
611 mLower(aLower)
612 {}
613
614 uint32_t upper() const {return mUpper; }
615 uint32_t lower() const {return mLower; }
616
617 bool operator==(const VBoxVHWAColorKey & other) const { return mUpper == other.mUpper && mLower == other.mLower; }
618private:
619 uint32_t mUpper;
620 uint32_t mLower;
621};
622
623class VBoxVHWAColorComponent
624{
625public:
626 VBoxVHWAColorComponent() :
627 mMask(0),
628 mRange(0),
629 mOffset(32),
630 mcBits(0)
631 {}
632
633 VBoxVHWAColorComponent(uint32_t aMask);
634
635 uint32_t mask() const { return mMask; }
636 uint32_t range() const { return mRange; }
637 uint32_t offset() const { return mOffset; }
638 uint32_t cBits() const { return mcBits; }
639 uint32_t colorVal(uint32_t col) const { return (col & mMask) >> mOffset; }
640 float colorValNorm(uint32_t col) const { return ((float)colorVal(col))/mRange; }
641private:
642 uint32_t mMask;
643 uint32_t mRange;
644 uint32_t mOffset;
645 uint32_t mcBits;
646};
647
648class VBoxVHWAColorFormat
649{
650public:
651
652// VBoxVHWAColorFormat(GLint aInternalFormat, GLenum aFormat, GLenum aType, uint32_t aDataFormat);
653 VBoxVHWAColorFormat(uint32_t bitsPerPixel, uint32_t r, uint32_t g, uint32_t b);
654 VBoxVHWAColorFormat(uint32_t fourcc);
655 VBoxVHWAColorFormat(){}
656 GLint internalFormat() const {return mInternalFormat; }
657 GLenum format() const {return mFormat; }
658 GLenum type() const {return mType; }
659 bool isValid() const {return mBitsPerPixel != 0; }
660 uint32_t fourcc() const {return mDataFormat;}
661 uint32_t bitsPerPixel() const { return mBitsPerPixel; }
662 uint32_t bitsPerPixelTex() const { return mBitsPerPixelTex; }
663// uint32_t bitsPerPixelDd() const { return mBitsPerPixelDd; }
664 void pixel2Normalized(uint32_t pix, float *r, float *g, float *b) const;
665 uint32_t widthCompression() const {return mWidthCompression;}
666 uint32_t heightCompression() const {return mHeightCompression;}
667 const VBoxVHWAColorComponent& r() const {return mR;}
668 const VBoxVHWAColorComponent& g() const {return mG;}
669 const VBoxVHWAColorComponent& b() const {return mB;}
670 const VBoxVHWAColorComponent& a() const {return mA;}
671
672private:
673 void VBoxVHWAColorFormat::init(uint32_t bitsPerPixel, uint32_t r, uint32_t g, uint32_t b);
674 void VBoxVHWAColorFormat::init(uint32_t fourcc);
675
676 GLint mInternalFormat;
677 GLenum mFormat;
678 GLenum mType;
679 uint32_t mDataFormat;
680
681 uint32_t mBitsPerPixel;
682 uint32_t mBitsPerPixelTex;
683// uint32_t mBitsPerPixelDd;
684 uint32_t mWidthCompression;
685 uint32_t mHeightCompression;
686 VBoxVHWAColorComponent mR;
687 VBoxVHWAColorComponent mG;
688 VBoxVHWAColorComponent mB;
689 VBoxVHWAColorComponent mA;
690};
691
692class VBoxVHWATexture
693{
694public:
695 VBoxVHWATexture() {}
696 VBoxVHWATexture(const QRect * pRect, const VBoxVHWAColorFormat *pFormat);
697 virtual ~VBoxVHWATexture();
698 virtual void init(uchar *pvMem);
699 void setAddress(uchar *pvMem) {mAddress = pvMem;}
700 void update(const QRect * pRect) { doUpdate(mAddress, pRect);}
701 void bind() {glBindTexture(texTarget(), mTexture);}
702
703 virtual void texCoord(int x, int y);
704 virtual void multiTexCoord(GLenum texUnit, int x, int y);
705
706// GLuint texture() {return mTexture;}
707 const QRect & texRect() {return mTexRect;}
708 const QRect & rect() {return mRect;}
709 uchar * address(){ return mAddress; }
710 uint32_t rectSizeTex(const QRect * pRect) {return pRect->width() * pRect->height() * mBytesPerPixelTex;}
711 uchar * pointAddress(int x, int y)
712 {
713 x = toXTex(x);
714 y = toYTex(y);
715 return pointAddressTex(x, y);
716 }
717 uint32_t pointOffsetTex(int x, int y) { return y*mBytesPerLine + x*mBytesPerPixelTex; }
718 uchar * pointAddressTex(int x, int y) { return mAddress + pointOffsetTex(x, y); }
719 int toXTex(int x) {return x/mColorFormat.widthCompression();}
720 int toYTex(int y) {return y/mColorFormat.heightCompression();}
721 ulong memSize(){ return mBytesPerLine * mRect.height(); }
722 uint32_t bytesPerLine() {return mBytesPerLine; }
723
724protected:
725 virtual void doUpdate(uchar * pAddress, const QRect * pRect);
726 virtual void initParams();
727 virtual void load();
728 virtual GLenum texTarget() {return GL_TEXTURE_2D; }
729
730
731 QRect mTexRect; /* texture size */
732 QRect mRect; /* img size */
733 uchar * mAddress;
734 GLuint mTexture;
735 uint32_t mBytesPerPixel;
736 uint32_t mBytesPerPixelTex;
737 uint32_t mBytesPerLine;
738 VBoxVHWAColorFormat mColorFormat;
739private:
740 void uninit();
741};
742
743class VBoxVHWATextureNP2 : public VBoxVHWATexture
744{
745public:
746 VBoxVHWATextureNP2() : VBoxVHWATexture() {}
747 VBoxVHWATextureNP2(const QRect * pRect, const VBoxVHWAColorFormat *pFormat) :
748 VBoxVHWATexture(pRect, pFormat){
749 mTexRect = QRect(0, 0, pRect->width()/pFormat->widthCompression(), pRect->height()/pFormat->heightCompression());
750 }
751};
752
753class VBoxVHWATextureNP2Rect : public VBoxVHWATextureNP2
754{
755public:
756 VBoxVHWATextureNP2Rect() : VBoxVHWATextureNP2() {}
757 VBoxVHWATextureNP2Rect(const QRect * pRect, const VBoxVHWAColorFormat *pFormat) :
758 VBoxVHWATextureNP2(pRect, pFormat){}
759
760 virtual void texCoord(int x, int y);
761 virtual void multiTexCoord(GLenum texUnit, int x, int y);
762protected:
763 virtual GLenum texTarget();
764};
765
766class VBoxVHWATextureNP2RectPBO : public VBoxVHWATextureNP2Rect
767{
768public:
769 VBoxVHWATextureNP2RectPBO() : VBoxVHWATextureNP2Rect() {}
770 VBoxVHWATextureNP2RectPBO(const QRect * pRect, const VBoxVHWAColorFormat *pFormat) :
771 VBoxVHWATextureNP2Rect(pRect, pFormat){}
772 virtual ~VBoxVHWATextureNP2RectPBO();
773
774 virtual void init(uchar *pvMem);
775protected:
776 virtual void load();
777 virtual void doUpdate(uchar * pAddress, const QRect * pRect);
778private:
779 void updateBuffer(uchar * pBuf, const QRect * pRect);
780 GLuint mPBO;
781};
782
783class VBoxVHWAHandleTable
784{
785public:
786 VBoxVHWAHandleTable(uint32_t initialSize);
787 ~VBoxVHWAHandleTable();
788 uint32_t put(void * data);
789 bool mapPut(uint32_t h, void * data);
790 void* get(uint32_t h);
791 void* remove(uint32_t h);
792private:
793 void doPut(uint32_t h, void * data);
794 void doRemove(uint32_t h);
795 void** mTable;
796 uint32_t mcSize;
797 uint32_t mcUsage;
798 uint32_t mCursor;
799};
800
801/* data flow:
802 * I. NON-Yinverted surface:
803 * 1.direct memory update (paint, lock/unlock):
804 * mem->tex->fb
805 * 2.blt
806 * srcTex->invFB->tex->fb
807 * |->mem
808 *
809 * II. Yinverted surface:
810 * 1.direct memory update (paint, lock/unlock):
811 * mem->tex->fb
812 * 2.blt
813 * srcTex->fb->tex
814 * |->mem
815 *
816 * III. flip support:
817 * 1. Yinverted<->NON-YInverted conversion :
818 * mem->tex-(rotate model view, force LAZY complete fb update)->invFB->tex
819 * fb-->| |->mem
820 * */
821class VBoxVHWASurfaceBase
822{
823public:
824 VBoxVHWASurfaceBase(
825 class VBoxGLWidget *mWidget,
826#if 0
827 class VBoxVHWAGlContextState *aState,
828 bool aIsYInverted,
829#endif
830 const QSize * aSize, const QSize * aTargetSize,
831 VBoxVHWAColorFormat & aColorFormat,
832 VBoxVHWAColorKey * pSrcBltCKey, VBoxVHWAColorKey * pDstBltCKey,
833 VBoxVHWAColorKey * pSrcOverlayCKey, VBoxVHWAColorKey * pDstOverlayCKey,
834 bool bVGA);
835
836 virtual ~VBoxVHWASurfaceBase();
837
838 void init(VBoxVHWASurfaceBase * pPrimary, uchar *pvMem);
839 void setupMatricies(VBoxVHWASurfaceBase *pPrimary);
840
841 void uninit();
842
843 static void globalInit();
844
845// int blt(const QRect * aDstRect, VBoxVHWASurfaceBase * aSrtSurface, const QRect * aSrcRect, const VBoxVHWAColorKey * pDstCKeyOverride, const VBoxVHWAColorKey * pSrcCKeyOverride);
846// int overlay(VBoxVHWASurfaceBase * aOverlaySurface);
847
848 int lock(const QRect * pRect, uint32_t flags);
849
850 int unlock();
851
852 void updatedMem(const QRect * aRect);
853
854 void performDisplay(VBoxVHWASurfaceBase *pPrimary);
855
856 void setRects(VBoxVHWASurfaceBase *pPrimary, const QRect * aTargRect, const QRect * aSrcRect);
857 void setTargetRectPosition(VBoxVHWASurfaceBase *pPrimary, const QPoint * aPoint);
858
859 static ulong calcBytesPerPixel(GLenum format, GLenum type);
860
861 static GLsizei makePowerOf2(GLsizei val);
862
863 bool addressAlocated() const { return mFreeAddress; }
864 uchar * address(){ return mAddress; }
865
866 ulong memSize();
867
868 ulong width() { return mRect.width(); }
869 ulong height() { return mRect.height(); }
870
871 GLenum format() {return mColorFormat.format(); }
872 GLint internalFormat() { return mColorFormat.internalFormat(); }
873 GLenum type() { return mColorFormat.type(); }
874 uint32_t fourcc() {return mColorFormat.fourcc(); }
875
876// ulong bytesPerPixel() { return mpTex[0]->bytesPerPixel(); }
877 ulong bitsPerPixel() { return mColorFormat.bitsPerPixel(); }
878// ulong bitsPerPixelDd() { return mColorFormat.bitsPerPixelDd(); }
879 ulong bytesPerLine() { return mpTex[0]->bytesPerLine(); }
880
881 const VBoxVHWAColorKey * dstBltCKey() const { return mpDstBltCKey; }
882 const VBoxVHWAColorKey * srcBltCKey() const { return mpSrcBltCKey; }
883 const VBoxVHWAColorKey * dstOverlayCKey() const { return mpDstOverlayCKey; }
884 const VBoxVHWAColorKey * defaultSrcOverlayCKey() const { return mpDefaultSrcOverlayCKey; }
885 const VBoxVHWAColorKey * defaultDstOverlayCKey() const { return mpDefaultDstOverlayCKey; }
886 const VBoxVHWAColorKey * srcOverlayCKey() const { return mpSrcOverlayCKey; }
887 void resetDefaultSrcOverlayCKey() { mpSrcOverlayCKey = mpDefaultSrcOverlayCKey; }
888 void resetDefaultDstOverlayCKey() { mpDstOverlayCKey = mpDefaultDstOverlayCKey; }
889
890 void setDstBltCKey(const VBoxVHWAColorKey * ckey)
891 {
892 if(ckey)
893 {
894 mDstBltCKey = *ckey;
895 mpDstBltCKey = &mDstBltCKey;
896 }
897 else
898 {
899 mpDstBltCKey = NULL;
900 }
901 }
902
903 void setSrcBltCKey(const VBoxVHWAColorKey * ckey)
904 {
905 if(ckey)
906 {
907 mSrcBltCKey = *ckey;
908 mpSrcBltCKey = &mSrcBltCKey;
909 }
910 else
911 {
912 mpSrcBltCKey = NULL;
913 }
914 }
915
916 void setDefaultDstOverlayCKey(const VBoxVHWAColorKey * ckey)
917 {
918 if(ckey)
919 {
920 mDefaultDstOverlayCKey = *ckey;
921 mpDefaultDstOverlayCKey = &mDefaultDstOverlayCKey;
922 }
923 else
924 {
925 mpDefaultDstOverlayCKey = NULL;
926 }
927 }
928
929 void setDefaultSrcOverlayCKey(const VBoxVHWAColorKey * ckey)
930 {
931 if(ckey)
932 {
933 mDefaultSrcOverlayCKey = *ckey;
934 mpDefaultSrcOverlayCKey = &mDefaultSrcOverlayCKey;
935 }
936 else
937 {
938 mpDefaultSrcOverlayCKey = NULL;
939 }
940 }
941
942 void setOverriddenDstOverlayCKey(const VBoxVHWAColorKey * ckey)
943 {
944 if(ckey)
945 {
946 mOverriddenDstOverlayCKey = *ckey;
947 mpDstOverlayCKey = &mOverriddenDstOverlayCKey;
948 }
949 else
950 {
951 mpDstOverlayCKey = NULL;
952 }
953 }
954
955 void setOverriddenSrcOverlayCKey(const VBoxVHWAColorKey * ckey)
956 {
957 if(ckey)
958 {
959 mOverriddenSrcOverlayCKey = *ckey;
960 mpSrcOverlayCKey = &mOverriddenSrcOverlayCKey;
961 }
962 else
963 {
964 mpSrcOverlayCKey = NULL;
965 }
966 }
967
968 const VBoxVHWAColorKey * getActiveSrcOverlayCKey()
969 {
970 return mpSrcOverlayCKey;
971 }
972
973 const VBoxVHWAColorKey * getActiveDstOverlayCKey(VBoxVHWASurfaceBase * pPrimary)
974 {
975 return mpDstOverlayCKey ? mpDefaultDstOverlayCKey : pPrimary->mpDstOverlayCKey;
976 }
977
978 const VBoxVHWAColorFormat & colorFormat() {return mColorFormat; }
979
980 void setAddress(uchar * addr);
981
982 const QRect& rect() const {return mRect;}
983 const QRect& srcRect() const {return mSrcRect; }
984 const QRect& targRect() const {return mTargRect; }
985 class VBoxVHWASurfList * getComplexList() {return mComplexList; }
986
987 class VBoxVHWAGlProgramMngr * getGlProgramMngr();
988 static int setCKey(class VBoxVHWAGlProgramVHWA * pProgram, const VBoxVHWAColorFormat * pFormat, const VBoxVHWAColorKey * pCKey, bool bDst);
989
990 uint64_t handle() {return mHGHandle;}
991 void setHandle(uint64_t h) {mHGHandle = h;}
992private:
993 void setComplexList(VBoxVHWASurfList *aComplexList) { mComplexList = aComplexList; }
994 void initDisplay(VBoxVHWASurfaceBase *pPrimary);
995 void deleteDisplay();
996
997 GLuint createDisplay(VBoxVHWASurfaceBase *pPrimary);
998 void doDisplay(VBoxVHWASurfaceBase *pPrimary, VBoxVHWAGlProgramVHWA * pProgram, bool bBindDst);
999 void synchTexMem(const QRect * aRect);
1000
1001 int performBlt(const QRect * pDstRect, VBoxVHWASurfaceBase * pSrcSurface, const QRect * pSrcRect, const VBoxVHWAColorKey * pDstCKey, const VBoxVHWAColorKey * pSrcCKey, bool blt);
1002
1003 void doTex2FB(const QRect * pDstRect, const QRect * pSrcRect);
1004 void doMultiTex2FB(const QRect * pDstRect, VBoxVHWATexture * pDstTex, const QRect * pSrcRect, int cSrcTex);
1005 void doMultiTex2FB(const QRect * pDstRect, const QRect * pSrcRect, int cSrcTex);
1006
1007 void doSetupMatrix(const QSize * pSize , bool bInverted);
1008
1009 QRect mRect; /* == Inv FB size */
1010
1011 QRect mSrcRect;
1012 QRect mTargRect; /* == Vis FB size */
1013 QRect mTargSize;
1014
1015 GLuint mVisibleDisplay;
1016
1017 bool mVisibleDisplayInitialized;
1018
1019 uchar * mAddress;
1020 VBoxVHWATexture *mpTex[3];
1021
1022 VBoxVHWAColorFormat mColorFormat;
1023
1024 VBoxVHWAColorKey *mpSrcBltCKey;
1025 VBoxVHWAColorKey *mpDstBltCKey;
1026 VBoxVHWAColorKey *mpSrcOverlayCKey;
1027 VBoxVHWAColorKey *mpDstOverlayCKey;
1028
1029 VBoxVHWAColorKey *mpDefaultDstOverlayCKey;
1030 VBoxVHWAColorKey *mpDefaultSrcOverlayCKey;
1031
1032 VBoxVHWAColorKey mSrcBltCKey;
1033 VBoxVHWAColorKey mDstBltCKey;
1034 VBoxVHWAColorKey mOverriddenSrcOverlayCKey;
1035 VBoxVHWAColorKey mOverriddenDstOverlayCKey;
1036 VBoxVHWAColorKey mDefaultDstOverlayCKey;
1037 VBoxVHWAColorKey mDefaultSrcOverlayCKey;
1038
1039 int mLockCount;
1040 /* memory buffer not reflected in fm and texture, e.g if memory buffer is replaced or in case of lock/unlock */
1041 VBoxVHWADirtyRect mUpdateMem2TexRect;
1042
1043 bool mFreeAddress;
1044
1045 class VBoxVHWASurfList *mComplexList;
1046
1047 class VBoxGLWidget *mWidget;
1048
1049 uint64_t mHGHandle;
1050protected:
1051
1052 friend class VBoxVHWASurfList;
1053#ifdef DEBUG
1054public:
1055 uint64_t cFlipsCurr;
1056 uint64_t cFlipsTarg;
1057#endif
1058};
1059
1060typedef std::list <VBoxVHWASurfaceBase*> SurfList;
1061typedef std::list <VBoxVHWASurfList*> OverlayList;
1062
1063class VBoxVHWASurfList
1064{
1065public:
1066
1067 VBoxVHWASurfList() : mCurrent(NULL) {}
1068 void add(VBoxVHWASurfaceBase *pSurf)
1069 {
1070 VBoxVHWASurfList * pOld = pSurf->getComplexList();
1071 if(pOld)
1072 {
1073 pOld->remove(pSurf);
1074 }
1075 mSurfaces.push_back(pSurf);
1076 pSurf->setComplexList(this);
1077 }
1078
1079 void clear()
1080 {
1081 for (SurfList::iterator it = mSurfaces.begin();
1082 it != mSurfaces.end(); ++ it)
1083 {
1084 (*it)->setComplexList(NULL);
1085 }
1086 mSurfaces.clear();
1087 mCurrent = NULL;
1088 }
1089
1090 void remove(VBoxVHWASurfaceBase *pSurf)
1091 {
1092 mSurfaces.remove(pSurf);
1093 pSurf->setComplexList(NULL);
1094 if(mCurrent == pSurf)
1095 mCurrent = NULL;
1096 }
1097
1098 bool empty() { return mSurfaces.empty(); }
1099
1100 void setCurrentVisible(VBoxVHWASurfaceBase *pSurf)
1101 {
1102 mCurrent = pSurf;
1103 }
1104
1105 VBoxVHWASurfaceBase * current() { return mCurrent; }
1106 const SurfList & surfaces() const {return mSurfaces;}
1107
1108private:
1109
1110 SurfList mSurfaces;
1111 VBoxVHWASurfaceBase* mCurrent;
1112};
1113
1114class VBoxVHWADisplay
1115{
1116public:
1117 VBoxVHWADisplay() :
1118 mSurfVGA(NULL)
1119// ,
1120// mSurfPrimary(NULL)
1121 {}
1122
1123 VBoxVHWASurfaceBase * setVGA(VBoxVHWASurfaceBase * pVga)
1124 {
1125 VBoxVHWASurfaceBase * old = mSurfVGA;
1126 mSurfVGA = pVga;
1127 mPrimary.clear();
1128 if(pVga)
1129 {
1130 mPrimary.add(pVga);
1131 mPrimary.setCurrentVisible(pVga);
1132 }
1133// mSurfPrimary = pVga;
1134 mOverlays.clear();
1135 return old;
1136 }
1137
1138 VBoxVHWASurfaceBase * getVGA()
1139 {
1140 return mSurfVGA;
1141 }
1142
1143 VBoxVHWASurfaceBase * getPrimary()
1144 {
1145 return mPrimary.current();
1146 }
1147//
1148// void setPrimary(VBoxVHWASurfList * pSurf)
1149// {
1150// mSurfPrimary = pSurf;
1151// }
1152
1153 void addOverlay(VBoxVHWASurfList * pSurf)
1154 {
1155 mOverlays.push_back(pSurf);
1156 }
1157
1158 void checkAddOverlay(VBoxVHWASurfList * pSurf)
1159 {
1160 if(!hasOverlay(pSurf))
1161 addOverlay(pSurf);
1162 }
1163
1164 bool hasOverlay(VBoxVHWASurfList * pSurf)
1165 {
1166 for (OverlayList::iterator it = mOverlays.begin();
1167 it != mOverlays.end(); ++ it)
1168 {
1169 if((*it) == pSurf)
1170 {
1171 return true;
1172 }
1173 }
1174 return false;
1175 }
1176
1177 void removeOverlay(VBoxVHWASurfList * pSurf)
1178 {
1179 mOverlays.remove(pSurf);
1180 }
1181
1182 void performDisplay()
1183 {
1184 VBoxVHWASurfaceBase * pPrimary = mPrimary.current();
1185 pPrimary->performDisplay(NULL);
1186
1187 for (OverlayList::const_iterator it = mOverlays.begin();
1188 it != mOverlays.end(); ++ it)
1189 {
1190 VBoxVHWASurfaceBase * pOverlay = (*it)->current();
1191 if(pOverlay)
1192 {
1193 pOverlay->performDisplay(pPrimary);
1194 }
1195 }
1196 }
1197
1198 const OverlayList & overlays() const {return mOverlays;}
1199
1200private:
1201 VBoxVHWASurfaceBase *mSurfVGA;
1202 VBoxVHWASurfList mPrimary;
1203
1204 OverlayList mOverlays;
1205};
1206
1207typedef void (VBoxGLWidget::*PFNVBOXQGLOP)(void* );
1208
1209class VBoxGLWidget : public QGLWidget
1210{
1211public:
1212 VBoxGLWidget (VBoxConsoleView *aView, QWidget *aParent);
1213 ~VBoxGLWidget();
1214
1215 ulong vboxPixelFormat() { return mPixelFormat; }
1216 bool vboxUsesGuestVRAM() { return mUsesGuestVRAM; }
1217
1218 uchar *vboxAddress() { return mDisplay.getVGA() ? mDisplay.getVGA()->address() : NULL; }
1219
1220#ifdef VBOX_WITH_VIDEOHWACCEL
1221 uchar *vboxVRAMAddressFromOffset(uint64_t offset);
1222 uint64_t vboxVRAMOffsetFromAddress(uchar* addr);
1223 uint64_t vboxVRAMOffset(VBoxVHWASurfaceBase * pSurf);
1224
1225 void vhwaSaveExec(struct SSMHANDLE * pSSM);
1226 int vhwaLoadExec(struct SSMHANDLE * pSSM, uint32_t u32Version);
1227#endif
1228
1229 ulong vboxBitsPerPixel() { return mDisplay.getVGA()->bitsPerPixel(); }
1230 ulong vboxBytesPerLine() { return mDisplay.getVGA() ? mDisplay.getVGA()->bytesPerLine() : NULL; }
1231
1232 void vboxPaintEvent (QPaintEvent *pe) {vboxPerformGLOp(&VBoxGLWidget::vboxDoPaint, pe);}
1233 void vboxResizeEvent (VBoxResizeEvent *re) {vboxPerformGLOp(&VBoxGLWidget::vboxDoResize, re);}
1234
1235 void vboxProcessVHWACommands(VBoxVHWACommandProcessEvent * pEvent) {vboxPerformGLOp(&VBoxGLWidget::vboxDoProcessVHWACommands, pEvent);}
1236#ifdef VBOX_WITH_VIDEOHWACCEL
1237 void vboxVHWACmd (struct _VBOXVHWACMD * pCmd) {vboxPerformGLOp(&VBoxGLWidget::vboxDoVHWACmd, pCmd);}
1238#endif
1239 class VBoxVHWAGlProgramMngr * vboxVHWAGetGlProgramMngr() { return mpMngr; }
1240
1241 VBoxVHWASurfaceBase * vboxGetVGASurface() { return mDisplay.getVGA(); }
1242
1243 void postCmd(VBOXVHWA_PIPECMD_TYPE aType, void * pvData);
1244protected:
1245
1246 void paintGL()
1247 {
1248 if(mpfnOp)
1249 {
1250 (this->*mpfnOp)(mOpContext);
1251 mpfnOp = NULL;
1252 }
1253 else
1254 {
1255 mDisplay.performDisplay();
1256 }
1257 }
1258
1259 void initializeGL();
1260private:
1261 void vboxDoResize(void *re);
1262 void vboxDoPaint(void *rec);
1263
1264 void vboxDoUpdateRect(const QRect * pRect);
1265#ifdef VBOXQGL_DBG_SURF
1266 void vboxDoTestSurfaces(void *context);
1267#endif
1268#ifdef VBOX_WITH_VIDEOHWACCEL
1269 void vboxDoVHWACmdExec(void *cmd);
1270 void vboxDoVHWACmd(void *cmd);
1271
1272 void vboxCheckUpdateAddress (VBoxVHWASurfaceBase * pSurface, uint64_t offset)
1273 {
1274#ifndef VBOXQGL_DBG_SURF
1275 if(offset == 0xffffffffffffffffL)
1276 {
1277 return;
1278 }
1279#endif
1280 if (pSurface->addressAlocated())
1281 {
1282 uchar * addr = vboxVRAMAddressFromOffset(offset);
1283 if(addr)
1284 {
1285 pSurface->setAddress(addr);
1286 }
1287 }
1288 }
1289 int vhwaSurfaceCanCreate(struct _VBOXVHWACMD_SURF_CANCREATE *pCmd);
1290 int vhwaSurfaceCreate(struct _VBOXVHWACMD_SURF_CREATE *pCmd);
1291 int vhwaSurfaceDestroy(struct _VBOXVHWACMD_SURF_DESTROY *pCmd);
1292 int vhwaSurfaceLock(struct _VBOXVHWACMD_SURF_LOCK *pCmd);
1293 int vhwaSurfaceUnlock(struct _VBOXVHWACMD_SURF_UNLOCK *pCmd);
1294 int vhwaSurfaceBlt(struct _VBOXVHWACMD_SURF_BLT *pCmd);
1295 int vhwaSurfaceFlip(struct _VBOXVHWACMD_SURF_FLIP *pCmd);
1296 int vhwaSurfaceOverlayUpdate(struct _VBOXVHWACMD_SURF_OVERLAY_UPDATE *pCmf);
1297 int vhwaSurfaceOverlaySetPosition(struct _VBOXVHWACMD_SURF_OVERLAY_SETPOSITION *pCmd);
1298 int vhwaSurfaceColorkeySet(struct _VBOXVHWACMD_SURF_COLORKEY_SET *pCmd);
1299 int vhwaQueryInfo1(struct _VBOXVHWACMD_QUERYINFO1 *pCmd);
1300 int vhwaQueryInfo2(struct _VBOXVHWACMD_QUERYINFO2 *pCmd);
1301 int vhwaConstruct(struct _VBOXVHWACMD_HH_CONSTRUCT *pCmd);
1302
1303 int vhwaSaveSurface(struct SSMHANDLE * pSSM, VBoxVHWASurfaceBase *pSurf, uint32_t surfCaps);
1304 int vhwaLoadSurface(struct SSMHANDLE * pSSM, uint32_t u32Version);
1305 int vhwaSaveOverlayData(struct SSMHANDLE * pSSM, VBoxVHWASurfaceBase *pSurf, bool bVisible);
1306 int vhwaLoadOverlayData(struct SSMHANDLE * pSSM, uint32_t u32Version);
1307
1308 void vhwaDoSurfaceOverlayUpdate(VBoxVHWASurfaceBase *pDstSurf, VBoxVHWASurfaceBase *pSrcSurf, struct _VBOXVHWACMD_SURF_OVERLAY_UPDATE *pCmd);
1309#endif
1310 static const QGLFormat & vboxGLFormat();
1311
1312 VBoxVHWADisplay mDisplay;
1313
1314
1315 /* we do all opengl stuff in the paintGL context,
1316 * submit the operation to be performed
1317 * @todo: could be moved outside the updateGL */
1318 void vboxPerformGLOp(PFNVBOXQGLOP pfn, void* pContext) {mpfnOp = pfn; mOpContext = pContext; updateGL();}
1319
1320 /* posts op to UI thread */
1321 int vboxExecOpSynch(PFNVBOXQGLOP pfn, void* pContext);
1322
1323 void cmdPipeInit();
1324 void cmdPipeDelete();
1325 void vboxDoProcessVHWACommands(void *pContext);
1326
1327 VBoxVHWACommandElement * detachCmdList(VBoxVHWACommandElement * pFirst2Free, VBoxVHWACommandElement * pLast2Free);
1328 VBoxVHWACommandElement * processCmdList(VBoxVHWACommandElement * pCmd);
1329
1330 VBoxVHWASurfaceBase* handle2Surface(uint32_t h) { return (VBoxVHWASurfaceBase*)mSurfHandleTable.get(h); }
1331
1332 VBoxVHWAHandleTable mSurfHandleTable;
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