| 1 | //============================================================================ | 
|---|
| 2 | // | 
|---|
| 3 | //   SSSS    tt          lll  lll | 
|---|
| 4 | //  SS  SS   tt           ll   ll | 
|---|
| 5 | //  SS     tttttt  eeee   ll   ll   aaaa | 
|---|
| 6 | //   SSSS    tt   ee  ee  ll   ll      aa | 
|---|
| 7 | //      SS   tt   eeeeee  ll   ll   aaaaa  --  "An Atari 2600 VCS Emulator" | 
|---|
| 8 | //  SS  SS   tt   ee      ll   ll  aa  aa | 
|---|
| 9 | //   SSSS     ttt  eeeee llll llll  aaaaa | 
|---|
| 10 | // | 
|---|
| 11 | // Copyright (c) 1995-2019 by Bradford W. Mott, Stephen Anthony | 
|---|
| 12 | // and the Stella Team | 
|---|
| 13 | // | 
|---|
| 14 | // See the file "License.txt" for information on usage and redistribution of | 
|---|
| 15 | // this file, and for a DISCLAIMER OF ALL WARRANTIES. | 
|---|
| 16 | //============================================================================ | 
|---|
| 17 |  | 
|---|
| 18 | #ifndef FRAMEBUFFER_SDL2_HXX | 
|---|
| 19 | #define FRAMEBUFFER_SDL2_HXX | 
|---|
| 20 |  | 
|---|
| 21 | #include "SDL_lib.hxx" | 
|---|
| 22 |  | 
|---|
| 23 | class OSystem; | 
|---|
| 24 | class FBSurfaceSDL2; | 
|---|
| 25 |  | 
|---|
| 26 | #include "bspf.hxx" | 
|---|
| 27 | #include "FrameBuffer.hxx" | 
|---|
| 28 |  | 
|---|
| 29 | /** | 
|---|
| 30 | This class implements a standard SDL2 2D, hardware accelerated framebuffer. | 
|---|
| 31 | Behind the scenes, it may be using Direct3D, OpenGL(ES), etc. | 
|---|
| 32 |  | 
|---|
| 33 | @author  Stephen Anthony | 
|---|
| 34 | */ | 
|---|
| 35 | class FrameBufferSDL2 : public FrameBuffer | 
|---|
| 36 | { | 
|---|
| 37 | friend class FBSurfaceSDL2; | 
|---|
| 38 |  | 
|---|
| 39 | public: | 
|---|
| 40 | /** | 
|---|
| 41 | Creates a new SDL2 framebuffer | 
|---|
| 42 | */ | 
|---|
| 43 | explicit FrameBufferSDL2(OSystem& osystem); | 
|---|
| 44 | virtual ~FrameBufferSDL2(); | 
|---|
| 45 |  | 
|---|
| 46 | ////////////////////////////////////////////////////////////////////// | 
|---|
| 47 | // The following are derived from public methods in FrameBuffer.hxx | 
|---|
| 48 | ////////////////////////////////////////////////////////////////////// | 
|---|
| 49 |  | 
|---|
| 50 | /** | 
|---|
| 51 | Updates window title. | 
|---|
| 52 |  | 
|---|
| 53 | @param title  The title of the application / window | 
|---|
| 54 | */ | 
|---|
| 55 | void setTitle(const string& title) override; | 
|---|
| 56 |  | 
|---|
| 57 | /** | 
|---|
| 58 | Shows or hides the cursor based on the given boolean value. | 
|---|
| 59 | */ | 
|---|
| 60 | void showCursor(bool show) override; | 
|---|
| 61 |  | 
|---|
| 62 | /** | 
|---|
| 63 | Answers if the display is currently in fullscreen mode. | 
|---|
| 64 | */ | 
|---|
| 65 | bool fullScreen() const override; | 
|---|
| 66 |  | 
|---|
| 67 | /** | 
|---|
| 68 | This method is called to retrieve the R/G/B data from the given pixel. | 
|---|
| 69 |  | 
|---|
| 70 | @param pixel  The pixel containing R/G/B data | 
|---|
| 71 | @param r      The red component of the color | 
|---|
| 72 | @param g      The green component of the color | 
|---|
| 73 | @param b      The blue component of the color | 
|---|
| 74 | */ | 
|---|
| 75 | inline void getRGB(uInt32 pixel, uInt8* r, uInt8* g, uInt8* b) const override | 
|---|
| 76 | { SDL_GetRGB(pixel, myPixelFormat, r, g, b); } | 
|---|
| 77 |  | 
|---|
| 78 | /** | 
|---|
| 79 | This method is called to map a given R/G/B triple to the screen palette. | 
|---|
| 80 |  | 
|---|
| 81 | @param r  The red component of the color. | 
|---|
| 82 | @param g  The green component of the color. | 
|---|
| 83 | @param b  The blue component of the color. | 
|---|
| 84 | */ | 
|---|
| 85 | inline uInt32 mapRGB(uInt8 r, uInt8 g, uInt8 b) const override | 
|---|
| 86 | { return SDL_MapRGB(myPixelFormat, r, g, b); } | 
|---|
| 87 |  | 
|---|
| 88 | /** | 
|---|
| 89 | This method is called to get a copy of the specified ARGB data from the | 
|---|
| 90 | viewable FrameBuffer area.  Note that this isn't the same as any | 
|---|
| 91 | internal surfaces that may be in use; it should return the actual data | 
|---|
| 92 | as it is currently seen onscreen. | 
|---|
| 93 |  | 
|---|
| 94 | @param buffer  A copy of the pixel data in ARGB8888 format | 
|---|
| 95 | @param pitch   The pitch (in bytes) for the pixel data | 
|---|
| 96 | @param rect    The bounding rectangle for the buffer | 
|---|
| 97 | */ | 
|---|
| 98 | void readPixels(uInt8* buffer, uInt32 pitch, const Common::Rect& rect) const override; | 
|---|
| 99 |  | 
|---|
| 100 | /** | 
|---|
| 101 | This method is called to query the video hardware for the index | 
|---|
| 102 | of the display the current window is displayed on | 
|---|
| 103 |  | 
|---|
| 104 | @return  the current display index or a negative value if no | 
|---|
| 105 | window is displayed | 
|---|
| 106 | */ | 
|---|
| 107 | Int32 getCurrentDisplayIndex() override; | 
|---|
| 108 |  | 
|---|
| 109 | /** | 
|---|
| 110 | This method is called to preserve the last current windowed position. | 
|---|
| 111 | */ | 
|---|
| 112 | void updateWindowedPos() override; | 
|---|
| 113 |  | 
|---|
| 114 | /** | 
|---|
| 115 | Clear the frame buffer. | 
|---|
| 116 | */ | 
|---|
| 117 | void clear() override; | 
|---|
| 118 |  | 
|---|
| 119 | protected: | 
|---|
| 120 | ////////////////////////////////////////////////////////////////////// | 
|---|
| 121 | // The following are derived from protected methods in FrameBuffer.hxx | 
|---|
| 122 | ////////////////////////////////////////////////////////////////////// | 
|---|
| 123 | /** | 
|---|
| 124 | This method is called to query and initialize the video hardware | 
|---|
| 125 | for desktop and fullscreen resolution information.  Since several | 
|---|
| 126 | monitors may be attached, we need the resolution for all of them. | 
|---|
| 127 |  | 
|---|
| 128 | @param fullscreenRes  Maximum resolution supported in fullscreen mode | 
|---|
| 129 | @param windowedRes    Maximum resolution supported in windowed mode | 
|---|
| 130 | @param renderers      List of renderer names (internal name -> end-user name) | 
|---|
| 131 | */ | 
|---|
| 132 | void queryHardware(vector<Common::Size>& fullscreenRes, | 
|---|
| 133 | vector<Common::Size>& windowedRes, | 
|---|
| 134 | VariantList& renderers) override; | 
|---|
| 135 |  | 
|---|
| 136 | /** | 
|---|
| 137 | This method is called to change to the given video mode. | 
|---|
| 138 |  | 
|---|
| 139 | @param title The title for the created window | 
|---|
| 140 | @param mode  The video mode to use | 
|---|
| 141 |  | 
|---|
| 142 | @return  False on any errors, else true | 
|---|
| 143 | */ | 
|---|
| 144 | bool setVideoMode(const string& title, const VideoMode& mode) override; | 
|---|
| 145 |  | 
|---|
| 146 | /** | 
|---|
| 147 | This method is called to create a surface with the given attributes. | 
|---|
| 148 |  | 
|---|
| 149 | @param w     The requested width of the new surface. | 
|---|
| 150 | @param h     The requested height of the new surface. | 
|---|
| 151 | @param data  If non-null, use the given data values as a static surface | 
|---|
| 152 | */ | 
|---|
| 153 | unique_ptr<FBSurface> | 
|---|
| 154 | createSurface(uInt32 w, uInt32 h, const uInt32* data) const override; | 
|---|
| 155 |  | 
|---|
| 156 | /** | 
|---|
| 157 | Grabs or ungrabs the mouse based on the given boolean value. | 
|---|
| 158 | */ | 
|---|
| 159 | void grabMouse(bool grab) override; | 
|---|
| 160 |  | 
|---|
| 161 | /** | 
|---|
| 162 | Set the icon for the main SDL window. | 
|---|
| 163 | */ | 
|---|
| 164 | void setWindowIcon() override; | 
|---|
| 165 |  | 
|---|
| 166 | /** | 
|---|
| 167 | This method is called to provide information about the FrameBuffer. | 
|---|
| 168 | */ | 
|---|
| 169 | string about() const override; | 
|---|
| 170 |  | 
|---|
| 171 | /** | 
|---|
| 172 | This method must be called after all drawing is done, and indicates | 
|---|
| 173 | that the buffers should be pushed to the physical screen. | 
|---|
| 174 | */ | 
|---|
| 175 | void renderToScreen() override; | 
|---|
| 176 |  | 
|---|
| 177 | private: | 
|---|
| 178 | // The SDL video buffer | 
|---|
| 179 | SDL_Window* myWindow; | 
|---|
| 180 | SDL_Renderer* myRenderer; | 
|---|
| 181 |  | 
|---|
| 182 | // Used by mapRGB (when palettes are created) | 
|---|
| 183 | SDL_PixelFormat* myPixelFormat; | 
|---|
| 184 |  | 
|---|
| 185 | // Center setting of current window | 
|---|
| 186 | bool myCenter; | 
|---|
| 187 |  | 
|---|
| 188 | // last position of windowed window | 
|---|
| 189 | Common::Point myWindowedPos; | 
|---|
| 190 |  | 
|---|
| 191 | private: | 
|---|
| 192 | // Following constructors and assignment operators not supported | 
|---|
| 193 | FrameBufferSDL2() = delete; | 
|---|
| 194 | FrameBufferSDL2(const FrameBufferSDL2&) = delete; | 
|---|
| 195 | FrameBufferSDL2(FrameBufferSDL2&&) = delete; | 
|---|
| 196 | FrameBufferSDL2& operator=(const FrameBufferSDL2&) = delete; | 
|---|
| 197 | FrameBufferSDL2& operator=(FrameBufferSDL2&&) = delete; | 
|---|
| 198 | }; | 
|---|
| 199 |  | 
|---|
| 200 | #endif | 
|---|
| 201 |  | 
|---|