VirtualBox

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

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

Video Hw Accel: basics for NP2 & RECTANGLE textures support, workaround for NVIDIA driver bug with GLSL

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