src/video/SDL_sysvideo.h
author Holmes Futrell <hfutrell@umail.ucsb.edu>
Tue, 02 Sep 2008 19:53:56 +0000
changeset 2742 b86247d21929
parent 2735 204be4fc2726
child 2753 0969758c8809
permissions -rw-r--r--
Added retained backing attribute, reference to UIKit renderer
     1 /*
     2     SDL - Simple DirectMedia Layer
     3     Copyright (C) 1997-2006 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_Window SDL_Window;
    33 typedef struct SDL_Texture SDL_Texture;
    34 typedef struct SDL_Renderer SDL_Renderer;
    35 typedef struct SDL_RenderDriver SDL_RenderDriver;
    36 typedef struct SDL_VideoDisplay SDL_VideoDisplay;
    37 typedef struct SDL_VideoDevice SDL_VideoDevice;
    38 
    39 /* Define the SDL texture structure */
    40 struct SDL_Texture {
    41 	Uint32          id;
    42 
    43 	Uint32          format;	/**< The pixel format of the texture */
    44 	int             access;	/**< SDL_TextureAccess */
    45 	int             w;	/**< The width of the texture */
    46 	int             h;	/**< The height of the texture */
    47 	int             modMode;/**< The texture modulation mode */
    48 	int             blendMode;	/**< The texture blend mode */
    49 	int             scaleMode;	/**< The texture scale mode */
    50 	Uint8           r, g, b, a;	/**< Texture modulation values */
    51 
    52 	SDL_Renderer   *renderer;
    53 
    54 	void           *driverdata;	/**< Driver specific texture representation */
    55 
    56 	SDL_Texture    *next;
    57 };
    58 
    59 /* Define the SDL renderer structure */
    60 struct SDL_Renderer {
    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             (*RenderFill) (SDL_Renderer * renderer, Uint8 r, Uint8 g, Uint8 b,
    90 			                    Uint8 a, const SDL_Rect * rect);
    91 	int             (*RenderCopy) (SDL_Renderer * renderer, SDL_Texture * texture,
    92 	                const SDL_Rect * srcrect, const SDL_Rect * dstrect);
    93 	void            (*RenderPresent) (SDL_Renderer * renderer);
    94 	void            (*DestroyTexture) (SDL_Renderer * renderer, SDL_Texture * texture);
    95 
    96 	void            (*DestroyRenderer) (SDL_Renderer * renderer);
    97 
    98 	/* The current renderer info */
    99 	SDL_RendererInfo info;
   100 
   101 	/* The window associated with the renderer */
   102 	SDL_WindowID    window;
   103 
   104 	void           *driverdata;
   105 };
   106 
   107 /* Define the SDL render driver structure */
   108 struct SDL_RenderDriver {
   109 	SDL_Renderer   *(*CreateRenderer) (SDL_Window * window, Uint32 flags);
   110 
   111 	/* Info about the renderer capabilities */
   112 	SDL_RendererInfo info;
   113 };
   114 
   115 /* Define the SDL window structure, corresponding to toplevel windows */
   116 struct SDL_Window {
   117 	Uint32          id;
   118 
   119 	char           *title;
   120 	int             x, y;
   121 	int             w, h;
   122 	Uint32          flags;
   123 
   124 	int             display;
   125 	SDL_Renderer   *renderer;
   126 
   127 	void           *userdata;
   128 	void           *driverdata;
   129 };
   130 #define FULLSCREEN_VISIBLE(W) \
   131     (((W)->flags & SDL_WINDOW_FULLSCREEN) && \
   132      ((W)->flags & SDL_WINDOW_SHOWN) && \
   133      !((W)->flags & SDL_WINDOW_MINIMIZED))
   134 
   135 /*
   136  * Define the SDL display structure This corresponds to physical monitors
   137  * attached to the system.
   138  */
   139 struct SDL_VideoDisplay {
   140 	int             max_display_modes;
   141 	int             num_display_modes;
   142 	SDL_DisplayMode *display_modes;
   143 	SDL_DisplayMode desktop_mode;
   144 	SDL_DisplayMode current_mode;
   145 	SDL_DisplayMode fullscreen_mode;
   146 	SDL_Palette    *palette;
   147 
   148 	Uint16         *gamma;
   149 	Uint16         *saved_gamma;	/* (just offset into gamma) */
   150 
   151 	int             num_render_drivers;
   152 	SDL_RenderDriver *render_drivers;
   153 
   154 	int             num_windows;
   155 	SDL_Window     *windows;
   156 
   157 	SDL_Renderer   *current_renderer;
   158 
   159 	/* The hash list of textures */
   160 	SDL_Texture    *textures[64];
   161 
   162 	SDL_VideoDevice *device;
   163 
   164 	void           *driverdata;
   165 };
   166 
   167 /* Define the SDL video driver structure */
   168 #define _THIS	SDL_VideoDevice *_this
   169 
   170 struct SDL_VideoDevice {
   171 	/* * * */
   172 	/* The name of this video driver */
   173 	const char     *name;
   174 
   175 	/* * * */
   176 	/* Initialization/Query functions */
   177 
   178 	/*
   179 	 * Initialize the native video subsystem, filling in the list of
   180 	 * displays for this driver, returning 0 or -1 if there's an error.
   181 	 */
   182 	int             (*VideoInit) (_THIS);
   183 
   184 	/*
   185 	 * Reverse the effects VideoInit() -- called if VideoInit() fails or
   186 	 * if the application is shutting down the video subsystem.
   187 	 */
   188 	void            (*VideoQuit) (_THIS);
   189 
   190 	/* * * */
   191 	/*
   192 	 * Display functions
   193 	 */
   194 
   195 	/*
   196 	 * Get a list of the available display modes. e.g.
   197 	 * SDL_AddDisplayMode(_this->current_display, mode)
   198 	 */
   199 	void            (*GetDisplayModes) (_THIS);
   200 
   201 	/*
   202 	 * Setting the display mode is independent of creating windows, so
   203 	 * when the display mode is changed, all existing windows should have
   204 	 * their data updated accordingly, including the display surfaces
   205 	 * associated with them.
   206 	 */
   207 	int             (*SetDisplayMode) (_THIS, SDL_DisplayMode * mode);
   208 
   209 	/* Set the color entries of the display palette */
   210 	int             (*SetDisplayPalette) (_THIS, SDL_Palette * palette);
   211 
   212 	/* Get the color entries of the display palette */
   213 	int             (*GetDisplayPalette) (_THIS, SDL_Palette * palette);
   214 
   215 	/* Set the gamma ramp */
   216 	int             (*SetDisplayGammaRamp) (_THIS, Uint16 * ramp);
   217 
   218 	/* Get the gamma ramp */
   219 	int             (*GetDisplayGammaRamp) (_THIS, Uint16 * ramp);
   220 
   221 	/* * * */
   222 	/*
   223 	 * Window functions
   224 	 */
   225 	int             (*CreateWindow) (_THIS, SDL_Window * window);
   226 	int             (*CreateWindowFrom) (_THIS, SDL_Window * window, const void *data);
   227 	void            (*SetWindowTitle) (_THIS, SDL_Window * window);
   228 	void            (*SetWindowPosition) (_THIS, SDL_Window * window);
   229 	void            (*SetWindowSize) (_THIS, SDL_Window * window);
   230 	void            (*ShowWindow) (_THIS, SDL_Window * window);
   231 	void            (*HideWindow) (_THIS, SDL_Window * window);
   232 	void            (*RaiseWindow) (_THIS, SDL_Window * window);
   233 	void            (*MaximizeWindow) (_THIS, SDL_Window * window);
   234 	void            (*MinimizeWindow) (_THIS, SDL_Window * window);
   235 	void            (*RestoreWindow) (_THIS, SDL_Window * window);
   236 	void            (*SetWindowGrab) (_THIS, SDL_Window * window);
   237 	void            (*DestroyWindow) (_THIS, SDL_Window * window);
   238 
   239 	/* Get some platform dependent window information */
   240 	                SDL_bool(*GetWindowWMInfo) (_THIS, SDL_Window * window,
   241 			                       struct SDL_SysWMinfo * info);
   242 
   243 	/* * * */
   244 	/*
   245 	 * OpenGL support
   246 	 */
   247 	int             (*GL_LoadLibrary) (_THIS, const char *path);
   248 	void           *(*GL_GetProcAddress) (_THIS, const char *proc);
   249 	                SDL_GLContext(*GL_CreateContext) (_THIS, SDL_Window * window);
   250 	int             (*GL_MakeCurrent) (_THIS, SDL_Window * window, SDL_GLContext context);
   251 	int             (*GL_SetSwapInterval) (_THIS, int interval);
   252 	int             (*GL_GetSwapInterval) (_THIS);
   253 	void            (*GL_SwapWindow) (_THIS, SDL_Window * window);
   254 	void            (*GL_DeleteContext) (_THIS, SDL_GLContext context);
   255 
   256 	/* * * */
   257 	/*
   258 	 * Event manager functions
   259 	 */
   260 	void            (*PumpEvents) (_THIS);
   261 
   262 	/* * * */
   263 	/* Data common to all drivers */
   264 	int             num_displays;
   265 	SDL_VideoDisplay *displays;
   266 	int             current_display;
   267 	Uint32          next_object_id;
   268 
   269 	/* * * */
   270 	/* Data used by the GL drivers */
   271 	struct {
   272 		int             red_size;
   273 		int             green_size;
   274 		int             blue_size;
   275 		int             alpha_size;
   276 		int             depth_size;
   277 		int             buffer_size;
   278 		int             stencil_size;
   279 		int             double_buffer;
   280 		int             accum_red_size;
   281 		int             accum_green_size;
   282 		int             accum_blue_size;
   283 		int             accum_alpha_size;
   284 		int             stereo;
   285 		int             multisamplebuffers;
   286 		int             multisamplesamples;
   287 		int             accelerated;
   288 		int             retained_backing;
   289 		int             driver_loaded;
   290 		char            driver_path[256];
   291 		void           *dll_handle;
   292 	}               gl_config;
   293 
   294 	/* * * */
   295 	/* Data private to this driver */
   296 	void           *driverdata;
   297 	struct SDL_GLDriverData *gl_data;
   298 
   299 	/* * * */
   300 	/* The function used to dispose of this structure */
   301 	void            (*free) (_THIS);
   302 };
   303 
   304 typedef struct VideoBootStrap {
   305 	const char     *name;
   306 	const char     *desc;
   307 	int             (*available) (void);
   308 	SDL_VideoDevice *(*create) (int devindex);
   309 }               VideoBootStrap;
   310 
   311 #if SDL_VIDEO_DRIVER_COCOA
   312 extern VideoBootStrap COCOA_bootstrap;
   313 #endif
   314 #if SDL_VIDEO_DRIVER_X11
   315 extern VideoBootStrap X11_bootstrap;
   316 #endif
   317 #if SDL_VIDEO_DRIVER_NANOX
   318 extern VideoBootStrap NX_bootstrap;
   319 #endif
   320 #if SDL_VIDEO_DRIVER_IPOD
   321 extern VideoBootStrap iPod_bootstrap;
   322 #endif
   323 #if SDL_VIDEO_DRIVER_WSCONS
   324 extern VideoBootStrap WSCONS_bootstrap;
   325 #endif
   326 #if SDL_VIDEO_DRIVER_FBCON
   327 extern VideoBootStrap FBCON_bootstrap;
   328 #endif
   329 #if SDL_VIDEO_DRIVER_DIRECTFB
   330 extern VideoBootStrap DirectFB_bootstrap;
   331 #endif
   332 #if SDL_VIDEO_DRIVER_PS2GS
   333 extern VideoBootStrap PS2GS_bootstrap;
   334 #endif
   335 #if SDL_VIDEO_DRIVER_VGL
   336 extern VideoBootStrap VGL_bootstrap;
   337 #endif
   338 #if SDL_VIDEO_DRIVER_SVGALIB
   339 extern VideoBootStrap SVGALIB_bootstrap;
   340 #endif
   341 #if SDL_VIDEO_DRIVER_GAPI
   342 extern VideoBootStrap GAPI_bootstrap;
   343 #endif
   344 #if SDL_VIDEO_DRIVER_WIN32
   345 extern VideoBootStrap WIN32_bootstrap;
   346 #endif
   347 #if SDL_VIDEO_DRIVER_BWINDOW
   348 extern VideoBootStrap BWINDOW_bootstrap;
   349 #endif
   350 #if SDL_VIDEO_DRIVER_PHOTON
   351 extern VideoBootStrap ph_bootstrap;
   352 #endif
   353 #if SDL_VIDEO_DRIVER_EPOC
   354 extern VideoBootStrap EPOC_bootstrap;
   355 #endif
   356 #if SDL_VIDEO_DRIVER_XBIOS
   357 extern VideoBootStrap XBIOS_bootstrap;
   358 #endif
   359 #if SDL_VIDEO_DRIVER_GEM
   360 extern VideoBootStrap GEM_bootstrap;
   361 #endif
   362 #if SDL_VIDEO_DRIVER_DC
   363 extern VideoBootStrap DC_bootstrap;
   364 #endif
   365 #if SDL_VIDEO_DRIVER_RISCOS
   366 extern VideoBootStrap RISCOS_bootstrap;
   367 #endif
   368 #if SDL_VIDEO_DRIVER_OS2FS
   369 extern VideoBootStrap OS2FSLib_bootstrap;
   370 #endif
   371 #if SDL_VIDEO_DRIVER_UIKIT
   372 extern VideoBootStrap UIKIT_bootstrap;
   373 #endif
   374 #if SDL_VIDEO_DRIVER_DUMMY
   375 extern VideoBootStrap DUMMY_bootstrap;
   376 #endif
   377 #if SDL_VIDEO_DRIVER_NDS
   378 extern VideoBootStrap NDS_bootstrap;
   379 #endif
   380 
   381 #define SDL_CurrentDisplay	(_this->displays[_this->current_display])
   382 
   383 extern SDL_VideoDevice *SDL_GetVideoDevice();
   384 extern int      SDL_AddBasicVideoDisplay(const SDL_DisplayMode * desktop_mode);
   385 extern int      SDL_AddVideoDisplay(const SDL_VideoDisplay * display);
   386 extern SDL_bool 
   387 SDL_AddDisplayMode(int displayIndex,
   388 		   const SDL_DisplayMode * mode);
   389 extern void 
   390 SDL_AddRenderDriver(int displayIndex,
   391 		    const SDL_RenderDriver * driver);
   392 
   393 extern int      SDL_RecreateWindow(SDL_Window * window, Uint32 flags);
   394 extern SDL_Window *SDL_GetWindowFromID(SDL_WindowID windowID);
   395 extern SDL_VideoDisplay *SDL_GetDisplayFromWindow(SDL_Window * window);
   396 
   397 extern void     SDL_OnWindowShown(SDL_Window * window);
   398 extern void     SDL_OnWindowHidden(SDL_Window * window);
   399 extern void     SDL_OnWindowResized(SDL_Window * window);
   400 extern void     SDL_OnWindowFocusGained(SDL_Window * window);
   401 extern void     SDL_OnWindowFocusLost(SDL_Window * window);
   402 extern SDL_WindowID SDL_GetFocusWindow(void);
   403 
   404 #endif				/* _SDL_sysvideo_h */
   405 
   406 /* vi: set ts=4 sw=4 expandtab: */