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 "graphics/surface.h"
29 
30 #include "atari-cursor.h"
31 #include "atari-pendingscreenchanges.h"
32 #include "atari-screen.h"
33 #include "atari-supervidel.h"
34 
35 #define MAX_HZ_SHAKE 16 // Falcon only
36 #define MAX_V_SHAKE 16
37 
39  friend class PendingScreenChanges;
40 
41 public:
43  virtual ~AtariGraphicsManager();
44 
45  bool hasFeature(OSystem::Feature f) const override;
46  void setFeatureState(OSystem::Feature f, bool enable) override;
47  bool getFeatureState(OSystem::Feature f) const override;
48 
49  const OSystem::GraphicsMode *getSupportedGraphicsModes() const override {
50  static const OSystem::GraphicsMode graphicsModes[] = {
51  { "direct", "Direct rendering", kDirectRendering },
52  { "single", "Single buffering", kSingleBuffering },
53  { "triple", "Triple buffering", kTripleBuffering },
54  { nullptr, nullptr, 0 }
55  };
56  return graphicsModes;
57  }
58  int getDefaultGraphicsMode() const override { return kTripleBuffering; }
59  bool setGraphicsMode(int mode, uint flags = OSystem::kGfxModeNoFlags) override;
60  int getGraphicsMode() const override { return _currentState.mode; }
61 
62  void initSize(uint width, uint height, const Graphics::PixelFormat *format = NULL) override;
63 
64  int getScreenChangeID() const override { return 0; }
65 
66  void beginGFXTransaction() override;
67  OSystem::TransactionError endGFXTransaction() override;
68 
69  int16 getHeight() const override { return _currentState.height; }
70  int16 getWidth() const override { return _currentState.width; }
71  void setPalette(const byte *colors, uint start, uint num) override;
72  void grabPalette(byte *colors, uint start, uint num) const override;
73  void copyRectToScreen(const void *buf, int pitch, int x, int y, int w, int h) override;
74  Graphics::Surface *lockScreen() override;
75  void unlockScreen() override;
76  void fillScreen(uint32 col) override;
77  void fillScreen(const Common::Rect &r, uint32 col) override;
78  void updateScreen() override;
79  void setShakePos(int shakeXOffset, int shakeYOffset) override;
80  void setFocusRectangle(const Common::Rect& rect) override {}
81  void clearFocusRectangle() override {}
82 
83  void showOverlay(bool inGUI) override;
84  void hideOverlay() override;
85  bool isOverlayVisible() const override { return _overlayState == kOverlayVisible; }
86  Graphics::PixelFormat getOverlayFormat() const override;
87  void clearOverlay() override;
88  void grabOverlay(Graphics::Surface &surface) const override;
89  void copyRectToOverlay(const void *buf, int pitch, int x, int y, int w, int h) override;
90  int16 getOverlayHeight() const override { return 480; }
91  int16 getOverlayWidth() const override { return _vgaMonitor ? 640 : 640*1.2; }
92 
93  bool showMouse(bool visible) override;
94  void warpMouse(int x, int y) override;
95  void setMouseCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor,
96  bool dontScale = false, const Graphics::PixelFormat *format = NULL, const byte *mask = NULL) override;
97  void setCursorPalette(const byte *colors, uint start, uint num) override;
98 
99  Common::Point getMousePosition() const {
100  if (isOverlayVisible()) {
101  return _screen[kOverlayBuffer]->cursor.getPosition();
102  } else {
103  // kFrontBuffer is always up to date
104  return _screen[kFrontBuffer]->cursor.getPosition();
105  }
106  }
107  void updateMousePosition(int deltaX, int deltaY);
108 
109  bool notifyEvent(const Common::Event &event) override;
110  Common::Keymap *getKeymap() const;
111 
112 private:
113  enum {
114  kUnknownMode = -1,
115  kDirectRendering = 0,
116  kSingleBuffering = 1,
117  kTripleBuffering = 3
118  };
119 
120  enum CustomEventAction {
121  kActionToggleAspectRatioCorrection = 100,
122  };
123 
124  void allocateSurfaces();
125  void freeSurfaces();
126 
127 #ifndef DISABLE_FANCY_THEMES
128  int16 getMaximumScreenHeight() const { return 480; }
129  int16 getMaximumScreenWidth() const { return _tt ? 320 : (_vgaMonitor ? 640 : 640*1.2); }
130 #else
131  int16 getMaximumScreenHeight() const { return _tt ? 480 : 240; }
132  int16 getMaximumScreenWidth() const { return _tt ? 320 : (_vgaMonitor ? 320 : 320*1.2); }
133 #endif
134 
135  void addDirtyRectToScreens(const Graphics::Surface &dstSurface,
136  int x, int y, int w, int h, bool directRendering);
137  bool updateScreenInternal(Screen *dstScreen, const Graphics::Surface *srcSurface);
138  void copyRectToAtariSurface(AtariSurface &dstSurface,
139  const byte *buf, int pitch, int x, int y, int w, int h);
140 
141  bool isOverlayDirectRendering() const {
142 #ifndef DISABLE_FANCY_THEMES
143  // see osystem_atari.cpp
144  extern bool g_gameEngineActive;
145 #endif
146  // overlay is direct rendered if in the launcher or if game is directly rendered
147  // (on SuperVidel we always want to use _overlaySurface as source for background pixels)
148  return !g_hasSuperVidel
149 #ifndef DISABLE_FANCY_THEMES
150  && (!g_gameEngineActive || _currentState.mode == kDirectRendering)
151 #endif
152  ;
153  }
154 
155  Graphics::Surface *lockOverlay();
156 
157  bool _vgaMonitor = true;
158  bool _tt = false;
159 
160  struct GraphicsState {
161  GraphicsState()
162  : inTransaction(false)
163  , mode(kUnknownMode)
164  , width(0)
165  , height(0)
166  , format(Graphics::PixelFormat()) {
167  }
168 
169  bool isValid() const {
170  return mode != kUnknownMode && width > 0 && height > 0 && format.bytesPerPixel != 0;
171  }
172 
173  bool inTransaction;
174  int mode;
175  int width;
176  int height;
177  Graphics::PixelFormat format;
178  };
179  GraphicsState _pendingState;
180  GraphicsState _currentState;
181 
182  // feature flags
183  bool _aspectRatioCorrection = false;
184 
185  PendingScreenChanges _pendingScreenChanges;
186 
187  enum {
188  kFrontBuffer = 0,
189  kBackBuffer1 = 1,
190  kBackBuffer2 = 2,
191  kOverlayBuffer = 3,
192  kBufferCount
193  };
194  Screen *_screen[kBufferCount] = {};
195 
196  Graphics::Surface _chunkySurface;
197  Graphics::Surface _chunkySurfaceOffsetted;
198 
199  enum {
200  kOverlayVisible,
201  kOverlayIgnoredHide,
202  kOverlayHidden
203  };
204  int _overlayState = kOverlayHidden;
205  bool _ignoreHideOverlay = true;
206  Graphics::Surface _overlaySurface;
207  bool _ignoreCursorChanges = false;
208 
209  Palette _palette;
210  Palette _overlayPalette;
211 };
212 
213 #endif
Definition: keymap.h:66
Definition: surface.h:67
Definition: system.h:770
bool notifyEvent(const Common::Event &event) override
void grabPalette(byte *colors, uint start, uint num) const override
Definition: pixelformat.h:138
Definition: system.h:721
Feature
Definition: system.h:405
Definition: rect.h:524
Definition: atari-screen.h:58
Definition: atari-surface.h:33
Definition: events.h:329
TransactionError
Definition: system.h:1168
Definition: events.h:210
Definition: rect.h:144
void setPalette(const byte *colors, uint start, uint num) override
Definition: graphics.h:38
Definition: atari-pendingscreenchanges.h:31
Definition: atari-graphics.h:38
Definition: atari-screen.h:42