1 | /* $Id: UIFrameBuffer.cpp 31698 2010-08-16 15:00:05Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | *
|
---|
4 | * VBox frontends: Qt GUI ("VirtualBox"):
|
---|
5 | * UIFrameBuffer class and subclasses implementation
|
---|
6 | */
|
---|
7 |
|
---|
8 | /*
|
---|
9 | * Copyright (C) 2010 Oracle Corporation
|
---|
10 | *
|
---|
11 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
12 | * available from http://www.virtualbox.org. This file is free software;
|
---|
13 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
14 | * General Public License (GPL) as published by the Free Software
|
---|
15 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
16 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
17 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
18 | */
|
---|
19 |
|
---|
20 | #ifdef VBOX_WITH_PRECOMPILED_HEADERS
|
---|
21 | # include "precomp.h"
|
---|
22 | #else /* !VBOX_WITH_PRECOMPILED_HEADERS */
|
---|
23 |
|
---|
24 | /* Local includes */
|
---|
25 | # include "UIMachineView.h"
|
---|
26 | # include "UIFrameBuffer.h"
|
---|
27 | # include "VBoxProblemReporter.h"
|
---|
28 | # include "VBoxGlobal.h"
|
---|
29 |
|
---|
30 | #endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
|
---|
31 |
|
---|
32 | #if defined (Q_OS_WIN32)
|
---|
33 | static CComModule _Module;
|
---|
34 | #else
|
---|
35 | NS_DECL_CLASSINFO (UIFrameBuffer)
|
---|
36 | NS_IMPL_THREADSAFE_ISUPPORTS1_CI (UIFrameBuffer, IFramebuffer)
|
---|
37 | #endif
|
---|
38 |
|
---|
39 | UIFrameBuffer::UIFrameBuffer(UIMachineView *pMachineView)
|
---|
40 | : m_pMachineView(pMachineView)
|
---|
41 | , m_width(0), m_height(0)
|
---|
42 | , m_fIsDeleted(false)
|
---|
43 | #if defined (Q_OS_WIN32)
|
---|
44 | , m_iRefCnt(0)
|
---|
45 | #endif
|
---|
46 | {
|
---|
47 | AssertMsg(m_pMachineView, ("UIMachineView must not be null\n"));
|
---|
48 | m_WinId = (m_pMachineView && m_pMachineView->viewport()) ? (LONG64)m_pMachineView->viewport()->winId() : 0;
|
---|
49 | int rc = RTCritSectInit(&m_critSect);
|
---|
50 | AssertRC(rc);
|
---|
51 | }
|
---|
52 |
|
---|
53 | UIFrameBuffer::~UIFrameBuffer()
|
---|
54 | {
|
---|
55 | RTCritSectDelete(&m_critSect);
|
---|
56 | }
|
---|
57 |
|
---|
58 | STDMETHODIMP UIFrameBuffer::COMGETTER(Address) (BYTE **ppAddress)
|
---|
59 | {
|
---|
60 | if (!ppAddress)
|
---|
61 | return E_POINTER;
|
---|
62 | *ppAddress = address();
|
---|
63 | return S_OK;
|
---|
64 | }
|
---|
65 |
|
---|
66 | STDMETHODIMP UIFrameBuffer::COMGETTER(Width) (ULONG *puWidth)
|
---|
67 | {
|
---|
68 | if (!puWidth)
|
---|
69 | return E_POINTER;
|
---|
70 | *puWidth = (ULONG)width();
|
---|
71 | return S_OK;
|
---|
72 | }
|
---|
73 |
|
---|
74 | STDMETHODIMP UIFrameBuffer::COMGETTER(Height) (ULONG *puHeight)
|
---|
75 | {
|
---|
76 | if (!puHeight)
|
---|
77 | return E_POINTER;
|
---|
78 | *puHeight = (ULONG)height();
|
---|
79 | return S_OK;
|
---|
80 | }
|
---|
81 |
|
---|
82 | STDMETHODIMP UIFrameBuffer::COMGETTER(BitsPerPixel) (ULONG *puBitsPerPixel)
|
---|
83 | {
|
---|
84 | if (!puBitsPerPixel)
|
---|
85 | return E_POINTER;
|
---|
86 | *puBitsPerPixel = bitsPerPixel();
|
---|
87 | return S_OK;
|
---|
88 | }
|
---|
89 |
|
---|
90 | STDMETHODIMP UIFrameBuffer::COMGETTER(BytesPerLine) (ULONG *puBytesPerLine)
|
---|
91 | {
|
---|
92 | if (!puBytesPerLine)
|
---|
93 | return E_POINTER;
|
---|
94 | *puBytesPerLine = bytesPerLine();
|
---|
95 | return S_OK;
|
---|
96 | }
|
---|
97 |
|
---|
98 | STDMETHODIMP UIFrameBuffer::COMGETTER(PixelFormat) (ULONG *puPixelFormat)
|
---|
99 | {
|
---|
100 | if (!puPixelFormat)
|
---|
101 | return E_POINTER;
|
---|
102 | *puPixelFormat = pixelFormat();
|
---|
103 | return S_OK;
|
---|
104 | }
|
---|
105 |
|
---|
106 | STDMETHODIMP UIFrameBuffer::COMGETTER(UsesGuestVRAM) (BOOL *pbUsesGuestVRAM)
|
---|
107 | {
|
---|
108 | if (!pbUsesGuestVRAM)
|
---|
109 | return E_POINTER;
|
---|
110 | *pbUsesGuestVRAM = usesGuestVRAM();
|
---|
111 | return S_OK;
|
---|
112 | }
|
---|
113 |
|
---|
114 | STDMETHODIMP UIFrameBuffer::COMGETTER(HeightReduction) (ULONG *puHeightReduction)
|
---|
115 | {
|
---|
116 | if (!puHeightReduction)
|
---|
117 | return E_POINTER;
|
---|
118 | *puHeightReduction = 0;
|
---|
119 | return S_OK;
|
---|
120 | }
|
---|
121 |
|
---|
122 | STDMETHODIMP UIFrameBuffer::COMGETTER(Overlay) (IFramebufferOverlay **ppOverlay)
|
---|
123 | {
|
---|
124 | if (!ppOverlay)
|
---|
125 | return E_POINTER;
|
---|
126 | /* not yet implemented */
|
---|
127 | *ppOverlay = 0;
|
---|
128 | return S_OK;
|
---|
129 | }
|
---|
130 |
|
---|
131 | STDMETHODIMP UIFrameBuffer::COMGETTER(WinId) (LONG64 *pWinId)
|
---|
132 | {
|
---|
133 | if (!pWinId)
|
---|
134 | return E_POINTER;
|
---|
135 | *pWinId = m_WinId;
|
---|
136 | return S_OK;
|
---|
137 | }
|
---|
138 |
|
---|
139 | STDMETHODIMP UIFrameBuffer::Lock()
|
---|
140 | {
|
---|
141 | this->lock();
|
---|
142 | return S_OK;
|
---|
143 | }
|
---|
144 |
|
---|
145 | STDMETHODIMP UIFrameBuffer::Unlock()
|
---|
146 | {
|
---|
147 | this->unlock();
|
---|
148 | return S_OK;
|
---|
149 | }
|
---|
150 |
|
---|
151 | /** @note This method is called on EMT from under this object's lock */
|
---|
152 | STDMETHODIMP UIFrameBuffer::RequestResize(ULONG uScreenId, ULONG uPixelFormat,
|
---|
153 | BYTE *pVRAM, ULONG uBitsPerPixel, ULONG uBytesPerLine,
|
---|
154 | ULONG uWidth, ULONG uHeight,
|
---|
155 | BOOL *pbFinished)
|
---|
156 | {
|
---|
157 | if (m_fIsDeleted)
|
---|
158 | return E_FAIL;
|
---|
159 |
|
---|
160 | NOREF(uScreenId);
|
---|
161 | QApplication::postEvent (m_pMachineView,
|
---|
162 | new UIResizeEvent(uPixelFormat, pVRAM, uBitsPerPixel,
|
---|
163 | uBytesPerLine, uWidth, uHeight));
|
---|
164 |
|
---|
165 | *pbFinished = FALSE;
|
---|
166 | return S_OK;
|
---|
167 | }
|
---|
168 |
|
---|
169 | /**
|
---|
170 | * Returns whether we like the given video mode.
|
---|
171 | *
|
---|
172 | * @returns COM status code
|
---|
173 | * @param width video mode width in pixels
|
---|
174 | * @param height video mode height in pixels
|
---|
175 | * @param bpp video mode bit depth in bits per pixel
|
---|
176 | * @param supported pointer to result variable
|
---|
177 | */
|
---|
178 | STDMETHODIMP UIFrameBuffer::VideoModeSupported(ULONG uWidth, ULONG uHeight, ULONG uBPP, BOOL *pbSupported)
|
---|
179 | {
|
---|
180 | NOREF(uBPP);
|
---|
181 | LogFlowThisFunc(("width=%lu, height=%lu, BPP=%lu\n",
|
---|
182 | (unsigned long)uWidth, (unsigned long)uHeight, (unsigned long)uBPP));
|
---|
183 | if (!pbSupported)
|
---|
184 | return E_POINTER;
|
---|
185 | *pbSupported = TRUE;
|
---|
186 | QSize screen = m_pMachineView->desktopGeometry();
|
---|
187 | if ((screen.width() != 0) && (uWidth > (ULONG)screen.width()))
|
---|
188 | *pbSupported = FALSE;
|
---|
189 | if ((screen.height() != 0) && (uHeight > (ULONG)screen.height()))
|
---|
190 | *pbSupported = FALSE;
|
---|
191 | LogFlowThisFunc(("screenW=%lu, screenH=%lu -> aSupported=%s\n",
|
---|
192 | screen.width(), screen.height(), *pbSupported ? "TRUE" : "FALSE"));
|
---|
193 | return S_OK;
|
---|
194 | }
|
---|
195 |
|
---|
196 | STDMETHODIMP UIFrameBuffer::GetVisibleRegion(BYTE *pRectangles, ULONG uCount, ULONG *puCountCopied)
|
---|
197 | {
|
---|
198 | PRTRECT rects = (PRTRECT)pRectangles;
|
---|
199 |
|
---|
200 | if (!rects)
|
---|
201 | return E_POINTER;
|
---|
202 |
|
---|
203 | NOREF(uCount);
|
---|
204 | NOREF(puCountCopied);
|
---|
205 |
|
---|
206 | return S_OK;
|
---|
207 | }
|
---|
208 |
|
---|
209 | STDMETHODIMP UIFrameBuffer::SetVisibleRegion(BYTE *pRectangles, ULONG uCount)
|
---|
210 | {
|
---|
211 | PRTRECT rects = (PRTRECT)pRectangles;
|
---|
212 |
|
---|
213 | if (!rects)
|
---|
214 | return E_POINTER;
|
---|
215 |
|
---|
216 | QRegion reg;
|
---|
217 | for (ULONG ind = 0; ind < uCount; ++ ind)
|
---|
218 | {
|
---|
219 | QRect rect;
|
---|
220 | rect.setLeft(rects->xLeft);
|
---|
221 | rect.setTop(rects->yTop);
|
---|
222 | /* QRect are inclusive */
|
---|
223 | rect.setRight(rects->xRight - 1);
|
---|
224 | rect.setBottom(rects->yBottom - 1);
|
---|
225 | reg += rect;
|
---|
226 | ++ rects;
|
---|
227 | }
|
---|
228 | QApplication::postEvent(m_pMachineView, new UISetRegionEvent(reg));
|
---|
229 |
|
---|
230 | return S_OK;
|
---|
231 | }
|
---|
232 |
|
---|
233 | STDMETHODIMP UIFrameBuffer::ProcessVHWACommand(BYTE *pCommand)
|
---|
234 | {
|
---|
235 | Q_UNUSED(pCommand);
|
---|
236 | return E_NOTIMPL;
|
---|
237 | }
|
---|
238 |
|
---|
239 | #ifdef VBOX_WITH_VIDEOHWACCEL
|
---|
240 | void UIFrameBuffer::doProcessVHWACommand(QEvent *pEvent)
|
---|
241 | {
|
---|
242 | Q_UNUSED(pEvent);
|
---|
243 | /* should never be here */
|
---|
244 | AssertBreakpoint();
|
---|
245 | }
|
---|
246 |
|
---|
247 | void UIFrameBuffer::setView(UIMachineView * pView)
|
---|
248 | {
|
---|
249 | m_pMachineView = pView;
|
---|
250 | m_WinId = (m_pMachineView && m_pMachineView->viewport()) ? (LONG64)m_pMachineView->viewport()->winId() : 0;
|
---|
251 | }
|
---|
252 | #endif
|
---|