diff --git a/backends/platform/iphone/osys_main.cpp b/backends/platform/iphone/osys_main.cpp index dd34e95c725c..790e192f972d 100644 --- a/backends/platform/iphone/osys_main.cpp +++ b/backends/platform/iphone/osys_main.cpp @@ -55,7 +55,7 @@ SoundProc OSystem_IPHONE::s_soundCallback = NULL; void *OSystem_IPHONE::s_soundParam = NULL; OSystem_IPHONE::OSystem_IPHONE() : - _mixer(NULL), _gameScreenRaw(NULL), + _mixer(NULL), _mouseBuf(NULL), _lastMouseTap(0), _queuedEventTime(0), _mouseNeedTextureUpdate(false), _secondaryTapped(false), _lastSecondaryTap(0), _screenOrientation(kScreenOrientationFlippedLandscape), _mouseClickAndDragEnabled(false), @@ -72,7 +72,7 @@ OSystem_IPHONE::~OSystem_IPHONE() { AudioQueueDispose(s_AudioQueue.queue, true); delete _mixer; - free(_gameScreenRaw); + _framebuffer.free(); } int OSystem_IPHONE::timerHandler(int t) { diff --git a/backends/platform/iphone/osys_main.h b/backends/platform/iphone/osys_main.h index 84c460aaf45b..675fc963217b 100644 --- a/backends/platform/iphone/osys_main.h +++ b/backends/platform/iphone/osys_main.h @@ -64,7 +64,6 @@ class OSystem_IPHONE : public EventsBaseBackend, public PaletteManager { VideoContext *_videoContext; Graphics::Surface _framebuffer; - byte *_gameScreenRaw; // For use with the game texture uint16 _gamePalette[256]; diff --git a/backends/platform/iphone/osys_video.mm b/backends/platform/iphone/osys_video.mm index 265a36f9469d..080b476a9efe 100644 --- a/backends/platform/iphone/osys_video.mm +++ b/backends/platform/iphone/osys_video.mm @@ -62,10 +62,7 @@ _videoContext->screenHeight = height; _videoContext->shakeOffsetY = 0; - free(_gameScreenRaw); - - _gameScreenRaw = (byte *)malloc(width * height); - bzero(_gameScreenRaw, width * height); + _framebuffer.create(width, height, Graphics::PixelFormat::createFormatCLUT8()); _fullScreenIsDirty = false; dirtyFullScreen(); @@ -134,12 +131,12 @@ y = 0; } - if (w > (int)_videoContext->screenWidth - x) { - w = _videoContext->screenWidth - x; + if (w > (int)_framebuffer.w - x) { + w = _framebuffer.w - x; } - if (h > (int)_videoContext->screenHeight - y) { - h = _videoContext->screenHeight - y; + if (h > (int)_framebuffer.h - y) { + h = _framebuffer.h - y; } if (w <= 0 || h <= 0) @@ -150,14 +147,14 @@ } - byte *dst = _gameScreenRaw + y * _videoContext->screenWidth + x; - if ((int)_videoContext->screenWidth == pitch && pitch == w) + byte *dst = (byte *)_framebuffer.getBasePtr(x, y); + if (_framebuffer.pitch == pitch && pitch == w) memcpy(dst, buf, h * w); else { do { memcpy(dst, buf, w); buf += pitch; - dst += _videoContext->screenWidth; + dst += _framebuffer.pitch; } while (--h); } } @@ -207,7 +204,7 @@ int h = dirtyRect.bottom - dirtyRect.top; int w = dirtyRect.right - dirtyRect.left; - byte *src = &_gameScreenRaw[dirtyRect.top * _videoContext->screenWidth + dirtyRect.left]; + const byte *src = (const byte *)_framebuffer.getBasePtr(dirtyRect.left, dirtyRect.top); byte *dstRaw = (byte *)_videoContext->screenTexture.getBasePtr(dirtyRect.left, dirtyRect.top); for (int y = h; y > 0; y--) { uint16 *dst = (uint16 *)dstRaw; @@ -215,19 +212,12 @@ *dst++ = _gamePalette[*src++]; dstRaw += _videoContext->screenTexture.pitch; - src += _videoContext->screenWidth - w; + src += _framebuffer.pitch - w; } } Graphics::Surface *OSystem_IPHONE::lockScreen() { //printf("lockScreen()\n"); - - _framebuffer.pixels = _gameScreenRaw; - _framebuffer.w = _videoContext->screenWidth; - _framebuffer.h = _videoContext->screenHeight; - _framebuffer.pitch = _videoContext->screenWidth; - _framebuffer.format = Graphics::PixelFormat::createFormatCLUT8(); - return &_framebuffer; }