ScummVM API documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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", kDirectRendering },
56  { "single", "Single buffering", kSingleBuffering },
57  { "triple", "Triple buffering", kTripleBuffering },
58  { nullptr, nullptr, 0 }
59  };
60  return graphicsModes;
61  }
62  int getDefaultGraphicsMode() const override { return kTripleBuffering; }
63  bool setGraphicsMode(int mode, uint flags = OSystem::kGfxModeNoFlags) override;
64  int getGraphicsMode() const override { return _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 _overlayState == kOverlayVisible; }
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 {
104  if (isOverlayVisible()) {
105  return _screen[kOverlayBuffer]->cursor.getPosition();
106  } else {
107  // kFrontBuffer is always up to date
108  return _screen[kFrontBuffer]->cursor.getPosition();
109  }
110  }
111  void updateMousePosition(int deltaX, int deltaY);
112 
113  bool notifyEvent(const Common::Event &event) override;
114  Common::Keymap *getKeymap() const;
115 
116 protected:
117  typedef void* (*AtariMemAlloc)(size_t bytes);
118  typedef void (*AtariMemFree)(void *ptr);
119 
120  void allocateSurfaces();
121  void freeSurfaces();
122 
123 private:
124  enum {
125  kUnknownMode = -1,
126  kDirectRendering = 0,
127  kSingleBuffering = 1,
128  kTripleBuffering = 3
129  };
130 
131  enum CustomEventAction {
132  kActionToggleAspectRatioCorrection = 100,
133  };
134 
135 #ifndef DISABLE_FANCY_THEMES
136  int16 getMaximumScreenHeight() const { return 480; }
137  int16 getMaximumScreenWidth() const { return _tt ? 320 : (_vgaMonitor ? 640 : 640*1.2); }
138 #else
139  int16 getMaximumScreenHeight() const { return _tt ? 480 : 240; }
140  int16 getMaximumScreenWidth() const { return _tt ? 320 : (_vgaMonitor ? 320 : 320*1.2); }
141 #endif
142 
143  void unlockScreenInternal(const Graphics::Surface &dstSurface,
144  int x, int y, int w, int h);
145  bool updateScreenInternal(Screen *dstScreen, const Graphics::Surface &srcSurface);
146  void copyRectToScreenInternal(Graphics::Surface &dstSurface,
147  const void *buf, int pitch, int x, int y, int w, int h,
148  const Graphics::PixelFormat &format, bool directRendering);
149 
150  int getBitsPerPixel(const Graphics::PixelFormat &format) const;
151 
152  bool isOverlayDirectRendering() const;
153 
154  virtual AtariMemAlloc getStRamAllocFunc() const {
155  return [](size_t bytes) { return (void*)Mxalloc(bytes, MX_STRAM); };
156  }
157  virtual AtariMemFree getStRamFreeFunc() const {
158  return [](void *ptr) { Mfree(ptr); };
159  }
160 
161  virtual void copyRectToSurface(Graphics::Surface &dstSurface, int dstBitsPerPixel, const Graphics::Surface &srcSurface,
162  int destX, int destY,
163  const Common::Rect &subRect) const {
164  dstSurface.copyRectToSurface(srcSurface, destX, destY, subRect);
165  }
166 
167  virtual void drawMaskedSprite(Graphics::Surface &dstSurface, int dstBitsPerPixel,
168  const Graphics::Surface &srcSurface, const Graphics::Surface &srcMask,
169  int destX, int destY,
170  const Common::Rect &subRect) = 0;
171 
172  virtual Common::Rect alignRect(int x, int y, int w, int h) const = 0;
173 
174  Common::Rect alignRect(const Common::Rect &rect) const {
175  return alignRect(rect.left, rect.top, rect.width(), rect.height());
176  }
177 
178  bool _vgaMonitor = true;
179  bool _tt = false;
180  bool _checkUnalignedPitch = false;
181 
182  struct GraphicsState {
183  GraphicsState()
184  : inTransaction(false)
185  , mode(kUnknownMode)
186  , width(0)
187  , height(0)
188  , format(Graphics::PixelFormat()) {
189  }
190 
191  bool isValid() const {
192  return mode != kUnknownMode && width > 0 && height > 0 && format.bytesPerPixel != 0;
193  }
194 
195  bool inTransaction;
196  int mode;
197  int width;
198  int height;
199  Graphics::PixelFormat format;
200  };
201  GraphicsState _pendingState;
202  GraphicsState _currentState;
203 
204  // feature flags
205  bool _aspectRatioCorrection = false;
206 
207  PendingScreenChanges _pendingScreenChanges;
208 
209  enum {
210  kFrontBuffer = 0,
211  kBackBuffer1 = 1,
212  kBackBuffer2 = 2,
213  kOverlayBuffer = 3,
214  kBufferCount
215  };
216  Screen *_screen[kBufferCount] = {};
217 
218  Graphics::Surface _chunkySurface;
219 
220  enum {
221  kOverlayVisible,
222  kOverlayIgnoredHide,
223  kOverlayHidden
224  };
225  int _overlayState = kOverlayHidden;
226  bool _ignoreHideOverlay = true;
227  Graphics::Surface _overlaySurface;
228 
229  Palette _palette;
230  Palette _overlayPalette;
231 };
232 
233 #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:192
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:33
Definition: atari-graphics.h:40
void copyRectToSurface(const void *buffer, int srcPitch, int destX, int destY, int width, int height)
byte bytesPerPixel
Definition: pixelformat.h:139
int16 height() const
Definition: rect.h:193
Definition: atari-screen.h:44