VirtualBox

source: vbox/trunk/src/VBox/Frontends/VBoxSDL/Framebuffer.h@ 649

Last change on this file since 649 was 523, checked in by vboxsync, 18 years ago

use the SDL-provided default bpp if there is one

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.5 KB
Line 
1/** @file
2 *
3 * VBox frontends: VBoxSDL (simple frontend based on SDL):
4 * Declaration of VBoxSDLFB (SDL framebuffer) class
5 */
6
7/*
8 * Copyright (C) 2006 InnoTek Systemberatung GmbH
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 as published by the Free Software Foundation,
14 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
15 * distribution. VirtualBox OSE is distributed in the hope that it will
16 * be useful, but WITHOUT ANY WARRANTY of any kind.
17 *
18 * If you received this file as part of a commercial VirtualBox
19 * distribution, then only the terms of your commercial VirtualBox
20 * license agreement apply instead of the previous paragraph.
21 */
22
23#ifndef __H_FRAMEBUFFER
24#define __H_FRAMEBUFFER
25
26#include "VBoxSDL.h"
27#include <iprt/thread.h>
28
29#include <iprt/critsect.h>
30
31#ifdef VBOX_SECURELABEL
32#include <SDL_ttf.h>
33/* function pointers */
34extern "C"
35{
36extern DECLSPEC int (SDLCALL *pTTF_Init)(void);
37extern DECLSPEC TTF_Font* (SDLCALL *pTTF_OpenFont)(const char *file, int ptsize);
38extern DECLSPEC SDL_Surface* (SDLCALL *pTTF_RenderUTF8_Solid)(TTF_Font *font, const char *text, SDL_Color fg);
39extern DECLSPEC void (SDLCALL *pTTF_CloseFont)(TTF_Font *font);
40extern DECLSPEC void (SDLCALL *pTTF_Quit)(void);
41}
42#endif /* VBOX_SECURELABEL */
43
44class VBoxSDLFBOverlay;
45
46class VBoxSDLFB :
47 public IFramebuffer
48{
49public:
50 VBoxSDLFB(bool fFullscreen = false, bool fResizable = true, bool fShowSDLConfig = false,
51 uint32_t u32FixedWidth = ~(uint32_t)0, uint32_t u32FixedHeight = ~(uint32_t)0, uint32_t u32FixedBPP = ~(uint32_t)0);
52 virtual ~VBoxSDLFB();
53
54#ifdef __WIN__
55 STDMETHOD_(ULONG, AddRef)()
56 {
57 return ::InterlockedIncrement (&refcnt);
58 }
59 STDMETHOD_(ULONG, Release)()
60 {
61 long cnt = ::InterlockedDecrement (&refcnt);
62 if (cnt == 0)
63 delete this;
64 return cnt;
65 }
66 STDMETHOD(QueryInterface) (REFIID riid , void **ppObj)
67 {
68 if (riid == IID_IUnknown)
69 {
70 *ppObj = this;
71 AddRef();
72 return S_OK;
73 }
74 if (riid == IID_IFramebuffer)
75 {
76 *ppObj = this;
77 AddRef();
78 return S_OK;
79 }
80 *ppObj = NULL;
81 return E_NOINTERFACE;
82 }
83#endif
84
85 NS_DECL_ISUPPORTS
86
87 STDMETHOD(COMGETTER(Width))(ULONG *width);
88 STDMETHOD(COMGETTER(Height))(ULONG *height);
89 STDMETHOD(Lock)();
90 STDMETHOD(Unlock)();
91 STDMETHOD(COMGETTER(Address))(BYTE **address);
92 STDMETHOD(COMGETTER(ColorDepth))(ULONG *colorDepth);
93 STDMETHOD(COMGETTER(LineSize))(ULONG *lineSize);
94 STDMETHOD(COMGETTER(PixelFormat)) (FramebufferPixelFormat_T *pixelFormat);
95 STDMETHOD(COMGETTER(HeightReduction)) (ULONG *heightReduction);
96 STDMETHOD(COMGETTER(Overlay)) (IFramebufferOverlay **aOverlay);
97
98 STDMETHOD(NotifyUpdate)(ULONG x, ULONG y,
99 ULONG w, ULONG h, BOOL *finished);
100 STDMETHOD(RequestResize)(FramebufferPixelFormat_T pixelFormat, BYTE *vram,
101 ULONG lineSize, ULONG w, ULONG h, BOOL *finished);
102 STDMETHOD(OperationSupported)(FramebufferAccelerationOperation_T operation, BOOL *supported);
103 STDMETHOD(VideoModeSupported)(ULONG width, ULONG height, ULONG bpp, BOOL *supported);
104 STDMETHOD(SolidFill)(ULONG x, ULONG y, ULONG width, ULONG height,
105 ULONG color, BOOL *handled);
106 STDMETHOD(CopyScreenBits)(ULONG xDst, ULONG yDst, ULONG xSrc, ULONG ySrc,
107 ULONG width, ULONG height, BOOL *handled);
108
109 // internal public methods
110 bool initialized() { return mfInitialized; }
111 void resizeGuest();
112 void resizeSDL();
113 void update(int x, int y, int w, int h, bool fGuestRelative);
114 void repaint();
115 bool getFullscreen();
116 void setFullscreen(bool fFullscreen);
117 int getXOffset();
118 int getYOffset();
119 uint32_t getGuestXRes() { return mGuestXRes; }
120 uint32_t getGuestYRes() { return mGuestYRes; }
121#ifdef VBOX_SECURELABEL
122 int initSecureLabel(uint32_t height, char *font, uint32_t pointsize);
123 void setSecureLabelText(const char *text);
124 void setSecureLabelColor(uint32_t colorFG, uint32_t colorBG);
125 void paintSecureLabel(int x, int y, int w, int h, bool fForce);
126#endif
127 void uninit();
128
129private:
130 /** the sdl thread */
131 RTNATIVETHREAD mSdlNativeThread;
132 /** current SDL framebuffer pointer (also includes screen width/height) */
133 SDL_Surface *mScreen;
134 /** false if constructor failed */
135 bool mfInitialized;
136 /** maximum possible screen width in pixels (~0 = no restriction) */
137 uint32_t mMaxScreenWidth;
138 /** maximum possible screen height in pixels (~0 = no restriction) */
139 uint32_t mMaxScreenHeight;
140 /** current guest screen width in pixels */
141 ULONG mGuestXRes;
142 /** current guest screen height in pixels */
143 ULONG mGuestYRes;
144 /** fixed SDL screen width (~0 = not set) */
145 uint32_t mFixedSDLWidth;
146 /** fixed SDL screen height (~0 = not set) */
147 uint32_t mFixedSDLHeight;
148 /** fixed SDL bits per pixel (~0 = not set) */
149 uint32_t mFixedSDLBPP;
150 /** default BPP */
151 uint32_t mDefaultSDLBPP;
152 /** Y offset in pixels, i.e. guest-nondrawable area at the top */
153 uint32_t mTopOffset;
154 /** X offset for guest screen centering */
155 uint32_t mCenterXOffset;
156 /** Y offset for guest screen centering */
157 uint32_t mCenterYOffset;
158 /** flag whether we're in fullscreen mode */
159 bool mfFullscreen;
160 /** framebuffer update semaphore */
161 RTCRITSECT mUpdateLock;
162 /** flag whether the SDL window should be resizable */
163 bool mfResizable;
164 /** flag whether we print out SDL information */
165 bool mfShowSDLConfig;
166#ifdef VBOX_SECURELABEL
167 /** current secure label text */
168 Utf8Str mSecureLabelText;
169 /** current secure label foreground color (RGB) */
170 uint32_t mSecureLabelColorFG;
171 /** current secure label background color (RGB) */
172 uint32_t mSecureLabelColorBG;
173 /** secure label font handle */
174 TTF_Font *mLabelFont;
175 /** secure label height in pixels */
176 uint32_t mLabelHeight;
177#endif
178#ifdef __WIN__
179 long refcnt;
180#endif
181 SDL_Surface *mSurfVRAM;
182
183 BYTE *mPtrVRAM;
184 ULONG mLineSize;
185 FramebufferPixelFormat_T mPixelFormat;
186
187 /** the application Icon */
188 SDL_Surface *mWMIcon;
189};
190
191class VBoxSDLFBOverlay :
192 public IFramebufferOverlay
193{
194public:
195 VBoxSDLFBOverlay(ULONG x, ULONG y, ULONG width, ULONG height, BOOL visible,
196 VBoxSDLFB *aParent);
197 virtual ~VBoxSDLFBOverlay();
198
199#ifdef __WIN__
200 STDMETHOD_(ULONG, AddRef)()
201 {
202 return ::InterlockedIncrement (&refcnt);
203 }
204 STDMETHOD_(ULONG, Release)()
205 {
206 long cnt = ::InterlockedDecrement (&refcnt);
207 if (cnt == 0)
208 delete this;
209 return cnt;
210 }
211 STDMETHOD(QueryInterface) (REFIID riid , void **ppObj)
212 {
213 if (riid == IID_IUnknown)
214 {
215 *ppObj = this;
216 AddRef();
217 return S_OK;
218 }
219 if (riid == IID_IFramebuffer)
220 {
221 *ppObj = this;
222 AddRef();
223 return S_OK;
224 }
225 *ppObj = NULL;
226 return E_NOINTERFACE;
227 }
228#endif
229
230 NS_DECL_ISUPPORTS
231
232 STDMETHOD(COMGETTER(X))(ULONG *x);
233 STDMETHOD(COMGETTER(Y))(ULONG *y);
234 STDMETHOD(COMGETTER(Width))(ULONG *width);
235 STDMETHOD(COMGETTER(Height))(ULONG *height);
236 STDMETHOD(COMGETTER(Visible))(BOOL *visible);
237 STDMETHOD(COMSETTER(Visible))(BOOL visible);
238 STDMETHOD(COMGETTER(Alpha))(ULONG *alpha);
239 STDMETHOD(COMSETTER(Alpha))(ULONG alpha);
240 STDMETHOD(COMGETTER(Address))(ULONG *address);
241 STDMETHOD(COMGETTER(LineSize))(ULONG *lineSize);
242
243 /* These are not used, or return standard values. */
244 STDMETHOD(COMGETTER(ColorDepth))(ULONG *colorDepth);
245 STDMETHOD(COMGETTER(PixelFormat)) (FramebufferPixelFormat_T *pixelFormat);
246 STDMETHOD(COMGETTER(HeightReduction)) (ULONG *heightReduction);
247 STDMETHOD(COMGETTER(Overlay)) (IFramebufferOverlay **aOverlay);
248
249 STDMETHOD(Lock)();
250 STDMETHOD(Unlock)();
251 STDMETHOD(Move)(ULONG x, ULONG y);
252 STDMETHOD(NotifyUpdate)(ULONG x, ULONG y,
253 ULONG w, ULONG h, BOOL *finished);
254 STDMETHOD(RequestResize)(FramebufferPixelFormat_T pixelFormat, ULONG vram,
255 ULONG lineSize, ULONG w, ULONG h, BOOL *finished);
256 STDMETHOD(OperationSupported)(FramebufferAccelerationOperation_T operation,
257 BOOL *supported);
258 STDMETHOD(VideoModeSupported)(ULONG width, ULONG height, ULONG bpp, BOOL *supported);
259 STDMETHOD(SolidFill)(ULONG x, ULONG y, ULONG width, ULONG height,
260 ULONG color, BOOL *handled);
261 STDMETHOD(CopyScreenBits)(ULONG xDst, ULONG yDst, ULONG xSrc, ULONG ySrc,
262 ULONG width, ULONG height, BOOL *handled);
263
264 // internal public methods
265 HRESULT init();
266
267private:
268 /** Overlay X offset */
269 ULONG mOverlayX;
270 /** Overlay Y offset */
271 ULONG mOverlayY;
272 /** Overlay width */
273 ULONG mOverlayWidth;
274 /** Overlay height */
275 ULONG mOverlayHeight;
276 /** Whether the overlay is currently active */
277 BOOL mOverlayVisible;
278 /** The parent IFramebuffer */
279 VBoxSDLFB *mParent;
280 /** SDL surface containing the actual framebuffer bits */
281 SDL_Surface *mOverlayBits;
282 /** Additional SDL surface used for combining the framebuffer and the overlay */
283 SDL_Surface *mBlendedBits;
284#ifdef __WIN__
285 long refcnt;
286#endif
287};
288
289#endif // __H_FRAMEBUFFER
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