diff options
author | Johannes Schickel | 2012-02-26 01:25:18 +0100 |
---|---|---|
committer | Johannes Schickel | 2012-02-26 01:25:18 +0100 |
commit | 3b1e4b5bdcdd67db03c6d225c0a7985d8ce35d3b (patch) | |
tree | 3830acb23f6b9ec2148b17dd24c8f5f144da22c6 | |
parent | 83ce8da9359d0f015165d8e75c37776a7a49474e (diff) | |
download | scummvm-rg350-3b1e4b5bdcdd67db03c6d225c0a7985d8ce35d3b.tar.gz scummvm-rg350-3b1e4b5bdcdd67db03c6d225c0a7985d8ce35d3b.tar.bz2 scummvm-rg350-3b1e4b5bdcdd67db03c6d225c0a7985d8ce35d3b.zip |
IPHONE: Let hi-color games directly draw onto the screen texture buffer.
This avoids an unecessary copying step from the framebuffer to the texture
buffer.
-rw-r--r-- | backends/platform/iphone/iphone_video.h | 1 | ||||
-rw-r--r-- | backends/platform/iphone/iphone_video.mm | 12 | ||||
-rw-r--r-- | backends/platform/iphone/osys_main.cpp | 6 | ||||
-rw-r--r-- | backends/platform/iphone/osys_video.mm | 45 |
4 files changed, 41 insertions, 23 deletions
diff --git a/backends/platform/iphone/iphone_video.h b/backends/platform/iphone/iphone_video.h index 168f9a4244..55a4acb7c7 100644 --- a/backends/platform/iphone/iphone_video.h +++ b/backends/platform/iphone/iphone_video.h @@ -75,6 +75,7 @@ - (void)drawRect:(CGRect)frame; +- (void)createScreenTexture; - (void)initSurface; - (void)setViewTransformation; diff --git a/backends/platform/iphone/iphone_video.mm b/backends/platform/iphone/iphone_video.mm index 0ddb90bece..04aaf59b21 100644 --- a/backends/platform/iphone/iphone_video.mm +++ b/backends/platform/iphone/iphone_video.mm @@ -443,13 +443,17 @@ const char *iPhone_getDocumentsDir() { } } -- (void)initSurface { - uint screenTexWidth = getSizeNextPOT(_videoContext.screenWidth); - uint screenTexHeight = getSizeNextPOT(_videoContext.screenHeight); +- (void)createScreenTexture { + const uint screenTexWidth = getSizeNextPOT(_videoContext.screenWidth); + const uint screenTexHeight = getSizeNextPOT(_videoContext.screenHeight); _gameScreenTexCoords[2] = _gameScreenTexCoords[6] = _videoContext.screenWidth / (GLfloat)screenTexWidth; _gameScreenTexCoords[5] = _gameScreenTexCoords[7] = _videoContext.screenHeight / (GLfloat)screenTexHeight; + _videoContext.screenTexture.create(screenTexWidth, screenTexHeight, Graphics::createPixelFormat<565>()); +} + +- (void)initSurface { int screenWidth, screenHeight; [self setUpOrientation:[[UIDevice currentDevice] orientation] width:&screenWidth height:&screenHeight]; @@ -467,8 +471,6 @@ const char *iPhone_getDocumentsDir() { glGenTextures(1, &_overlayTexture); printOpenGLError(); [self setFilterModeForTexture:_overlayTexture]; - _videoContext.screenTexture.create(screenTexWidth, screenTexHeight, Graphics::createPixelFormat<565>()); - glBindRenderbufferOES(GL_RENDERBUFFER_OES, _viewRenderbuffer); printOpenGLError(); [self clearColorBuffer]; diff --git a/backends/platform/iphone/osys_main.cpp b/backends/platform/iphone/osys_main.cpp index 0f63a13db7..f3e0d97b97 100644 --- a/backends/platform/iphone/osys_main.cpp +++ b/backends/platform/iphone/osys_main.cpp @@ -71,7 +71,11 @@ OSystem_IPHONE::~OSystem_IPHONE() { AudioQueueDispose(s_AudioQueue.queue, true); delete _mixer; - _framebuffer.free(); + // Prevent accidental freeing of the screen texture here. This needs to be + // checked since we might use the screen texture as framebuffer in the case + // of hi-color games for example. + if (_framebuffer.pixels == _videoContext->screenTexture.pixels) + _framebuffer.free(); _mouseBuffer.free(); } diff --git a/backends/platform/iphone/osys_video.mm b/backends/platform/iphone/osys_video.mm index 258b183bbe..2b5e78bd35 100644 --- a/backends/platform/iphone/osys_video.mm +++ b/backends/platform/iphone/osys_video.mm @@ -74,6 +74,16 @@ void OSystem_IPHONE::initSize(uint width, uint height, const Graphics::PixelForm _videoContext->screenHeight = height; _videoContext->shakeOffsetY = 0; + // In case we use the screen texture as frame buffer we reset the pixels + // pointer here to avoid freeing the screen texture. + if (_framebuffer.pixels == _videoContext->screenTexture.pixels) + _framebuffer.pixels = 0; + + // Create the screen texture right here. We need to do this here, since + // when a game requests hi-color mode, we actually set the framebuffer + // to the texture buffer to avoid an additional copy step. + [g_iPhoneViewInstance performSelectorOnMainThread:@selector(createScreenTexture) withObject:nil waitUntilDone: YES]; + if (!format || format->bytesPerPixel == 1) { _framebuffer.create(width, height, Graphics::PixelFormat::createFormatCLUT8()); } else { @@ -82,8 +92,13 @@ void OSystem_IPHONE::initSize(uint width, uint height, const Graphics::PixelForm format->rLoss, format->gLoss, format->bLoss, format->aLoss, format->rShift, format->gShift, format->bShift, format->aShift); #endif - assert(Graphics::createPixelFormat<565>() == *format); - _framebuffer.create(width, height, *format); + assert(_videoContext->screenTexture.format == *format); + // We directly draw on the screen texture in hi-color mode. Thus + // we copy over its settings here and just replace the width and + // height to avoid any problems. + _framebuffer = _videoContext->screenTexture; + _framebuffer.w = width; + _framebuffer.h = height; } _fullScreenIsDirty = false; @@ -222,28 +237,24 @@ void OSystem_IPHONE::internUpdateScreen() { } void OSystem_IPHONE::drawDirtyRect(const Common::Rect &dirtyRect) { + // We only need to do a color look up for CLUT8 + if (_framebuffer.format.bytesPerPixel != 1) + return; + int h = dirtyRect.bottom - dirtyRect.top; int w = dirtyRect.right - dirtyRect.left; const byte *src = (const byte *)_framebuffer.getBasePtr(dirtyRect.left, dirtyRect.top); byte *dstRaw = (byte *)_videoContext->screenTexture.getBasePtr(dirtyRect.left, dirtyRect.top); - if (_framebuffer.format.bytesPerPixel == 1) { - // When we use CLUT8 do a color look up - for (int y = h; y > 0; y--) { - uint16 *dst = (uint16 *)dstRaw; - for (int x = w; x > 0; x--) - *dst++ = _gamePalette[*src++]; + // When we use CLUT8 do a color look up + for (int y = h; y > 0; y--) { + uint16 *dst = (uint16 *)dstRaw; + for (int x = w; x > 0; x--) + *dst++ = _gamePalette[*src++]; - dstRaw += _videoContext->screenTexture.pitch; - src += _framebuffer.pitch - w; - } - } else { - do { - memcpy(dstRaw, src, w * _framebuffer.format.bytesPerPixel); - dstRaw += _videoContext->screenTexture.pitch; - src += _framebuffer.pitch; - } while (--h); + dstRaw += _videoContext->screenTexture.pitch; + src += _framebuffer.pitch - w; } } |