src/video/SDL_sysvideo.h
author Sam Lantinga <slouken@libsdl.org>
Wed, 15 Aug 2007 03:52:31 +0000
changeset 2245 989fb86ad1ec
parent 2062 c9aa6bcb26f3
child 2268 4baee598306d
permissions -rw-r--r--
Optimization suggested by Ryan:
Don't set the same OpenGL context multiple times
slouken@0
     1
/*
slouken@0
     2
    SDL - Simple DirectMedia Layer
slouken@1312
     3
    Copyright (C) 1997-2006 Sam Lantinga
slouken@0
     4
slouken@0
     5
    This library is free software; you can redistribute it and/or
slouken@1312
     6
    modify it under the terms of the GNU Lesser General Public
slouken@0
     7
    License as published by the Free Software Foundation; either
slouken@1312
     8
    version 2.1 of the License, or (at your option) any later version.
slouken@0
     9
slouken@0
    10
    This library is distributed in the hope that it will be useful,
slouken@0
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@0
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@1312
    13
    Lesser General Public License for more details.
slouken@0
    14
slouken@1312
    15
    You should have received a copy of the GNU Lesser General Public
slouken@1312
    16
    License along with this library; if not, write to the Free Software
slouken@1312
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
slouken@0
    18
slouken@0
    19
    Sam Lantinga
slouken@252
    20
    slouken@libsdl.org
slouken@0
    21
*/
slouken@1402
    22
#include "SDL_config.h"
slouken@0
    23
slouken@0
    24
#ifndef _SDL_sysvideo_h
slouken@0
    25
#define _SDL_sysvideo_h
slouken@0
    26
slouken@0
    27
#include "SDL_mouse.h"
slouken@0
    28
slouken@0
    29
/* The SDL video driver */
slouken@1895
    30
slouken@1895
    31
typedef struct SDL_Window SDL_Window;
slouken@1895
    32
typedef struct SDL_Texture SDL_Texture;
slouken@1895
    33
typedef struct SDL_Renderer SDL_Renderer;
slouken@1895
    34
typedef struct SDL_RenderDriver SDL_RenderDriver;
slouken@1895
    35
typedef struct SDL_VideoDisplay SDL_VideoDisplay;
slouken@0
    36
typedef struct SDL_VideoDevice SDL_VideoDevice;
slouken@0
    37
slouken@1895
    38
/* Define the SDL texture structure */
slouken@1895
    39
struct SDL_Texture
slouken@1895
    40
{
slouken@1895
    41
    Uint32 id;
slouken@1895
    42
slouken@1895
    43
    Uint32 format;      /**< The pixel format of the texture */
slouken@1895
    44
    int access;         /**< SDL_TextureAccess */
slouken@1895
    45
    int w;              /**< The width of the texture */
slouken@1895
    46
    int h;              /**< The height of the texture */
slouken@1985
    47
    int modMode;        /**< The texture modulation mode */
slouken@1985
    48
    int blendMode;      /**< The texture blend mode */
slouken@1985
    49
    int scaleMode;      /**< The texture scale mode */
slouken@1985
    50
    Uint8 r, g, b, a;   /**< Texture modulation values */
slouken@1895
    51
slouken@1895
    52
    SDL_Renderer *renderer;
slouken@1895
    53
slouken@1895
    54
    void *driverdata;   /**< Driver specific texture representation */
slouken@1895
    55
slouken@1895
    56
    SDL_Texture *next;
slouken@1895
    57
};
slouken@1895
    58
slouken@1895
    59
/* Define the SDL renderer structure */
slouken@1895
    60
struct SDL_Renderer
slouken@1895
    61
{
slouken@1923
    62
    int (*ActivateRenderer) (SDL_Renderer * renderer);
slouken@1970
    63
    int (*DisplayModeChanged) (SDL_Renderer * renderer);
slouken@1895
    64
    int (*CreateTexture) (SDL_Renderer * renderer, SDL_Texture * texture);
slouken@1895
    65
    int (*QueryTexturePixels) (SDL_Renderer * renderer, SDL_Texture * texture,
slouken@1895
    66
                               void **pixels, int *pitch);
slouken@1895
    67
    int (*SetTexturePalette) (SDL_Renderer * renderer, SDL_Texture * texture,
slouken@1895
    68
                              const SDL_Color * colors, int firstcolor,
slouken@1895
    69
                              int ncolors);
slouken@1895
    70
    int (*GetTexturePalette) (SDL_Renderer * renderer, SDL_Texture * texture,
slouken@1895
    71
                              SDL_Color * colors, int firstcolor,
slouken@1895
    72
                              int ncolors);
slouken@1985
    73
    int (*SetTextureColorMod) (SDL_Renderer * renderer,
slouken@1985
    74
                               SDL_Texture * texture);
slouken@1985
    75
    int (*SetTextureAlphaMod) (SDL_Renderer * renderer,
slouken@1985
    76
                               SDL_Texture * texture);
slouken@1985
    77
    int (*SetTextureBlendMode) (SDL_Renderer * renderer,
slouken@1985
    78
                                SDL_Texture * texture);
slouken@1985
    79
    int (*SetTextureScaleMode) (SDL_Renderer * renderer,
slouken@1985
    80
                                SDL_Texture * texture);
slouken@1895
    81
    int (*UpdateTexture) (SDL_Renderer * renderer, SDL_Texture * texture,
slouken@1895
    82
                          const SDL_Rect * rect, const void *pixels,
slouken@1895
    83
                          int pitch);
slouken@1895
    84
    int (*LockTexture) (SDL_Renderer * renderer, SDL_Texture * texture,
slouken@1895
    85
                        const SDL_Rect * rect, int markDirty, void **pixels,
slouken@1895
    86
                        int *pitch);
slouken@1895
    87
    void (*UnlockTexture) (SDL_Renderer * renderer, SDL_Texture * texture);
slouken@1895
    88
    void (*DirtyTexture) (SDL_Renderer * renderer, SDL_Texture * texture,
slouken@1895
    89
                          int numrects, const SDL_Rect * rects);
slouken@1985
    90
    int (*RenderFill) (SDL_Renderer * renderer, Uint8 r, Uint8 g, Uint8 b,
slouken@1985
    91
                       Uint8 a, const SDL_Rect * rect);
slouken@1895
    92
    int (*RenderCopy) (SDL_Renderer * renderer, SDL_Texture * texture,
slouken@1985
    93
                       const SDL_Rect * srcrect, const SDL_Rect * dstrect);
slouken@1895
    94
    void (*RenderPresent) (SDL_Renderer * renderer);
slouken@1895
    95
    void (*DestroyTexture) (SDL_Renderer * renderer, SDL_Texture * texture);
slouken@1895
    96
slouken@1895
    97
    void (*DestroyRenderer) (SDL_Renderer * renderer);
slouken@1895
    98
slouken@1895
    99
    /* The current renderer info */
slouken@1895
   100
    SDL_RendererInfo info;
slouken@1895
   101
slouken@1895
   102
    /* The window associated with the renderer */
slouken@1895
   103
    SDL_WindowID window;
slouken@1895
   104
slouken@1895
   105
    void *driverdata;
slouken@1895
   106
};
slouken@1895
   107
slouken@1895
   108
/* Define the SDL render driver structure */
slouken@1895
   109
struct SDL_RenderDriver
slouken@1895
   110
{
slouken@1895
   111
    SDL_Renderer *(*CreateRenderer) (SDL_Window * window, Uint32 flags);
slouken@1895
   112
slouken@1895
   113
    /* Info about the renderer capabilities */
slouken@1895
   114
    SDL_RendererInfo info;
slouken@1895
   115
};
slouken@1895
   116
slouken@1895
   117
/* Define the SDL window structure, corresponding to toplevel windows */
slouken@1895
   118
struct SDL_Window
slouken@1895
   119
{
slouken@1895
   120
    Uint32 id;
slouken@1895
   121
slouken@1895
   122
    char *title;
slouken@1895
   123
    int x, y;
slouken@1895
   124
    int w, h;
slouken@1895
   125
    Uint32 flags;
slouken@1895
   126
slouken@1895
   127
    int display;
slouken@1895
   128
    SDL_Renderer *renderer;
slouken@2245
   129
    SDL_GLContext context;
slouken@1895
   130
slouken@1895
   131
    void *userdata;
slouken@1895
   132
    void *driverdata;
slouken@1895
   133
};
slouken@1895
   134
#define FULLSCREEN_VISIBLE(W) \
slouken@1895
   135
    (((W)->flags & SDL_WINDOW_FULLSCREEN) && \
slouken@1895
   136
     ((W)->flags & SDL_WINDOW_SHOWN) && \
slouken@1895
   137
     !((W)->flags & SDL_WINDOW_MINIMIZED))
slouken@1895
   138
slouken@1895
   139
/* Define the SDL display structure
slouken@1895
   140
   This corresponds to physical monitors attached to the system.
slouken@1895
   141
 */
slouken@1895
   142
struct SDL_VideoDisplay
slouken@1895
   143
{
slouken@1895
   144
    int max_display_modes;
slouken@1895
   145
    int num_display_modes;
slouken@1895
   146
    SDL_DisplayMode *display_modes;
slouken@1895
   147
    SDL_DisplayMode desktop_mode;
slouken@1895
   148
    SDL_DisplayMode current_mode;
slouken@1970
   149
    SDL_DisplayMode fullscreen_mode;
slouken@1895
   150
    SDL_Palette *palette;
slouken@1895
   151
slouken@1895
   152
    Uint16 *gamma;
slouken@1895
   153
    Uint16 *saved_gamma;        /* (just offset into gamma) */
slouken@1895
   154
slouken@1895
   155
    int num_render_drivers;
slouken@1895
   156
    SDL_RenderDriver *render_drivers;
slouken@1895
   157
slouken@1895
   158
    int num_windows;
slouken@1895
   159
    SDL_Window *windows;
slouken@1895
   160
slouken@1895
   161
    SDL_Renderer *current_renderer;
slouken@1895
   162
slouken@1895
   163
    /* The hash list of textures */
slouken@1895
   164
    SDL_Texture *textures[64];
slouken@1895
   165
slouken@1895
   166
    SDL_VideoDevice *device;
slouken@1895
   167
slouken@1895
   168
    void *driverdata;
slouken@1895
   169
};
slouken@1895
   170
slouken@0
   171
/* Define the SDL video driver structure */
slouken@0
   172
#define _THIS	SDL_VideoDevice *_this
slouken@0
   173
slouken@1895
   174
struct SDL_VideoDevice
slouken@1895
   175
{
slouken@1895
   176
    /* * * */
slouken@1895
   177
    /* The name of this video driver */
slouken@1895
   178
    const char *name;
slouken@0
   179
slouken@1895
   180
    /* * * */
slouken@1895
   181
    /* Initialization/Query functions */
slouken@0
   182
slouken@1895
   183
    /* Initialize the native video subsystem, filling in the list
slouken@1895
   184
       of displays for this driver, returning 0 or -1 if there's an error.
slouken@1895
   185
     */
slouken@1895
   186
    int (*VideoInit) (_THIS);
slouken@0
   187
slouken@1913
   188
    /* Reverse the effects VideoInit() -- called if VideoInit() fails
slouken@1913
   189
       or if the application is shutting down the video subsystem.
slouken@1913
   190
     */
slouken@1913
   191
    void (*VideoQuit) (_THIS);
slouken@1913
   192
slouken@1895
   193
    /* * * */
slouken@1895
   194
    /* Display functions
slouken@1895
   195
     */
slouken@0
   196
slouken@1895
   197
    /* Get a list of the available display modes.
slouken@1895
   198
     * e.g.  SDL_AddDisplayMode(_this->current_display, mode)
slouken@1895
   199
     */
slouken@1895
   200
    void (*GetDisplayModes) (_THIS);
slouken@0
   201
slouken@1895
   202
    /* Setting the display mode is independent of creating windows,
slouken@1895
   203
     * so when the display mode is changed, all existing windows
slouken@1895
   204
     * should have their data updated accordingly, including the
slouken@1895
   205
     * display surfaces associated with them.
slouken@1895
   206
     */
slouken@1895
   207
    int (*SetDisplayMode) (_THIS, SDL_DisplayMode * mode);
slouken@0
   208
slouken@1895
   209
    /* Set the color entries of the display palette */
slouken@1895
   210
    int (*SetDisplayPalette) (_THIS, SDL_Palette * palette);
slouken@0
   211
slouken@1895
   212
    /* Get the color entries of the display palette */
slouken@1895
   213
    int (*GetDisplayPalette) (_THIS, SDL_Palette * palette);
slouken@0
   214
slouken@1895
   215
    /* Set the gamma ramp */
slouken@1895
   216
    int (*SetDisplayGammaRamp) (_THIS, Uint16 * ramp);
slouken@0
   217
slouken@1895
   218
    /* Get the gamma ramp */
slouken@1895
   219
    int (*GetDisplayGammaRamp) (_THIS, Uint16 * ramp);
slouken@0
   220
slouken@1895
   221
    /* * * */
slouken@1895
   222
    /* Window functions
slouken@1895
   223
     */
slouken@1895
   224
    int (*CreateWindow) (_THIS, SDL_Window * window);
slouken@1895
   225
    int (*CreateWindowFrom) (_THIS, SDL_Window * window, const void *data);
slouken@1895
   226
    void (*SetWindowTitle) (_THIS, SDL_Window * window);
slouken@1895
   227
    void (*SetWindowPosition) (_THIS, SDL_Window * window);
slouken@1895
   228
    void (*SetWindowSize) (_THIS, SDL_Window * window);
slouken@1895
   229
    void (*ShowWindow) (_THIS, SDL_Window * window);
slouken@1895
   230
    void (*HideWindow) (_THIS, SDL_Window * window);
slouken@1895
   231
    void (*RaiseWindow) (_THIS, SDL_Window * window);
slouken@1895
   232
    void (*MaximizeWindow) (_THIS, SDL_Window * window);
slouken@1895
   233
    void (*MinimizeWindow) (_THIS, SDL_Window * window);
slouken@1895
   234
    void (*RestoreWindow) (_THIS, SDL_Window * window);
slouken@1895
   235
    void (*SetWindowGrab) (_THIS, SDL_Window * window);
slouken@1895
   236
    void (*DestroyWindow) (_THIS, SDL_Window * window);
slouken@0
   237
slouken@1895
   238
    /* Get some platform dependent window information */
slouken@1895
   239
      SDL_bool(*GetWindowWMInfo) (_THIS, SDL_Window * window,
slouken@1895
   240
                                  struct SDL_SysWMinfo * info);
slouken@0
   241
slouken@1895
   242
    /* * * */
slouken@1912
   243
    /* OpenGL support
slouken@1912
   244
     */
slouken@1895
   245
    int (*GL_LoadLibrary) (_THIS, const char *path);
slouken@1895
   246
    void *(*GL_GetProcAddress) (_THIS, const char *proc);
slouken@1912
   247
      SDL_GLContext(*GL_CreateContext) (_THIS, SDL_Window * window);
slouken@1912
   248
    int (*GL_MakeCurrent) (_THIS, SDL_Window * window, SDL_GLContext context);
slouken@1912
   249
    int (*GL_SetSwapInterval) (_THIS, int interval);
slouken@1912
   250
    int (*GL_GetSwapInterval) (_THIS);
slouken@1912
   251
    void (*GL_SwapWindow) (_THIS, SDL_Window * window);
slouken@1912
   252
    void (*GL_DeleteContext) (_THIS, SDL_GLContext context);
slouken@0
   253
slouken@1895
   254
    /* * * */
slouken@1912
   255
    /* Event manager functions
slouken@1912
   256
     */
slouken@1895
   257
    void (*PumpEvents) (_THIS);
slouken@0
   258
slouken@1895
   259
    /* * * */
slouken@1895
   260
    /* Data common to all drivers */
slouken@1895
   261
    int num_displays;
slouken@1895
   262
    SDL_VideoDisplay *displays;
slouken@1895
   263
    int current_display;
slouken@1895
   264
    Uint32 next_object_id;
slouken@0
   265
slouken@1895
   266
    /* * * */
slouken@1895
   267
    /* Data used by the GL drivers */
slouken@1895
   268
    struct
slouken@1895
   269
    {
slouken@1895
   270
        int red_size;
slouken@1895
   271
        int green_size;
slouken@1895
   272
        int blue_size;
slouken@1895
   273
        int alpha_size;
slouken@1895
   274
        int depth_size;
slouken@1895
   275
        int buffer_size;
slouken@1895
   276
        int stencil_size;
slouken@1895
   277
        int double_buffer;
slouken@1895
   278
        int accum_red_size;
slouken@1895
   279
        int accum_green_size;
slouken@1895
   280
        int accum_blue_size;
slouken@1895
   281
        int accum_alpha_size;
slouken@1895
   282
        int stereo;
slouken@1895
   283
        int multisamplebuffers;
slouken@1895
   284
        int multisamplesamples;
slouken@1895
   285
        int accelerated;
slouken@1895
   286
        int driver_loaded;
slouken@1895
   287
        char driver_path[256];
slouken@1895
   288
        void *dll_handle;
slouken@1895
   289
    } gl_config;
slouken@0
   290
slouken@1895
   291
    /* * * */
slouken@1895
   292
    /* Data private to this driver */
slouken@1895
   293
    void *driverdata;
slouken@1913
   294
    struct SDL_GLDriverData *gl_data;
slouken@0
   295
slouken@1895
   296
    /* * * */
slouken@1895
   297
    /* The function used to dispose of this structure */
slouken@1895
   298
    void (*free) (_THIS);
slouken@1895
   299
};
slouken@0
   300
slouken@1895
   301
typedef struct VideoBootStrap
slouken@1895
   302
{
slouken@1895
   303
    const char *name;
slouken@1895
   304
    const char *desc;
slouken@1895
   305
    int (*available) (void);
slouken@1895
   306
    SDL_VideoDevice *(*create) (int devindex);
slouken@0
   307
} VideoBootStrap;
slouken@0
   308
slouken@1931
   309
#if SDL_VIDEO_DRIVER_COCOA
slouken@1931
   310
extern VideoBootStrap COCOA_bootstrap;
slouken@1361
   311
#endif
slouken@1361
   312
#if SDL_VIDEO_DRIVER_X11
slouken@0
   313
extern VideoBootStrap X11_bootstrap;
slouken@0
   314
#endif
slouken@1361
   315
#if SDL_VIDEO_DRIVER_NANOX
slouken@30
   316
extern VideoBootStrap NX_bootstrap;
slouken@30
   317
#endif
slouken@1361
   318
#if SDL_VIDEO_DRIVER_IPOD
icculus@1140
   319
extern VideoBootStrap iPod_bootstrap;
icculus@1140
   320
#endif
slouken@1361
   321
#if SDL_VIDEO_DRIVER_WSCONS
slouken@1361
   322
extern VideoBootStrap WSCONS_bootstrap;
slouken@1361
   323
#endif
slouken@1361
   324
#if SDL_VIDEO_DRIVER_FBCON
slouken@0
   325
extern VideoBootStrap FBCON_bootstrap;
slouken@0
   326
#endif
slouken@1361
   327
#if SDL_VIDEO_DRIVER_DIRECTFB
slouken@167
   328
extern VideoBootStrap DirectFB_bootstrap;
slouken@167
   329
#endif
slouken@1361
   330
#if SDL_VIDEO_DRIVER_PS2GS
slouken@0
   331
extern VideoBootStrap PS2GS_bootstrap;
slouken@0
   332
#endif
slouken@1361
   333
#if SDL_VIDEO_DRIVER_VGL
slouken@75
   334
extern VideoBootStrap VGL_bootstrap;
slouken@75
   335
#endif
slouken@1361
   336
#if SDL_VIDEO_DRIVER_SVGALIB
slouken@0
   337
extern VideoBootStrap SVGALIB_bootstrap;
slouken@0
   338
#endif
slouken@1361
   339
#if SDL_VIDEO_DRIVER_GAPI
slouken@1361
   340
extern VideoBootStrap GAPI_bootstrap;
slouken@1361
   341
#endif
slouken@1895
   342
#if SDL_VIDEO_DRIVER_WIN32
slouken@1895
   343
extern VideoBootStrap WIN32_bootstrap;
slouken@1361
   344
#endif
slouken@1361
   345
#if SDL_VIDEO_DRIVER_BWINDOW
slouken@1361
   346
extern VideoBootStrap BWINDOW_bootstrap;
slouken@1361
   347
#endif
slouken@1361
   348
#if SDL_VIDEO_DRIVER_PHOTON
slouken@1361
   349
extern VideoBootStrap ph_bootstrap;
slouken@1361
   350
#endif
slouken@1361
   351
#if SDL_VIDEO_DRIVER_EPOC
slouken@1361
   352
extern VideoBootStrap EPOC_bootstrap;
slouken@1361
   353
#endif
slouken@1361
   354
#if SDL_VIDEO_DRIVER_XBIOS
slouken@1361
   355
extern VideoBootStrap XBIOS_bootstrap;
slouken@1361
   356
#endif
slouken@1361
   357
#if SDL_VIDEO_DRIVER_GEM
slouken@1361
   358
extern VideoBootStrap GEM_bootstrap;
slouken@1361
   359
#endif
slouken@1361
   360
#if SDL_VIDEO_DRIVER_DC
slouken@1361
   361
extern VideoBootStrap DC_bootstrap;
slouken@1361
   362
#endif
slouken@1361
   363
#if SDL_VIDEO_DRIVER_RISCOS
slouken@1361
   364
extern VideoBootStrap RISCOS_bootstrap;
slouken@1361
   365
#endif
slouken@1361
   366
#if SDL_VIDEO_DRIVER_OS2FS
slouken@1361
   367
extern VideoBootStrap OS2FSLib_bootstrap;
slouken@1361
   368
#endif
slouken@1361
   369
#if SDL_VIDEO_DRIVER_DUMMY
slouken@173
   370
extern VideoBootStrap DUMMY_bootstrap;
slouken@173
   371
#endif
slouken@1361
   372
slouken@1895
   373
#define SDL_CurrentDisplay	(_this->displays[_this->current_display])
slouken@0
   374
slouken@1895
   375
extern SDL_VideoDevice *SDL_GetVideoDevice();
slouken@1895
   376
extern int SDL_AddBasicVideoDisplay(const SDL_DisplayMode * desktop_mode);
slouken@1895
   377
extern int SDL_AddVideoDisplay(const SDL_VideoDisplay * display);
slouken@1895
   378
extern SDL_bool SDL_AddDisplayMode(int displayIndex,
slouken@1895
   379
                                   const SDL_DisplayMode * mode);
slouken@1895
   380
extern void SDL_AddRenderDriver(int displayIndex,
slouken@1895
   381
                                const SDL_RenderDriver * driver);
slouken@1895
   382
slouken@1928
   383
extern int SDL_RecreateWindow(SDL_Window * window, Uint32 flags);
slouken@1895
   384
extern SDL_Window *SDL_GetWindowFromID(SDL_WindowID windowID);
slouken@1895
   385
extern SDL_VideoDisplay *SDL_GetDisplayFromWindow(SDL_Window * window);
slouken@1895
   386
slouken@1895
   387
extern void SDL_OnWindowShown(SDL_Window * window);
slouken@1895
   388
extern void SDL_OnWindowHidden(SDL_Window * window);
slouken@1970
   389
extern void SDL_OnWindowResized(SDL_Window * window);
slouken@1895
   390
extern void SDL_OnWindowFocusGained(SDL_Window * window);
slouken@1895
   391
extern void SDL_OnWindowFocusLost(SDL_Window * window);
slouken@1895
   392
extern SDL_WindowID SDL_GetFocusWindow(void);
slouken@0
   393
slouken@0
   394
#endif /* _SDL_sysvideo_h */
slouken@1895
   395
slouken@1895
   396
/* vi: set ts=4 sw=4 expandtab: */