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