src/video/SDL_sysvideo.h
author Sam Lantinga <slouken@libsdl.org>
Wed, 07 Jul 2010 23:54:03 -0700
changeset 4495 dbbfdb9ea716
parent 4472 791b3256fb22
child 4569 e1664f94f026
child 4755 436183eb30c8
permissions -rw-r--r--
Simplified clipboard API for sanity's sake.

A complete clipboard implementation would support multiple formats that could be queried at runtime, events for when the clipboard contents changed, support for HTML, images, etc. We're not going that crazy, at least for now. :)
     1 /*
     2     SDL - Simple DirectMedia Layer
     3     Copyright (C) 1997-2010 Sam Lantinga
     4 
     5     This library is free software; you can redistribute it and/or
     6     modify it under the terms of the GNU Lesser General Public
     7     License as published by the Free Software Foundation; either
     8     version 2.1 of the License, or (at your option) any later version.
     9 
    10     This library is distributed in the hope that it will be useful,
    11     but WITHOUT ANY WARRANTY; without even the implied warranty of
    12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    13     Lesser General Public License for more details.
    14 
    15     You should have received a copy of the GNU Lesser General Public
    16     License along with this library; if not, write to the Free Software
    17     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    18 
    19     Sam Lantinga
    20     slouken@libsdl.org
    21 */
    22 #include "SDL_config.h"
    23 
    24 #ifndef _SDL_sysvideo_h
    25 #define _SDL_sysvideo_h
    26 
    27 #include "SDL_mouse.h"
    28 #include "SDL_keysym.h"
    29 
    30 /* The SDL video driver */
    31 
    32 typedef struct SDL_Renderer SDL_Renderer;
    33 typedef struct SDL_RenderDriver SDL_RenderDriver;
    34 typedef struct SDL_VideoDisplay SDL_VideoDisplay;
    35 typedef struct SDL_VideoDevice SDL_VideoDevice;
    36 
    37 /* Define the SDL texture structure */
    38 struct SDL_Texture
    39 {
    40     const void *magic;
    41     Uint32 format;              /**< The pixel format of the texture */
    42     int access;                 /**< SDL_TextureAccess */
    43     int w;                      /**< The width of the texture */
    44     int h;                      /**< The height of the texture */
    45     int modMode;                /**< The texture modulation mode */
    46     int blendMode;              /**< The texture blend mode */
    47     int scaleMode;              /**< The texture scale mode */
    48     Uint8 r, g, b, a;           /**< Texture modulation values */
    49 
    50     SDL_Renderer *renderer;
    51 
    52     void *driverdata;           /**< Driver specific texture representation */
    53 
    54     SDL_Texture *prev;
    55     SDL_Texture *next;
    56 };
    57 
    58 /* Define the SDL renderer structure */
    59 struct SDL_Renderer
    60 {
    61     int (*ActivateRenderer) (SDL_Renderer * renderer);
    62     int (*DisplayModeChanged) (SDL_Renderer * renderer);
    63     int (*CreateTexture) (SDL_Renderer * renderer, SDL_Texture * texture);
    64     int (*QueryTexturePixels) (SDL_Renderer * renderer, SDL_Texture * texture,
    65                                void **pixels, int *pitch);
    66     int (*SetTexturePalette) (SDL_Renderer * renderer, SDL_Texture * texture,
    67                               const SDL_Color * colors, int firstcolor,
    68                               int ncolors);
    69     int (*GetTexturePalette) (SDL_Renderer * renderer, SDL_Texture * texture,
    70                               SDL_Color * colors, int firstcolor,
    71                               int ncolors);
    72     int (*SetTextureColorMod) (SDL_Renderer * renderer,
    73                                SDL_Texture * texture);
    74     int (*SetTextureAlphaMod) (SDL_Renderer * renderer,
    75                                SDL_Texture * texture);
    76     int (*SetTextureBlendMode) (SDL_Renderer * renderer,
    77                                 SDL_Texture * texture);
    78     int (*SetTextureScaleMode) (SDL_Renderer * renderer,
    79                                 SDL_Texture * texture);
    80     int (*UpdateTexture) (SDL_Renderer * renderer, SDL_Texture * texture,
    81                           const SDL_Rect * rect, const void *pixels,
    82                           int pitch);
    83     int (*LockTexture) (SDL_Renderer * renderer, SDL_Texture * texture,
    84                         const SDL_Rect * rect, int markDirty, void **pixels,
    85                         int *pitch);
    86     void (*UnlockTexture) (SDL_Renderer * renderer, SDL_Texture * texture);
    87     void (*DirtyTexture) (SDL_Renderer * renderer, SDL_Texture * texture,
    88                           int numrects, const SDL_Rect * rects);
    89     int (*SetDrawColor) (SDL_Renderer * renderer);
    90     int (*SetDrawBlendMode) (SDL_Renderer * renderer);
    91     int (*RenderClear) (SDL_Renderer * renderer);
    92     int (*RenderDrawPoints) (SDL_Renderer * renderer, const SDL_Point * points,
    93                              int count);
    94     int (*RenderDrawLines) (SDL_Renderer * renderer, const SDL_Point * points,
    95                             int count);
    96     int (*RenderDrawRects) (SDL_Renderer * renderer, const SDL_Rect ** rects,
    97                             int count);
    98     int (*RenderFillRects) (SDL_Renderer * renderer, const SDL_Rect ** rects,
    99                             int count);
   100     int (*RenderDrawEllipse) (SDL_Renderer * renderer, int x, int y,
   101                               int w, int h);
   102     int (*RenderFillEllipse) (SDL_Renderer * renderer, int x, int y,
   103                               int w, int h);
   104     int (*RenderCopy) (SDL_Renderer * renderer, SDL_Texture * texture,
   105                        const SDL_Rect * srcrect, const SDL_Rect * dstrect);
   106     int (*RenderReadPixels) (SDL_Renderer * renderer, const SDL_Rect * rect,
   107                              Uint32 format, void * pixels, int pitch);
   108     int (*RenderWritePixels) (SDL_Renderer * renderer, const SDL_Rect * rect,
   109                               Uint32 format, const void * pixels, int pitch);
   110     void (*RenderPresent) (SDL_Renderer * renderer);
   111     void (*DestroyTexture) (SDL_Renderer * renderer, SDL_Texture * texture);
   112 
   113     void (*DestroyRenderer) (SDL_Renderer * renderer);
   114 
   115     /* The current renderer info */
   116     SDL_RendererInfo info;
   117 
   118     /* The window associated with the renderer */
   119     SDL_Window *window;
   120 
   121     /* The list of textures */
   122     SDL_Texture *textures;
   123 
   124     Uint8 r, g, b, a;                   /**< Color for drawing operations values */
   125     int blendMode;                      /**< The drawing blend mode */
   126 
   127     void *driverdata;
   128 };
   129 
   130 /* Define the SDL render driver structure */
   131 struct SDL_RenderDriver
   132 {
   133     SDL_Renderer *(*CreateRenderer) (SDL_Window * window, Uint32 flags);
   134 
   135     /* Info about the renderer capabilities */
   136     SDL_RendererInfo info;
   137 };
   138 
   139 /* Define the SDL window structure, corresponding to toplevel windows */
   140 struct SDL_Window
   141 {
   142     const void *magic;
   143     Uint32 id;
   144     char *title;
   145     int x, y;
   146     int w, h;
   147     Uint32 flags;
   148 
   149     SDL_VideoDisplay *display;
   150     SDL_Renderer *renderer;
   151 
   152     SDL_DisplayMode fullscreen_mode;
   153 
   154     void *userdata;
   155     void *driverdata;
   156 
   157     SDL_Window *prev;
   158     SDL_Window *next;
   159 };
   160 #define FULLSCREEN_VISIBLE(W) \
   161     (((W)->flags & SDL_WINDOW_FULLSCREEN) && \
   162      ((W)->flags & SDL_WINDOW_SHOWN) && \
   163      !((W)->flags & SDL_WINDOW_MINIMIZED))
   164 
   165 /*
   166  * Define the SDL display structure This corresponds to physical monitors
   167  * attached to the system.
   168  */
   169 struct SDL_VideoDisplay
   170 {
   171     int max_display_modes;
   172     int num_display_modes;
   173     SDL_DisplayMode *display_modes;
   174     SDL_DisplayMode desktop_mode;
   175     SDL_DisplayMode current_mode;
   176     SDL_bool updating_fullscreen;
   177     SDL_Palette *palette;
   178 
   179     Uint16 *gamma;
   180     Uint16 *saved_gamma;        /* (just offset into gamma) */
   181 
   182     int num_render_drivers;
   183     SDL_RenderDriver *render_drivers;
   184 
   185     SDL_Window *windows;
   186     SDL_Window *fullscreen_window;
   187 
   188     SDL_Renderer *current_renderer;
   189 
   190     SDL_VideoDevice *device;
   191 
   192     void *driverdata;
   193 };
   194 
   195 /* Define the SDL video driver structure */
   196 #define _THIS	SDL_VideoDevice *_this
   197 
   198 struct SDL_VideoDevice
   199 {
   200     /* * * */
   201     /* The name of this video driver */
   202     const char *name;
   203 
   204     /* * * */
   205     /* Initialization/Query functions */
   206 
   207     /*
   208      * Initialize the native video subsystem, filling in the list of
   209      * displays for this driver, returning 0 or -1 if there's an error.
   210      */
   211     int (*VideoInit) (_THIS);
   212 
   213     /*
   214      * Reverse the effects VideoInit() -- called if VideoInit() fails or
   215      * if the application is shutting down the video subsystem.
   216      */
   217     void (*VideoQuit) (_THIS);
   218 
   219     /* * * */
   220     /*
   221      * Display functions
   222      */
   223 
   224     /*
   225      * Get the bounds of a display
   226      */
   227     int (*GetDisplayBounds) (_THIS, SDL_VideoDisplay * display, SDL_Rect * rect);
   228 
   229     /*
   230      * Get a list of the available display modes. e.g.
   231      * SDL_AddDisplayMode(_this->current_display, mode)
   232      */
   233     void (*GetDisplayModes) (_THIS, SDL_VideoDisplay * display);
   234 
   235     /*
   236      * Setting the display mode is independent of creating windows, so
   237      * when the display mode is changed, all existing windows should have
   238      * their data updated accordingly, including the display surfaces
   239      * associated with them.
   240      */
   241     int (*SetDisplayMode) (_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode);
   242 
   243     /* Set the color entries of the display palette */
   244     int (*SetDisplayPalette) (_THIS, SDL_VideoDisplay * display, SDL_Palette * palette);
   245 
   246     /* Get the color entries of the display palette */
   247     int (*GetDisplayPalette) (_THIS, SDL_VideoDisplay * display, SDL_Palette * palette);
   248 
   249     /* Set the gamma ramp */
   250     int (*SetDisplayGammaRamp) (_THIS, SDL_VideoDisplay * display, Uint16 * ramp);
   251 
   252     /* Get the gamma ramp */
   253     int (*GetDisplayGammaRamp) (_THIS, SDL_VideoDisplay * display, Uint16 * ramp);
   254 
   255     /* * * */
   256     /*
   257      * Window functions
   258      */
   259     int (*CreateWindow) (_THIS, SDL_Window * window);
   260     int (*CreateWindowFrom) (_THIS, SDL_Window * window, const void *data);
   261     void (*SetWindowTitle) (_THIS, SDL_Window * window);
   262     void (*SetWindowIcon) (_THIS, SDL_Window * window, SDL_Surface * icon);
   263     void (*SetWindowPosition) (_THIS, SDL_Window * window);
   264     void (*SetWindowSize) (_THIS, SDL_Window * window);
   265     void (*ShowWindow) (_THIS, SDL_Window * window);
   266     void (*HideWindow) (_THIS, SDL_Window * window);
   267     void (*RaiseWindow) (_THIS, SDL_Window * window);
   268     void (*MaximizeWindow) (_THIS, SDL_Window * window);
   269     void (*MinimizeWindow) (_THIS, SDL_Window * window);
   270     void (*RestoreWindow) (_THIS, SDL_Window * window);
   271     void (*SetWindowGrab) (_THIS, SDL_Window * window);
   272     void (*DestroyWindow) (_THIS, SDL_Window * window);
   273 
   274     /* Get some platform dependent window information */
   275       SDL_bool(*GetWindowWMInfo) (_THIS, SDL_Window * window,
   276                                   struct SDL_SysWMinfo * info);
   277 
   278     /* * * */
   279     /*
   280      * OpenGL support
   281      */
   282     int (*GL_LoadLibrary) (_THIS, const char *path);
   283     void *(*GL_GetProcAddress) (_THIS, const char *proc);
   284     void (*GL_UnloadLibrary) (_THIS);
   285       SDL_GLContext(*GL_CreateContext) (_THIS, SDL_Window * window);
   286     int (*GL_MakeCurrent) (_THIS, SDL_Window * window, SDL_GLContext context);
   287     int (*GL_SetSwapInterval) (_THIS, int interval);
   288     int (*GL_GetSwapInterval) (_THIS);
   289     void (*GL_SwapWindow) (_THIS, SDL_Window * window);
   290     void (*GL_DeleteContext) (_THIS, SDL_GLContext context);
   291 
   292     /* * * */
   293     /*
   294      * Event manager functions
   295      */
   296     void (*PumpEvents) (_THIS);
   297 
   298     /* Suspend the screensaver */
   299     void (*SuspendScreenSaver) (_THIS);
   300 
   301     /* Text input */
   302     void (*StartTextInput) (_THIS);
   303     void (*StopTextInput) (_THIS);
   304     void (*SetTextInputRect) (_THIS, SDL_Rect *rect);
   305 
   306     /* Clipboard */
   307     int (*SetClipboardText) (_THIS, const char *text);
   308     char * (*GetClipboardText) (_THIS);
   309     SDL_bool (*HasClipboardText) (_THIS);
   310 
   311     /* * * */
   312     /* Data common to all drivers */
   313     SDL_bool suspend_screensaver;
   314     int num_displays;
   315     SDL_VideoDisplay *displays;
   316     int current_display;
   317     Uint8 window_magic;
   318     Uint8 texture_magic;
   319     Uint32 next_object_id;
   320     char * clipboard_text;
   321 
   322     /* * * */
   323     /* Data used by the GL drivers */
   324     struct
   325     {
   326         int red_size;
   327         int green_size;
   328         int blue_size;
   329         int alpha_size;
   330         int depth_size;
   331         int buffer_size;
   332         int stencil_size;
   333         int double_buffer;
   334         int accum_red_size;
   335         int accum_green_size;
   336         int accum_blue_size;
   337         int accum_alpha_size;
   338         int stereo;
   339         int multisamplebuffers;
   340         int multisamplesamples;
   341         int accelerated;
   342         int major_version;
   343         int minor_version;
   344         int retained_backing;
   345         int driver_loaded;
   346         char driver_path[256];
   347         void *dll_handle;
   348     } gl_config;
   349 
   350     /* * * */
   351     /* Data private to this driver */
   352     void *driverdata;
   353     struct SDL_GLDriverData *gl_data;
   354 
   355 #if SDL_VIDEO_DRIVER_PANDORA
   356     struct SDL_PrivateGLESData *gles_data;
   357 #endif
   358 
   359     /* * * */
   360     /* The function used to dispose of this structure */
   361     void (*free) (_THIS);
   362 };
   363 
   364 typedef struct VideoBootStrap
   365 {
   366     const char *name;
   367     const char *desc;
   368     int (*available) (void);
   369     SDL_VideoDevice *(*create) (int devindex);
   370 } VideoBootStrap;
   371 
   372 #if SDL_VIDEO_DRIVER_COCOA
   373 extern VideoBootStrap COCOA_bootstrap;
   374 #endif
   375 #if SDL_VIDEO_DRIVER_X11
   376 extern VideoBootStrap X11_bootstrap;
   377 #endif
   378 #if SDL_VIDEO_DRIVER_FBCON
   379 extern VideoBootStrap FBCON_bootstrap;
   380 #endif
   381 #if SDL_VIDEO_DRIVER_DIRECTFB
   382 extern VideoBootStrap DirectFB_bootstrap;
   383 #endif
   384 #if SDL_VIDEO_DRIVER_PS3
   385 extern VideoBootStrap PS3_bootstrap;
   386 #endif
   387 #if SDL_VIDEO_DRIVER_SVGALIB
   388 extern VideoBootStrap SVGALIB_bootstrap;
   389 #endif
   390 #if SDL_VIDEO_DRIVER_GAPI
   391 extern VideoBootStrap GAPI_bootstrap;
   392 #endif
   393 #if SDL_VIDEO_DRIVER_WIN32
   394 extern VideoBootStrap WIN32_bootstrap;
   395 #endif
   396 #if SDL_VIDEO_DRIVER_BWINDOW
   397 extern VideoBootStrap BWINDOW_bootstrap;
   398 #endif
   399 #if SDL_VIDEO_DRIVER_PHOTON
   400 extern VideoBootStrap photon_bootstrap;
   401 #endif
   402 #if SDL_VIDEO_DRIVER_QNXGF
   403 extern VideoBootStrap qnxgf_bootstrap;
   404 #endif
   405 #if SDL_VIDEO_DRIVER_EPOC
   406 extern VideoBootStrap EPOC_bootstrap;
   407 #endif
   408 #if SDL_VIDEO_DRIVER_RISCOS
   409 extern VideoBootStrap RISCOS_bootstrap;
   410 #endif
   411 #if SDL_VIDEO_DRIVER_UIKIT
   412 extern VideoBootStrap UIKIT_bootstrap;
   413 #endif
   414 #if SDL_VIDEO_DRIVER_DUMMY
   415 extern VideoBootStrap DUMMY_bootstrap;
   416 #endif
   417 #if SDL_VIDEO_DRIVER_NDS
   418 extern VideoBootStrap NDS_bootstrap;
   419 #endif
   420 #if SDL_VIDEO_DRIVER_PANDORA
   421 extern VideoBootStrap PND_bootstrap;
   422 #endif
   423 
   424 #define SDL_CurrentDisplay	(&_this->displays[_this->current_display])
   425 #define SDL_CurrentRenderer	(SDL_CurrentDisplay->current_renderer)
   426 
   427 extern SDL_VideoDevice *SDL_GetVideoDevice(void);
   428 extern int SDL_AddBasicVideoDisplay(const SDL_DisplayMode * desktop_mode);
   429 extern int SDL_AddVideoDisplay(const SDL_VideoDisplay * display);
   430 extern SDL_bool SDL_AddDisplayMode(SDL_VideoDisplay *display, const SDL_DisplayMode * mode);
   431 extern int SDL_GetNumDisplayModesForDisplay(SDL_VideoDisplay * display);
   432 extern int SDL_GetDisplayModeForDisplay(SDL_VideoDisplay * display, int index, SDL_DisplayMode * mode);
   433 extern int SDL_GetDesktopDisplayModeForDisplay(SDL_VideoDisplay * display, SDL_DisplayMode * mode);
   434 extern int SDL_GetCurrentDisplayModeForDisplay(SDL_VideoDisplay * display, SDL_DisplayMode * mode);
   435 extern SDL_DisplayMode * SDL_GetClosestDisplayModeForDisplay(SDL_VideoDisplay * display, const SDL_DisplayMode * mode, SDL_DisplayMode * closest);
   436 extern int SDL_SetDisplayModeForDisplay(SDL_VideoDisplay * display, const SDL_DisplayMode * mode);
   437 extern int SDL_SetPaletteForDisplay(SDL_VideoDisplay * display, const SDL_Color * colors, int firstcolor, int ncolors);
   438 extern int SDL_GetPaletteForDisplay(SDL_VideoDisplay * display, SDL_Color * colors, int firstcolor, int ncolors);
   439 extern int SDL_SetGammaRampForDisplay(SDL_VideoDisplay * display, const Uint16 * red, const Uint16 * green, const Uint16 * blue);
   440 extern int SDL_GetGammaRampForDisplay(SDL_VideoDisplay * display, Uint16 * red, Uint16 * green, Uint16 * blue);
   441 extern void SDL_AddRenderDriver(SDL_VideoDisplay *display, const SDL_RenderDriver * driver);
   442 
   443 extern int SDL_RecreateWindow(SDL_Window * window, Uint32 flags);
   444 
   445 extern void SDL_OnWindowShown(SDL_Window * window);
   446 extern void SDL_OnWindowHidden(SDL_Window * window);
   447 extern void SDL_OnWindowResized(SDL_Window * window);
   448 extern void SDL_OnWindowMinimized(SDL_Window * window);
   449 extern void SDL_OnWindowRestored(SDL_Window * window);
   450 extern void SDL_OnWindowFocusGained(SDL_Window * window);
   451 extern void SDL_OnWindowFocusLost(SDL_Window * window);
   452 extern SDL_Window * SDL_GetFocusWindow(void);
   453 
   454 #endif /* _SDL_sysvideo_h */
   455 
   456 /* vi: set ts=4 sw=4 expandtab: */