Streamlined the API a bit and optimized the software renderer.
authorSam Lantinga
Sat, 15 Jul 2006 09:46:36 +0000
changeset 190706c27a737b7a
parent 1906 0c49855a7a3e
child 1908 e079dafea2bf
Streamlined the API a bit and optimized the software renderer.
include/SDL_video.h
src/SDL_compat.c
src/video/SDL_renderer_sw.c
src/video/SDL_sysvideo.h
src/video/SDL_video.c
src/video/dummy/SDL_nullrender.c
src/video/win32/SDL_d3drender.c
src/video/win32/SDL_gdirender.c
test/testsprite.c
test/testsprite2.c
     1.1 --- a/include/SDL_video.h	Fri Jul 14 08:24:43 2006 +0000
     1.2 +++ b/include/SDL_video.h	Sat Jul 15 09:46:36 2006 +0000
     1.3 @@ -176,9 +176,7 @@
     1.4      SDL_Renderer_PresentFlip3 = 0x00000008,     /**< Present uses a flip, rotating between two back buffers and a front buffer */
     1.5      SDL_Renderer_PresentDiscard = 0x00000010,   /**< Present leaves the contents of the backbuffer undefined */
     1.6      SDL_Renderer_PresentVSync = 0x00000020,     /**< Present is synchronized with the refresh rate */
     1.7 -    SDL_Renderer_RenderTarget = 0x00000040,     /**< The renderer can create texture render targets */
     1.8 -    SDL_Renderer_Accelerated = 0x00000080,      /**< The renderer uses hardware acceleration */
     1.9 -    SDL_Renderer_Minimal = 0x00000100,          /**< The renderer only supports the read/write pixel and present functions */
    1.10 +    SDL_Renderer_Accelerated = 0x00000040,      /**< The renderer uses hardware acceleration */
    1.11  } SDL_RendererFlags;
    1.12  
    1.13  /**
    1.14 @@ -193,7 +191,7 @@
    1.15      Uint32 blend_modes;         /**< A mask of supported blend modes */
    1.16      Uint32 scale_modes;         /**< A mask of supported scale modes */
    1.17      Uint32 num_texture_formats; /**< The number of available texture formats */
    1.18 -    Uint32 texture_formats[32]; /**< The available texture formats */
    1.19 +    Uint32 texture_formats[16]; /**< The available texture formats */
    1.20      int max_texture_width;      /**< The maximimum texture width */
    1.21      int max_texture_height;     /**< The maximimum texture height */
    1.22  } SDL_RendererInfo;
    1.23 @@ -205,9 +203,8 @@
    1.24   */
    1.25  typedef enum
    1.26  {
    1.27 -    SDL_TextureAccess_Render,   /**< Unlockable video memory, rendering allowed */
    1.28 +    SDL_TextureAccess_Local,    /**< Lockable system memory */
    1.29      SDL_TextureAccess_Remote,   /**< Unlockable video memory */
    1.30 -    SDL_TextureAccess_Local,    /**< Lockable system memory */
    1.31  } SDL_TextureAccess;
    1.32  
    1.33  /**
    1.34 @@ -836,11 +833,16 @@
    1.35  extern DECLSPEC int SDLCALL SDL_GetNumRenderers(void);
    1.36  
    1.37  /**
    1.38 - * \fn SDL_RendererInfo *SDL_GetRendererInfo(int index)
    1.39 + * \fn int SDL_GetRendererInfo(int index, SDL_RendererInfo *info)
    1.40   *
    1.41   * \brief Get information about a specific render manager on the current
    1.42   *        display.
    1.43   *
    1.44 + * \param index The index to query information about, or -1 to query the currently renderer
    1.45 + * \param info A pointer to an SDL_RendererInfo struct to be filled with information on the renderer
    1.46 + *
    1.47 + * \return 0 on success, -1 if the index was out of range
    1.48 + *
    1.49   * \sa SDL_CreateRenderer()
    1.50   */
    1.51  extern DECLSPEC int SDLCALL SDL_GetRendererInfo(int index,
     2.1 --- a/src/SDL_compat.c	Fri Jul 14 08:24:43 2006 +0000
     2.2 +++ b/src/SDL_compat.c	Sat Jul 15 09:46:36 2006 +0000
     2.3 @@ -31,6 +31,7 @@
     2.4  
     2.5  
     2.6  static SDL_WindowID SDL_VideoWindow;
     2.7 +static SDL_RendererInfo SDL_VideoRendererInfo;
     2.8  static SDL_TextureID SDL_VideoTexture;
     2.9  static SDL_Surface *SDL_VideoSurface;
    2.10  static SDL_Surface *SDL_ShadowSurface;
    2.11 @@ -442,10 +443,12 @@
    2.12      }
    2.13  
    2.14      /* Create a renderer for the window */
    2.15 -    if (SDL_CreateRenderer(SDL_VideoWindow, -1, SDL_Renderer_SingleBuffer) <
    2.16 -        0) {
    2.17 +    if (SDL_CreateRenderer
    2.18 +        (SDL_VideoWindow, -1,
    2.19 +         SDL_Renderer_SingleBuffer | SDL_Renderer_PresentDiscard) < 0) {
    2.20          return NULL;
    2.21      }
    2.22 +    SDL_GetRendererInfo(-1, &SDL_VideoRendererInfo);
    2.23  
    2.24      /* Create a texture for the screen surface */
    2.25      SDL_VideoTexture =
    2.26 @@ -642,8 +645,19 @@
    2.27          screen = SDL_VideoSurface;
    2.28      }
    2.29      if (screen == SDL_VideoSurface) {
    2.30 -        for (i = 0; i < numrects; ++i) {
    2.31 -            SDL_RenderCopy(SDL_VideoTexture, &rects[i], &rects[i],
    2.32 +        if (SDL_VideoRendererInfo.flags & SDL_Renderer_PresentCopy) {
    2.33 +            for (i = 0; i < numrects; ++i) {
    2.34 +                SDL_RenderCopy(SDL_VideoTexture, &rects[i], &rects[i],
    2.35 +                               SDL_TextureBlendMode_None,
    2.36 +                               SDL_TextureScaleMode_None);
    2.37 +            }
    2.38 +        } else {
    2.39 +            SDL_Rect rect;
    2.40 +            rect.x = 0;
    2.41 +            rect.y = 0;
    2.42 +            rect.w = screen->w;
    2.43 +            rect.h = screen->h;
    2.44 +            SDL_RenderCopy(SDL_VideoTexture, &rect, &rect,
    2.45                             SDL_TextureBlendMode_None,
    2.46                             SDL_TextureScaleMode_None);
    2.47          }
     3.1 --- a/src/video/SDL_renderer_sw.c	Fri Jul 14 08:24:43 2006 +0000
     3.2 +++ b/src/video/SDL_renderer_sw.c	Sat Jul 15 09:46:36 2006 +0000
     3.3 @@ -23,6 +23,7 @@
     3.4  
     3.5  #include "SDL_video.h"
     3.6  #include "SDL_sysvideo.h"
     3.7 +#include "SDL_pixels_c.h"
     3.8  #include "SDL_rect_c.h"
     3.9  #include "SDL_yuv_sw_c.h"
    3.10  
    3.11 @@ -53,20 +54,12 @@
    3.12  static void SDL_SW_DirtyTexture(SDL_Renderer * renderer,
    3.13                                  SDL_Texture * texture, int numrects,
    3.14                                  const SDL_Rect * rects);
    3.15 -static void SDL_SW_SelectRenderTexture(SDL_Renderer * renderer,
    3.16 -                                       SDL_Texture * texture);
    3.17  static int SDL_SW_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect,
    3.18                               Uint32 color);
    3.19  static int SDL_SW_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
    3.20                               const SDL_Rect * srcrect,
    3.21                               const SDL_Rect * dstrect, int blendMode,
    3.22                               int scaleMode);
    3.23 -static int SDL_SW_RenderReadPixels(SDL_Renderer * renderer,
    3.24 -                                   const SDL_Rect * rect, void *pixels,
    3.25 -                                   int pitch);
    3.26 -static int SDL_SW_RenderWritePixels(SDL_Renderer * renderer,
    3.27 -                                    const SDL_Rect * rect, const void *pixels,
    3.28 -                                    int pitch);
    3.29  static void SDL_SW_RenderPresent(SDL_Renderer * renderer);
    3.30  static void SDL_SW_DestroyTexture(SDL_Renderer * renderer,
    3.31                                    SDL_Texture * texture);
    3.32 @@ -79,7 +72,7 @@
    3.33       "software",
    3.34       (SDL_Renderer_SingleBuffer | SDL_Renderer_PresentCopy |
    3.35        SDL_Renderer_PresentFlip2 | SDL_Renderer_PresentFlip3 |
    3.36 -      SDL_Renderer_PresentDiscard | SDL_Renderer_RenderTarget),
    3.37 +      SDL_Renderer_PresentDiscard | SDL_Renderer_PresentVSync),
    3.38       (SDL_TextureBlendMode_None | SDL_TextureBlendMode_Mask |
    3.39        SDL_TextureBlendMode_Blend),
    3.40       (SDL_TextureScaleMode_None | SDL_TextureScaleMode_Fast),
    3.41 @@ -102,14 +95,63 @@
    3.42  
    3.43  typedef struct
    3.44  {
    3.45 -    int current_screen;
    3.46 -    SDL_Surface *screens[3];
    3.47 -    SDL_Surface *target;
    3.48 +    Uint32 format;
    3.49 +    int current_texture;
    3.50 +    SDL_Texture *texture[3];
    3.51 +    SDL_Surface surface;
    3.52      SDL_Renderer *renderer;
    3.53      SDL_DirtyRectList dirty;
    3.54 -    SDL_bool makedirty;
    3.55  } SDL_SW_RenderData;
    3.56  
    3.57 +static SDL_Texture *
    3.58 +CreateTexture(SDL_Renderer * renderer, Uint32 format, int w, int h)
    3.59 +{
    3.60 +    SDL_Texture *texture;
    3.61 +
    3.62 +    texture = (SDL_Texture *) SDL_malloc(sizeof(*texture));
    3.63 +    if (!texture) {
    3.64 +        SDL_OutOfMemory();
    3.65 +        return NULL;
    3.66 +    }
    3.67 +
    3.68 +    SDL_zerop(texture);
    3.69 +    texture->format = format;
    3.70 +    texture->access = SDL_TextureAccess_Local;
    3.71 +    texture->w = w;
    3.72 +    texture->h = h;
    3.73 +    texture->renderer = renderer;
    3.74 +
    3.75 +    if (renderer->CreateTexture(renderer, texture) < 0) {
    3.76 +        SDL_free(texture);
    3.77 +        return NULL;
    3.78 +    }
    3.79 +    return texture;
    3.80 +}
    3.81 +
    3.82 +static void
    3.83 +DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
    3.84 +{
    3.85 +    renderer->DestroyTexture(renderer, texture);
    3.86 +    SDL_free(texture);
    3.87 +}
    3.88 +
    3.89 +static int
    3.90 +DisplayPaletteChanged(void *userdata, SDL_Palette * palette)
    3.91 +{
    3.92 +    SDL_SW_RenderData *data = (SDL_SW_RenderData *) userdata;
    3.93 +    int i;
    3.94 +
    3.95 +    for (i = 0; i < SDL_arraysize(data->texture); ++i) {
    3.96 +        if (data->texture[i] && data->renderer->SetTexturePalette) {
    3.97 +            data->renderer->SetTexturePalette(data->renderer,
    3.98 +                                              data->texture[i],
    3.99 +                                              palette->colors, 0,
   3.100 +                                              palette->ncolors);
   3.101 +        }
   3.102 +    }
   3.103 +    return 0;
   3.104 +}
   3.105 +
   3.106  SDL_Renderer *
   3.107  SDL_SW_CreateRenderer(SDL_Window * window, Uint32 flags)
   3.108  {
   3.109 @@ -120,6 +162,7 @@
   3.110      int i, n;
   3.111      int bpp;
   3.112      Uint32 Rmask, Gmask, Bmask, Amask;
   3.113 +    Uint32 renderer_flags;
   3.114  
   3.115      if (!SDL_PixelFormatEnumToMasks
   3.116          (displayMode->format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) {
   3.117 @@ -149,11 +192,8 @@
   3.118      renderer->LockTexture = SDL_SW_LockTexture;
   3.119      renderer->UnlockTexture = SDL_SW_UnlockTexture;
   3.120      renderer->DirtyTexture = SDL_SW_DirtyTexture;
   3.121 -    renderer->SelectRenderTexture = SDL_SW_SelectRenderTexture;
   3.122      renderer->RenderFill = SDL_SW_RenderFill;
   3.123      renderer->RenderCopy = SDL_SW_RenderCopy;
   3.124 -    renderer->RenderReadPixels = SDL_SW_RenderReadPixels;
   3.125 -    renderer->RenderWritePixels = SDL_SW_RenderWritePixels;
   3.126      renderer->RenderPresent = SDL_SW_RenderPresent;
   3.127      renderer->DestroyTexture = SDL_SW_DestroyTexture;
   3.128      renderer->DestroyRenderer = SDL_SW_DestroyRenderer;
   3.129 @@ -161,7 +201,7 @@
   3.130      renderer->window = window->id;
   3.131      renderer->driverdata = data;
   3.132  
   3.133 -    renderer->info.flags = SDL_Renderer_RenderTarget;
   3.134 +    renderer->info.flags = 0;
   3.135  
   3.136      if (flags & SDL_Renderer_PresentFlip2) {
   3.137          renderer->info.flags |= SDL_Renderer_PresentFlip2;
   3.138 @@ -173,28 +213,18 @@
   3.139          renderer->info.flags |= SDL_Renderer_PresentCopy;
   3.140          n = 1;
   3.141      }
   3.142 -    for (i = 0; i < n; ++i) {
   3.143 -        data->screens[i] =
   3.144 -            SDL_CreateRGBSurface(0, window->w, window->h, bpp, Rmask, Gmask,
   3.145 -                                 Bmask, Amask);
   3.146 -        if (!data->screens[i]) {
   3.147 -            SDL_SW_DestroyRenderer(renderer);
   3.148 -            return NULL;
   3.149 -        }
   3.150 -        SDL_SetSurfacePalette(data->screens[i], display->palette);
   3.151 -    }
   3.152 -    data->current_screen = 0;
   3.153 -    data->target = data->screens[0];
   3.154 -    data->makedirty = SDL_TRUE;
   3.155 +    data->format = displayMode->format;
   3.156  
   3.157      /* Find a render driver that we can use to display data */
   3.158 +    renderer_flags = (SDL_Renderer_SingleBuffer |
   3.159 +                      SDL_Renderer_PresentDiscard);
   3.160 +    if (flags & SDL_Renderer_PresentVSync) {
   3.161 +        renderer_flags |= SDL_Renderer_PresentVSync;
   3.162 +    }
   3.163      for (i = 0; i < display->num_render_drivers; ++i) {
   3.164          SDL_RenderDriver *driver = &display->render_drivers[i];
   3.165          if (driver->info.name != SDL_SW_RenderDriver.info.name) {
   3.166 -            data->renderer =
   3.167 -                driver->CreateRenderer(window,
   3.168 -                                       (SDL_Renderer_SingleBuffer |
   3.169 -                                        SDL_Renderer_PresentDiscard));
   3.170 +            data->renderer = driver->CreateRenderer(window, renderer_flags);
   3.171              if (data->renderer) {
   3.172                  break;
   3.173              }
   3.174 @@ -205,6 +235,35 @@
   3.175          SDL_SetError("Couldn't find display render driver");
   3.176          return NULL;
   3.177      }
   3.178 +    if (data->renderer->info.flags & SDL_Renderer_PresentVSync) {
   3.179 +        renderer->info.flags |= SDL_Renderer_PresentVSync;
   3.180 +    }
   3.181 +
   3.182 +    /* Create the textures we'll use for display */
   3.183 +    for (i = 0; i < n; ++i) {
   3.184 +        data->texture[i] =
   3.185 +            CreateTexture(data->renderer, data->format, window->w, window->h);
   3.186 +        if (!data->texture[i]) {
   3.187 +            SDL_SW_DestroyRenderer(renderer);
   3.188 +            return NULL;
   3.189 +        }
   3.190 +    }
   3.191 +    data->current_texture = 0;
   3.192 +
   3.193 +    /* Create a surface we'll use for rendering */
   3.194 +    data->surface.flags = SDL_PREALLOC;
   3.195 +    data->surface.format = SDL_AllocFormat(bpp, Rmask, Gmask, Bmask, Amask);
   3.196 +    if (!data->surface.format) {
   3.197 +        SDL_SW_DestroyRenderer(renderer);
   3.198 +        return NULL;
   3.199 +    }
   3.200 +    SDL_SetSurfacePalette(&data->surface, display->palette);
   3.201 +
   3.202 +    /* Set up a palette watch on the display palette */
   3.203 +    if (display->palette) {
   3.204 +        SDL_AddPaletteWatch(display->palette, DisplayPaletteChanged, data);
   3.205 +    }
   3.206 +
   3.207      return renderer;
   3.208  }
   3.209  
   3.210 @@ -212,10 +271,6 @@
   3.211  SDL_SW_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
   3.212  {
   3.213      if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
   3.214 -        if (texture->access == SDL_TextureAccess_Render) {
   3.215 -            SDL_SetError("Rendering to YUV format textures is not supported");
   3.216 -            return -1;
   3.217 -        }
   3.218          texture->driverdata = SDL_SW_CreateYUVTexture(texture);
   3.219      } else {
   3.220          int bpp;
   3.221 @@ -347,29 +402,18 @@
   3.222  {
   3.223  }
   3.224  
   3.225 -static void
   3.226 -SDL_SW_SelectRenderTexture(SDL_Renderer * renderer, SDL_Texture * texture)
   3.227 -{
   3.228 -    SDL_SW_RenderData *data = (SDL_SW_RenderData *) renderer->driverdata;
   3.229 -
   3.230 -    if (texture) {
   3.231 -        data->target = (SDL_Surface *) texture->driverdata;
   3.232 -        data->makedirty = SDL_FALSE;
   3.233 -    } else {
   3.234 -        data->target = data->screens[data->current_screen];
   3.235 -        data->makedirty = SDL_TRUE;
   3.236 -    }
   3.237 -}
   3.238 -
   3.239  static int
   3.240  SDL_SW_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect,
   3.241                    Uint32 color)
   3.242  {
   3.243      SDL_SW_RenderData *data = (SDL_SW_RenderData *) renderer->driverdata;
   3.244 -    SDL_Rect real_rect = *rect;
   3.245      Uint8 r, g, b, a;
   3.246 +    void *pixels;
   3.247 +    int pitch;
   3.248 +    SDL_Rect real_rect;
   3.249 +    int status;
   3.250  
   3.251 -    if (data->makedirty) {
   3.252 +    if (data->renderer->info.flags & SDL_Renderer_PresentCopy) {
   3.253          SDL_AddDirtyRect(&data->dirty, rect);
   3.254      }
   3.255  
   3.256 @@ -377,9 +421,25 @@
   3.257      r = (Uint8) ((color >> 16) & 0xFF);
   3.258      g = (Uint8) ((color >> 8) & 0xFF);
   3.259      b = (Uint8) (color & 0xFF);
   3.260 -    color = SDL_MapRGBA(data->target->format, r, g, b, a);
   3.261 +    color = SDL_MapRGBA(data->surface.format, r, g, b, a);
   3.262  
   3.263 -    return SDL_FillRect(data->target, &real_rect, color);
   3.264 +    if (data->renderer->
   3.265 +        LockTexture(data->renderer, data->texture[data->current_texture],
   3.266 +                    rect, 1, &data->surface.pixels,
   3.267 +                    &data->surface.pitch) < 0) {
   3.268 +        return -1;
   3.269 +    }
   3.270 +    data->surface.w = rect->w;
   3.271 +    data->surface.h = rect->h;
   3.272 +    data->surface.clip_rect.w = rect->w;
   3.273 +    data->surface.clip_rect.h = rect->h;
   3.274 +    real_rect = data->surface.clip_rect;
   3.275 +
   3.276 +    status = SDL_FillRect(&data->surface, &real_rect, color);
   3.277 +
   3.278 +    data->renderer->UnlockTexture(data->renderer,
   3.279 +                                  data->texture[data->current_texture]);
   3.280 +    return status;
   3.281  }
   3.282  
   3.283  static int
   3.284 @@ -389,25 +449,34 @@
   3.285  {
   3.286      SDL_SW_RenderData *data = (SDL_SW_RenderData *) renderer->driverdata;
   3.287      SDL_Window *window = SDL_GetWindowFromID(renderer->window);
   3.288 -    SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
   3.289 +    int status;
   3.290 +
   3.291 +    if (data->renderer->info.flags & SDL_Renderer_PresentCopy) {
   3.292 +        SDL_AddDirtyRect(&data->dirty, dstrect);
   3.293 +    }
   3.294  
   3.295 -    if (data->makedirty) {
   3.296 -        SDL_AddDirtyRect(&data->dirty, dstrect);
   3.297 +    if (data->renderer->
   3.298 +        LockTexture(data->renderer, data->texture[data->current_texture],
   3.299 +                    dstrect, 1, &data->surface.pixels,
   3.300 +                    &data->surface.pitch) < 0) {
   3.301 +        return -1;
   3.302      }
   3.303  
   3.304      if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
   3.305 -        SDL_Surface *target = data->target;
   3.306 -        void *pixels =
   3.307 -            (Uint8 *) target->pixels + dstrect->y * target->pitch +
   3.308 -            dstrect->x * target->format->BytesPerPixel;
   3.309 -        return SDL_SW_CopyYUVToRGB((SDL_SW_YUVTexture *) texture->driverdata,
   3.310 -                                   srcrect, display->current_mode.format,
   3.311 -                                   dstrect->w, dstrect->h, pixels,
   3.312 -                                   target->pitch);
   3.313 +        status =
   3.314 +            SDL_SW_CopyYUVToRGB((SDL_SW_YUVTexture *) texture->driverdata,
   3.315 +                                srcrect, data->format, dstrect->w, dstrect->h,
   3.316 +                                data->surface.pixels, data->surface.pitch);
   3.317      } else {
   3.318          SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
   3.319          SDL_Rect real_srcrect = *srcrect;
   3.320 -        SDL_Rect real_dstrect = *dstrect;
   3.321 +        SDL_Rect real_dstrect;
   3.322 +
   3.323 +        data->surface.w = dstrect->w;
   3.324 +        data->surface.h = dstrect->h;
   3.325 +        data->surface.clip_rect.w = dstrect->w;
   3.326 +        data->surface.clip_rect.h = dstrect->h;
   3.327 +        real_dstrect = data->surface.clip_rect;
   3.328  
   3.329          if (blendMode &
   3.330              (SDL_TextureBlendMode_Mask | SDL_TextureBlendMode_Blend)) {
   3.331 @@ -417,91 +486,53 @@
   3.332          }
   3.333          if (scaleMode != SDL_TextureScaleMode_None &&
   3.334              (srcrect->w != dstrect->w || srcrect->h != dstrect->h)) {
   3.335 -            return SDL_SoftStretch(surface, &real_srcrect, data->target,
   3.336 -                                   &real_dstrect);
   3.337 +            status =
   3.338 +                SDL_SoftStretch(surface, &real_srcrect, &data->surface,
   3.339 +                                &real_dstrect);
   3.340          } else {
   3.341 -            return SDL_LowerBlit(surface, &real_srcrect, data->target,
   3.342 -                                 &real_dstrect);
   3.343 +            status =
   3.344 +                SDL_LowerBlit(surface, &real_srcrect, &data->surface,
   3.345 +                              &real_dstrect);
   3.346          }
   3.347      }
   3.348 -}
   3.349 -
   3.350 -static int
   3.351 -SDL_SW_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
   3.352 -                        void *pixels, int pitch)
   3.353 -{
   3.354 -    SDL_SW_RenderData *data = (SDL_SW_RenderData *) renderer->driverdata;
   3.355 -    SDL_Surface *surface = data->target;
   3.356 -    Uint8 *src, *dst;
   3.357 -    int row;
   3.358 -    size_t length;
   3.359 -
   3.360 -    src =
   3.361 -        (Uint8 *) surface->pixels + rect->y * surface->pitch +
   3.362 -        rect->x * surface->format->BytesPerPixel;
   3.363 -    dst = (Uint8 *) pixels;
   3.364 -    length = rect->w * surface->format->BytesPerPixel;
   3.365 -    for (row = 0; row < rect->h; ++row) {
   3.366 -        SDL_memcpy(dst, src, length);
   3.367 -        src += surface->pitch;
   3.368 -        dst += pitch;
   3.369 -    }
   3.370 -    return 0;
   3.371 -}
   3.372 -
   3.373 -static int
   3.374 -SDL_SW_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect,
   3.375 -                         const void *pixels, int pitch)
   3.376 -{
   3.377 -    SDL_SW_RenderData *data = (SDL_SW_RenderData *) renderer->driverdata;
   3.378 -    SDL_Surface *surface = data->target;
   3.379 -    Uint8 *src, *dst;
   3.380 -    int row;
   3.381 -    size_t length;
   3.382 -
   3.383 -    if (data->makedirty) {
   3.384 -        SDL_AddDirtyRect(&data->dirty, rect);
   3.385 -    }
   3.386 -
   3.387 -    src = (Uint8 *) pixels;
   3.388 -    dst =
   3.389 -        (Uint8 *) surface->pixels + rect->y * surface->pitch +
   3.390 -        rect->x * surface->format->BytesPerPixel;
   3.391 -    length = rect->w * surface->format->BytesPerPixel;
   3.392 -    for (row = 0; row < rect->h; ++row) {
   3.393 -        SDL_memcpy(dst, src, length);
   3.394 -        src += pitch;
   3.395 -        dst += surface->pitch;
   3.396 -    }
   3.397 -    return 0;
   3.398 +    data->renderer->UnlockTexture(data->renderer,
   3.399 +                                  data->texture[data->current_texture]);
   3.400 +    return status;
   3.401  }
   3.402  
   3.403  static void
   3.404  SDL_SW_RenderPresent(SDL_Renderer * renderer)
   3.405  {
   3.406      SDL_SW_RenderData *data = (SDL_SW_RenderData *) renderer->driverdata;
   3.407 -    SDL_Surface *surface = data->screens[data->current_screen];
   3.408 -    SDL_DirtyRect *dirty;
   3.409 +    SDL_Texture *texture = data->texture[data->current_texture];
   3.410  
   3.411      /* Send the data to the display */
   3.412 -    for (dirty = data->dirty.list; dirty; dirty = dirty->next) {
   3.413 -        void *pixels =
   3.414 -            (void *) ((Uint8 *) surface->pixels +
   3.415 -                      dirty->rect.y * surface->pitch +
   3.416 -                      dirty->rect.x * surface->format->BytesPerPixel);
   3.417 -        data->renderer->RenderWritePixels(data->renderer, &dirty->rect,
   3.418 -                                          pixels, surface->pitch);
   3.419 +    if (data->renderer->info.flags & SDL_Renderer_PresentCopy) {
   3.420 +        SDL_DirtyRect *dirty;
   3.421 +        for (dirty = data->dirty.list; dirty; dirty = dirty->next) {
   3.422 +            data->renderer->RenderCopy(data->renderer, texture, &dirty->rect,
   3.423 +                                       &dirty->rect,
   3.424 +                                       SDL_TextureBlendMode_None,
   3.425 +                                       SDL_TextureScaleMode_None);
   3.426 +        }
   3.427 +        SDL_ClearDirtyRects(&data->dirty);
   3.428 +    } else {
   3.429 +        SDL_Rect rect;
   3.430 +        rect.x = 0;
   3.431 +        rect.y = 0;
   3.432 +        rect.w = texture->w;
   3.433 +        rect.h = texture->h;
   3.434 +        data->renderer->RenderCopy(data->renderer, texture, &rect, &rect,
   3.435 +                                   SDL_TextureBlendMode_None,
   3.436 +                                   SDL_TextureScaleMode_None);
   3.437      }
   3.438 -    SDL_ClearDirtyRects(&data->dirty);
   3.439      data->renderer->RenderPresent(data->renderer);
   3.440  
   3.441      /* Update the flipping chain, if any */
   3.442      if (renderer->info.flags & SDL_Renderer_PresentFlip2) {
   3.443 -        data->current_screen = (data->current_screen + 1) % 2;
   3.444 -        data->target = data->screens[data->current_screen];
   3.445 +        data->current_texture = (data->current_texture + 1) % 2;
   3.446      } else if (renderer->info.flags & SDL_Renderer_PresentFlip3) {
   3.447 -        data->current_screen = (data->current_screen + 1) % 3;
   3.448 -        data->target = data->screens[data->current_screen];
   3.449 +        data->current_texture = (data->current_texture + 1) % 3;
   3.450      }
   3.451  }
   3.452  
   3.453 @@ -521,14 +552,27 @@
   3.454  SDL_SW_DestroyRenderer(SDL_Renderer * renderer)
   3.455  {
   3.456      SDL_SW_RenderData *data = (SDL_SW_RenderData *) renderer->driverdata;
   3.457 +    SDL_Window *window = SDL_GetWindowFromID(renderer->window);
   3.458 +    SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
   3.459      int i;
   3.460  
   3.461      if (data) {
   3.462 -        for (i = 0; i < SDL_arraysize(data->screens); ++i) {
   3.463 -            if (data->screens[i]) {
   3.464 -                SDL_FreeSurface(data->screens[i]);
   3.465 +        for (i = 0; i < SDL_arraysize(data->texture); ++i) {
   3.466 +            if (data->texture[i]) {
   3.467 +                DestroyTexture(data->renderer, data->texture[i]);
   3.468              }
   3.469          }
   3.470 +        if (data->surface.format) {
   3.471 +            SDL_SetSurfacePalette(&data->surface, NULL);
   3.472 +            SDL_FreeFormat(data->surface.format);
   3.473 +        }
   3.474 +        if (display->palette) {
   3.475 +            SDL_DelPaletteWatch(display->palette, DisplayPaletteChanged,
   3.476 +                                data);
   3.477 +        }
   3.478 +        if (data->renderer) {
   3.479 +            data->renderer->DestroyRenderer(data->renderer);
   3.480 +        }
   3.481          SDL_FreeDirtyRects(&data->dirty);
   3.482          SDL_free(data);
   3.483      }
     4.1 --- a/src/video/SDL_sysvideo.h	Fri Jul 14 08:24:43 2006 +0000
     4.2 +++ b/src/video/SDL_sysvideo.h	Sat Jul 15 09:46:36 2006 +0000
     4.3 @@ -73,17 +73,11 @@
     4.4      void (*UnlockTexture) (SDL_Renderer * renderer, SDL_Texture * texture);
     4.5      void (*DirtyTexture) (SDL_Renderer * renderer, SDL_Texture * texture,
     4.6                            int numrects, const SDL_Rect * rects);
     4.7 -    void (*SelectRenderTexture) (SDL_Renderer * renderer,
     4.8 -                                 SDL_Texture * texture);
     4.9      int (*RenderFill) (SDL_Renderer * renderer, const SDL_Rect * rect,
    4.10                         Uint32 color);
    4.11      int (*RenderCopy) (SDL_Renderer * renderer, SDL_Texture * texture,
    4.12                         const SDL_Rect * srcrect, const SDL_Rect * dstrect,
    4.13                         int blendMode, int scaleMode);
    4.14 -    int (*RenderReadPixels) (SDL_Renderer * renderer, const SDL_Rect * rect,
    4.15 -                             void *pixels, int pitch);
    4.16 -    int (*RenderWritePixels) (SDL_Renderer * renderer, const SDL_Rect * rect,
    4.17 -                              const void *pixels, int pitch);
    4.18      void (*RenderPresent) (SDL_Renderer * renderer);
    4.19      void (*DestroyTexture) (SDL_Renderer * renderer, SDL_Texture * texture);
    4.20  
     5.1 --- a/src/video/SDL_video.c	Fri Jul 14 08:24:43 2006 +0000
     5.2 +++ b/src/video/SDL_video.c	Sat Jul 15 09:46:36 2006 +0000
     5.3 @@ -1277,12 +1277,24 @@
     5.4  int
     5.5  SDL_GetRendererInfo(int index, SDL_RendererInfo * info)
     5.6  {
     5.7 -    if (index < 0 || index >= SDL_GetNumRenderers()) {
     5.8 +    if (!_this) {
     5.9 +        return -1;
    5.10 +    }
    5.11 +
    5.12 +    if (index >= SDL_GetNumRenderers()) {
    5.13          SDL_SetError("index must be in the range of 0 - %d",
    5.14                       SDL_GetNumRenderers() - 1);
    5.15          return -1;
    5.16      }
    5.17 -    *info = SDL_CurrentDisplay.render_drivers[index].info;
    5.18 +    if (index < 0) {
    5.19 +        if (!SDL_CurrentDisplay.current_renderer) {
    5.20 +            SDL_SetError("There is no current renderer");
    5.21 +            return -1;
    5.22 +        }
    5.23 +        *info = SDL_CurrentDisplay.current_renderer->info;
    5.24 +    } else {
    5.25 +        *info = SDL_CurrentDisplay.render_drivers[index].info;
    5.26 +    }
    5.27      return 0;
    5.28  }
    5.29  
    5.30 @@ -1307,11 +1319,6 @@
    5.31                      break;
    5.32                  }
    5.33              } else {
    5.34 -                /* Skip minimal drivers in automatic scans */
    5.35 -                if (!(flags & SDL_Renderer_Minimal)
    5.36 -                    && (driver->info.flags & SDL_Renderer_Minimal)) {
    5.37 -                    continue;
    5.38 -                }
    5.39                  if ((driver->info.flags & flags) == flags) {
    5.40                      break;
    5.41                  }
    5.42 @@ -1734,22 +1741,6 @@
    5.43      renderer->DirtyTexture(renderer, texture, numrects, rects);
    5.44  }
    5.45  
    5.46 -void
    5.47 -SDL_SelectRenderTexture(SDL_TextureID textureID)
    5.48 -{
    5.49 -    SDL_Texture *texture = SDL_GetTextureFromID(textureID);
    5.50 -    SDL_Renderer *renderer;
    5.51 -
    5.52 -    if (!texture || texture->access != SDL_TextureAccess_Render) {
    5.53 -        return;
    5.54 -    }
    5.55 -    renderer = texture->renderer;
    5.56 -    if (!renderer->SelectRenderTexture) {
    5.57 -        return;
    5.58 -    }
    5.59 -    renderer->SelectRenderTexture(renderer, texture);
    5.60 -}
    5.61 -
    5.62  int
    5.63  SDL_RenderFill(const SDL_Rect * rect, Uint32 color)
    5.64  {
    5.65 @@ -1821,60 +1812,6 @@
    5.66                                  &real_dstrect, blendMode, scaleMode);
    5.67  }
    5.68  
    5.69 -int
    5.70 -SDL_RenderReadPixels(const SDL_Rect * rect, void *pixels, int pitch)
    5.71 -{
    5.72 -    SDL_Renderer *renderer;
    5.73 -    SDL_Rect full_rect;
    5.74 -
    5.75 -    if (!_this) {
    5.76 -        return -1;
    5.77 -    }
    5.78 -
    5.79 -    renderer = SDL_CurrentDisplay.current_renderer;
    5.80 -    if (!renderer || !renderer->RenderReadPixels) {
    5.81 -        return -1;
    5.82 -    }
    5.83 -
    5.84 -    if (!rect) {
    5.85 -        SDL_Window *window = SDL_GetWindowFromID(renderer->window);
    5.86 -        full_rect.x = 0;
    5.87 -        full_rect.y = 0;
    5.88 -        full_rect.w = window->w;
    5.89 -        full_rect.h = window->h;
    5.90 -        rect = &full_rect;
    5.91 -    }
    5.92 -
    5.93 -    return renderer->RenderReadPixels(renderer, rect, pixels, pitch);
    5.94 -}
    5.95 -
    5.96 -int
    5.97 -SDL_RenderWritePixels(const SDL_Rect * rect, const void *pixels, int pitch)
    5.98 -{
    5.99 -    SDL_Renderer *renderer;
   5.100 -    SDL_Rect full_rect;
   5.101 -
   5.102 -    if (!_this) {
   5.103 -        return -1;
   5.104 -    }
   5.105 -
   5.106 -    renderer = SDL_CurrentDisplay.current_renderer;
   5.107 -    if (!renderer || !renderer->RenderWritePixels) {
   5.108 -        return -1;
   5.109 -    }
   5.110 -
   5.111 -    if (!rect) {
   5.112 -        SDL_Window *window = SDL_GetWindowFromID(renderer->window);
   5.113 -        full_rect.x = 0;
   5.114 -        full_rect.y = 0;
   5.115 -        full_rect.w = window->w;
   5.116 -        full_rect.h = window->h;
   5.117 -        rect = &full_rect;
   5.118 -    }
   5.119 -
   5.120 -    return renderer->RenderWritePixels(renderer, rect, pixels, pitch);
   5.121 -}
   5.122 -
   5.123  void
   5.124  SDL_RenderPresent(void)
   5.125  {
   5.126 @@ -1888,10 +1825,6 @@
   5.127      if (!renderer || !renderer->RenderPresent) {
   5.128          return;
   5.129      }
   5.130 -
   5.131 -    if (renderer->SelectRenderTexture) {
   5.132 -        renderer->SelectRenderTexture(renderer, NULL);
   5.133 -    }
   5.134      renderer->RenderPresent(renderer);
   5.135  }
   5.136  
     6.1 --- a/src/video/dummy/SDL_nullrender.c	Fri Jul 14 08:24:43 2006 +0000
     6.2 +++ b/src/video/dummy/SDL_nullrender.c	Sat Jul 15 09:46:36 2006 +0000
     6.3 @@ -31,12 +31,6 @@
     6.4                                                Uint32 flags);
     6.5  static int SDL_DUMMY_CreateTexture(SDL_Renderer * renderer,
     6.6                                     SDL_Texture * texture);
     6.7 -static int SDL_DUMMY_RenderReadPixels(SDL_Renderer * renderer,
     6.8 -                                      const SDL_Rect * rect, void *pixels,
     6.9 -                                      int pitch);
    6.10 -static int SDL_DUMMY_RenderWritePixels(SDL_Renderer * renderer,
    6.11 -                                       const SDL_Rect * rect,
    6.12 -                                       const void *pixels, int pitch);
    6.13  static void SDL_DUMMY_RenderPresent(SDL_Renderer * renderer);
    6.14  static void SDL_DUMMY_DestroyRenderer(SDL_Renderer * renderer);
    6.15  
    6.16 @@ -45,8 +39,7 @@
    6.17      SDL_DUMMY_CreateRenderer,
    6.18      {
    6.19       "dummy",
    6.20 -     (SDL_Renderer_Minimal | SDL_Renderer_PresentDiscard |
    6.21 -      SDL_Renderer_PresentCopy),
    6.22 +     (SDL_Renderer_PresentDiscard | SDL_Renderer_PresentCopy),
    6.23       SDL_TextureBlendMode_None,
    6.24       SDL_TextureScaleMode_None,
    6.25       0,
    6.26 @@ -91,8 +84,6 @@
    6.27      }
    6.28      SDL_zerop(data);
    6.29  
    6.30 -    renderer->RenderReadPixels = SDL_DUMMY_RenderReadPixels;
    6.31 -    renderer->RenderWritePixels = SDL_DUMMY_RenderWritePixels;
    6.32      renderer->RenderPresent = SDL_DUMMY_RenderPresent;
    6.33      renderer->DestroyRenderer = SDL_DUMMY_DestroyRenderer;
    6.34      renderer->info = SDL_DUMMY_RenderDriver.info;
    6.35 @@ -111,54 +102,6 @@
    6.36      return renderer;
    6.37  }
    6.38  
    6.39 -int
    6.40 -SDL_DUMMY_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
    6.41 -                           void *pixels, int pitch)
    6.42 -{
    6.43 -    SDL_DUMMY_RenderData *data =
    6.44 -        (SDL_DUMMY_RenderData *) renderer->driverdata;
    6.45 -    SDL_Surface *surface = data->surface;
    6.46 -    Uint8 *src, *dst;
    6.47 -    int row;
    6.48 -    size_t length;
    6.49 -
    6.50 -    src =
    6.51 -        (Uint8 *) surface->pixels + rect->y * surface->pitch +
    6.52 -        rect->x * surface->format->BytesPerPixel;
    6.53 -    dst = (Uint8 *) pixels;
    6.54 -    length = rect->w * surface->format->BytesPerPixel;
    6.55 -    for (row = 0; row < rect->h; ++row) {
    6.56 -        SDL_memcpy(dst, src, length);
    6.57 -        src += surface->pitch;
    6.58 -        dst += pitch;
    6.59 -    }
    6.60 -    return 0;
    6.61 -}
    6.62 -
    6.63 -int
    6.64 -SDL_DUMMY_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect,
    6.65 -                            const void *pixels, int pitch)
    6.66 -{
    6.67 -    SDL_DUMMY_RenderData *data =
    6.68 -        (SDL_DUMMY_RenderData *) renderer->driverdata;
    6.69 -    SDL_Surface *surface = data->surface;
    6.70 -    Uint8 *src, *dst;
    6.71 -    int row;
    6.72 -    size_t length;
    6.73 -
    6.74 -    src = (Uint8 *) pixels;
    6.75 -    dst =
    6.76 -        (Uint8 *) surface->pixels + rect->y * surface->pitch +
    6.77 -        rect->x * surface->format->BytesPerPixel;
    6.78 -    length = rect->w * surface->format->BytesPerPixel;
    6.79 -    for (row = 0; row < rect->h; ++row) {
    6.80 -        SDL_memcpy(dst, src, length);
    6.81 -        src += pitch;
    6.82 -        dst += surface->pitch;
    6.83 -    }
    6.84 -    return 0;
    6.85 -}
    6.86 -
    6.87  void
    6.88  SDL_DUMMY_RenderPresent(SDL_Renderer * renderer)
    6.89  {
     7.1 --- a/src/video/win32/SDL_d3drender.c	Fri Jul 14 08:24:43 2006 +0000
     7.2 +++ b/src/video/win32/SDL_d3drender.c	Sat Jul 15 09:46:36 2006 +0000
     7.3 @@ -50,20 +50,12 @@
     7.4  static void SDL_D3D_DirtyTexture(SDL_Renderer * renderer,
     7.5                                   SDL_Texture * texture, int numrects,
     7.6                                   const SDL_Rect * rects);
     7.7 -static void SDL_D3D_SelectRenderTexture(SDL_Renderer * renderer,
     7.8 -                                        SDL_Texture * texture);
     7.9  static int SDL_D3D_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect,
    7.10                                Uint32 color);
    7.11  static int SDL_D3D_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
    7.12                                const SDL_Rect * srcrect,
    7.13                                const SDL_Rect * dstrect, int blendMode,
    7.14                                int scaleMode);
    7.15 -static int SDL_D3D_RenderReadPixels(SDL_Renderer * renderer,
    7.16 -                                    const SDL_Rect * rect, void *pixels,
    7.17 -                                    int pitch);
    7.18 -static int SDL_D3D_RenderWritePixels(SDL_Renderer * renderer,
    7.19 -                                     const SDL_Rect * rect,
    7.20 -                                     const void *pixels, int pitch);
    7.21  static void SDL_D3D_RenderPresent(SDL_Renderer * renderer);
    7.22  static void SDL_D3D_DestroyTexture(SDL_Renderer * renderer,
    7.23                                     SDL_Texture * texture);
    7.24 @@ -76,10 +68,9 @@
    7.25       "d3d",
    7.26       (SDL_Renderer_SingleBuffer | SDL_Renderer_PresentCopy |
    7.27        SDL_Renderer_PresentFlip2 | SDL_Renderer_PresentFlip3 |
    7.28 -      SDL_Renderer_PresentDiscard | SDL_Renderer_RenderTarget),
    7.29 -     (SDL_TextureBlendMode_None |
    7.30 -      SDL_TextureBlendMode_Mask | SDL_TextureBlendMode_Blend),
    7.31 -     (SDL_TextureScaleMode_None | SDL_TextureScaleMode_Fast),
    7.32 +      SDL_Renderer_PresentDiscard | SDL_Renderer_PresentVSync),
    7.33 +     (SDL_TextureBlendMode_None | SDL_TextureBlendMode_Mask | SDL_TextureBlendMode_Blend),      /* FIXME */
    7.34 +     (SDL_TextureScaleMode_None | SDL_TextureScaleMode_Fast),   /* FIXME */
    7.35       12,
    7.36       {
    7.37        SDL_PixelFormat_Index8,
    7.38 @@ -101,8 +92,6 @@
    7.39  typedef struct
    7.40  {
    7.41      IDirect3DDevice9 *device;
    7.42 -    IDirect3DSurface9 *surface;
    7.43 -    IDirect3DSurface9 *offscreen;
    7.44      SDL_bool beginScene;
    7.45  } SDL_D3D_RenderData;
    7.46  
    7.47 @@ -250,6 +239,7 @@
    7.48      SDL_D3D_RenderData *data;
    7.49      HRESULT result;
    7.50      D3DPRESENT_PARAMETERS pparams;
    7.51 +    IDirect3DSwapChain9 *chain;
    7.52  
    7.53      renderer = (SDL_Renderer *) SDL_malloc(sizeof(*renderer));
    7.54      if (!renderer) {
    7.55 @@ -273,11 +263,8 @@
    7.56      renderer->LockTexture = SDL_D3D_LockTexture;
    7.57      renderer->UnlockTexture = SDL_D3D_UnlockTexture;
    7.58      renderer->DirtyTexture = SDL_D3D_DirtyTexture;
    7.59 -    renderer->SelectRenderTexture = SDL_D3D_SelectRenderTexture;
    7.60      renderer->RenderFill = SDL_D3D_RenderFill;
    7.61      renderer->RenderCopy = SDL_D3D_RenderCopy;
    7.62 -    renderer->RenderReadPixels = SDL_D3D_RenderReadPixels;
    7.63 -    renderer->RenderWritePixels = SDL_D3D_RenderWritePixels;
    7.64      renderer->RenderPresent = SDL_D3D_RenderPresent;
    7.65      renderer->DestroyTexture = SDL_D3D_DestroyTexture;
    7.66      renderer->DestroyRenderer = SDL_D3D_DestroyRenderer;
    7.67 @@ -285,7 +272,7 @@
    7.68      renderer->window = window->id;
    7.69      renderer->driverdata = data;
    7.70  
    7.71 -    renderer->info.flags = SDL_Renderer_RenderTarget;
    7.72 +    renderer->info.flags = SDL_Renderer_Accelerated;
    7.73  
    7.74      SDL_zero(pparams);
    7.75      pparams.BackBufferWidth = window->w;
    7.76 @@ -317,7 +304,11 @@
    7.77          pparams.Windowed = TRUE;
    7.78          pparams.FullScreen_RefreshRateInHz = 0;
    7.79      }
    7.80 -    pparams.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
    7.81 +    if (flags & SDL_Renderer_PresentVSync) {
    7.82 +        pparams.PresentationInterval = D3DPRESENT_INTERVAL_ONE;
    7.83 +    } else {
    7.84 +        pparams.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
    7.85 +    }
    7.86  
    7.87      result = IDirect3D9_CreateDevice(videodata->d3d, D3DADAPTER_DEFAULT,        /* FIXME */
    7.88                                       D3DDEVTYPE_HAL,
    7.89 @@ -331,6 +322,43 @@
    7.90      }
    7.91      data->beginScene = SDL_TRUE;
    7.92  
    7.93 +    /* Get presentation parameters to fill info */
    7.94 +    result = IDirect3DDevice9_GetSwapChain(data->device, 0, &chain);
    7.95 +    if (FAILED(result)) {
    7.96 +        SDL_D3D_DestroyRenderer(renderer);
    7.97 +        D3D_SetError("GetSwapChain()", result);
    7.98 +        return NULL;
    7.99 +    }
   7.100 +    result = IDirect3DSwapChain9_GetPresentParameters(chain, &pparams);
   7.101 +    if (FAILED(result)) {
   7.102 +        IDirect3DSwapChain9_Release(chain);
   7.103 +        SDL_D3D_DestroyRenderer(renderer);
   7.104 +        D3D_SetError("GetPresentParameters()", result);
   7.105 +        return NULL;
   7.106 +    }
   7.107 +    IDirect3DSwapChain9_Release(chain);
   7.108 +    switch (pparams.SwapEffect) {
   7.109 +    case D3DSWAPEFFECT_COPY:
   7.110 +        renderer->info.flags |= SDL_Renderer_PresentCopy;
   7.111 +        break;
   7.112 +    case D3DSWAPEFFECT_FLIP:
   7.113 +        switch (pparams.BackBufferCount) {
   7.114 +        case 2:
   7.115 +            renderer->info.flags |= SDL_Renderer_PresentFlip2;
   7.116 +            break;
   7.117 +        case 3:
   7.118 +            renderer->info.flags |= SDL_Renderer_PresentFlip3;
   7.119 +            break;
   7.120 +        }
   7.121 +        break;
   7.122 +    case D3DSWAPEFFECT_DISCARD:
   7.123 +        renderer->info.flags |= SDL_Renderer_PresentDiscard;
   7.124 +        break;
   7.125 +    }
   7.126 +    if (pparams.PresentationInterval == D3DPRESENT_INTERVAL_ONE) {
   7.127 +        renderer->info.flags |= SDL_Renderer_PresentVSync;
   7.128 +    }
   7.129 +
   7.130      /* Set up parameters for rendering */
   7.131      IDirect3DDevice9_SetVertexShader(data->device, NULL);
   7.132      IDirect3DDevice9_SetFVF(data->device, D3DFVF_XYZRHW | D3DFVF_TEX1);
   7.133 @@ -527,14 +555,6 @@
   7.134      }
   7.135  }
   7.136  
   7.137 -static void
   7.138 -SDL_D3D_SelectRenderTexture(SDL_Renderer * renderer, SDL_Texture * texture)
   7.139 -{
   7.140 -    SDL_D3D_RenderData *data = (SDL_D3D_RenderData *) renderer->driverdata;
   7.141 -
   7.142 -    /* FIXME */
   7.143 -}
   7.144 -
   7.145  static int
   7.146  SDL_D3D_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect,
   7.147                     Uint32 color)
   7.148 @@ -637,93 +657,6 @@
   7.149      return 0;
   7.150  }
   7.151  
   7.152 -static int
   7.153 -SDL_D3D_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
   7.154 -                         void *pixels, int pitch)
   7.155 -{
   7.156 -    SDL_D3D_RenderData *data = (SDL_D3D_RenderData *) renderer->driverdata;
   7.157 -
   7.158 -    /* FIXME */
   7.159 -    return 0;
   7.160 -}
   7.161 -
   7.162 -static int
   7.163 -SDL_D3D_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect,
   7.164 -                          const void *pixels, int pitch)
   7.165 -{
   7.166 -    SDL_Window *window = SDL_GetWindowFromID(renderer->window);
   7.167 -    SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
   7.168 -    SDL_D3D_RenderData *data = (SDL_D3D_RenderData *) renderer->driverdata;
   7.169 -    RECT d3drect;
   7.170 -    POINT point;
   7.171 -    D3DLOCKED_RECT locked;
   7.172 -    const Uint8 *src;
   7.173 -    Uint8 *dst;
   7.174 -    int row, length;
   7.175 -    HRESULT result;
   7.176 -
   7.177 -    if (!data->surface) {
   7.178 -        result =
   7.179 -            IDirect3DDevice9_GetBackBuffer(data->device, 0, 0,
   7.180 -                                           D3DBACKBUFFER_TYPE_MONO,
   7.181 -                                           &data->surface);
   7.182 -        if (FAILED(result)) {
   7.183 -            D3D_SetError("GetBackBuffer()", result);
   7.184 -            return -1;
   7.185 -        }
   7.186 -    }
   7.187 -    if (!data->offscreen) {
   7.188 -        result =
   7.189 -            IDirect3DDevice9_CreateOffscreenPlainSurface(data->device,
   7.190 -                                                         window->w, window->h,
   7.191 -                                                         PixelFormatToD3DFMT
   7.192 -                                                         (display->
   7.193 -                                                          current_mode.
   7.194 -                                                          format),
   7.195 -                                                         D3DPOOL_SYSTEMMEM,
   7.196 -                                                         &data->offscreen,
   7.197 -                                                         NULL);
   7.198 -        if (FAILED(result)) {
   7.199 -            D3D_SetError("CreateOffscreenPlainSurface()", result);
   7.200 -            return -1;
   7.201 -        }
   7.202 -    }
   7.203 -
   7.204 -    d3drect.left = rect->x;
   7.205 -    d3drect.right = rect->x + rect->w;
   7.206 -    d3drect.top = rect->y;
   7.207 -    d3drect.bottom = rect->y + rect->h;
   7.208 -
   7.209 -    result =
   7.210 -        IDirect3DSurface9_LockRect(data->offscreen, &locked, &d3drect, 0);
   7.211 -    if (FAILED(result)) {
   7.212 -        D3D_SetError("LockRect()", result);
   7.213 -        return -1;
   7.214 -    }
   7.215 -
   7.216 -    src = pixels;
   7.217 -    dst = locked.pBits;
   7.218 -    length = rect->w * SDL_BYTESPERPIXEL(display->current_mode.format);
   7.219 -    for (row = 0; row < rect->h; ++row) {
   7.220 -        SDL_memcpy(dst, src, length);
   7.221 -        src += pitch;
   7.222 -        dst += locked.Pitch;
   7.223 -    }
   7.224 -    IDirect3DSurface9_UnlockRect(data->offscreen);
   7.225 -
   7.226 -    point.x = rect->x;
   7.227 -    point.y = rect->y;
   7.228 -    result =
   7.229 -        IDirect3DDevice9_UpdateSurface(data->device, data->offscreen,
   7.230 -                                       &d3drect, data->surface, &point);
   7.231 -    if (FAILED(result)) {
   7.232 -        D3D_SetError("UpdateSurface()", result);
   7.233 -        return -1;
   7.234 -    }
   7.235 -
   7.236 -    return 0;
   7.237 -}
   7.238 -
   7.239  static void
   7.240  SDL_D3D_RenderPresent(SDL_Renderer * renderer)
   7.241  {
   7.242 @@ -765,12 +698,6 @@
   7.243          if (data->device) {
   7.244              IDirect3DDevice9_Release(data->device);
   7.245          }
   7.246 -        if (data->surface) {
   7.247 -            IDirect3DSurface9_Release(data->surface);
   7.248 -        }
   7.249 -        if (data->offscreen) {
   7.250 -            IDirect3DSurface9_Release(data->offscreen);
   7.251 -        }
   7.252          SDL_free(data);
   7.253      }
   7.254      SDL_free(renderer);
     8.1 --- a/src/video/win32/SDL_gdirender.c	Fri Jul 14 08:24:43 2006 +0000
     8.2 +++ b/src/video/win32/SDL_gdirender.c	Sat Jul 15 09:46:36 2006 +0000
     8.3 @@ -55,20 +55,12 @@
     8.4  static void SDL_GDI_DirtyTexture(SDL_Renderer * renderer,
     8.5                                   SDL_Texture * texture, int numrects,
     8.6                                   const SDL_Rect * rects);
     8.7 -static void SDL_GDI_SelectRenderTexture(SDL_Renderer * renderer,
     8.8 -                                        SDL_Texture * texture);
     8.9  static int SDL_GDI_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect,
    8.10                                Uint32 color);
    8.11  static int SDL_GDI_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
    8.12                                const SDL_Rect * srcrect,
    8.13                                const SDL_Rect * dstrect, int blendMode,
    8.14                                int scaleMode);
    8.15 -static int SDL_GDI_RenderReadPixels(SDL_Renderer * renderer,
    8.16 -                                    const SDL_Rect * rect, void *pixels,
    8.17 -                                    int pitch);
    8.18 -static int SDL_GDI_RenderWritePixels(SDL_Renderer * renderer,
    8.19 -                                     const SDL_Rect * rect,
    8.20 -                                     const void *pixels, int pitch);
    8.21  static void SDL_GDI_RenderPresent(SDL_Renderer * renderer);
    8.22  static void SDL_GDI_DestroyTexture(SDL_Renderer * renderer,
    8.23                                     SDL_Texture * texture);
    8.24 @@ -81,7 +73,7 @@
    8.25       "gdi",
    8.26       (SDL_Renderer_SingleBuffer | SDL_Renderer_PresentCopy |
    8.27        SDL_Renderer_PresentFlip2 | SDL_Renderer_PresentFlip3 |
    8.28 -      SDL_Renderer_PresentDiscard | SDL_Renderer_RenderTarget),
    8.29 +      SDL_Renderer_PresentDiscard),
    8.30       (SDL_TextureBlendMode_None | SDL_TextureBlendMode_Mask |
    8.31        SDL_TextureBlendMode_Blend),
    8.32       (SDL_TextureScaleMode_None | SDL_TextureScaleMode_Fast),
    8.33 @@ -114,9 +106,6 @@
    8.34      int current_hbm;
    8.35      SDL_DirtyRectList dirty;
    8.36      SDL_bool makedirty;
    8.37 -    HBITMAP window_dib;
    8.38 -    void *window_pixels;
    8.39 -    int window_pitch;
    8.40  } SDL_GDI_RenderData;
    8.41  
    8.42  typedef struct
    8.43 @@ -182,11 +171,8 @@
    8.44      renderer->LockTexture = SDL_GDI_LockTexture;
    8.45      renderer->UnlockTexture = SDL_GDI_UnlockTexture;
    8.46      renderer->DirtyTexture = SDL_GDI_DirtyTexture;
    8.47 -    renderer->SelectRenderTexture = SDL_GDI_SelectRenderTexture;
    8.48      renderer->RenderFill = SDL_GDI_RenderFill;
    8.49      renderer->RenderCopy = SDL_GDI_RenderCopy;
    8.50 -    renderer->RenderReadPixels = SDL_GDI_RenderReadPixels;
    8.51 -    renderer->RenderWritePixels = SDL_GDI_RenderWritePixels;
    8.52      renderer->RenderPresent = SDL_GDI_RenderPresent;
    8.53      renderer->DestroyTexture = SDL_GDI_DestroyTexture;
    8.54      renderer->DestroyRenderer = SDL_GDI_DestroyRenderer;
    8.55 @@ -194,7 +180,7 @@
    8.56      renderer->window = window->id;
    8.57      renderer->driverdata = data;
    8.58  
    8.59 -    renderer->info.flags = SDL_Renderer_RenderTarget;
    8.60 +    renderer->info.flags = SDL_Renderer_Accelerated;
    8.61  
    8.62      data->hwnd = windowdata->hwnd;
    8.63      data->window_hdc = GetDC(data->hwnd);
    8.64 @@ -218,7 +204,8 @@
    8.65      DeleteObject(hbm);
    8.66  
    8.67      if (flags & SDL_Renderer_SingleBuffer) {
    8.68 -        renderer->info.flags |= SDL_Renderer_SingleBuffer;
    8.69 +        renderer->info.flags |=
    8.70 +            (SDL_Renderer_SingleBuffer | SDL_Renderer_PresentCopy);
    8.71          n = 0;
    8.72      } else if (flags & SDL_Renderer_PresentFlip2) {
    8.73          renderer->info.flags |= SDL_Renderer_PresentFlip2;
    8.74 @@ -271,10 +258,6 @@
    8.75      texture->driverdata = data;
    8.76  
    8.77      if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
    8.78 -        if (texture->access == SDL_TextureAccess_Render) {
    8.79 -            SDL_SetError("Rendering to YUV format textures is not supported");
    8.80 -            return -1;
    8.81 -        }
    8.82          data->yuv = SDL_SW_CreateYUVTexture(texture);
    8.83          if (!data->yuv) {
    8.84              SDL_GDI_DestroyTexture(renderer, texture);
    8.85 @@ -521,31 +504,6 @@
    8.86  {
    8.87  }
    8.88  
    8.89 -static void
    8.90 -SDL_GDI_SelectRenderTexture(SDL_Renderer * renderer, SDL_Texture * texture)
    8.91 -{
    8.92 -    SDL_GDI_RenderData *data = (SDL_GDI_RenderData *) renderer->driverdata;
    8.93 -
    8.94 -    if (texture) {
    8.95 -        SDL_GDI_TextureData *texturedata =
    8.96 -            (SDL_GDI_TextureData *) texture->driverdata;
    8.97 -        SelectObject(data->render_hdc, texturedata->hbm);
    8.98 -        if (texturedata->hpal) {
    8.99 -            SelectPalette(data->render_hdc, texturedata->hpal, TRUE);
   8.100 -            RealizePalette(data->render_hdc);
   8.101 -        }
   8.102 -        data->current_hdc = data->render_hdc;
   8.103 -        data->makedirty = SDL_FALSE;
   8.104 -    } else if (renderer->info.flags & SDL_Renderer_SingleBuffer) {
   8.105 -        data->current_hdc = data->window_hdc;
   8.106 -        data->makedirty = SDL_FALSE;
   8.107 -    } else {
   8.108 -        SelectObject(data->render_hdc, data->hbm[data->current_hbm]);
   8.109 -        data->current_hdc = data->render_hdc;
   8.110 -        data->makedirty = SDL_TRUE;
   8.111 -    }
   8.112 -}
   8.113 -
   8.114  static int
   8.115  SDL_GDI_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect,
   8.116                     Uint32 color)
   8.117 @@ -637,98 +595,6 @@
   8.118      return 0;
   8.119  }
   8.120  
   8.121 -static int
   8.122 -CreateWindowDIB(SDL_GDI_RenderData * data, SDL_Window * window)
   8.123 -{
   8.124 -    data->window_pitch = window->w * (data->bmi->bmiHeader.biBitCount / 8);
   8.125 -    data->bmi->bmiHeader.biWidth = window->w;
   8.126 -    data->bmi->bmiHeader.biHeight = -window->h;
   8.127 -    data->bmi->bmiHeader.biSizeImage =
   8.128 -        window->h * (data->bmi->bmiHeader.biBitCount / 8);
   8.129 -    data->window_dib =
   8.130 -        CreateDIBSection(data->window_hdc, data->bmi, DIB_RGB_COLORS,
   8.131 -                         &data->window_pixels, NULL, 0);
   8.132 -    if (!data->window_dib) {
   8.133 -        WIN_SetError("CreateDIBSection()");
   8.134 -        return -1;
   8.135 -    }
   8.136 -    return 0;
   8.137 -}
   8.138 -
   8.139 -static int
   8.140 -SDL_GDI_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
   8.141 -                         void *pixels, int pitch)
   8.142 -{
   8.143 -    SDL_Window *window = SDL_GetWindowFromID(renderer->window);
   8.144 -    SDL_GDI_RenderData *data = (SDL_GDI_RenderData *) renderer->driverdata;
   8.145 -
   8.146 -    if (!data->window_dib) {
   8.147 -        if (CreateWindowDIB(data, window) < 0) {
   8.148 -            return -1;
   8.149 -        }
   8.150 -    }
   8.151 -
   8.152 -    SelectObject(data->memory_hdc, data->window_dib);
   8.153 -    BitBlt(data->memory_hdc, rect->x, rect->y, rect->w, rect->h,
   8.154 -           data->current_hdc, rect->x, rect->y, SRCCOPY);
   8.155 -
   8.156 -    {
   8.157 -        int bpp = data->bmi->bmiHeader.biBitCount / 8;
   8.158 -        Uint8 *src =
   8.159 -            (Uint8 *) data->window_pixels + rect->y * data->window_pitch +
   8.160 -            rect->x * bpp;
   8.161 -        Uint8 *dst = (Uint8 *) pixels;
   8.162 -        int row;
   8.163 -
   8.164 -        for (row = 0; row < rect->h; ++row) {
   8.165 -            SDL_memcpy(dst, src, rect->w * bpp);
   8.166 -            src += data->window_pitch;
   8.167 -            dst += pitch;
   8.168 -        }
   8.169 -    }
   8.170 -
   8.171 -    return 0;
   8.172 -}
   8.173 -
   8.174 -static int
   8.175 -SDL_GDI_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect,
   8.176 -                          const void *pixels, int pitch)
   8.177 -{
   8.178 -    SDL_Window *window = SDL_GetWindowFromID(renderer->window);
   8.179 -    SDL_GDI_RenderData *data = (SDL_GDI_RenderData *) renderer->driverdata;
   8.180 -
   8.181 -    if (data->makedirty) {
   8.182 -        SDL_AddDirtyRect(&data->dirty, rect);
   8.183 -    }
   8.184 -
   8.185 -    if (!data->window_dib) {
   8.186 -        if (CreateWindowDIB(data, window) < 0) {
   8.187 -            return -1;
   8.188 -        }
   8.189 -    }
   8.190 -
   8.191 -    {
   8.192 -        int bpp = data->bmi->bmiHeader.biBitCount / 8;
   8.193 -        Uint8 *src = (Uint8 *) pixels;
   8.194 -        Uint8 *dst =
   8.195 -            (Uint8 *) data->window_pixels + rect->y * data->window_pitch +
   8.196 -            rect->x * bpp;
   8.197 -        int row;
   8.198 -
   8.199 -        for (row = 0; row < rect->h; ++row) {
   8.200 -            SDL_memcpy(dst, src, rect->w * bpp);
   8.201 -            src += pitch;
   8.202 -            dst += data->window_pitch;
   8.203 -        }
   8.204 -    }
   8.205 -
   8.206 -    SelectObject(data->memory_hdc, data->window_dib);
   8.207 -    BitBlt(data->current_hdc, rect->x, rect->y, rect->w, rect->h,
   8.208 -           data->memory_hdc, rect->x, rect->y, SRCCOPY);
   8.209 -
   8.210 -    return 0;
   8.211 -}
   8.212 -
   8.213  static void
   8.214  SDL_GDI_RenderPresent(SDL_Renderer * renderer)
   8.215  {
   8.216 @@ -795,9 +661,6 @@
   8.217              }
   8.218          }
   8.219          SDL_FreeDirtyRects(&data->dirty);
   8.220 -        if (data->window_dib) {
   8.221 -            DeleteObject(data->window_dib);
   8.222 -        }
   8.223          SDL_free(data);
   8.224      }
   8.225      SDL_free(renderer);
     9.1 --- a/test/testsprite.c	Fri Jul 14 08:24:43 2006 +0000
     9.2 +++ b/test/testsprite.c	Sat Jul 15 09:46:36 2006 +0000
     9.3 @@ -1,6 +1,7 @@
     9.4  /* Simple program:  Move N sprites around on the screen as fast as possible */
     9.5  
     9.6  #include <stdlib.h>
     9.7 +#include <stdio.h>
     9.8  #include <time.h>
     9.9  
    9.10  #include "SDL.h"
    10.1 --- a/test/testsprite2.c	Fri Jul 14 08:24:43 2006 +0000
    10.2 +++ b/test/testsprite2.c	Sat Jul 15 09:46:36 2006 +0000
    10.3 @@ -1,6 +1,7 @@
    10.4  /* Simple program:  Move N sprites around on the screen as fast as possible */
    10.5  
    10.6  #include <stdlib.h>
    10.7 +#include <stdio.h>
    10.8  #include <time.h>
    10.9  
   10.10  #include "SDL.h"
   10.11 @@ -126,6 +127,7 @@
   10.12  {
   10.13      int window_w, window_h;
   10.14      Uint32 window_flags = SDL_WINDOW_SHOWN;
   10.15 +    Uint32 render_flags = 0;
   10.16      SDL_DisplayMode *mode, fullscreen_mode;
   10.17      int i, done;
   10.18      SDL_Event event;
   10.19 @@ -152,11 +154,13 @@
   10.20          } else if (strcmp(argv[i], "-fullscreen") == 0) {
   10.21              num_windows = 1;
   10.22              window_flags |= SDL_WINDOW_FULLSCREEN;
   10.23 +        } else if (strcmp(argv[i], "-sync") == 0) {
   10.24 +            render_flags |= SDL_Renderer_PresentVSync;
   10.25          } else if (isdigit(argv[i][0])) {
   10.26              num_sprites = atoi(argv[i]);
   10.27          } else {
   10.28              fprintf(stderr,
   10.29 -                    "Usage: %s [-width N] [-height N] [-windows N] [-fullscreen] [numsprites]\n",
   10.30 +                    "Usage: %s [-width N] [-height N] [-windows N] [-fullscreen] [-sync] [numsprites]\n",
   10.31                      argv[0]);
   10.32              quit(1);
   10.33          }
   10.34 @@ -189,7 +193,7 @@
   10.35              quit(2);
   10.36          }
   10.37  
   10.38 -        if (SDL_CreateRenderer(windows[i], -1, 0) < 0) {
   10.39 +        if (SDL_CreateRenderer(windows[i], -1, render_flags) < 0) {
   10.40              fprintf(stderr, "Couldn't create renderer: %s\n", SDL_GetError());
   10.41              quit(2);
   10.42          }