diff options
Diffstat (limited to 'backends/platform/iphone/osys_video.cpp')
-rw-r--r-- | backends/platform/iphone/osys_video.cpp | 232 |
1 files changed, 79 insertions, 153 deletions
diff --git a/backends/platform/iphone/osys_video.cpp b/backends/platform/iphone/osys_video.cpp index fa425b108a..78c6cd4625 100644 --- a/backends/platform/iphone/osys_video.cpp +++ b/backends/platform/iphone/osys_video.cpp @@ -25,25 +25,30 @@ #include "osys_main.h" -const OSystem::GraphicsMode* OSystem_IPHONE::getSupportedGraphicsModes() const { +const OSystem::GraphicsMode *OSystem_IPHONE::getSupportedGraphicsModes() const { return s_supportedGraphicsModes; } int OSystem_IPHONE::getDefaultGraphicsMode() const { - return -1; -} - -bool OSystem_IPHONE::setGraphicsMode(const char *mode) { - return true; + return kGraphicsModeLinear; } bool OSystem_IPHONE::setGraphicsMode(int mode) { - return true; + switch (mode) { + case kGraphicsModeNone: + case kGraphicsModeLinear: + _currentGraphicsMode = mode; + iPhone_setGraphicsMode(mode); + return true; + + default: + return false; + } } int OSystem_IPHONE::getGraphicsMode() const { - return -1; + return _currentGraphicsMode; } void OSystem_IPHONE::initSize(uint width, uint height, const Graphics::PixelFormat *format) { @@ -52,10 +57,10 @@ void OSystem_IPHONE::initSize(uint width, uint height, const Graphics::PixelForm _screenWidth = width; _screenHeight = height; - free(_offscreen); + free(_gameScreenRaw); - _offscreen = (byte *)malloc(width * height); - bzero(_offscreen, width * height); + _gameScreenRaw = (byte *)malloc(width * height); + bzero(_gameScreenRaw, width * height); //free(_overlayBuffer); @@ -63,10 +68,10 @@ void OSystem_IPHONE::initSize(uint width, uint height, const Graphics::PixelForm //_overlayBuffer = (OverlayColor *)malloc(fullSize); clearOverlay(); - free(_fullscreen); + free(_gameScreenConverted); - _fullscreen = (uint16 *)malloc(fullSize); - bzero(_fullscreen, fullSize); + _gameScreenConverted = (uint16 *)malloc(fullSize); + bzero(_gameScreenConverted, fullSize); iPhone_initSurface(width, height); @@ -81,6 +86,7 @@ void OSystem_IPHONE::initSize(uint width, uint height, const Graphics::PixelForm _fullScreenIsDirty = false; dirtyFullScreen(); _mouseVisible = false; + _mouseCursorPaletteEnabled = false; _screenChangeCount++; updateScreen(); } @@ -98,7 +104,8 @@ void OSystem_IPHONE::setPalette(const byte *colors, uint start, uint num) { const byte *b = colors; for (uint i = start; i < start + num; ++i) { - _palette[i] = Graphics::RGBToColor<Graphics::ColorMasks<565> >(b[0], b[1], b[2]); + _gamePalette[i] = Graphics::RGBToColor<Graphics::ColorMasks<565> >(b[0], b[1], b[2]); + _gamePaletteRGBA5551[i] = Graphics::RGBToColor<Graphics::ColorMasks<5551> >(b[0], b[1], b[2]); b += 3; } @@ -110,7 +117,7 @@ void OSystem_IPHONE::grabPalette(byte *colors, uint start, uint num) { byte *b = colors; for (uint i = start; i < start + num; ++i) { - Graphics::colorToRGB<Graphics::ColorMasks<565> >(_palette[i], b[0], b[1], b[2]); + Graphics::colorToRGB<Graphics::ColorMasks<565> >(_gamePalette[i], b[0], b[1], b[2]); b += 3; } } @@ -146,7 +153,7 @@ void OSystem_IPHONE::copyRectToScreen(const byte *buf, int pitch, int x, int y, } - byte *dst = _offscreen + y * _screenWidth + x; + byte *dst = _gameScreenRaw + y * _screenWidth + x; if (_screenWidth == pitch && pitch == w) memcpy(dst, buf, h * w); else { @@ -158,32 +165,6 @@ void OSystem_IPHONE::copyRectToScreen(const byte *buf, int pitch, int x, int y, } } -void OSystem_IPHONE::clipRectToScreen(int16 &x, int16 &y, int16 &w, int16 &h) { - if (x < 0) { - w += x; - x = 0; - } - - if (y < 0) { - h += y; - y = 0; - } - - if (w > _screenWidth - x) - w = _screenWidth - x; - - if (h > _screenHeight - y) - h = _screenHeight - y; - - if (w < 0) { - w = 0; - } - - if (h < 0) { - h = 0; - } -} - void OSystem_IPHONE::updateScreen() { //printf("updateScreen(): %i dirty rects.\n", _dirtyRects.size()); @@ -191,47 +172,24 @@ void OSystem_IPHONE::updateScreen() { return; internUpdateScreen(); + _mouseDirty = false; _fullScreenIsDirty = false; _fullScreenOverlayIsDirty = false; - iPhone_updateScreen(_mouseX - _mouseHotspotX, _mouseY - _mouseHotspotY); + iPhone_updateScreen(_mouseX, _mouseY); } void OSystem_IPHONE::internUpdateScreen() { - int16 mouseX = _mouseX - _mouseHotspotX; - int16 mouseY = _mouseY - _mouseHotspotY; - int16 mouseWidth = _mouseWidth; - int16 mouseHeight = _mouseHeight; - - clipRectToScreen(mouseX, mouseY, mouseWidth, mouseHeight); - - Common::Rect mouseRect(mouseX, mouseY, mouseX + mouseWidth, mouseY + mouseHeight); - - if (_mouseDirty) { - if (!_fullScreenIsDirty) { - _dirtyRects.push_back(_lastDrawnMouseRect); - _dirtyRects.push_back(mouseRect); - } - if (!_fullScreenOverlayIsDirty && _overlayVisible) { - _dirtyOverlayRects.push_back(_lastDrawnMouseRect); - _dirtyOverlayRects.push_back(mouseRect); - } - _mouseDirty = false; - _lastDrawnMouseRect = mouseRect; + if (_mouseNeedTextureUpdate) { + updateMouseTexture(); + _mouseNeedTextureUpdate = false; } while (_dirtyRects.size()) { Common::Rect dirtyRect = _dirtyRects.remove_at(_dirtyRects.size() - 1); //printf("Drawing: (%i, %i) -> (%i, %i)\n", dirtyRect.left, dirtyRect.top, dirtyRect.right, dirtyRect.bottom); - drawDirtyRect(dirtyRect); - - if (_overlayVisible) - drawDirtyOverlayRect(dirtyRect); - else - drawMouseCursorOnRectUpdate(dirtyRect, mouseRect); - updateHardwareSurfaceForRect(dirtyRect); } @@ -240,94 +198,38 @@ void OSystem_IPHONE::internUpdateScreen() { Common::Rect dirtyRect = _dirtyOverlayRects.remove_at(_dirtyOverlayRects.size() - 1); //printf("Drawing: (%i, %i) -> (%i, %i)\n", dirtyRect.left, dirtyRect.top, dirtyRect.right, dirtyRect.bottom); - drawDirtyOverlayRect(dirtyRect); - //drawMouseCursorOnRectUpdate(dirtyRect, mouseRect); - //updateHardwareSurfaceForRect(dirtyRect); } } } -void OSystem_IPHONE::drawDirtyRect(const Common::Rect& dirtyRect) { +void OSystem_IPHONE::drawDirtyRect(const Common::Rect &dirtyRect) { int h = dirtyRect.bottom - dirtyRect.top; int w = dirtyRect.right - dirtyRect.left; - byte *src = &_offscreen[dirtyRect.top * _screenWidth + dirtyRect.left]; - uint16 *dst = &_fullscreen[dirtyRect.top * _screenWidth + dirtyRect.left]; + byte *src = &_gameScreenRaw[dirtyRect.top * _screenWidth + dirtyRect.left]; + uint16 *dst = &_gameScreenConverted[dirtyRect.top * _screenWidth + dirtyRect.left]; for (int y = h; y > 0; y--) { for (int x = w; x > 0; x--) - *dst++ = _palette[*src++]; + *dst++ = _gamePalette[*src++]; dst += _screenWidth - w; src += _screenWidth - w; } } -void OSystem_IPHONE::drawDirtyOverlayRect(const Common::Rect& dirtyRect) { - // int h = dirtyRect.bottom - dirtyRect.top; - // - // uint16 *src = (uint16 *)&_overlayBuffer[dirtyRect.top * _screenWidth + dirtyRect.left]; - // uint16 *dst = &_fullscreen[dirtyRect.top * _screenWidth + dirtyRect.left]; - // int x = (dirtyRect.right - dirtyRect.left) * 2; - // for (int y = h; y > 0; y--) { - // memcpy(dst, src, x); - // src += _screenWidth; - // dst += _screenWidth; - // } +void OSystem_IPHONE::drawDirtyOverlayRect(const Common::Rect &dirtyRect) { iPhone_updateOverlayRect(_overlayBuffer, dirtyRect.left, dirtyRect.top, dirtyRect.right, dirtyRect.bottom); } -void OSystem_IPHONE::drawMouseCursorOnRectUpdate(const Common::Rect& updatedRect, const Common::Rect& mouseRect) { - //draw mouse on top - if (_mouseVisible && (updatedRect.intersects(mouseRect))) { - int srcX = 0; - int srcY = 0; - int left = _mouseX - _mouseHotspotX; - if (left < 0) { - srcX -= left; - left = 0; - } - int top = _mouseY - _mouseHotspotY; - if (top < 0) { - srcY -= top; - top = 0; - } - - int bottom = top + _mouseHeight; - if (bottom > _screenWidth) - bottom = _screenWidth; - - int displayWidth = _mouseWidth; - if (_mouseWidth + left > _screenWidth) - displayWidth = _screenWidth - left; - - int displayHeight = _mouseHeight; - if (_mouseHeight + top > _screenHeight) - displayHeight = _screenHeight - top; - - byte *src = &_mouseBuf[srcY * _mouseWidth + srcX]; - uint16 *dst = &_fullscreen[top * _screenWidth + left]; - for (int y = displayHeight; y > srcY; y--) { - for (int x = displayWidth; x > srcX; x--) { - if (*src != _mouseKeyColor) - *dst = _palette[*src]; - dst++; - src++; - } - dst += _screenWidth - displayWidth + srcX; - src += _mouseWidth - displayWidth + srcX; - } - } -} - -void OSystem_IPHONE::updateHardwareSurfaceForRect(const Common::Rect& updatedRect) { - iPhone_updateScreenRect(_fullscreen, updatedRect.left, updatedRect.top, updatedRect.right, updatedRect.bottom ); +void OSystem_IPHONE::updateHardwareSurfaceForRect(const Common::Rect &updatedRect) { + iPhone_updateScreenRect(_gameScreenConverted, updatedRect.left, updatedRect.top, updatedRect.right, updatedRect.bottom); } Graphics::Surface *OSystem_IPHONE::lockScreen() { //printf("lockScreen()\n"); - _framebuffer.pixels = _offscreen; + _framebuffer.pixels = _gameScreenRaw; _framebuffer.w = _screenWidth; _framebuffer.h = _screenHeight; _framebuffer.pitch = _screenWidth; @@ -431,6 +333,7 @@ int16 OSystem_IPHONE::getOverlayWidth() { bool OSystem_IPHONE::showMouse(bool visible) { bool last = _mouseVisible; _mouseVisible = visible; + iPhone_showCursor(visible); _mouseDirty = true; return last; @@ -463,24 +366,6 @@ void OSystem_IPHONE::dirtyFullOverlayScreen() { void OSystem_IPHONE::setMouseCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, int cursorTargetScale, const Graphics::PixelFormat *format) { //printf("setMouseCursor(%i, %i, scale %u)\n", hotspotX, hotspotY, cursorTargetScale); - int texWidth = getSizeNextPOT(w); - int texHeight = getSizeNextPOT(h); - int bufferSize = texWidth * texHeight * sizeof(int16); - int16* mouseBuf = (int16*)malloc(bufferSize); - memset(mouseBuf, 0, bufferSize); - - for (uint x = 0; x < w; ++x) { - for (uint y = 0; y < h; ++y) { - byte color = buf[y * w + x]; - if (color != keycolor) - mouseBuf[y * texWidth + x] = _palette[color] | 0x1; - else - mouseBuf[y * texWidth + x] = 0x0; - } - } - - iPhone_setMouseCursor(mouseBuf, w, h); - if (_mouseBuf != NULL && (_mouseWidth != w || _mouseHeight != h)) { free(_mouseBuf); _mouseBuf = NULL; @@ -500,4 +385,45 @@ void OSystem_IPHONE::setMouseCursor(const byte *buf, uint w, uint h, int hotspot memcpy(_mouseBuf, buf, w * h); _mouseDirty = true; + _mouseNeedTextureUpdate = true; +} + +void OSystem_IPHONE::setCursorPalette(const byte *colors, uint start, uint num) { + assert(start + num <= 256); + + for (uint i = start; i < start + num; ++i, colors += 3) + _mouseCursorPalette[i] = Graphics::RGBToColor<Graphics::ColorMasks<5551> >(colors[0], colors[1], colors[2]); + + // FIXME: This is just stupid, our client code seems to assume that this + // automatically enables the cursor palette. + _mouseCursorPaletteEnabled = true; + + if (_mouseCursorPaletteEnabled) + _mouseDirty = _mouseNeedTextureUpdate = true; +} + +void OSystem_IPHONE::updateMouseTexture() { + int texWidth = getSizeNextPOT(_mouseWidth); + int texHeight = getSizeNextPOT(_mouseHeight); + int bufferSize = texWidth * texHeight * sizeof(int16); + uint16 *mouseBuf = (uint16 *)malloc(bufferSize); + memset(mouseBuf, 0, bufferSize); + + const uint16 *palette; + if (_mouseCursorPaletteEnabled) + palette = _mouseCursorPalette; + else + palette = _gamePaletteRGBA5551; + + for (uint x = 0; x < _mouseWidth; ++x) { + for (uint y = 0; y < _mouseHeight; ++y) { + const byte color = _mouseBuf[y * _mouseWidth + x]; + if (color != _mouseKeyColor) + mouseBuf[y * texWidth + x] = palette[color] | 0x1; + else + mouseBuf[y * texWidth + x] = 0x0; + } + } + + iPhone_setMouseCursor(mouseBuf, _mouseWidth, _mouseHeight, _mouseHotspotX, _mouseHotspotY); } |