diff options
| author | Alejandro Marzini | 2010-06-30 04:46:55 +0000 |
|---|---|---|
| committer | Alejandro Marzini | 2010-06-30 04:46:55 +0000 |
| commit | c174d5327bfaf55d998cf67f3e4f49a0eaf2ed39 (patch) | |
| tree | b642082f28dd9de53c95f64aba19a4a789bd2bfc /backends/graphics | |
| parent | afd2a2c01d4bf3686a54c631d1cd4228ba1d710c (diff) | |
| download | scummvm-rg350-c174d5327bfaf55d998cf67f3e4f49a0eaf2ed39.tar.gz scummvm-rg350-c174d5327bfaf55d998cf67f3e4f49a0eaf2ed39.tar.bz2 scummvm-rg350-c174d5327bfaf55d998cf67f3e4f49a0eaf2ed39.zip | |
Modularized GP2XWIZ backend.
svn-id: r50514
Diffstat (limited to 'backends/graphics')
| -rw-r--r-- | backends/graphics/gp2xwizsdl/gp2xwizsdl-graphics.cpp | 445 | ||||
| -rw-r--r-- | backends/graphics/gp2xwizsdl/gp2xwizsdl-graphics.h | 58 | ||||
| -rw-r--r-- | backends/graphics/sdl/sdl-graphics.h | 66 |
3 files changed, 536 insertions, 33 deletions
diff --git a/backends/graphics/gp2xwizsdl/gp2xwizsdl-graphics.cpp b/backends/graphics/gp2xwizsdl/gp2xwizsdl-graphics.cpp new file mode 100644 index 0000000000..3131a7a3a9 --- /dev/null +++ b/backends/graphics/gp2xwizsdl/gp2xwizsdl-graphics.cpp @@ -0,0 +1,445 @@ +/* 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 2 + * 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + * + */ + +#ifndef GP2XWIZ + +#include "backends/graphics/gp2xwizsdl/gp2xwizsdl-graphics.h" +#include "backends/events/gp2xwizsdl/gp2xwizsdl-events.h" + +#include "common/mutex.h" +#include "graphics/scaler/aspect.h" +#include "graphics/scaler/downscaler.h" + +static const OSystem::GraphicsMode s_supportedGraphicsModes[] = { + {"1x", "Fullscreen", GFX_NORMAL}, +// {"½x", "Downscale", GFX_HALF}, + {0, 0, 0} +}; + +const OSystem::GraphicsMode *GP2XWIZSdlGraphicsManager::getSupportedGraphicsModes() const { + return s_supportedGraphicsModes; +} + +int GP2XWIZSdlGraphicsManager::getDefaultGraphicsMode() const { + return GFX_NORMAL; +} + +bool GP2XWIZSdlGraphicsManager::setGraphicsMode(int mode) { + Common::StackLock lock(_graphicsMutex); + + assert(_transactionMode == kTransactionActive); + + if (_oldVideoMode.setup && _oldVideoMode.mode == mode) + return true; + + int newScaleFactor = 1; + + switch (mode) { + case GFX_NORMAL: + newScaleFactor = 1; + break; + case GFX_HALF: + newScaleFactor = 1; + break; + default: + warning("unknown gfx mode %d", mode); + return false; + } + + _transactionDetails.normal1xScaler = (mode == GFX_NORMAL); + if (_oldVideoMode.setup && _oldVideoMode.scaleFactor != newScaleFactor) + _transactionDetails.needHotswap = true; + + _transactionDetails.needUpdatescreen = true; + + _videoMode.mode = mode; + _videoMode.scaleFactor = newScaleFactor; + + return true; +} + +void GP2XWIZSdlGraphicsManager::setGraphicsModeIntern() { + Common::StackLock lock(_graphicsMutex); + ScalerProc *newScalerProc = 0; + + switch (_videoMode.mode) { + case GFX_NORMAL: + newScalerProc = Normal1x; + break; + case GFX_HALF: + newScalerProc = DownscaleAllByHalf; + break; + + default: + error("Unknown gfx mode %d", _videoMode.mode); + } + + _scalerProc = newScalerProc; + + if (!_screen || !_hwscreen) + return; + + // Blit everything to the screen + _forceFull = true; + + // Even if the old and new scale factors are the same, we may have a + // different scaler for the cursor now. + blitCursor(); +} + +void GP2XWIZSdlGraphicsManager::initSize(uint w, uint h) { + assert(_transactionMode == kTransactionActive); + + // Avoid redundant res changes + if ((int)w == _videoMode.screenWidth && (int)h == _videoMode.screenHeight) + return; + + _videoMode.screenWidth = w; + _videoMode.screenHeight = h; + if (w > 320 || h > 240){ + setGraphicsMode(GFX_HALF); + setGraphicsModeIntern(); + ((GP2XWIZSdlEventManager *)g_system->getEventManager())->toggleMouseGrab(); + } + + _transactionDetails.sizeChanged = true; +} + +bool GP2XWIZSdlGraphicsManager::loadGFXMode() { + _videoMode.overlayWidth = 320; + _videoMode.overlayHeight = 240; + _videoMode.fullscreen = true; + + if (_videoMode.screenHeight != 200 && _videoMode.screenHeight != 400) + _videoMode.aspectRatioCorrection = false; + + return SdlGraphicsManager::loadGFXMode(); +} + +void GP2XWIZSdlGraphicsManager::drawMouse() { + if (!_mouseVisible || !_mouseSurface) { + _mouseBackup.x = _mouseBackup.y = _mouseBackup.w = _mouseBackup.h = 0; + return; + } + + SDL_Rect dst; + int scale; + int hotX, hotY; + + if (_videoMode.mode == GFX_HALF && !_overlayVisible){ + dst.x = _mouseCurState.x/2; + dst.y = _mouseCurState.y/2; + } else { + dst.x = _mouseCurState.x; + dst.y = _mouseCurState.y; + } + + if (!_overlayVisible) { + scale = _videoMode.scaleFactor; + dst.w = _mouseCurState.vW; + dst.h = _mouseCurState.vH; + hotX = _mouseCurState.vHotX; + hotY = _mouseCurState.vHotY; + } else { + scale = 1; + dst.w = _mouseCurState.rW; + dst.h = _mouseCurState.rH; + hotX = _mouseCurState.rHotX; + hotY = _mouseCurState.rHotY; + } + + // The mouse is undrawn using virtual coordinates, i.e. they may be + // scaled and aspect-ratio corrected. + + _mouseBackup.x = dst.x - hotX; + _mouseBackup.y = dst.y - hotY; + _mouseBackup.w = dst.w; + _mouseBackup.h = dst.h; + + // We draw the pre-scaled cursor image, so now we need to adjust for + // scaling, shake position and aspect ratio correction manually. + + if (!_overlayVisible) { + dst.y += _currentShakePos; + } + + if (_videoMode.aspectRatioCorrection && !_overlayVisible) + dst.y = real2Aspect(dst.y); + + dst.x = scale * dst.x - _mouseCurState.rHotX; + dst.y = scale * dst.y - _mouseCurState.rHotY; + dst.w = _mouseCurState.rW; + dst.h = _mouseCurState.rH; + + // Note that SDL_BlitSurface() and addDirtyRect() will both perform any + // clipping necessary + + if (SDL_BlitSurface(_mouseSurface, NULL, _hwscreen, &dst) != 0) + error("SDL_BlitSurface failed: %s", SDL_GetError()); + + // The screen will be updated using real surface coordinates, i.e. + // they will not be scaled or aspect-ratio corrected. + addDirtyRect(dst.x, dst.y, dst.w, dst.h, true); +} + +void GP2XWIZSdlGraphicsManager::undrawMouse() { + const int x = _mouseBackup.x; + const int y = _mouseBackup.y; + + // When we switch bigger overlay off mouse jumps. Argh! + // This is intended to prevent undrawing offscreen mouse + if (!_overlayVisible && (x >= _videoMode.screenWidth || y >= _videoMode.screenHeight)) + return; + + if (_mouseBackup.w != 0 && _mouseBackup.h != 0){ + if (_videoMode.mode == GFX_HALF && !_overlayVisible){ + addDirtyRect(x*2, y*2, _mouseBackup.w*2, _mouseBackup.h*2); + } else { + addDirtyRect(x, y, _mouseBackup.w, _mouseBackup.h); + } + } +} + +void GP2XWIZSdlGraphicsManager::internUpdateScreen() { + SDL_Surface *srcSurf, *origSurf; + int height, width; + ScalerProc *scalerProc; + int scale1; + +#if defined (DEBUG) && ! defined(_WIN32_WCE) // definitions not available for non-DEBUG here. (needed this to compile in SYMBIAN32 & linux?) + assert(_hwscreen != NULL); + assert(_hwscreen->map->sw_data != NULL); +#endif + + // If the shake position changed, fill the dirty area with blackness + if (_currentShakePos != _newShakePos) { + SDL_Rect blackrect = {0, 0, _videoMode.screenWidth * _videoMode.scaleFactor, _newShakePos * _videoMode.scaleFactor}; + + if (_videoMode.aspectRatioCorrection && !_overlayVisible) + blackrect.h = real2Aspect(blackrect.h - 1) + 1; + + SDL_FillRect(_hwscreen, &blackrect, 0); + + _currentShakePos = _newShakePos; + + _forceFull = true; + } + + // Check whether the palette was changed in the meantime and update the + // screen surface accordingly. + if (_screen && _paletteDirtyEnd != 0) { + SDL_SetColors(_screen, _currentPalette + _paletteDirtyStart, + _paletteDirtyStart, + _paletteDirtyEnd - _paletteDirtyStart); + + _paletteDirtyEnd = 0; + + _forceFull = true; + } + +#ifdef USE_OSD + // OSD visible (i.e. non-transparent)? + if (_osdAlpha != SDL_ALPHA_TRANSPARENT) { + // Updated alpha value + const int diff = SDL_GetTicks() - _osdFadeStartTime; + if (diff > 0) { + if (diff >= kOSDFadeOutDuration) { + // Back to full transparency + _osdAlpha = SDL_ALPHA_TRANSPARENT; + } else { + // Do a linear fade out... + const int startAlpha = SDL_ALPHA_TRANSPARENT + kOSDInitialAlpha * (SDL_ALPHA_OPAQUE - SDL_ALPHA_TRANSPARENT) / 100; + _osdAlpha = startAlpha + diff * (SDL_ALPHA_TRANSPARENT - startAlpha) / kOSDFadeOutDuration; + } + SDL_SetAlpha(_osdSurface, SDL_RLEACCEL | SDL_SRCCOLORKEY | SDL_SRCALPHA, _osdAlpha); + _forceFull = true; + } + } +#endif + + if (!_overlayVisible) { + origSurf = _screen; + srcSurf = _tmpscreen; + width = _videoMode.screenWidth; + height = _videoMode.screenHeight; + scalerProc = _scalerProc; + scale1 = _videoMode.scaleFactor; + } else { + origSurf = _overlayscreen; + srcSurf = _tmpscreen2; + width = _videoMode.overlayWidth; + height = _videoMode.overlayHeight; + scalerProc = Normal1x; + + scale1 = 1; + } + + // Add the area covered by the mouse cursor to the list of dirty rects if + // we have to redraw the mouse. + if (_mouseNeedsRedraw) + undrawMouse(); + + // Force a full redraw if requested + if (_forceFull) { + _numDirtyRects = 1; + _dirtyRectList[0].x = 0; + _dirtyRectList[0].y = 0; + _dirtyRectList[0].w = width; + _dirtyRectList[0].h = height; + } + + // Only draw anything if necessary + if (_numDirtyRects > 0 || _mouseNeedsRedraw) { + SDL_Rect *r; + SDL_Rect dst; + uint32 srcPitch, dstPitch; + SDL_Rect *lastRect = _dirtyRectList + _numDirtyRects; + + for (r = _dirtyRectList; r != lastRect; ++r) { + dst = *r; + dst.x++; // Shift rect by one since 2xSai needs to access the data around + dst.y++; // any pixel to scale it, and we want to avoid mem access crashes. + + if (SDL_BlitSurface(origSurf, r, srcSurf, &dst) != 0) + error("SDL_BlitSurface failed: %s", SDL_GetError()); + } + + SDL_LockSurface(srcSurf); + SDL_LockSurface(_hwscreen); + + srcPitch = srcSurf->pitch; + dstPitch = _hwscreen->pitch; + + for (r = _dirtyRectList; r != lastRect; ++r) { + register int dst_y = r->y + _currentShakePos; + register int dst_h = 0; + register int dst_w = r->w; + register int orig_dst_y = 0; + register int dst_x = r->x; + register int src_y; + register int src_x; + + if (dst_y < height) { + dst_h = r->h; + if (dst_h > height - dst_y) + dst_h = height - dst_y; + + orig_dst_y = dst_y; + src_x = dst_x; + src_y = dst_y; + + if (_videoMode.aspectRatioCorrection && !_overlayVisible) + dst_y = real2Aspect(dst_y); + + assert(scalerProc != NULL); + + if (_videoMode.mode == GFX_HALF && scalerProc == DownscaleAllByHalf){ + if (dst_x%2==1){ + dst_x--; + dst_w++; + } + if (dst_y%2==1){ + dst_y--; + dst_h++; + } + src_x = dst_x; + src_y = dst_y; + dst_x = dst_x / 2; + dst_y = dst_y / 2; + } + scalerProc((byte *)srcSurf->pixels + (src_x * 2 + 2) + (src_y + 1) * srcPitch, srcPitch, + (byte *)_hwscreen->pixels + dst_x * 2 + dst_y * dstPitch, dstPitch, dst_w, dst_h); + } + + if (_videoMode.mode == GFX_HALF && scalerProc == DownscaleAllByHalf){ + r->w = r->w / 2; + r->h = dst_h / 2; + } else { + r->w = r->w; + r->h = dst_h; + } + + r->x = dst_x; + r->y = dst_y; + + +#ifdef USE_SCALERS + if (_videoMode.aspectRatioCorrection && orig_dst_y < height && !_overlayVisible) + r->h = stretch200To240((uint8 *) _hwscreen->pixels, dstPitch, r->w, r->h, r->x, r->y, orig_dst_y * scale1); +#endif + } + SDL_UnlockSurface(srcSurf); + SDL_UnlockSurface(_hwscreen); + + // Readjust the dirty rect list in case we are doing a full update. + // This is necessary if shaking is active. + if (_forceFull) { + _dirtyRectList[0].y = 0; + _dirtyRectList[0].h = (_videoMode.mode == GFX_HALF) ? effectiveScreenHeight()/2 : effectiveScreenHeight(); + } + + drawMouse(); + +#ifdef USE_OSD + if (_osdAlpha != SDL_ALPHA_TRANSPARENT) { + SDL_BlitSurface(_osdSurface, 0, _hwscreen, 0); + } +#endif + // Finally, blit all our changes to the screen + SDL_UpdateRects(_hwscreen, _numDirtyRects, _dirtyRectList); + } + + _numDirtyRects = 0; + _forceFull = false; + _mouseNeedsRedraw = false; +} + +void GP2XWIZSdlGraphicsManager::showOverlay() { + if (_videoMode.mode == GFX_HALF){ + _mouseCurState.x = _mouseCurState.x / 2; + _mouseCurState.y = _mouseCurState.y / 2; + } + SdlGraphicsManager::showOverlay(); +} + +void GP2XWIZSdlGraphicsManager::hideOverlay() { + if (_videoMode.mode == GFX_HALF){ + _mouseCurState.x = _mouseCurState.x * 2; + _mouseCurState.y = _mouseCurState.y * 2; + } + SdlGraphicsManager::hideOverlay(); +} + +void GP2XWIZSdlGraphicsManager::warpMouse(int x, int y) { + if (_mouseCurState.x != x || _mouseCurState.y != y) { + if (_videoMode.mode == GFX_HALF && !_overlayVisible){ + x = x / 2; + y = y / 2; + } + } + SdlGraphicsManager::warpMouse(x, y); +} + +#endif diff --git a/backends/graphics/gp2xwizsdl/gp2xwizsdl-graphics.h b/backends/graphics/gp2xwizsdl/gp2xwizsdl-graphics.h new file mode 100644 index 0000000000..5f0c739379 --- /dev/null +++ b/backends/graphics/gp2xwizsdl/gp2xwizsdl-graphics.h @@ -0,0 +1,58 @@ +/* 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 2 + * 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + * + */ + +#ifndef BACKENDS_GRAPHICS_SDL_GP2XWIZ_H +#define BACKENDS_GRAPHICS_SDL_GP2XWIZ_H + +#include "backends/graphics/sdl/sdl-graphics.h" + +// FIXME: For now keep hacks in this header to save polluting the SDL backend. +enum { + GFX_HALF = 12 +}; + +class GP2XWIZSdlGraphicsManager : public SdlGraphicsManager { +public: + virtual void setGraphicsModeIntern(); + virtual bool setGraphicsMode(int mode); + virtual const OSystem::GraphicsMode *getSupportedGraphicsModes() const; + virtual int getDefaultGraphicsMode() const; + + virtual void initSize(uint w, uint h); + + virtual void internUpdateScreen(); + + virtual bool loadGFXMode(); + + virtual void drawMouse(); + virtual void undrawMouse(); + + virtual void showOverlay(); + virtual void hideOverlay(); + + virtual void warpMouse(int x, int y); +}; + +#endif diff --git a/backends/graphics/sdl/sdl-graphics.h b/backends/graphics/sdl/sdl-graphics.h index 04f95ff721..4db8c338df 100644 --- a/backends/graphics/sdl/sdl-graphics.h +++ b/backends/graphics/sdl/sdl-graphics.h @@ -73,14 +73,14 @@ public: SdlGraphicsManager(); ~SdlGraphicsManager(); - bool hasFeature(OSystem::Feature f); - void setFeatureState(OSystem::Feature f, bool enable); - bool getFeatureState(OSystem::Feature f); - - const OSystem::GraphicsMode *getSupportedGraphicsModes() const; - int getDefaultGraphicsMode() const; - bool setGraphicsMode(int mode); - int getGraphicsMode() const; + virtual bool hasFeature(OSystem::Feature f); + virtual void setFeatureState(OSystem::Feature f, bool enable); + virtual bool getFeatureState(OSystem::Feature f); + + virtual const OSystem::GraphicsMode *getSupportedGraphicsModes() const; + virtual int getDefaultGraphicsMode() const; + virtual bool setGraphicsMode(int mode); + virtual int getGraphicsMode() const; #ifdef USE_RGB_COLOR virtual Graphics::PixelFormat getScreenFormat() const { return _screenFormat; } virtual Common::List<Graphics::PixelFormat> getSupportedFormats(); @@ -88,52 +88,52 @@ public: virtual void initSize(uint w, uint h, const Graphics::PixelFormat *format = NULL); virtual int getScreenChangeID() const { return _screenChangeCount; } - void beginGFXTransaction(); - OSystem::TransactionError endGFXTransaction(); + virtual void beginGFXTransaction(); + virtual OSystem::TransactionError endGFXTransaction(); virtual int16 getHeight(); virtual int16 getWidth(); - void setPalette(const byte *colors, uint start, uint num); - void grabPalette(byte *colors, uint start, uint num); + virtual void setPalette(const byte *colors, uint start, uint num); + virtual void grabPalette(byte *colors, uint start, uint num); virtual void copyRectToScreen(const byte *buf, int pitch, int x, int y, int w, int h); virtual Graphics::Surface *lockScreen(); virtual void unlockScreen(); - void fillScreen(uint32 col); - void updateScreen(); - void setShakePos(int shakeOffset); - void setFocusRectangle(const Common::Rect& rect) {} - void clearFocusRectangle() {} + virtual void fillScreen(uint32 col); + virtual void updateScreen(); + virtual void setShakePos(int shakeOffset); + virtual void setFocusRectangle(const Common::Rect& rect) {} + virtual void clearFocusRectangle() {} virtual void showOverlay(); virtual void hideOverlay(); virtual Graphics::PixelFormat getOverlayFormat() const { return _overlayFormat; } - void clearOverlay(); - void grabOverlay(OverlayColor *buf, int pitch); - void copyRectToOverlay(const OverlayColor *buf, int pitch, int x, int y, int w, int h); + virtual void clearOverlay(); + virtual void grabOverlay(OverlayColor *buf, int pitch); + virtual void copyRectToOverlay(const OverlayColor *buf, int pitch, int x, int y, int w, int h); virtual int16 getOverlayHeight() { return _videoMode.overlayHeight; } virtual int16 getOverlayWidth() { return _videoMode.overlayWidth; } - bool showMouse(bool visible); + virtual bool showMouse(bool visible); virtual void warpMouse(int x, int y); virtual void setMouseCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, int cursorTargetScale = 1, const Graphics::PixelFormat *format = NULL); - void setCursorPalette(const byte *colors, uint start, uint num); - void disableCursorPalette(bool disable) { + virtual void setCursorPalette(const byte *colors, uint start, uint num); + virtual void disableCursorPalette(bool disable) { _cursorPaletteDisabled = disable; blitCursor(); } #ifdef USE_OSD - void displayMessageOnOSD(const char *msg); + virtual void displayMessageOnOSD(const char *msg); #endif - void forceFullRedraw(); + virtual void forceFullRedraw(); - bool handleScalerHotkeys(const SDL_KeyboardEvent &key); - bool isScalerHotkey(const Common::Event &event); + virtual bool handleScalerHotkeys(const SDL_KeyboardEvent &key); + virtual bool isScalerHotkey(const Common::Event &event); - void adjustMouseEvent(Common::Event &event); - void setMousePos(int x, int y); - void toggleFullScreen(); + virtual void adjustMouseEvent(Common::Event &event); + virtual void setMousePos(int x, int y); + virtual void toggleFullScreen(); virtual bool saveScreenshot(const char *filename); // overloaded by CE backend protected: @@ -299,10 +299,10 @@ protected: virtual void unloadGFXMode(); // overloaded by CE backend virtual bool hotswapGFXMode(); // overloaded by CE backend - void setFullscreenMode(bool enable); - void setAspectRatioCorrection(bool enable); + virtual void setFullscreenMode(bool enable); + virtual void setAspectRatioCorrection(bool enable); - int effectiveScreenHeight() const; + virtual int effectiveScreenHeight() const; }; #endif |
