ScummVM API documentation
atari-graphics.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef BACKENDS_GRAPHICS_ATARI_H
23 #define BACKENDS_GRAPHICS_ATARI_H
24 
25 #include "backends/graphics/graphics.h"
26 #include "common/events.h"
27 
28 #include <mint/osbind.h>
29 
30 #include "common/rect.h"
31 #include "graphics/surface.h"
32 
33 #include "atari-cursor.h"
34 #include "atari-pendingscreenchanges.h"
35 #include "atari-screen.h"
36 
37 #define MAX_HZ_SHAKE 16 // Falcon only
38 #define MAX_V_SHAKE 16
39 
41  friend class Cursor;
42  friend class PendingScreenChanges;
43  friend class Screen;
44 
45 public:
47  virtual ~AtariGraphicsManager();
48 
49  bool hasFeature(OSystem::Feature f) const override;
50  void setFeatureState(OSystem::Feature f, bool enable) override;
51  bool getFeatureState(OSystem::Feature f) const override;
52 
53  const OSystem::GraphicsMode *getSupportedGraphicsModes() const override {
54  static const OSystem::GraphicsMode graphicsModes[] = {
55  { "direct", "Direct rendering", (int)GraphicsMode::DirectRendering },
56  { "single", "Single buffering", (int)GraphicsMode::SingleBuffering },
57  { "triple", "Triple buffering", (int)GraphicsMode::TripleBuffering },
58  { nullptr, nullptr, 0 }
59  };
60  return graphicsModes;
61  }
62  int getDefaultGraphicsMode() const override { return (int)GraphicsMode::TripleBuffering; }
63  bool setGraphicsMode(int mode, uint flags = OSystem::kGfxModeNoFlags) override;
64  int getGraphicsMode() const override { return (int)_currentState.mode; }
65 
66  void initSize(uint width, uint height, const Graphics::PixelFormat *format = NULL) override;
67 
68  int getScreenChangeID() const override { return 0; }
69 
70  void beginGFXTransaction() override;
71  OSystem::TransactionError endGFXTransaction() override;
72 
73  int16 getHeight() const override { return _currentState.height; }
74  int16 getWidth() const override { return _currentState.width; }
75  void setPalette(const byte *colors, uint start, uint num) override;
76  void grabPalette(byte *colors, uint start, uint num) const override;
77  void copyRectToScreen(const void *buf, int pitch, int x, int y, int w, int h) override;
78  Graphics::Surface *lockScreen() override;
79  void unlockScreen() override;
80  void fillScreen(uint32 col) override;
81  void fillScreen(const Common::Rect &r, uint32 col) override;
82  void updateScreen() override;
83  void setShakePos(int shakeXOffset, int shakeYOffset) override;
84  void setFocusRectangle(const Common::Rect& rect) override {}
85  void clearFocusRectangle() override {}
86 
87  void showOverlay(bool inGUI) override;
88  void hideOverlay() override;
89  bool isOverlayVisible() const override { return _overlayVisible; }
90  Graphics::PixelFormat getOverlayFormat() const override;
91  void clearOverlay() override;
92  void grabOverlay(Graphics::Surface &surface) const override;
93  void copyRectToOverlay(const void *buf, int pitch, int x, int y, int w, int h) override;
94  int16 getOverlayHeight() const override { return 480; }
95  int16 getOverlayWidth() const override { return _vgaMonitor ? 640 : 640*1.2; }
96 
97  bool showMouse(bool visible) override;
98  void warpMouse(int x, int y) override;
99  void setMouseCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor,
100  bool dontScale = false, const Graphics::PixelFormat *format = NULL, const byte *mask = NULL) override;
101  void setCursorPalette(const byte *colors, uint start, uint num) override;
102 
103  Common::Point getMousePosition() const { return _workScreen->cursor.getPosition(); }
104  void updateMousePosition(int deltaX, int deltaY);
105 
106  bool notifyEvent(const Common::Event &event) override;
107  Common::Keymap *getKeymap() const;
108 
109 protected:
110  typedef void* (*AtariMemAlloc)(size_t bytes);
111  typedef void (*AtariMemFree)(void *ptr);
112 
113  void allocateSurfaces();
114  void freeSurfaces();
115 
116 private:
117  enum class GraphicsMode : int {
118  Unknown = -1,
119  DirectRendering = 0,
120  SingleBuffering = 1,
121  TripleBuffering = 3
122  };
123 
124  enum CustomEventAction {
125  kActionToggleAspectRatioCorrection = 100,
126  };
127 
128 #ifndef DISABLE_FANCY_THEMES
129  int16 getMaximumScreenHeight() const { return 480; }
130  int16 getMaximumScreenWidth() const { return _tt ? 320 : (_vgaMonitor ? 640 : 640*1.2); }
131 #else
132  int16 getMaximumScreenHeight() const { return _tt ? 480 : 240; }
133  int16 getMaximumScreenWidth() const { return _tt ? 320 : (_vgaMonitor ? 320 : 320*1.2); }
134 #endif
135 
136  bool updateScreenInternal(const Graphics::Surface &srcSurface);
137 
138  void copyRectToScreenInternal(const void *buf, int pitch, int x, int y, int w, int h,
139  const Graphics::PixelFormat &format, bool directRendering, bool tripleBuffer);
140 
141  int getBitsPerPixel(const Graphics::PixelFormat &format) const;
142 
143  bool isOverlayDirectRendering() const;
144 
145  virtual AtariMemAlloc getStRamAllocFunc() const {
146  return [](size_t bytes) { return (void*)Mxalloc(bytes, MX_STRAM); };
147  }
148  virtual AtariMemFree getStRamFreeFunc() const {
149  return [](void *ptr) { Mfree(ptr); };
150  }
151 
152  virtual void copyRectToSurface(Graphics::Surface &dstSurface, int dstBitsPerPixel, const Graphics::Surface &srcSurface,
153  int destX, int destY,
154  const Common::Rect &subRect) const {
155  dstSurface.copyRectToSurface(srcSurface, destX, destY, subRect);
156  }
157 
158  virtual void drawMaskedSprite(Graphics::Surface &dstSurface, int dstBitsPerPixel,
159  const Graphics::Surface &srcSurface, const Graphics::Surface &srcMask,
160  int destX, int destY,
161  const Common::Rect &subRect) = 0;
162 
163  virtual Common::Rect alignRect(int x, int y, int w, int h) const = 0;
164 
165  Common::Rect alignRect(const Common::Rect &rect) const {
166  return alignRect(rect.left, rect.top, rect.width(), rect.height());
167  }
168 
169  int getOverlayPaletteSize() const {
170 #ifndef DISABLE_FANCY_THEMES
171  return _tt ? 16 : 256;
172 #else
173  return 16;
174 #endif
175  }
176 
177  bool _vgaMonitor = true;
178  bool _tt = false;
179  bool _checkUnalignedPitch = false;
180 
181  struct GraphicsState {
182  GraphicsState()
183  : inTransaction(false)
184  , mode(GraphicsMode::Unknown)
185  , width(0)
186  , height(0)
187  , format(Graphics::PixelFormat()) {
188  }
189 
190  bool inTransaction;
191  GraphicsMode mode;
192  int width;
193  int height;
194  Graphics::PixelFormat format;
195  };
196  GraphicsState _pendingState;
197  GraphicsState _currentState;
198 
199  // feature flags
200  bool _aspectRatioCorrection = false;
201 
202  PendingScreenChanges _pendingScreenChanges;
203 
204  enum {
205  FRONT_BUFFER,
206  BACK_BUFFER1,
207  BACK_BUFFER2,
208  OVERLAY_BUFFER,
209  BUFFER_COUNT
210  };
211  Screen *_screen[BUFFER_COUNT] = {};
212  Screen *_workScreen = nullptr;
213  Screen *_oldWorkScreen = nullptr; // used in hideOverlay()
214 
215  Graphics::Surface _chunkySurface;
216 
217  bool _overlayVisible = true;
218  bool _overlayPending = true;
219  bool _ignoreHideOverlay = true;
220  Graphics::Surface _overlaySurface;
221 
222  Palette _palette;
223  Palette _overlayPalette;
224 };
225 
226 #endif
Definition: keymap.h:66
Definition: surface.h:67
Definition: system.h:779
bool notifyEvent(const Common::Event &event) override
void grabPalette(byte *colors, uint start, uint num) const override
Definition: pixelformat.h:138
Definition: system.h:730
Feature
Definition: system.h:403
Definition: rect.h:144
Definition: atari-screen.h:60
Definition: events.h:318
Definition: atari-cursor.h:38
int16 width() const
Definition: rect.h:191
TransactionError
Definition: system.h:1155
Definition: events.h:199
Definition: rect.h:45
int16 left
Definition: rect.h:145
void setPalette(const byte *colors, uint start, uint num) override
Definition: graphics.h:37
Definition: atari-pendingscreenchanges.h:32
Definition: atari-graphics.h:40
void copyRectToSurface(const void *buffer, int srcPitch, int destX, int destY, int width, int height)
int16 height() const
Definition: rect.h:192
Definition: atari-screen.h:44