VirtualBox

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

Last change on this file since 22099 was 22099, checked in by vboxsync, 15 years ago

video hw accel: YUY2 format support debugged, bugfixes

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 43.8 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(%d), u(%d)" _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// uint32_t r(uint32_t pix);
643// uint32_t g(uint32_t pix);
644// uint32_t b(uint32_t pix);
645
646private:
647 void VBoxVHWAColorFormat::init(uint32_t bitsPerPixel, uint32_t r, uint32_t g, uint32_t b);
648 void VBoxVHWAColorFormat::init(uint32_t fourcc);
649
650 GLint mInternalFormat;
651 GLenum mFormat;
652 GLenum mType;
653 uint32_t mDataFormat;
654
655 uint32_t mBitsPerPixel;
656 uint32_t mBitsPerPixelTex;
657// uint32_t mBitsPerPixelDd;
658 uint32_t mWidthCompression;
659 uint32_t mHeightCompression;
660 VBoxVHWAColorComponent mR;
661 VBoxVHWAColorComponent mG;
662 VBoxVHWAColorComponent mB;
663 VBoxVHWAColorComponent mA;
664};
665
666class VBoxVHWATexture
667{
668public:
669 VBoxVHWATexture() {}
670 VBoxVHWATexture(const QRect * pRect, const VBoxVHWAColorFormat *pFormat);
671 virtual ~VBoxVHWATexture();
672 virtual void init(uchar *pvMem);
673 void setAddress(uchar *pvMem) {mAddress = pvMem;}
674 void update(const QRect * pRect) { doUpdate(mAddress, pRect);}
675 void bind() {glBindTexture(texTarget(), mTexture);}
676
677 virtual void texCoord(int x, int y);
678 virtual void multiTexCoord(GLenum texUnit, int x, int y);
679
680// GLuint texture() {return mTexture;}
681 const QRect & texRect() {return mTexRect;}
682 const QRect & rect() {return mRect;}
683 uchar * address(){ return mAddress; }
684 uint32_t rectSizeTex(const QRect * pRect) {return pRect->width() * pRect->height() * mBytesPerPixelTex;}
685 uchar * pointAddress(int x, int y)
686 {
687 x = toXTex(x);
688 y = toYTex(y);
689 return pointAddressTex(x, y);
690 }
691 uint32_t pointOffsetTex(int x, int y) { return y*mBytesPerLine + x*mBytesPerPixelTex; }
692 uchar * pointAddressTex(int x, int y) { return mAddress + pointOffsetTex(x, y); }
693 int toXTex(int x) {return x/mColorFormat.widthCompression();}
694 int toYTex(int y) {return y/mColorFormat.heightCompression();}
695 ulong memSize(){ return mBytesPerLine * mRect.height(); }
696 uint32_t bytesPerLine() {return mBytesPerLine; }
697
698protected:
699 virtual void doUpdate(uchar * pAddress, const QRect * pRect);
700 virtual void initParams();
701 virtual void load();
702 virtual GLenum texTarget() {return GL_TEXTURE_2D; }
703
704
705 QRect mTexRect; /* texture size */
706 QRect mRect; /* img size */
707 uchar * mAddress;
708 GLuint mTexture;
709 uint32_t mBytesPerPixel;
710 uint32_t mBytesPerPixelTex;
711 uint32_t mBytesPerLine;
712 VBoxVHWAColorFormat mColorFormat;
713private:
714 void uninit();
715};
716
717class VBoxVHWATextureNP2 : public VBoxVHWATexture
718{
719public:
720 VBoxVHWATextureNP2() : VBoxVHWATexture() {}
721 VBoxVHWATextureNP2(const QRect * pRect, const VBoxVHWAColorFormat *pFormat) :
722 VBoxVHWATexture(pRect, pFormat){
723 mTexRect = QRect(0, 0, pRect->width()/pFormat->widthCompression(), pRect->height()/pFormat->heightCompression());
724 }
725};
726
727class VBoxVHWATextureNP2Rect : public VBoxVHWATextureNP2
728{
729public:
730 VBoxVHWATextureNP2Rect() : VBoxVHWATextureNP2() {}
731 VBoxVHWATextureNP2Rect(const QRect * pRect, const VBoxVHWAColorFormat *pFormat) :
732 VBoxVHWATextureNP2(pRect, pFormat){}
733
734 virtual void texCoord(int x, int y);
735 virtual void multiTexCoord(GLenum texUnit, int x, int y);
736protected:
737 virtual GLenum texTarget();
738};
739
740class VBoxVHWATextureNP2RectPBO : public VBoxVHWATextureNP2Rect
741{
742public:
743 VBoxVHWATextureNP2RectPBO() : VBoxVHWATextureNP2Rect() {}
744 VBoxVHWATextureNP2RectPBO(const QRect * pRect, const VBoxVHWAColorFormat *pFormat) :
745 VBoxVHWATextureNP2Rect(pRect, pFormat){}
746 virtual ~VBoxVHWATextureNP2RectPBO();
747
748 virtual void init(uchar *pvMem);
749protected:
750 virtual void load();
751 virtual void doUpdate(uchar * pAddress, const QRect * pRect);
752private:
753 void updateBuffer(uchar * pBuf, const QRect * pRect);
754 GLuint mPBO;
755};
756
757/* data flow:
758 * I. NON-Yinverted surface:
759 * 1.direct memory update (paint, lock/unlock):
760 * mem->tex->fb
761 * 2.blt
762 * srcTex->invFB->tex->fb
763 * |->mem
764 *
765 * II. Yinverted surface:
766 * 1.direct memory update (paint, lock/unlock):
767 * mem->tex->fb
768 * 2.blt
769 * srcTex->fb->tex
770 * |->mem
771 *
772 * III. flip support:
773 * 1. Yinverted<->NON-YInverted conversion :
774 * mem->tex-(rotate model view, force LAZY complete fb update)->invFB->tex
775 * fb-->| |->mem
776 * */
777class VBoxVHWASurfaceBase
778{
779public:
780 VBoxVHWASurfaceBase(
781 class VBoxGLWidget *mWidget,
782#if 0
783 class VBoxVHWAGlContextState *aState,
784 bool aIsYInverted,
785#endif
786 const QSize * aSize, const QSize * aTargetSize,
787 VBoxVHWAColorFormat & aColorFormat,
788 VBoxVHWAColorKey * pSrcBltCKey, VBoxVHWAColorKey * pDstBltCKey,
789 VBoxVHWAColorKey * pSrcOverlayCKey, VBoxVHWAColorKey * pDstOverlayCKey,
790 bool bVGA);
791
792 virtual ~VBoxVHWASurfaceBase();
793
794 void init(VBoxVHWASurfaceBase * pPrimary, uchar *pvMem);
795 void setupMatricies(VBoxVHWASurfaceBase *pPrimary);
796
797 void uninit();
798
799 static void globalInit();
800
801// int blt(const QRect * aDstRect, VBoxVHWASurfaceBase * aSrtSurface, const QRect * aSrcRect, const VBoxVHWAColorKey * pDstCKeyOverride, const VBoxVHWAColorKey * pSrcCKeyOverride);
802// int overlay(VBoxVHWASurfaceBase * aOverlaySurface);
803
804 int lock(const QRect * pRect, uint32_t flags);
805
806 int unlock();
807
808 void updatedMem(const QRect * aRect);
809
810 void performDisplay(VBoxVHWASurfaceBase *pPrimary);
811
812 void setRects(VBoxVHWASurfaceBase *pPrimary, const QRect * aTargRect, const QRect * aSrcRect);
813 void setTargetRectPosition(VBoxVHWASurfaceBase *pPrimary, const QPoint * aPoint);
814
815 static ulong calcBytesPerPixel(GLenum format, GLenum type);
816
817 static GLsizei makePowerOf2(GLsizei val);
818
819 bool addressAlocated() const { return mFreeAddress; }
820 uchar * address(){ return mAddress; }
821
822 ulong memSize();
823
824 ulong width() { return mRect.width(); }
825 ulong height() { return mRect.height(); }
826
827 GLenum format() {return mColorFormat.format(); }
828 GLint internalFormat() { return mColorFormat.internalFormat(); }
829 GLenum type() { return mColorFormat.type(); }
830 uint32_t fourcc() {return mColorFormat.fourcc(); }
831
832// ulong bytesPerPixel() { return mpTex[0]->bytesPerPixel(); }
833 ulong bitsPerPixel() { return mColorFormat.bitsPerPixel(); }
834// ulong bitsPerPixelDd() { return mColorFormat.bitsPerPixelDd(); }
835 ulong bytesPerLine() { return mpTex[0]->bytesPerLine(); }
836
837 const VBoxVHWAColorKey * dstBltCKey() const { return mpDstBltCKey; }
838 const VBoxVHWAColorKey * srcBltCKey() const { return mpSrcBltCKey; }
839 const VBoxVHWAColorKey * dstOverlayCKey() const { return mpDstOverlayCKey; }
840 const VBoxVHWAColorKey * defaultSrcOverlayCKey() const { return mpDefaultSrcOverlayCKey; }
841 const VBoxVHWAColorKey * defaultDstOverlayCKey() const { return mpDefaultDstOverlayCKey; }
842 const VBoxVHWAColorKey * srcOverlayCKey() const { return mpSrcOverlayCKey; }
843 void resetDefaultSrcOverlayCKey() { mpSrcOverlayCKey = mpDefaultSrcOverlayCKey; }
844 void resetDefaultDstOverlayCKey() { mpDstOverlayCKey = mpDefaultDstOverlayCKey; }
845
846 void setDstBltCKey(const VBoxVHWAColorKey * ckey)
847 {
848 if(ckey)
849 {
850 mDstBltCKey = *ckey;
851 mpDstBltCKey = &mDstBltCKey;
852 }
853 else
854 {
855 mpDstBltCKey = NULL;
856 }
857 }
858
859 void setSrcBltCKey(const VBoxVHWAColorKey * ckey)
860 {
861 if(ckey)
862 {
863 mSrcBltCKey = *ckey;
864 mpSrcBltCKey = &mSrcBltCKey;
865 }
866 else
867 {
868 mpSrcBltCKey = NULL;
869 }
870 }
871
872 void setDefaultDstOverlayCKey(const VBoxVHWAColorKey * ckey)
873 {
874 if(ckey)
875 {
876 mDefaultDstOverlayCKey = *ckey;
877 mpDefaultDstOverlayCKey = &mDefaultDstOverlayCKey;
878 }
879 else
880 {
881 mpDefaultDstOverlayCKey = NULL;
882 }
883 }
884
885 void setDefaultSrcOverlayCKey(const VBoxVHWAColorKey * ckey)
886 {
887 if(ckey)
888 {
889 mDefaultSrcOverlayCKey = *ckey;
890 mpDefaultSrcOverlayCKey = &mDefaultSrcOverlayCKey;
891 }
892 else
893 {
894 mpDefaultSrcOverlayCKey = NULL;
895 }
896 }
897
898 void setOverriddenDstOverlayCKey(const VBoxVHWAColorKey * ckey)
899 {
900 if(ckey)
901 {
902 mOverriddenDstOverlayCKey = *ckey;
903 mpDstOverlayCKey = &mOverriddenDstOverlayCKey;
904 }
905 else
906 {
907 mpDstOverlayCKey = NULL;
908 }
909 }
910
911 void setOverriddenSrcOverlayCKey(const VBoxVHWAColorKey * ckey)
912 {
913 if(ckey)
914 {
915 mOverriddenSrcOverlayCKey = *ckey;
916 mpSrcOverlayCKey = &mOverriddenSrcOverlayCKey;
917 }
918 else
919 {
920 mpSrcOverlayCKey = NULL;
921 }
922 }
923
924 const VBoxVHWAColorKey * getActiveSrcOverlayCKey()
925 {
926 return mpSrcOverlayCKey;
927 }
928
929 const VBoxVHWAColorKey * getActiveDstOverlayCKey(VBoxVHWASurfaceBase * pPrimary)
930 {
931 return mpDstOverlayCKey ? mpDefaultDstOverlayCKey : pPrimary->mpDstOverlayCKey;
932 }
933
934 const VBoxVHWAColorFormat & colorFormat() {return mColorFormat; }
935
936 /* clients should treat the returned texture as read-only */
937// GLuint textureSynched(const QRect * aRect) { /*synchTex(aRect); */synchTexMem(aRect); return mTexture; }
938
939 void setAddress(uchar * addr);
940
941 const QRect& rect() {return mRect;}
942// const QRect& texRect() {return mTexRect;}
943
944// /* surface currently being displayed in a flip chain */
945// virtual bool isPrimary() = 0;
946// /* surface representing the main framebuffer. */
947// virtual bool isMainFramebuffer() = 0;
948#if 0
949 virtual void makeCurrent() = 0;
950 virtual void makeYInvertedCurrent() = 0;
951 bool isYInverted() {return mIsYInverted; }
952
953 bool isHidden() {return mIsYInverted; }
954 void setHidden(bool hidden)
955 {
956 if(hidden == mIsYInverted)
957 return;
958
959 invert();
960 }
961 int invert();
962
963 bool isFrontBuffer() {return !mIsYInverted; }
964#endif
965
966 class VBoxVHWASurfList * getComplexList() {return mComplexList; }
967
968 class VBoxVHWAGlProgramMngr * getGlProgramMngr();
969 static int setCKey(class VBoxVHWAGlProgramVHWA * pProgram, const VBoxVHWAColorFormat * pFormat, const VBoxVHWAColorKey * pCKey, bool bDst);
970private:
971 void setComplexList(VBoxVHWASurfList *aComplexList) { mComplexList = aComplexList; }
972 void initDisplay(VBoxVHWASurfaceBase *pPrimary);
973 void deleteDisplay();
974// void initDisplay(bool bInverted);
975// void deleteDisplay(bool bInverted);
976 GLuint createDisplay(VBoxVHWASurfaceBase *pPrimary
977#if 0
978 bool bInverted
979#endif
980 );
981 void doDisplay(VBoxVHWASurfaceBase *pPrimary, VBoxVHWAGlProgramVHWA * pProgram, bool bBindDst);
982 void synchTexMem(const QRect * aRect);
983#if 0
984 void synchTex(const QRect * aRect);
985 void synchTexFB(const QRect * aRect);
986 void synchMem(const QRect * aRect);
987 void synchFB(const QRect * aRect);
988 void synch(const QRect * aRect);
989#endif
990 int performBlt(const QRect * pDstRect, VBoxVHWASurfaceBase * pSrcSurface, const QRect * pSrcRect, const VBoxVHWAColorKey * pDstCKey, const VBoxVHWAColorKey * pSrcCKey, bool blt);
991
992// void doTex2FB(const QRect * aRect);
993 void doTex2FB(const QRect * pDstRect, const QRect * pSrcRect);
994 void doMultiTex2FB(const QRect * pDstRect, VBoxVHWATexture * pDstTex, const QRect * pSrcRect, int cSrcTex);
995 void doMultiTex2FB(const QRect * pDstRect, const QRect * pSrcRect, int cSrcTex);
996// void doMultiTex2FB(GLenum tex, const QRect * pDstRect, const QRect * pSrcRect);
997
998 void doSetupMatrix(const QSize * pSize , bool bInverted);
999
1000 QRect mRect; /* == Inv FB size */
1001// QRect mTexRect; /* texture size */
1002
1003 QRect mSrcRect;
1004 QRect mTargRect; /* == Vis FB size */
1005 QRect mTargSize;
1006#if 0
1007 GLuint mYInvertedDisplay;
1008#endif
1009 GLuint mVisibleDisplay;
1010#if 0
1011 bool mYInvertedDisplayInitialized;
1012#endif
1013 bool mVisibleDisplayInitialized;
1014
1015 uchar * mAddress;
1016 VBoxVHWATexture *mpTex[3];
1017
1018 VBoxVHWAColorFormat mColorFormat;
1019
1020 VBoxVHWAColorKey *mpSrcBltCKey;
1021 VBoxVHWAColorKey *mpDstBltCKey;
1022 VBoxVHWAColorKey *mpSrcOverlayCKey;
1023 VBoxVHWAColorKey *mpDstOverlayCKey;
1024
1025 VBoxVHWAColorKey *mpDefaultDstOverlayCKey;
1026 VBoxVHWAColorKey *mpDefaultSrcOverlayCKey;
1027
1028 VBoxVHWAColorKey mSrcBltCKey;
1029 VBoxVHWAColorKey mDstBltCKey;
1030 VBoxVHWAColorKey mOverriddenSrcOverlayCKey;
1031 VBoxVHWAColorKey mOverriddenDstOverlayCKey;
1032 VBoxVHWAColorKey mDefaultDstOverlayCKey;
1033 VBoxVHWAColorKey mDefaultSrcOverlayCKey;
1034
1035
1036// GLenum mFormat;
1037// GLint mInternalFormat;
1038// GLenum mType;
1039// ulong mDisplayWidth;
1040// ulong mDisplayHeight;
1041// ulong mBytesPerPixel;
1042// ulong mBytesPerLine;
1043
1044 int mLockCount;
1045 /* memory buffer not reflected in fm and texture, e.g if memory buffer is replaced or in case of lock/unlock */
1046 VBoxVHWADirtyRect mUpdateMem2TexRect;
1047#if 0
1048 /* memory buffer not reflected in fm and texture, e.g if memory buffer is replaced or in case of lock/unlock */
1049 VBoxVHWADirtyRect mUpdateTex2FBRect;
1050 /*in case of blit we blit from another surface's texture, so our current texture gets durty */
1051 VBoxVHWADirtyRect mUpdateFB2TexRect;
1052 /*in case of blit the memory buffer does not get updated until we need it, e.g. for paint or lock operations */
1053 VBoxVHWADirtyRect mUpdateFB2MemRect;
1054#endif
1055
1056 bool mFreeAddress;
1057#if 0
1058 bool mIsYInverted;
1059#endif
1060
1061 class VBoxVHWASurfList *mComplexList;
1062
1063 class VBoxGLWidget *mWidget;
1064protected:
1065#if 0
1066 virtual void init(uchar *pvMem, bool bInverted);
1067 class VBoxVHWAGlContextState *mState;
1068#endif
1069
1070 friend class VBoxVHWASurfList;
1071
1072};
1073
1074typedef std::list <VBoxVHWASurfaceBase*> SurfList;
1075
1076class VBoxVHWASurfList
1077{
1078public:
1079
1080 VBoxVHWASurfList() : mCurrent(NULL) {}
1081 void add(VBoxVHWASurfaceBase *pSurf)
1082 {
1083 VBoxVHWASurfList * pOld = pSurf->getComplexList();
1084 if(pOld)
1085 {
1086 pOld->remove(pSurf);
1087 }
1088 mSurfaces.push_back(pSurf);
1089 pSurf->setComplexList(this);
1090 }
1091
1092 void clear()
1093 {
1094 for (SurfList::iterator it = mSurfaces.begin();
1095 it != mSurfaces.end(); ++ it)
1096 {
1097 (*it)->setComplexList(NULL);
1098 }
1099 mSurfaces.clear();
1100 mCurrent = NULL;
1101 }
1102
1103 void remove(VBoxVHWASurfaceBase *pSurf)
1104 {
1105 mSurfaces.remove(pSurf);
1106 pSurf->setComplexList(NULL);
1107 if(mCurrent == pSurf)
1108 mCurrent = NULL;
1109 }
1110
1111 bool empty() { return mSurfaces.empty(); }
1112
1113 void setCurrentVisible(VBoxVHWASurfaceBase *pSurf)
1114 {
1115 mCurrent = pSurf;
1116 }
1117
1118 VBoxVHWASurfaceBase * current() { return mCurrent; }
1119 const SurfList & surfaces() const {return mSurfaces;}
1120
1121private:
1122
1123 SurfList mSurfaces;
1124 VBoxVHWASurfaceBase* mCurrent;
1125};
1126
1127class VBoxVHWADisplay
1128{
1129public:
1130 VBoxVHWADisplay() :
1131 mSurfVGA(NULL)
1132// ,
1133// mSurfPrimary(NULL)
1134 {}
1135
1136 VBoxVHWASurfaceBase * setVGA(VBoxVHWASurfaceBase * pVga)
1137 {
1138 VBoxVHWASurfaceBase * old = mSurfVGA;
1139 mSurfVGA = pVga;
1140 mPrimary.clear();
1141 if(pVga)
1142 {
1143 mPrimary.add(pVga);
1144 mPrimary.setCurrentVisible(pVga);
1145 }
1146// mSurfPrimary = pVga;
1147 mOverlays.clear();
1148 return old;
1149 }
1150
1151 VBoxVHWASurfaceBase * getVGA()
1152 {
1153 return mSurfVGA;
1154 }
1155
1156 VBoxVHWASurfaceBase * getPrimary()
1157 {
1158 return mPrimary.current();
1159 }
1160//
1161// void setPrimary(VBoxVHWASurfList * pSurf)
1162// {
1163// mSurfPrimary = pSurf;
1164// }
1165
1166 void addOverlay(VBoxVHWASurfList * pSurf)
1167 {
1168 mOverlays.push_back(pSurf);
1169 }
1170
1171 void checkAddOverlay(VBoxVHWASurfList * pSurf)
1172 {
1173 if(!hasOverlay(pSurf))
1174 addOverlay(pSurf);
1175 }
1176
1177 bool hasOverlay(VBoxVHWASurfList * pSurf)
1178 {
1179 for (OverlayList::iterator it = mOverlays.begin();
1180 it != mOverlays.end(); ++ it)
1181 {
1182 if((*it) == pSurf)
1183 {
1184 return true;
1185 }
1186 }
1187 return false;
1188 }
1189
1190 void removeOverlay(VBoxVHWASurfList * pSurf)
1191 {
1192 mOverlays.remove(pSurf);
1193 }
1194
1195
1196 void performDisplay()
1197 {
1198 VBoxVHWASurfaceBase * pPrimary = mPrimary.current();
1199 pPrimary->performDisplay(NULL);
1200
1201 for (OverlayList::const_iterator it = mOverlays.begin();
1202 it != mOverlays.end(); ++ it)
1203 {
1204 VBoxVHWASurfaceBase * pOverlay = (*it)->current();
1205 if(pOverlay)
1206 {
1207 pOverlay->performDisplay(pPrimary);
1208// pPrimary->overlay(pOverlay);
1209 }
1210 }
1211 }
1212
1213private:
1214 VBoxVHWASurfaceBase *mSurfVGA;
1215 VBoxVHWASurfList mPrimary;
1216
1217 typedef std::list <VBoxVHWASurfList*> OverlayList;
1218
1219 OverlayList mOverlays;
1220};
1221
1222class VBoxGLWidget : public QGLWidget
1223{
1224public:
1225 VBoxGLWidget (VBoxConsoleView *aView, QWidget *aParent);
1226 ~VBoxGLWidget();
1227
1228 ulong vboxPixelFormat() { return mPixelFormat; }
1229 bool vboxUsesGuestVRAM() { return mUsesGuestVRAM; }
1230
1231 uchar *vboxAddress() { return mDisplay.getVGA() ? mDisplay.getVGA()->address() : NULL; }
1232#ifdef VBOX_WITH_VIDEOHWACCEL
1233 uchar *vboxVRAMAddressFromOffset(uint64_t offset);
1234#endif
1235 ulong vboxBitsPerPixel() { return mDisplay.getVGA()->bitsPerPixel(); }
1236 ulong vboxBytesPerLine() { return mDisplay.getVGA() ? mDisplay.getVGA()->bytesPerLine() : NULL; }
1237
1238typedef void (VBoxGLWidget::*PFNVBOXQGLOP)(void* );
1239//typedef FNVBOXQGLOP *PFNVBOXQGLOP;
1240
1241 void vboxPaintEvent (QPaintEvent *pe) {vboxPerformGLOp(&VBoxGLWidget::vboxDoPaint, pe);}
1242 void vboxResizeEvent (VBoxResizeEvent *re) {vboxPerformGLOp(&VBoxGLWidget::vboxDoResize, re);}
1243//#ifdef VBOXQGL_DBG_SURF
1244// void vboxTestSurfaces () {vboxPerformGLOp(&VBoxGLWidget::vboxDoTestSurfaces, NULL);}
1245//#endif
1246 void vboxProcessVHWACommands(VBoxVHWACommandProcessEvent * pEvent) {vboxPerformGLOp(&VBoxGLWidget::vboxDoProcessVHWACommands, pEvent);}
1247#ifdef VBOX_WITH_VIDEOHWACCEL
1248 void vboxVHWACmd (struct _VBOXVHWACMD * pCmd) {vboxPerformGLOp(&VBoxGLWidget::vboxDoVHWACmd, pCmd);}
1249#endif
1250 class VBoxVHWAGlProgramMngr * vboxVHWAGetGlProgramMngr() { return mpMngr; }
1251
1252 VBoxVHWASurfaceBase * vboxGetVGASurface() { return mDisplay.getVGA(); }
1253
1254 void postCmd(VBOXVHWA_PIPECMD_TYPE aType, void * pvData);
1255protected:
1256// void resizeGL (int height, int width);
1257
1258 void paintGL()
1259 {
1260// Assert(mState.getCurrent() == NULL);
1261// /* we are called with QGLWidget context */
1262// mState.assertCurrent(mDisplay.getVGA(), false);
1263 if(mpfnOp)
1264 {
1265 (this->*mpfnOp)(mOpContext);
1266 mpfnOp = NULL;
1267 }
1268 else
1269 {
1270 mDisplay.performDisplay();
1271 }
1272// /* restore the context */
1273// mState.makeCurrent(mDisplay.getVGA());
1274// /* clear*/
1275// mState.assertCurrent(NULL, false);
1276 }
1277
1278 void initializeGL();
1279private:
1280// void vboxDoInitDisplay();
1281// void vboxDoDeleteDisplay();
1282// void vboxDoPerformDisplay() { Assert(mDisplayInitialized); glCallList(mDisplay); }
1283 void vboxDoResize(void *re);
1284 void vboxDoPaint(void *rec);
1285
1286 void vboxDoUpdateRect(const QRect * pRect);
1287#ifdef VBOXQGL_DBG_SURF
1288 void vboxDoTestSurfaces(void *context);
1289#endif
1290#ifdef VBOX_WITH_VIDEOHWACCEL
1291 void vboxDoVHWACmd(void *cmd);
1292 void vboxCheckUpdateAddress (VBoxVHWASurfaceBase * pSurface, uint64_t offset)
1293 {
1294#ifndef VBOXQGL_DBG_SURF
1295 if(offset == 0xffffffff)
1296 {
1297 return;
1298 }
1299#endif
1300 if (pSurface->addressAlocated())
1301 {
1302 uchar * addr = vboxVRAMAddressFromOffset(offset);
1303 if(addr)
1304 {
1305 pSurface->setAddress(addr);
1306 }
1307 }
1308 }
1309 int vhwaSurfaceCanCreate(struct _VBOXVHWACMD_SURF_CANCREATE *pCmd);
1310 int vhwaSurfaceCreate(struct _VBOXVHWACMD_SURF_CREATE *pCmd);
1311 int vhwaSurfaceDestroy(struct _VBOXVHWACMD_SURF_DESTROY *pCmd);
1312 int vhwaSurfaceLock(struct _VBOXVHWACMD_SURF_LOCK *pCmd);
1313 int vhwaSurfaceUnlock(struct _VBOXVHWACMD_SURF_UNLOCK *pCmd);
1314 int vhwaSurfaceBlt(struct _VBOXVHWACMD_SURF_BLT *pCmd);
1315 int vhwaSurfaceFlip(struct _VBOXVHWACMD_SURF_FLIP *pCmd);
1316 int vhwaSurfaceOverlayUpdate(struct _VBOXVHWACMD_SURF_OVERLAY_UPDATE *pCmf);
1317 int vhwaSurfaceOverlaySetPosition(struct _VBOXVHWACMD_SURF_OVERLAY_SETPOSITION *pCmd);
1318 int vhwaSurfaceColorkeySet(struct _VBOXVHWACMD_SURF_COLORKEY_SET *pCmd);
1319 int vhwaQueryInfo1(struct _VBOXVHWACMD_QUERYINFO1 *pCmd);
1320 int vhwaQueryInfo2(struct _VBOXVHWACMD_QUERYINFO2 *pCmd);
1321
1322 void vhwaDoSurfaceOverlayUpdate(VBoxVHWASurfaceBase *pDstSurf, VBoxVHWASurfaceBase *pSrcSurf, struct _VBOXVHWACMD_SURF_OVERLAY_UPDATE *pCmd);
1323#endif
1324 static const QGLFormat & vboxGLFormat();
1325
1326// VBoxVHWASurfaceQGL * pDisplay;
1327 VBoxVHWADisplay mDisplay;
1328
1329
1330 /* we need to do all opengl stuff in the paintGL context,
1331 * submit the operation to be performed */
1332 void vboxPerformGLOp(PFNVBOXQGLOP pfn, void* pContext) {mpfnOp = pfn; mOpContext = pContext; updateGL();}
1333
1334 void cmdPipeInit();
1335 void cmdPipeDelete();
1336 void vboxDoProcessVHWACommands(void *pContext);
1337
1338 VBoxVHWACommandElement * detachCmdList(VBoxVHWACommandElement * pFirst2Free, VBoxVHWACommandElement * pLast2Free);
1339 VBoxVHWACommandElement * processCmdList(VBoxVHWACommandElement * pCmd);
1340
1341 PFNVBOXQGLOP mpfnOp;
1342 void *mOpContext;
1343
1344// ulong mBitsPerPixel;
1345 ulong mPixelFormat;
1346 bool mUsesGuestVRAM;
1347#if 0
1348 VBoxVHWAGlContextState mState;
1349#endif
1350
1351 RTCRITSECT mCritSect;
1352 VBoxVHWACommandProcessEvent *mpFirstEvent;
1353 VBoxVHWACommandProcessEvent *mpLastEvent;
1354 bool mbNewEvent;
1355 VBoxVHWACommandElementStack mFreeElements;
1356 VBoxVHWACommandElement mElementsBuffer[2048];
1357
1358 VBoxConsoleView *mView;
1359
1360 VBoxVHWASurfList *mConstructingList;
1361 int32_t mcRemaining2Contruct;
1362
1363 class VBoxVHWAGlProgramMngr *mpMngr;
1364};
1365
1366
1367class VBoxQGLFrameBuffer : public VBoxFrameBuffer
1368{
1369public:
1370
1371 VBoxQGLFrameBuffer (VBoxConsoleView *aView);
1372
1373 STDMETHOD(NotifyUpdate) (ULONG aX, ULONG aY,
1374 ULONG aW, ULONG aH);
1375#ifdef VBOXQGL_PROF_BASE
1376 STDMETHOD(RequestResize) (ULONG aScreenId, ULONG aPixelFormat,
1377 BYTE *aVRAM, ULONG aBitsPerPixel, ULONG aBytesPerLine,
1378 ULONG aWidth, ULONG aHeight,
1379 BOOL *aFinished);
1380#endif
1381
1382#ifdef VBOX_WITH_VIDEOHWACCEL
1383 STDMETHOD(ProcessVHWACommand)(BYTE *pCommand);
1384#endif
1385
1386 ulong pixelFormat() { return vboxWidget()->vboxPixelFormat(); }
1387 bool usesGuestVRAM() { return vboxWidget()->vboxUsesGuestVRAM(); }
1388
1389 uchar *address() { return vboxWidget()->vboxAddress(); }
1390 ulong bitsPerPixel() { return vboxWidget()->vboxBitsPerPixel(); }
1391 ulong bytesPerLine() { return vboxWidget()->vboxBytesPerLine(); }
1392
1393 void paintEvent (QPaintEvent *pe);
1394 void resizeEvent (VBoxResizeEvent *re);
1395 void doProcessVHWACommand(VBoxVHWACommandProcessEvent * pEvent);
1396
1397private:
1398// void vboxMakeCurrent();
1399 VBoxGLWidget * vboxWidget();
1400};
1401
1402
1403#endif
1404
1405/////////////////////////////////////////////////////////////////////////////
1406
1407#if defined (VBOX_GUI_USE_SDL)
1408
1409class VBoxSDLFrameBuffer : public VBoxFrameBuffer
1410{
1411public:
1412
1413 VBoxSDLFrameBuffer (VBoxConsoleView *aView);
1414 virtual ~VBoxSDLFrameBuffer();
1415
1416 STDMETHOD(NotifyUpdate) (ULONG aX, ULONG aY,
1417 ULONG aW, ULONG aH);
1418
1419 uchar *address()
1420 {
1421 SDL_Surface *surf = mSurfVRAM ? mSurfVRAM : mScreen;
1422 return surf ? (uchar *) (uintptr_t) surf->pixels : 0;
1423 }
1424
1425 ulong bitsPerPixel()
1426 {
1427 SDL_Surface *surf = mSurfVRAM ? mSurfVRAM : mScreen;
1428 return surf ? surf->format->BitsPerPixel : 0;
1429 }
1430
1431 ulong bytesPerLine()
1432 {
1433 SDL_Surface *surf = mSurfVRAM ? mSurfVRAM : mScreen;
1434 return surf ? surf->pitch : 0;
1435 }
1436
1437 ulong pixelFormat()
1438 {
1439 return mPixelFormat;
1440 }
1441
1442 bool usesGuestVRAM()
1443 {
1444 return mSurfVRAM != NULL;
1445 }
1446
1447 void paintEvent (QPaintEvent *pe);
1448 void resizeEvent (VBoxResizeEvent *re);
1449
1450private:
1451
1452 SDL_Surface *mScreen;
1453 SDL_Surface *mSurfVRAM;
1454
1455 ulong mPixelFormat;
1456};
1457
1458#endif
1459
1460/////////////////////////////////////////////////////////////////////////////
1461
1462#if defined (VBOX_GUI_USE_DDRAW)
1463
1464class VBoxDDRAWFrameBuffer : public VBoxFrameBuffer
1465{
1466public:
1467
1468 VBoxDDRAWFrameBuffer (VBoxConsoleView *aView);
1469 virtual ~VBoxDDRAWFrameBuffer();
1470
1471 STDMETHOD(NotifyUpdate) (ULONG aX, ULONG aY,
1472 ULONG aW, ULONG aH);
1473
1474 uchar *address() { return (uchar *) mSurfaceDesc.lpSurface; }
1475 ulong bitsPerPixel() { return mSurfaceDesc.ddpfPixelFormat.dwRGBBitCount; }
1476 ulong bytesPerLine() { return (ulong) mSurfaceDesc.lPitch; }
1477
1478 ulong pixelFormat() { return mPixelFormat; };
1479
1480 bool usesGuestVRAM() { return mUsesGuestVRAM; }
1481
1482 void paintEvent (QPaintEvent *pe);
1483 void resizeEvent (VBoxResizeEvent *re);
1484 void moveEvent (QMoveEvent *me);
1485
1486private:
1487
1488 void releaseObjects();
1489
1490 bool createSurface (ULONG aPixelFormat, uchar *pvVRAM,
1491 ULONG aBitsPerPixel, ULONG aBytesPerLine,
1492 ULONG aWidth, ULONG aHeight);
1493 void deleteSurface();
1494 void drawRect (ULONG x, ULONG y, ULONG w, ULONG h);
1495 void getWindowPosition (void);
1496
1497 LPDIRECTDRAW7 mDDRAW;
1498 LPDIRECTDRAWCLIPPER mClipper;
1499 LPDIRECTDRAWSURFACE7 mSurface;
1500 DDSURFACEDESC2 mSurfaceDesc;
1501 LPDIRECTDRAWSURFACE7 mPrimarySurface;
1502
1503 ulong mPixelFormat;
1504
1505 bool mUsesGuestVRAM;
1506
1507 int mWndX;
1508 int mWndY;
1509
1510 bool mSynchronousUpdates;
1511};
1512
1513#endif
1514
1515/////////////////////////////////////////////////////////////////////////////
1516
1517#if defined (Q_WS_MAC) && defined (VBOX_GUI_USE_QUARTZ2D)
1518
1519#include <Carbon/Carbon.h>
1520
1521class VBoxQuartz2DFrameBuffer : public VBoxFrameBuffer
1522{
1523public:
1524
1525 VBoxQuartz2DFrameBuffer (VBoxConsoleView *aView);
1526 virtual ~VBoxQuartz2DFrameBuffer ();
1527
1528 STDMETHOD (NotifyUpdate) (ULONG aX, ULONG aY,
1529 ULONG aW, ULONG aH);
1530 STDMETHOD (SetVisibleRegion) (BYTE *aRectangles, ULONG aCount);
1531
1532 uchar *address() { return mDataAddress; }
1533 ulong bitsPerPixel() { return CGImageGetBitsPerPixel (mImage); }
1534 ulong bytesPerLine() { return CGImageGetBytesPerRow (mImage); }
1535 ulong pixelFormat() { return mPixelFormat; };
1536 bool usesGuestVRAM() { return mBitmapData == NULL; }
1537
1538 const CGImageRef imageRef() const { return mImage; }
1539
1540 void paintEvent (QPaintEvent *pe);
1541 void resizeEvent (VBoxResizeEvent *re);
1542
1543private:
1544
1545 void clean();
1546
1547 uchar *mDataAddress;
1548 void *mBitmapData;
1549 ulong mPixelFormat;
1550 CGImageRef mImage;
1551 typedef struct
1552 {
1553 /** The size of this structure expressed in rcts entries. */
1554 ULONG allocated;
1555 /** The number of entries in the rcts array. */
1556 ULONG used;
1557 /** Variable sized array of the rectangle that makes up the region. */
1558 CGRect rcts[1];
1559 } RegionRects;
1560 /** The current valid region, all access is by atomic cmpxchg or atomic xchg.
1561 *
1562 * The protocol for updating and using this has to take into account that
1563 * the producer (SetVisibleRegion) and consumer (paintEvent) are running
1564 * on different threads. Therefore the producer will create a new RegionRects
1565 * structure before atomically replace the existing one. While the consumer
1566 * will read the value by atomically replace it by NULL, and then when its
1567 * done try restore it by cmpxchg. If the producer has already put a new
1568 * region there, it will be discarded (see mRegionUnused).
1569 */
1570 RegionRects volatile *mRegion;
1571 /** For keeping the unused region and thus avoid some RTMemAlloc/RTMemFree calls.
1572 * This is operated with atomic cmpxchg and atomic xchg. */
1573 RegionRects volatile *mRegionUnused;
1574};
1575
1576#endif /* Q_WS_MAC && VBOX_GUI_USE_QUARTZ2D */
1577
1578#endif // !___VBoxFrameBuffer_h___
Note: See TracBrowser for help on using the repository browser.

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