"Fossies" - the Fresh Open Source Software Archive

Member "stella-6.0.2/src/common/FrameBufferSDL2.hxx" (11 Oct 2019, 6040 Bytes) of package /linux/privat/stella-6.0.2-src.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "FrameBufferSDL2.hxx" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 6.0.1_vs_6.0.2.

    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 GUI::Rect& rect) const override;
   99 
  100     /**
  101       Clear the frame buffer
  102     */
  103     void clear() override;
  104 
  105   protected:
  106     //////////////////////////////////////////////////////////////////////
  107     // The following are derived from protected methods in FrameBuffer.hxx
  108     //////////////////////////////////////////////////////////////////////
  109     /**
  110       This method is called to query and initialize the video hardware
  111       for desktop and fullscreen resolution information.
  112     */
  113     void queryHardware(vector<GUI::Size>& displays, VariantList& renderers) override;
  114 
  115     /**
  116       This method is called to query the video hardware for the index
  117       of the display the current window is displayed on
  118 
  119       @return  the current display index or a negative value if no
  120                window is displayed
  121     */
  122     Int32 getCurrentDisplayIndex() override;
  123 
  124     /**
  125       This method is called to change to the given video mode.
  126 
  127       @param title The title for the created window
  128       @param mode  The video mode to use
  129 
  130       @return  False on any errors, else true
  131     */
  132     bool setVideoMode(const string& title, const VideoMode& mode) override;
  133 
  134     /**
  135       This method is called to invalidate the contents of the entire
  136       framebuffer (ie, mark the current content as invalid, and erase it on
  137       the next drawing pass).
  138     */
  139     void invalidate() override;
  140 
  141     /**
  142       This method is called to create a surface with the given attributes.
  143 
  144       @param w     The requested width of the new surface.
  145       @param h     The requested height of the new surface.
  146       @param data  If non-null, use the given data values as a static surface
  147     */
  148     unique_ptr<FBSurface>
  149         createSurface(uInt32 w, uInt32 h, const uInt32* data) const override;
  150 
  151     /**
  152       Grabs or ungrabs the mouse based on the given boolean value.
  153     */
  154     void grabMouse(bool grab) override;
  155 
  156     /**
  157       Set the icon for the main SDL window.
  158     */
  159     void setWindowIcon() override;
  160 
  161     /**
  162       This method is called to provide information about the FrameBuffer.
  163     */
  164     string about() const override;
  165 
  166     /**
  167       This method must be called after all drawing is done, and indicates
  168       that the buffers should be pushed to the physical screen.
  169     */
  170     void renderToScreen() override;
  171 
  172   private:
  173     // The SDL video buffer
  174     SDL_Window* myWindow;
  175     SDL_Renderer* myRenderer;
  176 
  177     // Used by mapRGB (when palettes are created)
  178     SDL_PixelFormat* myPixelFormat;
  179 
  180   private:
  181     // Following constructors and assignment operators not supported
  182     FrameBufferSDL2() = delete;
  183     FrameBufferSDL2(const FrameBufferSDL2&) = delete;
  184     FrameBufferSDL2(FrameBufferSDL2&&) = delete;
  185     FrameBufferSDL2& operator=(const FrameBufferSDL2&) = delete;
  186     FrameBufferSDL2& operator=(FrameBufferSDL2&&) = delete;
  187 };
  188 
  189 #endif