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 FBSURFACE_SDL2_HXX |
19 | #define FBSURFACE_SDL2_HXX |
20 | |
21 | #include "bspf.hxx" |
22 | #include "FBSurface.hxx" |
23 | #include "FrameBufferSDL2.hxx" |
24 | |
25 | /** |
26 | An FBSurface suitable for the SDL2 Render2D API, making use of hardware |
27 | acceleration behind the scenes. |
28 | |
29 | @author Stephen Anthony |
30 | */ |
31 | class FBSurfaceSDL2 : public FBSurface |
32 | { |
33 | public: |
34 | FBSurfaceSDL2(FrameBufferSDL2& buffer, uInt32 width, uInt32 height, |
35 | const uInt32* data); |
36 | virtual ~FBSurfaceSDL2(); |
37 | |
38 | // Most of the surface drawing primitives are implemented in FBSurface; |
39 | // the ones implemented here use SDL-specific code for extra performance |
40 | // |
41 | void fillRect(uInt32 x, uInt32 y, uInt32 w, uInt32 h, ColorId color) override; |
42 | // With hardware surfaces, it's faster to just update the entire surface |
43 | void setDirty() override { mySurfaceIsDirty = true; } |
44 | |
45 | uInt32 width() const override; |
46 | uInt32 height() const override; |
47 | |
48 | const Common::Rect& srcRect() const override; |
49 | const Common::Rect& dstRect() const override; |
50 | void setSrcPos(uInt32 x, uInt32 y) override; |
51 | void setSrcSize(uInt32 w, uInt32 h) override; |
52 | void setDstPos(uInt32 x, uInt32 y) override; |
53 | void setDstSize(uInt32 w, uInt32 h) override; |
54 | void setVisible(bool visible) override; |
55 | |
56 | void translateCoords(Int32& x, Int32& y) const override; |
57 | bool render() override; |
58 | void invalidate() override; |
59 | void free() override; |
60 | void reload() override; |
61 | void resize(uInt32 width, uInt32 height) override; |
62 | |
63 | protected: |
64 | void applyAttributes(bool immediate) override; |
65 | |
66 | private: |
67 | void createSurface(uInt32 width, uInt32 height, const uInt32* data); |
68 | |
69 | // Following constructors and assignment operators not supported |
70 | FBSurfaceSDL2() = delete; |
71 | FBSurfaceSDL2(const FBSurfaceSDL2&) = delete; |
72 | FBSurfaceSDL2(FBSurfaceSDL2&&) = delete; |
73 | FBSurfaceSDL2& operator=(const FBSurfaceSDL2&) = delete; |
74 | FBSurfaceSDL2& operator=(FBSurfaceSDL2&&) = delete; |
75 | |
76 | private: |
77 | FrameBufferSDL2& myFB; |
78 | |
79 | SDL_Surface* mySurface; |
80 | SDL_Texture* myTexture; |
81 | SDL_Texture* mySecondaryTexture; |
82 | SDL_Rect mySrcR, myDstR; |
83 | |
84 | bool mySurfaceIsDirty; |
85 | bool myIsVisible; |
86 | |
87 | SDL_TextureAccess myTexAccess; // Is pixel data constant or can it change? |
88 | bool myInterpolate; // Scaling is smoothed or blocky |
89 | bool myBlendEnabled; // Blending is enabled |
90 | uInt8 myBlendAlpha; // Alpha to use in blending mode |
91 | |
92 | unique_ptr<uInt32[]> myStaticData; // The data to use when the buffer contents are static |
93 | uInt32 myStaticPitch; // The number of bytes in a row of static data |
94 | |
95 | Common::Rect mySrcGUIR, myDstGUIR; |
96 | }; |
97 | |
98 | #endif |
99 | |