ANDROID: Shift graphics code to graphics.cpp

This brings our port more in line with ScummVM. Much of the code there
now is analogous to graphics/opengl/opengl-graphics.h
This commit is contained in:
Dries Harnie 2020-06-01 13:49:59 +02:00
parent 33975233de
commit 7823e94c18
7 changed files with 722 additions and 672 deletions

View file

@ -60,6 +60,7 @@
#include "backends/platform/android/jni-android.h" #include "backends/platform/android/jni-android.h"
#include "backends/platform/android/android.h" #include "backends/platform/android/android.h"
#include "backends/platform/android/graphics.h"
const char *android_log_tag = "ResidualVM"; const char *android_log_tag = "ResidualVM";
@ -115,22 +116,6 @@ OSystem_Android::OSystem_Android(int audio_sample_rate, int audio_buffer_size) :
_audio_sample_rate(audio_sample_rate), _audio_sample_rate(audio_sample_rate),
_audio_buffer_size(audio_buffer_size), _audio_buffer_size(audio_buffer_size),
_screen_changeid(0), _screen_changeid(0),
_force_redraw(false),
_game_texture(0),
_game_pbuf(),
_overlay_texture(0),
_opengl(false),
_mouse_texture(0),
_mouse_texture_palette(0),
_mouse_texture_rgb(0),
_mouse_hotspot(),
_mouse_keycolor(0),
_use_mouse_palette(false),
_graphicsMode(0),
_fullscreen(true),
_ar_correction(true),
_show_mouse(false),
_show_overlay(false),
_mixer(0), _mixer(0),
_queuedEventTime(0), _queuedEventTime(0),
_event_queue_lock(0), _event_queue_lock(0),
@ -148,18 +133,14 @@ OSystem_Android::OSystem_Android(int audio_sample_rate, int audio_buffer_size) :
_fsFactory = new POSIXFilesystemFactory(); _fsFactory = new POSIXFilesystemFactory();
Common::String mf = getSystemProperty("ro.product.manufacturer");
LOGI("Running on: [%s] [%s] [%s] [%s] [%s] SDK:%s ABI:%s", LOGI("Running on: [%s] [%s] [%s] [%s] [%s] SDK:%s ABI:%s",
mf.c_str(), getSystemProperty("ro.product.manufacturer").c_str(),
getSystemProperty("ro.product.model").c_str(), getSystemProperty("ro.product.model").c_str(),
getSystemProperty("ro.product.brand").c_str(), getSystemProperty("ro.product.brand").c_str(),
getSystemProperty("ro.build.fingerprint").c_str(), getSystemProperty("ro.build.fingerprint").c_str(),
getSystemProperty("ro.build.display.id").c_str(), getSystemProperty("ro.build.display.id").c_str(),
getSystemProperty("ro.build.version.sdk").c_str(), getSystemProperty("ro.build.version.sdk").c_str(),
getSystemProperty("ro.product.cpu.abi").c_str()); getSystemProperty("ro.product.cpu.abi").c_str());
mf.toLowercase();
} }
OSystem_Android::~OSystem_Android() { OSystem_Android::~OSystem_Android() {
@ -376,15 +357,9 @@ void OSystem_Android::initBackend() {
_audio_thread_exit = false; _audio_thread_exit = false;
pthread_create(&_audio_thread, 0, audioThreadFunc, this); pthread_create(&_audio_thread, 0, audioThreadFunc, this);
initSurface(); _graphicsManager = new AndroidGraphicsManager();
initViewport();
_game_texture = new GLESFakePalette565Texture(); dynamic_cast<AndroidGraphicsManager *>(_graphicsManager)->initSurface();
_overlay_texture = new GLES4444Texture();
_mouse_texture_palette = new GLESFakePalette5551Texture();
_mouse_texture = _mouse_texture_palette;
initOverlay();
// renice this thread to boost the audio thread // renice this thread to boost the audio thread
if (setpriority(PRIO_PROCESS, 0, 19) < 0) if (setpriority(PRIO_PROCESS, 0, 19) < 0)
@ -400,39 +375,23 @@ bool OSystem_Android::hasFeature(Feature f) {
f == kFeatureOpenUrl || f == kFeatureOpenUrl ||
f == kFeatureTouchpadMode || f == kFeatureTouchpadMode ||
f == kFeatureOnScreenControl || f == kFeatureOnScreenControl ||
f == kFeatureFullscreenMode ||
f == kFeatureClipboardSupport || f == kFeatureClipboardSupport ||
f == kFeatureAspectRatioCorrection ||
f == kFeatureCursorPalette ||
f == kFeatureOpenGL || f == kFeatureOpenGL ||
f == kFeatureOverlaySupportsAlpha || f == kFeatureOverlaySupportsAlpha ||
f == kFeatureClipboardSupport) { f == kFeatureClipboardSupport) {
return true; return true;
} }
return false; return ModularBackend::hasFeature(f);
} }
void OSystem_Android::setFeatureState(Feature f, bool enable) { void OSystem_Android::setFeatureState(Feature f, bool enable) {
ENTER("%d, %d", f, enable); ENTER("%d, %d", f, enable);
switch (f) { switch (f) {
case kFeatureFullscreenMode:
_fullscreen = enable;
updateScreenRect();
break;
case kFeatureAspectRatioCorrection:
_ar_correction = enable;
updateScreenRect();
break;
case kFeatureVirtualKeyboard: case kFeatureVirtualKeyboard:
_virtkeybd_on = enable; _virtkeybd_on = enable;
showVirtualKeyboard(enable); showVirtualKeyboard(enable);
break; break;
case kFeatureCursorPalette:
_use_mouse_palette = enable;
if (!enable)
disableCursorPalette();
break;
case kFeatureTouchpadMode: case kFeatureTouchpadMode:
ConfMan.setBool("touchpad_mouse_mode", enable); ConfMan.setBool("touchpad_mouse_mode", enable);
_touchpad_mode = enable; _touchpad_mode = enable;
@ -442,29 +401,29 @@ void OSystem_Android::setFeatureState(Feature f, bool enable) {
JNI::showKeyboardControl(enable); JNI::showKeyboardControl(enable);
break; break;
default: default:
ModularBackend::setFeatureState(f, enable);
break; break;
} }
} }
bool OSystem_Android::getFeatureState(Feature f) { bool OSystem_Android::getFeatureState(Feature f) {
switch (f) { switch (f) {
case kFeatureFullscreenMode:
return _fullscreen;
case kFeatureAspectRatioCorrection:
return _ar_correction;
case kFeatureVirtualKeyboard: case kFeatureVirtualKeyboard:
return _virtkeybd_on; return _virtkeybd_on;
case kFeatureCursorPalette:
return _use_mouse_palette;
case kFeatureTouchpadMode: case kFeatureTouchpadMode:
return ConfMan.getBool("touchpad_mouse_mode"); return ConfMan.getBool("touchpad_mouse_mode");
case kFeatureOnScreenControl: case kFeatureOnScreenControl:
return ConfMan.getBool("onscreen_control"); return ConfMan.getBool("onscreen_control");
default: default:
return false; return ModularBackend::getFeatureState(f);
} }
} }
// ResidualVM specific method
void OSystem_Android::launcherInitSize(uint w, uint h) {
dynamic_cast<AndroidGraphicsManager *>(_graphicsManager)->setupScreen(w, h, true, true, false);
}
uint32 OSystem_Android::getMillis(bool skipRecord) { uint32 OSystem_Android::getMillis(bool skipRecord) {
timeval curTime; timeval curTime;
@ -489,12 +448,7 @@ void OSystem_Android::quit() {
_timer_thread_exit = true; _timer_thread_exit = true;
pthread_join(_timer_thread, 0); pthread_join(_timer_thread, 0);
delete _game_texture; dynamic_cast<AndroidGraphicsManager *>(_graphicsManager)->deinitSurface();
delete _overlay_texture;
delete _mouse_texture_palette;
delete _mouse_texture_rgb;
deinitSurface();
} }
void OSystem_Android::setWindowCaption(const char *caption) { void OSystem_Android::setWindowCaption(const char *caption) {
@ -503,11 +457,6 @@ void OSystem_Android::setWindowCaption(const char *caption) {
JNI::setWindowCaption(caption); JNI::setWindowCaption(caption);
} }
void OSystem_Android::displayMessageOnOSD(const char *msg) {
ENTER("%s", msg);
JNI::displayMessageOnOSD(msg);
}
void OSystem_Android::showVirtualKeyboard(bool enable) { void OSystem_Android::showVirtualKeyboard(bool enable) {
ENTER("%d", enable); ENTER("%d", enable);

View file

@ -25,6 +25,7 @@
#if defined(__ANDROID__) #if defined(__ANDROID__)
#include "backends/platform/android/portdefs.h"
#include "common/fs.h" #include "common/fs.h"
#include "common/archive.h" #include "common/archive.h"
#include "audio/mixer_intern.h" #include "audio/mixer_intern.h"
@ -39,6 +40,7 @@
#include "backends/platform/android/events.h" #include "backends/platform/android/events.h"
#include "backends/platform/android/texture.h" #include "backends/platform/android/texture.h"
#include "backends/platform/android/graphics.h"
#include "backends/platform/android/touchcontrols.h" #include "backends/platform/android/touchcontrols.h"
#include <pthread.h> #include <pthread.h>
@ -98,7 +100,7 @@ extern void checkGlError(const char *expr, const char *file, int line);
#define GLTHREADCHECK do { } while (false) #define GLTHREADCHECK do { } while (false)
#endif #endif
class OSystem_Android : public ModularBackend, public PaletteManager, Common::EventSource { class OSystem_Android : public ModularBackend, Common::EventSource {
private: private:
// passed from the dark side // passed from the dark side
int _audio_sample_rate; int _audio_sample_rate;
@ -106,33 +108,6 @@ private:
int _screen_changeid; int _screen_changeid;
bool _force_redraw;
bool _opengl;
// Game layer
GLESBaseTexture *_game_texture;
Graphics::PixelBuffer _game_pbuf;
OpenGL::FrameBuffer *_frame_buffer;
// Overlay layer
GLES4444Texture *_overlay_texture;
bool _show_overlay;
// Mouse layer
GLESBaseTexture *_mouse_texture;
GLESBaseTexture *_mouse_texture_palette;
GLES5551Texture *_mouse_texture_rgb;
Common::Point _mouse_hotspot;
uint32 _mouse_keycolor;
int _mouse_targetscale;
bool _show_mouse;
bool _use_mouse_palette;
int _graphicsMode;
bool _fullscreen;
bool _ar_correction;
pthread_t _main_thread; pthread_t _main_thread;
bool _timer_thread_exit; bool _timer_thread_exit;
@ -150,19 +125,7 @@ private:
Common::String getSystemProperty(const char *name) const; Common::String getSystemProperty(const char *name) const;
void initSurface();
void deinitSurface();
void initViewport();
void initOverlay();
#ifdef USE_RGB_COLOR
void initTexture(GLESBaseTexture **texture, uint width, uint height,
const Graphics::PixelFormat *format);
#endif
void setupKeymapper(); void setupKeymapper();
void setCursorPaletteInternal(const byte *colors, uint start, uint num);
protected: protected:
virtual Common::EventSource *getDefaultEventSource() { return this; } virtual Common::EventSource *getDefaultEventSource() { return this; }
@ -177,35 +140,8 @@ public:
virtual void setFeatureState(OSystem::Feature f, bool enable); virtual void setFeatureState(OSystem::Feature f, bool enable);
virtual bool getFeatureState(OSystem::Feature f); virtual bool getFeatureState(OSystem::Feature f);
virtual const GraphicsMode *getSupportedGraphicsModes() const; virtual PaletteManager *getPaletteManager() override {
virtual int getDefaultGraphicsMode() const; return dynamic_cast<AndroidGraphicsManager *>(_graphicsManager);
virtual bool setGraphicsMode(int mode);
virtual int getGraphicsMode() const;
#ifdef USE_RGB_COLOR
virtual Graphics::PixelFormat getScreenFormat() const;
virtual Common::List<Graphics::PixelFormat> getSupportedFormats() const;
#endif
virtual void initSize(uint width, uint height,
const Graphics::PixelFormat *format);
enum FixupType {
kClear = 0, // glClear
kClearSwap, // glClear + swapBuffers
kClearUpdate // glClear + updateScreen
};
void clearScreen(FixupType type, byte count = 1);
void updateScreenRect();
virtual int getScreenChangeID() const;
virtual int16 getHeight();
virtual int16 getWidth();
virtual PaletteManager *getPaletteManager() {
return this;
} }
public: public:
@ -228,46 +164,12 @@ private:
int _fingersDown; int _fingersDown;
void clipMouse(Common::Point &p); void clipMouse(Common::Point &p);
void scaleMouse(Common::Point &p, int x, int y, bool deductDrawRect = true, bool touchpadMode = false); void scaleMouse(Common::Point &p, int x, int y, bool touchpadMode = false);
void updateEventScale();
void disableCursorPalette(); void disableCursorPalette();
TouchControls _touchControls; TouchControls _touchControls;
void drawVirtControls();
protected:
// PaletteManager API
virtual void setPalette(const byte *colors, uint start, uint num);
virtual void grabPalette(byte *colors, uint start, uint num) const;
public: public:
virtual void copyRectToScreen(const void *buf, int pitch, int x, int y,
int w, int h);
virtual void updateScreen();
virtual Graphics::Surface *lockScreen();
virtual void unlockScreen();
virtual void setShakePos(int shakeXOffset, int shakeYOffset);
virtual void fillScreen(uint32 col);
virtual void showOverlay();
virtual void hideOverlay();
virtual void clearOverlay();
virtual void grabOverlay(void *buf, int pitch);
virtual void copyRectToOverlay(const void *buf, int pitch,
int x, int y, int w, int h);
virtual int16 getOverlayHeight();
virtual int16 getOverlayWidth();
virtual Graphics::PixelFormat getOverlayFormat() const;
virtual bool showMouse(bool visible);
virtual void warpMouse(int x, int y);
virtual void setMouseCursor(const void *buf, uint w, uint h, int hotspotX,
int hotspotY, uint32 keycolor,
bool dontScale,
const Graphics::PixelFormat *format);
virtual void setCursorPalette(const byte *colors, uint start, uint num);
virtual void pushEvent(const Common::Event &event); virtual void pushEvent(const Common::Event &event);
virtual void pushKeyPressEvent(Common::Event &event); virtual void pushKeyPressEvent(Common::Event &event);
@ -278,7 +180,6 @@ public:
virtual void quit(); virtual void quit();
virtual void setWindowCaption(const char *caption); virtual void setWindowCaption(const char *caption);
virtual void displayMessageOnOSD(const char *msg);
virtual void showVirtualKeyboard(bool enable); virtual void showVirtualKeyboard(bool enable);
virtual Audio::Mixer *getMixer(); virtual Audio::Mixer *getMixer();
@ -295,12 +196,8 @@ public:
// ResidualVM specific method // ResidualVM specific method
virtual void launcherInitSize(uint w, uint h); virtual void launcherInitSize(uint w, uint h);
bool lockMouse(bool lock); void updateEventScale(const GLESBaseTexture *tex);
void setupScreen(uint screenW, uint screenH, bool fullscreen, bool accel3d) { TouchControls* getTouchControls() { return &_touchControls; }
setupScreen(screenW, screenH, fullscreen, accel3d, true);
}
void setupScreen(uint screenW, uint screenH, bool fullscreen, bool accel3d, bool isGame);
Graphics::PixelBuffer getScreenPixelBuffer();
}; };
#endif #endif

View file

@ -41,6 +41,7 @@
#include "backends/platform/android/android.h" #include "backends/platform/android/android.h"
#include "backends/platform/android/events.h" #include "backends/platform/android/events.h"
#include "backends/platform/android/graphics.h"
#include "backends/platform/android/jni-android.h" #include "backends/platform/android/jni-android.h"
#include "engines/engine.h" #include "engines/engine.h"
@ -79,40 +80,13 @@ void OSystem_Android::setupKeymapper() {
#endif #endif
} }
void OSystem_Android::warpMouse(int x, int y) {
ENTER("%d, %d", x, y);
Common::Event e;
e.type = Common::EVENT_MOUSEMOVE;
e.mouse.x = x;
e.mouse.y = y;
clipMouse(e.mouse);
pushEvent(e);
}
void OSystem_Android::clipMouse(Common::Point &p) { void OSystem_Android::clipMouse(Common::Point &p) {
const GLESBaseTexture *tex; dynamic_cast<AndroidGraphicsManager *>(_graphicsManager)->clipMouse(p);
if (_show_overlay)
tex = _overlay_texture;
else
tex = _game_texture;
p.x = CLIP(p.x, int16(0), int16(tex->width() - 1));
p.y = CLIP(p.y, int16(0), int16(tex->height() - 1));
} }
void OSystem_Android::scaleMouse(Common::Point &p, int x, int y, void OSystem_Android::scaleMouse(Common::Point &p, int x, int y, bool touchpadMode) {
bool deductDrawRect, bool touchpadMode) { const GLESBaseTexture *tex =
const GLESBaseTexture *tex; dynamic_cast<AndroidGraphicsManager *>(_graphicsManager)->getActiveTexture();
if (_show_overlay)
tex = _overlay_texture;
else
tex = _game_texture;
const Common::Rect &r = tex->getDrawRect(); const Common::Rect &r = tex->getDrawRect();
@ -121,23 +95,11 @@ void OSystem_Android::scaleMouse(Common::Point &p, int x, int y,
y = y * 100 / _touchpad_scale; y = y * 100 / _touchpad_scale;
} }
if (deductDrawRect) {
x -= r.left;
y -= r.top;
}
p.x = scalef(x, tex->width(), r.width()); p.x = scalef(x, tex->width(), r.width());
p.y = scalef(y, tex->height(), r.height()); p.y = scalef(y, tex->height(), r.height());
} }
void OSystem_Android::updateEventScale() { void OSystem_Android::updateEventScale(const GLESBaseTexture *tex) {
const GLESBaseTexture *tex;
if (_show_overlay)
tex = _overlay_texture;
else
tex = _game_texture;
_eventScaleY = 100 * 480 / tex->height(); _eventScaleY = 100 * 480 / tex->height();
_eventScaleX = 100 * 640 / tex->width(); _eventScaleX = 100 * 640 / tex->width();
} }
@ -429,12 +391,10 @@ void OSystem_Android::pushEvent(int type, int arg1, int arg2, int arg3,
} }
scaleMouse(e.mouse, arg3 - _touch_pt_scroll.x, scaleMouse(e.mouse, arg3 - _touch_pt_scroll.x,
arg4 - _touch_pt_scroll.y, false, true); arg4 - _touch_pt_scroll.y, true);
e.mouse += _touch_pt_down; e.mouse += _touch_pt_down;
clipMouse(e.mouse);
} else { } else {
scaleMouse(e.mouse, arg3, arg4); scaleMouse(e.mouse, arg3, arg4);
clipMouse(e.mouse);
} }
pushEvent(e); pushEvent(e);
@ -462,7 +422,6 @@ void OSystem_Android::pushEvent(int type, int arg1, int arg2, int arg3,
e.mouse = getEventManager()->getMousePos(); e.mouse = getEventManager()->getMousePos();
} else { } else {
scaleMouse(e.mouse, arg1, arg2); scaleMouse(e.mouse, arg1, arg2);
clipMouse(e.mouse);
} }
{ {
@ -515,7 +474,6 @@ void OSystem_Android::pushEvent(int type, int arg1, int arg2, int arg3,
e.mouse = getEventManager()->getMousePos(); e.mouse = getEventManager()->getMousePos();
} else { } else {
scaleMouse(e.mouse, arg1, arg2); scaleMouse(e.mouse, arg1, arg2);
clipMouse(e.mouse);
} }
{ {
@ -542,10 +500,8 @@ void OSystem_Android::pushEvent(int type, int arg1, int arg2, int arg3,
if (_touchpad_mode) { if (_touchpad_mode) {
scaleMouse(e.mouse, arg1 - _touch_pt_dt.x, scaleMouse(e.mouse, arg1 - _touch_pt_dt.x,
arg2 - _touch_pt_dt.y, false, true); arg2 - _touch_pt_dt.y, true);
e.mouse += _touch_pt_down; e.mouse += _touch_pt_down;
clipMouse(e.mouse);
} }
break; break;
@ -653,9 +609,7 @@ void OSystem_Android::pushEvent(int type, int arg1, int arg2, int arg3,
case JE_MOUSE_MOVE: case JE_MOUSE_MOVE:
e.type = Common::EVENT_MOUSEMOVE; e.type = Common::EVENT_MOUSEMOVE;
scaleMouse(e.mouse, arg1, arg2); scaleMouse(e.mouse, arg1, arg2);
clipMouse(e.mouse);
pushEvent(e); pushEvent(e);
@ -663,9 +617,7 @@ void OSystem_Android::pushEvent(int type, int arg1, int arg2, int arg3,
case JE_LMB_DOWN: case JE_LMB_DOWN:
e.type = Common::EVENT_LBUTTONDOWN; e.type = Common::EVENT_LBUTTONDOWN;
scaleMouse(e.mouse, arg1, arg2); scaleMouse(e.mouse, arg1, arg2);
clipMouse(e.mouse);
pushEvent(e); pushEvent(e);
@ -673,9 +625,7 @@ void OSystem_Android::pushEvent(int type, int arg1, int arg2, int arg3,
case JE_LMB_UP: case JE_LMB_UP:
e.type = Common::EVENT_LBUTTONUP; e.type = Common::EVENT_LBUTTONUP;
scaleMouse(e.mouse, arg1, arg2); scaleMouse(e.mouse, arg1, arg2);
clipMouse(e.mouse);
pushEvent(e); pushEvent(e);
@ -683,9 +633,7 @@ void OSystem_Android::pushEvent(int type, int arg1, int arg2, int arg3,
case JE_RMB_DOWN: case JE_RMB_DOWN:
e.type = Common::EVENT_RBUTTONDOWN; e.type = Common::EVENT_RBUTTONDOWN;
scaleMouse(e.mouse, arg1, arg2); scaleMouse(e.mouse, arg1, arg2);
clipMouse(e.mouse);
pushEvent(e); pushEvent(e);
@ -693,9 +641,7 @@ void OSystem_Android::pushEvent(int type, int arg1, int arg2, int arg3,
case JE_RMB_UP: case JE_RMB_UP:
e.type = Common::EVENT_RBUTTONUP; e.type = Common::EVENT_RBUTTONUP;
scaleMouse(e.mouse, arg1, arg2); scaleMouse(e.mouse, arg1, arg2);
clipMouse(e.mouse);
pushEvent(e); pushEvent(e);
@ -732,29 +678,23 @@ bool OSystem_Android::pollEvent(Common::Event &event) {
if (pthread_self() == _main_thread) { if (pthread_self() == _main_thread) {
if (_screen_changeid != JNI::surface_changeid) { if (_screen_changeid != JNI::surface_changeid) {
_screen_changeid = JNI::surface_changeid;
if (JNI::egl_surface_width > 0 && JNI::egl_surface_height > 0) { if (JNI::egl_surface_width > 0 && JNI::egl_surface_height > 0) {
// surface changed // surface changed
JNI::deinitSurface(); dynamic_cast<AndroidGraphicsManager *>(_graphicsManager)->deinitSurface();
initSurface(); dynamic_cast<AndroidGraphicsManager *>(_graphicsManager)->initSurface();
initViewport(); _touchControls.init(JNI::egl_surface_width, JNI::egl_surface_height);
updateScreenRect();
updateEventScale();
// double buffered, flip twice
clearScreen(kClearUpdate, 2);
event.type = Common::EVENT_SCREEN_CHANGED; event.type = Common::EVENT_SCREEN_CHANGED;
return true; return true;
} else { } else {
// surface lost // surface lost
deinitSurface(); dynamic_cast<AndroidGraphicsManager *>(_graphicsManager)->deinitSurface();
} }
} }
if (JNI::pause) { if (JNI::pause) {
deinitSurface();
LOGD("main thread going to sleep"); LOGD("main thread going to sleep");
sem_wait(&JNI::pause_sem); sem_wait(&JNI::pause_sem);
LOGD("main thread woke up"); LOGD("main thread woke up");
@ -779,11 +719,17 @@ bool OSystem_Android::pollEvent(Common::Event &event) {
unlockMutex(_event_queue_lock); unlockMutex(_event_queue_lock);
if (event.type == Common::EVENT_MOUSEMOVE) { switch (event.type) {
const Common::Point &m = getEventManager()->getMousePos(); case Common::EVENT_MOUSEMOVE:
case Common::EVENT_LBUTTONDOWN:
if (m != event.mouse) case Common::EVENT_LBUTTONUP:
_force_redraw = true; case Common::EVENT_RBUTTONDOWN:
case Common::EVENT_RBUTTONUP:
if (_graphicsManager)
return dynamic_cast<AndroidGraphicsManager *>(_graphicsManager)->notifyMousePosition(event.mouse);
break;
default:
break;
} }
return true; return true;

View file

@ -0,0 +1,168 @@
/* ResidualVM - Graphic Adventure Engine
*
* ResidualVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#ifndef ANDROID_GRAPHICS_H
#define ANDROID_GRAPHICS_H
#include "common/scummsys.h"
#include "backends/graphics/resvm-graphics.h"
class AndroidGraphicsManager : public ResVmGraphicsManager {
public:
AndroidGraphicsManager();
virtual ~AndroidGraphicsManager();
void initSurface();
void deinitSurface();
void updateScreen() override;
void displayMessageOnOSD(const char *msg);
bool notifyMousePosition(Common::Point &mouse);
Common::Point getMousePosition() { return Common::Point(_cursorX, _cursorY); }
void setMousePosition(int x, int y) { _cursorX = x; _cursorY = y; }
virtual const OSystem::GraphicsMode *getSupportedGraphicsModes() const override;
virtual int getDefaultGraphicsMode() const override;
virtual bool setGraphicsMode(int mode) override;
virtual void resetGraphicsScale() override;
virtual int getGraphicsMode() const override;
virtual bool hasFeature(OSystem::Feature f) const override;
virtual void setFeatureState(OSystem::Feature f, bool enable) override;
virtual bool getFeatureState(OSystem::Feature f) const override;
virtual void showOverlay() override;
virtual void hideOverlay() override;
virtual void clearOverlay() override;
virtual void grabOverlay(void *buf, int pitch) const override;
virtual void copyRectToOverlay(const void *buf, int pitch,
int x, int y, int w, int h) override;
virtual int16 getOverlayHeight() const override;
virtual int16 getOverlayWidth() const override;
virtual Graphics::PixelFormat getOverlayFormat() const override;
virtual int16 getHeight() const override;
virtual int16 getWidth() const override;
// PaletteManager API
virtual void setPalette(const byte *colors, uint start, uint num) override;
virtual void grabPalette(byte *colors, uint start, uint num) const override;
virtual void copyRectToScreen(const void *buf, int pitch, int x, int y,
int w, int h) override;
virtual Graphics::Surface *lockScreen() override;
virtual void unlockScreen() override;
virtual void fillScreen(uint32 col);
virtual void initSize(uint width, uint height,
const Graphics::PixelFormat *format) override;
virtual int getScreenChangeID() const override;
virtual bool showMouse(bool visible) override;
virtual void warpMouse(int x, int y) override;
virtual bool lockMouse(bool lock) override;
virtual void setMouseCursor(const void *buf, uint w, uint h, int hotspotX,
int hotspotY, uint32 keycolor,
bool dontScale,
const Graphics::PixelFormat *format) override;
virtual void setCursorPalette(const byte *colors, uint start, uint num) override;
void setupScreen(uint screenW, uint screenH, bool fullscreen, bool accel3d) override;
// ResidualVM specific method
void setupScreen(uint screenW, uint screenH, bool fullscreen, bool accel3d, bool isGame);
virtual Graphics::PixelBuffer getScreenPixelBuffer() override;
virtual void suggestSideTextures(Graphics::Surface *left, Graphics::Surface *right) override;
void updateScreenRect();
const GLESBaseTexture *getActiveTexture() const;
void clipMouse(Common::Point &p) const;
#ifdef USE_RGB_COLOR
virtual Graphics::PixelFormat getScreenFormat() const override;
virtual Common::List<Graphics::PixelFormat> getSupportedFormats() const override;
#endif
protected:
void setSystemMousePosition(int x, int y) {}
bool loadVideoMode(uint requestedWidth, uint requestedHeight, const Graphics::PixelFormat &format);
void refreshScreen();
void *getProcAddress(const char *name) const;
// ResidualVM specific code
private:
void setCursorPaletteInternal(const byte *colors, uint start, uint num);
void disableCursorPalette();
void initOverlay();
void initViewport();
void updateEventScale();
enum FixupType {
kClear = 0, // glClear
kClearSwap, // glClear + swapBuffers
kClearUpdate // glClear + updateScreen
};
void clearScreen(FixupType type, byte count = 1);
#ifdef USE_RGB_COLOR
void initTexture(GLESBaseTexture **texture, uint width, uint height,
const Graphics::PixelFormat *format);
#endif
private:
int _screenChangeID;
int _graphicsMode;
bool _opengl;
bool _fullscreen;
bool _ar_correction;
bool _force_redraw;
// Game layer
GLESBaseTexture *_game_texture;
Graphics::PixelBuffer _game_pbuf;
OpenGL::FrameBuffer *_frame_buffer;
/**
* The position of the mouse cursor, in window coordinates.
*/
int _cursorX, _cursorY;
// Overlay layer
GLES4444Texture *_overlay_texture;
bool _show_overlay;
// Mouse layer
GLESBaseTexture *_mouse_texture;
GLESBaseTexture *_mouse_texture_palette;
GLES5551Texture *_mouse_texture_rgb;
Common::Point _mouse_hotspot;
uint32 _mouse_keycolor;
int _mouse_targetscale;
bool _show_mouse;
bool _use_mouse_palette;
};
#endif

View file

@ -5,7 +5,7 @@ MODULE_OBJS := \
texture.o \ texture.o \
asset-archive.o \ asset-archive.o \
android.o \ android.o \
gfx.o \ graphics.o \
events.o \ events.o \
snprintf.o \ snprintf.o \
touchcontrols.o touchcontrols.o

View file

@ -58,11 +58,6 @@ static bool npot_supported = false;
OpenGL::Shader * g_box_shader; OpenGL::Shader * g_box_shader;
GLuint g_verticesVBO; GLuint g_verticesVBO;
static inline GLfixed xdiv(int numerator, int denominator) {
assert(numerator < (1 << 16));
return (numerator << 16) / denominator;
}
template<class T> template<class T>
static T nextHigher2(T k) { static T nextHigher2(T k) {
if (k == 0) if (k == 0)