1 | /* $Id: VBoxFBQGL.cpp 22822 2009-09-07 19:33:48Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBoxFBQGL Opengl-based FrameBuffer implementation
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2009 Sun Microsystems, Inc.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | *
|
---|
17 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
18 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
19 | * additional information or have any questions.
|
---|
20 | */
|
---|
21 | #if defined (VBOX_GUI_USE_QGL)
|
---|
22 |
|
---|
23 | #define LOG_GROUP LOG_GROUP_GUI
|
---|
24 |
|
---|
25 | #include "VBoxFrameBuffer.h"
|
---|
26 |
|
---|
27 | #include "VBoxConsoleView.h"
|
---|
28 | //#include "VBoxProblemReporter.h"
|
---|
29 | //#include "VBoxGlobal.h"
|
---|
30 |
|
---|
31 | /* Qt includes */
|
---|
32 | #include <QGLWidget>
|
---|
33 |
|
---|
34 | //#include <iprt/asm.h>
|
---|
35 | //
|
---|
36 | #ifdef VBOX_WITH_VIDEOHWACCEL
|
---|
37 | #include <VBox/VBoxVideo.h>
|
---|
38 | //#include <VBox/types.h>
|
---|
39 | //#include <VBox/ssm.h>
|
---|
40 | #endif
|
---|
41 | //#include <iprt/semaphore.h>
|
---|
42 | //
|
---|
43 | //#include <QFile>
|
---|
44 | //#include <QTextStream>
|
---|
45 |
|
---|
46 |
|
---|
47 | /** @class VBoxQGLFrameBuffer
|
---|
48 | *
|
---|
49 | * The VBoxQImageFrameBuffer class is a class that implements the IFrameBuffer
|
---|
50 | * interface and uses QImage as the direct storage for VM display data. QImage
|
---|
51 | * is then converted to QPixmap and blitted to the console view widget.
|
---|
52 | */
|
---|
53 |
|
---|
54 | VBoxQGLFrameBuffer::VBoxQGLFrameBuffer (VBoxConsoleView *aView) :
|
---|
55 | VBoxFrameBuffer (aView),
|
---|
56 | mCmdPipe(aView)
|
---|
57 | {
|
---|
58 | // mWidget = new GLWidget(aView->viewport());
|
---|
59 | #ifndef VBOXQGL_PROF_BASE
|
---|
60 | resizeEvent (new VBoxResizeEvent (FramebufferPixelFormat_Opaque,
|
---|
61 | NULL, 0, 0, 640, 480));
|
---|
62 | #else
|
---|
63 | resizeEvent (new VBoxResizeEvent (FramebufferPixelFormat_Opaque,
|
---|
64 | NULL, 0, 0, VBOXQGL_PROF_WIDTH, VBOXQGL_PROF_HEIGHT));
|
---|
65 | #endif
|
---|
66 | }
|
---|
67 |
|
---|
68 | /** @note This method is called on EMT from under this object's lock */
|
---|
69 | STDMETHODIMP VBoxQGLFrameBuffer::NotifyUpdate (ULONG aX, ULONG aY,
|
---|
70 | ULONG aW, ULONG aH)
|
---|
71 | {
|
---|
72 | // /* We're not on the GUI thread and update() isn't thread safe in
|
---|
73 | // * Qt 4.3.x on the Win, Qt 3.3.x on the Mac (4.2.x is),
|
---|
74 | // * on Linux (didn't check Qt 4.x there) and probably on other
|
---|
75 | // * non-DOS platforms, so post the event instead. */
|
---|
76 | #ifdef VBOXQGL_PROF_BASE
|
---|
77 | QApplication::postEvent (mView,
|
---|
78 | new VBoxRepaintEvent (aX, aY, aW, aH));
|
---|
79 | #else
|
---|
80 | QRect r(aX, aY, aW, aH);
|
---|
81 | mCmdPipe.postCmd(VBOXVHWA_PIPECMD_PAINT, &r);
|
---|
82 | #endif
|
---|
83 | return S_OK;
|
---|
84 | }
|
---|
85 |
|
---|
86 | #ifdef VBOXQGL_PROF_BASE
|
---|
87 | STDMETHODIMP VBoxQGLFrameBuffer::RequestResize (ULONG aScreenId, ULONG aPixelFormat,
|
---|
88 | BYTE *aVRAM, ULONG aBitsPerPixel, ULONG aBytesPerLine,
|
---|
89 | ULONG aWidth, ULONG aHeight,
|
---|
90 | BOOL *aFinished)
|
---|
91 | {
|
---|
92 | aWidth = VBOXQGL_PROF_WIDTH;
|
---|
93 | aHeight = VBOXQGL_PROF_HEIGHT;
|
---|
94 | VBoxFrameBuffer::RequestResize (aScreenId, aPixelFormat,
|
---|
95 | aVRAM, aBitsPerPixel, aBytesPerLine,
|
---|
96 | aWidth, aHeight,
|
---|
97 | aFinished);
|
---|
98 |
|
---|
99 | // if(aVRAM)
|
---|
100 | {
|
---|
101 | for(;;)
|
---|
102 | {
|
---|
103 | ULONG aX = 0;
|
---|
104 | ULONG aY = 0;
|
---|
105 | ULONG aW = aWidth;
|
---|
106 | ULONG aH = aHeight;
|
---|
107 | NotifyUpdate (aX, aY, aW, aH);
|
---|
108 | RTThreadSleep(40);
|
---|
109 | }
|
---|
110 | }
|
---|
111 | return S_OK;
|
---|
112 | }
|
---|
113 | #endif
|
---|
114 |
|
---|
115 | VBoxGLWidget* VBoxQGLFrameBuffer::vboxWidget()
|
---|
116 | {
|
---|
117 | return (VBoxGLWidget*)mView->viewport();
|
---|
118 | }
|
---|
119 |
|
---|
120 | void VBoxQGLFrameBuffer::paintEvent (QPaintEvent *pe)
|
---|
121 | {
|
---|
122 | VBoxGLWidget * pw = vboxWidget();
|
---|
123 | pw->makeCurrent();
|
---|
124 |
|
---|
125 | QRect vp(mView->contentsX(), mView->contentsY(), pw->width(), pw->height());
|
---|
126 | if(vp != pw->vboxViewport())
|
---|
127 | {
|
---|
128 | pw->vboxDoUpdateViewport(vp);
|
---|
129 | }
|
---|
130 |
|
---|
131 | pw->performDisplay();
|
---|
132 |
|
---|
133 | pw->swapBuffers();
|
---|
134 | }
|
---|
135 |
|
---|
136 | void VBoxQGLFrameBuffer::resizeEvent (VBoxResizeEvent *re)
|
---|
137 | {
|
---|
138 | mWdt = re->width();
|
---|
139 | mHgt = re->height();
|
---|
140 |
|
---|
141 | vboxWidget()->vboxResizeEvent(re);
|
---|
142 | }
|
---|
143 |
|
---|
144 | /* processing the VHWA command, called from the GUI thread */
|
---|
145 | void VBoxQGLFrameBuffer::doProcessVHWACommand(QEvent * pEvent)
|
---|
146 | {
|
---|
147 | vboxWidget()->vboxProcessVHWACommands(&mCmdPipe);
|
---|
148 | }
|
---|
149 |
|
---|
150 |
|
---|
151 | #ifdef VBOX_WITH_VIDEOHWACCEL
|
---|
152 |
|
---|
153 | STDMETHODIMP VBoxQGLFrameBuffer::ProcessVHWACommand(BYTE *pCommand)
|
---|
154 | {
|
---|
155 | VBOXVHWACMD * pCmd = (VBOXVHWACMD*)pCommand;
|
---|
156 | // Assert(0);
|
---|
157 | /* indicate that we process and complete the command asynchronously */
|
---|
158 | pCmd->Flags |= VBOXVHWACMD_FLAG_HG_ASYNCH;
|
---|
159 | /* post the command to the GUI thread for processing */
|
---|
160 | // QApplication::postEvent (mView,
|
---|
161 | // new VBoxVHWACommandProcessEvent (pCmd));
|
---|
162 | mCmdPipe.postCmd(VBOXVHWA_PIPECMD_VHWA, pCmd);
|
---|
163 | return S_OK;
|
---|
164 | }
|
---|
165 |
|
---|
166 | #endif
|
---|
167 |
|
---|
168 | #endif
|
---|