diff options
Diffstat (limited to 'backends/platform')
-rw-r--r-- | backends/platform/android/android.cpp | 3 | ||||
-rw-r--r-- | backends/platform/android/android.h | 1 | ||||
-rw-r--r-- | backends/platform/android/android.mk | 8 | ||||
-rw-r--r-- | backends/platform/android/events.cpp | 111 | ||||
-rw-r--r-- | backends/platform/android/org/scummvm/scummvm/MouseHelper.java | 18 | ||||
-rw-r--r-- | backends/platform/android/org/scummvm/scummvm/ScummVMActivity.java | 8 | ||||
-rw-r--r-- | backends/platform/android/org/scummvm/scummvm/ScummVMEvents.java | 36 | ||||
-rw-r--r-- | backends/platform/gph/gph-backend.cpp | 2 | ||||
-rw-r--r-- | backends/platform/openpandora/op-backend.cpp | 2 | ||||
-rw-r--r-- | backends/platform/sdl/sdl.cpp | 297 | ||||
-rw-r--r-- | backends/platform/sdl/sdl.h | 15 | ||||
-rw-r--r-- | backends/platform/tizen/graphics.cpp | 106 | ||||
-rw-r--r-- | backends/platform/tizen/graphics.h | 21 | ||||
-rw-r--r-- | backends/platform/tizen/system.cpp | 2 | ||||
-rw-r--r-- | backends/platform/wince/wince-sdl.cpp | 5 |
15 files changed, 402 insertions, 233 deletions
diff --git a/backends/platform/android/android.cpp b/backends/platform/android/android.cpp index ad80ea7f8c..5e3d1d0db6 100644 --- a/backends/platform/android/android.cpp +++ b/backends/platform/android/android.cpp @@ -146,7 +146,8 @@ OSystem_Android::OSystem_Android(int audio_sample_rate, int audio_buffer_size) : _touchpad_scale(66), _dpad_scale(4), _fingersDown(0), - _trackball_scale(2) { + _trackball_scale(2), + _joystick_scale(10) { _fsFactory = new POSIXFilesystemFactory(); diff --git a/backends/platform/android/android.h b/backends/platform/android/android.h index b4813b3bdf..704ce12f60 100644 --- a/backends/platform/android/android.h +++ b/backends/platform/android/android.h @@ -231,6 +231,7 @@ private: int _touchpad_scale; int _trackball_scale; int _dpad_scale; + int _joystick_scale; int _fingersDown; void clipMouse(Common::Point &p); diff --git a/backends/platform/android/android.mk b/backends/platform/android/android.mk index f498c671de..915bf8ac60 100644 --- a/backends/platform/android/android.mk +++ b/backends/platform/android/android.mk @@ -25,13 +25,19 @@ PATH_RESOURCES = $(PATH_DIST)/res PORT_DISTFILES = $(PATH_DIST)/README.Android +# FIXME: OUYA specific. +# "values-television" not present in vanilla Android. +# $(PATH_RESOURCES)/../res-ouya/values-television/margins.xml \ + RESOURCES = \ $(PATH_RESOURCES)/values/strings.xml \ + $(PATH_RESOURCES)/values/margins.xml \ $(PATH_RESOURCES)/layout/main.xml \ $(PATH_RESOURCES)/layout/splash.xml \ $(PATH_RESOURCES)/drawable/gradient.xml \ $(PATH_RESOURCES)/drawable/scummvm.png \ - $(PATH_RESOURCES)/drawable/scummvm_big.png + $(PATH_RESOURCES)/drawable/scummvm_big.png \ + $(PATH_RESOURCES)/drawable-xhdpi/ouya_icon.png PLUGIN_RESOURCES = \ $(PATH_RESOURCES)/values/strings.xml \ diff --git a/backends/platform/android/events.cpp b/backends/platform/android/events.cpp index db1261e432..5c42db9347 100644 --- a/backends/platform/android/events.cpp +++ b/backends/platform/android/events.cpp @@ -64,6 +64,10 @@ enum { JE_RMB_DOWN = 11, JE_RMB_UP = 12, JE_MOUSE_MOVE = 13, + JE_GAMEPAD = 14, + JE_JOYSTICK = 15, + JE_MMB_DOWN = 16, + JE_MMB_UP = 17, JE_QUIT = 0x1000 }; @@ -109,6 +113,25 @@ enum { JKEYCODE_DPAD_CENTER = 23 }; +// gamepad +enum { + JKEYCODE_BUTTON_A = 96, + JKEYCODE_BUTTON_B = 97, + JKEYCODE_BUTTON_C = 98, + JKEYCODE_BUTTON_X = 99, + JKEYCODE_BUTTON_Y = 100, + JKEYCODE_BUTTON_Z = 101, + JKEYCODE_BUTTON_L1 = 102, + JKEYCODE_BUTTON_R1 = 103, + JKEYCODE_BUTTON_L2 = 104, + JKEYCODE_BUTTON_R2 = 105, + JKEYCODE_BUTTON_THUMBL = 106, + JKEYCODE_BUTTON_THUMBR = 107, + JKEYCODE_BUTTON_START = 108, + JKEYCODE_BUTTON_SELECT = 109, + JKEYCODE_BUTTON_MODE = 110, +}; + // meta modifier enum { JMETA_SHIFT = 0x01, @@ -827,6 +850,94 @@ void OSystem_Android::pushEvent(int type, int arg1, int arg2, int arg3, return; + case JE_GAMEPAD: + switch (arg1) { + case JACTION_DOWN: + e.type = Common::EVENT_KEYDOWN; + break; + case JACTION_UP: + e.type = Common::EVENT_KEYUP; + break; + default: + LOGE("unhandled jaction on gamepad key: %d", arg1); + return; + } + + switch (arg2) { + case JKEYCODE_BUTTON_A: + case JKEYCODE_BUTTON_B: + switch (arg1) { + case JACTION_DOWN: + e.type = (arg2 == JKEYCODE_BUTTON_A? + Common::EVENT_LBUTTONDOWN : + Common::EVENT_RBUTTONDOWN); + break; + case JACTION_UP: + e.type = (arg2 == JKEYCODE_BUTTON_A? + Common::EVENT_LBUTTONUP : + Common::EVENT_RBUTTONUP); + break; + } + + e.mouse = getEventManager()->getMousePos(); + + break; + + case JKEYCODE_BUTTON_X: + e.kbd.keycode = Common::KEYCODE_ESCAPE; + e.kbd.ascii = Common::ASCII_ESCAPE; + break; + + default: + LOGW("unmapped gamepad key: %d", arg2); + return; + } + + lockMutex(_event_queue_lock); + _event_queue.push(e); + unlockMutex(_event_queue_lock); + + break; + + case JE_JOYSTICK: + e.mouse = getEventManager()->getMousePos(); + + switch (arg1) { + case JACTION_MULTIPLE: + e.type = Common::EVENT_MOUSEMOVE; + + // already multiplied by 100 + e.mouse.x += arg2 * _joystick_scale / _eventScaleX; + e.mouse.y += arg3 * _joystick_scale / _eventScaleY; + + clipMouse(e.mouse); + + break; + default: + LOGE("unhandled jaction on joystick: %d", arg1); + return; + } + + lockMutex(_event_queue_lock); + _event_queue.push(e); + unlockMutex(_event_queue_lock); + + return; + + case JE_MMB_DOWN: + e.type = Common::EVENT_MAINMENU; + + lockMutex(_event_queue_lock); + _event_queue.push(e); + unlockMutex(_event_queue_lock); + + return; + + case JE_MMB_UP: + // No action + + return; + case JE_QUIT: e.type = Common::EVENT_QUIT; diff --git a/backends/platform/android/org/scummvm/scummvm/MouseHelper.java b/backends/platform/android/org/scummvm/scummvm/MouseHelper.java index 999815593f..8990515b84 100644 --- a/backends/platform/android/org/scummvm/scummvm/MouseHelper.java +++ b/backends/platform/android/org/scummvm/scummvm/MouseHelper.java @@ -14,6 +14,7 @@ public class MouseHelper { private long _rmbGuardTime; private boolean _rmbPressed; private boolean _lmbPressed; + private boolean _mmbPressed; /** * Class initialization fails when this throws an exception. @@ -114,6 +115,23 @@ public class MouseHelper { _rmbPressed = false; } + boolean mmbDown = (buttonState & MotionEvent.BUTTON_TERTIARY) == MotionEvent.BUTTON_TERTIARY; + if (mmbDown) { + if (!_mmbPressed) { + // middle mouse button was pressed just now + _scummvm.pushEvent(ScummVMEvents.JE_MMB_DOWN, (int)e.getX(), (int)e.getY(), e.getButtonState(), 0, 0); + } + + _mmbPressed = true; + } else { + if (_mmbPressed) { + // middle mouse button was released just now + _scummvm.pushEvent(ScummVMEvents.JE_MMB_UP, (int)e.getX(), (int)e.getY(), e.getButtonState(), 0, 0); + } + + _mmbPressed = false; + } + return true; } diff --git a/backends/platform/android/org/scummvm/scummvm/ScummVMActivity.java b/backends/platform/android/org/scummvm/scummvm/ScummVMActivity.java index 829a948435..5d041dafd2 100644 --- a/backends/platform/android/org/scummvm/scummvm/ScummVMActivity.java +++ b/backends/platform/android/org/scummvm/scummvm/ScummVMActivity.java @@ -240,6 +240,14 @@ public class ScummVMActivity extends Activity { return false; } + @Override + public boolean onGenericMotionEvent(final MotionEvent e) { + if (_events != null) + return _events.onGenericMotionEvent(e); + + return false; + } + private void showKeyboard(boolean show) { SurfaceView main_surface = (SurfaceView)findViewById(R.id.main_surface); InputMethodManager imm = (InputMethodManager) diff --git a/backends/platform/android/org/scummvm/scummvm/ScummVMEvents.java b/backends/platform/android/org/scummvm/scummvm/ScummVMEvents.java index 5f51ffac6c..702215341b 100644 --- a/backends/platform/android/org/scummvm/scummvm/ScummVMEvents.java +++ b/backends/platform/android/org/scummvm/scummvm/ScummVMEvents.java @@ -9,6 +9,7 @@ import android.view.MotionEvent; import android.view.View; import android.view.ViewConfiguration; import android.view.GestureDetector; +import android.view.InputDevice; import android.view.inputmethod.InputMethodManager; public class ScummVMEvents implements @@ -31,6 +32,10 @@ public class ScummVMEvents implements public static final int JE_RMB_DOWN = 11; public static final int JE_RMB_UP = 12; public static final int JE_MOUSE_MOVE = 13; + public static final int JE_GAMEPAD = 14; + public static final int JE_JOYSTICK = 15; + public static final int JE_MMB_DOWN = 16; + public static final int JE_MMB_UP = 17; public static final int JE_QUIT = 0x1000; final protected Context _context; @@ -63,6 +68,18 @@ public class ScummVMEvents implements return true; } + public boolean onGenericMotionEvent(final MotionEvent e) { + if((e.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) { + _scummvm.pushEvent(JE_JOYSTICK, e.getAction(), + (int)(e.getAxisValue(MotionEvent.AXIS_X)*100), + (int)(e.getAxisValue(MotionEvent.AXIS_Y)*100), + 0, 0); + return true; + } + + return false; + } + final static int MSG_MENU_LONG_PRESS = 1; final private Handler keyHandler = new Handler() { @@ -177,6 +194,25 @@ public class ScummVMEvents implements (int)(e.getEventTime() - e.getDownTime()), e.getRepeatCount(), 0); return true; + case KeyEvent.KEYCODE_BUTTON_A: + case KeyEvent.KEYCODE_BUTTON_B: + case KeyEvent.KEYCODE_BUTTON_C: + case KeyEvent.KEYCODE_BUTTON_X: + case KeyEvent.KEYCODE_BUTTON_Y: + case KeyEvent.KEYCODE_BUTTON_Z: + case KeyEvent.KEYCODE_BUTTON_L1: + case KeyEvent.KEYCODE_BUTTON_R1: + case KeyEvent.KEYCODE_BUTTON_L2: + case KeyEvent.KEYCODE_BUTTON_R2: + case KeyEvent.KEYCODE_BUTTON_THUMBL: + case KeyEvent.KEYCODE_BUTTON_THUMBR: + case KeyEvent.KEYCODE_BUTTON_START: + case KeyEvent.KEYCODE_BUTTON_SELECT: + case KeyEvent.KEYCODE_BUTTON_MODE: + _scummvm.pushEvent(JE_GAMEPAD, action, keyCode, + (int)(e.getEventTime() - e.getDownTime()), + e.getRepeatCount(), 0); + return true; } _scummvm.pushEvent(JE_KEY, action, keyCode, diff --git a/backends/platform/gph/gph-backend.cpp b/backends/platform/gph/gph-backend.cpp index 485780b472..e51d7d0781 100644 --- a/backends/platform/gph/gph-backend.cpp +++ b/backends/platform/gph/gph-backend.cpp @@ -172,7 +172,7 @@ void OSystem_GPH::initSDL() { // Check if SDL has not been initialized if (!_initedSDL) { - uint32 sdlFlags = SDL_INIT_EVENTTHREAD; + uint32 sdlFlags = SDL_INIT_EVENTTHREAD | SDL_INIT_VIDEO; if (ConfMan.hasKey("disable_sdl_parachute")) sdlFlags |= SDL_INIT_NOPARACHUTE; diff --git a/backends/platform/openpandora/op-backend.cpp b/backends/platform/openpandora/op-backend.cpp index 354aa24b24..60c3cc7191 100644 --- a/backends/platform/openpandora/op-backend.cpp +++ b/backends/platform/openpandora/op-backend.cpp @@ -160,7 +160,7 @@ void OSystem_OP::initSDL() { // Check if SDL has not been initialized if (!_initedSDL) { - uint32 sdlFlags = SDL_INIT_EVENTTHREAD; + uint32 sdlFlags = SDL_INIT_EVENTTHREAD | SDL_INIT_VIDEO; if (ConfMan.hasKey("disable_sdl_parachute")) sdlFlags |= SDL_INIT_NOPARACHUTE; diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp index 7ab367d4a4..bc80d8ad6a 100644 --- a/backends/platform/sdl/sdl.cpp +++ b/backends/platform/sdl/sdl.cpp @@ -65,10 +65,13 @@ OSystem_SDL::OSystem_SDL() : #ifdef USE_OPENGL - _graphicsModes(0), + _desktopWidth(0), + _desktopHeight(0), + _graphicsModes(), _graphicsMode(0), - _sdlModesCount(0), - _glModesCount(0), + _firstGLMode(0), + _defaultSDLMode(0), + _defaultGLMode(0), #endif _inited(false), _initedSDL(false), @@ -87,6 +90,9 @@ OSystem_SDL::~OSystem_SDL() { // Hence, we perform the destruction on our own. delete _savefileManager; _savefileManager = 0; + if (_graphicsManager) { + _graphicsManager->deactivateManager(); + } delete _graphicsManager; _graphicsManager = 0; delete _eventManager; @@ -110,10 +116,6 @@ OSystem_SDL::~OSystem_SDL() { delete _mutexManager; _mutexManager = 0; -#ifdef USE_OPENGL - delete[] _graphicsModes; -#endif - delete _logger; _logger = 0; @@ -124,6 +126,12 @@ void OSystem_SDL::init() { // Initialize SDL initSDL(); + // Enable unicode support if possible + SDL_EnableUNICODE(1); + + // Disable OS cursor + SDL_ShowCursor(SDL_DISABLE); + if (!_logger) _logger = new Backends::Log::Log(this); @@ -144,10 +152,6 @@ void OSystem_SDL::init() { _taskbarManager = new Common::TaskbarManager(); #endif -#ifdef USE_OPENGL - // Setup a list with both SDL and OpenGL graphics modes - setupGraphicsModes(); -#endif } void OSystem_SDL::initBackend() { @@ -159,35 +163,41 @@ void OSystem_SDL::initBackend() { if (_eventSource == 0) _eventSource = new SdlEventSource(); - int graphicsManagerType = 0; +#ifdef USE_OPENGL + // Query the desktop resolution. We simply hope nothing tried to change + // the resolution so far. + const SDL_VideoInfo *videoInfo = SDL_GetVideoInfo(); + if (videoInfo && videoInfo->current_w > 0 && videoInfo->current_h > 0) { + _desktopWidth = videoInfo->current_w; + _desktopHeight = videoInfo->current_h; + } +#endif if (_graphicsManager == 0) { #ifdef USE_OPENGL + // Setup a list with both SDL and OpenGL graphics modes. We only do + // this whenever the subclass did not already set up an graphics + // manager yet. This is because we don't know the type of the graphics + // manager of the subclass, thus we cannot easily switch between the + // OpenGL one and the set up one. It also is to be expected that the + // subclass does not want any switching of graphics managers anyway. + setupGraphicsModes(); + if (ConfMan.hasKey("gfx_mode")) { + // If the gfx_mode is from OpenGL, create the OpenGL graphics manager Common::String gfxMode(ConfMan.get("gfx_mode")); - bool use_opengl = false; - const OSystem::GraphicsMode *mode = OpenGLSdlGraphicsManager::supportedGraphicsModes(); - int i = 0; - while (mode->name) { - if (scumm_stricmp(mode->name, gfxMode.c_str()) == 0) { - _graphicsMode = i + _sdlModesCount; - use_opengl = true; + for (uint i = _firstGLMode; i < _graphicsModeIds.size(); ++i) { + if (!scumm_stricmp(_graphicsModes[i].name, gfxMode.c_str())) { + _graphicsManager = new OpenGLSdlGraphicsManager(_desktopWidth, _desktopHeight, _eventSource); + _graphicsMode = i; + break; } - - mode++; - ++i; - } - - // If the gfx_mode is from OpenGL, create the OpenGL graphics manager - if (use_opengl) { - _graphicsManager = new OpenGLSdlGraphicsManager(_eventSource); - graphicsManagerType = 1; } } #endif + if (_graphicsManager == 0) { _graphicsManager = new SurfaceSdlGraphicsManager(_eventSource); - graphicsManagerType = 0; } } @@ -230,13 +240,7 @@ void OSystem_SDL::initBackend() { // so the virtual keyboard can be initialized, but we have to add the // graphics manager as an event observer after initializing the event // manager. - if (graphicsManagerType == 0) - ((SurfaceSdlGraphicsManager *)_graphicsManager)->initEventObserver(); -#ifdef USE_OPENGL - else if (graphicsManagerType == 1) - ((OpenGLSdlGraphicsManager *)_graphicsManager)->initEventObserver(); -#endif - + _graphicsManager->activateManager(); } #if defined(USE_TASKBAR) @@ -257,22 +261,19 @@ void OSystem_SDL::engineDone() { void OSystem_SDL::initSDL() { // Check if SDL has not been initialized if (!_initedSDL) { - uint32 sdlFlags = 0; + // We always initialize the video subsystem because we will need it to + // be initialized before the graphics managers to retrieve the desktop + // resolution, for example. WebOS also requires this initialization + // or otherwise the application won't start. + uint32 sdlFlags = SDL_INIT_VIDEO; + if (ConfMan.hasKey("disable_sdl_parachute")) sdlFlags |= SDL_INIT_NOPARACHUTE; -#ifdef WEBOS - // WebOS needs this flag or otherwise the application won't start - sdlFlags |= SDL_INIT_VIDEO; -#endif - // Initialize SDL (SDL Subsystems are initiliazed in the corresponding sdl managers) if (SDL_Init(sdlFlags) == -1) error("Could not initialize SDL: %s", SDL_GetError()); - // Enable unicode support if possible - SDL_EnableUNICODE(1); - _initedSDL = true; } } @@ -391,10 +392,15 @@ Common::String OSystem_SDL::getSystemLanguage() const { } #else // WIN32 // Activating current locale settings - const char *locale = setlocale(LC_ALL, ""); + const Common::String locale = setlocale(LC_ALL, ""); + + // Restore default C locale to prevent issues with + // portability of sscanf(), atof(), etc. + // See bug #3615148 + setlocale(LC_ALL, "C"); // Detect the language from the locale - if (!locale) { + if (locale.empty()) { return ModularBackend::getSystemLanguage(); } else { int length = 0; @@ -403,14 +409,14 @@ Common::String OSystem_SDL::getSystemLanguage() const { // ".UTF-8" or the like. We do this, since // our translation languages are usually // specified without any charset information. - for (int i = 0; locale[i]; ++i, ++length) { + for (int size = locale.size(); length < size; ++length) { // TODO: Check whether "@" should really be checked // here. - if (locale[i] == '.' || locale[i] == ' ' || locale[i] == '@') + if (locale[length] == '.' || locale[length] == ' ' || locale[length] == '@') break; } - return Common::String(locale, length); + return Common::String(locale.c_str(), length); } #endif // WIN32 #else // USE_DETECTLANG @@ -535,28 +541,33 @@ Common::TimerManager *OSystem_SDL::getTimerManager() { #ifdef USE_OPENGL const OSystem::GraphicsMode *OSystem_SDL::getSupportedGraphicsModes() const { - return _graphicsModes; + if (_graphicsModes.empty()) { + return _graphicsManager->getSupportedGraphicsModes(); + } else { + return _graphicsModes.begin(); + } } int OSystem_SDL::getDefaultGraphicsMode() const { - // Return the default graphics mode from the current graphics manager - if (_graphicsMode < _sdlModesCount) + if (_graphicsModes.empty()) { return _graphicsManager->getDefaultGraphicsMode(); - else - return _graphicsManager->getDefaultGraphicsMode() + _sdlModesCount; + } else { + // Return the default graphics mode from the current graphics manager + if (_graphicsMode < _firstGLMode) + return _defaultSDLMode; + else + return _defaultGLMode; + } } bool OSystem_SDL::setGraphicsMode(int mode) { - const OSystem::GraphicsMode *srcMode; - int i; + if (_graphicsModes.empty()) { + return _graphicsManager->setGraphicsMode(mode); + } - // Check if mode is from SDL or OpenGL - if (mode < _sdlModesCount) { - srcMode = SurfaceSdlGraphicsManager::supportedGraphicsModes(); - i = 0; - } else { - srcMode = OpenGLSdlGraphicsManager::supportedGraphicsModes(); - i = _sdlModesCount; + // Check whether a invalid mode is requested. + if (mode < 0 || (uint)mode >= _graphicsModeIds.size()) { + return false; } // Very hacky way to set up the old graphics manager state, in case we @@ -575,113 +586,121 @@ bool OSystem_SDL::setGraphicsMode(int mode) { bool switchedManager = false; - // Loop through modes - while (srcMode->name) { - if (i == mode) { - // If the new mode and the current mode are not from the same graphics - // manager, delete and create the new mode graphics manager - if (_graphicsMode >= _sdlModesCount && mode < _sdlModesCount) { - debug(1, "switching to plain SDL graphics"); - delete _graphicsManager; - _graphicsManager = new SurfaceSdlGraphicsManager(_eventSource); - ((SurfaceSdlGraphicsManager *)_graphicsManager)->initEventObserver(); - _graphicsManager->beginGFXTransaction(); - - switchedManager = true; - } else if (_graphicsMode < _sdlModesCount && mode >= _sdlModesCount) { - debug(1, "switching to OpenGL graphics"); - delete _graphicsManager; - _graphicsManager = new OpenGLSdlGraphicsManager(_eventSource); - ((OpenGLSdlGraphicsManager *)_graphicsManager)->initEventObserver(); - _graphicsManager->beginGFXTransaction(); - - switchedManager = true; - } + // If the new mode and the current mode are not from the same graphics + // manager, delete and create the new mode graphics manager + if (_graphicsMode >= _firstGLMode && mode < _firstGLMode) { + debug(1, "switching to plain SDL graphics"); + _graphicsManager->deactivateManager(); + delete _graphicsManager; + _graphicsManager = new SurfaceSdlGraphicsManager(_eventSource); + + switchedManager = true; + } else if (_graphicsMode < _firstGLMode && mode >= _firstGLMode) { + debug(1, "switching to OpenGL graphics"); + _graphicsManager->deactivateManager(); + delete _graphicsManager; + _graphicsManager = new OpenGLSdlGraphicsManager(_desktopWidth, _desktopHeight, _eventSource); + + switchedManager = true; + } + + _graphicsMode = mode; - _graphicsMode = mode; + if (switchedManager) { + _graphicsManager->activateManager(); - if (switchedManager) { + _graphicsManager->beginGFXTransaction(); #ifdef USE_RGB_COLOR - _graphicsManager->initSize(screenWidth, screenHeight, &pixelFormat); + _graphicsManager->initSize(screenWidth, screenHeight, &pixelFormat); #else - _graphicsManager->initSize(screenWidth, screenHeight, 0); + _graphicsManager->initSize(screenWidth, screenHeight, 0); #endif - _graphicsManager->setFeatureState(kFeatureAspectRatioCorrection, arState); - _graphicsManager->setFeatureState(kFeatureFullscreenMode, fullscreen); - _graphicsManager->setFeatureState(kFeatureCursorPalette, cursorPalette); + _graphicsManager->setFeatureState(kFeatureAspectRatioCorrection, arState); + _graphicsManager->setFeatureState(kFeatureFullscreenMode, fullscreen); + _graphicsManager->setFeatureState(kFeatureCursorPalette, cursorPalette); - // Worst part about this right now, tell the cursor manager to - // resetup the cursor + cursor palette if necessarily - - // First we need to try to setup the old state on the new manager... - if (_graphicsManager->endGFXTransaction() != kTransactionSuccess) { - // Oh my god if this failed the client code might just explode. - return false; - } + // Worst part about this right now, tell the cursor manager to + // resetup the cursor + cursor palette if necessarily - // Next setup the cursor again - CursorMan.pushCursor(0, 0, 0, 0, 0, 0); - CursorMan.popCursor(); + // First we need to try to setup the old state on the new manager... + if (_graphicsManager->endGFXTransaction() != kTransactionSuccess) { + // Oh my god if this failed the client code might just explode. + return false; + } - // Next setup cursor palette if needed - if (cursorPalette) { - CursorMan.pushCursorPalette(0, 0, 0); - CursorMan.popCursorPalette(); - } + // Next setup the cursor again + CursorMan.pushCursor(0, 0, 0, 0, 0, 0); + CursorMan.popCursor(); - _graphicsManager->beginGFXTransaction(); - // Oh my god if this failed the client code might just explode. - return _graphicsManager->setGraphicsMode(srcMode->id); - } else { - return _graphicsManager->setGraphicsMode(srcMode->id); - } + // Next setup cursor palette if needed + if (cursorPalette) { + CursorMan.pushCursorPalette(0, 0, 0); + CursorMan.popCursorPalette(); } - i++; - srcMode++; + _graphicsManager->beginGFXTransaction(); + // Oh my god if this failed the client code might just explode. + return _graphicsManager->setGraphicsMode(_graphicsModeIds[mode]); + } else { + return _graphicsManager->setGraphicsMode(_graphicsModeIds[mode]); } - - return false; } int OSystem_SDL::getGraphicsMode() const { - return _graphicsMode; + if (_graphicsModes.empty()) { + return _graphicsManager->getGraphicsMode(); + } else { + return _graphicsMode; + } } void OSystem_SDL::setupGraphicsModes() { - const OSystem::GraphicsMode *sdlGraphicsModes = SurfaceSdlGraphicsManager::supportedGraphicsModes(); - const OSystem::GraphicsMode *openglGraphicsModes = OpenGLSdlGraphicsManager::supportedGraphicsModes(); - _sdlModesCount = 0; - _glModesCount = 0; + _graphicsModes.clear(); + _graphicsModeIds.clear(); + _defaultSDLMode = _defaultGLMode = -1; // Count the number of graphics modes - const OSystem::GraphicsMode *srcMode = sdlGraphicsModes; + const OSystem::GraphicsMode *srcMode; + int defaultMode; + + GraphicsManager *manager = new SurfaceSdlGraphicsManager(_eventSource); + srcMode = manager->getSupportedGraphicsModes(); + defaultMode = manager->getDefaultGraphicsMode(); while (srcMode->name) { - _sdlModesCount++; + if (defaultMode == srcMode->id) { + _defaultSDLMode = _graphicsModes.size(); + } + _graphicsModes.push_back(*srcMode); srcMode++; } - srcMode = openglGraphicsModes; + delete manager; + assert(_defaultSDLMode != -1); + + _firstGLMode = _graphicsModes.size(); + manager = new OpenGLSdlGraphicsManager(_desktopWidth, _desktopHeight, _eventSource); + srcMode = manager->getSupportedGraphicsModes(); + defaultMode = manager->getDefaultGraphicsMode(); while (srcMode->name) { - _glModesCount++; + if (defaultMode == srcMode->id) { + _defaultGLMode = _graphicsModes.size(); + } + _graphicsModes.push_back(*srcMode); srcMode++; } - - // Allocate enough space for merged array of modes - _graphicsModes = new OSystem::GraphicsMode[_glModesCount + _sdlModesCount + 1]; - - // Copy SDL graphics modes - memcpy((void *)_graphicsModes, sdlGraphicsModes, _sdlModesCount * sizeof(OSystem::GraphicsMode)); - - // Copy OpenGL graphics modes - memcpy((void *)(_graphicsModes + _sdlModesCount), openglGraphicsModes, _glModesCount * sizeof(OSystem::GraphicsMode)); + delete manager; + manager = nullptr; + assert(_defaultGLMode != -1); // Set a null mode at the end - memset((void *)(_graphicsModes + _sdlModesCount + _glModesCount), 0, sizeof(OSystem::GraphicsMode)); + GraphicsMode nullMode; + memset(&nullMode, 0, sizeof(nullMode)); + _graphicsModes.push_back(nullMode); // Set new internal ids for all modes int i = 0; - OSystem::GraphicsMode *mode = _graphicsModes; + OSystem::GraphicsMode *mode = _graphicsModes.begin(); while (mode->name) { + _graphicsModeIds.push_back(mode->id); mode->id = i++; mode++; } diff --git a/backends/platform/sdl/sdl.h b/backends/platform/sdl/sdl.h index 840e73ff09..814cdd7c1b 100644 --- a/backends/platform/sdl/sdl.h +++ b/backends/platform/sdl/sdl.h @@ -30,6 +30,8 @@ #include "backends/events/sdl/sdl-events.h" #include "backends/log/log.h" +#include "common/array.h" + /** * Base OSystem class for all SDL ports. */ @@ -106,15 +108,20 @@ protected: Backends::Log::Log *_logger; #ifdef USE_OPENGL - OSystem::GraphicsMode *_graphicsModes; + int _desktopWidth, _desktopHeight; + + typedef Common::Array<GraphicsMode> GraphicsModeArray; + GraphicsModeArray _graphicsModes; + Common::Array<int> _graphicsModeIds; int _graphicsMode; - int _sdlModesCount; - int _glModesCount; + int _firstGLMode; + int _defaultSDLMode; + int _defaultGLMode; /** * Creates the merged graphics modes list */ - virtual void setupGraphicsModes(); + void setupGraphicsModes(); virtual const OSystem::GraphicsMode *getSupportedGraphicsModes() const; virtual int getDefaultGraphicsMode() const; diff --git a/backends/platform/tizen/graphics.cpp b/backends/platform/tizen/graphics.cpp index 2cafb9f781..390796dc0e 100644 --- a/backends/platform/tizen/graphics.cpp +++ b/backends/platform/tizen/graphics.cpp @@ -37,7 +37,6 @@ TizenGraphicsManager::TizenGraphicsManager(TizenAppForm *appForm) : _eglContext(EGL_NO_CONTEXT), _initState(true) { assert(appForm != NULL); - _videoMode.fullscreen = true; } TizenGraphicsManager::~TizenGraphicsManager() { @@ -51,17 +50,34 @@ TizenGraphicsManager::~TizenGraphicsManager() { } } +result TizenGraphicsManager::Construct() { + // Initialize our OpenGL ES context. + loadEgl(); + + // Notify the OpenGL code about our context. + + // We default to RGB565 and RGBA5551 which is closest to the actual output + // mode we setup. + notifyContextChange(Graphics::PixelFormat(2, 5, 6, 5, 0, 11, 5, 0, 0), Graphics::PixelFormat(2, 5, 5, 5, 1, 11, 6, 1, 0)); + + // Tell our size. + int x, y, width, height; + _appForm->GetBounds(x, y, width, height); + AppLog("screen size: %dx%d", width, height); + setActualScreenSize(width, height); + return E_SUCCESS; +} + const Graphics::Font *TizenGraphicsManager::getFontOSD() { return FontMan.getFontByUsage(Graphics::FontManager::kBigGUIFont); } bool TizenGraphicsManager::moveMouse(int16 &x, int16 &y) { - int16 currentX = _cursorState.x; - int16 currentY = _cursorState.y; + int16 currentX, currentY; + getMousePosition(currentX, currentY); // save the current hardware coordinates - _cursorState.x = x; - _cursorState.y = y; + setMousePosition(x, y); // return x/y as game coordinates adjustMousePosition(x, y); @@ -85,15 +101,17 @@ Common::List<Graphics::PixelFormat> TizenGraphicsManager::getSupportedFormats() } bool TizenGraphicsManager::hasFeature(OSystem::Feature f) { - bool result = (f == OSystem::kFeatureFullscreenMode || - f == OSystem::kFeatureVirtualKeyboard || + bool result = + (f == OSystem::kFeatureVirtualKeyboard || OpenGLGraphicsManager::hasFeature(f)); return result; } void TizenGraphicsManager::setFeatureState(OSystem::Feature f, bool enable) { - if (f == OSystem::kFeatureVirtualKeyboard && enable) { - _appForm->showKeypad(); + if (f == OSystem::kFeatureVirtualKeyboard) { + if (enable) { + _appForm->showKeypad(); + } } else { OpenGLGraphicsManager::setFeatureState(f, enable); } @@ -106,8 +124,9 @@ void TizenGraphicsManager::setReady() { } void TizenGraphicsManager::updateScreen() { - if (_transactionMode == kTransactionNone) { - internUpdateScreen(); + if (!_initState) { + OpenGLGraphicsManager::updateScreen(); + eglSwapBuffers(_eglDisplay, _eglSurface); } } @@ -133,10 +152,6 @@ bool TizenGraphicsManager::loadEgl() { eglBindAPI(EGL_OPENGL_ES_API); - if (_eglDisplay) { - unloadGFXMode(); - } - _eglDisplay = eglGetDisplay((EGLNativeDisplayType) EGL_DEFAULT_DISPLAY); if (EGL_NO_DISPLAY == _eglDisplay) { systemError("eglGetDisplay() failed"); @@ -178,65 +193,12 @@ bool TizenGraphicsManager::loadEgl() { systemError("eglMakeCurrent() failed"); return false; } - if (!_initState) { - _appForm->GetVisualElement()->SetShowState(true); - } logLeaving(); return true; } -bool TizenGraphicsManager::loadGFXMode() { - logEntered(); - - if (!loadEgl()) { - unloadGFXMode(); - return false; - } - - int x, y, width, height; - _appForm->GetBounds(x, y, width, height); - _videoMode.overlayWidth = _videoMode.hardwareWidth = width; - _videoMode.overlayHeight = _videoMode.hardwareHeight = height; - _videoMode.scaleFactor = 4; // for proportional sized cursor in the launcher - - AppLog("screen size: %dx%d", _videoMode.hardwareWidth, _videoMode.hardwareHeight); - return OpenGLGraphicsManager::loadGFXMode(); -} - -void TizenGraphicsManager::loadTextures() { - logEntered(); - OpenGLGraphicsManager::loadTextures(); -} - -void TizenGraphicsManager::internUpdateScreen() { - if (!_initState) { - OpenGLGraphicsManager::internUpdateScreen(); - eglSwapBuffers(_eglDisplay, _eglSurface); - } -} - -void TizenGraphicsManager::unloadGFXMode() { - logEntered(); - _appForm->GetVisualElement()->SetShowState(false); - - if (_eglDisplay != EGL_NO_DISPLAY) { - eglMakeCurrent(_eglDisplay, NULL, NULL, NULL); - - if (_eglContext != EGL_NO_CONTEXT) { - eglDestroyContext(_eglDisplay, _eglContext); - _eglContext = EGL_NO_CONTEXT; - } - - if (_eglSurface != EGL_NO_SURFACE) { - eglDestroySurface(_eglDisplay, _eglSurface); - _eglSurface = EGL_NO_SURFACE; - } - - eglTerminate(_eglDisplay); - _eglDisplay = EGL_NO_DISPLAY; - } - - _eglConfig = NULL; - OpenGLGraphicsManager::unloadGFXMode(); - logLeaving(); +bool TizenGraphicsManager::loadVideoMode(uint requestedWidth, uint requestedHeight, const Graphics::PixelFormat &format) { + // We get this whenever a new resolution is requested. Since Tizen is + // using a fixed output size we do nothing like that here. + return true; } diff --git a/backends/platform/tizen/graphics.h b/backends/platform/tizen/graphics.h index 27e5a6aaeb..29ba86a3c4 100644 --- a/backends/platform/tizen/graphics.h +++ b/backends/platform/tizen/graphics.h @@ -39,28 +39,31 @@ using namespace Tizen::Graphics; using namespace Tizen::Graphics::Opengl; using namespace Tizen::App; -class TizenGraphicsManager : public OpenGLGraphicsManager { +class TizenGraphicsManager : public OpenGL::OpenGLGraphicsManager { public: TizenGraphicsManager(TizenAppForm *appForm); virtual ~TizenGraphicsManager(); + result Construct(); + Common::List<Graphics::PixelFormat> getSupportedFormats() const; bool hasFeature(OSystem::Feature f); - void updateScreen(); void setFeatureState(OSystem::Feature f, bool enable); + void updateScreen(); + void setReady(); bool isReady() { return !_initState; } - const Graphics::Font *getFontOSD(); + bool moveMouse(int16 &x, int16 &y); -private: - void internUpdateScreen(); - bool loadGFXMode(); - void loadTextures(); - void unloadGFXMode(); +protected: void setInternalMousePosition(int x, int y) {} - void showSplash(); + bool loadVideoMode(uint requestedWidth, uint requestedHeight, const Graphics::PixelFormat &format); + + const Graphics::Font *getFontOSD(); + +private: bool loadEgl(); TizenAppForm *_appForm; EGLDisplay _eglDisplay; diff --git a/backends/platform/tizen/system.cpp b/backends/platform/tizen/system.cpp index 3448dc1421..f7ebc46719 100644 --- a/backends/platform/tizen/system.cpp +++ b/backends/platform/tizen/system.cpp @@ -267,7 +267,7 @@ result TizenSystem::initModules() { } _graphicsManager = (GraphicsManager *)new TizenGraphicsManager(_appForm); - if (!_graphicsManager) { + if (!_graphicsManager || graphicsManager->Construct() != E_SUCCESS) { return E_OUT_OF_MEMORY; } diff --git a/backends/platform/wince/wince-sdl.cpp b/backends/platform/wince/wince-sdl.cpp index 3897731db4..1c5cd5565b 100644 --- a/backends/platform/wince/wince-sdl.cpp +++ b/backends/platform/wince/wince-sdl.cpp @@ -563,7 +563,7 @@ void OSystem_WINCE3::setGraphicsModeIntern() { void OSystem_WINCE3::initSDL() { // Check if SDL has not been initialized if (!_initedSDL) { - uint32 sdlFlags = SDL_INIT_EVENTTHREAD; + uint32 sdlFlags = SDL_INIT_EVENTTHREAD | SDL_INIT_VIDEO; if (ConfMan.hasKey("disable_sdl_parachute")) sdlFlags |= SDL_INIT_NOPARACHUTE; @@ -576,9 +576,6 @@ void OSystem_WINCE3::initSDL() { if (SDL_Init(sdlFlags) == -1) error("Could not initialize SDL: %s", SDL_GetError()); - // Enable unicode support if possible - SDL_EnableUNICODE(1); - _initedSDL = true; } } |