src/video/SDL_sysvideo.h
author Gabriel Jacobo <gabomdq@gmail.com>
Sat, 14 Dec 2013 20:18:43 -0300
changeset 8062 4fc5f66d63cc
parent 7981 6d538bc1b395
child 8093 b43765095a6f
permissions -rw-r--r--
Wayland support

Based on the original port to Wayland by: Joel Teichroeb, Benjamin Franzke, Scott Moreau, et al.

Additional changes in this commit, done by me:

* Wayland uses the common EGL framework
* EGL can now create a desktop OpenGL context
* testgl2 loads GL functions dynamically, no need to link to libGL anymore
* Assorted fixes to the Wayland backend

Tested on the Weston Compositor (v1.0.5) that ships with Ubuntu 13.10,
running Weston under X. Tests ran: testrendercopyex (all backends), testgl2, testgles2,testintersections
slouken@0
     1
/*
slouken@5535
     2
  Simple DirectMedia Layer
slouken@6885
     3
  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
slouken@0
     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@0
     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@0
    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@0
    20
*/
slouken@1402
    21
#include "SDL_config.h"
slouken@0
    22
slouken@0
    23
#ifndef _SDL_sysvideo_h
slouken@0
    24
#define _SDL_sysvideo_h
slouken@0
    25
slouken@6602
    26
#include "SDL_messagebox.h"
eligottlieb@4782
    27
#include "SDL_shape.h"
jorgen@7390
    28
#include "SDL_thread.h"
slouken@0
    29
slouken@0
    30
/* The SDL video driver */
slouken@1895
    31
eligottlieb@4782
    32
typedef struct SDL_WindowShaper SDL_WindowShaper;
eligottlieb@4782
    33
typedef struct SDL_ShapeDriver SDL_ShapeDriver;
slouken@1895
    34
typedef struct SDL_VideoDisplay SDL_VideoDisplay;
slouken@0
    35
typedef struct SDL_VideoDevice SDL_VideoDevice;
slouken@0
    36
eligottlieb@4782
    37
/* Define the SDL window-shaper structure */
eligottlieb@4782
    38
struct SDL_WindowShaper
slouken@7191
    39
{
eligottlieb@4782
    40
    /* The window associated with the shaper */
eligottlieb@4782
    41
    SDL_Window *window;
slouken@7191
    42
eligottlieb@4851
    43
    /* The user's specified coordinates for the window, for once we give it a shape. */
eligottlieb@4851
    44
    Uint32 userx,usery;
slouken@7191
    45
eligottlieb@4807
    46
    /* The parameters for shape calculation. */
eligottlieb@4807
    47
    SDL_WindowShapeMode mode;
slouken@7191
    48
eligottlieb@4782
    49
    /* Has this window been assigned a shape? */
eligottlieb@4782
    50
    SDL_bool hasshape;
slouken@7191
    51
eligottlieb@4782
    52
    void *driverdata;
eligottlieb@4782
    53
};
eligottlieb@4782
    54
eligottlieb@4782
    55
/* Define the SDL shape driver structure */
eligottlieb@4782
    56
struct SDL_ShapeDriver
eligottlieb@4782
    57
{
eligottlieb@4782
    58
    SDL_WindowShaper *(*CreateShaper)(SDL_Window * window);
egottlieb@4849
    59
    int (*SetWindowShape)(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shape_mode);
eligottlieb@4782
    60
    int (*ResizeWindowShape)(SDL_Window *window);
eligottlieb@4782
    61
};
eligottlieb@4782
    62
slouken@5165
    63
typedef struct SDL_WindowUserData
slouken@5165
    64
{
slouken@5165
    65
    char *name;
slouken@5165
    66
    void *data;
slouken@5165
    67
    struct SDL_WindowUserData *next;
slouken@5165
    68
} SDL_WindowUserData;
slouken@5165
    69
slouken@1895
    70
/* Define the SDL window structure, corresponding to toplevel windows */
slouken@2753
    71
struct SDL_Window
slouken@2753
    72
{
slouken@3695
    73
    const void *magic;
slouken@2753
    74
    Uint32 id;
slouken@2753
    75
    char *title;
slouken@7523
    76
    SDL_Surface *icon;
slouken@2753
    77
    int x, y;
slouken@2753
    78
    int w, h;
stopiccot@6681
    79
    int min_w, min_h;
slouken@6788
    80
    int max_w, max_h;
slouken@2753
    81
    Uint32 flags;
slouken@1895
    82
slouken@5398
    83
    /* Stored position and size for windowed mode */
slouken@5398
    84
    SDL_Rect windowed;
slouken@5398
    85
slouken@3500
    86
    SDL_DisplayMode fullscreen_mode;
slouken@7191
    87
slouken@5466
    88
    float brightness;
slouken@5466
    89
    Uint16 *gamma;
slouken@5466
    90
    Uint16 *saved_gamma;        /* (just offset into gamma) */
slouken@5466
    91
slouken@5166
    92
    SDL_Surface *surface;
slouken@5174
    93
    SDL_bool surface_valid;
slouken@5166
    94
eligottlieb@4782
    95
    SDL_WindowShaper *shaper;
slouken@3500
    96
slouken@5165
    97
    SDL_WindowUserData *data;
slouken@5165
    98
slouken@2753
    99
    void *driverdata;
slouken@3685
   100
slouken@3685
   101
    SDL_Window *prev;
slouken@3685
   102
    SDL_Window *next;
slouken@1895
   103
};
slouken@1895
   104
#define FULLSCREEN_VISIBLE(W) \
slouken@1895
   105
    (((W)->flags & SDL_WINDOW_FULLSCREEN) && \
slouken@1895
   106
     ((W)->flags & SDL_WINDOW_SHOWN) && \
slouken@1895
   107
     !((W)->flags & SDL_WINDOW_MINIMIZED))
slouken@1895
   108
hfutrell@2742
   109
/*
hfutrell@2742
   110
 * Define the SDL display structure This corresponds to physical monitors
hfutrell@2742
   111
 * attached to the system.
slouken@1895
   112
 */
slouken@2753
   113
struct SDL_VideoDisplay
slouken@2753
   114
{
slouken@6787
   115
    char *name;
slouken@2753
   116
    int max_display_modes;
slouken@2753
   117
    int num_display_modes;
slouken@2753
   118
    SDL_DisplayMode *display_modes;
slouken@2753
   119
    SDL_DisplayMode desktop_mode;
slouken@2753
   120
    SDL_DisplayMode current_mode;
slouken@1895
   121
slouken@3517
   122
    SDL_Window *fullscreen_window;
slouken@1895
   123
slouken@2753
   124
    SDL_VideoDevice *device;
slouken@1895
   125
slouken@2753
   126
    void *driverdata;
slouken@1895
   127
};
slouken@1895
   128
slouken@5272
   129
/* Forward declaration */
slouken@5272
   130
struct SDL_SysWMinfo;
slouken@5272
   131
slouken@0
   132
/* Define the SDL video driver structure */
slouken@7191
   133
#define _THIS   SDL_VideoDevice *_this
slouken@0
   134
slouken@2753
   135
struct SDL_VideoDevice
slouken@2753
   136
{
slouken@2753
   137
    /* * * */
slouken@2753
   138
    /* The name of this video driver */
slouken@2753
   139
    const char *name;
slouken@0
   140
slouken@2753
   141
    /* * * */
slouken@2753
   142
    /* Initialization/Query functions */
slouken@0
   143
slouken@2753
   144
    /*
slouken@2753
   145
     * Initialize the native video subsystem, filling in the list of
slouken@2753
   146
     * displays for this driver, returning 0 or -1 if there's an error.
slouken@2753
   147
     */
slouken@2753
   148
    int (*VideoInit) (_THIS);
slouken@0
   149
slouken@2753
   150
    /*
slouken@2753
   151
     * Reverse the effects VideoInit() -- called if VideoInit() fails or
slouken@2753
   152
     * if the application is shutting down the video subsystem.
slouken@2753
   153
     */
slouken@2753
   154
    void (*VideoQuit) (_THIS);
slouken@1913
   155
slouken@2753
   156
    /* * * */
slouken@2753
   157
    /*
slouken@2753
   158
     * Display functions
slouken@2753
   159
     */
slouken@0
   160
slouken@2753
   161
    /*
slouken@3528
   162
     * Get the bounds of a display
slouken@3528
   163
     */
slouken@3528
   164
    int (*GetDisplayBounds) (_THIS, SDL_VideoDisplay * display, SDL_Rect * rect);
slouken@3528
   165
slouken@3528
   166
    /*
slouken@5246
   167
     * Get a list of the available display modes for a display.
slouken@2753
   168
     */
slouken@3500
   169
    void (*GetDisplayModes) (_THIS, SDL_VideoDisplay * display);
slouken@0
   170
slouken@2753
   171
    /*
slouken@2753
   172
     * Setting the display mode is independent of creating windows, so
slouken@2753
   173
     * when the display mode is changed, all existing windows should have
slouken@2753
   174
     * their data updated accordingly, including the display surfaces
slouken@2753
   175
     * associated with them.
slouken@2753
   176
     */
slouken@3500
   177
    int (*SetDisplayMode) (_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode);
slouken@0
   178
slouken@2753
   179
    /* * * */
slouken@2753
   180
    /*
slouken@2753
   181
     * Window functions
slouken@2753
   182
     */
slouken@2753
   183
    int (*CreateWindow) (_THIS, SDL_Window * window);
slouken@2753
   184
    int (*CreateWindowFrom) (_THIS, SDL_Window * window, const void *data);
slouken@2753
   185
    void (*SetWindowTitle) (_THIS, SDL_Window * window);
slouken@2967
   186
    void (*SetWindowIcon) (_THIS, SDL_Window * window, SDL_Surface * icon);
slouken@2753
   187
    void (*SetWindowPosition) (_THIS, SDL_Window * window);
slouken@2753
   188
    void (*SetWindowSize) (_THIS, SDL_Window * window);
stopiccot@6681
   189
    void (*SetWindowMinimumSize) (_THIS, SDL_Window * window);
slouken@6788
   190
    void (*SetWindowMaximumSize) (_THIS, SDL_Window * window);
slouken@2753
   191
    void (*ShowWindow) (_THIS, SDL_Window * window);
slouken@2753
   192
    void (*HideWindow) (_THIS, SDL_Window * window);
slouken@2753
   193
    void (*RaiseWindow) (_THIS, SDL_Window * window);
slouken@2753
   194
    void (*MaximizeWindow) (_THIS, SDL_Window * window);
slouken@2753
   195
    void (*MinimizeWindow) (_THIS, SDL_Window * window);
slouken@2753
   196
    void (*RestoreWindow) (_THIS, SDL_Window * window);
icculus@6422
   197
    void (*SetWindowBordered) (_THIS, SDL_Window * window, SDL_bool bordered);
slouken@5305
   198
    void (*SetWindowFullscreen) (_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen);
slouken@5466
   199
    int (*SetWindowGammaRamp) (_THIS, SDL_Window * window, const Uint16 * ramp);
slouken@5466
   200
    int (*GetWindowGammaRamp) (_THIS, SDL_Window * window, Uint16 * ramp);
slouken@6662
   201
    void (*SetWindowGrab) (_THIS, SDL_Window * window, SDL_bool grabbed);
slouken@2753
   202
    void (*DestroyWindow) (_THIS, SDL_Window * window);
slouken@5166
   203
    int (*CreateWindowFramebuffer) (_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch);
slouken@7014
   204
    int (*UpdateWindowFramebuffer) (_THIS, SDL_Window * window, const SDL_Rect * rects, int numrects);
slouken@5166
   205
    void (*DestroyWindowFramebuffer) (_THIS, SDL_Window * window);
jorgen@7089
   206
    void (*OnWindowEnter) (_THIS, SDL_Window * window);
slouken@5166
   207
eligottlieb@4782
   208
    /* * * */
eligottlieb@4782
   209
    /*
eligottlieb@4782
   210
     * Shaped-window functions
eligottlieb@4782
   211
     */
eligottlieb@4782
   212
    SDL_ShapeDriver shape_driver;
slouken@0
   213
slouken@2753
   214
    /* Get some platform dependent window information */
slouken@2753
   215
      SDL_bool(*GetWindowWMInfo) (_THIS, SDL_Window * window,
slouken@2753
   216
                                  struct SDL_SysWMinfo * info);
slouken@0
   217
slouken@2753
   218
    /* * * */
slouken@2753
   219
    /*
slouken@2753
   220
     * OpenGL support
slouken@2753
   221
     */
slouken@2753
   222
    int (*GL_LoadLibrary) (_THIS, const char *path);
slouken@2753
   223
    void *(*GL_GetProcAddress) (_THIS, const char *proc);
slouken@3057
   224
    void (*GL_UnloadLibrary) (_THIS);
slouken@2753
   225
      SDL_GLContext(*GL_CreateContext) (_THIS, SDL_Window * window);
slouken@2753
   226
    int (*GL_MakeCurrent) (_THIS, SDL_Window * window, SDL_GLContext context);
urkle@7746
   227
    void (*GL_GetDrawableSize) (_THIS, SDL_Window * window, int *w, int *h);
slouken@2753
   228
    int (*GL_SetSwapInterval) (_THIS, int interval);
slouken@2753
   229
    int (*GL_GetSwapInterval) (_THIS);
slouken@2753
   230
    void (*GL_SwapWindow) (_THIS, SDL_Window * window);
slouken@2753
   231
    void (*GL_DeleteContext) (_THIS, SDL_GLContext context);
slouken@0
   232
slouken@2753
   233
    /* * * */
slouken@2753
   234
    /*
slouken@2753
   235
     * Event manager functions
slouken@2753
   236
     */
slouken@2753
   237
    void (*PumpEvents) (_THIS);
slouken@0
   238
slouken@3025
   239
    /* Suspend the screensaver */
slouken@3025
   240
    void (*SuspendScreenSaver) (_THIS);
slouken@3025
   241
slouken@3280
   242
    /* Text input */
slouken@3280
   243
    void (*StartTextInput) (_THIS);
slouken@3280
   244
    void (*StopTextInput) (_THIS);
slouken@3280
   245
    void (*SetTextInputRect) (_THIS, SDL_Rect *rect);
slouken@3280
   246
slouken@6392
   247
    /* Screen keyboard */
philipp@7135
   248
    SDL_bool (*HasScreenKeyboardSupport) (_THIS);
philipp@7135
   249
    void (*ShowScreenKeyboard) (_THIS, SDL_Window *window);
philipp@7135
   250
    void (*HideScreenKeyboard) (_THIS, SDL_Window *window);
philipp@7135
   251
    SDL_bool (*IsScreenKeyboardShown) (_THIS, SDL_Window *window);
slouken@6392
   252
slouken@4495
   253
    /* Clipboard */
slouken@4495
   254
    int (*SetClipboardText) (_THIS, const char *text);
slouken@4495
   255
    char * (*GetClipboardText) (_THIS);
slouken@4495
   256
    SDL_bool (*HasClipboardText) (_THIS);
slouken@4495
   257
slouken@6602
   258
    /* MessageBox */
slouken@6602
   259
    int (*ShowMessageBox) (_THIS, const SDL_MessageBoxData *messageboxdata, int *buttonid);
slouken@6602
   260
slouken@2753
   261
    /* * * */
slouken@2753
   262
    /* Data common to all drivers */
slouken@3025
   263
    SDL_bool suspend_screensaver;
slouken@2753
   264
    int num_displays;
slouken@2753
   265
    SDL_VideoDisplay *displays;
slouken@5246
   266
    SDL_Window *windows;
slouken@3695
   267
    Uint8 window_magic;
slouken@2753
   268
    Uint32 next_object_id;
slouken@4495
   269
    char * clipboard_text;
slouken@0
   270
slouken@2753
   271
    /* * * */
slouken@2753
   272
    /* Data used by the GL drivers */
slouken@2753
   273
    struct
slouken@2753
   274
    {
slouken@2753
   275
        int red_size;
slouken@2753
   276
        int green_size;
slouken@2753
   277
        int blue_size;
slouken@2753
   278
        int alpha_size;
slouken@2753
   279
        int depth_size;
slouken@2753
   280
        int buffer_size;
slouken@2753
   281
        int stencil_size;
slouken@2753
   282
        int double_buffer;
slouken@2753
   283
        int accum_red_size;
slouken@2753
   284
        int accum_green_size;
slouken@2753
   285
        int accum_blue_size;
slouken@2753
   286
        int accum_alpha_size;
slouken@2753
   287
        int stereo;
slouken@2753
   288
        int multisamplebuffers;
slouken@2753
   289
        int multisamplesamples;
slouken@2753
   290
        int accelerated;
slouken@3100
   291
        int major_version;
slouken@3100
   292
        int minor_version;
slouken@6296
   293
        int flags;
slouken@6296
   294
        int profile_mask;
slouken@6393
   295
        int share_with_current_context;
icculus@7853
   296
        int framebuffer_srgb_capable;
slouken@2753
   297
        int retained_backing;
slouken@2753
   298
        int driver_loaded;
slouken@2753
   299
        char driver_path[256];
slouken@2753
   300
        void *dll_handle;
slouken@2753
   301
    } gl_config;
slouken@0
   302
slouken@2753
   303
    /* * * */
icculus@5563
   304
    /* Cache current GL context; don't call the OS when it hasn't changed. */
slouken@7558
   305
    /* We have the global pointers here so Cocoa continues to work the way
slouken@7558
   306
       it always has, and the thread-local storage for the general case.
slouken@7558
   307
     */
icculus@5563
   308
    SDL_Window *current_glwin;
icculus@5563
   309
    SDL_GLContext current_glctx;
slouken@7412
   310
    SDL_TLSID current_glwin_tls;
slouken@7412
   311
    SDL_TLSID current_glctx_tls;
icculus@5563
   312
icculus@5563
   313
    /* * * */
slouken@2753
   314
    /* Data private to this driver */
slouken@2753
   315
    void *driverdata;
slouken@2753
   316
    struct SDL_GLDriverData *gl_data;
gabomdq@7659
   317
    
gabomdq@7659
   318
#if SDL_VIDEO_OPENGL_EGL
gabomdq@7659
   319
    struct SDL_EGL_VideoData *egl_data;
gabomdq@7659
   320
#endif
gabomdq@7659
   321
    
slouken@6370
   322
#if SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
slouken@3161
   323
    struct SDL_PrivateGLESData *gles_data;
slouken@3161
   324
#endif
slouken@3161
   325
slouken@2753
   326
    /* * * */
slouken@2753
   327
    /* The function used to dispose of this structure */
slouken@2753
   328
    void (*free) (_THIS);
slouken@1895
   329
};
slouken@0
   330
slouken@2753
   331
typedef struct VideoBootStrap
slouken@2753
   332
{
slouken@2753
   333
    const char *name;
slouken@2753
   334
    const char *desc;
slouken@2753
   335
    int (*available) (void);
slouken@2753
   336
    SDL_VideoDevice *(*create) (int devindex);
slouken@2753
   337
} VideoBootStrap;
slouken@0
   338
slouken@1931
   339
#if SDL_VIDEO_DRIVER_COCOA
slouken@1931
   340
extern VideoBootStrap COCOA_bootstrap;
slouken@1361
   341
#endif
slouken@1361
   342
#if SDL_VIDEO_DRIVER_X11
slouken@0
   343
extern VideoBootStrap X11_bootstrap;
slouken@0
   344
#endif
slouken@1361
   345
#if SDL_VIDEO_DRIVER_DIRECTFB
slouken@167
   346
extern VideoBootStrap DirectFB_bootstrap;
slouken@167
   347
#endif
slouken@5062
   348
#if SDL_VIDEO_DRIVER_WINDOWS
slouken@5062
   349
extern VideoBootStrap WINDOWS_bootstrap;
slouken@1361
   350
#endif
icculus@7981
   351
#if SDL_VIDEO_DRIVER_HAIKU
icculus@7981
   352
extern VideoBootStrap HAIKU_bootstrap;
slouken@1361
   353
#endif
slouken@5150
   354
#if SDL_VIDEO_DRIVER_PANDORA
slouken@5150
   355
extern VideoBootStrap PND_bootstrap;
slouken@3083
   356
#endif
hfutrell@2742
   357
#if SDL_VIDEO_DRIVER_UIKIT
hfutrell@2742
   358
extern VideoBootStrap UIKIT_bootstrap;
hfutrell@2742
   359
#endif
slouken@5150
   360
#if SDL_VIDEO_DRIVER_ANDROID
slouken@5150
   361
extern VideoBootStrap Android_bootstrap;
slouken@5150
   362
#endif
kimonline@7009
   363
#if SDL_VIDEO_DRIVER_PSP
kimonline@7009
   364
extern VideoBootStrap PSP_bootstrap;
kimonline@7009
   365
#endif
gabomdq@7753
   366
#if SDL_VIDEO_DRIVER_RPI
gabomdq@7753
   367
extern VideoBootStrap RPI_bootstrap;
gabomdq@7753
   368
#endif
slouken@1361
   369
#if SDL_VIDEO_DRIVER_DUMMY
slouken@173
   370
extern VideoBootStrap DUMMY_bootstrap;
slouken@173
   371
#endif
gabomdq@8062
   372
#if SDL_VIDEO_DRIVER_WAYLAND
gabomdq@8062
   373
extern VideoBootStrap Wayland_bootstrap;
gabomdq@8062
   374
#endif
slouken@1361
   375
slouken@4472
   376
extern SDL_VideoDevice *SDL_GetVideoDevice(void);
slouken@2753
   377
extern int SDL_AddBasicVideoDisplay(const SDL_DisplayMode * desktop_mode);
slouken@2753
   378
extern int SDL_AddVideoDisplay(const SDL_VideoDisplay * display);
slouken@3500
   379
extern SDL_bool SDL_AddDisplayMode(SDL_VideoDisplay *display, const SDL_DisplayMode * mode);
slouken@5246
   380
extern SDL_VideoDisplay *SDL_GetDisplayForWindow(SDL_Window *window);
slouken@7742
   381
extern void *SDL_GetDisplayDriverData( int displayIndex );
slouken@1895
   382
slouken@2753
   383
extern int SDL_RecreateWindow(SDL_Window * window, Uint32 flags);
slouken@1895
   384
slouken@2753
   385
extern void SDL_OnWindowShown(SDL_Window * window);
slouken@2753
   386
extern void SDL_OnWindowHidden(SDL_Window * window);
slouken@5166
   387
extern void SDL_OnWindowResized(SDL_Window * window);
slouken@3502
   388
extern void SDL_OnWindowMinimized(SDL_Window * window);
slouken@3502
   389
extern void SDL_OnWindowRestored(SDL_Window * window);
jorgen@7089
   390
extern void SDL_OnWindowEnter(SDL_Window * window);
jorgen@7089
   391
extern void SDL_OnWindowLeave(SDL_Window * window);
slouken@2753
   392
extern void SDL_OnWindowFocusGained(SDL_Window * window);
slouken@2753
   393
extern void SDL_OnWindowFocusLost(SDL_Window * window);
slouken@6662
   394
extern void SDL_UpdateWindowGrab(SDL_Window * window);
slouken@3685
   395
extern SDL_Window * SDL_GetFocusWindow(void);
slouken@0
   396
philipp@7178
   397
extern SDL_bool SDL_ShouldAllowTopmost(void);
slouken@6784
   398
slouken@2753
   399
#endif /* _SDL_sysvideo_h */
slouken@1895
   400
slouken@1895
   401
/* vi: set ts=4 sw=4 expandtab: */