22 #ifndef BACKENDS_GRAPHICS_ATARI_H 23 #define BACKENDS_GRAPHICS_ATARI_H 25 #include "backends/graphics/graphics.h" 26 #include "common/events.h" 28 #include <mint/osbind.h> 29 #include <mint/ostruct.h> 30 #include <unordered_set> 32 #include "common/rect.h" 33 #include "graphics/surface.h" 38 std::size_t operator()(
Common::Rect const& rect)
const noexcept
40 return 31 * (31 * (31 * rect.
left + rect.top) + rect.
right) + rect.bottom;
57 {
"direct",
"Direct rendering", (int)GraphicsMode::DirectRendering },
58 {
"single",
"Single buffering", (int)GraphicsMode::SingleBuffering },
59 {
"triple",
"Triple buffering", (int)GraphicsMode::TripleBuffering },
60 {
nullptr,
nullptr, 0 }
64 int getDefaultGraphicsMode()
const override {
return (
int)GraphicsMode::TripleBuffering; }
66 int getGraphicsMode()
const override {
return (
int)_currentState.mode; }
70 int getScreenChangeID()
const override {
return 0; }
72 void beginGFXTransaction()
override;
75 int16 getHeight()
const override {
return _currentState.height; }
76 int16 getWidth()
const override {
return _currentState.width; }
77 void setPalette(
const byte *colors, uint start, uint num)
override;
78 void grabPalette(byte *colors, uint start, uint num)
const override;
79 void copyRectToScreen(
const void *buf,
int pitch,
int x,
int y,
int w,
int h)
override;
81 void unlockScreen()
override;
82 void fillScreen(uint32 col)
override;
83 void fillScreen(
const Common::Rect &r, uint32 col)
override;
84 void updateScreen()
override;
85 void setShakePos(
int shakeXOffset,
int shakeYOffset)
override;
86 void setFocusRectangle(
const Common::Rect& rect)
override {}
87 void clearFocusRectangle()
override {}
89 void showOverlay(
bool inGUI)
override;
90 void hideOverlay()
override;
91 bool isOverlayVisible()
const override {
return _overlayVisible; }
93 void clearOverlay()
override;
95 void copyRectToOverlay(
const void *buf,
int pitch,
int x,
int y,
int w,
int h)
override;
96 int16 getOverlayHeight()
const override {
return 480; }
97 int16 getOverlayWidth()
const override {
return _vgaMonitor ? 640 : 640*1.2; }
99 bool showMouse(
bool visible)
override;
100 void warpMouse(
int x,
int y)
override;
101 void setMouseCursor(
const void *buf, uint w, uint h,
int hotspotX,
int hotspotY, uint32 keycolor,
102 bool dontScale =
false,
const Graphics::PixelFormat *format = NULL,
const byte *mask = NULL)
override;
103 void setCursorPalette(
const byte *colors, uint start, uint num)
override;
105 Common::Point getMousePosition()
const {
return _cursor.getPosition(); }
106 void updateMousePosition(
int deltaX,
int deltaY);
112 typedef void* (*AtariMemAlloc)(
size_t bytes);
113 typedef void (*AtariMemFree)(
void *ptr);
115 void allocateSurfaces();
118 enum class GraphicsMode : int {
136 GraphicsState _pendingState{ (GraphicsMode)getDefaultGraphicsMode() };
139 using DirtyRects = std::unordered_set<Common::Rect>;
141 enum CustomEventAction {
142 kActionToggleAspectRatioCorrection = 100,
154 int16 getMaximumScreenHeight()
const {
return 480; }
155 int16 getMaximumScreenWidth()
const {
return _tt ? 320 : (_vgaMonitor ? 640 : 640*1.2); }
157 template <
bool directRendering>
160 void copyRectToScreenInternal(
const void *buf,
int pitch,
int x,
int y,
int w,
int h,
165 bool isOverlayDirectRendering()
const;
167 virtual AtariMemAlloc getStRamAllocFunc()
const {
168 return [](
size_t bytes) {
return (
void*)Mxalloc(bytes, MX_STRAM); };
170 virtual AtariMemFree getStRamFreeFunc()
const {
171 return [](
void *ptr) { Mfree(ptr); };
175 int destX,
int destY,
180 virtual void drawMaskedSprite(
Graphics::Surface &dstSurface,
int dstBitsPerPixel,
182 int destX,
int destY,
185 virtual Common::Rect alignRect(
int x,
int y,
int w,
int h)
const = 0;
191 void cursorPositionChanged() {
192 if (_overlayVisible) {
193 _screen[OVERLAY_BUFFER]->cursorPositionChanged =
true;
195 _screen[FRONT_BUFFER]->cursorPositionChanged
196 = _screen[BACK_BUFFER1]->cursorPositionChanged
197 = _screen[BACK_BUFFER2]->cursorPositionChanged
202 void cursorSurfaceChanged() {
203 if (_overlayVisible) {
204 _screen[OVERLAY_BUFFER]->cursorSurfaceChanged =
true;
206 _screen[FRONT_BUFFER]->cursorSurfaceChanged
207 = _screen[BACK_BUFFER1]->cursorSurfaceChanged
208 = _screen[BACK_BUFFER2]->cursorSurfaceChanged
213 void cursorVisibilityChanged() {
214 if (_overlayVisible) {
215 _screen[OVERLAY_BUFFER]->cursorVisibilityChanged =
true;
217 _screen[FRONT_BUFFER]->cursorVisibilityChanged
218 = _screen[BACK_BUFFER1]->cursorVisibilityChanged
219 = _screen[BACK_BUFFER2]->cursorVisibilityChanged
224 int getOverlayPaletteSize()
const {
225 #ifndef DISABLE_FANCY_THEMES 226 return _tt ? 16 : 256;
232 bool _vgaMonitor =
true;
234 bool _aspectRatioCorrection =
false;
235 bool _oldAspectRatioCorrection =
false;
236 bool _checkUnalignedPitch =
false;
238 GraphicsState _currentState{ (GraphicsMode)getDefaultGraphicsMode() };
240 enum PendingScreenChange {
241 kPendingScreenChangeNone = 0,
242 kPendingScreenChangeMode = 1<<0,
243 kPendingScreenChangeScreen = 1<<1,
244 kPendingScreenChangePalette = 1<<2
246 int _pendingScreenChange = kPendingScreenChangeNone;
259 memset(data, 0,
sizeof(data));
262 uint16 *
const tt =
reinterpret_cast<uint16*
>(data);
263 _RGB *
const falcon =
reinterpret_cast<_RGB*
>(data);
266 byte data[256*4] = {};
273 void reset(
int width,
int height,
int bitsPerPixel);
277 void clearDirtyRects() {
286 const Palette *palette;
287 bool cursorPositionChanged =
true;
288 bool cursorSurfaceChanged =
true;
289 bool cursorVisibilityChanged =
false;
290 DirtyRects dirtyRects;
291 bool fullRedraw =
false;
297 int oldScreenSurfaceWidth = -1;
298 int oldScreenSurfaceHeight = -1;
299 int oldScreenSurfacePitch = -1;
300 int oldOffsettedSurfaceWidth = -1;
301 int oldOffsettedSurfaceHeight = -1;
304 static constexpr
size_t ALIGN = 16;
312 Screen *_screen[BUFFER_COUNT] = {};
313 Screen *_workScreen =
nullptr;
314 Screen *_oldWorkScreen =
nullptr;
318 bool _overlayVisible =
false;
324 bool visible =
false;
330 void setPosition(
int x,
int y) {
336 const int tmpX = _oldX;
337 const int tmpY = _oldY;
347 void setSurface(
const void *buf,
int w,
int h,
int hotspotX,
int hotspotY, uint32 keycolor);
348 template <
bool isClut8>
354 bool isClipped()
const {
355 return outOfScreen ? false : _width != srcRect.width();
357 bool outOfScreen =
true;
362 byte palette[256*3] = {};
365 int _x = -1, _y = -1;
366 int _oldX = -1, _oldY = -1;
369 const byte *_buf =
nullptr;
376 int _rShift, _gShift, _bShift;
377 int _rMask, _gMask, _bMask;
382 Palette _overlayPalette;
Feature
Definition: system.h:417
int16 right
Definition: rect.h:146
int16 width() const
Definition: rect.h:191
TransactionError
Definition: system.h:1148
Definition: algorithm.h:29
int16 left
Definition: rect.h:145
Definition: graphics.h:36
Definition: atari-graphics.h:46
void copyRectToSurface(const void *buffer, int srcPitch, int destX, int destY, int width, int height)
int16 height() const
Definition: rect.h:192
Definition: atari-graphics.h:124