VirtualBox

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

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

warning

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