1 | /*
|
---|
2 | * Copyright (C) 2010-2012 Oracle Corporation
|
---|
3 | *
|
---|
4 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
5 | * available from http://www.virtualbox.org. This file is free software;
|
---|
6 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
7 | * General Public License (GPL) as published by the Free Software
|
---|
8 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
9 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
10 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
11 | */
|
---|
12 |
|
---|
13 | #ifndef __NULL_FRAMEBUFFER_H
|
---|
14 | #define __NULL_FRAMEBUFFER_H
|
---|
15 |
|
---|
16 | #include <VBox/com/VirtualBox.h>
|
---|
17 | #include <iprt/alloc.h>
|
---|
18 |
|
---|
19 | class NullFB : VBOX_SCRIPTABLE_IMPL(IFramebuffer)
|
---|
20 | {
|
---|
21 | public:
|
---|
22 | NullFB()
|
---|
23 | :
|
---|
24 | mScreen(NULL), mBuffer(NULL),
|
---|
25 | mUsesGuestVRAM(false),
|
---|
26 | mWidth(0), mHeight(0)
|
---|
27 | #ifndef VBOX_WITH_XPCOM
|
---|
28 | , refcnt(0)
|
---|
29 | #endif
|
---|
30 | {}
|
---|
31 | virtual ~NullFB()
|
---|
32 | {
|
---|
33 | if (mBuffer)
|
---|
34 | RTMemFree(mBuffer);
|
---|
35 | }
|
---|
36 |
|
---|
37 | #ifndef VBOX_WITH_XPCOM
|
---|
38 | STDMETHOD_(ULONG, AddRef)() {
|
---|
39 | return ::InterlockedIncrement (&refcnt);
|
---|
40 | }
|
---|
41 | STDMETHOD_(ULONG, Release)() {
|
---|
42 | long cnt = ::InterlockedDecrement (&refcnt);
|
---|
43 | if (cnt == 0)
|
---|
44 | delete this;
|
---|
45 | return cnt;
|
---|
46 | }
|
---|
47 | #endif
|
---|
48 | VBOX_SCRIPTABLE_DISPATCH_IMPL(IFramebuffer)
|
---|
49 |
|
---|
50 | NS_DECL_ISUPPORTS
|
---|
51 |
|
---|
52 | // public methods only for internal purposes
|
---|
53 | HRESULT init ()
|
---|
54 | {
|
---|
55 |
|
---|
56 | RequestResize(0, FramebufferPixelFormat_Opaque, 0, 0, 0, 640, 480, 0);
|
---|
57 | return S_OK;
|
---|
58 | }
|
---|
59 |
|
---|
60 | STDMETHOD(COMGETTER(Width))(ULONG *width)
|
---|
61 | {
|
---|
62 | if (!width)
|
---|
63 | return E_POINTER;
|
---|
64 | *width = mWidth;
|
---|
65 | return S_OK;
|
---|
66 | }
|
---|
67 | STDMETHOD(COMGETTER(Height))(ULONG *height)
|
---|
68 | {
|
---|
69 | if (!height)
|
---|
70 | return E_POINTER;
|
---|
71 | *height = mHeight;
|
---|
72 | return S_OK;
|
---|
73 | }
|
---|
74 | STDMETHOD(Lock)()
|
---|
75 | {
|
---|
76 | return S_OK;
|
---|
77 | }
|
---|
78 | STDMETHOD(Unlock)()
|
---|
79 | {
|
---|
80 | return S_OK;
|
---|
81 | }
|
---|
82 | STDMETHOD(COMGETTER(Address))(BYTE **address)
|
---|
83 | {
|
---|
84 | if (!address)
|
---|
85 | return E_POINTER;
|
---|
86 | *address = mScreen;
|
---|
87 | return S_OK;
|
---|
88 | }
|
---|
89 | STDMETHOD(COMGETTER(BitsPerPixel))(ULONG *bitsPerPixel)
|
---|
90 | {
|
---|
91 | if (!bitsPerPixel)
|
---|
92 | return E_POINTER;
|
---|
93 | *bitsPerPixel = mBitsPerPixel;
|
---|
94 | return S_OK;
|
---|
95 | }
|
---|
96 | STDMETHOD(COMGETTER(BytesPerLine))(ULONG *bytesPerLine)
|
---|
97 | {
|
---|
98 | if (!bytesPerLine)
|
---|
99 | return E_POINTER;
|
---|
100 | *bytesPerLine = mBytesPerLine;
|
---|
101 | return S_OK;
|
---|
102 | }
|
---|
103 | STDMETHOD(COMGETTER(PixelFormat)) (ULONG *pixelFormat)
|
---|
104 | {
|
---|
105 | if (!pixelFormat)
|
---|
106 | return E_POINTER;
|
---|
107 | *pixelFormat = mPixelFormat;
|
---|
108 | return S_OK;
|
---|
109 | }
|
---|
110 | STDMETHOD(COMGETTER(UsesGuestVRAM)) (BOOL *usesGuestVRAM)
|
---|
111 | {
|
---|
112 | if (!usesGuestVRAM)
|
---|
113 | return E_POINTER;
|
---|
114 | *usesGuestVRAM = mUsesGuestVRAM;
|
---|
115 | return S_OK;
|
---|
116 | }
|
---|
117 | STDMETHOD(COMGETTER(HeightReduction)) (ULONG *heightReduction)
|
---|
118 | {
|
---|
119 | if (!heightReduction)
|
---|
120 | return E_POINTER;
|
---|
121 | /* no reduction */
|
---|
122 | *heightReduction = 0;
|
---|
123 | return S_OK;
|
---|
124 | }
|
---|
125 | STDMETHOD(COMGETTER(Overlay)) (IFramebufferOverlay **aOverlay)
|
---|
126 | {
|
---|
127 | if (!aOverlay)
|
---|
128 | return E_POINTER;
|
---|
129 | *aOverlay = 0;
|
---|
130 | return S_OK;
|
---|
131 | }
|
---|
132 | STDMETHOD(COMGETTER(WinId)) (LONG64 *winId)
|
---|
133 | {
|
---|
134 | if (!winId)
|
---|
135 | return E_POINTER;
|
---|
136 | *winId = 0;
|
---|
137 | return S_OK;
|
---|
138 | }
|
---|
139 |
|
---|
140 | STDMETHOD(NotifyUpdate)(ULONG x, ULONG y, ULONG w, ULONG h)
|
---|
141 | {
|
---|
142 | return S_OK;
|
---|
143 | }
|
---|
144 | STDMETHOD(RequestResize)(ULONG aScreenId,
|
---|
145 | ULONG pixelFormat,
|
---|
146 | BYTE *vram,
|
---|
147 | ULONG bitsPerPixel,
|
---|
148 | ULONG bytesPerLine,
|
---|
149 | ULONG w,
|
---|
150 | ULONG h,
|
---|
151 | BOOL *finished)
|
---|
152 | {
|
---|
153 | if (mBuffer)
|
---|
154 | {
|
---|
155 | RTMemFree(mBuffer);
|
---|
156 | mBuffer = NULL;
|
---|
157 | }
|
---|
158 |
|
---|
159 | mWidth = w;
|
---|
160 | mHeight = h;
|
---|
161 | mPixelFormat = pixelFormat;
|
---|
162 | if (mPixelFormat == FramebufferPixelFormat_Opaque)
|
---|
163 | {
|
---|
164 | mBitsPerPixel = 32;
|
---|
165 | mBytesPerLine = w * 4;
|
---|
166 | mBuffer = (uint8_t*)RTMemAllocZ(mBytesPerLine * h);
|
---|
167 | mScreen = mBuffer;
|
---|
168 | mUsesGuestVRAM = false;
|
---|
169 | }
|
---|
170 | else
|
---|
171 | {
|
---|
172 | mBytesPerLine = bytesPerLine;
|
---|
173 | mBitsPerPixel = bitsPerPixel;
|
---|
174 | mScreen = (uint8_t*)vram;
|
---|
175 | mUsesGuestVRAM = true;
|
---|
176 | }
|
---|
177 |
|
---|
178 | if (finished)
|
---|
179 | *finished = true;
|
---|
180 | return S_OK;
|
---|
181 | }
|
---|
182 | STDMETHOD(VideoModeSupported)(ULONG width, ULONG height, ULONG bpp, BOOL *supported)
|
---|
183 | {
|
---|
184 | if (!supported)
|
---|
185 | return E_POINTER;
|
---|
186 | *supported = true;
|
---|
187 | return S_OK;
|
---|
188 | }
|
---|
189 | STDMETHOD(GetVisibleRegion)(BYTE *rectangles, ULONG count, ULONG *countCopied)
|
---|
190 | {
|
---|
191 | if (!rectangles)
|
---|
192 | return E_POINTER;
|
---|
193 | *rectangles = 0;
|
---|
194 | return S_OK;
|
---|
195 | }
|
---|
196 | STDMETHOD(SetVisibleRegion)(BYTE *rectangles, ULONG count)
|
---|
197 | {
|
---|
198 | if (!rectangles)
|
---|
199 | return E_POINTER;
|
---|
200 | return S_OK;
|
---|
201 | }
|
---|
202 |
|
---|
203 | STDMETHOD(ProcessVHWACommand)(BYTE *pCommand)
|
---|
204 | {
|
---|
205 | return E_NOTIMPL;
|
---|
206 | }
|
---|
207 |
|
---|
208 | STDMETHOD(Notify3DEvent)(ULONG uType, BYTE *pReserved)
|
---|
209 | {
|
---|
210 | return E_NOTIMPL;
|
---|
211 | }
|
---|
212 |
|
---|
213 | private:
|
---|
214 | /** Guest framebuffer pixel format */
|
---|
215 | ULONG mPixelFormat;
|
---|
216 | /** Guest framebuffer color depth */
|
---|
217 | ULONG mBitsPerPixel;
|
---|
218 | /** Guest framebuffer line length */
|
---|
219 | ULONG mBytesPerLine;
|
---|
220 | /* VRAM pointer */
|
---|
221 | uint8_t *mScreen;
|
---|
222 | /* VRAM buffer */
|
---|
223 | uint8_t *mBuffer;
|
---|
224 | bool mUsesGuestVRAM;
|
---|
225 |
|
---|
226 | ULONG mWidth, mHeight;
|
---|
227 |
|
---|
228 | #ifndef VBOX_WITH_XPCOM
|
---|
229 | long refcnt;
|
---|
230 | #endif
|
---|
231 | };
|
---|
232 |
|
---|
233 | #endif // __NULL_FRAMEBUFFER_H
|
---|