aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Schickel2012-02-23 21:20:24 +0100
committerJohannes Schickel2012-02-23 21:20:24 +0100
commit2ab5958c93c19a0ea23b76c2360ca8ef4d905b94 (patch)
tree104b246af6e3a7279063e2fd22f2d30ae12f32b4
parent97feac5342420653bb1f4a5fbca68a5aae6b09a8 (diff)
downloadscummvm-rg350-2ab5958c93c19a0ea23b76c2360ca8ef4d905b94.tar.gz
scummvm-rg350-2ab5958c93c19a0ea23b76c2360ca8ef4d905b94.tar.bz2
scummvm-rg350-2ab5958c93c19a0ea23b76c2360ca8ef4d905b94.zip
IPHONE: Move screen and overlay texture buffer to VideoContext.
-rw-r--r--backends/platform/iphone/iphone_common.h6
-rw-r--r--backends/platform/iphone/iphone_main.mm3
-rw-r--r--backends/platform/iphone/iphone_video.mm58
-rw-r--r--backends/platform/iphone/osys_video.mm16
4 files changed, 40 insertions, 43 deletions
diff --git a/backends/platform/iphone/iphone_common.h b/backends/platform/iphone/iphone_common.h
index f5111fbe8c..6e97d9d853 100644
--- a/backends/platform/iphone/iphone_common.h
+++ b/backends/platform/iphone/iphone_common.h
@@ -23,6 +23,8 @@
#ifndef BACKENDS_PLATFORM_IPHONE_IPHONE_COMMON_H
#define BACKENDS_PLATFORM_IPHONE_IPHONE_COMMON_H
+#include "graphics/surface.h"
+
enum InputEvent {
kInputMouseDown,
kInputMouseUp,
@@ -64,10 +66,12 @@ struct VideoContext {
// Game screen state
uint screenWidth, screenHeight;
+ Graphics::Surface screenTexture;
// Overlay state
bool overlayVisible;
uint overlayWidth, overlayHeight;
+ Graphics::Surface overlayTexture;
// Mouse cursor state
uint mouseX, mouseY;
@@ -82,8 +86,6 @@ struct VideoContext {
// On the ObjC side
void iPhone_updateScreen();
-void iPhone_updateScreenRect(unsigned short *screen, int x1, int y1, int x2, int y2, int width);
-void iPhone_updateOverlayRect(unsigned short *screen, int x1, int y1, int x2, int y2, int width);
bool iPhone_fetchEvent(int *outEvent, int *outX, int *outY);
const char *iPhone_getDocumentsDir();
bool iPhone_isHighResDevice();
diff --git a/backends/platform/iphone/iphone_main.mm b/backends/platform/iphone/iphone_main.mm
index 1559ef8a6e..20406e6342 100644
--- a/backends/platform/iphone/iphone_main.mm
+++ b/backends/platform/iphone/iphone_main.mm
@@ -20,6 +20,9 @@
*
*/
+// Disable symbol overrides so that we can use system headers.
+#define FORBIDDEN_SYMBOL_ALLOW_ALL
+
#include <UIKit/UIKit.h>
#include <Foundation/NSThread.h>
diff --git a/backends/platform/iphone/iphone_video.mm b/backends/platform/iphone/iphone_video.mm
index 4442552c0d..7ae5dd6a7d 100644
--- a/backends/platform/iphone/iphone_video.mm
+++ b/backends/platform/iphone/iphone_video.mm
@@ -20,20 +20,18 @@
*
*/
+// Disable symbol overrides so that we can use system headers.
+#define FORBIDDEN_SYMBOL_ALLOW_ALL
+
#include "iphone_video.h"
+#include "graphics/colormasks.h"
+
iPhoneView *g_iPhoneViewInstance = nil;
static int _fullWidth;
static int _fullHeight;
static CGRect _gameScreenRect;
-static char *_gameScreenTextureBuffer = 0;
-static int _gameScreenTextureWidth = 0;
-static int _gameScreenTextureHeight = 0;
-
-static char *_overlayTexBuffer = 0;
-static int _overlayTexWidth = 0;
-static int _overlayTexHeight = 0;
static CGRect _overlayRect;
static int _needsScreenUpdate = 0;
@@ -85,17 +83,6 @@ void iPhone_updateScreen() {
}
}
-void iPhone_updateScreenRect(unsigned short *screen, int x1, int y1, int x2, int y2, int width) {
- for (int y = y1; y < y2; ++y)
- memcpy(&_gameScreenTextureBuffer[(y * _gameScreenTextureWidth + x1) * 2], &screen[y * width + x1], (x2 - x1) * 2);
-}
-
-void iPhone_updateOverlayRect(unsigned short *screen, int x1, int y1, int x2, int y2, int width) {
- //printf("Overlaywidth: %u, fullwidth %u\n", _videoContext.overlayWidth, _fullWidth);
- for (int y = y1; y < y2; ++y)
- memcpy(&_overlayTexBuffer[(y * _overlayTexWidth + x1) * 2], &screen[y * width + x1], (x2 - x1) * 2);
-}
-
bool iPhone_fetchEvent(int *outEvent, int *outX, int *outY) {
id event = [g_iPhoneViewInstance getEvent];
if (event == nil) {
@@ -181,18 +168,16 @@ const char *iPhone_getDocumentsDir() {
_videoContext.overlayHeight = _renderBufferWidth;
_videoContext.overlayWidth = _renderBufferHeight;
- _overlayTexWidth = getSizeNextPOT(_videoContext.overlayHeight);
- _overlayTexHeight = getSizeNextPOT(_videoContext.overlayWidth);
+ uint overlayTextureWidth = getSizeNextPOT(_videoContext.overlayHeight);
+ uint overlayTextureHeight = getSizeNextPOT(_videoContext.overlayWidth);
// Since the overlay size won't change the whole run, we can
// precalculate the texture coordinates for the overlay texture here
// and just use it later on.
- _overlayTexCoords[2] = _overlayTexCoords[6] = _videoContext.overlayWidth / (GLfloat)_overlayTexWidth;
- _overlayTexCoords[5] = _overlayTexCoords[7] = _videoContext.overlayHeight / (GLfloat)_overlayTexHeight;
+ _overlayTexCoords[2] = _overlayTexCoords[6] = _videoContext.overlayWidth / (GLfloat)overlayTextureWidth;
+ _overlayTexCoords[5] = _overlayTexCoords[7] = _videoContext.overlayHeight / (GLfloat)overlayTextureHeight;
- int textureSize = _overlayTexWidth * _overlayTexHeight * 2;
- _overlayTexBuffer = (char *)malloc(textureSize);
- memset(_overlayTexBuffer, 0, textureSize);
+ _videoContext.overlayTexture.create(overlayTextureWidth, overlayTextureHeight, Graphics::createPixelFormat<5551>());
glViewport(0, 0, _renderBufferWidth, _renderBufferHeight); printOpenGLError();
glClearColor(0.0f, 0.0f, 0.0f, 1.0f); printOpenGLError();
@@ -258,8 +243,8 @@ const char *iPhone_getDocumentsDir() {
[_keyboardView dealloc];
}
- free(_gameScreenTextureBuffer);
- free(_overlayTexBuffer);
+ _videoContext.screenTexture.free();
+ _videoContext.overlayTexture.free();
}
- (void)drawRect:(CGRect)frame {
@@ -348,7 +333,7 @@ const char *iPhone_getDocumentsDir() {
// Unfortunately we have to update the whole texture every frame, since glTexSubImage2D is actually slower in all cases
// due to the iPhone internals having to convert the whole texture back from its internal format when used.
// In the future we could use several tiled textures instead.
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, _gameScreenTextureWidth, _gameScreenTextureHeight, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, _gameScreenTextureBuffer); printOpenGLError();
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, _videoContext.screenTexture.w, _videoContext.screenTexture.h, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, _videoContext.screenTexture.pixels); printOpenGLError();
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); printOpenGLError();
}
@@ -357,7 +342,7 @@ const char *iPhone_getDocumentsDir() {
glTexCoordPointer(2, GL_FLOAT, 0, _overlayTexCoords); printOpenGLError();
glBindTexture(GL_TEXTURE_2D, _overlayTexture); printOpenGLError();
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, _overlayTexWidth, _overlayTexHeight, 0, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, _overlayTexBuffer); printOpenGLError();
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, _videoContext.overlayTexture.w, _videoContext.overlayTexture.h, 0, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, _videoContext.overlayTexture.pixels); printOpenGLError();
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); printOpenGLError();
}
@@ -473,17 +458,15 @@ const char *iPhone_getDocumentsDir() {
}
- (void)initSurface {
- _gameScreenTextureWidth = getSizeNextPOT(_videoContext.screenWidth);
- _gameScreenTextureHeight = getSizeNextPOT(_videoContext.screenHeight);
+ uint screenTexWidth = getSizeNextPOT(_videoContext.screenWidth);
+ uint screenTexHeight = getSizeNextPOT(_videoContext.screenHeight);
- _gameScreenTexCoords[2] = _gameScreenTexCoords[6] = _videoContext.screenWidth / (GLfloat)_gameScreenTextureWidth;
- _gameScreenTexCoords[5] = _gameScreenTexCoords[7] = _videoContext.screenHeight / (GLfloat)_gameScreenTextureHeight;
+ _gameScreenTexCoords[2] = _gameScreenTexCoords[6] = _videoContext.screenWidth / (GLfloat)screenTexWidth;
+ _gameScreenTexCoords[5] = _gameScreenTexCoords[7] = _videoContext.screenHeight / (GLfloat)screenTexHeight;
int screenWidth, screenHeight;
[self setUpOrientation:[[UIDevice currentDevice] orientation] width:&screenWidth height:&screenHeight];
- //printf("Window: (%d, %d), Surface: (%d, %d), Texture(%d, %d)\n", _fullWidth, _fullHeight, _videoContext.screenWidth, _videoContext.screenHeight, _gameScreenTextureWidth, _gameScreenTextureHeight);
-
if (_screenTexture > 0) {
glDeleteTextures(1, &_screenTexture); printOpenGLError();
}
@@ -498,10 +481,7 @@ const char *iPhone_getDocumentsDir() {
glGenTextures(1, &_overlayTexture); printOpenGLError();
[self setFilterModeForTexture:_overlayTexture];
- free(_gameScreenTextureBuffer);
- int textureSize = _gameScreenTextureWidth * _gameScreenTextureHeight * 2;
- _gameScreenTextureBuffer = (char *)malloc(textureSize);
- memset(_gameScreenTextureBuffer, 0, textureSize);
+ _videoContext.screenTexture.create(screenTexWidth, screenTexHeight, Graphics::createPixelFormat<565>());
glBindRenderbufferOES(GL_RENDERBUFFER_OES, _viewRenderbuffer); printOpenGLError();
diff --git a/backends/platform/iphone/osys_video.mm b/backends/platform/iphone/osys_video.mm
index a40fcae78c..45f62377d4 100644
--- a/backends/platform/iphone/osys_video.mm
+++ b/backends/platform/iphone/osys_video.mm
@@ -228,11 +228,23 @@ void OSystem_IPHONE::drawDirtyRect(const Common::Rect &dirtyRect) {
}
void OSystem_IPHONE::drawDirtyOverlayRect(const Common::Rect &dirtyRect) {
- iPhone_updateOverlayRect(_overlayBuffer, dirtyRect.left, dirtyRect.top, dirtyRect.right, dirtyRect.bottom, _videoContext->overlayWidth);
+ const int x1 = dirtyRect.left;
+ const int y1 = dirtyRect.top;
+ const int x2 = dirtyRect.right;
+ const int y2 = dirtyRect.bottom;
+
+ for (int y = y1; y < y2; ++y)
+ memcpy(_videoContext->overlayTexture.getBasePtr(x1, y), &_overlayBuffer[y * _videoContext->overlayWidth + x1], (x2 - x1) * 2);
}
void OSystem_IPHONE::updateHardwareSurfaceForRect(const Common::Rect &updatedRect) {
- iPhone_updateScreenRect(_gameScreenConverted, updatedRect.left, updatedRect.top, updatedRect.right, updatedRect.bottom, _videoContext->screenWidth);
+ const int x1 = updatedRect.left;
+ const int y1 = updatedRect.top;
+ const int x2 = updatedRect.right;
+ const int y2 = updatedRect.bottom;
+
+ for (int y = y1; y < y2; ++y)
+ memcpy(_videoContext->screenTexture.getBasePtr(x1, y), &_gameScreenConverted[y * _videoContext->screenWidth + x1], (x2 - x1) * 2);
}
Graphics::Surface *OSystem_IPHONE::lockScreen() {