aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordhewg2011-03-12 09:33:45 +0100
committerdhewg2011-03-12 09:36:23 +0100
commit0cdaff65c104f11954167048455d4258d053e1cd (patch)
tree4b9fbe9dc1762b675d5bfb29470e185f60bad36d
parentcaf21a357bef24ced14d8b67c7f3f6687a767570 (diff)
downloadscummvm-rg350-0cdaff65c104f11954167048455d4258d053e1cd.tar.gz
scummvm-rg350-0cdaff65c104f11954167048455d4258d053e1cd.tar.bz2
scummvm-rg350-0cdaff65c104f11954167048455d4258d053e1cd.zip
ANDROID: Use 16bit pixel formats on CLUT8 textures
This reduces the CPU usage on 640x480 games by ~5% on my droid when reuploading the textures to the GPU
-rw-r--r--backends/platform/android/android.cpp6
-rw-r--r--backends/platform/android/android.h1
-rw-r--r--backends/platform/android/gfx.cpp60
3 files changed, 42 insertions, 25 deletions
diff --git a/backends/platform/android/android.cpp b/backends/platform/android/android.cpp
index 2be435c701..ca65863fc9 100644
--- a/backends/platform/android/android.cpp
+++ b/backends/platform/android/android.cpp
@@ -112,6 +112,8 @@ OSystem_Android::OSystem_Android(int audio_sample_rate, int audio_buffer_size) :
_mouse_texture(0),
_mouse_texture_palette(0),
_mouse_texture_rgb(0),
+ _mouse_hotspot(),
+ _mouse_keycolor(0),
_use_mouse_palette(false),
_show_mouse(false),
_show_overlay(false),
@@ -328,9 +330,9 @@ void OSystem_Android::initBackend() {
initSurface();
initViewport();
- _game_texture = new GLESPalette888Texture();
+ _game_texture = new GLESPalette565Texture();
_overlay_texture = new GLES4444Texture();
- _mouse_texture_palette = new GLESPalette8888Texture();
+ _mouse_texture_palette = new GLESPalette5551Texture();
_mouse_texture = _mouse_texture_palette;
initOverlay();
diff --git a/backends/platform/android/android.h b/backends/platform/android/android.h
index ba1a47a10f..f73131b317 100644
--- a/backends/platform/android/android.h
+++ b/backends/platform/android/android.h
@@ -116,6 +116,7 @@ private:
GLESPaletteTexture *_mouse_texture_palette;
GLES5551Texture *_mouse_texture_rgb;
Common::Point _mouse_hotspot;
+ uint32 _mouse_keycolor;
int _mouse_targetscale;
bool _show_mouse;
bool _use_mouse_palette;
diff --git a/backends/platform/android/gfx.cpp b/backends/platform/android/gfx.cpp
index d7650fb00c..6be7a03b22 100644
--- a/backends/platform/android/gfx.cpp
+++ b/backends/platform/android/gfx.cpp
@@ -25,6 +25,7 @@
#if defined(__ANDROID__)
+#include "common/endian.h"
#include "graphics/conversion.h"
#include "backends/platform/android/android.h"
@@ -134,7 +135,7 @@ void OSystem_Android::initTexture(GLESTexture **texture,
LOGE("unsupported pixel format: %s",
getPixelFormatName(format_new).c_str());
- *texture = new GLESPalette888Texture;
+ *texture = new GLESPalette565Texture;
}
LOGD("new pixel format: %s",
@@ -296,10 +297,14 @@ void OSystem_Android::setPalette(const byte *colors, uint start, uint num) {
GLTHREADCHECK;
- memcpy(_game_texture->palette() + start * 3, colors, num * 3);
-
if (!_use_mouse_palette)
setCursorPaletteInternal(colors, start, num);
+
+ const Graphics::PixelFormat &pf = _game_texture->getPalettePixelFormat();
+ byte *p = _game_texture->palette() + start * 2;
+
+ for (uint i = 0; i < num; ++i, colors += 3, p += 2)
+ WRITE_UINT16(p, pf.RGBToColor(colors[0], colors[1], colors[2]));
}
void OSystem_Android::grabPalette(byte *colors, uint start, uint num) {
@@ -311,7 +316,11 @@ void OSystem_Android::grabPalette(byte *colors, uint start, uint num) {
GLTHREADCHECK;
- memcpy(colors, _game_texture->palette() + start * 3, num * 3);
+ const Graphics::PixelFormat &pf = _game_texture->getPalettePixelFormat();
+ const byte *p = _game_texture->palette_const() + start * 2;
+
+ for (uint i = 0; i < num; ++i, colors += 3, p += 2)
+ pf.colorToRGB(READ_UINT16(p), colors[0], colors[1], colors[2]);
}
void OSystem_Android::copyRectToScreen(const byte *buf, int pitch,
@@ -594,13 +603,11 @@ void OSystem_Android::setMouseCursor(const byte *buf, uint w, uint 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;
+ byte *p = _mouse_texture_palette->palette() + _mouse_keycolor * 2;
- _mouse_texture_palette->palette()[keycolor * 4 + 3] = 0;
+ WRITE_UINT16(p, READ_UINT16(p) | 1);
+ _mouse_keycolor = keycolor;
+ WRITE_UINT16(_mouse_texture_palette->palette() + keycolor * 2, 0);
}
if (w == 0 || h == 0)
@@ -644,14 +651,14 @@ void OSystem_Android::setMouseCursor(const byte *buf, uint w, uint h,
void OSystem_Android::setCursorPaletteInternal(const byte *colors,
uint start, uint num) {
- byte *palette = _mouse_texture_palette->palette() + start * 4;
+ const Graphics::PixelFormat &pf =
+ _mouse_texture_palette->getPalettePixelFormat();
+ byte *p = _mouse_texture_palette->palette() + start * 2;
- for (uint i = 0; i < num; ++i, palette += 4, colors += 3) {
- palette[0] = colors[0];
- palette[1] = colors[1];
- palette[2] = colors[2];
- // Leave alpha untouched to preserve keycolor
- }
+ for (uint i = 0; i < num; ++i, colors += 3, p += 2)
+ WRITE_UINT16(p, pf.RGBToColor(colors[0], colors[1], colors[2]));
+
+ WRITE_UINT16(_mouse_texture_palette->palette() + _mouse_keycolor * 2, 0);
}
void OSystem_Android::setCursorPalette(const byte *colors,
@@ -679,15 +686,22 @@ void OSystem_Android::disableCursorPalette(bool disable) {
// when disabling the cursor palette, and we're running a clut8 game,
// it expects the game palette to be used for the cursor
if (disable && _game_texture->hasPalette()) {
- byte *src = _game_texture->palette();
+ const byte *src = _game_texture->palette_const();
byte *dst = _mouse_texture_palette->palette();
- for (uint i = 0; i < 256; ++i, src += 3, dst += 4) {
- dst[0] = src[0];
- dst[1] = src[1];
- dst[2] = src[2];
- // Leave alpha untouched to preserve keycolor
+ const Graphics::PixelFormat &pf_src =
+ _game_texture->getPalettePixelFormat();
+ const Graphics::PixelFormat &pf_dst =
+ _mouse_texture_palette->getPalettePixelFormat();
+
+ uint8 r, g, b;
+
+ for (uint i = 0; i < 256; ++i, src += 2, dst += 2) {
+ pf_src.colorToRGB(READ_UINT16(src), r, g, b);
+ WRITE_UINT16(dst, pf_dst.RGBToColor(r, g, b));
}
+
+ WRITE_UINT16(_mouse_texture_palette->palette() + _mouse_keycolor * 2, 0);
}
_use_mouse_palette = !disable;