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-screen.h"
35 
36 #define MAX_HZ_SHAKE 16 // Falcon only
37 #define MAX_V_SHAKE 16
38 
40  friend class Cursor;
41  friend class Screen;
42 
43 public:
45  virtual ~AtariGraphicsManager();
46 
47  bool hasFeature(OSystem::Feature f) const override;
48  void setFeatureState(OSystem::Feature f, bool enable) override;
49  bool getFeatureState(OSystem::Feature f) const override;
50 
51  const OSystem::GraphicsMode *getSupportedGraphicsModes() const override {
52  static const OSystem::GraphicsMode graphicsModes[] = {
53  { "direct", "Direct rendering", (int)GraphicsMode::DirectRendering },
54  { "single", "Single buffering", (int)GraphicsMode::SingleBuffering },
55  { "triple", "Triple buffering", (int)GraphicsMode::TripleBuffering },
56  { nullptr, nullptr, 0 }
57  };
58  return graphicsModes;
59  }
60  int getDefaultGraphicsMode() const override { return (int)GraphicsMode::TripleBuffering; }
61  bool setGraphicsMode(int mode, uint flags = OSystem::kGfxModeNoFlags) override;
62  int getGraphicsMode() const override { return (int)_currentState.mode; }
63 
64  void initSize(uint width, uint height, const Graphics::PixelFormat *format = NULL) override;
65 
66  int getScreenChangeID() const override { return 0; }
67 
68  void beginGFXTransaction() override;
69  OSystem::TransactionError endGFXTransaction() override;
70 
71  int16 getHeight() const override { return _currentState.height; }
72  int16 getWidth() const override { return _currentState.width; }
73  void setPalette(const byte *colors, uint start, uint num) override;
74  void grabPalette(byte *colors, uint start, uint num) const override;
75  void copyRectToScreen(const void *buf, int pitch, int x, int y, int w, int h) override;
76  Graphics::Surface *lockScreen() override;
77  void unlockScreen() override;
78  void fillScreen(uint32 col) override;
79  void fillScreen(const Common::Rect &r, uint32 col) override;
80  void updateScreen() override;
81  void setShakePos(int shakeXOffset, int shakeYOffset) override;
82  void setFocusRectangle(const Common::Rect& rect) override {}
83  void clearFocusRectangle() override {}
84 
85  void showOverlay(bool inGUI) override;
86  void hideOverlay() override;
87  bool isOverlayVisible() const override { return _overlayVisible; }
88  Graphics::PixelFormat getOverlayFormat() const override;
89  void clearOverlay() override;
90  void grabOverlay(Graphics::Surface &surface) const override;
91  void copyRectToOverlay(const void *buf, int pitch, int x, int y, int w, int h) override;
92  int16 getOverlayHeight() const override { return 480; }
93  int16 getOverlayWidth() const override { return _vgaMonitor ? 640 : 640*1.2; }
94 
95  bool showMouse(bool visible) override;
96  void warpMouse(int x, int y) override;
97  void setMouseCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor,
98  bool dontScale = false, const Graphics::PixelFormat *format = NULL, const byte *mask = NULL) override;
99  void setCursorPalette(const byte *colors, uint start, uint num) override;
100 
101  Common::Point getMousePosition() const { return _workScreen->cursor.getPosition(); }
102  void updateMousePosition(int deltaX, int deltaY);
103 
104  bool notifyEvent(const Common::Event &event) override;
105  Common::Keymap *getKeymap() const;
106 
107 protected:
108  typedef void* (*AtariMemAlloc)(size_t bytes);
109  typedef void (*AtariMemFree)(void *ptr);
110 
111  void allocateSurfaces();
112  void freeSurfaces();
113 
114 private:
115  enum class GraphicsMode : int {
116  Unknown = -1,
117  DirectRendering = 0,
118  SingleBuffering = 1,
119  TripleBuffering = 3
120  };
121 
122  enum CustomEventAction {
123  kActionToggleAspectRatioCorrection = 100,
124  };
125 
126 #ifndef DISABLE_FANCY_THEMES
127  int16 getMaximumScreenHeight() const { return 480; }
128  int16 getMaximumScreenWidth() const { return _tt ? 320 : (_vgaMonitor ? 640 : 640*1.2); }
129 #else
130  int16 getMaximumScreenHeight() const { return _tt ? 480 : 240; }
131  int16 getMaximumScreenWidth() const { return _tt ? 320 : (_vgaMonitor ? 320 : 320*1.2); }
132 #endif
133 
134  bool updateScreenInternal(const Graphics::Surface &srcSurface);
135 
136  void copyRectToScreenInternal(const void *buf, int pitch, int x, int y, int w, int h,
137  const Graphics::PixelFormat &format, bool directRendering, bool tripleBuffer);
138 
139  int getBitsPerPixel(const Graphics::PixelFormat &format) const;
140 
141  bool isOverlayDirectRendering() const;
142 
143  virtual AtariMemAlloc getStRamAllocFunc() const {
144  return [](size_t bytes) { return (void*)Mxalloc(bytes, MX_STRAM); };
145  }
146  virtual AtariMemFree getStRamFreeFunc() const {
147  return [](void *ptr) { Mfree(ptr); };
148  }
149 
150  virtual void copyRectToSurface(Graphics::Surface &dstSurface, int dstBitsPerPixel, const Graphics::Surface &srcSurface,
151  int destX, int destY,
152  const Common::Rect &subRect) const {
153  dstSurface.copyRectToSurface(srcSurface, destX, destY, subRect);
154  }
155 
156  virtual void drawMaskedSprite(Graphics::Surface &dstSurface, int dstBitsPerPixel,
157  const Graphics::Surface &srcSurface, const Graphics::Surface &srcMask,
158  int destX, int destY,
159  const Common::Rect &subRect) = 0;
160 
161  virtual Common::Rect alignRect(int x, int y, int w, int h) const = 0;
162 
163  Common::Rect alignRect(const Common::Rect &rect) const {
164  return alignRect(rect.left, rect.top, rect.width(), rect.height());
165  }
166 
167  int getOverlayPaletteSize() const {
168 #ifndef DISABLE_FANCY_THEMES
169  return _tt ? 16 : 256;
170 #else
171  return 16;
172 #endif
173  }
174 
175  bool _vgaMonitor = true;
176  bool _tt = false;
177  bool _checkUnalignedPitch = false;
178 
179  struct GraphicsState {
180  GraphicsState()
181  : mode(GraphicsMode::Unknown)
182  , width(0)
183  , height(0)
184  , format(Graphics::PixelFormat()) {
185  }
186 
187  GraphicsMode mode;
188  int width;
189  int height;
190  Graphics::PixelFormat format;
191  };
192  GraphicsState _pendingState;
193  GraphicsState _currentState;
194 
195  // feature flags
196  bool _aspectRatioCorrection = false;
197 
198  enum PendingScreenChange {
199  kPendingNone = 0,
200  kPendingVideoMode = 1<<0,
201  kPendingScreenAddress = 1<<1,
202  kPendingAspectRatioCorrection = 1<<2,
203  kPendingPalette = 1<<3,
204  kPendingShakeScreen = 1<<4,
205  kPendingTransaction = kPendingVideoMode | kPendingScreenAddress | kPendingAspectRatioCorrection,
206  kPendingAll = kPendingTransaction | kPendingPalette | kPendingShakeScreen
207  };
208  int _pendingScreenChange = kPendingNone;
209 
210  enum {
211  FRONT_BUFFER,
212  BACK_BUFFER1,
213  BACK_BUFFER2,
214  OVERLAY_BUFFER,
215  BUFFER_COUNT
216  };
217  Screen *_screen[BUFFER_COUNT] = {};
218  Screen *_workScreen = nullptr;
219  Screen *_oldWorkScreen = nullptr; // used in hideOverlay()
220 
221  Graphics::Surface _chunkySurface;
222 
223  bool _overlayVisible = true;
224  bool _overlayPending = true;
225  bool _ignoreHideOverlay = true;
226  Graphics::Surface _overlaySurface;
227 
228  Palette _palette;
229  Palette _overlayPalette;
230 };
231 
232 #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-graphics.h:39
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