diff options
Diffstat (limited to 'backends/platform/android/gfx.cpp')
-rw-r--r-- | backends/platform/android/gfx.cpp | 80 |
1 files changed, 55 insertions, 25 deletions
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; } |