[1] | 1 | /** @file
|
---|
| 2 | *
|
---|
| 3 | * VBox frontends: VBoxSDL (simple frontend based on SDL):
|
---|
| 4 | * Declaration of VBoxSDLFB (SDL framebuffer) class
|
---|
| 5 | */
|
---|
| 6 |
|
---|
| 7 | /*
|
---|
[28800] | 8 | * Copyright (C) 2006-2007 Oracle Corporation
|
---|
[1] | 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
|
---|
[5999] | 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.
|
---|
[1] | 17 | */
|
---|
| 18 |
|
---|
| 19 | #ifndef __H_FRAMEBUFFER
|
---|
| 20 | #define __H_FRAMEBUFFER
|
---|
| 21 |
|
---|
| 22 | #include "VBoxSDL.h"
|
---|
| 23 | #include <iprt/thread.h>
|
---|
| 24 |
|
---|
| 25 | #include <iprt/critsect.h>
|
---|
| 26 |
|
---|
| 27 | #ifdef VBOX_SECURELABEL
|
---|
| 28 | #include <SDL_ttf.h>
|
---|
| 29 | /* function pointers */
|
---|
| 30 | extern "C"
|
---|
| 31 | {
|
---|
| 32 | extern DECLSPEC int (SDLCALL *pTTF_Init)(void);
|
---|
| 33 | extern DECLSPEC TTF_Font* (SDLCALL *pTTF_OpenFont)(const char *file, int ptsize);
|
---|
| 34 | extern DECLSPEC SDL_Surface* (SDLCALL *pTTF_RenderUTF8_Solid)(TTF_Font *font, const char *text, SDL_Color fg);
|
---|
[8144] | 35 | extern DECLSPEC SDL_Surface* (SDLCALL *pTTF_RenderUTF8_Shaded)(TTF_Font *font, const char *text, SDL_Color fg, SDL_Color bg);
|
---|
| 36 | extern DECLSPEC SDL_Surface* (SDLCALL *pTTF_RenderUTF8_Blended)(TTF_Font *font, const char *text, SDL_Color fg);
|
---|
[1] | 37 | extern DECLSPEC void (SDLCALL *pTTF_CloseFont)(TTF_Font *font);
|
---|
| 38 | extern DECLSPEC void (SDLCALL *pTTF_Quit)(void);
|
---|
| 39 | }
|
---|
[20433] | 40 | #endif /* VBOX_SECURELABEL && !VBOX_WITH_SDL13 */
|
---|
[1] | 41 |
|
---|
| 42 | class VBoxSDLFBOverlay;
|
---|
| 43 |
|
---|
| 44 | class VBoxSDLFB :
|
---|
[19134] | 45 | VBOX_SCRIPTABLE_IMPL(IFramebuffer)
|
---|
[1] | 46 | {
|
---|
| 47 | public:
|
---|
[20433] | 48 | VBoxSDLFB(uint32_t uScreenId,
|
---|
| 49 | bool fFullscreen = false, bool fResizable = true, bool fShowSDLConfig = false,
|
---|
[10675] | 50 | bool fKeepHostRes = false, uint32_t u32FixedWidth = ~(uint32_t)0,
|
---|
| 51 | uint32_t u32FixedHeight = ~(uint32_t)0, uint32_t u32FixedBPP = ~(uint32_t)0);
|
---|
[1] | 52 | virtual ~VBoxSDLFB();
|
---|
| 53 |
|
---|
[23170] | 54 | static bool init(bool fShowSDLConfig);
|
---|
[20433] | 55 | static void uninit();
|
---|
| 56 |
|
---|
[3669] | 57 | #ifdef RT_OS_WINDOWS
|
---|
[1] | 58 | STDMETHOD_(ULONG, AddRef)()
|
---|
| 59 | {
|
---|
| 60 | return ::InterlockedIncrement (&refcnt);
|
---|
| 61 | }
|
---|
| 62 | STDMETHOD_(ULONG, Release)()
|
---|
| 63 | {
|
---|
| 64 | long cnt = ::InterlockedDecrement (&refcnt);
|
---|
| 65 | if (cnt == 0)
|
---|
| 66 | delete this;
|
---|
| 67 | return cnt;
|
---|
| 68 | }
|
---|
| 69 | #endif
|
---|
[21520] | 70 | VBOX_SCRIPTABLE_DISPATCH_IMPL(IFramebuffer)
|
---|
[1] | 71 |
|
---|
| 72 | NS_DECL_ISUPPORTS
|
---|
| 73 |
|
---|
| 74 | STDMETHOD(COMGETTER(Width))(ULONG *width);
|
---|
| 75 | STDMETHOD(COMGETTER(Height))(ULONG *height);
|
---|
| 76 | STDMETHOD(Lock)();
|
---|
| 77 | STDMETHOD(Unlock)();
|
---|
[470] | 78 | STDMETHOD(COMGETTER(Address))(BYTE **address);
|
---|
[3761] | 79 | STDMETHOD(COMGETTER(BitsPerPixel))(ULONG *bitsPerPixel);
|
---|
| 80 | STDMETHOD(COMGETTER(BytesPerLine))(ULONG *bytesPerLine);
|
---|
| 81 | STDMETHOD(COMGETTER(PixelFormat)) (ULONG *pixelFormat);
|
---|
| 82 | STDMETHOD(COMGETTER(UsesGuestVRAM)) (BOOL *usesGuestVRAM);
|
---|
[1] | 83 | STDMETHOD(COMGETTER(HeightReduction)) (ULONG *heightReduction);
|
---|
| 84 | STDMETHOD(COMGETTER(Overlay)) (IFramebufferOverlay **aOverlay);
|
---|
[31698] | 85 | STDMETHOD(COMGETTER(WinId)) (int64_t *winId);
|
---|
[1] | 86 |
|
---|
[19817] | 87 | STDMETHOD(NotifyUpdate)(ULONG x, ULONG y, ULONG w, ULONG h);
|
---|
[3761] | 88 | STDMETHOD(RequestResize)(ULONG aScreenId, ULONG pixelFormat, BYTE *vram,
|
---|
| 89 | ULONG bitsPerPixel, ULONG bytesPerLine,
|
---|
| 90 | ULONG w, ULONG h, BOOL *finished);
|
---|
[1] | 91 | STDMETHOD(VideoModeSupported)(ULONG width, ULONG height, ULONG bpp, BOOL *supported);
|
---|
| 92 |
|
---|
[3576] | 93 | STDMETHOD(GetVisibleRegion)(BYTE *aRectangles, ULONG aCount, ULONG *aCountCopied);
|
---|
| 94 | STDMETHOD(SetVisibleRegion)(BYTE *aRectangles, ULONG aCount);
|
---|
[3532] | 95 |
|
---|
[19844] | 96 | STDMETHOD(ProcessVHWACommand)(BYTE *pCommand);
|
---|
| 97 |
|
---|
[1] | 98 | // internal public methods
|
---|
| 99 | bool initialized() { return mfInitialized; }
|
---|
| 100 | void resizeGuest();
|
---|
| 101 | void resizeSDL();
|
---|
| 102 | void update(int x, int y, int w, int h, bool fGuestRelative);
|
---|
| 103 | void repaint();
|
---|
| 104 | void setFullscreen(bool fFullscreen);
|
---|
[11400] | 105 | void getFullscreenGeometry(uint32_t *width, uint32_t *height);
|
---|
[20433] | 106 | uint32_t getScreenId() { return mScreenId; }
|
---|
[1] | 107 | uint32_t getGuestXRes() { return mGuestXRes; }
|
---|
| 108 | uint32_t getGuestYRes() { return mGuestYRes; }
|
---|
[20433] | 109 | int32_t getOriginX() { return mOriginX; }
|
---|
| 110 | int32_t getOriginY() { return mOriginY; }
|
---|
| 111 | int32_t getXOffset() { return mCenterXOffset; }
|
---|
| 112 | int32_t getYOffset() { return mCenterYOffset; }
|
---|
| 113 | #ifdef VBOX_WITH_SDL13
|
---|
| 114 | bool hasWindow(SDL_WindowID id) { return mScreen && mWindow == id; }
|
---|
| 115 | #endif
|
---|
[1] | 116 | #ifdef VBOX_SECURELABEL
|
---|
[8154] | 117 | int initSecureLabel(uint32_t height, char *font, uint32_t pointsize, uint32_t labeloffs);
|
---|
[1] | 118 | void setSecureLabelText(const char *text);
|
---|
| 119 | void setSecureLabelColor(uint32_t colorFG, uint32_t colorBG);
|
---|
| 120 | void paintSecureLabel(int x, int y, int w, int h, bool fForce);
|
---|
| 121 | #endif
|
---|
[31698] | 122 | void setWinId(int64_t winId) { mWinId = winId; }
|
---|
[20433] | 123 | void setOrigin(int32_t axOrigin, int32_t ayOrigin) { mOriginX = axOrigin; mOriginY = ayOrigin; }
|
---|
| 124 | bool getFullscreen() { return mfFullscreen; }
|
---|
[1] | 125 |
|
---|
| 126 | private:
|
---|
| 127 | /** current SDL framebuffer pointer (also includes screen width/height) */
|
---|
| 128 | SDL_Surface *mScreen;
|
---|
[20433] | 129 | #ifdef VBOX_WITH_SDL13
|
---|
| 130 | /** the SDL window */
|
---|
| 131 | SDL_WindowID mWindow;
|
---|
| 132 | /** the texture */
|
---|
| 133 | SDL_TextureID mTexture;
|
---|
| 134 | /** render info */
|
---|
| 135 | SDL_RendererInfo mRenderInfo;
|
---|
| 136 | #endif
|
---|
[1] | 137 | /** false if constructor failed */
|
---|
| 138 | bool mfInitialized;
|
---|
[20433] | 139 | /** the screen number of this framebuffer */
|
---|
| 140 | uint32_t mScreenId;
|
---|
[1] | 141 | /** maximum possible screen width in pixels (~0 = no restriction) */
|
---|
| 142 | uint32_t mMaxScreenWidth;
|
---|
| 143 | /** maximum possible screen height in pixels (~0 = no restriction) */
|
---|
| 144 | uint32_t mMaxScreenHeight;
|
---|
| 145 | /** current guest screen width in pixels */
|
---|
| 146 | ULONG mGuestXRes;
|
---|
| 147 | /** current guest screen height in pixels */
|
---|
| 148 | ULONG mGuestYRes;
|
---|
[20433] | 149 | int32_t mOriginX;
|
---|
| 150 | int32_t mOriginY;
|
---|
[1] | 151 | /** fixed SDL screen width (~0 = not set) */
|
---|
| 152 | uint32_t mFixedSDLWidth;
|
---|
| 153 | /** fixed SDL screen height (~0 = not set) */
|
---|
| 154 | uint32_t mFixedSDLHeight;
|
---|
| 155 | /** fixed SDL bits per pixel (~0 = not set) */
|
---|
| 156 | uint32_t mFixedSDLBPP;
|
---|
| 157 | /** Y offset in pixels, i.e. guest-nondrawable area at the top */
|
---|
| 158 | uint32_t mTopOffset;
|
---|
| 159 | /** X offset for guest screen centering */
|
---|
| 160 | uint32_t mCenterXOffset;
|
---|
| 161 | /** Y offset for guest screen centering */
|
---|
| 162 | uint32_t mCenterYOffset;
|
---|
| 163 | /** flag whether we're in fullscreen mode */
|
---|
| 164 | bool mfFullscreen;
|
---|
[33540] | 165 | /** flag whether we keep the host screen resolution when switching to
|
---|
[10675] | 166 | * fullscreen or not */
|
---|
| 167 | bool mfKeepHostRes;
|
---|
[1] | 168 | /** framebuffer update semaphore */
|
---|
| 169 | RTCRITSECT mUpdateLock;
|
---|
| 170 | /** flag whether the SDL window should be resizable */
|
---|
| 171 | bool mfResizable;
|
---|
| 172 | /** flag whether we print out SDL information */
|
---|
| 173 | bool mfShowSDLConfig;
|
---|
[12449] | 174 | /** handle to window where framebuffer context is being drawn*/
|
---|
[31698] | 175 | int64_t mWinId;
|
---|
[1] | 176 | #ifdef VBOX_SECURELABEL
|
---|
| 177 | /** current secure label text */
|
---|
| 178 | Utf8Str mSecureLabelText;
|
---|
| 179 | /** current secure label foreground color (RGB) */
|
---|
| 180 | uint32_t mSecureLabelColorFG;
|
---|
| 181 | /** current secure label background color (RGB) */
|
---|
| 182 | uint32_t mSecureLabelColorBG;
|
---|
| 183 | /** secure label font handle */
|
---|
| 184 | TTF_Font *mLabelFont;
|
---|
| 185 | /** secure label height in pixels */
|
---|
| 186 | uint32_t mLabelHeight;
|
---|
[8154] | 187 | /** secure label offset from the top of the secure label */
|
---|
| 188 | uint32_t mLabelOffs;
|
---|
[20433] | 189 |
|
---|
[1] | 190 | #endif
|
---|
[3669] | 191 | #ifdef RT_OS_WINDOWS
|
---|
[1] | 192 | long refcnt;
|
---|
| 193 | #endif
|
---|
| 194 | SDL_Surface *mSurfVRAM;
|
---|
| 195 |
|
---|
[470] | 196 | BYTE *mPtrVRAM;
|
---|
[3761] | 197 | ULONG mBitsPerPixel;
|
---|
| 198 | ULONG mBytesPerLine;
|
---|
| 199 | ULONG mPixelFormat;
|
---|
| 200 | BOOL mUsesGuestVRAM;
|
---|
[15868] | 201 | BOOL mfSameSizeRequested;
|
---|
[1] | 202 | };
|
---|
| 203 |
|
---|
| 204 | class VBoxSDLFBOverlay :
|
---|
| 205 | public IFramebufferOverlay
|
---|
| 206 | {
|
---|
| 207 | public:
|
---|
| 208 | VBoxSDLFBOverlay(ULONG x, ULONG y, ULONG width, ULONG height, BOOL visible,
|
---|
| 209 | VBoxSDLFB *aParent);
|
---|
| 210 | virtual ~VBoxSDLFBOverlay();
|
---|
| 211 |
|
---|
[3669] | 212 | #ifdef RT_OS_WINDOWS
|
---|
[1] | 213 | STDMETHOD_(ULONG, AddRef)()
|
---|
| 214 | {
|
---|
| 215 | return ::InterlockedIncrement (&refcnt);
|
---|
| 216 | }
|
---|
| 217 | STDMETHOD_(ULONG, Release)()
|
---|
| 218 | {
|
---|
| 219 | long cnt = ::InterlockedDecrement (&refcnt);
|
---|
| 220 | if (cnt == 0)
|
---|
| 221 | delete this;
|
---|
| 222 | return cnt;
|
---|
| 223 | }
|
---|
| 224 | #endif
|
---|
[21520] | 225 | VBOX_SCRIPTABLE_DISPATCH_IMPL(IFramebuffer)
|
---|
[1] | 226 |
|
---|
| 227 | NS_DECL_ISUPPORTS
|
---|
| 228 |
|
---|
| 229 | STDMETHOD(COMGETTER(X))(ULONG *x);
|
---|
| 230 | STDMETHOD(COMGETTER(Y))(ULONG *y);
|
---|
| 231 | STDMETHOD(COMGETTER(Width))(ULONG *width);
|
---|
| 232 | STDMETHOD(COMGETTER(Height))(ULONG *height);
|
---|
| 233 | STDMETHOD(COMGETTER(Visible))(BOOL *visible);
|
---|
| 234 | STDMETHOD(COMSETTER(Visible))(BOOL visible);
|
---|
| 235 | STDMETHOD(COMGETTER(Alpha))(ULONG *alpha);
|
---|
| 236 | STDMETHOD(COMSETTER(Alpha))(ULONG alpha);
|
---|
| 237 | STDMETHOD(COMGETTER(Address))(ULONG *address);
|
---|
[3761] | 238 | STDMETHOD(COMGETTER(BytesPerLine))(ULONG *bytesPerLine);
|
---|
[1] | 239 |
|
---|
| 240 | /* These are not used, or return standard values. */
|
---|
[3761] | 241 | STDMETHOD(COMGETTER(BitsPerPixel))(ULONG *bitsPerPixel);
|
---|
| 242 | STDMETHOD(COMGETTER(PixelFormat)) (ULONG *pixelFormat);
|
---|
| 243 | STDMETHOD(COMGETTER(UsesGuestVRAM)) (BOOL *usesGuestVRAM);
|
---|
[1] | 244 | STDMETHOD(COMGETTER(HeightReduction)) (ULONG *heightReduction);
|
---|
| 245 | STDMETHOD(COMGETTER(Overlay)) (IFramebufferOverlay **aOverlay);
|
---|
[31698] | 246 | STDMETHOD(COMGETTER(WinId)) (LONG64 *winId);
|
---|
[1] | 247 |
|
---|
| 248 | STDMETHOD(Lock)();
|
---|
| 249 | STDMETHOD(Unlock)();
|
---|
| 250 | STDMETHOD(Move)(ULONG x, ULONG y);
|
---|
[19817] | 251 | STDMETHOD(NotifyUpdate)(ULONG x, ULONG y, ULONG w, ULONG h);
|
---|
[3761] | 252 | STDMETHOD(RequestResize)(ULONG aScreenId, ULONG pixelFormat, ULONG vram,
|
---|
| 253 | ULONG bitsPerPixel, ULONG bytesPerLine,
|
---|
| 254 | ULONG w, ULONG h, BOOL *finished);
|
---|
[1] | 255 | STDMETHOD(VideoModeSupported)(ULONG width, ULONG height, ULONG bpp, BOOL *supported);
|
---|
| 256 |
|
---|
| 257 | // internal public methods
|
---|
| 258 | HRESULT init();
|
---|
| 259 |
|
---|
| 260 | private:
|
---|
| 261 | /** Overlay X offset */
|
---|
| 262 | ULONG mOverlayX;
|
---|
| 263 | /** Overlay Y offset */
|
---|
| 264 | ULONG mOverlayY;
|
---|
| 265 | /** Overlay width */
|
---|
| 266 | ULONG mOverlayWidth;
|
---|
| 267 | /** Overlay height */
|
---|
| 268 | ULONG mOverlayHeight;
|
---|
| 269 | /** Whether the overlay is currently active */
|
---|
| 270 | BOOL mOverlayVisible;
|
---|
| 271 | /** The parent IFramebuffer */
|
---|
| 272 | VBoxSDLFB *mParent;
|
---|
| 273 | /** SDL surface containing the actual framebuffer bits */
|
---|
| 274 | SDL_Surface *mOverlayBits;
|
---|
| 275 | /** Additional SDL surface used for combining the framebuffer and the overlay */
|
---|
| 276 | SDL_Surface *mBlendedBits;
|
---|
[3669] | 277 | #ifdef RT_OS_WINDOWS
|
---|
[1] | 278 | long refcnt;
|
---|
| 279 | #endif
|
---|
| 280 | };
|
---|
| 281 |
|
---|
| 282 | #endif // __H_FRAMEBUFFER
|
---|