mirror of
https://github.com/libretro/scummvm.git
synced 2025-03-04 01:07:22 +00:00
BACKENDS: ATARI: Move Screen outside AtariGraphicsManager
This commit is contained in:
parent
957aa15e7e
commit
c7bc03d4f4
@ -21,18 +21,15 @@
|
||||
|
||||
#define FORBIDDEN_SYMBOL_EXCEPTION_FILE // atari-graphics.h's unordered_set
|
||||
|
||||
#include "backends/graphics/atari/atari-graphics.h"
|
||||
#include "atari-graphics.h"
|
||||
|
||||
#include <mint/cookie.h>
|
||||
#include <mint/falcon.h>
|
||||
#include <mint/osbind.h>
|
||||
#include <mint/sysvars.h>
|
||||
|
||||
#include "backends/graphics/atari/atari-graphics-superblitter.h"
|
||||
#include "backends/platform/atari/dlmalloc.h"
|
||||
#include "backends/keymapper/action.h"
|
||||
#include "backends/keymapper/keymap.h"
|
||||
#include "backends/platform/atari/dlmalloc.h"
|
||||
|
||||
#include "common/config-manager.h"
|
||||
#include "common/str.h"
|
||||
#include "common/textconsole.h" // for warning() & error()
|
||||
@ -41,10 +38,9 @@
|
||||
#include "graphics/blit.h"
|
||||
#include "gui/ThemeEngine.h"
|
||||
|
||||
#define SCREEN_ACTIVE
|
||||
#include "atari-graphics-superblitter.h"
|
||||
|
||||
#define MAX_HZ_SHAKE 16 // Falcon only
|
||||
#define MAX_V_SHAKE 16
|
||||
#define SCREEN_ACTIVE
|
||||
|
||||
bool g_unalignedPitch = false;
|
||||
mspace g_mspace = nullptr;
|
||||
@ -991,15 +987,15 @@ template <bool directRendering> // hopefully compiler optimizes all the branchin
|
||||
bool AtariGraphicsManager::updateScreenInternal(const Graphics::Surface &srcSurface) {
|
||||
//debug("updateScreenInternal");
|
||||
|
||||
const DirtyRects &dirtyRects = _workScreen->dirtyRects;
|
||||
Graphics::Surface *dstSurface = _workScreen->offsettedSurf;
|
||||
bool &cursorPositionChanged = _workScreen->cursorPositionChanged;
|
||||
bool &cursorSurfaceChanged = _workScreen->cursorSurfaceChanged;
|
||||
bool &cursorVisibilityChanged = _workScreen->cursorVisibilityChanged;
|
||||
Common::Rect &oldCursorRect = _workScreen->oldCursorRect;
|
||||
const bool &fullRedraw = _workScreen->fullRedraw;
|
||||
const Screen::DirtyRects &dirtyRects = _workScreen->dirtyRects;
|
||||
Graphics::Surface *dstSurface = _workScreen->offsettedSurf;
|
||||
bool &cursorPositionChanged = _workScreen->cursorPositionChanged;
|
||||
bool &cursorSurfaceChanged = _workScreen->cursorSurfaceChanged;
|
||||
bool &cursorVisibilityChanged = _workScreen->cursorVisibilityChanged;
|
||||
Common::Rect &oldCursorRect = _workScreen->oldCursorRect;
|
||||
const bool &fullRedraw = _workScreen->fullRedraw;
|
||||
|
||||
const int dstBitsPerPixel = getBitsPerPixel(dstSurface->format);
|
||||
const int dstBitsPerPixel = getBitsPerPixel(dstSurface->format);
|
||||
|
||||
bool updated = false;
|
||||
|
||||
@ -1129,182 +1125,3 @@ bool AtariGraphicsManager::isOverlayDirectRendering() const {
|
||||
#endif
|
||||
;
|
||||
}
|
||||
|
||||
AtariGraphicsManager::Screen::Screen(AtariGraphicsManager *manager, int width, int height, const Graphics::PixelFormat &format, const Palette *palette_)
|
||||
: _manager(manager)
|
||||
, palette(palette_) {
|
||||
const AtariMemAlloc &allocFunc = _manager->getStRamAllocFunc();
|
||||
|
||||
surf.init(
|
||||
width + (_manager->_tt ? 0 : 2 * MAX_HZ_SHAKE),
|
||||
height + 2 * MAX_V_SHAKE,
|
||||
(width + (_manager->_tt ? 0 : 2 * MAX_HZ_SHAKE)) * _manager->getBitsPerPixel(format) / 8,
|
||||
nullptr,
|
||||
format);
|
||||
|
||||
void *pixelsUnaligned = allocFunc(sizeof(uintptr) + (surf.h * surf.pitch) + ALIGN - 1);
|
||||
if (!pixelsUnaligned) {
|
||||
error("Failed to allocate memory in ST RAM");
|
||||
}
|
||||
|
||||
surf.setPixels((void *)(((uintptr)pixelsUnaligned + sizeof(uintptr) + ALIGN - 1) & (-ALIGN)));
|
||||
|
||||
// store the unaligned pointer for later release
|
||||
*((uintptr *)surf.getPixels() - 1) = (uintptr)pixelsUnaligned;
|
||||
|
||||
memset(surf.getPixels(), 0, surf.h * surf.pitch);
|
||||
|
||||
_offsettedSurf.init(
|
||||
width, height, surf.pitch,
|
||||
surf.getBasePtr((surf.w - width) / 2, (surf.h - height) / 2),
|
||||
surf.format);
|
||||
}
|
||||
|
||||
AtariGraphicsManager::Screen::~Screen() {
|
||||
const AtariMemFree &freeFunc = _manager->getStRamFreeFunc();
|
||||
|
||||
freeFunc((void *)*((uintptr *)surf.getPixels() - 1));
|
||||
}
|
||||
|
||||
void AtariGraphicsManager::Screen::reset(int width, int height, int bitsPerPixel) {
|
||||
cursorPositionChanged = true;
|
||||
cursorSurfaceChanged = true;
|
||||
cursorVisibilityChanged = false;
|
||||
clearDirtyRects();
|
||||
oldCursorRect = Common::Rect();
|
||||
rez = -1;
|
||||
mode = -1;
|
||||
|
||||
// erase old screen
|
||||
_offsettedSurf.fillRect(Common::Rect(_offsettedSurf.w, _offsettedSurf.h), 0);
|
||||
|
||||
if (_manager->_tt) {
|
||||
if (width <= 320 && height <= 240) {
|
||||
surf.w = 320;
|
||||
surf.h = 240 + 2 * MAX_V_SHAKE;
|
||||
surf.pitch = 2 * surf.w * bitsPerPixel / 8;
|
||||
rez = kRezValueTTLow;
|
||||
} else {
|
||||
surf.w = 640;
|
||||
surf.h = 480 + 2 * MAX_V_SHAKE;
|
||||
surf.pitch = surf.w * bitsPerPixel / 8;
|
||||
rez = kRezValueTTMid;
|
||||
}
|
||||
} else {
|
||||
mode = VsetMode(VM_INQUIRE) & PAL;
|
||||
|
||||
if (_manager->_vgaMonitor) {
|
||||
mode |= VGA | (bitsPerPixel == 4 ? BPS4 : (hasSuperVidel() ? BPS8C : BPS8));
|
||||
|
||||
if (width <= 320 && height <= 240) {
|
||||
surf.w = 320;
|
||||
surf.h = 240;
|
||||
mode |= VERTFLAG | COL40;
|
||||
} else {
|
||||
surf.w = 640;
|
||||
surf.h = 480;
|
||||
mode |= COL80;
|
||||
}
|
||||
} else {
|
||||
mode |= TV | (bitsPerPixel == 4 ? BPS4 : BPS8);
|
||||
|
||||
if (width <= 320 && height <= 200) {
|
||||
surf.w = 320;
|
||||
surf.h = 200;
|
||||
mode |= COL40;
|
||||
} else if (width <= 320*1.2 && height <= 200*1.2) {
|
||||
surf.w = 320*1.2;
|
||||
surf.h = 200*1.2;
|
||||
mode |= OVERSCAN | COL40;
|
||||
} else if (width <= 640 && height <= 400) {
|
||||
surf.w = 640;
|
||||
surf.h = 400;
|
||||
mode |= VERTFLAG | COL80;
|
||||
} else {
|
||||
surf.w = 640*1.2;
|
||||
surf.h = 400*1.2;
|
||||
mode |= VERTFLAG | OVERSCAN | COL80;
|
||||
}
|
||||
}
|
||||
|
||||
surf.w += 2 * MAX_HZ_SHAKE;
|
||||
surf.h += 2 * MAX_V_SHAKE;
|
||||
surf.pitch = surf.w * bitsPerPixel / 8;
|
||||
}
|
||||
|
||||
_offsettedSurf.init(
|
||||
width, height, surf.pitch,
|
||||
surf.getBasePtr((surf.w - width) / 2, (surf.h - height) / 2),
|
||||
surf.format);
|
||||
}
|
||||
|
||||
void AtariGraphicsManager::Screen::addDirtyRect(const Graphics::Surface &srcSurface, const Common::Rect &rect, bool directRendering) {
|
||||
if (fullRedraw)
|
||||
return;
|
||||
|
||||
if ((rect.width() == srcSurface.w && rect.height() == srcSurface.h)
|
||||
|| dirtyRects.size() == 128) { // 320x200 can hold at most 250 16x16 rectangles
|
||||
//debug("addDirtyRect[%d]: purge %d x %d", (int)dirtyRects.size(), srcSurface.w, srcSurface.h);
|
||||
|
||||
dirtyRects.clear();
|
||||
dirtyRects.emplace(srcSurface.w, srcSurface.h);
|
||||
|
||||
oldCursorRect = Common::Rect();
|
||||
|
||||
fullRedraw = true;
|
||||
return;
|
||||
}
|
||||
|
||||
dirtyRects.insert(rect);
|
||||
|
||||
if (!oldCursorRect.isEmpty()) {
|
||||
const Common::Rect alignedOldCursorRect = _manager->alignRect(oldCursorRect);
|
||||
|
||||
// we have to check *aligned* oldCursorRect because it is background which gets copied,
|
||||
// i.e. it has to be up to date even outside the cursor rectangle.
|
||||
// do it now to avoid complex checking in updateScreenInternal()
|
||||
if (rect.contains(alignedOldCursorRect)) {
|
||||
oldCursorRect = Common::Rect();
|
||||
} else if (rect.intersects(alignedOldCursorRect)) {
|
||||
if (!directRendering) {
|
||||
_manager->copyRectToSurface(
|
||||
*offsettedSurf, _manager->getBitsPerPixel(offsettedSurf->format), srcSurface,
|
||||
alignedOldCursorRect.left, alignedOldCursorRect.top,
|
||||
alignedOldCursorRect);
|
||||
} else {
|
||||
restoreBackground(alignedOldCursorRect);
|
||||
}
|
||||
|
||||
oldCursorRect = Common::Rect();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AtariGraphicsManager::Screen::storeBackground(const Common::Rect &rect) {
|
||||
const int bitsPerPixel = _manager->getBitsPerPixel(offsettedSurf->format);
|
||||
|
||||
if (_cursorBackgroundSurf.w != rect.width()
|
||||
|| _cursorBackgroundSurf.h != rect.height()
|
||||
|| _cursorBackgroundSurf.format != offsettedSurf->format) {
|
||||
_cursorBackgroundSurf.create(rect.width(), rect.height(), offsettedSurf->format);
|
||||
_cursorBackgroundSurf.pitch = _cursorBackgroundSurf.pitch * bitsPerPixel / 8;
|
||||
}
|
||||
|
||||
Graphics::copyBlit(
|
||||
(byte *)_cursorBackgroundSurf.getPixels(),
|
||||
(const byte *)offsettedSurf->getPixels() + rect.top * offsettedSurf->pitch + rect.left * bitsPerPixel / 8,
|
||||
_cursorBackgroundSurf.pitch, offsettedSurf->pitch,
|
||||
rect.width() * bitsPerPixel / 8, rect.height(), // fake 4bpp by 8bpp's width/2
|
||||
offsettedSurf->format.bytesPerPixel);
|
||||
}
|
||||
|
||||
void AtariGraphicsManager::Screen::restoreBackground(const Common::Rect &rect) {
|
||||
const int bitsPerPixel = _manager->getBitsPerPixel(offsettedSurf->format);
|
||||
|
||||
Graphics::copyBlit(
|
||||
(byte *)offsettedSurf->getPixels() + rect.top * offsettedSurf->pitch + rect.left * bitsPerPixel / 8,
|
||||
(const byte *)_cursorBackgroundSurf.getPixels(),
|
||||
offsettedSurf->pitch, _cursorBackgroundSurf.pitch,
|
||||
rect.width() * bitsPerPixel / 8, rect.height(), // fake 4bpp by 8bpp's width/2
|
||||
offsettedSurf->format.bytesPerPixel);
|
||||
}
|
||||
|
@ -26,25 +26,19 @@
|
||||
#include "common/events.h"
|
||||
|
||||
#include <mint/osbind.h>
|
||||
#include <mint/ostruct.h>
|
||||
#include <unordered_set>
|
||||
|
||||
#include "atari-cursor.h"
|
||||
#include "common/rect.h"
|
||||
#include "graphics/surface.h"
|
||||
|
||||
template<>
|
||||
struct std::hash<Common::Rect>
|
||||
{
|
||||
std::size_t operator()(Common::Rect const& rect) const noexcept
|
||||
{
|
||||
return 31 * (31 * (31 * rect.left + rect.top) + rect.right) + rect.bottom;
|
||||
}
|
||||
};
|
||||
#include "atari-cursor.h"
|
||||
#include "atari-screen.h"
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
#define MAX_HZ_SHAKE 16 // Falcon only
|
||||
#define MAX_V_SHAKE 16
|
||||
|
||||
class AtariGraphicsManager : public GraphicsManager, Common::EventObserver {
|
||||
friend class Screen;
|
||||
|
||||
public:
|
||||
AtariGraphicsManager();
|
||||
virtual ~AtariGraphicsManager();
|
||||
@ -116,42 +110,11 @@ protected:
|
||||
void allocateSurfaces();
|
||||
void freeSurfaces();
|
||||
|
||||
enum class GraphicsMode : int {
|
||||
DirectRendering = 0,
|
||||
SingleBuffering = 1,
|
||||
TripleBuffering = 3
|
||||
};
|
||||
|
||||
struct GraphicsState {
|
||||
GraphicsState(GraphicsMode mode_)
|
||||
: mode(mode_)
|
||||
, width(0)
|
||||
, height(0) {
|
||||
}
|
||||
|
||||
GraphicsMode mode;
|
||||
int width;
|
||||
int height;
|
||||
Graphics::PixelFormat format;
|
||||
};
|
||||
GraphicsState _pendingState{ (GraphicsMode)getDefaultGraphicsMode() };
|
||||
|
||||
private:
|
||||
using DirtyRects = std::unordered_set<Common::Rect>;
|
||||
|
||||
enum CustomEventAction {
|
||||
kActionToggleAspectRatioCorrection = 100,
|
||||
};
|
||||
|
||||
enum SteTtRezValue {
|
||||
kRezValueSTLow = 0, // 320x200@4bpp, ST palette
|
||||
kRezValueSTMid = 1, // 640x200@2bpp, ST palette
|
||||
kRezValueSTHigh = 2, // 640x400@1bpp, ST palette
|
||||
kRezValueTTLow = 7, // 320x480@8bpp, TT palette
|
||||
kRezValueTTMid = 4, // 640x480@4bpp, TT palette
|
||||
kRezValueTTHigh = 6 // 1280x960@1bpp, TT palette
|
||||
};
|
||||
|
||||
int16 getMaximumScreenHeight() const { return 480; }
|
||||
int16 getMaximumScreenWidth() const { return _tt ? 320 : (_vgaMonitor ? 640 : 640*1.2); }
|
||||
|
||||
@ -236,6 +199,25 @@ private:
|
||||
bool _oldAspectRatioCorrection = false;
|
||||
bool _checkUnalignedPitch = false;
|
||||
|
||||
enum class GraphicsMode : int {
|
||||
DirectRendering = 0,
|
||||
SingleBuffering = 1,
|
||||
TripleBuffering = 3
|
||||
};
|
||||
|
||||
struct GraphicsState {
|
||||
GraphicsState(GraphicsMode mode_)
|
||||
: mode(mode_)
|
||||
, width(0)
|
||||
, height(0) {
|
||||
}
|
||||
|
||||
GraphicsMode mode;
|
||||
int width;
|
||||
int height;
|
||||
Graphics::PixelFormat format;
|
||||
};
|
||||
GraphicsState _pendingState{ (GraphicsMode)getDefaultGraphicsMode() };
|
||||
GraphicsState _currentState{ (GraphicsMode)getDefaultGraphicsMode() };
|
||||
|
||||
enum PendingScreenChange {
|
||||
@ -253,63 +235,6 @@ private:
|
||||
OVERLAY_BUFFER,
|
||||
BUFFER_COUNT
|
||||
};
|
||||
|
||||
class Palette {
|
||||
public:
|
||||
void clear() {
|
||||
memset(data, 0, sizeof(data));
|
||||
}
|
||||
|
||||
uint16 *const tt = reinterpret_cast<uint16*>(data);
|
||||
_RGB *const falcon = reinterpret_cast<_RGB*>(data);
|
||||
|
||||
private:
|
||||
byte data[256*4] = {};
|
||||
};
|
||||
|
||||
struct Screen {
|
||||
Screen(AtariGraphicsManager *manager, int width, int height, const Graphics::PixelFormat &format, const Palette *palette);
|
||||
~Screen();
|
||||
|
||||
void reset(int width, int height, int bitsPerPixel);
|
||||
// must be called before any rectangle drawing
|
||||
void addDirtyRect(const Graphics::Surface &srcSurface, const Common::Rect &rect, bool directRendering);
|
||||
|
||||
void clearDirtyRects() {
|
||||
dirtyRects.clear();
|
||||
fullRedraw = false;
|
||||
}
|
||||
|
||||
void storeBackground(const Common::Rect &rect);
|
||||
void restoreBackground(const Common::Rect &rect);
|
||||
|
||||
Graphics::Surface surf;
|
||||
const Palette *palette;
|
||||
bool cursorPositionChanged = true;
|
||||
bool cursorSurfaceChanged = true;
|
||||
bool cursorVisibilityChanged = false;
|
||||
DirtyRects dirtyRects;
|
||||
bool fullRedraw = false;
|
||||
Common::Rect oldCursorRect;
|
||||
int rez = -1;
|
||||
int mode = -1;
|
||||
Graphics::Surface *const offsettedSurf = &_offsettedSurf;
|
||||
|
||||
int oldScreenSurfaceWidth = -1;
|
||||
int oldScreenSurfaceHeight = -1;
|
||||
int oldScreenSurfacePitch = -1;
|
||||
int oldOffsettedSurfaceWidth = -1;
|
||||
int oldOffsettedSurfaceHeight = -1;
|
||||
|
||||
private:
|
||||
static constexpr size_t ALIGN = 16; // 16 bytes
|
||||
|
||||
const AtariGraphicsManager *_manager;
|
||||
|
||||
Graphics::Surface _offsettedSurf;
|
||||
// used by direct rendering
|
||||
Graphics::Surface _cursorBackgroundSurf;
|
||||
};
|
||||
Screen *_screen[BUFFER_COUNT] = {};
|
||||
Screen *_workScreen = nullptr;
|
||||
Screen *_oldWorkScreen = nullptr; // used in hideOverlay()
|
||||
|
208
backends/graphics/atari/atari-screen.cpp
Normal file
208
backends/graphics/atari/atari-screen.cpp
Normal file
@ -0,0 +1,208 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "atari-screen.h"
|
||||
|
||||
#include <mint/falcon.h>
|
||||
|
||||
#include "graphics/blit.h"
|
||||
|
||||
#include "atari-graphics.h"
|
||||
#include "atari-graphics-superblitter.h"
|
||||
|
||||
Screen::Screen(AtariGraphicsManager *manager, int width, int height, const Graphics::PixelFormat &format, const Palette *palette_)
|
||||
: _manager(manager)
|
||||
, palette(palette_) {
|
||||
const AtariGraphicsManager::AtariMemAlloc &allocFunc = _manager->getStRamAllocFunc();
|
||||
|
||||
surf.init(
|
||||
width + (_manager->_tt ? 0 : 2 * MAX_HZ_SHAKE),
|
||||
height + 2 * MAX_V_SHAKE,
|
||||
(width + (_manager->_tt ? 0 : 2 * MAX_HZ_SHAKE)) * _manager->getBitsPerPixel(format) / 8,
|
||||
nullptr,
|
||||
format);
|
||||
|
||||
void *pixelsUnaligned = allocFunc(sizeof(uintptr) + (surf.h * surf.pitch) + ALIGN - 1);
|
||||
if (!pixelsUnaligned) {
|
||||
error("Failed to allocate memory in ST RAM");
|
||||
}
|
||||
|
||||
surf.setPixels((void *)(((uintptr)pixelsUnaligned + sizeof(uintptr) + ALIGN - 1) & (-ALIGN)));
|
||||
|
||||
// store the unaligned pointer for later release
|
||||
*((uintptr *)surf.getPixels() - 1) = (uintptr)pixelsUnaligned;
|
||||
|
||||
memset(surf.getPixels(), 0, surf.h * surf.pitch);
|
||||
|
||||
_offsettedSurf.init(
|
||||
width, height, surf.pitch,
|
||||
surf.getBasePtr((surf.w - width) / 2, (surf.h - height) / 2),
|
||||
surf.format);
|
||||
}
|
||||
|
||||
Screen::~Screen() {
|
||||
const AtariGraphicsManager::AtariMemFree &freeFunc = _manager->getStRamFreeFunc();
|
||||
|
||||
freeFunc((void *)*((uintptr *)surf.getPixels() - 1));
|
||||
}
|
||||
|
||||
void Screen::reset(int width, int height, int bitsPerPixel) {
|
||||
cursorPositionChanged = true;
|
||||
cursorSurfaceChanged = true;
|
||||
cursorVisibilityChanged = false;
|
||||
clearDirtyRects();
|
||||
oldCursorRect = Common::Rect();
|
||||
rez = -1;
|
||||
mode = -1;
|
||||
|
||||
// erase old screen
|
||||
_offsettedSurf.fillRect(Common::Rect(_offsettedSurf.w, _offsettedSurf.h), 0);
|
||||
|
||||
if (_manager->_tt) {
|
||||
if (width <= 320 && height <= 240) {
|
||||
surf.w = 320;
|
||||
surf.h = 240 + 2 * MAX_V_SHAKE;
|
||||
surf.pitch = 2 * surf.w * bitsPerPixel / 8;
|
||||
rez = kRezValueTTLow;
|
||||
} else {
|
||||
surf.w = 640;
|
||||
surf.h = 480 + 2 * MAX_V_SHAKE;
|
||||
surf.pitch = surf.w * bitsPerPixel / 8;
|
||||
rez = kRezValueTTMid;
|
||||
}
|
||||
} else {
|
||||
mode = VsetMode(VM_INQUIRE) & PAL;
|
||||
|
||||
if (_manager->_vgaMonitor) {
|
||||
mode |= VGA | (bitsPerPixel == 4 ? BPS4 : (hasSuperVidel() ? BPS8C : BPS8));
|
||||
|
||||
if (width <= 320 && height <= 240) {
|
||||
surf.w = 320;
|
||||
surf.h = 240;
|
||||
mode |= VERTFLAG | COL40;
|
||||
} else {
|
||||
surf.w = 640;
|
||||
surf.h = 480;
|
||||
mode |= COL80;
|
||||
}
|
||||
} else {
|
||||
mode |= TV | (bitsPerPixel == 4 ? BPS4 : BPS8);
|
||||
|
||||
if (width <= 320 && height <= 200) {
|
||||
surf.w = 320;
|
||||
surf.h = 200;
|
||||
mode |= COL40;
|
||||
} else if (width <= 320*1.2 && height <= 200*1.2) {
|
||||
surf.w = 320*1.2;
|
||||
surf.h = 200*1.2;
|
||||
mode |= OVERSCAN | COL40;
|
||||
} else if (width <= 640 && height <= 400) {
|
||||
surf.w = 640;
|
||||
surf.h = 400;
|
||||
mode |= VERTFLAG | COL80;
|
||||
} else {
|
||||
surf.w = 640*1.2;
|
||||
surf.h = 400*1.2;
|
||||
mode |= VERTFLAG | OVERSCAN | COL80;
|
||||
}
|
||||
}
|
||||
|
||||
surf.w += 2 * MAX_HZ_SHAKE;
|
||||
surf.h += 2 * MAX_V_SHAKE;
|
||||
surf.pitch = surf.w * bitsPerPixel / 8;
|
||||
}
|
||||
|
||||
_offsettedSurf.init(
|
||||
width, height, surf.pitch,
|
||||
surf.getBasePtr((surf.w - width) / 2, (surf.h - height) / 2),
|
||||
surf.format);
|
||||
}
|
||||
|
||||
void Screen::addDirtyRect(const Graphics::Surface &srcSurface, const Common::Rect &rect, bool directRendering) {
|
||||
if (fullRedraw)
|
||||
return;
|
||||
|
||||
if ((rect.width() == srcSurface.w && rect.height() == srcSurface.h)
|
||||
|| dirtyRects.size() == 128) { // 320x200 can hold at most 250 16x16 rectangles
|
||||
//debug("addDirtyRect[%d]: purge %d x %d", (int)dirtyRects.size(), srcSurface.w, srcSurface.h);
|
||||
|
||||
dirtyRects.clear();
|
||||
dirtyRects.emplace(srcSurface.w, srcSurface.h);
|
||||
|
||||
oldCursorRect = Common::Rect();
|
||||
|
||||
fullRedraw = true;
|
||||
return;
|
||||
}
|
||||
|
||||
dirtyRects.insert(rect);
|
||||
|
||||
if (!oldCursorRect.isEmpty()) {
|
||||
const Common::Rect alignedOldCursorRect = _manager->alignRect(oldCursorRect);
|
||||
|
||||
// we have to check *aligned* oldCursorRect because it is background which gets copied,
|
||||
// i.e. it has to be up to date even outside the cursor rectangle.
|
||||
// do it now to avoid complex checking in updateScreenInternal()
|
||||
if (rect.contains(alignedOldCursorRect)) {
|
||||
oldCursorRect = Common::Rect();
|
||||
} else if (rect.intersects(alignedOldCursorRect)) {
|
||||
if (!directRendering) {
|
||||
_manager->copyRectToSurface(
|
||||
*offsettedSurf, _manager->getBitsPerPixel(offsettedSurf->format), srcSurface,
|
||||
alignedOldCursorRect.left, alignedOldCursorRect.top,
|
||||
alignedOldCursorRect);
|
||||
} else {
|
||||
restoreBackground(alignedOldCursorRect);
|
||||
}
|
||||
|
||||
oldCursorRect = Common::Rect();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Screen::storeBackground(const Common::Rect &rect) {
|
||||
const int bitsPerPixel = _manager->getBitsPerPixel(offsettedSurf->format);
|
||||
|
||||
if (_cursorBackgroundSurf.w != rect.width()
|
||||
|| _cursorBackgroundSurf.h != rect.height()
|
||||
|| _cursorBackgroundSurf.format != offsettedSurf->format) {
|
||||
_cursorBackgroundSurf.create(rect.width(), rect.height(), offsettedSurf->format);
|
||||
_cursorBackgroundSurf.pitch = _cursorBackgroundSurf.pitch * bitsPerPixel / 8;
|
||||
}
|
||||
|
||||
Graphics::copyBlit(
|
||||
(byte *)_cursorBackgroundSurf.getPixels(),
|
||||
(const byte *)offsettedSurf->getPixels() + rect.top * offsettedSurf->pitch + rect.left * bitsPerPixel / 8,
|
||||
_cursorBackgroundSurf.pitch, offsettedSurf->pitch,
|
||||
rect.width() * bitsPerPixel / 8, rect.height(), // fake 4bpp by 8bpp's width/2
|
||||
offsettedSurf->format.bytesPerPixel);
|
||||
}
|
||||
|
||||
void Screen::restoreBackground(const Common::Rect &rect) {
|
||||
const int bitsPerPixel = _manager->getBitsPerPixel(offsettedSurf->format);
|
||||
|
||||
Graphics::copyBlit(
|
||||
(byte *)offsettedSurf->getPixels() + rect.top * offsettedSurf->pitch + rect.left * bitsPerPixel / 8,
|
||||
(const byte *)_cursorBackgroundSurf.getPixels(),
|
||||
offsettedSurf->pitch, _cursorBackgroundSurf.pitch,
|
||||
rect.width() * bitsPerPixel / 8, rect.height(), // fake 4bpp by 8bpp's width/2
|
||||
offsettedSurf->format.bytesPerPixel);
|
||||
}
|
110
backends/graphics/atari/atari-screen.h
Normal file
110
backends/graphics/atari/atari-screen.h
Normal file
@ -0,0 +1,110 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef BACKENDS_GRAPHICS_ATARI_SCREEN_H
|
||||
#define BACKENDS_GRAPHICS_ATARI_SCREEN_H
|
||||
|
||||
#include <unordered_set>
|
||||
#include <mint/ostruct.h>
|
||||
|
||||
#include "common/rect.h"
|
||||
#include "graphics/surface.h"
|
||||
|
||||
template<>
|
||||
struct std::hash<Common::Rect>
|
||||
{
|
||||
std::size_t operator()(Common::Rect const& rect) const noexcept
|
||||
{
|
||||
return 31 * (31 * (31 * rect.left + rect.top) + rect.right) + rect.bottom;
|
||||
}
|
||||
};
|
||||
|
||||
class AtariGraphicsManager;
|
||||
|
||||
class Palette {
|
||||
public:
|
||||
void clear() {
|
||||
memset(data, 0, sizeof(data));
|
||||
}
|
||||
|
||||
uint16 *const tt = reinterpret_cast<uint16*>(data);
|
||||
_RGB *const falcon = reinterpret_cast<_RGB*>(data);
|
||||
|
||||
private:
|
||||
byte data[256*4] = {};
|
||||
};
|
||||
|
||||
struct Screen {
|
||||
using DirtyRects = std::unordered_set<Common::Rect>;
|
||||
|
||||
Screen(AtariGraphicsManager *manager, int width, int height, const Graphics::PixelFormat &format, const Palette *palette);
|
||||
~Screen();
|
||||
|
||||
void reset(int width, int height, int bitsPerPixel);
|
||||
// must be called before any rectangle drawing
|
||||
void addDirtyRect(const Graphics::Surface &srcSurface, const Common::Rect &rect, bool directRendering);
|
||||
|
||||
void clearDirtyRects() {
|
||||
dirtyRects.clear();
|
||||
fullRedraw = false;
|
||||
}
|
||||
|
||||
void storeBackground(const Common::Rect &rect);
|
||||
void restoreBackground(const Common::Rect &rect);
|
||||
|
||||
Graphics::Surface surf;
|
||||
const Palette *palette;
|
||||
bool cursorPositionChanged = true;
|
||||
bool cursorSurfaceChanged = true;
|
||||
bool cursorVisibilityChanged = false;
|
||||
DirtyRects dirtyRects;
|
||||
bool fullRedraw = false;
|
||||
Common::Rect oldCursorRect;
|
||||
int rez = -1;
|
||||
int mode = -1;
|
||||
Graphics::Surface *const offsettedSurf = &_offsettedSurf;
|
||||
|
||||
int oldScreenSurfaceWidth = -1;
|
||||
int oldScreenSurfaceHeight = -1;
|
||||
int oldScreenSurfacePitch = -1;
|
||||
int oldOffsettedSurfaceWidth = -1;
|
||||
int oldOffsettedSurfaceHeight = -1;
|
||||
|
||||
private:
|
||||
static constexpr size_t ALIGN = 16; // 16 bytes
|
||||
|
||||
enum SteTtRezValue {
|
||||
kRezValueSTLow = 0, // 320x200@4bpp, ST palette
|
||||
kRezValueSTMid = 1, // 640x200@2bpp, ST palette
|
||||
kRezValueSTHigh = 2, // 640x400@1bpp, ST palette
|
||||
kRezValueTTLow = 7, // 320x480@8bpp, TT palette
|
||||
kRezValueTTMid = 4, // 640x480@4bpp, TT palette
|
||||
kRezValueTTHigh = 6 // 1280x960@1bpp, TT palette
|
||||
};
|
||||
|
||||
const AtariGraphicsManager *_manager;
|
||||
|
||||
Graphics::Surface _offsettedSurf;
|
||||
// used by direct rendering
|
||||
Graphics::Surface _cursorBackgroundSurf;
|
||||
};
|
||||
|
||||
#endif // BACKENDS_GRAPHICS_ATARI_SCREEN_H
|
@ -371,6 +371,7 @@ MODULE_OBJS += \
|
||||
graphics/atari/atari-cursor.o \
|
||||
graphics/atari/atari-graphics.o \
|
||||
graphics/atari/atari-graphics-asm.o \
|
||||
graphics/atari/atari-screen.o \
|
||||
mixer/atari/atari-mixer.o
|
||||
endif
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user