updated to latest love-android revision (aada9b59bcdf)

This commit is contained in:
fysx
2014-01-20 10:09:26 +01:00
parent ab51b4cc9b
commit ba5f33f9aa
45 changed files with 1112 additions and 50480 deletions
+110 -41
View File
@@ -28,6 +28,9 @@
#include <vector>
#include <algorithm>
// C
#include <cstring>
namespace love
{
namespace window
@@ -63,21 +66,21 @@ Window::~Window()
Window::_currentMode::_currentMode()
: width(800)
, height(600)
, attribs()
, settings()
, icon(0)
{
}
bool Window::setWindow(int width, int height, WindowAttributes *attribs)
bool Window::setWindow(int width, int height, WindowSettings *settings)
{
graphics::Graphics *gfx = (graphics::Graphics *) Module::findInstance("love.graphics.");
if (gfx)
if (gfx != nullptr)
gfx->unSetMode();
WindowAttributes f;
WindowSettings f;
if (attribs)
f = *attribs;
if (settings)
f = *settings;
f.minwidth = std::max(f.minwidth, 1);
f.minheight = std::max(f.minheight, 1);
@@ -116,15 +119,28 @@ bool Window::setWindow(int width, int height, WindowAttributes *attribs)
if (f.borderless)
sdlflags |= SDL_WINDOW_BORDERLESS;
#if SDL_VERSION_ATLEAST(2,0,1)
if (f.highdpi)
sdlflags |= SDL_WINDOW_ALLOW_HIGHDPI;
#endif
// Destroy and recreate the window if the dimensions or flags have changed.
if (window)
{
int curdisplay = SDL_GetWindowDisplayIndex(window);
Uint32 wflags = SDL_GetWindowFlags(window);
wflags &= (SDL_WINDOW_OPENGL | SDL_WINDOW_FULLSCREEN_DESKTOP | SDL_WINDOW_RESIZABLE | SDL_WINDOW_BORDERLESS);
Uint32 testflags = SDL_WINDOW_OPENGL | SDL_WINDOW_FULLSCREEN_DESKTOP
| SDL_WINDOW_RESIZABLE | SDL_WINDOW_BORDERLESS;
#if SDL_VERSION_ATLEAST(2,0,1)
testflags |= SDL_WINDOW_ALLOW_HIGHDPI;
#endif
wflags &= testflags;
if (sdlflags != wflags || width != curMode.width || height != curMode.height
|| f.display != curdisplay || f.fsaa != curMode.attribs.fsaa)
|| f.display != curdisplay || f.fsaa != curMode.settings.fsaa)
{
SDL_DestroyWindow(window);
window = 0;
@@ -185,11 +201,18 @@ bool Window::setWindow(int width, int height, WindowAttributes *attribs)
created = true;
updateAttributes(f);
updateSettings(f);
if (gfx)
if (gfx != nullptr)
{
if (!gfx->setMode(curMode.width, curMode.height))
int width = curMode.width;
int height = curMode.height;
#if SDL_VERSION_ATLEAST(2,0,1)
SDL_GL_GetDrawableSize(window, &width, &height);
#endif
if (!gfx->setMode(width, height))
displayError("Could not set graphics mode", "Unsupported OpenGL version?");
}
@@ -256,8 +279,8 @@ bool Window::setContext(int fsaa, bool vsync)
fsaa = (buffers > 0) ? samples : 0;
}
curMode.attribs.fsaa = fsaa;
curMode.attribs.vsync = SDL_GL_GetSwapInterval() != 0;
curMode.settings.fsaa = fsaa;
curMode.settings.vsync = SDL_GL_GetSwapInterval() != 0;
return true;
}
@@ -276,8 +299,19 @@ void Window::setWindowGLAttributes(int fsaa) const
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, (fsaa > 0) ? 1 : 0);
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, (fsaa > 0) ? fsaa : 0);
const char *glesHint = SDL_GetHint("LOVE_GRAPHICS_USE_OPENGLES");
if (glesHint && *glesHint == '1')
bool tryES2 = false;
const char *driver = SDL_GetCurrentVideoDriver();
// We always want to use OpenGL ES on certain video backends.
if (driver && (strstr(driver, "RPI") || strstr(driver, "Android") || strstr(driver, "uikit")))
tryES2 = true;
const char *hint = SDL_GetHint("LOVE_GRAPHICS_USE_OPENGLES");
if (hint)
tryES2 = (*hint) != '0';
if (tryES2)
{
// Use OpenGL ES 2+.
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
@@ -293,7 +327,7 @@ void Window::setWindowGLAttributes(int fsaa) const
}
}
void Window::updateAttributes(const WindowAttributes &newattribs)
void Window::updateSettings(const WindowSettings &newsettings)
{
Uint32 wflags = SDL_GetWindowFlags(window);
@@ -302,39 +336,45 @@ void Window::updateAttributes(const WindowAttributes &newattribs)
if ((wflags & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP)
{
curMode.attribs.fullscreen = true;
curMode.attribs.fstype = FULLSCREEN_TYPE_DESKTOP;
curMode.settings.fullscreen = true;
curMode.settings.fstype = FULLSCREEN_TYPE_DESKTOP;
}
else if ((wflags & SDL_WINDOW_FULLSCREEN) == SDL_WINDOW_FULLSCREEN)
{
curMode.attribs.fullscreen = true;
curMode.attribs.fstype = FULLSCREEN_TYPE_NORMAL;
curMode.settings.fullscreen = true;
curMode.settings.fstype = FULLSCREEN_TYPE_NORMAL;
}
else
{
curMode.attribs.fullscreen = false;
curMode.attribs.fstype = newattribs.fstype;
curMode.settings.fullscreen = false;
curMode.settings.fstype = newsettings.fstype;
}
// The min width/height is set to 0 internally in SDL when in fullscreen.
if (curMode.attribs.fullscreen)
if (curMode.settings.fullscreen)
{
curMode.attribs.minwidth = newattribs.minwidth;
curMode.attribs.minheight = newattribs.minheight;
curMode.settings.minwidth = newsettings.minwidth;
curMode.settings.minheight = newsettings.minheight;
}
else
SDL_GetWindowMinimumSize(window, &curMode.attribs.minwidth, &curMode.attribs.minheight);
SDL_GetWindowMinimumSize(window, &curMode.settings.minwidth, &curMode.settings.minheight);
curMode.attribs.resizable = (wflags & SDL_WINDOW_RESIZABLE) != 0;
curMode.attribs.borderless = (wflags & SDL_WINDOW_BORDERLESS) != 0;
curMode.attribs.centered = newattribs.centered;
curMode.attribs.display = std::max(SDL_GetWindowDisplayIndex(window), 0);
curMode.settings.resizable = (wflags & SDL_WINDOW_RESIZABLE) != 0;
curMode.settings.borderless = (wflags & SDL_WINDOW_BORDERLESS) != 0;
curMode.settings.centered = newsettings.centered;
curMode.settings.display = std::max(SDL_GetWindowDisplayIndex(window), 0);
#if SDL_VERSION_ATLEAST(2,0,1)
curMode.settings.highdpi = (wflags & SDL_WINDOW_ALLOW_HIGHDPI) != 0;
#else
curMode.settings.highdpi = false;
#endif
// Only minimize on focus loss if the window is in exclusive-fullscreen
// mode (mimics behaviour of SDL 2.0.2+).
// In OS X we always disable this to prevent dock minimization weirdness.
#ifndef LOVE_MACOSX
if (curMode.attribs.fullscreen && curMode.attribs.fstype == FULLSCREEN_TYPE_NORMAL)
if (curMode.settings.fullscreen && curMode.settings.fstype == FULLSCREEN_TYPE_NORMAL)
SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, "1");
else
#endif
@@ -351,15 +391,15 @@ void Window::displayError(const std::string &title, const std::string &text) con
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, title.c_str(), text.c_str(), window);
}
void Window::getWindow(int &width, int &height, WindowAttributes &attribs)
void Window::getWindow(int &width, int &height, WindowSettings &settings)
{
// Window position may be different from creation - update display index.
if (window)
curMode.attribs.display = std::max(SDL_GetWindowDisplayIndex(window), 0);
curMode.settings.display = std::max(SDL_GetWindowDisplayIndex(window), 0);
width = curMode.width;
height = curMode.height;
attribs = curMode.attribs;
settings = curMode.settings;
}
bool Window::setFullscreen(bool fullscreen, Window::FullscreenType fstype)
@@ -367,9 +407,9 @@ bool Window::setFullscreen(bool fullscreen, Window::FullscreenType fstype)
if (!window)
return false;
WindowAttributes newattribs = curMode.attribs;
newattribs.fullscreen = fullscreen;
newattribs.fstype = fstype;
WindowSettings newsettings = curMode.settings;
newsettings.fullscreen = fullscreen;
newsettings.fstype = fstype;
Uint32 sdlflags = 0;
@@ -393,12 +433,21 @@ bool Window::setFullscreen(bool fullscreen, Window::FullscreenType fstype)
if (SDL_SetWindowFullscreen(window, sdlflags) == 0)
{
SDL_GL_MakeCurrent(window, context);
updateAttributes(newattribs);
updateSettings(newsettings);
// Update the viewport size now instead of waiting for event polling.
graphics::Graphics *gfx = (graphics::Graphics *) Module::findInstance("love.graphics.");
if (gfx)
gfx->setViewportSize(curMode.width, curMode.height);
if (gfx != nullptr)
{
int width = curMode.width;
int height = curMode.height;
#if SDL_VERSION_ATLEAST(2,0,1)
SDL_GL_GetDrawableSize(window, &width, &height);
#endif
gfx->setViewportSize(width, height);
}
return true;
}
@@ -408,7 +457,7 @@ bool Window::setFullscreen(bool fullscreen, Window::FullscreenType fstype)
bool Window::setFullscreen(bool fullscreen)
{
return setFullscreen(fullscreen, curMode.attribs.fstype);
return setFullscreen(fullscreen, curMode.settings.fstype);
}
int Window::getDisplayCount() const
@@ -591,6 +640,26 @@ bool Window::isMouseGrabbed() const
return mouseGrabbed;
}
double Window::getPixelScale() const
{
double scale = 1.0;
#if SDL_VERSION_ATLEAST(2,0,1)
if (window)
{
int wheight;
SDL_GetWindowSize(window, nullptr, &wheight);
int dheight = wheight;
SDL_GL_GetDrawableSize(window, nullptr, &dheight);
scale = (double) dheight / wheight;
}
#endif
return scale;
}
const void *Window::getHandle() const
{
return window;