ScummVM API documentation
libretro-graphics.h
1 /* Copyright (C) 2024 Giovanni Cascione <ing.cascione@gmail.com>
2  *
3  * This program is free software: you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation, either version 3 of the License, or
6  * (at your option) any later version.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  */
17 #ifndef BACKENDS_LIBRETRO_GRAPHICS_H
18 #define BACKENDS_LIBRETRO_GRAPHICS_H
19 
20 #include "common/system.h"
21 #include "graphics/paletteman.h"
22 #include "graphics/surface.h"
23 #include "backends/graphics/graphics.h"
24 
25 #ifdef USE_OPENGL
26 #include "backends/graphics/opengl/opengl-graphics.h"
27 #endif
28 
30 public:
31  const byte *_prevColorsSource;
32  unsigned char _colors[256 * 3];
33  LibretroPalette(void);
34  ~LibretroPalette(void) {};
35  void set(const byte *colors, uint start, uint num);
36  void get(byte *colors, uint start, uint num) const;
37  unsigned char *getColor(uint aIndex) const;
38  void reset(void) {
39  _prevColorsSource = NULL;
40  }
41 };
42 
44 
45 public:
46  Graphics::Surface _screen;
47  Graphics::Surface _gameScreen;
48  Graphics::Surface _overlay;
49  Graphics::Surface _mouseImage;
50  LibretroPalette _mousePalette;
51  LibretroPalette _gamePalette;
52 
53 private:
54  bool _overlayInGUI;
55  bool _overlayVisible;
56  bool _mouseDontScale;
57  bool _mousePaletteEnabled;
58  bool _mouseVisible;
59  bool _screenUpdatePending;
60  int _mouseHotspotX;
61  int _mouseHotspotY;
62  int _mouseKeyColor;
63 
64 public:
67  Common::List<Graphics::PixelFormat> getSupportedFormats() const override;
68  const OSystem::GraphicsMode *getSupportedGraphicsModes(void) const override;
69  void initSize(uint width, uint height, const Graphics::PixelFormat *format) override;
70  int16 getHeight(void) const override;
71  int16 getWidth(void) const override;
72  Graphics::PixelFormat getScreenFormat(void) const override;
73  void copyRectToScreen(const void *buf, int pitch, int x, int y, int w, int h) override;
74  void updateScreen(void) override;
75  void showOverlay(bool inGUI) override;
76  void hideOverlay(void) override;
77  void clearOverlay(void) override;
78  void grabOverlay(Graphics::Surface &surface) const override;
79  void copyRectToOverlay(const void *buf, int pitch, int x, int y, int w, int h) override;
80  int16 getOverlayHeight(void) const override;
81  int16 getOverlayWidth(void) const override;
82  Graphics::PixelFormat getOverlayFormat() const override;
83  const Graphics::Surface *getScreen(void);
84  bool showMouse(bool visible) override;
85  void warpMouse(int x, int y) override;
86  void setMouseCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor = 255, bool dontScale = false, const Graphics::PixelFormat *format = NULL, const byte *mask = nullptr) override;
87  void setCursorPalette(const byte *colors, uint start, uint num) override;
88  bool isOverlayInGUI(void);
89 
90  bool hasFeature(OSystem::Feature f) const override;
91  void setFeatureState(OSystem::Feature f, bool enable) override;
92  bool getFeatureState(OSystem::Feature f) const override;
93 
94  int getDefaultGraphicsMode() const override {
95  return 0;
96  }
97  bool isOverlayVisible() const override {
98  return _overlayVisible;
99  }
100  bool setGraphicsMode(int mode, uint flags = OSystem::kGfxModeNoFlags) override {
101  return true;
102  }
103  int getGraphicsMode() const override {
104  return 0;
105  }
106  Graphics::Surface *lockScreen() override {
107  return &_gameScreen;
108  }
109  void unlockScreen() override {}
110 
111  void setShakePos(int shakeXOffset, int shakeYOffset) override {}
112  int getScreenChangeID() const override {
113  return 0;
114  }
115  void beginGFXTransaction() override {}
116  OSystem::TransactionError endGFXTransaction() override {
118  }
119  void fillScreen(uint32 col) override {}
120  void fillScreen(const Common::Rect &r, uint32 col) override {}
121  void setFocusRectangle(const Common::Rect &rect) override {}
122  void clearFocusRectangle() override {}
123  void displayMessageOnOSD(const Common::U32String &msg) override;
124  void displayActivityIconOnOSD(const Graphics::Surface *icon) override {}
125 
126  void realUpdateScreen(void);
127 
128 protected:
129  void setPalette(const byte *colors, uint start, uint num) override;
130  void grabPalette(byte *colors, uint start, uint num) const override;
131 };
132 
133 #ifdef USE_OPENGL
134 class LibretroOpenGLGraphics : public OpenGL::OpenGLGraphicsManager {
135 public:
136  LibretroOpenGLGraphics(OpenGL::ContextType contextType);
137  bool loadVideoMode(uint requestedWidth, uint requestedHeight, const Graphics::PixelFormat &format) override { return true; };
138  void refreshScreen() override;
139  void setSystemMousePosition(const int x, const int y) override {};
140 
141  bool isOverlayInGUI(void){ return _overlayInGUI; }
142  void setMousePosition(int x, int y);
143  Common::Point convertWindowToVirtual(int x, int y) const;
144 };
145 
146 class LibretroHWFramebuffer : public OpenGL::Backbuffer {
147 
148 protected:
149  void activateInternal() override;
150 };
151 #endif
152 #endif //BACKENDS_LIBRETRO_GRAPHICS_H
Definition: surface.h:66
Definition: system.h:788
Definition: framebuffer.h:181
Definition: pixelformat.h:138
Definition: system.h:739
Definition: libretro-graphics.h:29
Feature
Definition: system.h:417
Definition: list.h:44
Definition: rect.h:144
Definition: ustr.h:57
TransactionError
Definition: system.h:1148
Definition: opengl-graphics.h:55
Definition: rect.h:45
Definition: graphics.h:36
Definition: libretro-graphics.h:43
Definition: system.h:1149