src/video/x11/SDL_x11dyn.c
author Ryan C. Gordon <icculus@icculus.org>
Thu, 09 Apr 2015 22:28:37 -0400
changeset 9541 cf8fab52e33b
parent 8149 681eb46b8ac4
child 9619 b94b6d0bff0f
permissions -rw-r--r--
Merged Alex Szpakowski's iOS-improvement branch to default.

Fixes Bugzilla #2798.
Fixes Bugzilla #2212.
Fixes Bugzilla #2826.
Fixes Bugzilla #2661.
Fixes Bugzilla #1885.
Fixes Bugzilla #1578.
Fixes Bugzilla #2751.

(whew!)

Notable changes, from Alex's notes:

- The SDL_WINDOW_ALLOW_HIGHDPI flag is now needed (along with SDL_GL_GetDrawableSize or SDL_GetRendererOutputSize) to use Retina / high DPI resolutions, bringing SDL’s Retina-related behavior on iOS in line with Mac OS X. Window dimensions and display modes are now in the “points” (non-high DPI) coordinate system rather than pixels, whereas SDL_GL_GetDrawableSize is in pixels.

- Reworked the custom extended launch screen code:
- It now hides after the first SDL_PumpEvents call rather than SDL_CreateWindow, and it fades out in a similar manner to the system launch screen behavior.
- It now mirrors the system launch screen behavior when deciding which image to display: it falls back to using the Launch Images dictionary in Info.plist if the iOS 8+ launch screen nib isn’t available, and if the Launch Images dictionary doesn’t exist it uses the old standard launch image names.
- The extended launch screen can now be disabled via the SDL_IPHONE_LAUNCHSCREEN define in SDL_config_iphoneos.h.

- Added support for SDL_HINT_ACCELEROMETER_AS_JOYSTICK.

- Added access to a window view's renderbuffer and framebuffer to syswm.

- Added OpenGL ES debug labels for the Renderbuffer and Framebuffer Objects created with SDL_GL_CreateContext.

- Added support for sRGB OpenGL ES contexts on iOS 7+.

- Updated OpenGL ES contexts to support native-resolution rendering (when SDL_WINDOW_ALLOW_HIGHDPI is enabled) on the iPhone 6 Plus, i.e. 1080x1920 rather than 1242x2208.

- Updated SDL_GL_CreateContext, SDL_GL_SwapWindow, SDL_GL_MakeCurrent, and SDL_GL_DeleteContext to be more robust.

- Updated SDL windows to display a UIView at all times, even when an OpenGL context is not active. This allows rotation, touch events, and other windowing-related events to work properly without an active OpenGL context. It also makes it easier to use SDL_GetWindowWMInfo after creating a SDL window.

- Updated the iOS-specific Objective-C code to use cleaner and more modern language features and APIs, including ARC instead of manual reference counting.

- Updated SDL_HINT_ORIENTATIONS to allow disabling custom orientations if the hint is set with no valid orientation names.

- Fixed several rotation and orientation bugs with windows and display modes, especially in iOS 8+.

- Fixed SDL_SetWindowFullscreen failing to update the status bar visibility on iOS 7+.

- Fixed the orientation of the offset applied to the window’s view when the onscreen keyboard is shown in iOS 8+.

- Fixed SDL_IsScreenKeyboardShown (patch by Phil Hassey.)

- Fixed several major memory leaks caused by missing autorelease pool blocks in the iOS-specific Objective-C code.

- Removed several dead code paths.

- The iOS 7 SDK (Xcode 5) or newer is now required to build SDL for iOS.
     1 /*
     2   Simple DirectMedia Layer
     3   Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
     4 
     5   This software is provided 'as-is', without any express or implied
     6   warranty.  In no event will the authors be held liable for any damages
     7   arising from the use of this software.
     8 
     9   Permission is granted to anyone to use this software for any purpose,
    10   including commercial applications, and to alter it and redistribute it
    11   freely, subject to the following restrictions:
    12 
    13   1. The origin of this software must not be misrepresented; you must not
    14      claim that you wrote the original software. If you use this software
    15      in a product, an acknowledgment in the product documentation would be
    16      appreciated but is not required.
    17   2. Altered source versions must be plainly marked as such, and must not be
    18      misrepresented as being the original software.
    19   3. This notice may not be removed or altered from any source distribution.
    20 */
    21 #include "../../SDL_internal.h"
    22 
    23 #if SDL_VIDEO_DRIVER_X11
    24 
    25 #define DEBUG_DYNAMIC_X11 0
    26 
    27 #include "SDL_x11dyn.h"
    28 
    29 #if DEBUG_DYNAMIC_X11
    30 #include <stdio.h>
    31 #endif
    32 
    33 #ifdef SDL_VIDEO_DRIVER_X11_DYNAMIC
    34 
    35 #include "SDL_name.h"
    36 #include "SDL_loadso.h"
    37 
    38 typedef struct
    39 {
    40     void *lib;
    41     const char *libname;
    42 } x11dynlib;
    43 
    44 #ifndef SDL_VIDEO_DRIVER_X11_DYNAMIC
    45 #define SDL_VIDEO_DRIVER_X11_DYNAMIC NULL
    46 #endif
    47 #ifndef SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT
    48 #define SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT NULL
    49 #endif
    50 #ifndef SDL_VIDEO_DRIVER_X11_DYNAMIC_XCURSOR
    51 #define SDL_VIDEO_DRIVER_X11_DYNAMIC_XCURSOR NULL
    52 #endif
    53 #ifndef SDL_VIDEO_DRIVER_X11_DYNAMIC_XINERAMA
    54 #define SDL_VIDEO_DRIVER_X11_DYNAMIC_XINERAMA NULL
    55 #endif
    56 #ifndef SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT2
    57 #define SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT2 NULL
    58 #endif
    59 #ifndef SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR
    60 #define SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR NULL
    61 #endif
    62 #ifndef SDL_VIDEO_DRIVER_X11_DYNAMIC_XSS
    63 #define SDL_VIDEO_DRIVER_X11_DYNAMIC_XSS NULL
    64 #endif
    65 #ifndef SDL_VIDEO_DRIVER_X11_DYNAMIC_XVIDMODE
    66 #define SDL_VIDEO_DRIVER_X11_DYNAMIC_XVIDMODE NULL
    67 #endif
    68 
    69 static x11dynlib x11libs[] = {
    70     {NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC},
    71     {NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT},
    72     {NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XCURSOR},
    73     {NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XINERAMA},
    74     {NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT2},
    75     {NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR},
    76     {NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XSS},
    77     {NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XVIDMODE}
    78 };
    79 
    80 static void *
    81 X11_GetSym(const char *fnname, int *pHasModule)
    82 {
    83     int i;
    84     void *fn = NULL;
    85     for (i = 0; i < SDL_TABLESIZE(x11libs); i++) {
    86         if (x11libs[i].lib != NULL) {
    87             fn = SDL_LoadFunction(x11libs[i].lib, fnname);
    88             if (fn != NULL)
    89                 break;
    90         }
    91     }
    92 
    93 #if DEBUG_DYNAMIC_X11
    94     if (fn != NULL)
    95         printf("X11: Found '%s' in %s (%p)\n", fnname, x11libs[i].libname, fn);
    96     else
    97         printf("X11: Symbol '%s' NOT FOUND!\n", fnname);
    98 #endif
    99 
   100     if (fn == NULL)
   101         *pHasModule = 0;  /* kill this module. */
   102 
   103     return fn;
   104 }
   105 
   106 #endif /* SDL_VIDEO_DRIVER_X11_DYNAMIC */
   107 
   108 /* Define all the function pointers and wrappers... */
   109 #define SDL_X11_MODULE(modname)
   110 #define SDL_X11_SYM(rc,fn,params,args,ret) SDL_DYNX11FN_##fn X11_##fn = NULL;
   111 #include "SDL_x11sym.h"
   112 #undef SDL_X11_MODULE
   113 #undef SDL_X11_SYM
   114 
   115 /* Annoying varargs entry point... */
   116 #ifdef X_HAVE_UTF8_STRING
   117 SDL_DYNX11FN_XCreateIC X11_XCreateIC = NULL;
   118 SDL_DYNX11FN_XGetICValues X11_XGetICValues = NULL;
   119 #endif
   120 
   121 /* These SDL_X11_HAVE_* flags are here whether you have dynamic X11 or not. */
   122 #define SDL_X11_MODULE(modname) int SDL_X11_HAVE_##modname = 0;
   123 #define SDL_X11_SYM(rc,fn,params,args,ret)
   124 #include "SDL_x11sym.h"
   125 #undef SDL_X11_MODULE
   126 #undef SDL_X11_SYM
   127 
   128 static int x11_load_refcount = 0;
   129 
   130 void
   131 SDL_X11_UnloadSymbols(void)
   132 {
   133     /* Don't actually unload if more than one module is using the libs... */
   134     if (x11_load_refcount > 0) {
   135         if (--x11_load_refcount == 0) {
   136             int i;
   137 
   138             /* set all the function pointers to NULL. */
   139 #define SDL_X11_MODULE(modname) SDL_X11_HAVE_##modname = 0;
   140 #define SDL_X11_SYM(rc,fn,params,args,ret) X11_##fn = NULL;
   141 #include "SDL_x11sym.h"
   142 #undef SDL_X11_MODULE
   143 #undef SDL_X11_SYM
   144 
   145 #ifdef X_HAVE_UTF8_STRING
   146             X11_XCreateIC = NULL;
   147             X11_XGetICValues = NULL;
   148 #endif
   149 
   150 #ifdef SDL_VIDEO_DRIVER_X11_DYNAMIC
   151             for (i = 0; i < SDL_TABLESIZE(x11libs); i++) {
   152                 if (x11libs[i].lib != NULL) {
   153                     SDL_UnloadObject(x11libs[i].lib);
   154                     x11libs[i].lib = NULL;
   155                 }
   156             }
   157 #endif
   158         }
   159     }
   160 }
   161 
   162 /* returns non-zero if all needed symbols were loaded. */
   163 int
   164 SDL_X11_LoadSymbols(void)
   165 {
   166     int rc = 1;                 /* always succeed if not using Dynamic X11 stuff. */
   167 
   168     /* deal with multiple modules (dga, x11, etc) needing these symbols... */
   169     if (x11_load_refcount++ == 0) {
   170 #ifdef SDL_VIDEO_DRIVER_X11_DYNAMIC
   171         int i;
   172         int *thismod = NULL;
   173         for (i = 0; i < SDL_TABLESIZE(x11libs); i++) {
   174             if (x11libs[i].libname != NULL) {
   175                 x11libs[i].lib = SDL_LoadObject(x11libs[i].libname);
   176             }
   177         }
   178 
   179 #define SDL_X11_MODULE(modname) SDL_X11_HAVE_##modname = 1; /* default yes */
   180 #define SDL_X11_SYM(a,fn,x,y,z)
   181 #include "SDL_x11sym.h"
   182 #undef SDL_X11_MODULE
   183 #undef SDL_X11_SYM
   184 
   185 #define SDL_X11_MODULE(modname) thismod = &SDL_X11_HAVE_##modname;
   186 #define SDL_X11_SYM(a,fn,x,y,z) X11_##fn = (SDL_DYNX11FN_##fn) X11_GetSym(#fn,thismod);
   187 #include "SDL_x11sym.h"
   188 #undef SDL_X11_MODULE
   189 #undef SDL_X11_SYM
   190 
   191 #ifdef X_HAVE_UTF8_STRING
   192         X11_XCreateIC = (SDL_DYNX11FN_XCreateIC)
   193                         X11_GetSym("XCreateIC", &SDL_X11_HAVE_UTF8);
   194         X11_XGetICValues = (SDL_DYNX11FN_XGetICValues)
   195                         X11_GetSym("XGetICValues", &SDL_X11_HAVE_UTF8);
   196 #endif
   197 
   198         if (SDL_X11_HAVE_BASEXLIB) {
   199             /* all required symbols loaded. */
   200             SDL_ClearError();
   201         } else {
   202             /* in case something got loaded... */
   203             SDL_X11_UnloadSymbols();
   204             rc = 0;
   205         }
   206 
   207 #else  /* no dynamic X11 */
   208 
   209 #define SDL_X11_MODULE(modname) SDL_X11_HAVE_##modname = 1; /* default yes */
   210 #define SDL_X11_SYM(a,fn,x,y,z) X11_##fn = fn;
   211 #include "SDL_x11sym.h"
   212 #undef SDL_X11_MODULE
   213 #undef SDL_X11_SYM
   214 
   215 #ifdef X_HAVE_UTF8_STRING
   216         X11_XCreateIC = XCreateIC;
   217         X11_XGetICValues = XGetICValues;
   218 #endif
   219 #endif
   220     }
   221 
   222     return rc;
   223 }
   224 
   225 #endif /* SDL_VIDEO_DRIVER_X11 */
   226 
   227 /* vi: set ts=4 sw=4 expandtab: */