diff -r 89e97caa2387 include/SDL_video.h --- a/include/SDL_video.h Thu Jul 31 12:46:23 2014 -0700 +++ b/include/SDL_video.h Fri Aug 01 20:08:50 2014 +0200 @@ -290,6 +290,13 @@ extern DECLSPEC int SDLCALL SDL_GetDisplayBounds(int displayIndex, SDL_Rect * rect); /** + * \brief Get the screen physical size in milimeters. + * + * \return 0 on success, or -1 if the index is out of range, or -2 if not implemented + */ +extern DECLSPEC int SDLCALL SDL_GetDisplayPhysicalSize(int displayIndex, float *width, float *height); + +/** * \brief Returns the number of available display modes. * * \sa SDL_GetDisplayMode() diff -r 89e97caa2387 src/core/android/SDL_android.c --- a/src/core/android/SDL_android.c Thu Jul 31 12:46:23 2014 -0700 +++ b/src/core/android/SDL_android.c Fri Aug 01 20:08:50 2014 +0200 @@ -38,6 +38,8 @@ #include "../../joystick/android/SDL_sysjoystick_c.h" #include +#include +#include #include #include #include @@ -1505,6 +1507,52 @@ } return s_AndroidExternalFilesPath; } + +int Android_JNI_GetDensity(int *density) +{ + struct LocalReferenceHolder refs = LocalReferenceHolder_Setup(__FUNCTION__); + JNIEnv* env = Android_JNI_GetEnv(); + int retval = -1; + + JNIEnv *mEnv = Android_JNI_GetEnv(); + if (!LocalReferenceHolder_Init(&refs, env)) { + LocalReferenceHolder_Cleanup(&refs); + return -1; + } + + jmethodID mid; + jobject context; + jobject assetManager; + + /* context = SDLActivity.getContext(); */ + mid = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass, + "getContext","()Landroid/content/Context;"); + context = (*mEnv)->CallStaticObjectMethod(mEnv, mActivityClass, mid); + + /* assetManager = context.getAssets(); */ + mid = (*mEnv)->GetMethodID(mEnv, (*mEnv)->GetObjectClass(mEnv, context), + "getAssets", "()Landroid/content/res/AssetManager;"); + assetManager = (*mEnv)->CallObjectMethod(mEnv, context, mid); + + /* API from NDK: android/configuration.h */ + /* API from NDK: android/asset_manager_jni.h */ + AAssetManager* asset_mgr = AAssetManager_fromJava(env, assetManager); + AConfiguration *cfg = AConfiguration_new(); + + if (asset_mgr && cfg) + { + AConfiguration_fromAssetManager(cfg, asset_mgr); + *density = AConfiguration_getDensity(cfg); + retval = 0; + } + + if (cfg) { + AConfiguration_delete(cfg); + } + + LocalReferenceHolder_Cleanup(&refs); + return retval; +} #endif /* __ANDROID__ */ diff -r 89e97caa2387 src/core/android/SDL_android.h --- a/src/core/android/SDL_android.h Thu Jul 31 12:46:23 2014 -0700 +++ b/src/core/android/SDL_android.h Fri Aug 01 20:08:50 2014 +0200 @@ -80,6 +80,9 @@ /* Generic messages */ int Android_JNI_SendMessage(int command, int param); +/* Video */ +int Android_JNI_GetDensity(int *density); + /* Ends C function definitions when using C++ */ #ifdef __cplusplus /* *INDENT-OFF* */ diff -r 89e97caa2387 src/dynapi/SDL_dynapi_overrides.h --- a/src/dynapi/SDL_dynapi_overrides.h Thu Jul 31 12:46:23 2014 -0700 +++ b/src/dynapi/SDL_dynapi_overrides.h Fri Aug 01 20:08:50 2014 +0200 @@ -505,6 +505,7 @@ #define SDL_GetNumVideoDisplays SDL_GetNumVideoDisplays_REAL #define SDL_GetDisplayName SDL_GetDisplayName_REAL #define SDL_GetDisplayBounds SDL_GetDisplayBounds_REAL +#define SDL_GetDisplayPhysicalSize SDL_GetDisplayPhysicalSize_REAL #define SDL_GetNumDisplayModes SDL_GetNumDisplayModes_REAL #define SDL_GetDisplayMode SDL_GetDisplayMode_REAL #define SDL_GetDesktopDisplayMode SDL_GetDesktopDisplayMode_REAL diff -r 89e97caa2387 src/dynapi/SDL_dynapi_procs.h --- a/src/dynapi/SDL_dynapi_procs.h Thu Jul 31 12:46:23 2014 -0700 +++ b/src/dynapi/SDL_dynapi_procs.h Fri Aug 01 20:08:50 2014 +0200 @@ -534,6 +534,7 @@ SDL_DYNAPI_PROC(int,SDL_GetNumVideoDisplays,(void),(),return) SDL_DYNAPI_PROC(const char*,SDL_GetDisplayName,(int a),(a),return) SDL_DYNAPI_PROC(int,SDL_GetDisplayBounds,(int a, SDL_Rect *b),(a,b),return) +SDL_DYNAPI_PROC(int,SDL_GetDisplayPhysicalSize,(int a, float *b, float *c),(a,b,c),return) SDL_DYNAPI_PROC(int,SDL_GetNumDisplayModes,(int a),(a),return) SDL_DYNAPI_PROC(int,SDL_GetDisplayMode,(int a, int b, SDL_DisplayMode *c),(a,b,c),return) SDL_DYNAPI_PROC(int,SDL_GetDesktopDisplayMode,(int a, SDL_DisplayMode *b),(a,b),return) diff -r 89e97caa2387 src/events/SDL_gesture.c --- a/src/events/SDL_gesture.c Thu Jul 31 12:46:23 2014 -0700 +++ b/src/events/SDL_gesture.c Fri Aug 01 20:08:50 2014 +0200 @@ -38,7 +38,7 @@ #define DOLLARNPOINTS 64 #define DOLLARSIZE 256 -#define ENABLE_DOLLAR +// PATCH slvn #define ENABLE_DOLLAR #define PHI 0.618033989 diff -r 89e97caa2387 src/video/SDL_sysvideo.h --- a/src/video/SDL_sysvideo.h Thu Jul 31 12:46:23 2014 -0700 +++ b/src/video/SDL_sysvideo.h Fri Aug 01 20:08:50 2014 +0200 @@ -171,6 +171,11 @@ int (*GetDisplayBounds) (_THIS, SDL_VideoDisplay * display, SDL_Rect * rect); /* + * Get the physical size of display + */ + int (*GetDisplayPhysicalSize) (_THIS, SDL_VideoDisplay * display, float *width, float *height); + + /* * Get a list of the available display modes for a display. */ void (*GetDisplayModes) (_THIS, SDL_VideoDisplay * display); diff -r 89e97caa2387 src/video/SDL_video.c --- a/src/video/SDL_video.c Thu Jul 31 12:46:23 2014 -0700 +++ b/src/video/SDL_video.c Fri Aug 01 20:08:50 2014 +0200 @@ -677,6 +677,27 @@ return 0; } +int +SDL_GetDisplayPhysicalSize(int displayIndex, float *width, float *height) +{ + CHECK_DISPLAY_INDEX(displayIndex, -1); + + if (width && height) { + SDL_VideoDisplay *display = &_this->displays[displayIndex]; + + if (_this->GetDisplayPhysicalSize) { + if (_this->GetDisplayPhysicalSize(_this, display, width, height) == 0) { + return 0; + } + } else { + return -2; + } + } + return 0; +} + + + SDL_bool SDL_AddDisplayMode(SDL_VideoDisplay * display, const SDL_DisplayMode * mode) { diff -r 89e97caa2387 src/video/android/SDL_androidvideo.c --- a/src/video/android/SDL_androidvideo.c Thu Jul 31 12:46:23 2014 -0700 +++ b/src/video/android/SDL_androidvideo.c Fri Aug 01 20:08:50 2014 +0200 @@ -57,6 +57,9 @@ #define Android_GLES_GetSwapInterval SDL_EGL_GetSwapInterval #define Android_GLES_DeleteContext SDL_EGL_DeleteContext +/* Video functions */ +static int Android_GetDisplayPhysicalSize(_THIS, SDL_VideoDisplay * sdl_display, float *width, float *height); + /* Android driver bootstrap functions */ @@ -114,6 +117,7 @@ device->GetWindowWMInfo = Android_GetWindowWMInfo; device->free = Android_DeleteDevice; + device->GetDisplayPhysicalSize = Android_GetDisplayPhysicalSize; /* GL pointers */ device->GL_LoadLibrary = Android_GLES_LoadLibrary; @@ -191,6 +195,28 @@ } } +static +int +Android_GetDisplayPhysicalSize(_THIS, SDL_VideoDisplay * sdl_display, float *width, float *height) +{ + int density = 0.0; /* Pixels per inch */ + + /* JNI call to get the screen density */ + if (Android_JNI_GetDensity(&density) < 0) { + return -1; + } + + if (density == 0.0) { + return -1; + } + + /* In milimeters */ + *width = 25.4 * (float) Android_ScreenWidth / (float) density; + *height = 25.4 * (float) Android_ScreenHeight / (float) density; + + return 0; +} + #endif /* SDL_VIDEO_DRIVER_ANDROID */ /* vi: set ts=4 sw=4 expandtab: */ diff -r 89e97caa2387 src/video/cocoa/SDL_cocoamodes.h --- a/src/video/cocoa/SDL_cocoamodes.h Thu Jul 31 12:46:23 2014 -0700 +++ b/src/video/cocoa/SDL_cocoamodes.h Fri Aug 01 20:08:50 2014 +0200 @@ -35,6 +35,7 @@ extern void Cocoa_InitModes(_THIS); extern int Cocoa_GetDisplayBounds(_THIS, SDL_VideoDisplay * display, SDL_Rect * rect); +extern int Cocoa_GetDisplayPhysicalSize(_THIS, SDL_VideoDisplay * display, float *width, float *height); extern void Cocoa_GetDisplayModes(_THIS, SDL_VideoDisplay * display); extern int Cocoa_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode); extern void Cocoa_QuitModes(_THIS); diff -r 89e97caa2387 src/video/cocoa/SDL_cocoamodes.m --- a/src/video/cocoa/SDL_cocoamodes.m Thu Jul 31 12:46:23 2014 -0700 +++ b/src/video/cocoa/SDL_cocoamodes.m Fri Aug 01 20:08:50 2014 +0200 @@ -314,6 +314,24 @@ return 0; } +int +Cocoa_GetDisplayPhysicalSize(_THIS, SDL_VideoDisplay * display, float *width, float *height) +{ +#if 0 +TODO ... not tested. + + SDL_DisplayData *displaydata = (SDL_DisplayData *) display->driverdata; + CGSize cgsize; + + NSObject *foo = [NSObject alloc];cgsize = CGDisplayScreenSize(displaydata->display); + *width = (int)cgsize.width; + *height = (int)cgsize.height; + return 0; +#endif + return -1; +} + + void Cocoa_GetDisplayModes(_THIS, SDL_VideoDisplay * display) { diff -r 89e97caa2387 src/video/cocoa/SDL_cocoavideo.m --- a/src/video/cocoa/SDL_cocoavideo.m Thu Jul 31 12:46:23 2014 -0700 +++ b/src/video/cocoa/SDL_cocoavideo.m Fri Aug 01 20:08:50 2014 +0200 @@ -73,6 +73,7 @@ device->VideoInit = Cocoa_VideoInit; device->VideoQuit = Cocoa_VideoQuit; device->GetDisplayBounds = Cocoa_GetDisplayBounds; + device->GetDisplayPhysicalSize = Cocoa_GetDisplayPhysicalSize; device->GetDisplayModes = Cocoa_GetDisplayModes; device->SetDisplayMode = Cocoa_SetDisplayMode; device->PumpEvents = Cocoa_PumpEvents; diff -r 89e97caa2387 src/video/uikit/SDL_uikitmodes.h --- a/src/video/uikit/SDL_uikitmodes.h Thu Jul 31 12:46:23 2014 -0700 +++ b/src/video/uikit/SDL_uikitmodes.h Fri Aug 01 20:08:50 2014 +0200 @@ -41,6 +41,7 @@ extern int UIKit_InitModes(_THIS); extern void UIKit_GetDisplayModes(_THIS, SDL_VideoDisplay * display); +extern int UIKit_GetDisplayPhysicalSize(_THIS, SDL_VideoDisplay * sdl_display, float *width, float *height); extern int UIKit_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode); extern void UIKit_QuitModes(_THIS); diff -r 89e97caa2387 src/video/uikit/SDL_uikitmodes.m --- a/src/video/uikit/SDL_uikitmodes.m Thu Jul 31 12:46:23 2014 -0700 +++ b/src/video/uikit/SDL_uikitmodes.m Fri Aug 01 20:08:50 2014 +0200 @@ -215,6 +215,19 @@ } int +UIKit_GetDisplayPhysicalSize(_THIS, SDL_VideoDisplay * sdl_display, float *width, float *height) +{ +#if 0 +# TODO .. +# maybe some help there : +# http://stackoverflow.com/questions/14517356/getting-the-physical-screen-size-in-inches-for-iphone +# http://stackoverflow.com/questions/8257947/ios-get-physical-screen-size-programmatically + +#endif + return -1 +} + +int UIKit_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode) { SDL_DisplayData *data = (SDL_DisplayData *) display->driverdata; diff -r 89e97caa2387 src/video/uikit/SDL_uikitvideo.m --- a/src/video/uikit/SDL_uikitvideo.m Thu Jul 31 12:46:23 2014 -0700 +++ b/src/video/uikit/SDL_uikitvideo.m Fri Aug 01 20:08:50 2014 +0200 @@ -72,6 +72,7 @@ device->VideoInit = UIKit_VideoInit; device->VideoQuit = UIKit_VideoQuit; device->GetDisplayModes = UIKit_GetDisplayModes; + device->GetDisplayPhysicalSize = UIKit_GetDisplayPhysicalSize; device->SetDisplayMode = UIKit_SetDisplayMode; device->PumpEvents = UIKit_PumpEvents; device->CreateWindow = UIKit_CreateWindow; diff -r 89e97caa2387 src/video/winrt/SDL_winrtvideo.cpp --- a/src/video/winrt/SDL_winrtvideo.cpp Thu Jul 31 12:46:23 2014 -0700 +++ b/src/video/winrt/SDL_winrtvideo.cpp Fri Aug 01 20:08:50 2014 +0200 @@ -61,7 +61,7 @@ static int WINRT_InitModes(_THIS); static int WINRT_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode); static void WINRT_VideoQuit(_THIS); - +static int WINRT_GetDisplayPhysicalSize(_THIS, SDL_VideoDisplay * display, float *width, float *height); /* Window functions */ static int WINRT_CreateWindow(_THIS, SDL_Window * window); @@ -122,6 +122,7 @@ /* Set the function pointers */ device->VideoInit = WINRT_VideoInit; device->VideoQuit = WINRT_VideoQuit; + device->GetDisplayPhysicalSize = WINRT_GetDisplayPhysicalSize; device->CreateWindow = WINRT_CreateWindow; device->DestroyWindow = WINRT_DestroyWindow; device->SetDisplayMode = WINRT_SetDisplayMode; @@ -280,6 +281,27 @@ WINRT_QuitMouse(_this); } + +int +WINRT_GetDisplayPhysicalSize(_THIS, SDL_VideoDisplay * sdl_display, float *width, float *height) +{ +#if 0 + // TODO ... not tested + + const float currentDPI = WINRT_DISPLAY_PROPERTY(LogicalDpi); + int w = CoreWindow::GetForCurrentThread()->Bounds.Width + int h = CoreWindow::GetForCurrentThread()->Bounds.Height, + + /* In milimeters */ + *width = 25.4 * (float) w / currentDPI; + *height = 25.4 * (float) w / currentDPI; + + return 0; +#endif + return -1; +} + + int WINRT_CreateWindow(_THIS, SDL_Window * window) { diff -r 89e97caa2387 src/video/x11/SDL_x11modes.c --- a/src/video/x11/SDL_x11modes.c Thu Jul 31 12:46:23 2014 -0700 +++ b/src/video/x11/SDL_x11modes.c Fri Aug 01 20:08:50 2014 +0200 @@ -887,6 +887,29 @@ return 0; } +int +X11_GetDisplayPhysicalSize(_THIS, SDL_VideoDisplay * sdl_display, float *width, float *height) +{ + SDL_DisplayData *data = (SDL_DisplayData *) sdl_display->driverdata; + Display *display = ((SDL_VideoData *) _this->driverdata)->display; + int screen = 0; + + /* display has not been opened yet */ + if (display == NULL) + { + return SDL_SetError("No available displays"); + } + + /* screen ? */ + screen = data->screen; + + /* size in milimeters */ + *width = DisplayWidthMM(display, screen); + *height = DisplayHeightMM(display, screen); + + return 0; +} + #endif /* SDL_VIDEO_DRIVER_X11 */ /* vi: set ts=4 sw=4 expandtab: */ diff -r 89e97caa2387 src/video/x11/SDL_x11modes.h --- a/src/video/x11/SDL_x11modes.h Thu Jul 31 12:46:23 2014 -0700 +++ b/src/video/x11/SDL_x11modes.h Fri Aug 01 20:08:50 2014 +0200 @@ -75,6 +75,8 @@ XVisualInfo * vinfo); extern int X11_GetDisplayBounds(_THIS, SDL_VideoDisplay * sdl_display, SDL_Rect * rect); +extern int X11_GetDisplayPhysicalSize(_THIS, SDL_VideoDisplay * sdl_display, float *width, float *height); + #endif /* _SDL_x11modes_h */ /* vi: set ts=4 sw=4 expandtab: */ diff -r 89e97caa2387 src/video/x11/SDL_x11video.c --- a/src/video/x11/SDL_x11video.c Thu Jul 31 12:46:23 2014 -0700 +++ b/src/video/x11/SDL_x11video.c Fri Aug 01 20:08:50 2014 +0200 @@ -216,6 +216,7 @@ device->VideoQuit = X11_VideoQuit; device->GetDisplayModes = X11_GetDisplayModes; device->GetDisplayBounds = X11_GetDisplayBounds; + device->GetDisplayPhysicalSize = X11_GetDisplayPhysicalSize; device->SetDisplayMode = X11_SetDisplayMode; device->SuspendScreenSaver = X11_SuspendScreenSaver; device->PumpEvents = X11_PumpEvents;