aboutsummaryrefslogtreecommitdiff
path: root/backends
diff options
context:
space:
mode:
authorsylvaintv2011-03-08 00:54:40 +0100
committersylvaintv2011-03-08 00:54:40 +0100
commitb2a72da6518b30a58a1257ff7217185ae5683628 (patch)
tree41e5d532124466b09a396ec4b043ec74e1b9ea56 /backends
parent53d6a4f831c9e7c7de594cdaed3c8546b41ea2e2 (diff)
parent9fb28410b5ea27fa8e79ac5f0ac4ce70ae4cf3c6 (diff)
downloadscummvm-rg350-b2a72da6518b30a58a1257ff7217185ae5683628.tar.gz
scummvm-rg350-b2a72da6518b30a58a1257ff7217185ae5683628.tar.bz2
scummvm-rg350-b2a72da6518b30a58a1257ff7217185ae5683628.zip
Merge branch 'master' of github.com:scummvm/scummvm
Diffstat (limited to 'backends')
-rw-r--r--backends/graphics/opengl/opengl-graphics.cpp28
-rw-r--r--backends/platform/android/android.cpp2
-rw-r--r--backends/platform/android/android.h6
-rw-r--r--backends/platform/android/gfx.cpp80
-rw-r--r--backends/platform/android/jni.cpp6
-rw-r--r--backends/platform/android/texture.cpp78
-rw-r--r--backends/platform/android/texture.h25
7 files changed, 131 insertions, 94 deletions
diff --git a/backends/graphics/opengl/opengl-graphics.cpp b/backends/graphics/opengl/opengl-graphics.cpp
index 522c36e22d..9a2efe3eec 100644
--- a/backends/graphics/opengl/opengl-graphics.cpp
+++ b/backends/graphics/opengl/opengl-graphics.cpp
@@ -168,11 +168,9 @@ void OpenGLGraphicsManager::resetGraphicsScale() {
}
#ifdef USE_RGB_COLOR
-
Graphics::PixelFormat OpenGLGraphicsManager::getScreenFormat() const {
return _screenFormat;
}
-
#endif
void OpenGLGraphicsManager::initSize(uint width, uint height, const Graphics::PixelFormat *format) {
@@ -310,7 +308,7 @@ int16 OpenGLGraphicsManager::getWidth() {
void OpenGLGraphicsManager::setPalette(const byte *colors, uint start, uint num) {
assert(colors);
-
+
#ifdef USE_RGB_COLOR
assert(_screenFormat.bytesPerPixel == 1);
#endif
@@ -326,7 +324,7 @@ void OpenGLGraphicsManager::setPalette(const byte *colors, uint start, uint num)
void OpenGLGraphicsManager::grabPalette(byte *colors, uint start, uint num) {
assert(colors);
-
+
#ifdef USE_RGB_COLOR
assert(_screenFormat.bytesPerPixel == 1);
#endif
@@ -369,6 +367,7 @@ void OpenGLGraphicsManager::fillScreen(uint32 col) {
if (_gameTexture == NULL)
return;
+#ifdef USE_RGB_COLOR
if (_screenFormat.bytesPerPixel == 1) {
memset(_screenData.pixels, col, _screenData.h * _screenData.pitch);
} else if (_screenFormat.bytesPerPixel == 2) {
@@ -394,7 +393,9 @@ void OpenGLGraphicsManager::fillScreen(uint32 col) {
pixels[i] = col;
}
}
-
+#else
+ memset(_screenData.pixels, col, _screenData.h * _screenData.pitch);
+#endif
_screenNeedsRedraw = true;
}
@@ -1138,7 +1139,7 @@ void OpenGLGraphicsManager::loadTextures() {
_cursorTexture = new GLTexture(4, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
else
_cursorTexture->refresh();
-
+
GLint filter = _videoMode.antialiasing ? GL_LINEAR : GL_NEAREST;
_gameTexture->setFilter(filter);
_overlayTexture->setFilter(filter);
@@ -1149,17 +1150,26 @@ void OpenGLGraphicsManager::loadTextures() {
_overlayTexture->allocBuffer(_videoMode.overlayWidth, _videoMode.overlayHeight);
_cursorTexture->allocBuffer(_cursorState.w, _cursorState.h);
- if (_transactionDetails.formatChanged ||
+ if (
+#ifdef USE_RGB_COLOR
+ _transactionDetails.formatChanged ||
+#endif
_oldVideoMode.screenWidth != _videoMode.screenWidth ||
_oldVideoMode.screenHeight != _videoMode.screenHeight)
_screenData.create(_videoMode.screenWidth, _videoMode.screenHeight,
- _screenFormat.bytesPerPixel);
+#ifdef USE_RGB_COLOR
+ _screenFormat.bytesPerPixel
+#else
+ 1
+#endif
+ );
+
if (_oldVideoMode.overlayWidth != _videoMode.overlayWidth ||
_oldVideoMode.overlayHeight != _videoMode.overlayHeight)
_overlayData.create(_videoMode.overlayWidth, _videoMode.overlayHeight,
_overlayFormat.bytesPerPixel);
-
+
_screenNeedsRedraw = true;
_overlayNeedsRedraw = true;
_cursorNeedsRedraw = true;
diff --git a/backends/platform/android/android.cpp b/backends/platform/android/android.cpp
index 0cfe7c9a22..2be435c701 100644
--- a/backends/platform/android/android.cpp
+++ b/backends/platform/android/android.cpp
@@ -333,6 +333,8 @@ void OSystem_Android::initBackend() {
_mouse_texture_palette = new GLESPalette8888Texture();
_mouse_texture = _mouse_texture_palette;
+ initOverlay();
+
// renice this thread to boost the audio thread
if (setpriority(PRIO_PROCESS, 0, 19) < 0)
warning("couldn't renice the main thread");
diff --git a/backends/platform/android/android.h b/backends/platform/android/android.h
index 2c0641f789..f6406c4132 100644
--- a/backends/platform/android/android.h
+++ b/backends/platform/android/android.h
@@ -114,7 +114,7 @@ private:
// Mouse layer
GLESTexture *_mouse_texture;
GLESPaletteTexture *_mouse_texture_palette;
- GLESTexture *_mouse_texture_rgb;
+ GLES5551Texture *_mouse_texture_rgb;
Common::Point _mouse_hotspot;
int _mouse_targetscale;
bool _show_mouse;
@@ -146,6 +146,8 @@ private:
void deinitSurface();
void initViewport();
+ void initOverlay();
+
#ifdef USE_RGB_COLOR
Common::String getPixelFormatName(const Graphics::PixelFormat &format) const;
void initTexture(GLESTexture **texture, uint width, uint height,
@@ -153,7 +155,7 @@ private:
#endif
void setupKeymapper();
- void _setCursorPalette(const byte *colors, uint start, uint num);
+ void setCursorPaletteInternal(const byte *colors, uint start, uint num);
public:
OSystem_Android(int audio_sample_rate, int audio_buffer_size);
diff --git a/backends/platform/android/gfx.cpp b/backends/platform/android/gfx.cpp
index d6dc71fcfb..605f4eb744 100644
--- a/backends/platform/android/gfx.cpp
+++ b/backends/platform/android/gfx.cpp
@@ -25,6 +25,8 @@
#if defined(__ANDROID__)
+#include "graphics/conversion.h"
+
#include "backends/platform/android/android.h"
#include "backends/platform/android/jni.h"
@@ -167,8 +169,10 @@ void OSystem_Android::initSurface() {
if (_game_texture)
_game_texture->reinit();
- if (_overlay_texture)
+ if (_overlay_texture) {
_overlay_texture->reinit();
+ initOverlay();
+ }
if (_mouse_texture)
_mouse_texture->reinit();
@@ -231,12 +235,7 @@ void OSystem_Android::initViewport() {
clearFocusRectangle();
}
-void OSystem_Android::initSize(uint width, uint height,
- const Graphics::PixelFormat *format) {
- ENTER("%d, %d, %p", width, height, format);
-
- GLTHREADCHECK;
-
+void OSystem_Android::initOverlay() {
int overlay_width = _egl_surface_width;
int overlay_height = _egl_surface_height;
@@ -254,6 +253,13 @@ void OSystem_Android::initSize(uint width, uint height,
LOGI("overlay size is %ux%u", overlay_width, overlay_height);
_overlay_texture->allocBuffer(overlay_width, overlay_height);
+}
+
+void OSystem_Android::initSize(uint width, uint height,
+ const Graphics::PixelFormat *format) {
+ ENTER("%d, %d, %p", width, height, format);
+
+ GLTHREADCHECK;
#ifdef USE_RGB_COLOR
initTexture(&_game_texture, width, height, format, false);
@@ -298,7 +304,7 @@ void OSystem_Android::setPalette(const byte *colors, uint start, uint num) {
colors, num * 3);
if (!_use_mouse_palette)
- _setCursorPalette(colors, start, num);
+ setCursorPaletteInternal(colors, start, num);
}
void OSystem_Android::grabPalette(byte *colors, uint start, uint num) {
@@ -458,8 +464,6 @@ void OSystem_Android::fillScreen(uint32 col) {
GLTHREADCHECK;
- // TODO FIXME rgb colors
- assert(col < 256);
_game_texture->fillBuffer(col);
}
@@ -573,53 +577,79 @@ void OSystem_Android::setMouseCursor(const byte *buf, uint w, uint h,
GLTHREADCHECK;
- assert(keycolor < 256);
-
#ifdef USE_RGB_COLOR
if (format && format->bytesPerPixel > 1) {
if (_mouse_texture != _mouse_texture_rgb)
LOGD("switching to rgb mouse cursor");
- initTexture(&_mouse_texture_rgb, w, h, format, true);
-
+ _mouse_texture_rgb = new GLES5551Texture();
_mouse_texture = _mouse_texture_rgb;
} else {
if (_mouse_texture != _mouse_texture_palette)
LOGD("switching to paletted mouse cursor");
- initTexture((GLESTexture **)&_mouse_texture_palette, w, h, format,
- true);
-
_mouse_texture = _mouse_texture_palette;
delete _mouse_texture_rgb;
_mouse_texture_rgb = 0;
}
-#else
- _mouse_texture_palette->allocBuffer(w, h);
#endif
- if (_mouse_texture->getPixelFormat().bytesPerPixel == 1) {
+ _mouse_texture->allocBuffer(w, h);
+
+ if (_mouse_texture == _mouse_texture_palette) {
+ assert(keycolor < 256);
+
// Update palette alpha based on keycolor
byte *palette = _mouse_texture_palette->palette();
for (uint i = 0; i < 256; ++i, palette += 4)
palette[3] = 0xff;
- _mouse_texture_palette->palette()[keycolor * 4 + 3] = 0x00;
+ _mouse_texture_palette->palette()[keycolor * 4 + 3] = 0;
}
if (w == 0 || h == 0)
return;
- _mouse_texture->updateBuffer(0, 0, w, h, buf, w);
+ if (_mouse_texture == _mouse_texture_palette) {
+ _mouse_texture->updateBuffer(0, 0, w, h, buf, w);
+ } else {
+ uint16 pitch = _mouse_texture->pitch();
+
+ byte *tmp = new byte[pitch * h];
+
+ // meh, a 16bit cursor without alpha bits... this is so silly
+ if (!crossBlit(tmp, buf, pitch, w * 2, w, h,
+ _mouse_texture->getPixelFormat(),
+ *format)) {
+ LOGE("crossblit failed");
+
+ delete[] tmp;
+
+ _mouse_texture->fillBuffer(0);
+
+ return;
+ }
+
+ uint16 *s = (uint16 *)buf;
+ uint16 *d = (uint16 *)tmp;
+ for (uint16 y = 0; y < h; ++y, d += pitch / 2 - w)
+ for (uint16 x = 0; x < w; ++x, d++)
+ if (*s++ != (keycolor & 0xffff))
+ *d |= 1;
+
+ _mouse_texture->updateBuffer(0, 0, w, h, tmp, pitch);
+
+ delete[] tmp;
+ }
_mouse_hotspot = Common::Point(hotspotX, hotspotY);
_mouse_targetscale = cursorTargetScale;
}
-void OSystem_Android::_setCursorPalette(const byte *colors,
- uint start, uint num) {
+void OSystem_Android::setCursorPaletteInternal(const byte *colors,
+ uint start, uint num) {
byte *palette = _mouse_texture_palette->palette() + start * 4;
for (uint i = 0; i < num; ++i, palette += 4, colors += 3) {
@@ -645,7 +675,7 @@ void OSystem_Android::setCursorPalette(const byte *colors,
_mouse_texture_rgb = 0;
}
- _setCursorPalette(colors, start, num);
+ setCursorPaletteInternal(colors, start, num);
_use_mouse_palette = true;
}
diff --git a/backends/platform/android/jni.cpp b/backends/platform/android/jni.cpp
index 73b74394c0..6bfe9c2095 100644
--- a/backends/platform/android/jni.cpp
+++ b/backends/platform/android/jni.cpp
@@ -631,7 +631,13 @@ void JNI::setPause(JNIEnv *env, jobject self, jboolean value) {
if (g_engine) {
LOGD("pauseEngine: %d", value);
+
g_engine->pauseEngine(value);
+
+ if (value &&
+ g_engine->hasFeature(Engine::kSupportsSavingDuringRuntime) &&
+ g_engine->canSaveGameStateCurrently())
+ g_engine->saveGameState(0, "Android parachute");
}
pause = value;
diff --git a/backends/platform/android/texture.cpp b/backends/platform/android/texture.cpp
index e4c98e3ce0..24e6549b1a 100644
--- a/backends/platform/android/texture.cpp
+++ b/backends/platform/android/texture.cpp
@@ -88,19 +88,15 @@ GLESTexture::GLESTexture(byte bytesPerPixel, GLenum glFormat, GLenum glType,
_glFormat(glFormat),
_glType(glType),
_paletteSize(paletteSize),
- _pixelFormat(pixelFormat),
+ _texture_name(0),
+ _surface(),
_texture_width(0),
_texture_height(0),
- _all_dirty(true)
+ _all_dirty(false),
+ _dirty_rect(),
+ _pixelFormat(pixelFormat)
{
GLCALL(glGenTextures(1, &_texture_name));
-
- // This all gets reset later in allocBuffer:
- _surface.w = 0;
- _surface.h = 0;
- _surface.pitch = 0;
- _surface.pixels = 0;
- _surface.bytesPerPixel = 0;
}
GLESTexture::~GLESTexture() {
@@ -166,15 +162,15 @@ void GLESTexture::allocBuffer(GLuint w, GLuint h) {
}
void GLESTexture::updateBuffer(GLuint x, GLuint y, GLuint w, GLuint h,
- const void *buf, int pitch) {
- ENTER("%u, %u, %u, %u, %p, %d", x, y, w, h, buf, pitch);
+ const void *buf, int pitch_buf) {
+ ENTER("%u, %u, %u, %u, %p, %d", x, y, w, h, buf, pitch_buf);
GLCALL(glBindTexture(GL_TEXTURE_2D, _texture_name));
GLCALL(glPixelStorei(GL_UNPACK_ALIGNMENT, 1));
setDirtyRect(Common::Rect(x, y, x + w, y + h));
- if (static_cast<int>(w) * _bytesPerPixel == pitch) {
+ if (static_cast<int>(w) * _bytesPerPixel == pitch_buf) {
GLCALL(glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, w, h,
_glFormat, _glType, buf));
} else {
@@ -191,7 +187,7 @@ void GLESTexture::updateBuffer(GLuint x, GLuint y, GLuint w, GLuint h,
do {
memcpy(dst, src, w * _bytesPerPixel);
dst += w * _bytesPerPixel;
- src += pitch;
+ src += pitch_buf;
} while (--count);
GLCALL(glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, w, h,
@@ -206,19 +202,24 @@ void GLESTexture::updateBuffer(GLuint x, GLuint y, GLuint w, GLuint h,
GLCALL(glTexSubImage2D(GL_TEXTURE_2D, 0, x, y,
w, 1, _glFormat, _glType, src));
++y;
- src += pitch;
+ src += pitch_buf;
} while (--h);
#endif
}
}
-void GLESTexture::fillBuffer(byte x) {
+void GLESTexture::fillBuffer(uint32 color) {
uint rowbytes = _surface.w * _bytesPerPixel;
byte *tmp = new byte[rowbytes];
assert(tmp);
- memset(tmp, x, rowbytes);
+ if (_bytesPerPixel == 1 || ((color & 0xff) == ((color >> 8) & 0xff))) {
+ memset(tmp, color & 0xff, rowbytes);
+ } else {
+ uint16 *p = (uint16 *)tmp;
+ Common::set_to(p, p + _surface.w, (uint16)color);
+ }
GLCALL(glBindTexture(GL_TEXTURE_2D, _texture_name));
GLCALL(glPixelStorei(GL_UNPACK_ALIGNMENT, 1));
@@ -275,8 +276,7 @@ void GLESTexture::drawTexture(GLshort x, GLshort y, GLshort w, GLshort h) {
GLCALL(glDrawArrays(GL_TRIANGLE_STRIP, 0, ARRAYSIZE(vertices) / 2));
}
- _all_dirty = false;
- _dirty_rect = Common::Rect();
+ clearDirty();
}
GLES4444Texture::GLES4444Texture() :
@@ -313,28 +313,13 @@ GLESPaletteTexture::~GLESPaletteTexture() {
}
void GLESPaletteTexture::allocBuffer(GLuint w, GLuint h) {
- _surface.w = w;
- _surface.h = h;
- _surface.bytesPerPixel = _bytesPerPixel;
-
- // Already allocated a sufficiently large buffer?
- if (w <= _texture_width && h <= _texture_height)
- return;
-
- if (npot_supported) {
- _texture_width = _surface.w;
- _texture_height = _surface.h;
- } else {
- _texture_width = nextHigher2(_surface.w);
- _texture_height = nextHigher2(_surface.h);
- }
-
- _surface.pitch = _texture_width * _bytesPerPixel;
+ GLESTexture::allocBuffer(w, h);
// Texture gets uploaded later (from drawTexture())
byte *new_buffer = new byte[_paletteSize +
_texture_width * _texture_height * _bytesPerPixel];
+ assert(new_buffer);
if (_texture) {
// preserve palette
@@ -346,16 +331,15 @@ void GLESPaletteTexture::allocBuffer(GLuint w, GLuint h) {
_surface.pixels = _texture + _paletteSize;
}
-void GLESPaletteTexture::fillBuffer(byte x) {
+void GLESPaletteTexture::fillBuffer(uint32 color) {
assert(_surface.pixels);
- memset(_surface.pixels, x, _surface.pitch * _surface.h);
+ memset(_surface.pixels, color & 0xff, _surface.pitch * _surface.h);
setDirty();
}
-void GLESPaletteTexture::updateBuffer(GLuint x, GLuint y,
- GLuint w, GLuint h,
- const void *buf, int pitch) {
- _all_dirty = true;
+void GLESPaletteTexture::updateBuffer(GLuint x, GLuint y, GLuint w, GLuint h,
+ const void *buf, int pitch_buf) {
+ setDirtyRect(Common::Rect(x, y, x + w, y + h));
const byte * src = static_cast<const byte *>(buf);
byte *dst = static_cast<byte *>(_surface.getBasePtr(x, y));
@@ -363,22 +347,14 @@ void GLESPaletteTexture::updateBuffer(GLuint x, GLuint y,
do {
memcpy(dst, src, w * _bytesPerPixel);
dst += _surface.pitch;
- src += pitch;
+ src += pitch_buf;
} while (--h);
}
void GLESPaletteTexture::drawTexture(GLshort x, GLshort y, GLshort w,
GLshort h) {
- if (_all_dirty) {
+ if (dirty()) {
GLCALL(glBindTexture(GL_TEXTURE_2D, _texture_name));
- GLCALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
- GL_NEAREST));
- GLCALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
- GL_NEAREST));
- GLCALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
- GL_CLAMP_TO_EDGE));
- GLCALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
- GL_CLAMP_TO_EDGE));
const size_t texture_size =
_paletteSize + _texture_width * _texture_height * _bytesPerPixel;
diff --git a/backends/platform/android/texture.h b/backends/platform/android/texture.h
index 14eea44914..78df43aea9 100644
--- a/backends/platform/android/texture.h
+++ b/backends/platform/android/texture.h
@@ -54,8 +54,8 @@ public:
virtual void allocBuffer(GLuint width, GLuint height);
virtual void updateBuffer(GLuint x, GLuint y, GLuint width, GLuint height,
- const void *buf, int pitch);
- virtual void fillBuffer(byte x);
+ const void *buf, int pitch_buf);
+ virtual void fillBuffer(uint32 color);
virtual void drawTexture(GLshort x, GLshort y, GLshort w, GLshort h);
@@ -71,6 +71,10 @@ public:
return _surface.h;
}
+ inline uint16 pitch() const {
+ return _surface.pitch;
+ }
+
inline const Graphics::Surface *surface_const() const {
return &_surface;
}
@@ -84,14 +88,21 @@ public:
return _all_dirty || !_dirty_rect.isEmpty();
}
- inline Graphics::PixelFormat getPixelFormat() const {
+ inline const Graphics::PixelFormat &getPixelFormat() const {
return _pixelFormat;
}
protected:
inline void setDirty() {
_all_dirty = true;
- _dirty_rect = Common::Rect();
+ }
+
+ inline void clearDirty() {
+ _all_dirty = false;
+ _dirty_rect.top = 0;
+ _dirty_rect.left = 0;
+ _dirty_rect.bottom = 0;
+ _dirty_rect.right = 0;
}
inline void setDirtyRect(const Common::Rect& r) {
@@ -112,9 +123,9 @@ protected:
Graphics::Surface _surface;
GLuint _texture_width;
GLuint _texture_height;
- bool _all_dirty;
// Covers dirty area
+ bool _all_dirty;
Common::Rect _dirty_rect;
Graphics::PixelFormat _pixelFormat;
@@ -163,8 +174,8 @@ public:
virtual void allocBuffer(GLuint width, GLuint height);
virtual void updateBuffer(GLuint x, GLuint y, GLuint width, GLuint height,
- const void *buf, int pitch);
- virtual void fillBuffer(byte x);
+ const void *buf, int pitch_buf);
+ virtual void fillBuffer(uint32 color);
virtual void drawTexture(GLshort x, GLshort y, GLshort w, GLshort h);