Work in progress. :) SDL-1.3
authorSam Lantinga <slouken@libsdl.org>
Wed, 07 Jun 2006 16:10:28 +0000
branchSDL-1.3
changeset 1670eef792d31de8
parent 1669 9857d21967bb
child 1671 89f7510fe17a
Work in progress. :)
Makefile.in
include/SDL_compat.h
include/SDL_mouse.h
include/SDL_video.h
src/SDL_compat.c
src/events/SDL_events_c.h
src/events/SDL_keyboard.c
src/events/SDL_mouse.c
src/events/SDL_mouse_c.h
src/events/SDL_quit.c
src/video/SDL_blit.c
src/video/SDL_bmp.c
src/video/SDL_cursor.c
src/video/SDL_cursor_c.h
src/video/SDL_pixels.c
src/video/SDL_pixels_c.h
src/video/SDL_surface.c
src/video/SDL_sysvideo.h
src/video/SDL_video.c
     1.1 --- a/Makefile.in	Mon May 29 05:08:33 2006 +0000
     1.2 +++ b/Makefile.in	Wed Jun 07 16:10:28 2006 +0000
     1.3 @@ -125,14 +125,6 @@
     1.4  	    rm -f $(mandir)/man3/$$file; \
     1.5  	done
     1.6  
     1.7 -indent:
     1.8 -	cd $(srcdir) && \
     1.9 -	find . \( \
    1.10 -	    -name '*.h' -o \
    1.11 -	    -name '*.c' -o \
    1.12 -	    -name '*.cc' \) \
    1.13 -	    -exec indent {} \;
    1.14 -
    1.15  clean:
    1.16  	rm -rf $(objects)
    1.17  	if test -f test/Makefile; then (cd test; $(MAKE) $@); fi
    1.18 @@ -173,6 +165,29 @@
    1.19  rpm: $(distfile)
    1.20  	rpmbuild -ta $?
    1.21  
    1.22 +# Run indent on the source to standardize coding style
    1.23 +indent:
    1.24 +	@echo "Running indent... modified files:"
    1.25 +	@cd $(srcdir) && \
    1.26 +	find . \( \
    1.27 +	    -name '*.h' -o \
    1.28 +	    -name '*.c' -o \
    1.29 +	    -name '*.cc' \) \
    1.30 +	    -print | \
    1.31 +	while read file; do \
    1.32 +	    indent "$$file" -o "$$file.indent"; \
    1.33 +	    if cmp "$$file" "$$file.indent" >/dev/null; then \
    1.34 +	        rm -f "$$file.indent"; \
    1.35 +	    else \
    1.36 +	        echo "$$file"; \
    1.37 +	        mv -f "$$file.indent" "$$file"; \
    1.38 +	    fi; \
    1.39 +	done
    1.40 +
    1.41 +# Run indent and then commit modified files
    1.42 +commit: indent
    1.43 +	svn commit
    1.44 +
    1.45  # Create a SVN snapshot that people can run update on
    1.46  snapshot:
    1.47  	svn co svn://libsdl.org/trunk/SDL
     2.1 --- a/include/SDL_compat.h	Mon May 29 05:08:33 2006 +0000
     2.2 +++ b/include/SDL_compat.h	Wed Jun 07 16:10:28 2006 +0000
     2.3 @@ -36,22 +36,18 @@
     2.4  /* *INDENT-ON* */
     2.5  #endif
     2.6  
     2.7 -#define SDL_SWSURFACE	0x00000000
     2.8 -#define SDL_HWSURFACE	0x00000001
     2.9 -#define SDL_ASYNCBLIT	0x00000004
    2.10 -#define SDL_ANYFORMAT	0x10000000
    2.11 -#define SDL_HWPALETTE	0x20000000
    2.12 -#define SDL_DOUBLEBUF	0x40000000
    2.13 -#define SDL_FULLSCREEN	0x80000000
    2.14 -#define SDL_OPENGL      0x00000002
    2.15 -#define SDL_INTERNALOPENGL 0x00000008
    2.16 -#define SDL_RESIZABLE	0x00000010
    2.17 -#define SDL_NOFRAME	0x00000020
    2.18 -#define SDL_HWACCEL	0x00000100
    2.19 -#define SDL_SRCCOLORKEY	0x00001000
    2.20 -#define SDL_RLEACCELOK	0x00002000
    2.21 -#define SDL_RLEACCEL	0x00004000
    2.22 -#define SDL_SRCALPHA	0x00010000
    2.23 +#define SDL_SWSURFACE       0x00000000
    2.24 +#define SDL_ANYFORMAT       0x00100000
    2.25 +#define SDL_HWPALETTE       0x00200000
    2.26 +#define SDL_DOUBLEBUF       0x00400000
    2.27 +#define SDL_FULLSCREEN      0x00800000
    2.28 +#define SDL_RESIZABLE       0x01000000
    2.29 +#define SDL_NOFRAME         0x02000000
    2.30 +#define SDL_OPENGL          0x04000000
    2.31 +#define SDL_ASYNCBLIT       0x00000000
    2.32 +#define SDL_HWACCEL         0x00000000
    2.33 +#define SDL_SCREEN_SURFACE  0x10000000  /* Surface is a window screen surface */
    2.34 +#define SDL_SHADOW_SURFACE  0x20000000  /* Surface is a window shadow surface */
    2.35  
    2.36  #define SDL_APPMOUSEFOCUS	0x01
    2.37  #define SDL_APPINPUTFOCUS	0x02
    2.38 @@ -64,6 +60,25 @@
    2.39  #define SDL_VIDEORESIZE	SDL_EVENT_RESERVED2
    2.40  #define SDL_VIDEOEXPOSE	SDL_EVENT_RESERVED3
    2.41  
    2.42 +typedef struct SDL_VideoInfo
    2.43 +{
    2.44 +    Uint32 hw_available:1;
    2.45 +    Uint32 wm_available:1;
    2.46 +    Uint32 UnusedBits1:6;
    2.47 +    Uint32 UnusedBits2:1;
    2.48 +    Uint32 blit_hw:1;
    2.49 +    Uint32 blit_hw_CC:1;
    2.50 +    Uint32 blit_hw_A:1;
    2.51 +    Uint32 blit_sw:1;
    2.52 +    Uint32 blit_sw_CC:1;
    2.53 +    Uint32 blit_sw_A:1;
    2.54 +    Uint32 blit_fill:1;
    2.55 +    Uint32 UnusedBits3:16;
    2.56 +    Uint32 video_mem;
    2.57 +
    2.58 +    SDL_PixelFormat *vfmt;
    2.59 +} SDL_VideoInfo;
    2.60 +
    2.61  typedef enum
    2.62  {
    2.63      SDL_GRAB_QUERY = -1,
    2.64 @@ -71,9 +86,12 @@
    2.65      SDL_GRAB_ON = 1
    2.66  } SDL_GrabMode;
    2.67  
    2.68 +#define SDL_AllocSurface    SDL_CreateRGBSurface
    2.69 +
    2.70  extern DECLSPEC const SDL_version *SDLCALL SDL_Linked_Version(void);
    2.71  extern DECLSPEC char *SDLCALL SDL_AudioDriverName(char *namebuf, int maxlen);
    2.72  extern DECLSPEC char *SDLCALL SDL_VideoDriverName(char *namebuf, int maxlen);
    2.73 +extern DECLSPEC const SDL_VideoInfo *SDLCALL SDL_GetVideoInfo(void);
    2.74  extern DECLSPEC int SDLCALL SDL_VideoModeOK(int width, int height, int bpp,
    2.75                                              Uint32 flags);
    2.76  extern DECLSPEC SDL_Rect **SDLCALL SDL_ListModes(SDL_PixelFormat * format,
    2.77 @@ -81,6 +99,14 @@
    2.78  extern DECLSPEC SDL_Surface *SDLCALL SDL_SetVideoMode(int width, int height,
    2.79                                                        int bpp, Uint32 flags);
    2.80  extern DECLSPEC SDL_Surface *SDLCALL SDL_GetVideoSurface(void);
    2.81 +extern DECLSPEC void SDLCALL SDL_UpdateRects(SDL_Surface * screen,
    2.82 +                                             int numrects, SDL_Rect * rects);
    2.83 +extern DECLSPEC void SDLCALL SDL_UpdateRect(SDL_Surface * screen, Sint32 x,
    2.84 +                                            Sint32 y, Uint32 w, Uint32 h);
    2.85 +extern DECLSPEC int SDLCALL SDL_Flip(SDL_Surface * screen);
    2.86 +extern DECLSPEC SDL_Surface *SDLCALL SDL_DisplayFormat(SDL_Surface * surface);
    2.87 +extern DECLSPEC SDL_Surface *SDLCALL SDL_DisplayFormatAlpha(SDL_Surface *
    2.88 +                                                            surface);
    2.89  extern DECLSPEC void SDLCALL SDL_WM_SetCaption(const char *title,
    2.90                                                 const char *icon);
    2.91  extern DECLSPEC void SDLCALL SDL_WM_GetCaption(char **title, char **icon);
    2.92 @@ -92,6 +118,9 @@
    2.93  extern DECLSPEC int SDLCALL SDL_SetPalette(SDL_Surface * surface, int flags,
    2.94                                             SDL_Color * colors,
    2.95                                             int firstcolor, int ncolors);
    2.96 +extern DECLSPEC int SDLCALL SDL_SetScreenColors(SDL_Surface * screen,
    2.97 +                                                SDL_Color * colors,
    2.98 +                                                int firstcolor, int ncolors);
    2.99  extern DECLSPEC int SDLCALL SDL_GetWMInfo(SDL_SysWMinfo * info);
   2.100  
   2.101  /* Ends C function definitions when using C++ */
   2.102 @@ -103,3 +132,6 @@
   2.103  #include "close_code.h"
   2.104  
   2.105  #endif /* _SDL_compat_h */
   2.106 +
   2.107 +/* vi: set ts=4 sw=4 expandtab: */
   2.108 +extern DECLSPEC void SDLCALL SDL_WarpMouse(Uint16 x, Uint16 y);
     3.1 --- a/include/SDL_mouse.h	Mon May 29 05:08:33 2006 +0000
     3.2 +++ b/include/SDL_mouse.h	Wed Jun 07 16:10:28 2006 +0000
     3.3 @@ -41,28 +41,53 @@
     3.4  /* *INDENT-ON* */
     3.5  #endif
     3.6  
     3.7 -typedef struct WMcursor WMcursor;       /* Implementation dependent */
     3.8 -typedef struct SDL_Cursor
     3.9 -{
    3.10 -    SDL_Rect area;              /* The area of the mouse cursor */
    3.11 -    Sint16 hot_x, hot_y;        /* The "tip" of the cursor */
    3.12 -    Uint8 *data;                /* B/W cursor data */
    3.13 -    Uint8 *mask;                /* B/W cursor mask */
    3.14 -    Uint8 *save[2];             /* Place to save cursor area */
    3.15 -    WMcursor *wm_cursor;        /* Window-manager cursor */
    3.16 -} SDL_Cursor;
    3.17 +typedef struct SDL_Cursor SDL_Cursor;   /* Implementation dependent */
    3.18  
    3.19  /* Function prototypes */
    3.20 +
    3.21 +/* \fn int SDL_GetNumMice(void)
    3.22 + *
    3.23 + * \brief Get the number of mouse input devices available.
    3.24 + *
    3.25 + * \sa SDL_SelectMouse()
    3.26 + */
    3.27 +extern DECLSPEC int SDLCALL SDL_GetNumMice(void);
    3.28 +
    3.29 +/* \fn int SDL_SelectMouse(int index)
    3.30 + *
    3.31 + * \brief Set the index of the currently selected mouse.
    3.32 + *
    3.33 + * \return The index of the currently selected mouse.
    3.34 + *
    3.35 + * \note You can query the currently selected mouse by passing an index of -1.
    3.36 + *
    3.37 + * \sa SDL_GetNumMice()
    3.38 + */
    3.39 +extern DECLSPEC int SDLCALL SDL_SelectMouse(int index);
    3.40 +
    3.41 +/* \fn SDL_WindowID SDL_GetMouseFocusWindow(void)
    3.42 + *
    3.43 + * \brief Get the window which currently has focus for the currently selected mouse.
    3.44 + */
    3.45 +extern DECLSPEC SDL_WindowID SDLCALL SDL_GetMouseFocusWindow(void);
    3.46 +
    3.47  /*
    3.48 - * Retrieve the current state of the mouse.
    3.49 + * \fn Uint8 SDL_GetMouseState(int *x, int *y)
    3.50 + *
    3.51 + * \brief Retrieve the current state of the mouse.
    3.52 + *
    3.53   * The current button state is returned as a button bitmask, which can
    3.54   * be tested using the SDL_BUTTON(X) macros, and x and y are set to the
    3.55 - * current mouse cursor position.  You can pass NULL for either x or y.
    3.56 + * mouse cursor position relative to the focus window for the currently
    3.57 + * selected mouse.  You can pass NULL for either x or y.
    3.58   */
    3.59  extern DECLSPEC Uint8 SDLCALL SDL_GetMouseState(int *x, int *y);
    3.60  
    3.61  /*
    3.62 - * Retrieve the current state of the mouse.
    3.63 + * \fn Uint8 SDL_GetRelativeMouseState(int *x, int *y)
    3.64 + *
    3.65 + * \brief Retrieve the current state of the mouse.
    3.66 + *
    3.67   * The current button state is returned as a button bitmask, which can
    3.68   * be tested using the SDL_BUTTON(X) macros, and x and y are set to the
    3.69   * mouse deltas since the last call to SDL_GetRelativeMouseState().
    3.70 @@ -70,9 +95,18 @@
    3.71  extern DECLSPEC Uint8 SDLCALL SDL_GetRelativeMouseState(int *x, int *y);
    3.72  
    3.73  /*
    3.74 - * Set the position of the mouse cursor (generates a mouse motion event)
    3.75 + * \fn void SDL_WarpMouseInWindow(SDL_WindowID windowID, int x, int y)
    3.76 + *
    3.77 + * \brief Moves the currently selected mouse to the given position within the window.
    3.78 + *
    3.79 + * \param windowID The window to move the mouse into, or 0 for the current mouse focus
    3.80 + * \param x The x coordinate within the window
    3.81 + * \param y The y coordinate within the window
    3.82 + *
    3.83 + * \note This function generates a mouse motion event
    3.84   */
    3.85 -extern DECLSPEC void SDLCALL SDL_WarpMouse(Uint16 x, Uint16 y);
    3.86 +extern DECLSPEC void SDLCALL SDL_WarpMouseInWindow(SDL_WindowID windowID,
    3.87 +                                                   int x, int y);
    3.88  
    3.89  /*
    3.90   * Create a cursor using the specified data and mask (in MSB format).
     4.1 --- a/include/SDL_video.h	Mon May 29 05:08:33 2006 +0000
     4.2 +++ b/include/SDL_video.h	Wed Jun 07 16:10:28 2006 +0000
     4.3 @@ -46,111 +46,17 @@
     4.4  #define SDL_ALPHA_OPAQUE 255
     4.5  #define SDL_ALPHA_TRANSPARENT 0
     4.6  
     4.7 -/* Useful data types */
     4.8 +/**
     4.9 + * \struct SDL_Rect
    4.10 + *
    4.11 + * \brief A rectangle, with the origin at the upper left.
    4.12 + */
    4.13  typedef struct SDL_Rect
    4.14  {
    4.15      Sint16 x, y;
    4.16      Uint16 w, h;
    4.17  } SDL_Rect;
    4.18  
    4.19 -/* This structure should be treated as read-only, except for 'pixels',
    4.20 -   which, if not NULL, contains the raw pixel data for the surface.
    4.21 -*/
    4.22 -typedef struct SDL_Surface
    4.23 -{
    4.24 -    Uint32 flags;               /* Read-only */
    4.25 -    SDL_PixelFormat *format;    /* Read-only */
    4.26 -    int w, h;                   /* Read-only */
    4.27 -    Uint16 pitch;               /* Read-only */
    4.28 -    void *pixels;               /* Read-write */
    4.29 -    int offset;                 /* Private */
    4.30 -
    4.31 -    /* Hardware-specific surface info */
    4.32 -    struct private_hwdata *hwdata;
    4.33 -
    4.34 -    /* clipping information */
    4.35 -    SDL_Rect clip_rect;         /* Read-only */
    4.36 -    Uint32 unused1;             /* for binary compatibility */
    4.37 -
    4.38 -    /* Allow recursive locks */
    4.39 -    Uint32 locked;              /* Private */
    4.40 -
    4.41 -    /* info for fast blit mapping to other surfaces */
    4.42 -    struct SDL_BlitMap *map;    /* Private */
    4.43 -
    4.44 -    /* format version, bumped at every change to invalidate blit maps */
    4.45 -    unsigned int format_version;        /* Private */
    4.46 -
    4.47 -    /* Reference count -- used when freeing surface */
    4.48 -    int refcount;               /* Read-mostly */
    4.49 -} SDL_Surface;
    4.50 -
    4.51 -/* The most common video overlay formats.
    4.52 -   For an explanation of these pixel formats, see:
    4.53 -	http://www.webartz.com/fourcc/indexyuv.htm
    4.54 -
    4.55 -   For information on the relationship between color spaces, see:
    4.56 -   http://www.neuro.sfc.keio.ac.jp/~aly/polygon/info/color-space-faq.html
    4.57 - */
    4.58 -#define SDL_YV12_OVERLAY  0x32315659    /* Planar mode: Y + V + U  (3 planes) */
    4.59 -#define SDL_IYUV_OVERLAY  0x56555949    /* Planar mode: Y + U + V  (3 planes) */
    4.60 -#define SDL_YUY2_OVERLAY  0x32595559    /* Packed mode: Y0+U0+Y1+V0 (1 plane) */
    4.61 -#define SDL_UYVY_OVERLAY  0x59565955    /* Packed mode: U0+Y0+V0+Y1 (1 plane) */
    4.62 -#define SDL_YVYU_OVERLAY  0x55595659    /* Packed mode: Y0+V0+Y1+U0 (1 plane) */
    4.63 -
    4.64 -/* The YUV hardware video overlay */
    4.65 -typedef struct SDL_Overlay
    4.66 -{
    4.67 -    Uint32 format;              /* Read-only */
    4.68 -    int w, h;                   /* Read-only */
    4.69 -    int planes;                 /* Read-only */
    4.70 -    Uint16 *pitches;            /* Read-only */
    4.71 -    Uint8 **pixels;             /* Read-write */
    4.72 -
    4.73 -    /* Hardware-specific surface info */
    4.74 -    struct private_yuvhwfuncs *hwfuncs;
    4.75 -    struct private_yuvhwdata *hwdata;
    4.76 -
    4.77 -    /* Special flags */
    4.78 -    Uint32 hw_overlay:1;        /* Flag: This overlay hardware accelerated? */
    4.79 -    Uint32 UnusedBits:31;
    4.80 -} SDL_Overlay;
    4.81 -
    4.82 -/* Evaluates to true if the surface needs to be locked before access */
    4.83 -#define SDL_MUSTLOCK(surface)	\
    4.84 -  (surface->offset ||		\
    4.85 -  ((surface->flags & (SDL_HWSURFACE|SDL_RLEACCEL)) != 0))
    4.86 -
    4.87 -/* typedef for private surface blitting functions */
    4.88 -typedef int (*SDL_blit) (struct SDL_Surface * src, SDL_Rect * srcrect,
    4.89 -                         struct SDL_Surface * dst, SDL_Rect * dstrect);
    4.90 -
    4.91 -
    4.92 -/**
    4.93 - * \struct SDL_VideoInfo
    4.94 - *
    4.95 - * \brief Useful for determining the video hardware capabilities
    4.96 - */
    4.97 -typedef struct SDL_VideoInfo
    4.98 -{
    4.99 -    Uint32 hw_available:1;  /**< Flag: Can you create hardware surfaces? */
   4.100 -    Uint32 wm_available:1;  /**< Flag: Can you talk to a window manager? */
   4.101 -    Uint32 UnusedBits1:6;
   4.102 -    Uint32 UnusedBits2:1;
   4.103 -    Uint32 blit_hw:1;       /**< Flag: Accelerated blits HW --> HW */
   4.104 -    Uint32 blit_hw_CC:1;    /**< Flag: Accelerated blits with Colorkey */
   4.105 -    Uint32 blit_hw_A:1;     /**< Flag: Accelerated blits with Alpha */
   4.106 -    Uint32 blit_sw:1;       /**< Flag: Accelerated blits SW --> HW */
   4.107 -    Uint32 blit_sw_CC:1;    /**< Flag: Accelerated blits with Colorkey */
   4.108 -    Uint32 blit_sw_A:1;     /**< Flag: Accelerated blits with Alpha */
   4.109 -    Uint32 blit_fill:1;     /**< Flag: Accelerated color fill */
   4.110 -    Uint32 UnusedBits3:16;
   4.111 -    Uint32 video_mem;           /* The total amount of video memory (in K) */
   4.112 -
   4.113 -    /* Here for backwards compatibility */
   4.114 -    SDL_PixelFormat *vfmt;
   4.115 -} SDL_VideoInfo;
   4.116 -
   4.117  /**
   4.118   * \struct SDL_DisplayMode
   4.119   *
   4.120 @@ -204,6 +110,8 @@
   4.121   * \enum SDL_WindowFlags
   4.122   *
   4.123   * \brief The flags on a window
   4.124 + *
   4.125 + * \sa SDL_GetWindowFlags()
   4.126   */
   4.127  typedef enum
   4.128  {
   4.129 @@ -241,6 +149,163 @@
   4.130  } SDL_WindowEventID;
   4.131  
   4.132  /**
   4.133 + * \enum SDL_RendererFlags
   4.134 + *
   4.135 + * \brief Flags used when initializing a render manager.
   4.136 + */
   4.137 +typedef enum
   4.138 +{
   4.139 +    SDL_Renderer_PresentDiscard = 0x00000001,   /**< Present leaves the contents of the backbuffer undefined */
   4.140 +    SDL_Renderer_PresentCopy = 0x00000002,      /**< Present uses a copy from back buffer to the front buffer */
   4.141 +    SDL_Renderer_PresentFlip2 = 0x00000004,     /**< Present uses a flip, swapping back buffer and front buffer */
   4.142 +    SDL_Renderer_PresentFlip3 = 0x00000008,     /**< Present uses a flip, rotating between two back buffers and a front buffer */
   4.143 +    SDL_Renderer_PresentVSync = 0x00000010,     /**< Present is synchronized with the refresh rate */
   4.144 +    SDL_Renderer_RenderTarget = 0x00000020,     /**< The renderer can create texture render targets */
   4.145 +    SDL_Renderer_Accelerated = 0x00000040,      /**< The renderer uses hardware acceleration */
   4.146 +    SDL_Renderer_Minimal = 0x00000080,          /**< The renderer only supports the read/write pixel and present functions */
   4.147 +} SDL_RendererFlags;
   4.148 +
   4.149 +/**
   4.150 + * \struct SDL_RendererInfo
   4.151 + *
   4.152 + * \brief Information on the capabilities of a render manager.
   4.153 + */
   4.154 +typedef struct SDL_RendererInfo
   4.155 +{
   4.156 +    const char *name;           /**< The name of the renderer */
   4.157 +    Uint32 flags;               /**< Supported SDL_RendererFlags */
   4.158 +    Uint32 blend_modes;         /**< A mask of supported blend modes */
   4.159 +    Uint32 scale_modes;         /**< A mask of supported scale modes */
   4.160 +    Uint32 num_texture_formats; /**< The number of available texture formats */
   4.161 +    Uint32 texture_formats[32]; /**< The available texture formats */
   4.162 +    int max_texture_width;      /**< The maximimum texture width */
   4.163 +    int max_texture_height;     /**< The maximimum texture height */
   4.164 +} SDL_RendererInfo;
   4.165 +
   4.166 +/**
   4.167 + * \enum SDL_TextureAccess
   4.168 + *
   4.169 + * \brief The access pattern allowed for a texture
   4.170 + */
   4.171 +typedef enum
   4.172 +{
   4.173 +    SDL_TextureAccess_Render,   /**< Unlockable video memory, rendering allowed */
   4.174 +    SDL_TextureAccess_Remote,   /**< Unlockable video memory */
   4.175 +    SDL_TextureAccess_Local,    /**< Lockable system memory */
   4.176 +} SDL_TextureAccess;
   4.177 +
   4.178 +/**
   4.179 + * \enum SDL_TextureBlendMode
   4.180 + *
   4.181 + * \brief The blend mode used in SDL_RenderCopy()
   4.182 + */
   4.183 +typedef enum
   4.184 +{
   4.185 +    SDL_TextureBlendMode_None,  /**< No blending */
   4.186 +    SDL_TextureBlendMode_Mask,  /**< dst = A ? src : dst (alpha is mask) */
   4.187 +    SDL_TextureBlendMode_Blend, /**< dst = (src * A) + (dst * (1-A)) */
   4.188 +    SDL_TextureBlendMode_Add,   /**< dst = (src * A) + dst */
   4.189 +    SDL_TextureBlendMode_Mod,   /**< dst = src * dst */
   4.190 +} SDL_TextureBlendMode;
   4.191 +
   4.192 +/**
   4.193 + * \enum SDL_TextureScaleMode
   4.194 + *
   4.195 + * \brief The scale mode used in SDL_RenderCopy()
   4.196 + */
   4.197 +typedef enum
   4.198 +{
   4.199 +    SDL_TextureScaleMode_None,  /**< No scaling, rectangles must match dimensions */
   4.200 +    SDL_TextureScaleMode_Fast,  /**< Point sampling or equivalent algorithm */
   4.201 +    SDL_TextureScaleMode_Slow,  /**< Linear filtering or equivalent algorithm */
   4.202 +    SDL_TextureScaleMode_Best,  /**< Bicubic filtering or equivalent algorithm */
   4.203 +} SDL_TextureScaleMode;
   4.204 +
   4.205 +/**
   4.206 + * \typedef SDL_TextureID
   4.207 + *
   4.208 + * \brief An efficient driver-specific representation of pixel data
   4.209 + */
   4.210 +typedef Uint32 SDL_TextureID;
   4.211 +
   4.212 +
   4.213 +/* These are the currently supported flags for the SDL_surface */
   4.214 +/* Used internally (read-only) */
   4.215 +#define SDL_HWSURFACE       0x00000001  /* Surface represents a texture */
   4.216 +#define SDL_PREALLOC        0x00000002  /* Surface uses preallocated memory */
   4.217 +#define SDL_SRCALPHA        0x00000004  /* Blit uses source alpha blending */
   4.218 +#define SDL_SRCCOLORKEY     0x00000008  /* Blit uses a source color key */
   4.219 +#define SDL_RLEACCELOK      0x00000010  /* Private flag */
   4.220 +#define SDL_RLEACCEL        0x00000020  /* Surface is RLE encoded */
   4.221 +
   4.222 +/* Evaluates to true if the surface needs to be locked before access */
   4.223 +#define SDL_MUSTLOCK(S)	(((S)->flags & (SDL_HWSURFACE|SDL_RLEACCEL)) != 0)
   4.224 +
   4.225 +/* This structure should be treated as read-only, except for 'pixels',
   4.226 +   which, if not NULL, contains the raw pixel data for the surface.
   4.227 +*/
   4.228 +typedef struct SDL_Surface
   4.229 +{
   4.230 +    Uint32 flags;               /* Read-only */
   4.231 +    SDL_PixelFormat *format;    /* Read-only */
   4.232 +    int w, h;                   /* Read-only */
   4.233 +    int pitch;                  /* Read-only */
   4.234 +    void *pixels;               /* Read-write */
   4.235 +
   4.236 +    /* information needed for surfaces requiring locks */
   4.237 +    int locked;
   4.238 +    void *lock_data;
   4.239 +
   4.240 +    /* clipping information */
   4.241 +    SDL_Rect clip_rect;         /* Read-only */
   4.242 +
   4.243 +    /* info for fast blit mapping to other surfaces */
   4.244 +    struct SDL_BlitMap *map;    /* Private */
   4.245 +
   4.246 +    /* format version, bumped at every change to invalidate blit maps */
   4.247 +    unsigned int format_version;        /* Private */
   4.248 +
   4.249 +    /* Reference count -- used when freeing surface */
   4.250 +    int refcount;               /* Read-mostly */
   4.251 +} SDL_Surface;
   4.252 +
   4.253 +/* typedef for private surface blitting functions */
   4.254 +typedef int (*SDL_blit) (struct SDL_Surface * src, SDL_Rect * srcrect,
   4.255 +                         struct SDL_Surface * dst, SDL_Rect * dstrect);
   4.256 +
   4.257 +
   4.258 +/* The most common video overlay formats.
   4.259 +   For an explanation of these pixel formats, see:
   4.260 +   http://www.webartz.com/fourcc/indexyuv.htm
   4.261 +
   4.262 +   For information on the relationship between color spaces, see:
   4.263 +   http://www.neuro.sfc.keio.ac.jp/~aly/polygon/info/color-space-faq.html
   4.264 + */
   4.265 +#define SDL_YV12_OVERLAY  0x32315659    /* Planar mode: Y + V + U  (3 planes) */
   4.266 +#define SDL_IYUV_OVERLAY  0x56555949    /* Planar mode: Y + U + V  (3 planes) */
   4.267 +#define SDL_YUY2_OVERLAY  0x32595559    /* Packed mode: Y0+U0+Y1+V0 (1 plane) */
   4.268 +#define SDL_UYVY_OVERLAY  0x59565955    /* Packed mode: U0+Y0+V0+Y1 (1 plane) */
   4.269 +#define SDL_YVYU_OVERLAY  0x55595659    /* Packed mode: Y0+V0+Y1+U0 (1 plane) */
   4.270 +
   4.271 +/* The YUV hardware video overlay */
   4.272 +typedef struct SDL_Overlay
   4.273 +{
   4.274 +    Uint32 format;              /* Read-only */
   4.275 +    int w, h;                   /* Read-only */
   4.276 +    int planes;                 /* Read-only */
   4.277 +    Uint16 *pitches;            /* Read-only */
   4.278 +    Uint8 **pixels;             /* Read-write */
   4.279 +
   4.280 +    /* Hardware-specific surface info */
   4.281 +    struct private_yuvhwfuncs *hwfuncs;
   4.282 +    struct private_yuvhwdata *hwdata;
   4.283 +
   4.284 +    /* Special flags */
   4.285 +    Uint32 hw_overlay:1;        /* Flag: This overlay hardware accelerated? */
   4.286 +    Uint32 UnusedBits:31;
   4.287 +} SDL_Overlay;
   4.288 +
   4.289 +/**
   4.290   * \enum SDL_GLattr
   4.291   *
   4.292   * \brief OpenGL configuration attributes
   4.293 @@ -266,22 +331,6 @@
   4.294      SDL_GL_SWAP_CONTROL
   4.295  } SDL_GLattr;
   4.296  
   4.297 -/* These are the currently supported flags for the SDL_surface */
   4.298 -#define SDL_SWSURFACE	0x00000000      /* Surface is in system memory */
   4.299 -#define SDL_HWSURFACE	0x00000001      /* Surface is in video memory */
   4.300 -/* Available for SDL_CreateWindowSurface() */
   4.301 -#define SDL_ANYFORMAT	0x10000000      /* Allow any video depth/pixel-format */
   4.302 -#define SDL_HWPALETTE	0x20000000      /* Surface has exclusive palette */
   4.303 -#define SDL_DOUBLEBUF	0x40000000      /* Set up double-buffered surface */
   4.304 -/* Used internally (read-only) */
   4.305 -#define SDL_HWACCEL	0x00000100      /* Blit uses hardware acceleration */
   4.306 -#define SDL_SRCCOLORKEY	0x00001000      /* Blit uses a source color key */
   4.307 -#define SDL_RLEACCELOK	0x00002000      /* Private flag */
   4.308 -#define SDL_RLEACCEL	0x00004000      /* Surface is RLE encoded */
   4.309 -#define SDL_SRCALPHA	0x00010000      /* Blit uses source alpha blending */
   4.310 -#define SDL_PREALLOC	0x00100000      /* Surface uses preallocated memory */
   4.311 -#define SDL_SCREEN_SURFACE 0x01000000   /* Surface is a window screen surface */
   4.312 -#define SDL_SHADOW_SURFACE 0x02000000   /* Surface is a window shadow surface */
   4.313  
   4.314  /* Function prototypes */
   4.315  
   4.316 @@ -350,16 +399,6 @@
   4.317  extern DECLSPEC const char *SDLCALL SDL_GetCurrentVideoDriver(void);
   4.318  
   4.319  /**
   4.320 - * \fn const SDL_VideoInfo *SDL_GetVideoInfo(void)
   4.321 - *
   4.322 - * \brief Returns information about the currently initialized video driver.
   4.323 - *
   4.324 - * \return A read-only pointer to information about the video hardware,
   4.325 - *         or NULL if no video driver has been initialized.
   4.326 - */
   4.327 -extern DECLSPEC const SDL_VideoInfo *SDLCALL SDL_GetVideoInfo(void);
   4.328 -
   4.329 -/**
   4.330   * \fn int SDL_GetNumVideoDisplays(void)
   4.331   *
   4.332   * \brief Returns the number of available video displays.
   4.333 @@ -373,6 +412,8 @@
   4.334   *
   4.335   * \brief Set the index of the currently selected display.
   4.336   *
   4.337 + * \return The index of the currently selected display.
   4.338 + *
   4.339   * \note You can query the currently selected display by passing an index of -1.
   4.340   *
   4.341   * \sa SDL_GetNumVideoDisplays()
   4.342 @@ -452,6 +493,16 @@
   4.343  extern DECLSPEC int SDLCALL SDL_SetDisplayMode(const SDL_DisplayMode * mode);
   4.344  
   4.345  /**
   4.346 + * \fn int SDL_SetDisplayColormap(SDL_Color *colors, int firstcolor, int ncolors)
   4.347 + *
   4.348 + * \brief Set the colormap for indexed display modes.
   4.349 + *
   4.350 + * \return 0 on success, or -1 if not all the colors could be set.
   4.351 + */
   4.352 +extern DECLSPEC int SDLCALL SDL_SetDisplayColors(SDL_Color * colors,
   4.353 +                                                 int firstcolor, int ncolors);
   4.354 +
   4.355 +/**
   4.356   * \fn SDL_WindowID SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags)
   4.357   *
   4.358   * \brief Create a window with the specified position, dimensions, and flags.
   4.359 @@ -673,37 +724,294 @@
   4.360  extern DECLSPEC void SDLCALL SDL_DestroyWindow(SDL_WindowID windowID);
   4.361  
   4.362  /**
   4.363 - * \fn SDL_Surface *SDL_CreateWindowSurface (SDL_WindowID windowID, Uint32 format, Uint32 flags)
   4.364 + * \fn int SDL_GetNumRenderers(void)
   4.365   *
   4.366 - * \brief Create an SDL_Surface representing the drawing area of the window.
   4.367 + * \brief Get the number of render managers on the current display.
   4.368 + *
   4.369 + * A render manager is a set of code that handles rendering and texture
   4.370 + * management on a particular display.  Normally there is only one, but
   4.371 + * some drivers may have several available with different capabilities.
   4.372 + *
   4.373 + * \sa SDL_GetRendererInfo()
   4.374 + * \sa SDL_CreateRenderer()
   4.375   */
   4.376 -extern DECLSPEC SDL_Surface *SDLCALL SDL_CreateWindowSurface(SDL_WindowID
   4.377 -                                                             windowID,
   4.378 -                                                             Uint32 format,
   4.379 -                                                             Uint32 flags);
   4.380 +extern DECLSPEC int SDLCALL SDL_GetNumRenderers(void);
   4.381  
   4.382 -/*
   4.383 - * Makes sure the given list of rectangles is updated on the given screen.
   4.384 - * If 'x', 'y', 'w' and 'h' are all 0, SDL_UpdateRect will update the entire
   4.385 - * screen.
   4.386 - * These functions should not be called while 'screen' is locked.
   4.387 +/**
   4.388 + * \fn SDL_RendererInfo *SDL_GetRendererInfo(int index)
   4.389 + *
   4.390 + * \brief Get information about a specific render manager on the current
   4.391 + *        display.
   4.392 + *
   4.393 + * \sa SDL_CreateRenderer()
   4.394   */
   4.395 -extern DECLSPEC void SDLCALL SDL_UpdateRects
   4.396 -    (SDL_Surface * screen, int numrects, SDL_Rect * rects);
   4.397 -extern DECLSPEC void SDLCALL SDL_UpdateRect
   4.398 -    (SDL_Surface * screen, Sint32 x, Sint32 y, Uint32 w, Uint32 h);
   4.399 +extern DECLSPEC int SDLCALL SDL_GetRendererInfo(int index,
   4.400 +                                                SDL_RendererInfo * info);
   4.401  
   4.402 -/*
   4.403 - * On hardware that supports double-buffering, this function sets up a flip
   4.404 - * and returns.  The hardware will wait for vertical retrace, and then swap
   4.405 - * video buffers before the next video surface blit or lock will return.
   4.406 - * On hardware that doesn not support double-buffering, this is equivalent
   4.407 - * to calling SDL_UpdateRect(screen, 0, 0, 0, 0);
   4.408 - * The SDL_DOUBLEBUF flag must have been passed to SDL_SetVideoMode() when
   4.409 - * setting the video mode for this function to perform hardware flipping.
   4.410 - * This function returns 0 if successful, or -1 if there was an error.
   4.411 +/**
   4.412 + * \fn int SDL_CreateRenderer(SDL_WindowID window, int index, Uint32 flags)
   4.413 + *
   4.414 + * \brief Create and make active a 2D rendering context for a window.
   4.415 + *
   4.416 + * \param windowID The window used for rendering.
   4.417 + * \param index The index of the render manager to initialize, or -1 to initialize the first one supporting the requested flags.
   4.418 + * \param flags SDL_RendererFlags
   4.419 + *
   4.420 + * \return 0 on success, -1 if the flags were not supported, or -2 if
   4.421 + *         there isn't enough memory to support the requested flags
   4.422 + *
   4.423 + * \sa SDL_SelectRenderer()
   4.424 + * \sa SDL_DestroyRenderer()
   4.425   */
   4.426 -extern DECLSPEC int SDLCALL SDL_Flip(SDL_Surface * screen);
   4.427 +extern DECLSPEC int SDLCALL SDL_CreateRenderer(SDL_WindowID windowID,
   4.428 +                                               int index, Uint32 flags);
   4.429 +
   4.430 +/**
   4.431 + * \fn int SDL_SelectRenderer(SDL_WindowID windowID)
   4.432 + *
   4.433 + * \brief Select the rendering context for a particular window.
   4.434 + *
   4.435 + * \return 0 on success, -1 if the selected window doesn't have a
   4.436 + *         rendering context.
   4.437 + */
   4.438 +extern DECLSPEC int SDLCALL SDL_SelectRenderer(SDL_WindowID windowID);
   4.439 +
   4.440 +/**
   4.441 + * \fn SDL_TextureID SDL_CreateTexture(Uint32 format, int access, int w, int h)
   4.442 + *
   4.443 + * \brief Create a texture
   4.444 + *
   4.445 + * \param format The format of the texture
   4.446 + * \param access One of the enumerated values in SDL_TextureAccess
   4.447 + * \param w The width of the texture in pixels
   4.448 + * \param h The height of the texture in pixels
   4.449 + *
   4.450 + * \return The created texture is returned, or 0 if no render manager was active,  the format was unsupported, or the width or height were out of range.
   4.451 + *
   4.452 + * \sa SDL_QueryTexture()
   4.453 + * \sa SDL_DestroyTexture()
   4.454 + */
   4.455 +extern DECLSPEC SDL_TextureID SDLCALL SDL_CreateTexture(Uint32 format,
   4.456 +                                                        int access, int w,
   4.457 +                                                        int h);
   4.458 +
   4.459 +/**
   4.460 + * \fn SDL_TextureID SDL_CreateTextureFromSurface(Uint32 format, int access, SDL_Surface *surface)
   4.461 + *
   4.462 + * \brief Create a texture from an existing surface
   4.463 + *
   4.464 + * \param format The format of the texture, or 0 to pick an appropriate format
   4.465 + * \param access One of the enumerated values in SDL_TextureAccess
   4.466 + * \param surface The surface containing pixel data used to fill the texture
   4.467 + *
   4.468 + * \return The created texture is returned, or 0 if no render manager was active,  the format was unsupported, or the surface width or height were out of range.
   4.469 + *
   4.470 + * \note The surface is not modified or freed by this function.
   4.471 + *
   4.472 + * \sa SDL_QueryTexture()
   4.473 + * \sa SDL_DestroyTexture()
   4.474 + */
   4.475 +extern DECLSPEC SDL_TextureID SDLCALL SDL_CreateTextureFromSurface(Uint32
   4.476 +                                                                   format,
   4.477 +                                                                   int access,
   4.478 +                                                                   SDL_Surface
   4.479 +                                                                   * surface);
   4.480 +
   4.481 +/**
   4.482 + * \fn int SDL_QueryTexture(SDL_TextureID textureID, Uint32 *format, int *access, int *w, int *h)
   4.483 + *
   4.484 + * \brief Query the attributes of a texture
   4.485 + *
   4.486 + * \param texture A texture to be queried
   4.487 + * \param format A pointer filled in with the raw format of the texture.  The actual format may differ, but pixel transfers will use this format.
   4.488 + * \param access A pointer filled in with the actual access to the texture.
   4.489 + * \param w A pointer filled in with the width of the texture in pixels
   4.490 + * \param h A pointer filled in with the height of the texture in pixels
   4.491 + *
   4.492 + * \return 0 on success, or -1 if the texture is not valid
   4.493 + */
   4.494 +extern DECLSPEC int SDLCALL SDL_QueryTexture(SDL_TextureID textureID,
   4.495 +                                             Uint32 * format, int *access,
   4.496 +                                             int *w, int *h);
   4.497 +
   4.498 +/**
   4.499 + * \fn int SDL_SetTexturePalette(SDL_TextureID textureID, SDL_Color * colors, int firstcolor, int ncolors)
   4.500 + *
   4.501 + * \brief Update an indexed texture with a color palette
   4.502 + *
   4.503 + * \param texture The texture to update
   4.504 + * \param colors The array of RGB color data
   4.505 + * \param firstcolor The first index to update
   4.506 + * \param ncolors The number of palette entries to fill with the color data
   4.507 + *
   4.508 + * \return 0 on success, or -1 if the texture is not valid or not an indexed texture
   4.509 + */
   4.510 +extern DECLSPEC int SDLCALL SDL_SetTexturePalette(SDL_TextureID textureID,
   4.511 +                                                  SDL_Color * colors,
   4.512 +                                                  int firstcolor,
   4.513 +                                                  int ncolors);
   4.514 +
   4.515 +/**
   4.516 + * \fn int SDL_UpdateTexture(SDL_TextureID textureID, SDL_Rect *rect, const void *pixels, int pitch)
   4.517 + *
   4.518 + * \brief Update the given texture rectangle with new pixel data.
   4.519 + *
   4.520 + * \param texture The texture to update
   4.521 + * \param rect A pointer to the rectangle of pixels to update, or NULL to update the entire texture.
   4.522 + * \param pixels The raw pixel data
   4.523 + * \param pitch The number of bytes between rows of pixel data
   4.524 + *
   4.525 + * \return 0 on success, or -1 if the texture is not valid
   4.526 + *
   4.527 + * \note This is a very slow function for textures not created with SDL_TextureAccess_Local.
   4.528 + */
   4.529 +extern DECLSPEC int SDLCALL SDL_UpdateTexture(SDL_TextureID textureID,
   4.530 +                                              SDL_Rect * rect,
   4.531 +                                              const void *pixels, int pitch);
   4.532 +
   4.533 +/**
   4.534 + * \fn void SDL_LockTexture(SDL_TextureID textureID, SDL_Rect *rect, int markDirty, void **pixels, int *pitch)
   4.535 + *
   4.536 + * \brief Lock a portion of the texture for pixel access.
   4.537 + *
   4.538 + * \param texture The texture to lock for access, which must have been created with SDL_TextureAccess_Local.
   4.539 + * \param rect A pointer to the rectangle to lock for access. If the rect is NULL, the entire texture will be locked.
   4.540 + * \param markDirty If this is nonzero, the locked area will be marked dirty when the texture is unlocked.
   4.541 + * \param pixels This is filled in with a pointer to the locked pixels, appropriately offset by the locked area.
   4.542 + * \param pitch This is filled in with the pitch of the locked pixels.
   4.543 + *
   4.544 + * \return 0 on success, or -1 if the texture is not valid or was created with SDL_TextureAccess_Remote
   4.545 + *
   4.546 + * \sa SDL_DirtyTexture()
   4.547 + * \sa SDL_UnlockTexture()
   4.548 + */
   4.549 +extern DECLSPEC int SDLCALL SDL_LockTexture(SDL_TextureID textureID,
   4.550 +                                            SDL_Rect * rect, int markDirty,
   4.551 +                                            void **pixels, int *pitch);
   4.552 +
   4.553 +/**
   4.554 + * \fn void SDL_UnlockTexture(SDL_TextureID textureID)
   4.555 + *
   4.556 + * \brief Unlock a texture, uploading the changes to video memory, if needed.
   4.557 + *
   4.558 + * \sa SDL_LockTexture()
   4.559 + * \sa SDL_DirtyTexture()
   4.560 + */
   4.561 +extern DECLSPEC void SDLCALL SDL_UnlockTexture(SDL_TextureID textureID);
   4.562 +
   4.563 +/**
   4.564 + * \fn void SDL_DirtyTexture(SDL_TextureID textureID, int numrects, SDL_Rect * rects)
   4.565 + *
   4.566 + * \brief Mark the specified rectangles of the texture as dirty.
   4.567 + *
   4.568 + * \note The texture must have been created with SDL_TextureAccess_Local.
   4.569 + *
   4.570 + * \sa SDL_LockTexture()
   4.571 + * \sa SDL_UnlockTexture()
   4.572 + */
   4.573 +extern DECLSPEC void SDLCALL SDL_DirtyTexture(SDL_TextureID textureID,
   4.574 +                                              int numrects, SDL_Rect * rects);
   4.575 +
   4.576 +/**
   4.577 + * \fn void SDL_SelectRenderTexture(SDL_TextureID textureID)
   4.578 + *
   4.579 + * \brief Select a texture as the rendering target, or 0 to reselect the current window.
   4.580 + *
   4.581 + * \note The texture must have been created with SDL_TextureAccess_Render.
   4.582 + */
   4.583 +extern DECLSPEC void SDLCALL SDL_SelectRenderTexture(SDL_TextureID textureID);
   4.584 +
   4.585 +/**
   4.586 + * \fn void SDL_RenderFill(SDL_Rect *rect, Uint32 color)
   4.587 + *
   4.588 + * \brief Fill the current rendering target with the specified color.
   4.589 + *
   4.590 + * \param rect A pointer to the destination rectangle, or NULL for the entire rendering target.
   4.591 + * \param color An ARGB color value.
   4.592 + *
   4.593 + * \return 0 on success, or -1 if there is no renderer current
   4.594 + */
   4.595 +extern DECLSPEC int SDLCALL SDL_RenderFill(SDL_Rect * rect, Uint32 color);
   4.596 +
   4.597 +/**
   4.598 + * \fn int SDL_RenderCopy(SDL_TextureID textureID, SDL_Rect *srcrect, SDL_Rect *dstrect, Uint32 blendMode, Uint32 scaleMode)
   4.599 + *
   4.600 + * \brief Copy a portion of the texture to the current rendering target.
   4.601 + *
   4.602 + * \param texture The source texture.
   4.603 + * \param srcrect A pointer to the source rectangle, or NULL for the entire texture.
   4.604 + * \param dstrect A pointer to the destination rectangle, or NULL for the entire rendering target.
   4.605 + * \param blendMode SDL_TextureBlendMode to be used if the source texture has an alpha channel.
   4.606 + * \param scaleMode SDL_TextureScaleMode to be used if the source and destination rectangles don't have the same width and height.
   4.607 + *
   4.608 + * \return 0 on success, or -1 if there is no renderer current, or the driver doesn't support the requested operation.
   4.609 + *
   4.610 + * \note You can check the video driver info to see what operations are supported.
   4.611 + */
   4.612 +extern DECLSPEC int SDLCALL SDL_RenderCopy(SDL_TextureID textureID,
   4.613 +                                           SDL_Rect * srcrect,
   4.614 +                                           SDL_Rect * dstrect, int blendMode,
   4.615 +                                           int scaleMode);
   4.616 +
   4.617 +/**
   4.618 + * \fn int SDL_RenderReadPixels(SDL_Rect *rect, void *pixels, int pitch)
   4.619 + *
   4.620 + * \brief Read pixels from the current rendering target.
   4.621 + *
   4.622 + * \param rect A pointer to the rectangle to read, or NULL for the entire render target
   4.623 + * \param pixels A pointer to be filled in with the pixel data
   4.624 + * \param pitch The pitch of the pixels parameter
   4.625 + *
   4.626 + * \return 0 on success, or -1 if pixel reading is not supported.
   4.627 + *
   4.628 + * \warning This is a very slow operation, and should not be used frequently.
   4.629 + */
   4.630 +extern DECLSPEC int SDLCALL SDL_RenderReadPixels(SDL_Rect * rect,
   4.631 +                                                 void *pixels, int pitch);
   4.632 +
   4.633 +/**
   4.634 + * \fn int SDL_RenderWritePixels(SDL_Rect *rect, const void *pixels, int pitch)
   4.635 + *
   4.636 + * \brief Write pixels to the current rendering target.
   4.637 + *
   4.638 + * \param rect A pointer to the rectangle to write, or NULL for the entire render target
   4.639 + * \param pixels A pointer to the pixel data to write
   4.640 + * \param pitch The pitch of the pixels parameter
   4.641 + *
   4.642 + * \return 0 on success, or -1 if pixel writing is not supported.
   4.643 + *
   4.644 + * \warning This is a very slow operation, and should not be used frequently.
   4.645 + */
   4.646 +extern DECLSPEC int SDLCALL SDL_RenderWritePixels(SDL_Rect * rect,
   4.647 +                                                  const void *pixels,
   4.648 +                                                  int pitch);
   4.649 +
   4.650 +/**
   4.651 + * \fn void SDL_RenderPresent(void)
   4.652 + *
   4.653 + * \brief Update the screen with rendering performed.
   4.654 + */
   4.655 +extern DECLSPEC void SDLCALL SDL_RenderPresent(void);
   4.656 +
   4.657 +/**
   4.658 + * \fn void SDL_DestroyTexture(SDL_TextureID textureID);
   4.659 + *
   4.660 + * \brief Destroy the specified texture.
   4.661 + *
   4.662 + * \sa SDL_CreateTexture()
   4.663 + * \sa SDL_CreateTextureFromSurface()
   4.664 + */
   4.665 +extern DECLSPEC void SDLCALL SDL_DestroyTexture(SDL_TextureID textureID);
   4.666 +
   4.667 +/**
   4.668 + * \fn void SDL_DestroyRenderer(SDL_WindowID windowID);
   4.669 + *
   4.670 + * \brief Destroy the rendering context for a window and free associated
   4.671 + *        textures.
   4.672 + *
   4.673 + * \sa SDL_CreateRenderer()
   4.674 + */
   4.675 +extern DECLSPEC void SDLCALL SDL_DestroyRenderer(SDL_WindowID windowID);
   4.676  
   4.677  /*
   4.678   * Set the gamma correction for each of the color channels.
   4.679 @@ -796,33 +1104,9 @@
   4.680   * If the function runs out of memory, it will return NULL.
   4.681   *
   4.682   * The 'flags' tell what kind of surface to create.
   4.683 - * SDL_SWSURFACE means that the surface should be created in system memory.
   4.684 - * SDL_HWSURFACE means that the surface should be created in video memory,
   4.685 - * with the same format as the display surface.  This is useful for surfaces
   4.686 - * that will not change much, to take advantage of hardware acceleration
   4.687 - * when being blitted to the display surface.
   4.688 - * SDL_ASYNCBLIT means that SDL will try to perform asynchronous blits with
   4.689 - * this surface, but you must always lock it before accessing the pixels.
   4.690 - * SDL will wait for current blits to finish before returning from the lock.
   4.691   * SDL_SRCCOLORKEY indicates that the surface will be used for colorkey blits.
   4.692 - * If the hardware supports acceleration of colorkey blits between
   4.693 - * two surfaces in video memory, SDL will try to place the surface in
   4.694 - * video memory. If this isn't possible or if there is no hardware
   4.695 - * acceleration available, the surface will be placed in system memory.
   4.696 - * SDL_SRCALPHA means that the surface will be used for alpha blits and 
   4.697 - * if the hardware supports hardware acceleration of alpha blits between
   4.698 - * two surfaces in video memory, to place the surface in video memory
   4.699 - * if possible, otherwise it will be placed in system memory.
   4.700 - * If the surface is created in video memory, blits will be _much_ faster,
   4.701 - * but the surface format must be identical to the video surface format,
   4.702 - * and the only way to access the pixels member of the surface is to use
   4.703 - * the SDL_LockSurface() and SDL_UnlockSurface() calls.
   4.704 - * If the requested surface actually resides in video memory, SDL_HWSURFACE
   4.705 - * will be set in the flags member of the returned surface.  If for some
   4.706 - * reason the surface could not be placed in video memory, it will not have
   4.707 - * the SDL_HWSURFACE flag set, and will be created in system memory instead.
   4.708 + * SDL_SRCALPHA means that the surface will be used for alpha blits.
   4.709   */
   4.710 -#define SDL_AllocSurface    SDL_CreateRGBSurface
   4.711  extern DECLSPEC SDL_Surface *SDLCALL SDL_CreateRGBSurface
   4.712      (Uint32 flags, int width, int height, int depth,
   4.713       Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask);
   4.714 @@ -835,6 +1119,8 @@
   4.715                                                                Uint32 Gmask,
   4.716                                                                Uint32 Bmask,
   4.717                                                                Uint32 Amask);
   4.718 +extern DECLSPEC SDL_Surface *SDLCALL
   4.719 +SDL_CreateRGBSurfaceFromTexture(SDL_TextureID textureID);
   4.720  extern DECLSPEC void SDLCALL SDL_FreeSurface(SDL_Surface * surface);
   4.721  
   4.722  /*
   4.723 @@ -846,9 +1132,7 @@
   4.724   *
   4.725   * Not all surfaces require locking.  If SDL_MUSTLOCK(surface) evaluates
   4.726   * to 0, then you can read and write to the surface at any time, and the
   4.727 - * pixel format of the surface will not change.  In particular, if the
   4.728 - * SDL_HWSURFACE flag is not given when calling SDL_SetVideoMode(), you
   4.729 - * will not need to lock the display surface before accessing it.
   4.730 + * pixel format of the surface will not change.
   4.731   * 
   4.732   * No operating system or library calls should be made between lock/unlock
   4.733   * pairs, as critical system locks may be held during this time.
   4.734 @@ -951,6 +1235,18 @@
   4.735      (SDL_Surface * src, SDL_PixelFormat * fmt, Uint32 flags);
   4.736  
   4.737  /*
   4.738 + * This function performs a fast fill of the given rectangle with 'color'
   4.739 + * The given rectangle is clipped to the destination surface clip area
   4.740 + * and the final fill rectangle is saved in the passed in pointer.
   4.741 + * If 'dstrect' is NULL, the whole surface will be filled with 'color'
   4.742 + * The color should be a pixel of the format used by the surface, and 
   4.743 + * can be generated by the SDL_MapRGB() function.
   4.744 + * This function returns 0 on success, or -1 on error.
   4.745 + */
   4.746 +extern DECLSPEC int SDLCALL SDL_FillRect
   4.747 +    (SDL_Surface * dst, SDL_Rect * dstrect, Uint32 color);
   4.748 +
   4.749 +/*
   4.750   * This performs a fast blit from the source surface to the destination
   4.751   * surface.  It assumes that the source and destination rectangles are
   4.752   * the same size.  If either 'srcrect' or 'dstrect' are NULL, the entire
   4.753 @@ -1034,45 +1330,16 @@
   4.754      (SDL_Surface * src, SDL_Rect * srcrect,
   4.755       SDL_Surface * dst, SDL_Rect * dstrect);
   4.756  
   4.757 -/*
   4.758 - * This function performs a fast fill of the given rectangle with 'color'
   4.759 - * The given rectangle is clipped to the destination surface clip area
   4.760 - * and the final fill rectangle is saved in the passed in pointer.
   4.761 - * If 'dstrect' is NULL, the whole surface will be filled with 'color'
   4.762 - * The color should be a pixel of the format used by the surface, and 
   4.763 - * can be generated by the SDL_MapRGB() function.
   4.764 - * This function returns 0 on success, or -1 on error.
   4.765 +/**
   4.766 + * \fn int SDL_SoftStretch(SDL_Surface * src, SDL_Rect * srcrect, SDL_Surface * dst, SDL_Rect * dstrect)
   4.767 + *
   4.768 + * \brief Perform a fast, low quality, stretch blit between two surfaces of the same pixel format.
   4.769 + * \note This function uses a static buffer, and is not thread-safe.
   4.770   */
   4.771 -extern DECLSPEC int SDLCALL SDL_FillRect
   4.772 -    (SDL_Surface * dst, SDL_Rect * dstrect, Uint32 color);
   4.773 -
   4.774 -/* 
   4.775 - * This function takes a surface and copies it to a new surface of the
   4.776 - * pixel format and colors of the video framebuffer, suitable for fast
   4.777 - * blitting onto the display surface.  It calls SDL_ConvertSurface()
   4.778 - *
   4.779 - * If you want to take advantage of hardware colorkey or alpha blit
   4.780 - * acceleration, you should set the colorkey and alpha value before
   4.781 - * calling this function.
   4.782 - *
   4.783 - * If the conversion fails or runs out of memory, it returns NULL
   4.784 - */
   4.785 -extern DECLSPEC SDL_Surface *SDLCALL SDL_DisplayFormat(SDL_Surface * surface);
   4.786 -
   4.787 -/* 
   4.788 - * This function takes a surface and copies it to a new surface of the
   4.789 - * pixel format and colors of the video framebuffer (if possible),
   4.790 - * suitable for fast alpha blitting onto the display surface.
   4.791 - * The new surface will always have an alpha channel.
   4.792 - *
   4.793 - * If you want to take advantage of hardware colorkey or alpha blit
   4.794 - * acceleration, you should set the colorkey and alpha value before
   4.795 - * calling this function.
   4.796 - *
   4.797 - * If the conversion fails or runs out of memory, it returns NULL
   4.798 - */
   4.799 -extern DECLSPEC SDL_Surface *SDLCALL SDL_DisplayFormatAlpha(SDL_Surface *
   4.800 -                                                            surface);
   4.801 +extern DECLSPEC int SDLCALL SDL_SoftStretch(SDL_Surface * src,
   4.802 +                                            SDL_Rect * srcrect,
   4.803 +                                            SDL_Surface * dst,
   4.804 +                                            SDL_Rect * dstrect);
   4.805  
   4.806  
   4.807  /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
   4.808 @@ -1145,12 +1412,6 @@
   4.809   */
   4.810  extern DECLSPEC void SDLCALL SDL_GL_SwapBuffers(void);
   4.811  
   4.812 -/* Not in public API at the moment - do not use! */
   4.813 -extern DECLSPEC int SDLCALL SDL_SoftStretch(SDL_Surface * src,
   4.814 -                                            SDL_Rect * srcrect,
   4.815 -                                            SDL_Surface * dst,
   4.816 -                                            SDL_Rect * dstrect);
   4.817 -
   4.818  /* Ends C function definitions when using C++ */
   4.819  #ifdef __cplusplus
   4.820  /* *INDENT-OFF* */
     5.1 --- a/src/SDL_compat.c	Mon May 29 05:08:33 2006 +0000
     5.2 +++ b/src/SDL_compat.c	Wed Jun 07 16:10:28 2006 +0000
     5.3 @@ -53,6 +53,23 @@
     5.4      return NULL;
     5.5  }
     5.6  
     5.7 +const SDL_VideoInfo *
     5.8 +SDL_GetVideoInfo(void)
     5.9 +{
    5.10 +    static SDL_VideoInfo info;
    5.11 +
    5.12 +    /* Memory leak, compatibility code, who cares? */
    5.13 +    if (!info.vfmt && SDL_GetDesktopDisplayMode()) {
    5.14 +        int bpp;
    5.15 +        Uint32 Rmask, Gmask, Bmask, Amask;
    5.16 +
    5.17 +        SDL_PixelFormatEnumToMasks(SDL_GetDesktopDisplayMode()->format, &bpp,
    5.18 +                                   &Rmask, &Gmask, &Bmask, &Amask);
    5.19 +        info.vfmt = SDL_AllocFormat(bpp, Rmask, Gmask, Bmask, Amask);
    5.20 +    }
    5.21 +    return &info;
    5.22 +}
    5.23 +
    5.24  int
    5.25  SDL_VideoModeOK(int width, int height, int bpp, Uint32 flags)
    5.26  {
    5.27 @@ -296,6 +313,91 @@
    5.28  }
    5.29  
    5.30  SDL_Surface *
    5.31 +SDL_CreateWindowSurface(SDL_WindowID windowID, Uint32 format, Uint32 flags)
    5.32 +{
    5.33 +    SDL_Window *window = SDL_GetWindowFromID(windowID);
    5.34 +    Uint32 black;
    5.35 +    SDL_Surface *surface;
    5.36 +
    5.37 +    if (!window) {
    5.38 +        return NULL;
    5.39 +    }
    5.40 +
    5.41 +    if (!_this->CreateWindowSurface) {
    5.42 +        return NULL;
    5.43 +    }
    5.44 +
    5.45 +    if (!window->surface) {
    5.46 +        _this->CreateWindowSurface(_this, window, flags);
    5.47 +        if (!window->surface) {
    5.48 +            return NULL;
    5.49 +        }
    5.50 +        window->surface->flags |= SDL_SCREEN_SURFACE;
    5.51 +
    5.52 +        /* If we have a palettized surface, create a default palette */
    5.53 +        if (window->surface->format->palette) {
    5.54 +            SDL_Color colors[256];
    5.55 +            SDL_PixelFormat *vf = window->surface->format;
    5.56 +            SDL_DitherColors(colors, vf->BitsPerPixel);
    5.57 +            SDL_SetColors(window->surface, colors, 0, vf->palette->ncolors);
    5.58 +        }
    5.59 +    }
    5.60 +    surface = window->surface;
    5.61 +
    5.62 +    if (window->shadow) {
    5.63 +        SDL_FreeSurface(window->shadow);
    5.64 +        window->shadow = NULL;
    5.65 +    }
    5.66 +
    5.67 +    /* Create a shadow surface if necessary */
    5.68 +    if ((!(flags & SDL_ANYFORMAT)
    5.69 +         && (format != SDL_GetCurrentDisplayMode()->format))
    5.70 +        || ((flags & SDL_HWPALETTE)
    5.71 +            && !(window->surface->flags & SDL_HWPALETTE))) {
    5.72 +        int bpp;
    5.73 +        Uint32 Rmask, Gmask, Bmask, Amask;
    5.74 +
    5.75 +        SDL_PixelFormatEnumToMasks(format, &bpp, &Amask, &Gmask, &Bmask,
    5.76 +                                   &Amask);
    5.77 +        window->shadow =
    5.78 +            SDL_CreateRGBSurface(SDL_SWSURFACE, surface->w, surface->h, bpp,
    5.79 +                                 Rmask, Gmask, Bmask, Amask);
    5.80 +        if (window->shadow == NULL) {
    5.81 +            return NULL;
    5.82 +        }
    5.83 +        window->shadow->flags |= SDL_SHADOW_SURFACE;
    5.84 +
    5.85 +        surface = window->shadow;
    5.86 +
    5.87 +        /* 8-bit shadow surfaces report that they have exclusive palette */
    5.88 +        if (surface->format->palette) {
    5.89 +            surface->flags |= SDL_HWPALETTE;
    5.90 +            if (format == SDL_GetCurrentDisplayMode()->format) {
    5.91 +                SDL_memcpy(surface->format->palette->colors,
    5.92 +                           window->surface->format->palette->colors,
    5.93 +                           window->surface->format->palette->ncolors *
    5.94 +                           sizeof(SDL_Color));
    5.95 +            } else {
    5.96 +                SDL_DitherColors(surface->format->palette->colors, bpp);
    5.97 +            }
    5.98 +        }
    5.99 +    }
   5.100 +
   5.101 +    /* Clear the surface for display */
   5.102 +    {
   5.103 +        Uint32 black = SDL_MapRGB(surface->format, 0, 0, 0);
   5.104 +        SDL_FillRect(surface, NULL, black);
   5.105 +        if (surface->flags & SDL_DOUBLEBUF) {
   5.106 +            SDL_Flip(surface);
   5.107 +            SDL_FillRect(surface, NULL, black);
   5.108 +        }
   5.109 +        SDL_Flip(surface);
   5.110 +    }
   5.111 +
   5.112 +    return surface;
   5.113 +}
   5.114 +
   5.115 +SDL_Surface *
   5.116  SDL_GetVideoSurface(void)
   5.117  {
   5.118      SDL_VideoDevice *_this = SDL_GetVideoDevice();
   5.119 @@ -303,6 +405,201 @@
   5.120      return SDL_VideoSurface;
   5.121  }
   5.122  
   5.123 +SDL_Surface *
   5.124 +SDL_DisplayFormat(SDL_Surface * surface)
   5.125 +{
   5.126 +    Uint32 flags;
   5.127 +
   5.128 +    if (!SDL_PublicSurface) {
   5.129 +        SDL_SetError("No video mode has been set");
   5.130 +        return (NULL);
   5.131 +    }
   5.132 +    /* Set the flags appropriate for copying to display surface */
   5.133 +    if (((SDL_PublicSurface->flags & SDL_HWSURFACE) == SDL_HWSURFACE)
   5.134 +        && _this->info.blit_hw)
   5.135 +        flags = SDL_HWSURFACE;
   5.136 +    else
   5.137 +        flags = SDL_SWSURFACE;
   5.138 +#ifdef AUTORLE_DISPLAYFORMAT
   5.139 +    flags |= (surface->flags & (SDL_SRCCOLORKEY | SDL_SRCALPHA));
   5.140 +    flags |= SDL_RLEACCELOK;
   5.141 +#else
   5.142 +    flags |=
   5.143 +        surface->flags & (SDL_SRCCOLORKEY | SDL_SRCALPHA | SDL_RLEACCELOK);
   5.144 +#endif
   5.145 +    return (SDL_ConvertSurface(surface, SDL_PublicSurface->format, flags));
   5.146 +}
   5.147 +
   5.148 +SDL_Surface *
   5.149 +SDL_DisplayFormatAlpha(SDL_Surface * surface)
   5.150 +{
   5.151 +    SDL_PixelFormat *vf;
   5.152 +    SDL_PixelFormat *format;
   5.153 +    SDL_Surface *converted;
   5.154 +    Uint32 flags;
   5.155 +    /* default to ARGB8888 */
   5.156 +    Uint32 amask = 0xff000000;
   5.157 +    Uint32 rmask = 0x00ff0000;
   5.158 +    Uint32 gmask = 0x0000ff00;
   5.159 +    Uint32 bmask = 0x000000ff;
   5.160 +
   5.161 +    if (!SDL_PublicSurface) {
   5.162 +        SDL_SetError("No video mode has been set");
   5.163 +        return (NULL);
   5.164 +    }
   5.165 +    vf = SDL_PublicSurface->format;
   5.166 +
   5.167 +    switch (vf->BytesPerPixel) {
   5.168 +    case 2:
   5.169 +        /* For XGY5[56]5, use, AXGY8888, where {X, Y} = {R, B}.
   5.170 +           For anything else (like ARGB4444) it doesn't matter
   5.171 +           since we have no special code for it anyway */
   5.172 +        if ((vf->Rmask == 0x1f) &&
   5.173 +            (vf->Bmask == 0xf800 || vf->Bmask == 0x7c00)) {
   5.174 +            rmask = 0xff;
   5.175 +            bmask = 0xff0000;
   5.176 +        }
   5.177 +        break;
   5.178 +
   5.179 +    case 3:
   5.180 +    case 4:
   5.181 +        /* Keep the video format, as long as the high 8 bits are
   5.182 +           unused or alpha */
   5.183 +        if ((vf->Rmask == 0xff) && (vf->Bmask == 0xff0000)) {
   5.184 +            rmask = 0xff;
   5.185 +            bmask = 0xff0000;
   5.186 +        }
   5.187 +        break;
   5.188 +
   5.189 +    default:
   5.190 +        /* We have no other optimised formats right now. When/if a new
   5.191 +           optimised alpha format is written, add the converter here */
   5.192 +        break;
   5.193 +    }
   5.194 +    format = SDL_AllocFormat(32, rmask, gmask, bmask, amask);
   5.195 +    flags = SDL_PublicSurface->flags & SDL_HWSURFACE;
   5.196 +    flags |= surface->flags & (SDL_SRCALPHA | SDL_RLEACCELOK);
   5.197 +    converted = SDL_ConvertSurface(surface, format, flags);
   5.198 +    SDL_FreeFormat(format);
   5.199 +    return (converted);
   5.200 +}
   5.201 +
   5.202 +void
   5.203 +SDL_UpdateRect(SDL_Surface * screen, Sint32 x, Sint32 y, Uint32 w, Uint32 h)
   5.204 +{
   5.205 +    if (screen) {
   5.206 +        SDL_Rect rect;
   5.207 +
   5.208 +        /* Perform some checking */
   5.209 +        if (w == 0)
   5.210 +            w = screen->w;
   5.211 +        if (h == 0)
   5.212 +            h = screen->h;
   5.213 +        if ((int) (x + w) > screen->w)
   5.214 +            return;
   5.215 +        if ((int) (y + h) > screen->h)
   5.216 +            return;
   5.217 +
   5.218 +        /* Fill the rectangle */
   5.219 +        rect.x = (Sint16) x;
   5.220 +        rect.y = (Sint16) y;
   5.221 +        rect.w = (Uint16) w;
   5.222 +        rect.h = (Uint16) h;
   5.223 +        SDL_UpdateRects(screen, 1, &rect);
   5.224 +    }
   5.225 +}
   5.226 +void
   5.227 +SDL_UpdateRects(SDL_Surface * screen, int numrects, SDL_Rect * rects)
   5.228 +{
   5.229 +    int i;
   5.230 +    SDL_Window *window;
   5.231 +
   5.232 +    /* Find the window corresponding to this surface */
   5.233 +    window = SDL_GetWindowFromSurface(screen);
   5.234 +    if (!window) {
   5.235 +        SDL_SetError("Couldn't find window associated with surface");
   5.236 +        return;
   5.237 +    }
   5.238 +
   5.239 +    if (screen->flags & SDL_SHADOW_SURFACE) {
   5.240 +        if (SHOULD_DRAWCURSOR(SDL_cursorstate)) {
   5.241 +            SDL_LockCursor();
   5.242 +            SDL_DrawCursor(screen);
   5.243 +            for (i = 0; i < numrects; ++i) {
   5.244 +                SDL_LowerBlit(screen, &rects[i], window->surface, &rects[i]);
   5.245 +            }
   5.246 +            SDL_EraseCursor(screen);
   5.247 +            SDL_UnlockCursor();
   5.248 +        } else {
   5.249 +            for (i = 0; i < numrects; ++i) {
   5.250 +                SDL_LowerBlit(screen, &rects[i], window->surface, &rects[i]);
   5.251 +            }
   5.252 +        }
   5.253 +
   5.254 +        /* Fall through to video surface update */
   5.255 +        screen = window->surface;
   5.256 +    }
   5.257 +    if ((screen->flags & SDL_SCREEN_SURFACE) && _this->UpdateWindowSurface) {
   5.258 +        /* Update the video surface */
   5.259 +        if (screen->offset) {
   5.260 +            int offset_y = screen->offset / screen->pitch;
   5.261 +            int offset_x = screen->offset % screen->pitch;
   5.262 +            for (i = 0; i < numrects; ++i) {
   5.263 +                rects[i].x += offset_x;
   5.264 +                rects[i].y += offset_y;
   5.265 +            }
   5.266 +            _this->UpdateWindowSurface(_this, window, numrects, rects);
   5.267 +            for (i = 0; i < numrects; ++i) {
   5.268 +                rects[i].x -= offset_x;
   5.269 +                rects[i].y -= offset_y;
   5.270 +            }
   5.271 +        } else {
   5.272 +            _this->UpdateWindowSurface(_this, window, numrects, rects);
   5.273 +        }
   5.274 +    }
   5.275 +}
   5.276 +
   5.277 +int
   5.278 +SDL_Flip(SDL_Surface * screen)
   5.279 +{
   5.280 +    SDL_Window *window;
   5.281 +
   5.282 +    /* Find the window corresponding to this surface */
   5.283 +    window = SDL_GetWindowFromSurface(screen);
   5.284 +    if (!window) {
   5.285 +        SDL_SetError("Couldn't find window associated with surface");
   5.286 +        return;
   5.287 +    }
   5.288 +
   5.289 +    /* Copy the shadow surface to the video surface */
   5.290 +    if (screen->flags & SDL_SHADOW_SURFACE) {
   5.291 +        SDL_Rect rect;
   5.292 +
   5.293 +        rect.x = 0;
   5.294 +        rect.y = 0;
   5.295 +        rect.w = screen->w;
   5.296 +        rect.h = screen->h;
   5.297 +        if (SHOULD_DRAWCURSOR(SDL_cursorstate)) {
   5.298 +            SDL_LockCursor();
   5.299 +            SDL_DrawCursor(screen);
   5.300 +            SDL_LowerBlit(screen, &rect, window->surface, &rect);
   5.301 +            SDL_EraseCursor(screen);
   5.302 +            SDL_UnlockCursor();
   5.303 +        } else {
   5.304 +            SDL_LowerBlit(screen, &rect, window->surface, &rect);
   5.305 +        }
   5.306 +
   5.307 +        /* Fall through to video surface update */
   5.308 +        screen = window->surface;
   5.309 +    }
   5.310 +    if (screen->flags & SDL_DOUBLEBUF) {
   5.311 +        _this->FlipWindowSurface(_this, window);
   5.312 +    } else {
   5.313 +        SDL_UpdateRect(screen, 0, 0, 0, 0);
   5.314 +    }
   5.315 +    return (0);
   5.316 +}
   5.317 +
   5.318  void
   5.319  SDL_WM_SetCaption(const char *title, const char *icon)
   5.320  {
   5.321 @@ -387,9 +684,555 @@
   5.322  }
   5.323  
   5.324  int
   5.325 +SDL_SetScreenColors(SDL_Surface * screen, SDL_Color * colors, int firstcolor,
   5.326 +                    int ncolors)
   5.327 +{
   5.328 +    SDL_Window *window = NULL;
   5.329 +    SDL_Palette *pal;
   5.330 +    int gotall;
   5.331 +    int palsize;
   5.332 +
   5.333 +    /* Verify the parameters */
   5.334 +    pal = screen->format->palette;
   5.335 +    if (!pal) {
   5.336 +        return 0;               /* not a palettized surface */
   5.337 +    }
   5.338 +    gotall = 1;
   5.339 +    palsize = 1 << screen->format->BitsPerPixel;
   5.340 +    if (ncolors > (palsize - firstcolor)) {
   5.341 +        ncolors = (palsize - firstcolor);
   5.342 +        gotall = 0;
   5.343 +    }
   5.344 +
   5.345 +    if (screen->flags & (SDL_SHADOW_SURFACE | SDL_SCREEN_SURFACE)) {
   5.346 +        window = SDL_GetWindowFromSurface(screen);
   5.347 +        if (!window) {
   5.348 +            return 0;
   5.349 +        }
   5.350 +    }
   5.351 +
   5.352 +    if (screen->flags & SDL_SHADOW_SURFACE) {
   5.353 +        SDL_Palette *vidpal;
   5.354 +
   5.355 +        vidpal = window->surface->format->palette;
   5.356 +        if (vidpal && vidpal->ncolors == pal->ncolors) {
   5.357 +            /* This is a shadow surface, and the physical
   5.358 +             * framebuffer is also indexed. Propagate the
   5.359 +             * changes to its logical palette so that
   5.360 +             * updates are always identity blits
   5.361 +             */
   5.362 +            SDL_memcpy(vidpal->colors + firstcolor, colors,
   5.363 +                       ncolors * sizeof(*colors));
   5.364 +        }
   5.365 +        if (window->surface->flags & SDL_HWPALETTE) {
   5.366 +            /* Set the physical palette */
   5.367 +            screen = window->surface;
   5.368 +        } else {
   5.369 +            SDL_UpdateRect(screen, 0, 0, 0, 0);
   5.370 +        }
   5.371 +    }
   5.372 +
   5.373 +    if (screen->flags & SDL_SCREEN_SURFACE) {
   5.374 +        if (_this->SetWindowColors) {
   5.375 +            gotall =
   5.376 +                _this->SetWindowColors(_this, window, firstcolor, ncolors,
   5.377 +                                       colors);
   5.378 +            if (!gotall) {
   5.379 +                /* The video flags shouldn't have SDL_HWPALETTE, and
   5.380 +                   the video driver is responsible for copying back the
   5.381 +                   correct colors into the video surface palette.
   5.382 +                 */
   5.383 +                ;
   5.384 +            }
   5.385 +        }
   5.386 +        SDL_CursorPaletteChanged();
   5.387 +    }
   5.388 +
   5.389 +    return gotall;
   5.390 +}
   5.391 +
   5.392 +int
   5.393  SDL_GetWMInfo(SDL_SysWMinfo * info)
   5.394  {
   5.395      return SDL_GetWindowWMInfo(window, info);
   5.396  }
   5.397  
   5.398 +void
   5.399 +SDL_MoveCursor(int x, int y)
   5.400 +{
   5.401 +    SDL_VideoDevice *_this = SDL_GetVideoDevice();
   5.402 +
   5.403 +    /* Erase and update the current mouse position */
   5.404 +    if (SHOULD_DRAWCURSOR(SDL_cursorstate)) {
   5.405 +        /* Erase and redraw mouse cursor in new position */
   5.406 +        SDL_LockCursor();
   5.407 +        SDL_EraseCursor(SDL_VideoSurface);
   5.408 +        SDL_cursor->area.x = (x - SDL_cursor->hot_x);
   5.409 +        SDL_cursor->area.y = (y - SDL_cursor->hot_y);
   5.410 +        SDL_DrawCursor(SDL_VideoSurface);
   5.411 +        SDL_UnlockCursor();
   5.412 +    } else if (_this->MoveWMCursor) {
   5.413 +        _this->MoveWMCursor(_this, x, y);
   5.414 +    }
   5.415 +}
   5.416 +
   5.417 +/* Keep track of the current cursor colors */
   5.418 +static int palette_changed = 1;
   5.419 +static Uint8 pixels8[2];
   5.420 +
   5.421 +void
   5.422 +SDL_CursorPaletteChanged(void)
   5.423 +{
   5.424 +    palette_changed = 1;
   5.425 +}
   5.426 +
   5.427 +void
   5.428 +SDL_MouseRect(SDL_Rect * area)
   5.429 +{
   5.430 +    SDL_VideoDevice *_this = SDL_GetVideoDevice();
   5.431 +    int clip_diff;
   5.432 +
   5.433 +    *area = SDL_cursor->area;
   5.434 +    if (area->x < 0) {
   5.435 +        area->w += area->x;
   5.436 +        area->x = 0;
   5.437 +    }
   5.438 +    if (area->y < 0) {
   5.439 +        area->h += area->y;
   5.440 +        area->y = 0;
   5.441 +    }
   5.442 +    clip_diff = (area->x + area->w) - SDL_VideoSurface->w;
   5.443 +    if (clip_diff > 0) {
   5.444 +        area->w = area->w < clip_diff ? 0 : area->w - clip_diff;
   5.445 +    }
   5.446 +    clip_diff = (area->y + area->h) - SDL_VideoSurface->h;
   5.447 +    if (clip_diff > 0) {
   5.448 +        area->h = area->h < clip_diff ? 0 : area->h - clip_diff;
   5.449 +    }
   5.450 +}
   5.451 +
   5.452 +static void
   5.453 +SDL_DrawCursorFast(SDL_Surface * screen, SDL_Rect * area)
   5.454 +{
   5.455 +    const Uint32 pixels[2] = { 0xFFFFFFFF, 0x00000000 };
   5.456 +    int i, w, h;
   5.457 +    Uint8 *data, datab;
   5.458 +    Uint8 *mask, maskb;
   5.459 +
   5.460 +    data = SDL_cursor->data + area->y * SDL_cursor->area.w / 8;
   5.461 +    mask = SDL_cursor->mask + area->y * SDL_cursor->area.w / 8;
   5.462 +    switch (screen->format->BytesPerPixel) {
   5.463 +
   5.464 +    case 1:
   5.465 +        {
   5.466 +            Uint8 *dst;
   5.467 +            int dstskip;
   5.468 +
   5.469 +            if (palette_changed) {
   5.470 +                pixels8[0] =
   5.471 +                    (Uint8) SDL_MapRGB(screen->format, 255, 255, 255);
   5.472 +                pixels8[1] = (Uint8) SDL_MapRGB(screen->format, 0, 0, 0);
   5.473 +                palette_changed = 0;
   5.474 +            }
   5.475 +            dst = (Uint8 *) screen->pixels +
   5.476 +                (SDL_cursor->area.y + area->y) * screen->pitch +
   5.477 +                SDL_cursor->area.x;
   5.478 +            dstskip = screen->pitch - area->w;
   5.479 +
   5.480 +            for (h = area->h; h; h--) {
   5.481 +                for (w = area->w / 8; w; w--) {
   5.482 +                    maskb = *mask++;
   5.483 +                    datab = *data++;
   5.484 +                    for (i = 0; i < 8; ++i) {
   5.485 +                        if (maskb & 0x80) {
   5.486 +                            *dst = pixels8[datab >> 7];
   5.487 +                        }
   5.488 +                        maskb <<= 1;
   5.489 +                        datab <<= 1;
   5.490 +                        dst++;
   5.491 +                    }
   5.492 +                }
   5.493 +                dst += dstskip;
   5.494 +            }
   5.495 +        }
   5.496 +        break;
   5.497 +
   5.498 +    case 2:
   5.499 +        {
   5.500 +            Uint16 *dst;
   5.501 +            int dstskip;
   5.502 +
   5.503 +            dst = (Uint16 *) screen->pixels +
   5.504 +                (SDL_cursor->area.y + area->y) * screen->pitch / 2 +
   5.505 +                SDL_cursor->area.x;
   5.506 +            dstskip = (screen->pitch / 2) - area->w;
   5.507 +
   5.508 +            for (h = area->h; h; h--) {
   5.509 +                for (w = area->w / 8; w; w--) {
   5.510 +                    maskb = *mask++;
   5.511 +                    datab = *data++;
   5.512 +                    for (i = 0; i < 8; ++i) {
   5.513 +                        if (maskb & 0x80) {
   5.514 +                            *dst = (Uint16) pixels[datab >> 7];
   5.515 +                        }
   5.516 +                        maskb <<= 1;
   5.517 +                        datab <<= 1;
   5.518 +                        dst++;
   5.519 +                    }
   5.520 +                }
   5.521 +                dst += dstskip;
   5.522 +            }
   5.523 +        }
   5.524 +        break;
   5.525 +
   5.526 +    case 3:
   5.527 +        {
   5.528 +            Uint8 *dst;
   5.529 +            int dstskip;
   5.530 +
   5.531 +            dst = (Uint8 *) screen->pixels +
   5.532 +                (SDL_cursor->area.y + area->y) * screen->pitch +
   5.533 +                SDL_cursor->area.x * 3;
   5.534 +            dstskip = screen->pitch - area->w * 3;
   5.535 +
   5.536 +            for (h = area->h; h; h--) {
   5.537 +                for (w = area->w / 8; w; w--) {
   5.538 +                    maskb = *mask++;
   5.539 +                    datab = *data++;
   5.540 +                    for (i = 0; i < 8; ++i) {
   5.541 +                        if (maskb & 0x80) {
   5.542 +                            SDL_memset(dst, pixels[datab >> 7], 3);
   5.543 +                        }
   5.544 +                        maskb <<= 1;
   5.545 +                        datab <<= 1;
   5.546 +                        dst += 3;
   5.547 +                    }
   5.548 +                }
   5.549 +                dst += dstskip;
   5.550 +            }
   5.551 +        }
   5.552 +        break;
   5.553 +
   5.554 +    case 4:
   5.555 +        {
   5.556 +            Uint32 *dst;
   5.557 +            int dstskip;
   5.558 +
   5.559 +            dst = (Uint32 *) screen->pixels +
   5.560 +                (SDL_cursor->area.y + area->y) * screen->pitch / 4 +
   5.561 +                SDL_cursor->area.x;
   5.562 +            dstskip = (screen->pitch / 4) - area->w;
   5.563 +
   5.564 +            for (h = area->h; h; h--) {
   5.565 +                for (w = area->w / 8; w; w--) {
   5.566 +                    maskb = *mask++;
   5.567 +                    datab = *data++;
   5.568 +                    for (i = 0; i < 8; ++i) {
   5.569 +                        if (maskb & 0x80) {
   5.570 +                            *dst = pixels[datab >> 7];
   5.571 +                        }
   5.572 +                        maskb <<= 1;
   5.573 +                        datab <<= 1;
   5.574 +                        dst++;
   5.575 +                    }
   5.576 +                }
   5.577 +                dst += dstskip;
   5.578 +            }
   5.579 +        }
   5.580 +        break;
   5.581 +    }
   5.582 +}
   5.583 +
   5.584 +static void
   5.585 +SDL_DrawCursorSlow(SDL_Surface * screen, SDL_Rect * area)
   5.586 +{
   5.587 +    const Uint32 pixels[2] = { 0xFFFFFF, 0x000000 };
   5.588 +    int h;
   5.589 +    int x, minx, maxx;
   5.590 +    Uint8 *data, datab = 0;
   5.591 +    Uint8 *mask, maskb = 0;
   5.592 +    Uint8 *dst;
   5.593 +    int dstbpp, dstskip;
   5.594 +
   5.595 +    data = SDL_cursor->data + area->y * SDL_cursor->area.w / 8;
   5.596 +    mask = SDL_cursor->mask + area->y * SDL_cursor->area.w / 8;
   5.597 +    dstbpp = screen->format->BytesPerPixel;
   5.598 +    dst = (Uint8 *) screen->pixels +
   5.599 +        (SDL_cursor->area.y + area->y) * screen->pitch +
   5.600 +        SDL_cursor->area.x * dstbpp;
   5.601 +    dstskip = screen->pitch - SDL_cursor->area.w * dstbpp;
   5.602 +
   5.603 +    minx = area->x;
   5.604 +    maxx = area->x + area->w;
   5.605 +    if (screen->format->BytesPerPixel == 1) {
   5.606 +        if (palette_changed) {
   5.607 +            pixels8[0] = (Uint8) SDL_MapRGB(screen->format, 255, 255, 255);
   5.608 +            pixels8[1] = (Uint8) SDL_MapRGB(screen->format, 0, 0, 0);
   5.609 +            palette_changed = 0;
   5.610 +        }
   5.611 +        for (h = area->h; h; h--) {
   5.612 +            for (x = 0; x < SDL_cursor->area.w; ++x) {
   5.613 +                if ((x % 8) == 0) {
   5.614 +                    maskb = *mask++;
   5.615 +                    datab = *data++;
   5.616 +                }
   5.617 +                if ((x >= minx) && (x < maxx)) {
   5.618 +                    if (maskb & 0x80) {
   5.619 +                        SDL_memset(dst, pixels8[datab >> 7], dstbpp);
   5.620 +                    }
   5.621 +                }
   5.622 +                maskb <<= 1;
   5.623 +                datab <<= 1;
   5.624 +                dst += dstbpp;
   5.625 +            }
   5.626 +            dst += dstskip;
   5.627 +        }
   5.628 +    } else {
   5.629 +        for (h = area->h; h; h--) {
   5.630 +            for (x = 0; x < SDL_cursor->area.w; ++x) {
   5.631 +                if ((x % 8) == 0) {
   5.632 +                    maskb = *mask++;
   5.633 +                    datab = *data++;
   5.634 +                }
   5.635 +                if ((x >= minx) && (x < maxx)) {
   5.636 +                    if (maskb & 0x80) {
   5.637 +                        SDL_memset(dst, pixels[datab >> 7], dstbpp);
   5.638 +                    }
   5.639 +                }
   5.640 +                maskb <<= 1;
   5.641 +                datab <<= 1;
   5.642 +                dst += dstbpp;
   5.643 +            }
   5.644 +            dst += dstskip;
   5.645 +        }
   5.646 +    }
   5.647 +}
   5.648 +
   5.649 +/* This handles the ugly work of converting the saved cursor background from
   5.650 +   the pixel format of the shadow surface to that of the video surface.
   5.651 +   This is only necessary when blitting from a shadow surface of a different
   5.652 +   pixel format than the video surface, and using a software rendered cursor.
   5.653 +*/
   5.654 +static void
   5.655 +SDL_ConvertCursorSave(SDL_Surface * screen, int w, int h)
   5.656 +{
   5.657 +    SDL_VideoDevice *_this = SDL_GetVideoDevice();
   5.658 +    SDL_BlitInfo info;
   5.659 +    SDL_loblit RunBlit;
   5.660 +
   5.661 +    /* Make sure we can steal the blit mapping */
   5.662 +    if (screen->map->dst != SDL_VideoSurface) {
   5.663 +        return;
   5.664 +    }
   5.665 +
   5.666 +    /* Set up the blit information */
   5.667 +    info.s_pixels = SDL_cursor->save[1];
   5.668 +    info.s_width = w;
   5.669 +    info.s_height = h;
   5.670 +    info.s_skip = 0;
   5.671 +    info.d_pixels = SDL_cursor->save[0];
   5.672 +    info.d_width = w;
   5.673 +    info.d_height = h;
   5.674 +    info.d_skip = 0;
   5.675 +    info.aux_data = screen->map->sw_data->aux_data;
   5.676 +    info.src = screen->format;
   5.677 +    info.table = screen->map->table;
   5.678 +    info.dst = SDL_VideoSurface->format;
   5.679 +    RunBlit = screen->map->sw_data->blit;
   5.680 +
   5.681 +    /* Run the actual software blit */
   5.682 +    RunBlit(&info);
   5.683 +}
   5.684 +
   5.685 +void
   5.686 +SDL_DrawCursorNoLock(SDL_Surface * screen)
   5.687 +{
   5.688 +    SDL_VideoDevice *_this = SDL_GetVideoDevice();
   5.689 +    SDL_Rect area;
   5.690 +
   5.691 +    /* Get the mouse rectangle, clipped to the screen */
   5.692 +    SDL_MouseRect(&area);
   5.693 +    if ((area.w == 0) || (area.h == 0)) {
   5.694 +        return;
   5.695 +    }
   5.696 +
   5.697 +    /* Copy mouse background */
   5.698 +    {
   5.699 +        int w, h, screenbpp;
   5.700 +        Uint8 *src, *dst;
   5.701 +
   5.702 +        /* Set up the copy pointers */
   5.703 +        screenbpp = screen->format->BytesPerPixel;
   5.704 +        if ((screen == SDL_VideoSurface) ||
   5.705 +            FORMAT_EQUAL(screen->format, SDL_VideoSurface->format)) {
   5.706 +            dst = SDL_cursor->save[0];
   5.707 +        } else {
   5.708 +            dst = SDL_cursor->save[1];
   5.709 +        }
   5.710 +        src = (Uint8 *) screen->pixels + area.y * screen->pitch +
   5.711 +            area.x * screenbpp;
   5.712 +
   5.713 +        /* Perform the copy */
   5.714 +        w = area.w * screenbpp;
   5.715 +        h = area.h;
   5.716 +        while (h--) {
   5.717 +            SDL_memcpy(dst, src, w);
   5.718 +            dst += w;
   5.719 +            src += screen->pitch;
   5.720 +        }
   5.721 +    }
   5.722 +
   5.723 +    /* Draw the mouse cursor */
   5.724 +    area.x -= SDL_cursor->area.x;
   5.725 +    area.y -= SDL_cursor->area.y;
   5.726 +    if ((area.x == 0) && (area.w == SDL_cursor->area.w)) {
   5.727 +        SDL_DrawCursorFast(screen, &area);
   5.728 +    } else {
   5.729 +        SDL_DrawCursorSlow(screen, &area);
   5.730 +    }
   5.731 +}
   5.732 +
   5.733 +void
   5.734 +SDL_DrawCursor(SDL_Surface * screen)
   5.735 +{
   5.736 +    /* Lock the screen if necessary */
   5.737 +    if (screen == NULL) {
   5.738 +        return;
   5.739 +    }
   5.740 +    if (SDL_MUSTLOCK(screen)) {
   5.741 +        if (SDL_LockSurface(screen) < 0) {
   5.742 +            return;
   5.743 +        }
   5.744 +    }
   5.745 +
   5.746 +    SDL_DrawCursorNoLock(screen);
   5.747 +
   5.748 +    /* Unlock the screen and update if necessary */
   5.749 +    if (SDL_MUSTLOCK(screen)) {
   5.750 +        SDL_UnlockSurface(screen);
   5.751 +    }
   5.752 +    if ((screen->flags & SDL_SCREEN_SURFACE) &&
   5.753 +        !(screen->flags & SDL_HWSURFACE)) {
   5.754 +        SDL_VideoDevice *_this = SDL_GetVideoDevice();
   5.755 +        SDL_Window *window;
   5.756 +        SDL_Rect area;
   5.757 +
   5.758 +        window = SDL_GetWindowFromSurface(screen);
   5.759 +        if (!window) {
   5.760 +            return;
   5.761 +        }
   5.762 +
   5.763 +        SDL_MouseRect(&area);
   5.764 +
   5.765 +        if (_this->UpdateWindowSurface) {
   5.766 +            _this->UpdateWindowSurface(_this, window, 1, &area);
   5.767 +        }
   5.768 +    }
   5.769 +}
   5.770 +
   5.771 +void
   5.772 +SDL_EraseCursorNoLock(SDL_Surface * screen)
   5.773 +{
   5.774 +    SDL_VideoDevice *_this = SDL_GetVideoDevice();
   5.775 +    SDL_Window *window;
   5.776 +    SDL_Rect area;
   5.777 +
   5.778 +    /* Get the window associated with the surface */
   5.779 +    window = SDL_GetWindowFromSurface(screen);
   5.780 +    if (!window || !window->surface) {
   5.781 +        return;
   5.782 +    }
   5.783 +
   5.784 +    /* Get the mouse rectangle, clipped to the screen */
   5.785 +    SDL_MouseRect(&area);
   5.786 +    if ((area.w == 0) || (area.h == 0)) {
   5.787 +        return;
   5.788 +    }
   5.789 +
   5.790 +    /* Copy mouse background */
   5.791 +    {
   5.792 +        int w, h, screenbpp;
   5.793 +        Uint8 *src, *dst;
   5.794 +
   5.795 +        /* Set up the copy pointers */
   5.796 +        screenbpp = screen->format->BytesPerPixel;
   5.797 +        if ((screen->flags & SDL_SCREEN_SURFACE) ||
   5.798 +            FORMAT_EQUAL(screen->format, window->surface->format)) {
   5.799 +            src = SDL_cursor->save[0];
   5.800 +        } else {
   5.801 +            src = SDL_cursor->save[1];
   5.802 +        }
   5.803 +        dst = (Uint8 *) screen->pixels + area.y * screen->pitch +
   5.804 +            area.x * screenbpp;
   5.805 +
   5.806 +        /* Perform the copy */
   5.807 +        w = area.w * screenbpp;
   5.808 +        h = area.h;
   5.809 +        while (h--) {
   5.810 +            SDL_memcpy(dst, src, w);
   5.811 +            src += w;
   5.812 +            dst += screen->pitch;
   5.813 +        }
   5.814 +
   5.815 +        /* Perform pixel conversion on cursor background */
   5.816 +        if (src > SDL_cursor->save[1]) {
   5.817 +            SDL_ConvertCursorSave(screen, area.w, area.h);
   5.818 +        }
   5.819 +    }
   5.820 +}
   5.821 +
   5.822 +void
   5.823 +SDL_EraseCursor(SDL_Surface * screen)
   5.824 +{
   5.825 +    /* Lock the screen if necessary */
   5.826 +    if (screen == NULL) {
   5.827 +        return;
   5.828 +    }
   5.829 +    if (SDL_MUSTLOCK(screen)) {
   5.830 +        if (SDL_LockSurface(screen) < 0) {
   5.831 +            return;
   5.832 +        }
   5.833 +    }
   5.834 +
   5.835 +    SDL_EraseCursorNoLock(screen);
   5.836 +
   5.837 +    /* Unlock the screen and update if necessary */
   5.838 +    if (SDL_MUSTLOCK(screen)) {
   5.839 +        SDL_UnlockSurface(screen);
   5.840 +    }
   5.841 +    if ((screen->flags & SDL_SCREEN_SURFACE) &&
   5.842 +        !(screen->flags & SDL_HWSURFACE)) {
   5.843 +        SDL_VideoDevice *_this = SDL_GetVideoDevice();
   5.844 +        SDL_Window *window;
   5.845 +        SDL_Rect area;
   5.846 +
   5.847 +        window = SDL_GetWindowFromSurface(screen);
   5.848 +        if (!window) {
   5.849 +            return;
   5.850 +        }
   5.851 +
   5.852 +        SDL_MouseRect(&area);
   5.853 +
   5.854 +        if (_this->UpdateWindowSurface) {
   5.855 +            _this->UpdateWindowSurface(_this, window, 1, &area);
   5.856 +        }
   5.857 +    }
   5.858 +}
   5.859 +
   5.860 +/* Reset the cursor on video mode change
   5.861 +   FIXME:  Keep track of all cursors, and reset them all.
   5.862 + */
   5.863 +void
   5.864 +SDL_ResetCursor(void)
   5.865 +{
   5.866 +    int savelen;
   5.867 +
   5.868 +    if (SDL_cursor) {
   5.869 +        savelen = SDL_cursor->area.w * 4 * SDL_cursor->area.h;
   5.870 +        SDL_cursor->area.x = 0;
   5.871 +        SDL_cursor->area.y = 0;
   5.872 +        SDL_memset(SDL_cursor->save[0], 0, savelen);
   5.873 +    }
   5.874 +}
   5.875 +
   5.876  /* vi: set ts=4 sw=4 expandtab: */
     6.1 --- a/src/events/SDL_events_c.h	Mon May 29 05:08:33 2006 +0000
     6.2 +++ b/src/events/SDL_events_c.h	Wed Jun 07 16:10:28 2006 +0000
     6.3 @@ -23,6 +23,7 @@
     6.4  
     6.5  /* Useful functions and variables from SDL_events.c */
     6.6  #include "SDL_events.h"
     6.7 +#include "SDL_mouse_c.h"
     6.8  
     6.9  /* Start and stop the event processing loop */
    6.10  extern int SDL_StartEventLoop(Uint32 flags);
    6.11 @@ -33,15 +34,18 @@
    6.12  extern void SDL_Unlock_EventThread(void);
    6.13  extern Uint32 SDL_EventThreadID(void);
    6.14  
    6.15 -/* Event handler init routines */
    6.16  extern int SDL_KeyboardInit(void);
    6.17 -extern int SDL_MouseInit(void);
    6.18 +extern int SDL_SendKeyboard(Uint8 state, SDL_keysym * key);
    6.19 +extern void SDL_KeyboardQuit(void);
    6.20 +
    6.21  extern int SDL_QuitInit(void);
    6.22 +extern int SDL_SendQuit(void);
    6.23 +extern void SDL_QuitQuit(void);
    6.24  
    6.25 -/* Event handler quit routines */
    6.26 -extern void SDL_KeyboardQuit(void);
    6.27 -extern void SDL_MouseQuit(void);
    6.28 -extern void SDL_QuitQuit(void);
    6.29 +extern int SDL_SendWindowEvent(SDL_WindowID windowID, Uint8 windowevent,
    6.30 +                               int data1, int data2);
    6.31 +
    6.32 +extern int SDL_SendSysWMEvent(SDL_SysWMmsg * message);
    6.33  
    6.34  /* The event filter function */
    6.35  extern SDL_EventFilter SDL_EventOK;
    6.36 @@ -49,25 +53,6 @@
    6.37  /* The array of event processing states */
    6.38  extern Uint8 SDL_ProcessEvents[SDL_NUMEVENTS];
    6.39  
    6.40 -/* Internal event queueing functions
    6.41 -   (from SDL_mouse.c, SDL_keyboard.c, SDL_quit.c, SDL_events.c, SDL_windowevents.c)
    6.42 - */
    6.43 -extern int SDL_PrivateWindowEvent(SDL_WindowID windowID, Uint8 windowevent,
    6.44 -                                  int data1, int data2);
    6.45 -extern int SDL_PrivateMouseMotion(Uint8 buttonstate, int relative, Sint16 x,
    6.46 -                                  Sint16 y);
    6.47 -extern int SDL_PrivateMouseButton(Uint8 state, Uint8 button, Sint16 x,
    6.48 -                                  Sint16 y);
    6.49 -extern int SDL_PrivateKeyboard(Uint8 state, SDL_keysym * key);
    6.50 -extern int SDL_PrivateQuit(void);
    6.51 -extern int SDL_PrivateSysWMEvent(SDL_SysWMmsg * message);
    6.52 -
    6.53 -/* Used by the activity event handler to remove mouse focus */
    6.54 -extern void SDL_ResetMouse(void);
    6.55 -
    6.56 -/* Used by the activity event handler to remove keyboard focus */
    6.57 -extern void SDL_ResetKeyboard(void);
    6.58 -
    6.59  /* Used by the event loop to queue pending keyboard repeat events */
    6.60  extern void SDL_CheckKeyRepeat(void);
    6.61  
     7.1 --- a/src/events/SDL_keyboard.c	Mon May 29 05:08:33 2006 +0000
     7.2 +++ b/src/events/SDL_keyboard.c	Wed Jun 07 16:10:28 2006 +0000
     7.3 @@ -326,7 +326,7 @@
     7.4      for (key = SDLK_FIRST; key < SDLK_LAST; ++key) {
     7.5          if (SDL_KeyState[key] == SDL_PRESSED) {
     7.6              keysym.sym = key;
     7.7 -            SDL_PrivateKeyboard(SDL_RELEASED, &keysym);
     7.8 +            SDL_SendKeyboard(SDL_RELEASED, &keysym);
     7.9          }
    7.10      }
    7.11      SDL_KeyRepeat.timestamp = 0;
    7.12 @@ -382,7 +382,7 @@
    7.13  
    7.14  /* These are global for SDL_eventloop.c */
    7.15  int
    7.16 -SDL_PrivateKeyboard(Uint8 state, SDL_keysym * keysym)
    7.17 +SDL_SendKeyboard(Uint8 state, SDL_keysym * keysym)
    7.18  {
    7.19      SDL_Event event;
    7.20      int posted, repeatable;
     8.1 --- a/src/events/SDL_mouse.c	Mon May 29 05:08:33 2006 +0000
     8.2 +++ b/src/events/SDL_mouse.c	Wed Jun 07 16:10:28 2006 +0000
     8.3 @@ -25,249 +25,261 @@
     8.4  
     8.5  #include "SDL_events.h"
     8.6  #include "SDL_events_c.h"
     8.7 -#include "../video/SDL_cursor_c.h"
     8.8 -#include "../video/SDL_sysvideo.h"
     8.9 +#include "SDL_mouse_c.h"
    8.10  
    8.11  
    8.12 -/* These are static for our mouse handling code */
    8.13 -static Sint16 SDL_MouseX = 0;
    8.14 -static Sint16 SDL_MouseY = 0;
    8.15 -static Sint16 SDL_DeltaX = 0;
    8.16 -static Sint16 SDL_DeltaY = 0;
    8.17 -static Uint8 SDL_ButtonState = 0;
    8.18 +static int SDL_num_mice;
    8.19 +static int SDL_current_mouse;
    8.20 +static SDL_Mouse *SDL_mice;
    8.21  
    8.22  
    8.23  /* Public functions */
    8.24  int
    8.25  SDL_MouseInit(void)
    8.26  {
    8.27 -    /* The mouse is at (0,0) */
    8.28 -    SDL_MouseX = 0;
    8.29 -    SDL_MouseY = 0;
    8.30 -    SDL_DeltaX = 0;
    8.31 -    SDL_DeltaY = 0;
    8.32 -    SDL_ButtonState = 0;
    8.33 +    return (0);
    8.34 +}
    8.35  
    8.36 -    /* That's it! */
    8.37 -    return (0);
    8.38 +int
    8.39 +SDL_AddMouse(SDL_WindowID focus, int x, int y, Uint8 buttonstate)
    8.40 +{
    8.41 +    SDL_Mouse *new_mice;
    8.42 +    int index;
    8.43 +    SDL_Mouse *mouse;
    8.44 +
    8.45 +    new_mice =
    8.46 +        (SDL_Mouse *) SDL_realloc(SDL_mice,
    8.47 +                                  (SDL_num_mice + 1) * sizeof(*new_mice));
    8.48 +    if (!new_mice) {
    8.49 +        SDL_OutOfMemory();
    8.50 +        return -1;
    8.51 +    }
    8.52 +
    8.53 +    index = SDL_num_mice++;
    8.54 +    mouse = &SDL_mice[index];
    8.55 +    mouse->focus = focus;
    8.56 +    mouse->x = x;
    8.57 +    mouse->y = y;
    8.58 +    mouse->xdelta = 0;
    8.59 +    mouse->ydelta = 0;
    8.60 +    mouse->buttonstate = buttonstate;
    8.61 +
    8.62 +    return index;
    8.63 +}
    8.64 +
    8.65 +SDL_Mouse *
    8.66 +SDL_GetMouse(int index)
    8.67 +{
    8.68 +    if (index < 0 || index >= SDL_num_mice) {
    8.69 +        return NULL;
    8.70 +    }
    8.71 +    return &SDL_mice[index];
    8.72  }
    8.73  
    8.74  void
    8.75  SDL_MouseQuit(void)
    8.76  {
    8.77 +    SDL_num_mice = 0;
    8.78 +    SDL_current_mouse = 0;
    8.79 +
    8.80 +    if (SDL_mice) {
    8.81 +        SDL_free(SDL_mice);
    8.82 +        SDL_mice = NULL;
    8.83 +    }
    8.84  }
    8.85  
    8.86 -/* We lost the mouse, so post button up messages for all pressed buttons */
    8.87 -void
    8.88 -SDL_ResetMouse(void)
    8.89 +int
    8.90 +SDL_GetNumMice(void)
    8.91  {
    8.92 -    Uint8 i;
    8.93 -    for (i = 0; i < sizeof(SDL_ButtonState) * 8; ++i) {
    8.94 -        if (SDL_ButtonState & SDL_BUTTON(i)) {
    8.95 -            SDL_PrivateMouseButton(SDL_RELEASED, i, 0, 0);
    8.96 -        }
    8.97 +    return SDL_num_mice;
    8.98 +}
    8.99 +
   8.100 +int
   8.101 +SDL_SelectMouse(int index)
   8.102 +{
   8.103 +    if (index >= 0 && index < SDL_num_mice) {
   8.104 +        SDL_current_mouse = index;
   8.105      }
   8.106 +    return SDL_current_mouse;
   8.107 +}
   8.108 +
   8.109 +SDL_WindowID
   8.110 +SDL_GetMouseFocusWindow()
   8.111 +{
   8.112 +    SDL_Mouse *mouse = SDL_GetMouse(SDL_current_mouse);
   8.113 +
   8.114 +    if (!mouse) {
   8.115 +        return 0;
   8.116 +    }
   8.117 +    return mouse->focus;
   8.118  }
   8.119  
   8.120  Uint8
   8.121  SDL_GetMouseState(int *x, int *y)
   8.122  {
   8.123 +    SDL_Mouse *mouse = SDL_GetMouse(SDL_current_mouse);
   8.124 +
   8.125 +    if (!mouse) {
   8.126 +        if (x) {
   8.127 +            *x = 0;
   8.128 +        }
   8.129 +        if (y) {
   8.130 +            *y = 0;
   8.131 +        }
   8.132 +        return 0;
   8.133 +    }
   8.134 +
   8.135      if (x) {
   8.136 -        *x = SDL_MouseX;
   8.137 +        *x = mouse->x;
   8.138      }
   8.139      if (y) {
   8.140 -        *y = SDL_MouseY;
   8.141 +        *y = mouse->y;
   8.142      }
   8.143 -    return (SDL_ButtonState);
   8.144 +    return mouse->buttonstate;
   8.145  }
   8.146  
   8.147  Uint8
   8.148  SDL_GetRelativeMouseState(int *x, int *y)
   8.149  {
   8.150 -    if (x)
   8.151 -        *x = SDL_DeltaX;
   8.152 -    if (y)
   8.153 -        *y = SDL_DeltaY;
   8.154 -    SDL_DeltaX = 0;
   8.155 -    SDL_DeltaY = 0;
   8.156 -    return (SDL_ButtonState);
   8.157 +    SDL_Mouse *mouse = SDL_GetMouse(SDL_current_mouse);
   8.158 +
   8.159 +    if (!mouse) {
   8.160 +        if (x) {
   8.161 +            *x = 0;
   8.162 +        }
   8.163 +        if (y) {
   8.164 +            *y = 0;
   8.165 +        }
   8.166 +        return 0;
   8.167 +    }
   8.168 +
   8.169 +    if (x) {
   8.170 +        *x = mouse->xdelta;
   8.171 +    }
   8.172 +    if (y) {
   8.173 +        *y = mouse->ydelta;
   8.174 +    }
   8.175 +    mouse->xdelta = 0;
   8.176 +    mouse->ydelta = 0;
   8.177 +    return mouse->buttonstate;
   8.178  }
   8.179  
   8.180 -static void
   8.181 -ClipOffset(Sint16 * x, Sint16 * y)
   8.182 +int
   8.183 +SDL_SendMouseMotion(int index, SDL_WindowID windowID, int relative, int x,
   8.184 +                    int y)
   8.185  {
   8.186 -    SDL_VideoDevice *_this = SDL_GetVideoDevice();
   8.187 +    SDL_Mouse *mouse = SDL_GetMouse(index);
   8.188 +    int posted;
   8.189 +    int xrel;
   8.190 +    int yrel;
   8.191  
   8.192 -    /* This clips absolute mouse coordinates when the apparent
   8.193 -       display surface is smaller than the real display surface.
   8.194 -     */
   8.195 -    if (SDL_VideoSurface->offset) {
   8.196 -        *y -= SDL_VideoSurface->offset / SDL_VideoSurface->pitch;
   8.197 -        *x -= (SDL_VideoSurface->offset % SDL_VideoSurface->pitch) /
   8.198 -            SDL_VideoSurface->format->BytesPerPixel;
   8.199 -    }
   8.200 -}
   8.201 -
   8.202 -/* These are global for SDL_eventloop.c */
   8.203 -int
   8.204 -SDL_PrivateMouseMotion(Uint8 buttonstate, int relative, Sint16 x, Sint16 y)
   8.205 -{
   8.206 -    SDL_VideoDevice *_this = SDL_GetVideoDevice();
   8.207 -    int posted;
   8.208 -    Uint16 X, Y;
   8.209 -    Sint16 Xrel;
   8.210 -    Sint16 Yrel;
   8.211 -
   8.212 -    /* Don't handle mouse motion if there's no cursor surface */
   8.213 -    if (SDL_VideoSurface == NULL) {
   8.214 -        return (0);
   8.215 +    if (!mouse) {
   8.216 +        return 0;
   8.217      }
   8.218  
   8.219 -    /* Default buttonstate is the current one */
   8.220 -    if (!buttonstate) {
   8.221 -        buttonstate = SDL_ButtonState;
   8.222 +    if (windowID) {
   8.223 +        mouse->focus = windowID;
   8.224      }
   8.225  
   8.226 -    Xrel = x;
   8.227 -    Yrel = y;
   8.228      if (relative) {
   8.229          /* Push the cursor around */
   8.230 -        x = (SDL_MouseX + x);
   8.231 -        y = (SDL_MouseY + y);
   8.232 +        xrel = x;
   8.233 +        yrel = y;
   8.234 +        x = (mouse->x + xrel);
   8.235 +        y = (mouse->y + yrel);
   8.236      } else {
   8.237 -        /* Do we need to clip {x,y} ? */
   8.238 -        ClipOffset(&x, &y);
   8.239 -    }
   8.240 -
   8.241 -    /* Mouse coordinates range from 0 - width-1 and 0 - height-1 */
   8.242 -    if (x < 0)
   8.243 -        X = 0;
   8.244 -    else if (x >= SDL_VideoSurface->w)
   8.245 -        X = SDL_VideoSurface->w - 1;
   8.246 -    else
   8.247 -        X = (Uint16) x;
   8.248 -
   8.249 -    if (y < 0)
   8.250 -        Y = 0;
   8.251 -    else if (y >= SDL_VideoSurface->h)
   8.252 -        Y = SDL_VideoSurface->h - 1;
   8.253 -    else
   8.254 -        Y = (Uint16) y;
   8.255 -
   8.256 -    /* If not relative mode, generate relative motion from clamped X/Y.
   8.257 -       This prevents lots of extraneous large delta relative motion when
   8.258 -       the screen is windowed mode and the mouse is outside the window.
   8.259 -     */
   8.260 -    if (!relative) {
   8.261 -        Xrel = X - SDL_MouseX;
   8.262 -        Yrel = Y - SDL_MouseY;
   8.263 +        xrel = x - mouse->x;
   8.264 +        yrel = y - mouse->y;
   8.265      }
   8.266  
   8.267      /* Drop events that don't change state */
   8.268 -    if (!Xrel && !Yrel) {
   8.269 +    if (!xrel && !yrel) {
   8.270  #if 0
   8.271          printf("Mouse event didn't change state - dropped!\n");
   8.272  #endif
   8.273 -        return (0);
   8.274 +        return 0;
   8.275      }
   8.276  
   8.277      /* Update internal mouse state */
   8.278 -    SDL_ButtonState = buttonstate;
   8.279 -    SDL_MouseX = X;
   8.280 -    SDL_MouseY = Y;
   8.281 -    SDL_DeltaX += Xrel;
   8.282 -    SDL_DeltaY += Yrel;
   8.283 -    SDL_MoveCursor(SDL_MouseX, SDL_MouseY);
   8.284 +    mouse->xdelta += xrel;
   8.285 +    mouse->ydelta += yrel;
   8.286  
   8.287      /* Post the event, if desired */
   8.288      posted = 0;
   8.289      if (SDL_ProcessEvents[SDL_MOUSEMOTION] == SDL_ENABLE) {
   8.290          SDL_Event event;
   8.291 -        SDL_memset(&event, 0, sizeof(event));
   8.292 -        event.type = SDL_MOUSEMOTION;
   8.293 -        event.motion.state = buttonstate;
   8.294 -        event.motion.x = X;
   8.295 -        event.motion.y = Y;
   8.296 -        event.motion.xrel = Xrel;
   8.297 -        event.motion.yrel = Yrel;
   8.298 +        event.motion.type = SDL_MOUSEMOTION;
   8.299 +        event.motion.which = (Uint8) index;
   8.300 +        event.motion.state = mouse->buttonstate;
   8.301 +        event.motion.x = mouse->x;
   8.302 +        event.motion.y = mouse->y;
   8.303 +        event.motion.xrel = xrel;
   8.304 +        event.motion.yrel = yrel;
   8.305 +        event.motion.windowID = mouse->focus;
   8.306          if ((SDL_EventOK == NULL) || (*SDL_EventOK) (&event)) {
   8.307              posted = 1;
   8.308              SDL_PushEvent(&event);
   8.309          }
   8.310      }
   8.311 -    return (posted);
   8.312 +    return posted;
   8.313  }
   8.314  
   8.315  int
   8.316 -SDL_PrivateMouseButton(Uint8 state, Uint8 button, Sint16 x, Sint16 y)
   8.317 +SDL_PrivateMouseButton(int index, SDL_WindowID windowID, Uint8 state,
   8.318 +                       Uint8 button)
   8.319  {
   8.320 -    SDL_VideoDevice *_this = SDL_GetVideoDevice();
   8.321 -    SDL_Event event;
   8.322 +    SDL_Mouse *mouse = SDL_GetMouse(index);
   8.323      int posted;
   8.324 -    int move_mouse;
   8.325 -    Uint8 buttonstate;
   8.326 +    Uint8 type;
   8.327  
   8.328 -    SDL_memset(&event, 0, sizeof(event));
   8.329 +    if (!mouse) {
   8.330 +        return 0;
   8.331 +    }
   8.332  
   8.333 -    /* Check parameters */
   8.334 -    if (x || y) {
   8.335 -        ClipOffset(&x, &y);
   8.336 -        move_mouse = 1;
   8.337 -        /* Mouse coordinates range from 0 - width-1 and 0 - height-1 */
   8.338 -        if (x < 0)
   8.339 -            x = 0;
   8.340 -        else if (x >= SDL_VideoSurface->w)
   8.341 -            x = SDL_VideoSurface->w - 1;
   8.342 -
   8.343 -        if (y < 0)
   8.344 -            y = 0;
   8.345 -        else if (y >= SDL_VideoSurface->h)
   8.346 -            y = SDL_VideoSurface->h - 1;
   8.347 -    } else {
   8.348 -        move_mouse = 0;
   8.349 +    if (windowID) {
   8.350 +        mouse->focus = windowID;
   8.351      }
   8.352 -    if (!x)
   8.353 -        x = SDL_MouseX;
   8.354 -    if (!y)
   8.355 -        y = SDL_MouseY;
   8.356  
   8.357      /* Figure out which event to perform */
   8.358 -    buttonstate = SDL_ButtonState;
   8.359      switch (state) {
   8.360      case SDL_PRESSED:
   8.361 -        event.type = SDL_MOUSEBUTTONDOWN;
   8.362 -        buttonstate |= SDL_BUTTON(button);
   8.363 +        if (mouse->buttonstate & SDL_BUTTON(button)) {
   8.364 +            /* Ignore this event, no state change */
   8.365 +            return 0;
   8.366 +        }
   8.367 +        type = SDL_MOUSEBUTTONDOWN;
   8.368 +        mouse->buttonstate |= SDL_BUTTON(button);
   8.369          break;
   8.370      case SDL_RELEASED:
   8.371 -        event.type = SDL_MOUSEBUTTONUP;
   8.372 -        buttonstate &= ~SDL_BUTTON(button);
   8.373 +        if (!(mouse->buttonstate & SDL_BUTTON(button))) {
   8.374 +            /* Ignore this event, no state change */
   8.375 +            return 0;
   8.376 +        }
   8.377 +        type = SDL_MOUSEBUTTONUP;
   8.378 +        mouse->buttonstate &= ~SDL_BUTTON(button);
   8.379          break;
   8.380      default:
   8.381          /* Invalid state -- bail */
   8.382 -        return (0);
   8.383 -    }
   8.384 -
   8.385 -    /* Update internal mouse state */
   8.386 -    SDL_ButtonState = buttonstate;
   8.387 -    if (move_mouse) {
   8.388 -        SDL_MouseX = x;
   8.389 -        SDL_MouseY = y;
   8.390 -        SDL_MoveCursor(SDL_MouseX, SDL_MouseY);
   8.391 +        return 0;
   8.392      }
   8.393  
   8.394      /* Post the event, if desired */
   8.395      posted = 0;
   8.396 -    if (SDL_ProcessEvents[event.type] == SDL_ENABLE) {
   8.397 +    if (SDL_ProcessEvents[type] == SDL_ENABLE) {
   8.398 +        SDL_Event event;
   8.399 +        event.type = type;
   8.400 +        event.button.which = (Uint8) index;
   8.401          event.button.state = state;
   8.402          event.button.button = button;
   8.403 -        event.button.x = x;
   8.404 -        event.button.y = y;
   8.405 +        event.button.x = mouse->x;
   8.406 +        event.button.y = mouse->y;
   8.407 +        event.button.windowID = windowID;
   8.408          if ((SDL_EventOK == NULL) || (*SDL_EventOK) (&event)) {
   8.409              posted = 1;
   8.410              SDL_PushEvent(&event);
   8.411          }
   8.412      }
   8.413 -    return (posted);
   8.414 +    return posted;
   8.415  }
   8.416  
   8.417  /* vi: set ts=4 sw=4 expandtab: */
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/src/events/SDL_mouse_c.h	Wed Jun 07 16:10:28 2006 +0000
     9.3 @@ -0,0 +1,48 @@
     9.4 +/*
     9.5 +    SDL - Simple DirectMedia Layer
     9.6 +    Copyright (C) 1997-2006 Sam Lantinga
     9.7 +
     9.8 +    This library is free software; you can redistribute it and/or
     9.9 +    modify it under the terms of the GNU Lesser General Public
    9.10 +    License as published by the Free Software Foundation; either
    9.11 +    version 2.1 of the License, or (at your option) any later version.
    9.12 +
    9.13 +    This library is distributed in the hope that it will be useful,
    9.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    9.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    9.16 +    Lesser General Public License for more details.
    9.17 +
    9.18 +    You should have received a copy of the GNU Lesser General Public
    9.19 +    License along with this library; if not, write to the Free Software
    9.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    9.21 +
    9.22 +    Sam Lantinga
    9.23 +    slouken@libsdl.org
    9.24 +*/
    9.25 +#include "SDL_config.h"
    9.26 +
    9.27 +#ifndef _SDL_mouse_c_h
    9.28 +#define _SDL_mouse_c_h
    9.29 +
    9.30 +typedef struct
    9.31 +{
    9.32 +    SDL_WindowID focus;
    9.33 +    int x;
    9.34 +    int y;
    9.35 +    int xdelta;
    9.36 +    int ydelta;
    9.37 +    Uint8 buttonstate;
    9.38 +} SDL_Mouse;
    9.39 +
    9.40 +extern int SDL_MouseInit(void);
    9.41 +extern int SDL_AddMouse(SDL_WindowID focus, int x, int y, Uint8 buttonstate);
    9.42 +extern SDL_Mouse *SDL_GetMouse(int index);
    9.43 +extern int SDL_SendMouseMotion(int index, SDL_WindowID windowID, int relative,
    9.44 +                               int x, int y);
    9.45 +extern int SDL_SendMouseButton(int index, SDL_WindowID windowID, Uint8 state,
    9.46 +                               Uint8 button);
    9.47 +extern void SDL_MouseQuit(void);
    9.48 +
    9.49 +#endif /* _SDL_mouse_c_h */
    9.50 +
    9.51 +/* vi: set ts=4 sw=4 expandtab: */
    10.1 --- a/src/events/SDL_quit.c	Mon May 29 05:08:33 2006 +0000
    10.2 +++ b/src/events/SDL_quit.c	Wed Jun 07 16:10:28 2006 +0000
    10.3 @@ -39,7 +39,7 @@
    10.4      signal(sig, SDL_HandleSIG);
    10.5  
    10.6      /* Signal a quit interrupt */
    10.7 -    SDL_PrivateQuit();
    10.8 +    SDL_SendQuit();
    10.9  }
   10.10  #endif /* HAVE_SIGNAL_H */
   10.11  
   10.12 @@ -80,7 +80,7 @@
   10.13  
   10.14  /* This function returns 1 if it's okay to close the application window */
   10.15  int
   10.16 -SDL_PrivateQuit(void)
   10.17 +SDL_SendQuit(void)
   10.18  {
   10.19      int posted;
   10.20  
    11.1 --- a/src/video/SDL_blit.c	Mon May 29 05:08:33 2006 +0000
    11.2 +++ b/src/video/SDL_blit.c	Wed Jun 07 16:10:28 2006 +0000
    11.3 @@ -217,8 +217,6 @@
    11.4  int
    11.5  SDL_CalculateBlit(SDL_Surface * surface)
    11.6  {
    11.7 -    SDL_VideoDevice *_this = SDL_GetVideoDevice();
    11.8 -    const SDL_VideoInfo *info = SDL_GetVideoInfo();
    11.9      int blit_index;
   11.10  
   11.11      /* Clean everything out to start */
   11.12 @@ -227,52 +225,6 @@
   11.13      }
   11.14      surface->map->sw_blit = NULL;
   11.15  
   11.16 -    /* Figure out if an accelerated hardware blit is possible */
   11.17 -    surface->flags &= ~SDL_HWACCEL;
   11.18 -    if (surface->map->identity) {
   11.19 -        int hw_blit_ok;
   11.20 -
   11.21 -        if ((surface->flags & SDL_HWSURFACE) == SDL_HWSURFACE) {
   11.22 -            /* We only support accelerated blitting to hardware */
   11.23 -            if (surface->map->dst->flags & SDL_HWSURFACE) {
   11.24 -                hw_blit_ok = info->blit_hw;
   11.25 -            } else {
   11.26 -                hw_blit_ok = 0;
   11.27 -            }
   11.28 -            if (hw_blit_ok && (surface->flags & SDL_SRCCOLORKEY)) {
   11.29 -                hw_blit_ok = info->blit_hw_CC;
   11.30 -            }
   11.31 -            if (hw_blit_ok && (surface->flags & SDL_SRCALPHA)) {
   11.32 -                hw_blit_ok = info->blit_hw_A;
   11.33 -            }
   11.34 -        } else {
   11.35 -            /* We only support accelerated blitting to hardware */
   11.36 -            if (surface->map->dst->flags & SDL_HWSURFACE) {
   11.37 -                hw_blit_ok = info->blit_sw;
   11.38 -            } else {
   11.39 -                hw_blit_ok = 0;
   11.40 -            }
   11.41 -            if (hw_blit_ok && (surface->flags & SDL_SRCCOLORKEY)) {
   11.42 -                hw_blit_ok = info->blit_sw_CC;
   11.43 -            }
   11.44 -            if (hw_blit_ok && (surface->flags & SDL_SRCALPHA)) {
   11.45 -                hw_blit_ok = info->blit_sw_A;
   11.46 -            }
   11.47 -        }
   11.48 -        if (hw_blit_ok) {
   11.49 -            _this->CheckHWBlit(_this, surface, surface->map->dst);
   11.50 -        }
   11.51 -    }
   11.52 -
   11.53 -    /* if an alpha pixel format is specified, we can accelerate alpha blits */
   11.54 -    if (((surface->flags & SDL_HWSURFACE) == SDL_HWSURFACE)
   11.55 -        && (_this->displayformatalphapixel)) {
   11.56 -        if ((surface->flags & SDL_SRCALPHA))
   11.57 -            if (info->blit_hw_A) {
   11.58 -                _this->CheckHWBlit(_this, surface, surface->map->dst);
   11.59 -            }
   11.60 -    }
   11.61 -
   11.62      /* Get the blit function index, based on surface mode */
   11.63      /* { 0 = nothing, 1 = colorkey, 2 = alpha, 3 = colorkey+alpha } */
   11.64      blit_index = 0;
   11.65 @@ -321,9 +273,7 @@
   11.66      }
   11.67  
   11.68      /* Choose software blitting function */
   11.69 -    if (surface->flags & SDL_RLEACCELOK
   11.70 -        && (surface->flags & SDL_HWACCEL) != SDL_HWACCEL) {
   11.71 -
   11.72 +    if (surface->flags & SDL_RLEACCELOK) {
   11.73          if (surface->map->identity
   11.74              && (blit_index == 1
   11.75                  || (blit_index == 3 && !surface->format->Amask))) {
    12.1 --- a/src/video/SDL_bmp.c	Mon May 29 05:08:33 2006 +0000
    12.2 +++ b/src/video/SDL_bmp.c	Wed Jun 07 16:10:28 2006 +0000
    12.3 @@ -203,9 +203,9 @@
    12.4      }
    12.5  
    12.6      /* Create a compatible surface, note that the colors are RGB ordered */
    12.7 -    surface = SDL_CreateRGBSurface(SDL_SWSURFACE,
    12.8 -                                   biWidth, biHeight, biBitCount, Rmask,
    12.9 -                                   Gmask, Bmask, 0);
   12.10 +    surface =
   12.11 +        SDL_CreateRGBSurface(0, biWidth, biHeight, biBitCount, Rmask, Gmask,
   12.12 +                             Bmask, 0);
   12.13      if (surface == NULL) {
   12.14          was_error = 1;
   12.15          goto done;
   12.16 @@ -386,8 +386,7 @@
   12.17              SDL_Rect bounds;
   12.18  
   12.19              /* Convert to 24 bits per pixel */
   12.20 -            surface = SDL_CreateRGBSurface(SDL_SWSURFACE,
   12.21 -                                           saveme->w, saveme->h, 24,
   12.22 +            surface = SDL_CreateRGBSurface(0, saveme->w, saveme->h, 24,
   12.23  #if SDL_BYTEORDER == SDL_LIL_ENDIAN
   12.24                                             0x00FF0000, 0x0000FF00, 0x000000FF,
   12.25  #else
    13.1 --- a/src/video/SDL_cursor.c	Mon May 29 05:08:33 2006 +0000
    13.2 +++ b/src/video/SDL_cursor.c	Wed Jun 07 16:10:28 2006 +0000
    13.3 @@ -23,22 +23,17 @@
    13.4  
    13.5  /* General cursor handling code for SDL */
    13.6  
    13.7 -#include "SDL_mutex.h"
    13.8  #include "SDL_video.h"
    13.9  #include "SDL_mouse.h"
   13.10 -#include "SDL_blit.h"
   13.11  #include "SDL_sysvideo.h"
   13.12  #include "SDL_cursor_c.h"
   13.13 -#include "SDL_pixels_c.h"
   13.14  #include "default_cursor.h"
   13.15 -#include "../events/SDL_sysevents.h"
   13.16 -#include "../events/SDL_events_c.h"
   13.17  
   13.18  /* These are static for our cursor handling code */
   13.19 +/* FIXME: Add support for multiple simultaneous cursors */
   13.20  volatile int SDL_cursorstate = CURSOR_VISIBLE;
   13.21  SDL_Cursor *SDL_cursor = NULL;
   13.22  static SDL_Cursor *SDL_defcursor = NULL;
   13.23 -SDL_mutex *SDL_cursorlock = NULL;
   13.24  
   13.25  /* Public functions */
   13.26  void
   13.27 @@ -58,13 +53,10 @@
   13.28              SDL_FreeCursor(cursor);
   13.29          }
   13.30      }
   13.31 -    if (SDL_cursorlock != NULL) {
   13.32 -        SDL_DestroyMutex(SDL_cursorlock);
   13.33 -        SDL_cursorlock = NULL;
   13.34 -    }
   13.35  }
   13.36 +
   13.37  int
   13.38 -SDL_CursorInit(Uint32 multithreaded)
   13.39 +SDL_CursorInit(void)
   13.40  {
   13.41      /* We don't have mouse focus, and the cursor isn't drawn yet */
   13.42  #ifndef IPOD
   13.43 @@ -79,43 +71,15 @@
   13.44          SDL_SetCursor(SDL_defcursor);
   13.45      }
   13.46  
   13.47 -    /* Create a lock if necessary */
   13.48 -    if (multithreaded) {
   13.49 -        SDL_cursorlock = SDL_CreateMutex();
   13.50 -    }
   13.51 -
   13.52      /* That's it! */
   13.53      return (0);
   13.54  }
   13.55  
   13.56 -/* Multi-thread support for cursors */
   13.57 -#ifndef SDL_LockCursor
   13.58 -void
   13.59 -SDL_LockCursor(void)
   13.60 -{
   13.61 -    if (SDL_cursorlock) {
   13.62 -        SDL_mutexP(SDL_cursorlock);
   13.63 -    }
   13.64 -}
   13.65 -#endif
   13.66 -#ifndef SDL_UnlockCursor
   13.67 -void
   13.68 -SDL_UnlockCursor(void)
   13.69 -{
   13.70 -    if (SDL_cursorlock) {
   13.71 -        SDL_mutexV(SDL_cursorlock);
   13.72 -    }
   13.73 -}
   13.74 -#endif
   13.75 -
   13.76 -/* Software cursor drawing support */
   13.77  SDL_Cursor *
   13.78  SDL_CreateCursor(Uint8 * data, Uint8 * mask,
   13.79                   int w, int h, int hot_x, int hot_y)
   13.80  {
   13.81      SDL_VideoDevice *_this = SDL_GetVideoDevice();
   13.82 -    int savelen;
   13.83 -    int i;
   13.84      SDL_Cursor *cursor;
   13.85  
   13.86      /* Make sure the width is a multiple of 8 */
   13.87 @@ -127,41 +91,10 @@
   13.88          return (NULL);
   13.89      }
   13.90  
   13.91 -    /* Allocate memory for the cursor */
   13.92 -    cursor = (SDL_Cursor *) SDL_malloc(sizeof *cursor);
   13.93 -    if (cursor == NULL) {
   13.94 -        SDL_OutOfMemory();
   13.95 -        return (NULL);
   13.96 -    }
   13.97 -    savelen = (w * 4) * h;
   13.98 -    cursor->area.x = 0;
   13.99 -    cursor->area.y = 0;
  13.100 -    cursor->area.w = w;
  13.101 -    cursor->area.h = h;
  13.102 -    cursor->hot_x = hot_x;
  13.103 -    cursor->hot_y = hot_y;
  13.104 -    cursor->data = (Uint8 *) SDL_malloc((w / 8) * h * 2);
  13.105 -    cursor->mask = cursor->data + ((w / 8) * h);
  13.106 -    cursor->save[0] = (Uint8 *) SDL_malloc(savelen * 2);
  13.107 -    cursor->save[1] = cursor->save[0] + savelen;
  13.108 -    cursor->wm_cursor = NULL;
  13.109 -    if (!cursor->data || !cursor->save[0]) {
  13.110 -        SDL_FreeCursor(cursor);
  13.111 -        SDL_OutOfMemory();
  13.112 -        return (NULL);
  13.113 -    }
  13.114 -    for (i = ((w / 8) * h) - 1; i >= 0; --i) {
  13.115 -        cursor->data[i] = data[i];
  13.116 -        cursor->mask[i] = mask[i] | data[i];
  13.117 -    }
  13.118 -    SDL_memset(cursor->save[0], 0, savelen * 2);
  13.119 -
  13.120 -    /* If the window manager gives us a good cursor, we're done! */
  13.121      if (_this->CreateWMCursor) {
  13.122 -        cursor->wm_cursor = _this->CreateWMCursor(_this, data, mask,
  13.123 -                                                  w, h, hot_x, hot_y);
  13.124 +        cursor = _this->CreateWMCursor(_this, data, mask, w, h, hot_x, hot_y);
  13.125      } else {
  13.126 -        cursor->wm_cursor = NULL;
  13.127 +        cursor = NULL;
  13.128      }
  13.129      return (cursor);
  13.130  }
  13.131 @@ -180,56 +113,22 @@
  13.132          return;
  13.133      }
  13.134  
  13.135 -    /* Prevent the event thread from moving the mouse */
  13.136 -    SDL_LockCursor();
  13.137 -
  13.138      /* Set the new cursor */
  13.139      if (cursor && (cursor != SDL_cursor)) {
  13.140 -        /* Erase the current mouse position */
  13.141 -        if (SHOULD_DRAWCURSOR(SDL_cursorstate)) {
  13.142 -            SDL_EraseCursor(SDL_VideoSurface);
  13.143 -        } else if (_this->MoveWMCursor) {
  13.144 -            /* If the video driver is moving the cursor directly,
  13.145 -               it needs to hide the old cursor before (possibly)
  13.146 -               showing the new one.  (But don't erase NULL cursor)
  13.147 -             */
  13.148 -            if (SDL_cursor) {
  13.149 -                _this->ShowWMCursor(_this, NULL);
  13.150 -            }
  13.151 -        }
  13.152          SDL_cursor = cursor;
  13.153      }
  13.154  
  13.155      /* Draw the new mouse cursor */
  13.156      if (SDL_cursor && (SDL_cursorstate & CURSOR_VISIBLE)) {
  13.157 -        /* Use window manager cursor if possible */
  13.158 -        if (SDL_cursor->wm_cursor &&
  13.159 -            _this->ShowWMCursor(_this, SDL_cursor->wm_cursor)) {
  13.160 -            SDL_cursorstate &= ~CURSOR_USINGSW;
  13.161 -        } else {
  13.162 -            SDL_cursorstate |= CURSOR_USINGSW;
  13.163 -            if (_this->ShowWMCursor) {
  13.164 -                _this->ShowWMCursor(_this, NULL);
  13.165 -            }
  13.166 -            {
  13.167 -                int x, y;
  13.168 -                SDL_GetMouseState(&x, &y);
  13.169 -                SDL_cursor->area.x = (x - SDL_cursor->hot_x);
  13.170 -                SDL_cursor->area.y = (y - SDL_cursor->hot_y);
  13.171 -            }
  13.172 -            SDL_DrawCursor(SDL_VideoSurface);
  13.173 +        if (_this->ShowWMCursor) {
  13.174 +            _this->ShowWMCursor(_this, SDL_cursor);
  13.175          }
  13.176      } else {
  13.177          /* Erase window manager mouse (cursor not visible) */
  13.178 -        if (SDL_cursor && (SDL_cursorstate & CURSOR_USINGSW)) {
  13.179 -            SDL_EraseCursor(SDL_VideoSurface);
  13.180 -        } else {
  13.181 -            if (_this) {
  13.182 -                _this->ShowWMCursor(_this, NULL);
  13.183 -            }
  13.184 +        if (_this->ShowWMCursor) {
  13.185 +            _this->ShowWMCursor(_this, NULL);
  13.186          }
  13.187      }
  13.188 -    SDL_UnlockCursor();
  13.189  }
  13.190  
  13.191  SDL_Cursor *
  13.192 @@ -248,16 +147,9 @@
  13.193          if (cursor != SDL_defcursor) {
  13.194              SDL_VideoDevice *_this = SDL_GetVideoDevice();
  13.195  
  13.196 -            if (cursor->data) {
  13.197 -                SDL_free(cursor->data);
  13.198 +            if (_this && _this->FreeWMCursor) {
  13.199 +                _this->FreeWMCursor(_this, cursor);
  13.200              }
  13.201 -            if (cursor->save[0]) {
  13.202 -                SDL_free(cursor->save[0]);
  13.203 -            }
  13.204 -            if (_this && cursor->wm_cursor) {
  13.205 -                _this->FreeWMCursor(_this, cursor->wm_cursor);
  13.206 -            }
  13.207 -            SDL_free(cursor);
  13.208          }
  13.209      }
  13.210  }
  13.211 @@ -269,13 +161,11 @@
  13.212  
  13.213      showing = (SDL_cursorstate & CURSOR_VISIBLE);
  13.214      if (toggle >= 0) {
  13.215 -        SDL_LockCursor();
  13.216          if (toggle) {
  13.217              SDL_cursorstate |= CURSOR_VISIBLE;
  13.218          } else {
  13.219              SDL_cursorstate &= ~CURSOR_VISIBLE;
  13.220          }
  13.221 -        SDL_UnlockCursor();
  13.222          if ((SDL_cursorstate & CURSOR_VISIBLE) != showing) {
  13.223              SDL_VideoDevice *_this = SDL_GetVideoDevice();
  13.224  
  13.225 @@ -291,509 +181,23 @@
  13.226  }
  13.227  
  13.228  void
  13.229 -SDL_WarpMouse(Uint16 x, Uint16 y)
  13.230 +SDL_WarpMouseInWindow(SDL_WindowID windowID, int x, int y)
  13.231  {
  13.232      SDL_VideoDevice *_this = SDL_GetVideoDevice();
  13.233  
  13.234 -    if (!_this || !SDL_PublicSurface) {
  13.235 -        SDL_SetError("A video mode must be set before warping mouse");
  13.236 +    /* FIXME: This should specify the target window */
  13.237 +    if (!_this || !SDL_CurrentDisplay.num_windows) {
  13.238 +        SDL_SetError("A window must be created before warping mouse");
  13.239          return;
  13.240      }
  13.241  
  13.242 -    /* If we have an offset video mode, offset the mouse coordinates */
  13.243 -    if (SDL_VideoSurface->pitch == 0) {
  13.244 -        x += SDL_VideoSurface->offset /
  13.245 -            SDL_VideoSurface->format->BytesPerPixel;
  13.246 -        y += SDL_VideoSurface->offset;
  13.247 -    } else {
  13.248 -        x += (SDL_VideoSurface->offset % SDL_VideoSurface->pitch) /
  13.249 -            SDL_VideoSurface->format->BytesPerPixel;
  13.250 -        y += (SDL_VideoSurface->offset / SDL_VideoSurface->pitch);
  13.251 +    if (!windowID) {
  13.252 +        windowID = SDL_CurrentWindow;
  13.253      }
  13.254  
  13.255      /* This generates a mouse motion event */
  13.256      if (_this->WarpWMCursor) {
  13.257 -        _this->WarpWMCursor(_this, x, y);
  13.258 -    } else {
  13.259 -        SDL_PrivateMouseMotion(0, 0, x, y);
  13.260 -    }
  13.261 -}
  13.262 -
  13.263 -void
  13.264 -SDL_MoveCursor(int x, int y)
  13.265 -{
  13.266 -    SDL_VideoDevice *_this = SDL_GetVideoDevice();
  13.267 -
  13.268 -    /* Erase and update the current mouse position */
  13.269 -    if (SHOULD_DRAWCURSOR(SDL_cursorstate)) {
  13.270 -        /* Erase and redraw mouse cursor in new position */
  13.271 -        SDL_LockCursor();
  13.272 -        SDL_EraseCursor(SDL_VideoSurface);
  13.273 -        SDL_cursor->area.x = (x - SDL_cursor->hot_x);
  13.274 -        SDL_cursor->area.y = (y - SDL_cursor->hot_y);
  13.275 -        SDL_DrawCursor(SDL_VideoSurface);
  13.276 -        SDL_UnlockCursor();
  13.277 -    } else if (_this->MoveWMCursor) {
  13.278 -        _this->MoveWMCursor(_this, x, y);
  13.279 -    }
  13.280 -}
  13.281 -
  13.282 -/* Keep track of the current cursor colors */
  13.283 -static int palette_changed = 1;
  13.284 -static Uint8 pixels8[2];
  13.285 -
  13.286 -void
  13.287 -SDL_CursorPaletteChanged(void)
  13.288 -{
  13.289 -    palette_changed = 1;
  13.290 -}
  13.291 -
  13.292 -void
  13.293 -SDL_MouseRect(SDL_Rect * area)
  13.294 -{
  13.295 -    SDL_VideoDevice *_this = SDL_GetVideoDevice();
  13.296 -    int clip_diff;
  13.297 -
  13.298 -    *area = SDL_cursor->area;
  13.299 -    if (area->x < 0) {
  13.300 -        area->w += area->x;
  13.301 -        area->x = 0;
  13.302 -    }
  13.303 -    if (area->y < 0) {
  13.304 -        area->h += area->y;
  13.305 -        area->y = 0;
  13.306 -    }
  13.307 -    clip_diff = (area->x + area->w) - SDL_VideoSurface->w;
  13.308 -    if (clip_diff > 0) {
  13.309 -        area->w = area->w < clip_diff ? 0 : area->w - clip_diff;
  13.310 -    }
  13.311 -    clip_diff = (area->y + area->h) - SDL_VideoSurface->h;
  13.312 -    if (clip_diff > 0) {
  13.313 -        area->h = area->h < clip_diff ? 0 : area->h - clip_diff;
  13.314 -    }
  13.315 -}
  13.316 -
  13.317 -static void
  13.318 -SDL_DrawCursorFast(SDL_Surface * screen, SDL_Rect * area)
  13.319 -{
  13.320 -    const Uint32 pixels[2] = { 0xFFFFFFFF, 0x00000000 };
  13.321 -    int i, w, h;
  13.322 -    Uint8 *data, datab;
  13.323 -    Uint8 *mask, maskb;
  13.324 -
  13.325 -    data = SDL_cursor->data + area->y * SDL_cursor->area.w / 8;
  13.326 -    mask = SDL_cursor->mask + area->y * SDL_cursor->area.w / 8;
  13.327 -    switch (screen->format->BytesPerPixel) {
  13.328 -
  13.329 -    case 1:
  13.330 -        {
  13.331 -            Uint8 *dst;
  13.332 -            int dstskip;
  13.333 -
  13.334 -            if (palette_changed) {
  13.335 -                pixels8[0] =
  13.336 -                    (Uint8) SDL_MapRGB(screen->format, 255, 255, 255);
  13.337 -                pixels8[1] = (Uint8) SDL_MapRGB(screen->format, 0, 0, 0);
  13.338 -                palette_changed = 0;
  13.339 -            }
  13.340 -            dst = (Uint8 *) screen->pixels +
  13.341 -                (SDL_cursor->area.y + area->y) * screen->pitch +
  13.342 -                SDL_cursor->area.x;
  13.343 -            dstskip = screen->pitch - area->w;
  13.344 -
  13.345 -            for (h = area->h; h; h--) {
  13.346 -                for (w = area->w / 8; w; w--) {
  13.347 -                    maskb = *mask++;
  13.348 -                    datab = *data++;
  13.349 -                    for (i = 0; i < 8; ++i) {
  13.350 -                        if (maskb & 0x80) {
  13.351 -                            *dst = pixels8[datab >> 7];
  13.352 -                        }
  13.353 -                        maskb <<= 1;
  13.354 -                        datab <<= 1;
  13.355 -                        dst++;
  13.356 -                    }
  13.357 -                }
  13.358 -                dst += dstskip;
  13.359 -            }
  13.360 -        }
  13.361 -        break;
  13.362 -
  13.363 -    case 2:
  13.364 -        {
  13.365 -            Uint16 *dst;
  13.366 -            int dstskip;
  13.367 -
  13.368 -            dst = (Uint16 *) screen->pixels +
  13.369 -                (SDL_cursor->area.y + area->y) * screen->pitch / 2 +
  13.370 -                SDL_cursor->area.x;
  13.371 -            dstskip = (screen->pitch / 2) - area->w;
  13.372 -
  13.373 -            for (h = area->h; h; h--) {
  13.374 -                for (w = area->w / 8; w; w--) {
  13.375 -                    maskb = *mask++;
  13.376 -                    datab = *data++;
  13.377 -                    for (i = 0; i < 8; ++i) {
  13.378 -                        if (maskb & 0x80) {
  13.379 -                            *dst = (Uint16) pixels[datab >> 7];
  13.380 -                        }
  13.381 -                        maskb <<= 1;
  13.382 -                        datab <<= 1;
  13.383 -                        dst++;
  13.384 -                    }
  13.385 -                }
  13.386 -                dst += dstskip;
  13.387 -            }
  13.388 -        }
  13.389 -        break;
  13.390 -
  13.391 -    case 3:
  13.392 -        {
  13.393 -            Uint8 *dst;
  13.394 -            int dstskip;
  13.395 -
  13.396 -            dst = (Uint8 *) screen->pixels +
  13.397 -                (SDL_cursor->area.y + area->y) * screen->pitch +
  13.398 -                SDL_cursor->area.x * 3;
  13.399 -            dstskip = screen->pitch - area->w * 3;
  13.400 -
  13.401 -            for (h = area->h; h; h--) {
  13.402 -                for (w = area->w / 8; w; w--) {
  13.403 -                    maskb = *mask++;
  13.404 -                    datab = *data++;
  13.405 -                    for (i = 0; i < 8; ++i) {
  13.406 -                        if (maskb & 0x80) {
  13.407 -                            SDL_memset(dst, pixels[datab >> 7], 3);
  13.408 -                        }
  13.409 -                        maskb <<= 1;
  13.410 -                        datab <<= 1;
  13.411 -                        dst += 3;
  13.412 -                    }
  13.413 -                }
  13.414 -                dst += dstskip;
  13.415 -            }
  13.416 -        }
  13.417 -        break;
  13.418 -
  13.419 -    case 4:
  13.420 -        {
  13.421 -            Uint32 *dst;
  13.422 -            int dstskip;
  13.423 -
  13.424 -            dst = (Uint32 *) screen->pixels +
  13.425 -                (SDL_cursor->area.y + area->y) * screen->pitch / 4 +
  13.426 -                SDL_cursor->area.x;
  13.427 -            dstskip = (screen->pitch / 4) - area->w;
  13.428 -
  13.429 -            for (h = area->h; h; h--) {
  13.430 -                for (w = area->w / 8; w; w--) {
  13.431 -                    maskb = *mask++;
  13.432 -                    datab = *data++;
  13.433 -                    for (i = 0; i < 8; ++i) {
  13.434 -                        if (maskb & 0x80) {
  13.435 -                            *dst = pixels[datab >> 7];
  13.436 -                        }
  13.437 -                        maskb <<= 1;
  13.438 -                        datab <<= 1;
  13.439 -                        dst++;
  13.440 -                    }
  13.441 -                }
  13.442 -                dst += dstskip;
  13.443 -            }
  13.444 -        }
  13.445 -        break;
  13.446 -    }
  13.447 -}
  13.448 -
  13.449 -static void
  13.450 -SDL_DrawCursorSlow(SDL_Surface * screen, SDL_Rect * area)
  13.451 -{
  13.452 -    const Uint32 pixels[2] = { 0xFFFFFF, 0x000000 };
  13.453 -    int h;
  13.454 -    int x, minx, maxx;
  13.455 -    Uint8 *data, datab = 0;
  13.456 -    Uint8 *mask, maskb = 0;
  13.457 -    Uint8 *dst;
  13.458 -    int dstbpp, dstskip;
  13.459 -
  13.460 -    data = SDL_cursor->data + area->y * SDL_cursor->area.w / 8;
  13.461 -    mask = SDL_cursor->mask + area->y * SDL_cursor->area.w / 8;
  13.462 -    dstbpp = screen->format->BytesPerPixel;
  13.463 -    dst = (Uint8 *) screen->pixels +
  13.464 -        (SDL_cursor->area.y + area->y) * screen->pitch +
  13.465 -        SDL_cursor->area.x * dstbpp;
  13.466 -    dstskip = screen->pitch - SDL_cursor->area.w * dstbpp;
  13.467 -
  13.468 -    minx = area->x;
  13.469 -    maxx = area->x + area->w;
  13.470 -    if (screen->format->BytesPerPixel == 1) {
  13.471 -        if (palette_changed) {
  13.472 -            pixels8[0] = (Uint8) SDL_MapRGB(screen->format, 255, 255, 255);
  13.473 -            pixels8[1] = (Uint8) SDL_MapRGB(screen->format, 0, 0, 0);
  13.474 -            palette_changed = 0;
  13.475 -        }
  13.476 -        for (h = area->h; h; h--) {
  13.477 -            for (x = 0; x < SDL_cursor->area.w; ++x) {
  13.478 -                if ((x % 8) == 0) {
  13.479 -                    maskb = *mask++;
  13.480 -                    datab = *data++;
  13.481 -                }
  13.482 -                if ((x >= minx) && (x < maxx)) {
  13.483 -                    if (maskb & 0x80) {
  13.484 -                        SDL_memset(dst, pixels8[datab >> 7], dstbpp);
  13.485 -                    }
  13.486 -                }
  13.487 -                maskb <<= 1;
  13.488 -                datab <<= 1;
  13.489 -                dst += dstbpp;
  13.490 -            }
  13.491 -            dst += dstskip;
  13.492 -        }
  13.493 -    } else {
  13.494 -        for (h = area->h; h; h--) {
  13.495 -            for (x = 0; x < SDL_cursor->area.w; ++x) {
  13.496 -                if ((x % 8) == 0) {
  13.497 -                    maskb = *mask++;
  13.498 -                    datab = *data++;
  13.499 -                }
  13.500 -                if ((x >= minx) && (x < maxx)) {
  13.501 -                    if (maskb & 0x80) {
  13.502 -                        SDL_memset(dst, pixels[datab >> 7], dstbpp);
  13.503 -                    }
  13.504 -                }
  13.505 -                maskb <<= 1;
  13.506 -                datab <<= 1;
  13.507 -                dst += dstbpp;
  13.508 -            }
  13.509 -            dst += dstskip;
  13.510 -        }
  13.511 -    }
  13.512 -}
  13.513 -
  13.514 -/* This handles the ugly work of converting the saved cursor background from
  13.515 -   the pixel format of the shadow surface to that of the video surface.
  13.516 -   This is only necessary when blitting from a shadow surface of a different
  13.517 -   pixel format than the video surface, and using a software rendered cursor.
  13.518 -*/
  13.519 -static void
  13.520 -SDL_ConvertCursorSave(SDL_Surface * screen, int w, int h)
  13.521 -{
  13.522 -    SDL_VideoDevice *_this = SDL_GetVideoDevice();
  13.523 -    SDL_BlitInfo info;
  13.524 -    SDL_loblit RunBlit;
  13.525 -
  13.526 -    /* Make sure we can steal the blit mapping */
  13.527 -    if (screen->map->dst != SDL_VideoSurface) {
  13.528 -        return;
  13.529 -    }
  13.530 -
  13.531 -    /* Set up the blit information */
  13.532 -    info.s_pixels = SDL_cursor->save[1];
  13.533 -    info.s_width = w;
  13.534 -    info.s_height = h;
  13.535 -    info.s_skip = 0;
  13.536 -    info.d_pixels = SDL_cursor->save[0];
  13.537 -    info.d_width = w;
  13.538 -    info.d_height = h;
  13.539 -    info.d_skip = 0;
  13.540 -    info.aux_data = screen->map->sw_data->aux_data;
  13.541 -    info.src = screen->format;
  13.542 -    info.table = screen->map->table;
  13.543 -    info.dst = SDL_VideoSurface->format;
  13.544 -    RunBlit = screen->map->sw_data->blit;
  13.545 -
  13.546 -    /* Run the actual software blit */
  13.547 -    RunBlit(&info);
  13.548 -}
  13.549 -
  13.550 -void
  13.551 -SDL_DrawCursorNoLock(SDL_Surface * screen)
  13.552 -{
  13.553 -    SDL_VideoDevice *_this = SDL_GetVideoDevice();
  13.554 -    SDL_Rect area;
  13.555 -
  13.556 -    /* Get the mouse rectangle, clipped to the screen */
  13.557 -    SDL_MouseRect(&area);
  13.558 -    if ((area.w == 0) || (area.h == 0)) {
  13.559 -        return;
  13.560 -    }
  13.561 -
  13.562 -    /* Copy mouse background */
  13.563 -    {
  13.564 -        int w, h, screenbpp;
  13.565 -        Uint8 *src, *dst;
  13.566 -
  13.567 -        /* Set up the copy pointers */
  13.568 -        screenbpp = screen->format->BytesPerPixel;
  13.569 -        if ((screen == SDL_VideoSurface) ||
  13.570 -            FORMAT_EQUAL(screen->format, SDL_VideoSurface->format)) {
  13.571 -            dst = SDL_cursor->save[0];
  13.572 -        } else {
  13.573 -            dst = SDL_cursor->save[1];
  13.574 -        }
  13.575 -        src = (Uint8 *) screen->pixels + area.y * screen->pitch +
  13.576 -            area.x * screenbpp;
  13.577 -
  13.578 -        /* Perform the copy */
  13.579 -        w = area.w * screenbpp;
  13.580 -        h = area.h;
  13.581 -        while (h--) {
  13.582 -            SDL_memcpy(dst, src, w);
  13.583 -            dst += w;
  13.584 -            src += screen->pitch;
  13.585 -        }
  13.586 -    }
  13.587 -
  13.588 -    /* Draw the mouse cursor */
  13.589 -    area.x -= SDL_cursor->area.x;
  13.590 -    area.y -= SDL_cursor->area.y;
  13.591 -    if ((area.x == 0) && (area.w == SDL_cursor->area.w)) {
  13.592 -        SDL_DrawCursorFast(screen, &area);
  13.593 -    } else {
  13.594 -        SDL_DrawCursorSlow(screen, &area);
  13.595 -    }
  13.596 -}
  13.597 -
  13.598 -void
  13.599 -SDL_DrawCursor(SDL_Surface * screen)
  13.600 -{
  13.601 -    /* Lock the screen if necessary */
  13.602 -    if (screen == NULL) {
  13.603 -        return;
  13.604 -    }
  13.605 -    if (SDL_MUSTLOCK(screen)) {
  13.606 -        if (SDL_LockSurface(screen) < 0) {
  13.607 -            return;
  13.608 -        }
  13.609 -    }
  13.610 -
  13.611 -    SDL_DrawCursorNoLock(screen);
  13.612 -
  13.613 -    /* Unlock the screen and update if necessary */
  13.614 -    if (SDL_MUSTLOCK(screen)) {
  13.615 -        SDL_UnlockSurface(screen);
  13.616 -    }
  13.617 -    if ((screen->flags & SDL_SCREEN_SURFACE) &&
  13.618 -        !(screen->flags & SDL_HWSURFACE)) {
  13.619 -        SDL_VideoDevice *_this = SDL_GetVideoDevice();
  13.620 -        SDL_Window *window;
  13.621 -        SDL_Rect area;
  13.622 -
  13.623 -        window = SDL_GetWindowFromSurface(screen);
  13.624 -        if (!window) {
  13.625 -            return;
  13.626 -        }
  13.627 -
  13.628 -        SDL_MouseRect(&area);
  13.629 -
  13.630 -        if (_this->UpdateWindowSurface) {
  13.631 -            _this->UpdateWindowSurface(_this, window, 1, &area);
  13.632 -        }
  13.633 -    }
  13.634 -}
  13.635 -
  13.636 -void
  13.637 -SDL_EraseCursorNoLock(SDL_Surface * screen)
  13.638 -{
  13.639 -    SDL_VideoDevice *_this = SDL_GetVideoDevice();
  13.640 -    SDL_Window *window;
  13.641 -    SDL_Rect area;
  13.642 -
  13.643 -    /* Get the window associated with the surface */
  13.644 -    window = SDL_GetWindowFromSurface(screen);
  13.645 -    if (!window || !window->surface) {
  13.646 -        return;
  13.647 -    }
  13.648 -
  13.649 -    /* Get the mouse rectangle, clipped to the screen */
  13.650 -    SDL_MouseRect(&area);
  13.651 -    if ((area.w == 0) || (area.h == 0)) {
  13.652 -        return;
  13.653 -    }
  13.654 -
  13.655 -    /* Copy mouse background */
  13.656 -    {
  13.657 -        int w, h, screenbpp;
  13.658 -        Uint8 *src, *dst;
  13.659 -
  13.660 -        /* Set up the copy pointers */
  13.661 -        screenbpp = screen->format->BytesPerPixel;
  13.662 -        if ((screen->flags & SDL_SCREEN_SURFACE) ||
  13.663 -            FORMAT_EQUAL(screen->format, window->surface->format)) {
  13.664 -            src = SDL_cursor->save[0];
  13.665 -        } else {
  13.666 -            src = SDL_cursor->save[1];
  13.667 -        }
  13.668 -        dst = (Uint8 *) screen->pixels + area.y * screen->pitch +
  13.669 -            area.x * screenbpp;
  13.670 -
  13.671 -        /* Perform the copy */
  13.672 -        w = area.w * screenbpp;
  13.673 -        h = area.h;
  13.674 -        while (h--) {
  13.675 -            SDL_memcpy(dst, src, w);
  13.676 -            src += w;
  13.677 -            dst += screen->pitch;
  13.678 -        }
  13.679 -
  13.680 -        /* Perform pixel conversion on cursor background */
  13.681 -        if (src > SDL_cursor->save[1]) {
  13.682 -            SDL_ConvertCursorSave(screen, area.w, area.h);
  13.683 -        }
  13.684 -    }
  13.685 -}
  13.686 -
  13.687 -void
  13.688 -SDL_EraseCursor(SDL_Surface * screen)
  13.689 -{
  13.690 -    /* Lock the screen if necessary */
  13.691 -    if (screen == NULL) {
  13.692 -        return;
  13.693 -    }
  13.694 -    if (SDL_MUSTLOCK(screen)) {
  13.695 -        if (SDL_LockSurface(screen) < 0) {
  13.696 -            return;
  13.697 -        }
  13.698 -    }
  13.699 -
  13.700 -    SDL_EraseCursorNoLock(screen);
  13.701 -
  13.702 -    /* Unlock the screen and update if necessary */
  13.703 -    if (SDL_MUSTLOCK(screen)) {
  13.704 -        SDL_UnlockSurface(screen);
  13.705 -    }
  13.706 -    if ((screen->flags & SDL_SCREEN_SURFACE) &&
  13.707 -        !(screen->flags & SDL_HWSURFACE)) {
  13.708 -        SDL_VideoDevice *_this = SDL_GetVideoDevice();
  13.709 -        SDL_Window *window;
  13.710 -        SDL_Rect area;
  13.711 -
  13.712 -        window = SDL_GetWindowFromSurface(screen);
  13.713 -        if (!window) {
  13.714 -            return;
  13.715 -        }
  13.716 -
  13.717 -        SDL_MouseRect(&area);
  13.718 -
  13.719 -        if (_this->UpdateWindowSurface) {
  13.720 -            _this->UpdateWindowSurface(_this, window, 1, &area);
  13.721 -        }
  13.722 -    }
  13.723 -}
  13.724 -
  13.725 -/* Reset the cursor on video mode change
  13.726 -   FIXME:  Keep track of all cursors, and reset them all.
  13.727 - */
  13.728 -void
  13.729 -SDL_ResetCursor(void)
  13.730 -{
  13.731 -    int savelen;
  13.732 -
  13.733 -    if (SDL_cursor) {
  13.734 -        savelen = SDL_cursor->area.w * 4 * SDL_cursor->area.h;
  13.735 -        SDL_cursor->area.x = 0;
  13.736 -        SDL_cursor->area.y = 0;
  13.737 -        SDL_memset(SDL_cursor->save[0], 0, savelen);
  13.738 +        _this->WarpWMCursor(_this, windowID, x, y);
  13.739      }
  13.740  }
  13.741  
    14.1 --- a/src/video/SDL_cursor_c.h	Mon May 29 05:08:33 2006 +0000
    14.2 +++ b/src/video/SDL_cursor_c.h	Wed Jun 07 16:10:28 2006 +0000
    14.3 @@ -24,51 +24,12 @@
    14.4  /* Useful variables and functions from SDL_cursor.c */
    14.5  #include "SDL_mouse.h"
    14.6  
    14.7 -extern int SDL_CursorInit(Uint32 flags);
    14.8 -extern void SDL_CursorPaletteChanged(void);
    14.9 -extern void SDL_DrawCursor(SDL_Surface * screen);
   14.10 -extern void SDL_DrawCursorNoLock(SDL_Surface * screen);
   14.11 -extern void SDL_EraseCursor(SDL_Surface * screen);
   14.12 -extern void SDL_EraseCursorNoLock(SDL_Surface * screen);
   14.13 -extern void SDL_UpdateCursor(SDL_Surface * screen);
   14.14 -extern void SDL_ResetCursor(void);
   14.15 -extern void SDL_MoveCursor(int x, int y);
   14.16 +extern int SDL_CursorInit(void);
   14.17  extern void SDL_CursorQuit(void);
   14.18  
   14.19 -#define INLINE_MOUSELOCK
   14.20 -#ifdef INLINE_MOUSELOCK
   14.21 -/* Inline (macro) versions of the mouse lock functions */
   14.22 -#include "SDL_mutex.h"
   14.23 -
   14.24 -extern SDL_mutex *SDL_cursorlock;
   14.25 -
   14.26 -#define SDL_LockCursor()						\
   14.27 -	do {								\
   14.28 -		if ( SDL_cursorlock ) {					\
   14.29 -			SDL_mutexP(SDL_cursorlock);			\
   14.30 -		}							\
   14.31 -	} while ( 0 )
   14.32 -#define SDL_UnlockCursor()						\
   14.33 -	do {								\
   14.34 -		if ( SDL_cursorlock ) {					\
   14.35 -			SDL_mutexV(SDL_cursorlock);			\
   14.36 -		}							\
   14.37 -	} while ( 0 )
   14.38 -#else
   14.39 -extern void SDL_LockCursor(void);
   14.40 -extern void SDL_UnlockCursor(void);
   14.41 -#endif /* INLINE_MOUSELOCK */
   14.42 -
   14.43 -/* Only for low-level mouse cursor drawing */
   14.44 -extern SDL_Cursor *SDL_cursor;
   14.45 -extern void SDL_MouseRect(SDL_Rect * area);
   14.46 -
   14.47  /* State definitions for the SDL cursor */
   14.48  #define CURSOR_VISIBLE	0x01
   14.49 -#define CURSOR_USINGSW	0x10
   14.50 -#define SHOULD_DRAWCURSOR(X) 						\
   14.51 -			(((X)&(CURSOR_VISIBLE|CURSOR_USINGSW)) ==  	\
   14.52 -					(CURSOR_VISIBLE|CURSOR_USINGSW))
   14.53  
   14.54  extern volatile int SDL_cursorstate;
   14.55 +
   14.56  /* vi: set ts=4 sw=4 expandtab: */
    15.1 --- a/src/video/SDL_pixels.c	Mon May 29 05:08:33 2006 +0000
    15.2 +++ b/src/video/SDL_pixels.c	Wed Jun 07 16:10:28 2006 +0000
    15.3 @@ -480,10 +480,10 @@
    15.4  /* 
    15.5   * Calculate the pad-aligned scanline width of a surface
    15.6   */
    15.7 -Uint16
    15.8 +int
    15.9  SDL_CalculatePitch(SDL_Surface * surface)
   15.10  {
   15.11 -    Uint16 pitch;
   15.12 +    int pitch;
   15.13  
   15.14      /* Surface should be 4-byte aligned for speed */
   15.15      pitch = surface->w * surface->format->BytesPerPixel;
    16.1 --- a/src/video/SDL_pixels_c.h	Mon May 29 05:08:33 2006 +0000
    16.2 +++ b/src/video/SDL_pixels_c.h	Wed Jun 07 16:10:28 2006 +0000
    16.3 @@ -42,7 +42,7 @@
    16.4  extern void SDL_FreeBlitMap(SDL_BlitMap * map);
    16.5  
    16.6  /* Miscellaneous functions */
    16.7 -extern Uint16 SDL_CalculatePitch(SDL_Surface * surface);
    16.8 +extern int SDL_CalculatePitch(SDL_Surface * surface);
    16.9  extern void SDL_DitherColors(SDL_Color * colors, int bpp);
   16.10  extern Uint8 SDL_FindColor(SDL_Palette * pal, Uint8 r, Uint8 g, Uint8 b);
   16.11  extern void SDL_ApplyGamma(Uint16 * gamma, SDL_Color * colors,
    17.1 --- a/src/video/SDL_surface.c	Mon May 29 05:08:33 2006 +0000
    17.2 +++ b/src/video/SDL_surface.c	Wed Jun 07 16:10:28 2006 +0000
    17.3 @@ -43,6 +43,7 @@
    17.4      SDL_Surface *screen;
    17.5      SDL_Surface *surface;
    17.6  
    17.7 +    /* FIXME!! */
    17.8      /* Make sure the size requested doesn't overflow our datatypes */
    17.9      /* Next time I write a library like SDL, I'll use int for size. :) */
   17.10      if (width >= 16384 || height >= 65536) {
   17.11 @@ -50,52 +51,13 @@
   17.12          return (NULL);
   17.13      }
   17.14  
   17.15 -    /* Check to see if we desire the surface in video memory */
   17.16 -    if (_this) {
   17.17 -        screen = SDL_PublicSurface;
   17.18 -    } else {
   17.19 -        screen = NULL;
   17.20 -    }
   17.21 -    if (screen && ((screen->flags & SDL_HWSURFACE) == SDL_HWSURFACE)) {
   17.22 -        if ((flags & (SDL_SRCCOLORKEY | SDL_SRCALPHA)) != 0) {
   17.23 -            flags |= SDL_HWSURFACE;
   17.24 -        }
   17.25 -        if ((flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY) {
   17.26 -            if (!_this->info.blit_hw_CC) {
   17.27 -                flags &= ~SDL_HWSURFACE;
   17.28 -            }
   17.29 -        }
   17.30 -        if ((flags & SDL_SRCALPHA) == SDL_SRCALPHA) {
   17.31 -            if (!_this->info.blit_hw_A) {
   17.32 -                flags &= ~SDL_HWSURFACE;
   17.33 -            }
   17.34 -        }
   17.35 -    } else {
   17.36 -        flags &= ~SDL_HWSURFACE;
   17.37 -    }
   17.38 -
   17.39      /* Allocate the surface */
   17.40      surface = (SDL_Surface *) SDL_malloc(sizeof(*surface));
   17.41      if (surface == NULL) {
   17.42          SDL_OutOfMemory();
   17.43          return (NULL);
   17.44      }
   17.45 -    surface->flags = SDL_SWSURFACE;
   17.46 -    if ((flags & SDL_HWSURFACE) == SDL_HWSURFACE) {
   17.47 -        if ((Amask) && (_this->displayformatalphapixel)) {
   17.48 -            depth = _this->displayformatalphapixel->BitsPerPixel;
   17.49 -            Rmask = _this->displayformatalphapixel->Rmask;
   17.50 -            Gmask = _this->displayformatalphapixel->Gmask;
   17.51 -            Bmask = _this->displayformatalphapixel->Bmask;
   17.52 -            Amask = _this->displayformatalphapixel->Amask;
   17.53 -        } else {
   17.54 -            depth = screen->format->BitsPerPixel;
   17.55 -            Rmask = screen->format->Rmask;
   17.56 -            Gmask = screen->format->Gmask;
   17.57 -            Bmask = screen->format->Bmask;
   17.58 -            Amask = screen->format->Amask;
   17.59 -        }
   17.60 -    }
   17.61 +    surface->flags = 0;
   17.62      surface->format = SDL_AllocFormat(depth, Rmask, Gmask, Bmask, Amask);
   17.63      if (surface->format == NULL) {
   17.64          SDL_free(surface);
   17.65 @@ -108,27 +70,22 @@
   17.66      surface->h = height;
   17.67      surface->pitch = SDL_CalculatePitch(surface);
   17.68      surface->pixels = NULL;
   17.69 -    surface->offset = 0;
   17.70      surface->hwdata = NULL;
   17.71      surface->locked = 0;
   17.72      surface->map = NULL;
   17.73 -    surface->unused1 = 0;
   17.74      SDL_SetClipRect(surface, NULL);
   17.75      SDL_FormatChanged(surface);
   17.76  
   17.77      /* Get the pixels */
   17.78 -    if (((flags & SDL_HWSURFACE) == SDL_SWSURFACE) ||
   17.79 -        (_this->AllocHWSurface(_this, surface) < 0)) {
   17.80 -        if (surface->w && surface->h) {
   17.81 -            surface->pixels = SDL_malloc(surface->h * surface->pitch);
   17.82 -            if (surface->pixels == NULL) {
   17.83 -                SDL_FreeSurface(surface);
   17.84 -                SDL_OutOfMemory();
   17.85 -                return (NULL);
   17.86 -            }
   17.87 -            /* This is important for bitmaps */
   17.88 -            SDL_memset(surface->pixels, 0, surface->h * surface->pitch);
   17.89 +    if (surface->w && surface->h) {
   17.90 +        surface->pixels = SDL_malloc(surface->h * surface->pitch);
   17.91 +        if (surface->pixels == NULL) {
   17.92 +            SDL_FreeSurface(surface);
   17.93 +            SDL_OutOfMemory();
   17.94 +            return NULL;
   17.95          }
   17.96 +        /* This is important for bitmaps */
   17.97 +        SDL_memset(surface->pixels, 0, surface->h * surface->pitch);
   17.98      }
   17.99  
  17.100      /* Allocate an empty mapping */
  17.101 @@ -167,7 +124,72 @@
  17.102          surface->pitch = pitch;
  17.103          SDL_SetClipRect(surface, NULL);
  17.104      }
  17.105 -    return (surface);
  17.106 +    return surface;
  17.107 +}
  17.108 +
  17.109 +SDL_Surface *
  17.110 +SDL_CreateRGBSurfaceFromTexture(SDL_TextureID textureID)
  17.111 +{
  17.112 +    SDL_Surface *surface;
  17.113 +    Uint32 format;
  17.114 +    int w, h;
  17.115 +    int bpp;
  17.116 +    Uint32 Rmask, Gmask, Bmask, Amask;
  17.117 +
  17.118 +    if (SDL_QueryTexture(textureID, &format, NULL, &w, &h) < 0) {
  17.119 +        return NULL;
  17.120 +    }
  17.121 +
  17.122 +    if (!SDL_PixelFormatEnumToMasks
  17.123 +        (format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) {
  17.124 +        SDL_SetError("Unknown texture format");
  17.125 +        return NULL;
  17.126 +    }
  17.127 +
  17.128 +    surface = SDL_CreateRGBSurface(SDL_SWSURFACE, 0, 0, bpp,
  17.129 +                                   Rmask, Gmask, Bmask, Amask);
  17.130 +    if (surface != NULL) {
  17.131 +        surface->flags |= (SDL_HWSURFACE | SDL_PREALLOC);
  17.132 +        surface->w = width;
  17.133 +        surface->h = height;
  17.134 +        SDL_SetClipRect(surface, NULL);
  17.135 +    }
  17.136 +    return surface;
  17.137 +}
  17.138 +
  17.139 +/*
  17.140 + * Set the palette in a blittable surface
  17.141 + */
  17.142 +int
  17.143 +SDL_SetColors(SDL_Surface * surface, SDL_Color * colors, int firstcolor,
  17.144 +              int ncolors)
  17.145 +{
  17.146 +    SDL_Palette *pal;
  17.147 +    int gotall;
  17.148 +    int palsize;
  17.149 +
  17.150 +    /* Verify the parameters */
  17.151 +    pal = surface->format->palette;
  17.152 +    if (!pal) {
  17.153 +        return 0;               /* not a palettized surface */
  17.154 +    }
  17.155 +    gotall = 1;
  17.156 +    palsize = 1 << surface->format->BitsPerPixel;
  17.157 +    if (ncolors > (palsize - firstcolor)) {
  17.158 +        ncolors = (palsize - firstcolor);
  17.159 +        gotall = 0;
  17.160 +    }
  17.161 +
  17.162 +    if (colors != (pal->colors + firstcolor)) {
  17.163 +        SDL_memcpy(pal->colors + firstcolor, colors,
  17.164 +                   ncolors * sizeof(*colors));
  17.165 +    }
  17.166 +    SDL_FormatChanged(surface);
  17.167 +
  17.168 +    if (surface->flags & (SDL_SHADOW_SURFACE | SDL_SCREEN_SURFACE)) {
  17.169 +        gotall &= SDL_SetScreenColors(surface, colors, firstcolor, ncolors);
  17.170 +    }
  17.171 +    return gotall;
  17.172  }
  17.173  
  17.174  /*
    18.1 --- a/src/video/SDL_sysvideo.h	Mon May 29 05:08:33 2006 +0000
    18.2 +++ b/src/video/SDL_sysvideo.h	Wed Jun 07 16:10:28 2006 +0000
    18.3 @@ -39,9 +39,71 @@
    18.4  
    18.5  /* The SDL video driver */
    18.6  
    18.7 +typedef struct SDL_Window SDL_Window;
    18.8 +typedef struct SDL_Texture SDL_Texture;
    18.9 +typedef struct SDL_Renderer SDL_Renderer;
   18.10 +typedef struct SDL_RenderDriver SDL_RenderDriver;
   18.11 +typedef struct SDL_VideoDisplay SDL_VideoDisplay;
   18.12 +typedef struct SDL_VideoDevice SDL_VideoDevice;
   18.13 +
   18.14 +/* Define the SDL texture structure */
   18.15 +struct SDL_Texture
   18.16 +{
   18.17 +    Uint32 id;
   18.18 +
   18.19 +    Uint32 format;      /**< The pixel format of the texture */
   18.20 +    int access;         /**< SDL_TextureAccess */
   18.21 +    int w;              /**< The width of the texture */
   18.22 +    int h;              /**< The height of the texture */
   18.23 +
   18.24 +    SDL_Renderer *renderer;
   18.25 +
   18.26 +    void *driverdata;   /**< Driver specific texture representation */
   18.27 +
   18.28 +    SDL_Texture *next;
   18.29 +};
   18.30 +
   18.31 +/* Define the SDL renderer structure */
   18.32 +struct SDL_Renderer
   18.33 +{
   18.34 +    int (*CreateTexture) (SDL_Texture * texture);
   18.35 +    int (*UpdateTexture) (SDL_Texture * texture, SDL_Rect * rect,
   18.36 +                          const void *pixels, int pitch);
   18.37 +    int (*LockTexture) (SDL_Texture * texture, SDL_Rect * rect, int markDirty,
   18.38 +                        void **pixels, int *pitch);
   18.39 +    void (*UnlockTexture) (SDL_Texture * texture);
   18.40 +    void (*DirtyTexture) (SDL_Texture * texture, int numrects,
   18.41 +                          SDL_Rect * rects);
   18.42 +    void (*SelectRenderTexture) (SDL_Texture * texture);
   18.43 +    void (*RenderFill) (SDL_Rect * rect, Uint32 color);
   18.44 +    int (*RenderCopy) (SDL_Texture * texture, SDL_Rect * srcrect,
   18.45 +                       SDL_Rect * dstrect, int blendMode, int scaleMode);
   18.46 +    int (*RenderReadPixels) (SDL_Rect * rect, void *pixels, int pitch);
   18.47 +    int (*RenderWritePixels) (SDL_Rect * rect, const void *pixels, int pitch);
   18.48 +    void (*RenderPresent) (void);
   18.49 +    void (*DestroyTexture) (SDL_Texture * texture);
   18.50 +
   18.51 +    void (*DestroyRenderer) (SDL_Renderer * renderer);
   18.52 +
   18.53 +    /* The current renderer info */
   18.54 +    SDL_RendererInfo info;
   18.55 +
   18.56 +    /* The window associated with the renderer */
   18.57 +    SDL_Window *window;
   18.58 +
   18.59 +    void *driverdata;
   18.60 +};
   18.61 +
   18.62 +/* Define the SDL render driver structure */
   18.63 +struct SDL_RenderDriver
   18.64 +{
   18.65 +    SDL_Renderer *(*CreateRenderer) (SDL_Window * window, Uint32 flags);
   18.66 +
   18.67 +    /* Info about the renderer capabilities */
   18.68 +    SDL_RendererInfo info;
   18.69 +};
   18.70 +
   18.71  /* Define the SDL window structure, corresponding to toplevel windows */
   18.72 -typedef struct SDL_Window SDL_Window;
   18.73 -
   18.74  struct SDL_Window
   18.75  {
   18.76      Uint32 id;
   18.77 @@ -51,10 +113,10 @@
   18.78      int w, h;
   18.79      Uint32 flags;
   18.80  
   18.81 -    SDL_Surface *surface;
   18.82 -    SDL_Surface *shadow;
   18.83      Uint16 *gamma;
   18.84  
   18.85 +    SDL_Renderer *renderer;
   18.86 +
   18.87      void *userdata;
   18.88      void *driverdata;
   18.89  };
   18.90 @@ -62,21 +124,26 @@
   18.91  /* Define the SDL display structure
   18.92     This corresponds to physical monitors attached to the system.
   18.93   */
   18.94 -typedef struct SDL_VideoDisplay
   18.95 +struct SDL_VideoDisplay
   18.96  {
   18.97      int num_display_modes;
   18.98      SDL_DisplayMode *display_modes;
   18.99      SDL_DisplayMode desktop_mode;
  18.100      SDL_DisplayMode current_mode;
  18.101  
  18.102 -    int max_windows;
  18.103 +    int num_render_drivers;
  18.104 +    SDL_RenderDriver *render_drivers;
  18.105 +
  18.106      int num_windows;
  18.107      SDL_Window *windows;
  18.108  
  18.109 +    SDL_Renderer *current_renderer;
  18.110 +
  18.111 +    /* The hash list of textures */
  18.112 +    SDL_Texture *textures[64];
  18.113 +
  18.114      void *driverdata;
  18.115 -} SDL_VideoDisplay;
  18.116 -
  18.117 -typedef struct SDL_VideoDevice SDL_VideoDevice;
  18.118 +};
  18.119  
  18.120  /* Define the SDL video driver structure */
  18.121  #define _THIS	SDL_VideoDevice *_this
  18.122 @@ -105,6 +172,13 @@
  18.123       */
  18.124      int (*SetDisplayMode) (_THIS, const SDL_DisplayMode * mode);
  18.125  
  18.126 +    /* Sets the color entries { firstcolor .. (firstcolor+ncolors-1) }
  18.127 +       of the physical palette to those in 'colors'.  The return value
  18.128 +       is 0 if all entries could be set properly or -1 otherwise.
  18.129 +     */
  18.130 +    int (*SetDisplayColors) (_THIS, int firstcolor, int ncolors,
  18.131 +                             SDL_Color * colors);
  18.132 +
  18.133      /* * * */
  18.134      /* Window functions
  18.135       */
  18.136 @@ -122,22 +196,6 @@
  18.137      void (*SetWindowGrab) (_THIS, SDL_Window * window);
  18.138      void (*DestroyWindow) (_THIS, SDL_Window * window);
  18.139  
  18.140 -    void (*CreateWindowSurface) (_THIS, SDL_Window * window, Uint32 flags);
  18.141 -    void (*UpdateWindowSurface) (_THIS, SDL_Window * window, int numrects,
  18.142 -                                 SDL_Rect * rects);
  18.143 -    void (*FlipWindowSurface) (_THIS, SDL_Window * window);
  18.144 -
  18.145 -    /* Sets the color entries { firstcolor .. (firstcolor+ncolors-1) }
  18.146 -       of the physical palette to those in 'colors'. If the device is
  18.147 -       using a software palette (SDL_HWPALETTE not set), then the
  18.148 -       changes are reflected in the logical palette of the screen
  18.149 -       as well.
  18.150 -       The return value is 1 if all entries could be set properly
  18.151 -       or 0 otherwise.
  18.152 -     */
  18.153 -    int (*SetWindowColors) (_THIS, SDL_Window * window,
  18.154 -                            int firstcolor, int ncolors, SDL_Color * colors);
  18.155 -
  18.156      /* Get some platform dependent window information */
  18.157        SDL_bool(*GetWindowWMInfo) (_THIS, SDL_Window * window,
  18.158                                    SDL_SysWMinfo * info);
  18.159 @@ -157,9 +215,6 @@
  18.160      /* * * */
  18.161      /* Hardware acceleration functions */
  18.162  
  18.163 -    /* Information about the video hardware */
  18.164 -    SDL_VideoInfo info;
  18.165 -
  18.166      /* The pixel format used when SDL_CreateRGBSurface creates SDL_HWSURFACEs with alpha */
  18.167      SDL_PixelFormat *displayformatalphapixel;
  18.168  
  18.169 @@ -242,23 +297,23 @@
  18.170      /* Free a window manager cursor
  18.171         This function can be NULL if CreateWMCursor is also NULL.
  18.172       */
  18.173 -    void (*FreeWMCursor) (_THIS, WMcursor * cursor);
  18.174 +    void (*FreeCursor) (_THIS, SDL_Cursor * cursor);
  18.175  
  18.176      /* If not NULL, create a black/white window manager cursor */
  18.177 -    WMcursor *(*CreateWMCursor) (_THIS,
  18.178 +    SDL_Cursor *(*CreateCursor) (_THIS,
  18.179                                   Uint8 * data, Uint8 * mask, int w, int h,
  18.180                                   int hot_x, int hot_y);
  18.181  
  18.182      /* Show the specified cursor, or hide if cursor is NULL */
  18.183 -    int (*ShowWMCursor) (_THIS, WMcursor * cursor);
  18.184 +    int (*ShowCursor) (_THIS, SDL_Cursor * cursor);
  18.185  
  18.186      /* Warp the window manager cursor to (x,y)
  18.187         If NULL, a mouse motion event is posted internally.
  18.188       */
  18.189 -    void (*WarpWMCursor) (_THIS, Uint16 x, Uint16 y);
  18.190 +    void (*WarpCursor) (_THIS, SDL_WindowID windowID, int x, int y);
  18.191  
  18.192      /* If not NULL, this is called when a mouse motion event occurs */
  18.193 -    void (*MoveWMCursor) (_THIS, int x, int y);
  18.194 +    void (*MoveCursor) (_THIS, int x, int y);
  18.195  
  18.196      /* Determine whether the mouse should be in relative mode or not.
  18.197         This function is called when the input grab state or cursor
  18.198 @@ -283,7 +338,7 @@
  18.199      int num_displays;
  18.200      SDL_VideoDisplay *displays;
  18.201      int current_display;
  18.202 -    Uint32 next_window_id;
  18.203 +    Uint32 next_object_id;
  18.204  
  18.205      /* Driver information flags */
  18.206  
  18.207 @@ -428,15 +483,14 @@
  18.208  
  18.209  #define SDL_CurrentDisplay	(_this->displays[_this->current_display])
  18.210  #define SDL_CurrentWindow	(SDL_CurrentDisplay.windows[0])
  18.211 -#define SDL_VideoSurface	((_this && SDL_CurrentDisplay.num_windows > 0) ? SDL_CurrentWindow.surface : NULL)
  18.212 -#define SDL_ShadowSurface	((_this && SDL_CurrentDisplay.num_windows > 0) ? SDL_CurrentWindow.shadow : NULL)
  18.213 -#define SDL_PublicSurface	(SDL_ShadowSurface ? SDL_ShadowSurface : SDL_VideoSurface)
  18.214  
  18.215  extern SDL_VideoDevice *SDL_GetVideoDevice();
  18.216  extern void SDL_AddBasicVideoDisplay(const SDL_DisplayMode * desktop_mode);
  18.217  extern void SDL_AddVideoDisplay(const SDL_VideoDisplay * display);
  18.218 -extern void SDL_AddDisplayMode(int display, const SDL_DisplayMode * mode);
  18.219 -extern SDL_Window *SDL_GetWindowFromSurface(SDL_Surface * surface);
  18.220 +extern void SDL_AddDisplayMode(int displayIndex,
  18.221 +                               const SDL_DisplayMode * mode);
  18.222 +extern void SDL_AddRenderDriver(int displayIndex,
  18.223 +                                const SDL_RenderDriver * driver);
  18.224  
  18.225  #endif /* _SDL_sysvideo_h */
  18.226  
    19.1 --- a/src/video/SDL_video.c	Mon May 29 05:08:33 2006 +0000
    19.2 +++ b/src/video/SDL_video.c	Wed Jun 07 16:10:28 2006 +0000
    19.3 @@ -231,7 +231,7 @@
    19.4      }
    19.5      _this = video;
    19.6      _this->name = bootstrap[i]->name;
    19.7 -    _this->next_window_id = 1;
    19.8 +    _this->next_object_id = 1;
    19.9  
   19.10  
   19.11      /* Set some very sane GL defaults */
   19.12 @@ -268,16 +268,6 @@
   19.13          return (-1);
   19.14      }
   19.15  
   19.16 -    /* Temporarily here for backwards compatibility */
   19.17 -    {
   19.18 -        int bpp;
   19.19 -        Uint32 Rmask, Gmask, Bmask, Amask;
   19.20 -
   19.21 -        SDL_PixelFormatEnumToMasks(SDL_GetDesktopDisplayMode()->format, &bpp,
   19.22 -                                   &Rmask, &Gmask, &Bmask, &Amask);
   19.23 -        _this->info.vfmt = SDL_AllocFormat(bpp, Rmask, Gmask, Bmask, Amask);
   19.24 -    }
   19.25 -
   19.26      /* Sort the video modes */
   19.27      for (i = 0; i < _this->num_displays; ++i) {
   19.28          SDL_qsort(_this->displays[i].display_modes,
   19.29 @@ -311,15 +301,6 @@
   19.30      return _this;
   19.31  }
   19.32  
   19.33 -const SDL_VideoInfo *
   19.34 -SDL_GetVideoInfo(void)
   19.35 -{
   19.36 -    if (!_this) {
   19.37 -        return NULL;
   19.38 -    }
   19.39 -    return &_this->info;
   19.40 -}
   19.41 -
   19.42  void
   19.43  SDL_AddBasicVideoDisplay(const SDL_DisplayMode * desktop_mode)
   19.44  {
   19.45 @@ -330,7 +311,6 @@
   19.46          display.desktop_mode = *desktop_mode;
   19.47      }
   19.48      display.current_mode = display.desktop_mode;
   19.49 -    display.max_windows = 1;
   19.50  
   19.51      SDL_AddVideoDisplay(&display);
   19.52  }
   19.53 @@ -378,14 +358,15 @@
   19.54  }
   19.55  
   19.56  void
   19.57 -SDL_AddDisplayMode(int display, const SDL_DisplayMode * mode)
   19.58 +SDL_AddDisplayMode(int displayIndex, const SDL_DisplayMode * mode)
   19.59  {
   19.60 +    SDL_VideoDisplay *display = &_this->displays[displayIndex];
   19.61      SDL_DisplayMode *modes;
   19.62      int i, nmodes;
   19.63  
   19.64      /* Make sure we don't already have the mode in the list */
   19.65 -    modes = SDL_CurrentDisplay.display_modes;
   19.66 -    nmodes = SDL_CurrentDisplay.num_display_modes;
   19.67 +    modes = display->display_modes;
   19.68 +    nmodes = display->num_display_modes;
   19.69      for (i = 0; i < nmodes; ++i) {
   19.70          if (SDL_memcmp(mode, &modes[i], sizeof(*mode)) == 0) {
   19.71              return;
   19.72 @@ -395,9 +376,9 @@
   19.73      /* Go ahead and add the new mode */
   19.74      modes = SDL_realloc(modes, (nmodes + 1) * sizeof(*mode));
   19.75      if (modes) {
   19.76 -        SDL_CurrentDisplay.display_modes = modes;
   19.77 +        display->display_modes = modes;
   19.78          modes[nmodes] = *mode;
   19.79 -        SDL_CurrentDisplay.num_display_modes++;
   19.80 +        display->num_display_modes++;
   19.81      }
   19.82  }
   19.83  
   19.84 @@ -415,7 +396,7 @@
   19.85  {
   19.86      if (index < 0 || index >= SDL_GetNumDisplayModes()) {
   19.87          SDL_SetError("index must be in the range of 0 - %d",
   19.88 -                     SDL_GetNumDisplayModes());
   19.89 +                     SDL_GetNumDisplayModes() - 1);
   19.90          return NULL;
   19.91      }
   19.92      return &SDL_CurrentDisplay.display_modes[index];
   19.93 @@ -568,19 +549,6 @@
   19.94          return 0;
   19.95      }
   19.96  
   19.97 -    /* Free any previous window surfaces */
   19.98 -    for (i = 0; i < display->num_windows; ++i) {
   19.99 -        SDL_Window *window = &display->windows[i];
  19.100 -        if (window->shadow) {
  19.101 -            SDL_FreeSurface(window->shadow);
  19.102 -            window->shadow = NULL;
  19.103 -        }
  19.104 -        if (window->surface) {
  19.105 -            SDL_FreeSurface(window->surface);
  19.106 -            window->surface = NULL;
  19.107 -        }
  19.108 -    }
  19.109 -
  19.110      return _this->SetDisplayMode(_this, &display_mode);
  19.111  }
  19.112  
  19.113 @@ -605,7 +573,7 @@
  19.114      }
  19.115  
  19.116      SDL_zero(window);
  19.117 -    window.id = _this->next_window_id++;
  19.118 +    window.id = _this->next_object_id++;
  19.119      window.title = title ? SDL_strdup(title) : NULL;
  19.120      window.x = x;
  19.121      window.y = y;
  19.122 @@ -653,7 +621,7 @@
  19.123      }
  19.124  
  19.125      SDL_zero(window);
  19.126 -    window.id = _this->next_window_id++;
  19.127 +    window.id = _this->next_object_id++;
  19.128  
  19.129      if (!_this->CreateWindowFrom ||
  19.130          _this->CreateWindowFrom(_this, &window, data) < 0) {
  19.131 @@ -701,28 +669,6 @@
  19.132      return NULL;
  19.133  }
  19.134  
  19.135 -SDL_Window *
  19.136 -SDL_GetWindowFromSurface(SDL_Surface * surface)
  19.137 -{
  19.138 -    int i, j;
  19.139 -
  19.140 -    if (!_this || !surface) {
  19.141 -        return NULL;
  19.142 -    }
  19.143 -
  19.144 -    for (i = 0; i < _this->num_displays; ++i) {
  19.145 -        SDL_VideoDisplay *display = &_this->displays[i];
  19.146 -        for (j = 0; j < display->num_windows; ++j) {
  19.147 -            SDL_Window *window = &display->windows[j];
  19.148 -            if (surface == window->surface || surface == window->shadow) {
  19.149 -                return window;
  19.150 -            }
  19.151 -        }
  19.152 -    }
  19.153 -    return NULL;
  19.154 -}
  19.155 -
  19.156 -
  19.157  Uint32
  19.158  SDL_GetWindowFlags(SDL_WindowID windowID)
  19.159  {
  19.160 @@ -998,11 +944,8 @@
  19.161                  window->flags &= ~SDL_WINDOW_INPUT_GRABBED;
  19.162                  _this->SetWindowGrab(_this, window);
  19.163              }
  19.164 -            if (window->shadow) {
  19.165 -                SDL_FreeSurface(window->shadow);
  19.166 -            }
  19.167 -            if (window->surface) {
  19.168 -                SDL_FreeSurface(window->surface);
  19.169 +            if (window->renderer) {
  19.170 +                SDL_DestroyRenderer(window->id);
  19.171              }
  19.172              if (_this->DestroyWindow) {
  19.173                  _this->DestroyWindow(_this, window);
  19.174 @@ -1024,371 +967,569 @@
  19.175      }
  19.176  }
  19.177  
  19.178 -SDL_Surface *
  19.179 -SDL_CreateWindowSurface(SDL_WindowID windowID, Uint32 format, Uint32 flags)
  19.180 +void
  19.181 +SDL_AddRenderDriver(int displayIndex, const SDL_RenderDriver * driver)
  19.182 +{
  19.183 +    SDL_VideoDisplay *display = &_this->displays[displayIndex];
  19.184 +    SDL_RenderDriver *render_drivers;
  19.185 +
  19.186 +    render_drivers =
  19.187 +        SDL_realloc(display->render_drivers,
  19.188 +                    (display->num_render_drivers +
  19.189 +                     1) * sizeof(*render_drivers));
  19.190 +    if (render_drivers) {
  19.191 +        render_drivers[display->num_render_drivers] = *driver;
  19.192 +        display->render_drivers = render_drivers;
  19.193 +        display->num_render_drivers++;
  19.194 +    }
  19.195 +}
  19.196 +
  19.197 +int
  19.198 +SDL_GetNumRenderers(void)
  19.199 +{
  19.200 +    if (_this) {
  19.201 +        return SDL_CurrentDisplay.num_render_drivers;
  19.202 +    }
  19.203 +    return 0;
  19.204 +}
  19.205 +
  19.206 +int
  19.207 +SDL_GetRendererInfo(int index, SDL_RendererInfo * info)
  19.208 +{
  19.209 +    if (index < 0 || index >= SDL_GetNumRenderers()) {
  19.210 +        SDL_SetError("index must be in the range of 0 - %d",
  19.211 +                     SDL_GetNumRenderers() - 1);
  19.212 +        return -1;
  19.213 +    }
  19.214 +    *info = SDL_CurrentDisplay.render_drivers[index].info;
  19.215 +    return 0;
  19.216 +}
  19.217 +
  19.218 +int
  19.219 +SDL_CreateRenderer(SDL_WindowID windowID, int index, Uint32 flags)
  19.220  {
  19.221      SDL_Window *window = SDL_GetWindowFromID(windowID);
  19.222 -    Uint32 black;
  19.223 -    SDL_Surface *surface;
  19.224  
  19.225      if (!window) {
  19.226 +        return 0;
  19.227 +    }
  19.228 +
  19.229 +    if (index < 0) {
  19.230 +        int n = SDL_GetNumRenderers();
  19.231 +        for (index = 0; index < n; ++index) {
  19.232 +            if ((SDL_CurrentDisplay.render_drivers[index].info.
  19.233 +                 flags & flags) == flags) {
  19.234 +                break;
  19.235 +            }
  19.236 +        }
  19.237 +        if (index == n) {
  19.238 +            SDL_SetError("Couldn't find matching render driver");
  19.239 +            return -1;
  19.240 +        }
  19.241 +    }
  19.242 +
  19.243 +    if (index >= SDL_GetNumRenderers()) {
  19.244 +        SDL_SetError("index must be -1 or in the range of 0 - %d",
  19.245 +                     SDL_GetNumRenderers() - 1);
  19.246 +        return -1;
  19.247 +    }
  19.248 +
  19.249 +    /* Free any existing renderer */
  19.250 +    SDL_DestroyRenderer(windowID);
  19.251 +
  19.252 +    /* Create a new renderer instance */
  19.253 +    window->renderer =
  19.254 +        SDL_CurrentDisplay.render_drivers[index].CreateRenderer(window,
  19.255 +                                                                flags);
  19.256 +    if (!window->renderer) {
  19.257 +        return -1;
  19.258 +    }
  19.259 +    SDL_CurrentDisplay.current_renderer = window->renderer;
  19.260 +
  19.261 +    return 0;
  19.262 +}
  19.263 +
  19.264 +int
  19.265 +SDL_SelectRenderer(SDL_WindowID windowID)
  19.266 +{
  19.267 +    SDL_Window *window = SDL_GetWindowFromID(windowID);
  19.268 +
  19.269 +    if (!window || !window->renderer) {
  19.270 +        return -1;
  19.271 +    }
  19.272 +    SDL_CurrentDisplay.current_renderer = window->renderer;
  19.273 +    return 0;
  19.274 +}
  19.275 +
  19.276 +SDL_TextureID
  19.277 +SDL_CreateTexture(Uint32 format, int access, int w, int h)
  19.278 +{
  19.279 +    SDL_Renderer *renderer;
  19.280 +    SDL_Texture *texture;
  19.281 +
  19.282 +    if (!_this) {
  19.283 +        return 0;
  19.284 +    }
  19.285 +
  19.286 +    renderer = SDL_CurrentDisplay.current_renderer;
  19.287 +    if (!renderer || !renderer->CreateTexture) {
  19.288 +        return 0;
  19.289 +    }
  19.290 +
  19.291 +    texture = (SDL_Texture *) SDL_malloc(sizeof(*texture));
  19.292 +    if (!texture) {
  19.293 +        SDL_OutOfMemory();
  19.294 +        return 0;
  19.295 +    }
  19.296 +
  19.297 +    SDL_zerop(texture);
  19.298 +    texture->id = _this->next_object_id++;
  19.299 +    texture->format = format;
  19.300 +    texture->access = access;
  19.301 +    texture->w = w;
  19.302 +    texture->h = h;
  19.303 +    texture->renderer = renderer;
  19.304 +
  19.305 +    if (renderer->CreateTexture(texture) < 0) {
  19.306 +        SDL_free(texture);
  19.307 +        return 0;
  19.308 +    }
  19.309 +}
  19.310 +
  19.311 +SDL_TextureID
  19.312 +SDL_CreateTextureFromSurface(Uint32 format, int access, SDL_Surface * surface)
  19.313 +{
  19.314 +    SDL_TextureID textureID;
  19.315 +    Uint32 surface_flags = surface->flags;
  19.316 +    SDL_PixelFormat *fmt = surface->format;
  19.317 +    Uint32 colorkey;
  19.318 +    Uint8 alpha;
  19.319 +    SDL_Rect bounds;
  19.320 +    SDL_Surface dst;
  19.321 +    int bpp;
  19.322 +    Uint32 Rmask, Gmask, Bmask, Amask;
  19.323 +
  19.324 +    if (!surface) {
  19.325 +        SDL_SetError("SDL_CreateTextureFromSurface() passed NULL surface");
  19.326 +        return 0;
  19.327 +    }
  19.328 +
  19.329 +    if (format) {
  19.330 +        if (!SDL_PixelFormatEnumToMasks
  19.331 +            (format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) {
  19.332 +            SDL_SetError("Unknown pixel format");
  19.333 +            return 0;
  19.334 +        }
  19.335 +    } else {
  19.336 +        bpp = fmt->BitsPerPixel;
  19.337 +        Rmask = fmt->Rmask;
  19.338 +        Gmask = fmt->Gmask;
  19.339 +        Bmask = fmt->Bmask;
  19.340 +        Amask = fmt->Amask;
  19.341 +        format = SDL_MasksToPixelFormatEnum(bpp, Rmask, Gmask, Bmask, Amask);
  19.342 +        if (!format) {
  19.343 +            SDL_SetError("Unknown pixel format");
  19.344 +            return 0;
  19.345 +        }
  19.346 +    }
  19.347 +
  19.348 +    textureID = SDL_CreateTexture(format, access, surface->w, surface->h);
  19.349 +    if (!textureID) {
  19.350 +        return 0;
  19.351 +    }
  19.352 +
  19.353 +    /* Set up a destination surface for the texture update */
  19.354 +    SDL_zero(dst);
  19.355 +    dst.format = SDL_AllocFormat(bpp, Rmask, Gmask, Bmask, Amask);
  19.356 +    if (!dst.format) {
  19.357 +        SDL_DestroyTexture(textureID);
  19.358 +        return 0;
  19.359 +    }
  19.360 +    dst.w = surface->w;
  19.361 +    dst.h = surface->h;
  19.362 +    if (SDL_LockTexture(textureID, NULL, 1, &dst.pixels, &dst.pitch) == 0) {
  19.363 +        dst.flags |= SDL_PREALLOC;
  19.364 +    } else {
  19.365 +        dst.pitch = SDL_CalculatePitch(&dst);
  19.366 +        dst.pixels = SDL_malloc(dst.h * dst.pitch);
  19.367 +        if (!dst.pixels) {
  19.368 +            SDL_DestroyTexture(textureID);
  19.369 +            SDL_FreeFormat(dst.format);
  19.370 +            SDL_OutOfMemory();
  19.371 +            return 0;
  19.372 +        }
  19.373 +    }
  19.374 +
  19.375 +    /* Copy the palette if any */
  19.376 +    if (fmt->palette && dst.format->palette) {
  19.377 +        SDL_SetTexturePalette(textureID, fmt->palette->colors, 0,
  19.378 +                              fmt->palette->ncolors);
  19.379 +
  19.380 +        SDL_memcpy(dst.format->palette->colors,
  19.381 +                   fmt->palette->colors,
  19.382 +                   fmt->palette->ncolors * sizeof(SDL_Color));
  19.383 +        dst.format->palette->ncolors = fmt->palette->ncolors;
  19.384 +    }
  19.385 +
  19.386 +    /* Make the texture transparent if the surface has colorkey */
  19.387 +    if (surface_flags & SDL_SRCCOLORKEY) {
  19.388 +        int row;
  19.389 +        int length = dst.w * dst.format->BytesPerPixel;
  19.390 +        Uint8 *p = (Uint8 *) dst.pixels;
  19.391 +        for (row = 0; row < dst.h; ++row) {
  19.392 +            SDL_memset(p, 0, length);
  19.393 +            p += dst.pitch;
  19.394 +        }
  19.395 +    }
  19.396 +
  19.397 +    /* Copy over the alpha channel */
  19.398 +    if (surface_flags & SDL_SRCALPHA) {
  19.399 +        if (fmt->Amask) {
  19.400 +            surface->flags &= ~SDL_SRCALPHA;
  19.401 +        } else {
  19.402 +            /* FIXME: Need to make sure the texture has an alpha channel
  19.403 +             *        and copy 'alpha' into the texture alpha channel.
  19.404 +             */
  19.405 +            alpha = surface->format->alpha;
  19.406 +            SDL_SetAlpha(surface, 0, 0);
  19.407 +        }
  19.408 +    }
  19.409 +
  19.410 +    /* Copy over the image data */
  19.411 +    bounds.x = 0;
  19.412 +    bounds.y = 0;
  19.413 +    bounds.w = surface->w;
  19.414 +    bounds.h = surface->h;
  19.415 +    SDL_LowerBlit(surface, &bounds, &dst, &bounds);
  19.416 +
  19.417 +    /* Clean up the original surface */
  19.418 +    if ((surface_flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY) {
  19.419 +        Uint32 cflags = surface_flags & (SDL_SRCCOLORKEY | SDL_RLEACCELOK);
  19.420 +        SDL_SetColorKey(surface, cflags, colorkey);
  19.421 +    }
  19.422 +    if ((surface_flags & SDL_SRCALPHA) == SDL_SRCALPHA) {
  19.423 +        Uint32 aflags = surface_flags & (SDL_SRCALPHA | SDL_RLEACCELOK);
  19.424 +        if (fmt->Amask) {
  19.425 +            surface->flags |= SDL_SRCALPHA;
  19.426 +        } else {
  19.427 +            SDL_SetAlpha(surface, aflags, alpha);
  19.428 +        }
  19.429 +    }
  19.430 +
  19.431 +    /* Update the texture */
  19.432 +    if (dst.flags & SDL_PREALLOC) {
  19.433 +        SDL_UnlockTexture(textureID);
  19.434 +    } else {
  19.435 +        SDL_UpdateTexture(textureID, NULL, dst.pixels, dst.pitch);
  19.436 +        SDL_free(dst.pixels);
  19.437 +    }
  19.438 +    SDL_FreeFormat(dst.format);
  19.439 +
  19.440 +    return textureID;
  19.441 +}
  19.442 +
  19.443 +static __inline__ SDL_Texture *
  19.444 +SDL_GetTextureFromID(SDL_TextureID textureID)
  19.445 +{
  19.446 +    int hash;
  19.447 +    SDL_Texture *texture;
  19.448 +
  19.449 +    if (!_this) {
  19.450          return NULL;
  19.451      }
  19.452  
  19.453 -    if (!_this->CreateWindowSurface) {
  19.454 -        return NULL;
  19.455 +    hash = (textureID % SDL_arraysize(SDL_CurrentDisplay.textures));
  19.456 +    for (texture = SDL_CurrentDisplay.textures[hash]; texture;
  19.457 +         texture = texture->next) {
  19.458 +        if (texture->id == textureID) {
  19.459 +            return texture;
  19.460 +        }
  19.461 +    }
  19.462 +    return NULL;
  19.463 +}
  19.464 +
  19.465 +int
  19.466 +SDL_QueryTexture(SDL_TextureID textureID, Uint32 * format, int *access,
  19.467 +                 int *w, int *h)
  19.468 +{
  19.469 +    SDL_Texture *texture = SDL_GetTextureFromID(textureID);
  19.470 +
  19.471 +    if (!texture) {
  19.472 +        return -1;
  19.473      }
  19.474  
  19.475 -    if (!window->surface) {
  19.476 -        _this->CreateWindowSurface(_this, window, flags);
  19.477 -        if (!window->surface) {
  19.478 -            return NULL;
  19.479 -        }
  19.480 -        window->surface->flags |= SDL_SCREEN_SURFACE;
  19.481 +    if (format) {
  19.482 +        *format = texture->format;
  19.483 +    }
  19.484 +    if (access) {
  19.485 +        *access = texture->access;
  19.486 +    }
  19.487 +    if (w) {
  19.488 +        *w = texture->w;
  19.489 +    }
  19.490 +    if (h) {
  19.491 +        *h = texture->h;
  19.492 +    }
  19.493 +    return 0;
  19.494 +}
  19.495  
  19.496 -        /* If we have a palettized surface, create a default palette */
  19.497 -        if (window->surface->format->palette) {
  19.498 -            SDL_Color colors[256];
  19.499 -            SDL_PixelFormat *vf = window->surface->format;
  19.500 -            SDL_DitherColors(colors, vf->BitsPerPixel);
  19.501 -            SDL_SetColors(window->surface, colors, 0, vf->palette->ncolors);
  19.502 +int
  19.503 +SDL_UpdateTexture(SDL_TextureID textureID, SDL_Rect * rect,
  19.504 +                  const void *pixels, int pitch)
  19.505 +{
  19.506 +    SDL_Texture *texture = SDL_GetTextureFromID(textureID);
  19.507 +    SDL_Renderer *renderer;
  19.508 +
  19.509 +    if (!texture) {
  19.510 +        return -1;
  19.511 +    }
  19.512 +
  19.513 +    renderer = texture->renderer;
  19.514 +    if (!renderer->UpdateTexture) {
  19.515 +        return -1;
  19.516 +    }
  19.517 +    return renderer->UpdateTexture(texture, rect, pixels, pitch);
  19.518 +}
  19.519 +
  19.520 +int
  19.521 +SDL_LockTexture(SDL_TextureID textureID, SDL_Rect * rect, int markDirty,
  19.522 +                void **pixels, int *pitch)
  19.523 +{
  19.524 +    SDL_Texture *texture = SDL_GetTextureFromID(textureID);
  19.525 +    SDL_Renderer *renderer;
  19.526 +
  19.527 +    if (!texture) {
  19.528 +        return -1;
  19.529 +    }
  19.530 +
  19.531 +    renderer = texture->renderer;
  19.532 +    if (!renderer->LockTexture) {
  19.533 +        return -1;
  19.534 +    }
  19.535 +    return renderer->LockTexture(texture, rect, markDirty, pixels, pitch);
  19.536 +}
  19.537 +
  19.538 +void
  19.539 +SDL_UnlockTexture(SDL_TextureID textureID)
  19.540 +{
  19.541 +    SDL_Texture *texture = SDL_GetTextureFromID(textureID);
  19.542 +    SDL_Renderer *renderer;
  19.543 +
  19.544 +    if (!texture) {
  19.545 +        return;
  19.546 +    }
  19.547 +
  19.548 +    renderer = texture->renderer;
  19.549 +    if (!renderer->UnlockTexture) {
  19.550 +        return;
  19.551 +    }
  19.552 +    return renderer->UnlockTexture(texture);
  19.553 +}
  19.554 +
  19.555 +void
  19.556 +SDL_DirtyTexture(SDL_TextureID textureID, int numrects, SDL_Rect * rects)
  19.557 +{
  19.558 +    SDL_Texture *texture = SDL_GetTextureFromID(textureID);
  19.559 +    SDL_Renderer *renderer;
  19.560 +
  19.561 +    if (!texture) {
  19.562 +        return;
  19.563 +    }
  19.564 +
  19.565 +    renderer = texture->renderer;
  19.566 +    if (!renderer->DirtyTexture) {
  19.567 +        return;
  19.568 +    }
  19.569 +    renderer->DirtyTexture(texture, numrects, rects);
  19.570 +}
  19.571 +
  19.572 +void
  19.573 +SDL_SelectRenderTexture(SDL_TextureID textureID)
  19.574 +{
  19.575 +    SDL_Texture *texture = SDL_GetTextureFromID(textureID);
  19.576 +    SDL_Renderer *renderer;
  19.577 +
  19.578 +    if (!texture || texture->access != SDL_TextureAccess_Render) {
  19.579 +        return;
  19.580 +    }
  19.581 +    renderer = texture->renderer;
  19.582 +    if (!renderer->SelectRenderTexture) {
  19.583 +        return;
  19.584 +    }
  19.585 +    renderer->SelectRenderTexture(texture);
  19.586 +}
  19.587 +
  19.588 +int
  19.589 +SDL_RenderFill(SDL_Rect * rect, Uint32 color)
  19.590 +{
  19.591 +    SDL_Renderer *renderer;
  19.592 +
  19.593 +    if (!_this) {
  19.594 +        return -1;
  19.595 +    }
  19.596 +
  19.597 +    renderer = SDL_CurrentDisplay.current_renderer;
  19.598 +    if (!renderer || !renderer->RenderFill) {
  19.599 +        return -1;
  19.600 +    }
  19.601 +
  19.602 +    renderer->RenderFill(rect, color);
  19.603 +}
  19.604 +
  19.605 +int
  19.606 +SDL_RenderCopy(SDL_TextureID textureID, SDL_Rect * srcrect,
  19.607 +               SDL_Rect * dstrect, int blendMode, int scaleMode)
  19.608 +{
  19.609 +    SDL_Texture *texture = SDL_GetTextureFromID(textureID);
  19.610 +    SDL_Renderer *renderer;
  19.611 +
  19.612 +    if (!texture || texture->renderer != SDL_CurrentDisplay.current_renderer) {
  19.613 +        return;
  19.614 +    }
  19.615 +
  19.616 +    renderer = SDL_CurrentDisplay.current_renderer;
  19.617 +    if (!renderer || !renderer->RenderCopy) {
  19.618 +        return -1;
  19.619 +    }
  19.620 +
  19.621 +    return renderer->RenderCopy(texture, srcrect, dstrect, blendMode,
  19.622 +                                scaleMode);
  19.623 +}
  19.624 +
  19.625 +int
  19.626 +SDL_RenderReadPixels(SDL_Rect * rect, void *pixels, int pitch)
  19.627 +{
  19.628 +    SDL_Renderer *renderer;
  19.629 +
  19.630 +    if (!_this) {
  19.631 +        return -1;
  19.632 +    }
  19.633 +
  19.634 +    renderer = SDL_CurrentDisplay.current_renderer;
  19.635 +    if (!renderer || !renderer->RenderReadPixels) {
  19.636 +        return -1;
  19.637 +    }
  19.638 +
  19.639 +    return renderer->RenderReadPixels(rect, pixels, pitch);
  19.640 +}
  19.641 +
  19.642 +int
  19.643 +SDL_RenderWritePixels(SDL_Rect * rect, const void *pixels, int pitch)
  19.644 +{
  19.645 +    SDL_Renderer *renderer;
  19.646 +
  19.647 +    if (!_this) {
  19.648 +        return -1;
  19.649 +    }
  19.650 +
  19.651 +    renderer = SDL_CurrentDisplay.current_renderer;
  19.652 +    if (!renderer || !renderer->RenderWritePixels) {
  19.653 +        return -1;
  19.654 +    }
  19.655 +
  19.656 +    return renderer->RenderWritePixels(rect, pixels, pitch);
  19.657 +}
  19.658 +
  19.659 +void
  19.660 +SDL_RenderPresent(void)
  19.661 +{
  19.662 +    SDL_Renderer *renderer;
  19.663 +
  19.664 +    if (!_this) {
  19.665 +        return;
  19.666 +    }
  19.667 +
  19.668 +    renderer = SDL_CurrentDisplay.current_renderer;
  19.669 +    if (!renderer || !renderer->RenderPresent) {
  19.670 +        return;
  19.671 +    }
  19.672 +
  19.673 +    renderer->RenderPresent();
  19.674 +}
  19.675 +
  19.676 +void
  19.677 +SDL_DestroyTexture(SDL_TextureID textureID)
  19.678 +{
  19.679 +    int hash;
  19.680 +    SDL_Texture *prev, *texture;
  19.681 +    SDL_Renderer *renderer;
  19.682 +
  19.683 +    if (!_this) {
  19.684 +        return;
  19.685 +    }
  19.686 +
  19.687 +    /* Look up the texture in the hash table */
  19.688 +    hash = (textureID % SDL_arraysize(SDL_CurrentDisplay.textures));
  19.689 +    prev = NULL;
  19.690 +    for (texture = SDL_CurrentDisplay.textures[hash]; texture;
  19.691 +         prev = texture, texture = texture->next) {
  19.692 +        if (texture->id == textureID) {
  19.693 +            break;
  19.694          }
  19.695      }
  19.696 -    surface = window->surface;
  19.697 -
  19.698 -    if (window->shadow) {
  19.699 -        SDL_FreeSurface(window->shadow);
  19.700 -        window->shadow = NULL;
  19.701 +    if (!texture) {
  19.702 +        return;
  19.703      }
  19.704  
  19.705 -    /* Create a shadow surface if necessary */
  19.706 -    if ((!(flags & SDL_ANYFORMAT)
  19.707 -         && (format != SDL_GetCurrentDisplayMode()->format))
  19.708 -        || ((flags & SDL_HWPALETTE)
  19.709 -            && !(window->surface->flags & SDL_HWPALETTE))) {
  19.710 -        int bpp;
  19.711 -        Uint32 Rmask, Gmask, Bmask, Amask;
  19.712 +    /* Unlink the texture from the list */
  19.713 +    if (prev) {
  19.714 +        prev->next = texture->next;
  19.715 +    } else {
  19.716 +        SDL_CurrentDisplay.textures[hash] = texture->next;
  19.717 +    }
  19.718  
  19.719 -        SDL_PixelFormatEnumToMasks(format, &bpp, &Amask, &Gmask, &Bmask,
  19.720 -                                   &Amask);
  19.721 -        window->shadow =
  19.722 -            SDL_CreateRGBSurface(SDL_SWSURFACE, surface->w, surface->h, bpp,
  19.723 -                                 Rmask, Gmask, Bmask, Amask);
  19.724 -        if (window->shadow == NULL) {
  19.725 -            return NULL;
  19.726 -        }
  19.727 -        window->shadow->flags |= SDL_SHADOW_SURFACE;
  19.728 +    /* Free the texture */
  19.729 +    renderer = texture->renderer;
  19.730 +    renderer->DestroyTexture(texture);
  19.731 +    SDL_free(texture);
  19.732 +}
  19.733  
  19.734 -        surface = window->shadow;
  19.735 +void
  19.736 +SDL_DestroyRenderer(SDL_WindowID windowID)
  19.737 +{
  19.738 +    SDL_Window *window = SDL_GetWindowFromID(windowID);
  19.739 +    SDL_Renderer *renderer;
  19.740 +    int i;
  19.741  
  19.742 -        /* 8-bit shadow surfaces report that they have exclusive palette */
  19.743 -        if (surface->format->palette) {
  19.744 -            surface->flags |= SDL_HWPALETTE;
  19.745 -            if (format == SDL_GetCurrentDisplayMode()->format) {
  19.746 -                SDL_memcpy(surface->format->palette->colors,
  19.747 -                           window->surface->format->palette->colors,
  19.748 -                           window->surface->format->palette->ncolors *
  19.749 -                           sizeof(SDL_Color));
  19.750 +    if (!window) {
  19.751 +        return;
  19.752 +    }
  19.753 +
  19.754 +    renderer = window->renderer;
  19.755 +    if (!renderer) {
  19.756 +        return;
  19.757 +    }
  19.758 +
  19.759 +    /* Free existing textures for this renderer */
  19.760 +    for (i = 0; i < SDL_arraysize(SDL_CurrentDisplay.textures); ++i) {
  19.761 +        SDL_Texture *texture;
  19.762 +        SDL_Texture *prev = NULL;
  19.763 +        SDL_Texture *next;
  19.764 +        for (texture = SDL_CurrentDisplay.textures[i]; texture;
  19.765 +             texture = next) {
  19.766 +            next = texture->next;
  19.767 +            if (texture->renderer == renderer) {
  19.768 +                if (prev) {
  19.769 +                    prev->next = next;
  19.770 +                } else {
  19.771 +                    SDL_CurrentDisplay.textures[i] = next;
  19.772 +                }
  19.773 +                renderer->DestroyTexture(texture);
  19.774 +                SDL_free(texture);
  19.775              } else {
  19.776 -                SDL_DitherColors(surface->format->palette->colors, bpp);
  19.777 +                prev = texture;
  19.778              }
  19.779          }
  19.780      }
  19.781  
  19.782 -    /* Clear the surface for display */
  19.783 -    {
  19.784 -        Uint32 black = SDL_MapRGB(surface->format, 0, 0, 0);
  19.785 -        SDL_FillRect(surface, NULL, black);
  19.786 -        if (surface->flags & SDL_DOUBLEBUF) {
  19.787 -            SDL_Flip(surface);
  19.788 -            SDL_FillRect(surface, NULL, black);
  19.789 -        }
  19.790 -        SDL_Flip(surface);
  19.791 +    /* Free the renderer instance */
  19.792 +    renderer->DestroyRenderer(renderer);
  19.793 +
  19.794 +    /* Clear references */
  19.795 +    window->renderer = NULL;
  19.796 +    if (SDL_CurrentDisplay.current_renderer == renderer) {
  19.797 +        SDL_CurrentDisplay.current_renderer = NULL;
  19.798      }
  19.799 -
  19.800 -    return surface;
  19.801 -}
  19.802 -
  19.803 -/* 
  19.804 - * Convert a surface into the video pixel format.
  19.805 - */
  19.806 -SDL_Surface *
  19.807 -SDL_DisplayFormat(SDL_Surface * surface)
  19.808 -{
  19.809 -    Uint32 flags;
  19.810 -
  19.811 -    if (!SDL_PublicSurface) {
  19.812 -        SDL_SetError("No video mode has been set");
  19.813 -        return (NULL);
  19.814 -    }
  19.815 -    /* Set the flags appropriate for copying to display surface */
  19.816 -    if (((SDL_PublicSurface->flags & SDL_HWSURFACE) == SDL_HWSURFACE)
  19.817 -        && _this->info.blit_hw)
  19.818 -        flags = SDL_HWSURFACE;
  19.819 -    else
  19.820 -        flags = SDL_SWSURFACE;
  19.821 -#ifdef AUTORLE_DISPLAYFORMAT
  19.822 -    flags |= (surface->flags & (SDL_SRCCOLORKEY | SDL_SRCALPHA));
  19.823 -    flags |= SDL_RLEACCELOK;
  19.824 -#else
  19.825 -    flags |=
  19.826 -        surface->flags & (SDL_SRCCOLORKEY | SDL_SRCALPHA | SDL_RLEACCELOK);
  19.827 -#endif
  19.828 -    return (SDL_ConvertSurface(surface, SDL_PublicSurface->format, flags));
  19.829 -}
  19.830 -
  19.831 -/*
  19.832 - * Convert a surface into a format that's suitable for blitting to
  19.833 - * the screen, but including an alpha channel.
  19.834 - */
  19.835 -SDL_Surface *
  19.836 -SDL_DisplayFormatAlpha(SDL_Surface * surface)
  19.837 -{
  19.838 -    SDL_PixelFormat *vf;
  19.839 -    SDL_PixelFormat *format;
  19.840 -    SDL_Surface *converted;
  19.841 -    Uint32 flags;
  19.842 -    /* default to ARGB8888 */
  19.843 -    Uint32 amask = 0xff000000;
  19.844 -    Uint32 rmask = 0x00ff0000;
  19.845 -    Uint32 gmask = 0x0000ff00;
  19.846 -    Uint32 bmask = 0x000000ff;
  19.847 -
  19.848 -    if (!SDL_PublicSurface) {
  19.849 -        SDL_SetError("No video mode has been set");
  19.850 -        return (NULL);
  19.851 -    }
  19.852 -    vf = SDL_PublicSurface->format;
  19.853 -
  19.854 -    switch (vf->BytesPerPixel) {
  19.855 -    case 2:
  19.856 -        /* For XGY5[56]5, use, AXGY8888, where {X, Y} = {R, B}.
  19.857 -           For anything else (like ARGB4444) it doesn't matter
  19.858 -           since we have no special code for it anyway */
  19.859 -        if ((vf->Rmask == 0x1f) &&
  19.860 -            (vf->Bmask == 0xf800 || vf->Bmask == 0x7c00)) {
  19.861 -            rmask = 0xff;
  19.862 -            bmask = 0xff0000;
  19.863 -        }
  19.864 -        break;
  19.865 -
  19.866 -    case 3:
  19.867 -    case 4:
  19.868 -        /* Keep the video format, as long as the high 8 bits are
  19.869 -           unused or alpha */
  19.870 -        if ((vf->Rmask == 0xff) && (vf->Bmask == 0xff0000)) {
  19.871 -            rmask = 0xff;
  19.872 -            bmask = 0xff0000;
  19.873 -        }
  19.874 -        break;
  19.875 -
  19.876 -    default:
  19.877 -        /* We have no other optimised formats right now. When/if a new
  19.878 -           optimised alpha format is written, add the converter here */
  19.879 -        break;
  19.880 -    }
  19.881 -    format = SDL_AllocFormat(32, rmask, gmask, bmask, amask);
  19.882 -    flags = SDL_PublicSurface->flags & SDL_HWSURFACE;
  19.883 -    flags |= surface->flags & (SDL_SRCALPHA | SDL_RLEACCELOK);
  19.884 -    converted = SDL_ConvertSurface(surface, format, flags);
  19.885 -    SDL_FreeFormat(format);
  19.886 -    return (converted);
  19.887 -}
  19.888 -
  19.889 -/*
  19.890 - * Update a specific portion of the physical screen
  19.891 - */
  19.892 -void
  19.893 -SDL_UpdateRect(SDL_Surface * screen, Sint32 x, Sint32 y, Uint32 w, Uint32 h)
  19.894 -{
  19.895 -    if (screen) {
  19.896 -        SDL_Rect rect;
  19.897 -
  19.898 -        /* Perform some checking */
  19.899 -        if (w == 0)
  19.900 -            w = screen->w;
  19.901 -        if (h == 0)
  19.902 -            h = screen->h;
  19.903 -        if ((int) (x + w) > screen->w)
  19.904 -            return;
  19.905 -        if ((int) (y + h) > screen->h)
  19.906 -            return;
  19.907 -
  19.908 -        /* Fill the rectangle */
  19.909 -        rect.x = (Sint16) x;
  19.910 -        rect.y = (Sint16) y;
  19.911 -        rect.w = (Uint16) w;
  19.912 -        rect.h = (Uint16) h;
  19.913 -        SDL_UpdateRects(screen, 1, &rect);
  19.914 -    }
  19.915 -}
  19.916 -void
  19.917 -SDL_UpdateRects(SDL_Surface * screen, int numrects, SDL_Rect * rects)
  19.918 -{
  19.919 -    int i;
  19.920 -    SDL_Window *window;
  19.921 -
  19.922 -    /* Find the window corresponding to this surface */
  19.923 -    window = SDL_GetWindowFromSurface(screen);
  19.924 -    if (!window) {
  19.925 -        SDL_SetError("Couldn't find window associated with surface");
  19.926 -        return;
  19.927 -    }
  19.928 -
  19.929 -    if (screen->flags & SDL_SHADOW_SURFACE) {
  19.930 -        if (SHOULD_DRAWCURSOR(SDL_cursorstate)) {
  19.931 -            SDL_LockCursor();
  19.932 -            SDL_DrawCursor(screen);
  19.933 -            for (i = 0; i < numrects; ++i) {
  19.934 -                SDL_LowerBlit(screen, &rects[i], window->surface, &rects[i]);
  19.935 -            }
  19.936 -            SDL_EraseCursor(screen);
  19.937 -            SDL_UnlockCursor();
  19.938 -        } else {
  19.939 -            for (i = 0; i < numrects; ++i) {
  19.940 -                SDL_LowerBlit(screen, &rects[i], window->surface, &rects[i]);
  19.941 -            }
  19.942 -        }
  19.943 -
  19.944 -        /* Fall through to video surface update */
  19.945 -        screen = window->surface;
  19.946 -    }
  19.947 -    if ((screen->flags & SDL_SCREEN_SURFACE) && _this->UpdateWindowSurface) {
  19.948 -        /* Update the video surface */
  19.949 -        if (screen->offset) {
  19.950 -            int offset_y = screen->offset / screen->pitch;
  19.951 -            int offset_x = screen->offset % screen->pitch;
  19.952 -            for (i = 0; i < numrects; ++i) {
  19.953 -                rects[i].x += offset_x;
  19.954 -                rects[i].y += offset_y;
  19.955 -            }
  19.956 -            _this->UpdateWindowSurface(_this, window, numrects, rects);
  19.957 -            for (i = 0; i < numrects; ++i) {
  19.958 -                rects[i].x -= offset_x;
  19.959 -                rects[i].y -= offset_y;
  19.960 -            }
  19.961 -        } else {
  19.962 -            _this->UpdateWindowSurface(_this, window, numrects, rects);
  19.963 -        }
  19.964 -    }
  19.965 -}
  19.966 -
  19.967 -/*
  19.968 - * Performs hardware double buffering, if possible, or a full update if not.
  19.969 - */
  19.970 -int
  19.971 -SDL_Flip(SDL_Surface * screen)
  19.972 -{
  19.973 -    SDL_Window *window;
  19.974 -
  19.975 -    /* Find the window corresponding to this surface */
  19.976 -    window = SDL_GetWindowFromSurface(screen);
  19.977 -    if (!window) {
  19.978 -        SDL_SetError("Couldn't find window associated with surface");
  19.979 -        return;
  19.980 -    }
  19.981 -
  19.982 -    /* Copy the shadow surface to the video surface */
  19.983 -    if (screen->flags & SDL_SHADOW_SURFACE) {
  19.984 -        SDL_Rect rect;
  19.985 -
  19.986 -        rect.x = 0;
  19.987 -        rect.y = 0;
  19.988 -        rect.w = screen->w;
  19.989 -        rect.h = screen->h;
  19.990 -        if (SHOULD_DRAWCURSOR(SDL_cursorstate)) {
  19.991 -            SDL_LockCursor();
  19.992 -            SDL_DrawCursor(screen);
  19.993 -            SDL_LowerBlit(screen, &rect, window->surface, &rect);
  19.994 -            SDL_EraseCursor(screen);
  19.995 -            SDL_UnlockCursor();
  19.996 -        } else {
  19.997 -            SDL_LowerBlit(screen, &rect, window->surface, &rect);
  19.998 -        }
  19.999 -
 19.1000 -        /* Fall through to video surface update */
 19.1001 -        screen = window->surface;
 19.1002 -    }
 19.1003 -    if (screen->flags & SDL_DOUBLEBUF) {
 19.1004 -        _this->FlipWindowSurface(_this, window);
 19.1005 -    } else {
 19.1006 -        SDL_UpdateRect(screen, 0, 0, 0, 0);
 19.1007 -    }
 19.1008 -    return (0);
 19.1009 -}
 19.1010 -
 19.1011 -int
 19.1012 -SDL_SetColors(SDL_Surface * screen, SDL_Color * colors, int firstcolor,
 19.1013 -              int ncolors)
 19.1014 -{
 19.1015 -    SDL_Window *window = NULL;
 19.1016 -    SDL_Palette *pal;
 19.1017 -    int gotall;
 19.1018 -    int palsize;
 19.1019 -
 19.1020 -    /* Verify the parameters */
 19.1021 -    pal = screen->format->palette;
 19.1022 -    if (!pal) {
 19.1023 -        return 0;               /* not a palettized surface */
 19.1024 -    }
 19.1025 -    gotall = 1;
 19.1026 -    palsize = 1 << screen->format->BitsPerPixel;
 19.1027 -    if (ncolors > (palsize - firstcolor)) {
 19.1028 -        ncolors = (palsize - firstcolor);
 19.1029 -        gotall = 0;
 19.1030 -    }
 19.1031 -
 19.1032 -    if (colors != (pal->colors + firstcolor)) {
 19.1033 -        SDL_memcpy(pal->colors + firstcolor, colors,
 19.1034 -                   ncolors * sizeof(*colors));
 19.1035 -    }
 19.1036 -    SDL_FormatChanged(screen);
 19.1037 -
 19.1038 -    if (screen->flags & (SDL_SHADOW_SURFACE | SDL_SCREEN_SURFACE)) {
 19.1039 -        window = SDL_GetWindowFromSurface(screen);
 19.1040 -        if (!window) {
 19.1041 -            return 0;
 19.1042 -        }
 19.1043 -    }
 19.1044 -
 19.1045 -    if (screen->flags & SDL_SHADOW_SURFACE) {
 19.1046 -        SDL_Palette *vidpal;
 19.1047 -
 19.1048 -        vidpal = window->surface->format->palette;
 19.1049 -        if (vidpal && vidpal->ncolors == pal->ncolors) {
 19.1050 -            /* This is a shadow surface, and the physical
 19.1051 -             * framebuffer is also indexed. Propagate the
 19.1052 -             * changes to its logical palette so that
 19.1053 -             * updates are always identity blits
 19.1054 -             */
 19.1055 -            SDL_memcpy(vidpal->colors + firstcolor, colors,
 19.1056 -                       ncolors * sizeof(*colors));
 19.1057 -        }
 19.1058 -        if (window->surface->flags & SDL_HWPALETTE) {
 19.1059 -            /* Set the physical palette */
 19.1060 -            screen = window->surface;
 19.1061 -        } else {
 19.1062 -            SDL_UpdateRect(screen, 0, 0, 0, 0);
 19.1063 -        }
 19.1064 -    }
 19.1065 -
 19.1066 -    if (screen->flags & SDL_SCREEN_SURFACE) {
 19.1067 -        if (_this->SetWindowColors) {
 19.1068 -            gotall =
 19.1069 -                _this->SetWindowColors(_this, window, firstcolor, ncolors,
 19.1070 -                                       colors);
 19.1071 -            if (!gotall) {
 19.1072 -                /* The video flags shouldn't have SDL_HWPALETTE, and
 19.1073 -                   the video driver is responsible for copying back the
 19.1074 -                   correct colors into the video surface palette.
 19.1075 -                 */
 19.1076 -                ;
 19.1077 -            }
 19.1078 -        }
 19.1079 -        SDL_CursorPaletteChanged();
 19.1080 -    }
 19.1081 -
 19.1082 -    return gotall;
 19.1083  }
 19.1084  
 19.1085  void
 19.1086 @@ -1416,12 +1557,12 @@
 19.1087              SDL_free(display->windows);
 19.1088              display->windows = NULL;
 19.1089          }
 19.1090 +        SDL_free(display->info.vfmt);
 19.1091      }
 19.1092      _this->VideoQuit(_this);
 19.1093      if (_this->displays) {
 19.1094          SDL_free(_this->displays);
 19.1095      }
 19.1096 -    SDL_free(_this->info.vfmt);
 19.1097      _this->free(_this);
 19.1098      _this = NULL;
 19.1099  }
 19.1100 @@ -1549,11 +1690,8 @@
 19.1101  void
 19.1102  SDL_GL_SwapBuffers(void)
 19.1103  {
 19.1104 -    if (SDL_VideoSurface->flags & SDL_INTERNALOPENGL) {
 19.1105 -        _this->GL_SwapBuffers(_this);
 19.1106 -    } else {
 19.1107 -        SDL_SetError("OpenGL video mode has not been set");
 19.1108 -    }
 19.1109 +    // FIXME: Track the current window context - do we provide N contexts, and match them to M windows, or is there a one-to-one mapping?
 19.1110 +    _this->GL_SwapBuffers(_this);
 19.1111  }
 19.1112  
 19.1113  #if 0                           // FIXME