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