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-2021 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 FB_BACKEND_HXX 19 #define FB_BACKEND_HXX 20 21 class FBSurface; 22 23 #include "Rect.hxx" 24 #include "Variant.hxx" 25 #include "FrameBufferConstants.hxx" 26 #include "VideoModeHandler.hxx" 27 #include "bspf.hxx" 28 29 /** 30 This class provides an interface/abstraction for platform-specific, 31 framebuffer-related rendering operations. Different graphical 32 platforms will inherit from this. For most ports that means SDL2, 33 but some (such as libretro) use their own graphical subsystem. 34 35 @author Stephen Anthony 36 */ 37 class FBBackend 38 { 39 friend class FrameBuffer; 40 41 public: 42 FBBackend() = default; 43 virtual ~FBBackend() = default; 44 45 protected: 46 /** 47 This method is called to query and initialize the video hardware 48 for desktop and fullscreen resolution information. Since several 49 monitors may be attached, we need the resolution for all of them. 50 51 @param fullscreenRes Maximum resolution supported in fullscreen mode 52 @param windowedRes Maximum resolution supported in windowed mode 53 @param renderers List of renderer names (internal name -> end-user name) 54 */ 55 virtual void queryHardware(vector<Common::Size>& fullscreenRes, 56 vector<Common::Size>& windowedRes, 57 VariantList& renderers) = 0; 58 59 /** 60 This method is called to change to the given video mode. 61 62 @param mode The video mode to use 63 @param winIdx The display/monitor that the window last opened on 64 @param winPos The position that the window last opened at 65 66 @return False on any errors, else true 67 */ 68 virtual bool setVideoMode(const VideoModeHandler::Mode& mode, 69 int winIdx, const Common::Point& winPos) = 0; 70 71 /** 72 Clear the framebuffer. 73 */ 74 virtual void clear() = 0; 75 76 /** 77 Transform from window to renderer coordinates, x direction 78 */ 79 virtual int scaleX(int x) const = 0; 80 81 /** 82 Transform from window to renderer coordinates, y direction 83 */ 84 virtual int scaleY(int y) const = 0; 85 86 /** 87 Updates window title. 88 89 @param title The title of the application / window 90 */ 91 virtual void setTitle(const string& title) = 0; 92 93 /** 94 Shows or hides the cursor based on the given boolean value. 95 */ 96 virtual void showCursor(bool show) = 0; 97 98 /** 99 Grabs or ungrabs the mouse based on the given boolean value. 100 */ 101 virtual void grabMouse(bool grab) = 0; 102 103 /** 104 This method must be called after all drawing is done, and indicates 105 that the buffers should be pushed to the physical screen. 106 */ 107 virtual void renderToScreen() = 0; 108 109 /** 110 Answers if the display is currently in fullscreen mode. 111 112 @return Whether the display is actually in fullscreen mode 113 */ 114 virtual bool fullScreen() const = 0; 115 116 /** 117 Retrieve the current display's refresh rate. 118 */ 119 virtual int refreshRate() const = 0; 120 121 /** 122 This method is called to retrieve the R/G/B data from the given pixel. 123 124 @param pixel The pixel containing R/G/B data 125 @param r The red component of the color 126 @param g The green component of the color 127 @param b The blue component of the color 128 */ 129 virtual void getRGB(uInt32 pixel, uInt8* r, uInt8* g, uInt8* b) const = 0; 130 131 /** 132 This method is called to map a given R/G/B triple to the screen palette. 133 134 @param r The red component of the color. 135 @param g The green component of the color. 136 @param b The blue component of the color. 137 */ 138 virtual uInt32 mapRGB(uInt8 r, uInt8 g, uInt8 b) const = 0; 139 140 /** 141 This method is called to get the specified ARGB data from the viewable 142 FrameBuffer area. Note that this isn't the same as any internal 143 surfaces that may be in use; it should return the actual data as it 144 is currently seen onscreen. 145 146 @param buffer The actual pixel data in ARGB8888 format 147 @param pitch The pitch (in bytes) for the pixel data 148 @param rect The bounding rectangle for the buffer 149 */ 150 virtual void readPixels(uInt8* buffer, uInt32 pitch, 151 const Common::Rect& rect) const = 0; 152 153 /** 154 This method is called to query if the current window is not 155 centered or fullscreen. 156 157 @return True, if the current window is positioned 158 */ 159 virtual bool isCurrentWindowPositioned() const = 0; 160 161 /** 162 This method is called to query the video hardware for position of 163 the current window. 164 165 @return The position of the currently displayed window 166 */ 167 virtual Common::Point getCurrentWindowPos() const = 0; 168 169 /** 170 This method is called to query the video hardware for the index 171 of the display the current window is displayed on. 172 173 @return The current display index or a negative value if no 174 window is displayed 175 */ 176 virtual Int32 getCurrentDisplayIndex() const = 0; 177 178 /** 179 This method is called to create a surface with the given attributes. 180 181 @param w The requested width of the new surface. 182 @param h The requested height of the new surface. 183 @param inter Interpolation mode 184 @param data If non-null, use the given data values as a static surface 185 */ 186 virtual unique_ptr<FBSurface> 187 createSurface( 188 uInt32 w, 189 uInt32 h, 190 ScalingInterpolation inter = ScalingInterpolation::none, 191 const uInt32* data = nullptr 192 ) const = 0; 193 194 /** 195 This method is called to provide information about the backend. 196 */ 197 virtual string about() const = 0; 198 199 private: 200 // Following constructors and assignment operators not supported 201 FBBackend(const FBBackend&) = delete; 202 FBBackend(FBBackend&&) = delete; 203 FBBackend& operator=(const FBBackend&) = delete; 204 FBBackend& operator=(FBBackend&&) = delete; 205 }; 206 207 #endif 208