Adding software renderer implementation SDL-1.3
authorSam Lantinga <slouken@libsdl.org>
Mon, 12 Jun 2006 09:10:06 +0000
branchSDL-1.3
changeset 1676e136f3ffdc1b
parent 1675 d33dcfc3fde7
child 1677 5e4c5e095925
Adding software renderer implementation
include/SDL_pixels.h
include/SDL_video.h
src/video/SDL_renderer_sw.c
src/video/SDL_renderer_sw.h
src/video/SDL_sysvideo.h
src/video/SDL_video.c
src/video/dummy/SDL_nullevents.c
src/video/dummy/SDL_nullevents_c.h
src/video/dummy/SDL_nullvideo.c
     1.1 --- a/include/SDL_pixels.h	Sun Jun 11 07:30:16 2006 +0000
     1.2 +++ b/include/SDL_pixels.h	Mon Jun 12 09:10:06 2006 +0000
     1.3 @@ -108,6 +108,8 @@
     1.4  #define SDL_BITSPERPIXEL(X)	(((X) >> 8) & 0xFF)
     1.5  #define SDL_BYTESPERPIXEL(X)	(((X) >> 0) & 0xFF)
     1.6  
     1.7 +#define SDL_ISPIXELFORMAT_FOURCC(format)    (((format) & 0x8000000) != 0)
     1.8 +
     1.9  enum
    1.10  {
    1.11      SDL_PixelFormat_Unknown,
     2.1 --- a/include/SDL_video.h	Sun Jun 11 07:30:16 2006 +0000
     2.2 +++ b/include/SDL_video.h	Mon Jun 12 09:10:06 2006 +0000
     2.3 @@ -201,11 +201,11 @@
     2.4   */
     2.5  typedef enum
     2.6  {
     2.7 -    SDL_TextureBlendMode_None,  /**< No blending */
     2.8 -    SDL_TextureBlendMode_Mask,  /**< dst = A ? src : dst (alpha is mask) */
     2.9 -    SDL_TextureBlendMode_Blend, /**< dst = (src * A) + (dst * (1-A)) */
    2.10 -    SDL_TextureBlendMode_Add,   /**< dst = (src * A) + dst */
    2.11 -    SDL_TextureBlendMode_Mod,   /**< dst = src * dst */
    2.12 +    SDL_TextureBlendMode_None = 0x00000000,     /**< No blending */
    2.13 +    SDL_TextureBlendMode_Mask = 0x00000001,     /**< dst = A ? src : dst (alpha is mask) */
    2.14 +    SDL_TextureBlendMode_Blend = 0x00000002,    /**< dst = (src * A) + (dst * (1-A)) */
    2.15 +    SDL_TextureBlendMode_Add = 0x00000004,      /**< dst = (src * A) + dst */
    2.16 +    SDL_TextureBlendMode_Mod = 0x00000008,      /**< dst = src * dst */
    2.17  } SDL_TextureBlendMode;
    2.18  
    2.19  /**
    2.20 @@ -215,10 +215,10 @@
    2.21   */
    2.22  typedef enum
    2.23  {
    2.24 -    SDL_TextureScaleMode_None,  /**< No scaling, rectangles must match dimensions */
    2.25 -    SDL_TextureScaleMode_Fast,  /**< Point sampling or equivalent algorithm */
    2.26 -    SDL_TextureScaleMode_Slow,  /**< Linear filtering or equivalent algorithm */
    2.27 -    SDL_TextureScaleMode_Best,  /**< Bicubic filtering or equivalent algorithm */
    2.28 +    SDL_TextureScaleMode_None = 0x00000000,     /**< No scaling, rectangles must match dimensions */
    2.29 +    SDL_TextureScaleMode_Fast = 0x00000001,     /**< Point sampling or equivalent algorithm */
    2.30 +    SDL_TextureScaleMode_Slow = 0x00000002,     /**< Linear filtering or equivalent algorithm */
    2.31 +    SDL_TextureScaleMode_Best = 0x00000004,     /**< Bicubic filtering or equivalent algorithm */
    2.32  } SDL_TextureScaleMode;
    2.33  
    2.34  /**
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/src/video/SDL_renderer_sw.c	Mon Jun 12 09:10:06 2006 +0000
     3.3 @@ -0,0 +1,409 @@
     3.4 +/*
     3.5 +    SDL - Simple DirectMedia Layer
     3.6 +    Copyright (C) 1997-2006 Sam Lantinga
     3.7 +
     3.8 +    This library is free software; you can redistribute it and/or
     3.9 +    modify it under the terms of the GNU Lesser General Public
    3.10 +    License as published by the Free Software Foundation; either
    3.11 +    version 2.1 of the License, or (at your option) any later version.
    3.12 +
    3.13 +    This library is distributed in the hope that it will be useful,
    3.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    3.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    3.16 +    Lesser General Public License for more details.
    3.17 +
    3.18 +    You should have received a copy of the GNU Lesser General Public
    3.19 +    License along with this library; if not, write to the Free Software
    3.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    3.21 +
    3.22 +    Sam Lantinga
    3.23 +    slouken@libsdl.org
    3.24 +*/
    3.25 +#include "SDL_config.h"
    3.26 +
    3.27 +#include "SDL_video.h"
    3.28 +#include "SDL_sysvideo.h"
    3.29 +
    3.30 +
    3.31 +/* SDL surface based renderer implementation */
    3.32 +
    3.33 +static SDL_Renderer *SDL_SW_CreateRenderer(SDL_Window * window, Uint32 flags);
    3.34 +static int SDL_SW_CreateTexture(SDL_Renderer * renderer,
    3.35 +                                SDL_Texture * texture);
    3.36 +static int SDL_SW_UpdateTexture(SDL_Renderer * renderer,
    3.37 +                                SDL_Texture * texture, SDL_Rect * rect,
    3.38 +                                const void *pixels, int pitch);
    3.39 +static int SDL_SW_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
    3.40 +                              SDL_Rect * rect, int markDirty, void **pixels,
    3.41 +                              int *pitch);
    3.42 +static void SDL_SW_UnlockTexture(SDL_Renderer * renderer,
    3.43 +                                 SDL_Texture * texture);
    3.44 +static void SDL_SW_DirtyTexture(SDL_Renderer * renderer,
    3.45 +                                SDL_Texture * texture, int numrects,
    3.46 +                                SDL_Rect * rects);
    3.47 +static void SDL_SW_SelectRenderTexture(SDL_Renderer * renderer,
    3.48 +                                       SDL_Texture * texture);
    3.49 +static void SDL_SW_RenderFill(SDL_Renderer * renderer, SDL_Rect * rect,
    3.50 +                              Uint32 color);
    3.51 +static int SDL_SW_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
    3.52 +                             SDL_Rect * srcrect, SDL_Rect * dstrect,
    3.53 +                             int blendMode, int scaleMode);
    3.54 +static int SDL_SW_RenderReadPixels(SDL_Renderer * renderer, SDL_Rect * rect,
    3.55 +                                   void *pixels, int pitch);
    3.56 +static int SDL_SW_RenderWritePixels(SDL_Renderer * renderer, SDL_Rect * rect,
    3.57 +                                    const void *pixels, int pitch);
    3.58 +static void SDL_SW_RenderPresent(SDL_Renderer * renderer);
    3.59 +static void SDL_SW_DestroyTexture(SDL_Renderer * renderer,
    3.60 +                                  SDL_Texture * texture);
    3.61 +static void SDL_SW_DestroyRenderer(SDL_Renderer * renderer);
    3.62 +
    3.63 +
    3.64 +SDL_RenderDriver SDL_SW_RenderDriver = {
    3.65 +    SDL_SW_CreateRenderer,
    3.66 +    {
    3.67 +     "software",
    3.68 +     (SDL_Renderer_PresentDiscard |
    3.69 +      SDL_Renderer_PresentCopy |
    3.70 +      SDL_Renderer_PresentFlip2 |
    3.71 +      SDL_Renderer_PresentFlip3 | SDL_Renderer_RenderTarget),
    3.72 +     (SDL_TextureBlendMode_None |
    3.73 +      SDL_TextureBlendMode_Mask | SDL_TextureBlendMode_Blend),
    3.74 +     (SDL_TextureScaleMode_None | SDL_TextureScaleMode_Fast),
    3.75 +     11,
    3.76 +     {
    3.77 +      SDL_PixelFormat_Index8,
    3.78 +      SDL_PixelFormat_RGB555,
    3.79 +      SDL_PixelFormat_RGB565,
    3.80 +      SDL_PixelFormat_RGB888,
    3.81 +      SDL_PixelFormat_BGR888,
    3.82 +      SDL_PixelFormat_ARGB8888,
    3.83 +      SDL_PixelFormat_RGBA8888,
    3.84 +      SDL_PixelFormat_ABGR8888,
    3.85 +      SDL_PixelFormat_BGRA8888,
    3.86 +      SDL_PixelFormat_YUY2,
    3.87 +      SDL_PixelFormat_UYVY},
    3.88 +     32768,
    3.89 +     32768}
    3.90 +};
    3.91 +
    3.92 +typedef struct
    3.93 +{
    3.94 +    int current_screen;
    3.95 +    SDL_Surface *screens[3];
    3.96 +    SDL_Surface *target;
    3.97 +    SDL_Renderer *renderer;
    3.98 +} SDL_SW_RenderData;
    3.99 +
   3.100 +SDL_Renderer *
   3.101 +SDL_SW_CreateRenderer(SDL_Window * window, Uint32 flags)
   3.102 +{
   3.103 +    SDL_DisplayMode *displayMode = &window->display->current_mode;
   3.104 +    SDL_Renderer *renderer;
   3.105 +    SDL_SW_RenderData *data;
   3.106 +    int i, n;
   3.107 +    int bpp;
   3.108 +    Uint32 Rmask, Gmask, Bmask, Amask;
   3.109 +
   3.110 +    if (!SDL_PixelFormatEnumToMasks
   3.111 +        (displayMode->format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) {
   3.112 +        SDL_SetError("Unknown display format");
   3.113 +        return NULL;
   3.114 +    }
   3.115 +
   3.116 +    renderer = (SDL_Renderer *) SDL_malloc(sizeof(*renderer));
   3.117 +    if (!renderer) {
   3.118 +        SDL_OutOfMemory();
   3.119 +        return NULL;
   3.120 +    }
   3.121 +    SDL_zerop(renderer);
   3.122 +
   3.123 +    data = (SDL_SW_RenderData *) SDL_malloc(sizeof(*data));
   3.124 +    if (!data) {
   3.125 +        SDL_SW_DestroyRenderer(renderer);
   3.126 +        SDL_OutOfMemory();
   3.127 +        return NULL;
   3.128 +    }
   3.129 +    SDL_zerop(data);
   3.130 +
   3.131 +    renderer->CreateTexture = SDL_SW_CreateTexture;
   3.132 +    renderer->UpdateTexture = SDL_SW_UpdateTexture;
   3.133 +    renderer->LockTexture = SDL_SW_LockTexture;
   3.134 +    renderer->UnlockTexture = SDL_SW_UnlockTexture;
   3.135 +    renderer->DirtyTexture = SDL_SW_DirtyTexture;
   3.136 +    renderer->SelectRenderTexture = SDL_SW_SelectRenderTexture;
   3.137 +    renderer->RenderFill = SDL_SW_RenderFill;
   3.138 +    renderer->RenderCopy = SDL_SW_RenderCopy;
   3.139 +    renderer->RenderReadPixels = SDL_SW_RenderReadPixels;
   3.140 +    renderer->RenderWritePixels = SDL_SW_RenderWritePixels;
   3.141 +    renderer->RenderPresent = SDL_SW_RenderPresent;
   3.142 +    renderer->DestroyTexture = SDL_SW_DestroyTexture;
   3.143 +    renderer->DestroyRenderer = SDL_SW_DestroyRenderer;
   3.144 +    renderer->info = SDL_SW_RenderDriver.info;
   3.145 +    renderer->window = window;
   3.146 +    renderer->driverdata = data;
   3.147 +
   3.148 +    renderer->info.flags = SDL_Renderer_RenderTarget;
   3.149 +
   3.150 +    if (flags & SDL_Renderer_PresentFlip2) {
   3.151 +        renderer->info.flags |= SDL_Renderer_PresentFlip2;
   3.152 +        n = 2;
   3.153 +    } else if (flags & SDL_Renderer_PresentFlip3) {
   3.154 +        renderer->info.flags |= SDL_Renderer_PresentFlip3;
   3.155 +        n = 3;
   3.156 +    } else {
   3.157 +        renderer->info.flags |= SDL_Renderer_PresentCopy;
   3.158 +        n = 1;
   3.159 +    }
   3.160 +    for (i = 0; i < n; ++i) {
   3.161 +        data->screens[i] =
   3.162 +            SDL_CreateRGBSurface(0, window->w, window->h, bpp, Rmask, Gmask,
   3.163 +                                 Bmask, Amask);
   3.164 +        if (!data->screens[i]) {
   3.165 +            SDL_SW_DestroyRenderer(renderer);
   3.166 +            return NULL;
   3.167 +        }
   3.168 +    }
   3.169 +    data->current_screen = 0;
   3.170 +    data->target = data->screens[0];
   3.171 +
   3.172 +    /* Find a render driver that we can use to display data */
   3.173 +    for (i = 0; i < window->display->num_render_drivers; ++i) {
   3.174 +        SDL_RenderDriver *driver = &window->display->render_drivers[i];
   3.175 +        if (driver->info.name != SDL_SW_RenderDriver.info.name) {
   3.176 +            data->renderer =
   3.177 +                driver->CreateRenderer(window, SDL_Renderer_PresentDiscard);
   3.178 +            if (data->renderer) {
   3.179 +                break;
   3.180 +            }
   3.181 +        }
   3.182 +    }
   3.183 +    if (i == window->display->num_render_drivers) {
   3.184 +        SDL_SW_DestroyRenderer(renderer);
   3.185 +        SDL_SetError("Couldn't find display render driver");
   3.186 +        return NULL;
   3.187 +    }
   3.188 +    return renderer;
   3.189 +}
   3.190 +
   3.191 +int
   3.192 +SDL_SW_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
   3.193 +{
   3.194 +    SDL_Surface *surface;
   3.195 +    int bpp;
   3.196 +    Uint32 Rmask, Gmask, Bmask, Amask;
   3.197 +
   3.198 +    if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
   3.199 +        /* FIXME: implement this */
   3.200 +        return -1;
   3.201 +    }
   3.202 +
   3.203 +    if (!SDL_PixelFormatEnumToMasks
   3.204 +        (texture->format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) {
   3.205 +        SDL_SetError("Unknown texture format");
   3.206 +        return -1;
   3.207 +    }
   3.208 +
   3.209 +    surface =
   3.210 +        SDL_CreateRGBSurface(0, texture->w, texture->h, bpp, Rmask, Gmask,
   3.211 +                             Bmask, Amask);
   3.212 +    if (!surface) {
   3.213 +        return -1;
   3.214 +    }
   3.215 +
   3.216 +    texture->driverdata = surface;
   3.217 +    return 0;
   3.218 +}
   3.219 +
   3.220 +int
   3.221 +SDL_SW_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
   3.222 +                     SDL_Rect * rect, const void *pixels, int pitch)
   3.223 +{
   3.224 +    SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
   3.225 +    Uint8 *src, *dst;
   3.226 +    int row;
   3.227 +    size_t length;
   3.228 +
   3.229 +    src = (Uint8 *) pixels;
   3.230 +    dst =
   3.231 +        (Uint8 *) surface->pixels + rect->y * surface->pitch +
   3.232 +        rect->x * surface->format->BytesPerPixel;
   3.233 +    length = rect->w * surface->format->BytesPerPixel;
   3.234 +    for (row = 0; row < rect->h; ++row) {
   3.235 +        SDL_memcpy(dst, src, length);
   3.236 +        src += pitch;
   3.237 +        dst += surface->pitch;
   3.238 +    }
   3.239 +    return 0;
   3.240 +}
   3.241 +
   3.242 +int
   3.243 +SDL_SW_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
   3.244 +                   SDL_Rect * rect, int markDirty, void **pixels, int *pitch)
   3.245 +{
   3.246 +    SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
   3.247 +
   3.248 +    *pixels =
   3.249 +        (void *) ((Uint8 *) surface->pixels + rect->y * surface->pitch +
   3.250 +                  rect->x * surface->format->BytesPerPixel);
   3.251 +    *pitch = surface->pitch;
   3.252 +    return 0;
   3.253 +}
   3.254 +
   3.255 +void
   3.256 +SDL_SW_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
   3.257 +{
   3.258 +}
   3.259 +
   3.260 +void
   3.261 +SDL_SW_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture,
   3.262 +                    int numrects, SDL_Rect * rects)
   3.263 +{
   3.264 +}
   3.265 +
   3.266 +void
   3.267 +SDL_SW_SelectRenderTexture(SDL_Renderer * renderer, SDL_Texture * texture)
   3.268 +{
   3.269 +    SDL_SW_RenderData *data = (SDL_SW_RenderData *) renderer->driverdata;
   3.270 +    data->target = (SDL_Surface *) texture->driverdata;
   3.271 +}
   3.272 +
   3.273 +void
   3.274 +SDL_SW_RenderFill(SDL_Renderer * renderer, SDL_Rect * rect, Uint32 color)
   3.275 +{
   3.276 +    SDL_SW_RenderData *data = (SDL_SW_RenderData *) renderer->driverdata;
   3.277 +    Uint8 r, g, b, a;
   3.278 +
   3.279 +    a = (Uint8) ((color >> 24) & 0xFF);
   3.280 +    r = (Uint8) ((color >> 16) & 0xFF);
   3.281 +    g = (Uint8) ((color >> 8) & 0xFF);
   3.282 +    b = (Uint8) (color & 0xFF);
   3.283 +    color = SDL_MapRGBA(data->target->format, r, g, b, a);
   3.284 +
   3.285 +    SDL_FillRect(data->target, rect, color);
   3.286 +}
   3.287 +
   3.288 +int
   3.289 +SDL_SW_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
   3.290 +                  SDL_Rect * srcrect, SDL_Rect * dstrect, int blendMode,
   3.291 +                  int scaleMode)
   3.292 +{
   3.293 +    SDL_SW_RenderData *data = (SDL_SW_RenderData *) renderer->driverdata;
   3.294 +    SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
   3.295 +
   3.296 +    if (blendMode & (SDL_TextureBlendMode_Mask | SDL_TextureBlendMode_Blend)) {
   3.297 +        SDL_SetAlpha(surface, SDL_SRCALPHA, 0);
   3.298 +    } else {
   3.299 +        SDL_SetAlpha(surface, 0, 0);
   3.300 +    }
   3.301 +    if (scaleMode != SDL_TextureScaleMode_None &&
   3.302 +        (srcrect->w != dstrect->w || srcrect->h != dstrect->h)) {
   3.303 +        return SDL_SoftStretch(surface, srcrect, data->target, dstrect);
   3.304 +    } else {
   3.305 +        return SDL_LowerBlit(surface, srcrect, data->target, dstrect);
   3.306 +    }
   3.307 +}
   3.308 +
   3.309 +int
   3.310 +SDL_SW_RenderReadPixels(SDL_Renderer * renderer, SDL_Rect * rect,
   3.311 +                        void *pixels, int pitch)
   3.312 +{
   3.313 +    SDL_SW_RenderData *data = (SDL_SW_RenderData *) renderer->driverdata;
   3.314 +    SDL_Surface *surface = data->target;
   3.315 +    Uint8 *src, *dst;
   3.316 +    int row;
   3.317 +    size_t length;
   3.318 +
   3.319 +    src =
   3.320 +        (Uint8 *) surface->pixels + rect->y * surface->pitch +
   3.321 +        rect->x * surface->format->BytesPerPixel;
   3.322 +    dst = (Uint8 *) pixels;
   3.323 +    length = rect->w * surface->format->BytesPerPixel;
   3.324 +    for (row = 0; row < rect->h; ++row) {
   3.325 +        SDL_memcpy(dst, src, length);
   3.326 +        src += surface->pitch;
   3.327 +        dst += pitch;
   3.328 +    }
   3.329 +    return 0;
   3.330 +}
   3.331 +
   3.332 +int
   3.333 +SDL_SW_RenderWritePixels(SDL_Renderer * renderer, SDL_Rect * rect,
   3.334 +                         const void *pixels, int pitch)
   3.335 +{
   3.336 +    SDL_SW_RenderData *data = (SDL_SW_RenderData *) renderer->driverdata;
   3.337 +    SDL_Surface *surface = data->target;
   3.338 +    Uint8 *src, *dst;
   3.339 +    int row;
   3.340 +    size_t length;
   3.341 +
   3.342 +    src = (Uint8 *) pixels;
   3.343 +    dst =
   3.344 +        (Uint8 *) surface->pixels + rect->y * surface->pitch +
   3.345 +        rect->x * surface->format->BytesPerPixel;
   3.346 +    length = rect->w * surface->format->BytesPerPixel;
   3.347 +    for (row = 0; row < rect->h; ++row) {
   3.348 +        SDL_memcpy(dst, src, length);
   3.349 +        src += pitch;
   3.350 +        dst += surface->pitch;
   3.351 +    }
   3.352 +    return 0;
   3.353 +}
   3.354 +
   3.355 +void
   3.356 +SDL_SW_RenderPresent(SDL_Renderer * renderer)
   3.357 +{
   3.358 +    SDL_SW_RenderData *data = (SDL_SW_RenderData *) renderer->driverdata;
   3.359 +    SDL_Surface *surface = data->screens[data->current_screen];
   3.360 +    SDL_Rect rect;
   3.361 +    int new_screen;
   3.362 +
   3.363 +    /* Send the data to the display */
   3.364 +    /* FIXME: implement dirty rect updates */
   3.365 +    rect.x = 0;
   3.366 +    rect.y = 0;
   3.367 +    rect.w = surface->w;
   3.368 +    rect.h = surface->h;
   3.369 +    data->renderer->RenderWritePixels(data->renderer, &rect, surface->pixels,
   3.370 +                                      surface->pitch);
   3.371 +    data->renderer->RenderPresent(data->renderer);
   3.372 +
   3.373 +    /* Update the flipping chain, if any */
   3.374 +    if (renderer->info.flags & SDL_Renderer_PresentFlip2) {
   3.375 +        new_screen = (data->current_screen + 1) % 2;
   3.376 +    } else if (renderer->info.flags & SDL_Renderer_PresentFlip3) {
   3.377 +        new_screen = (data->current_screen + 1) % 3;
   3.378 +    } else {
   3.379 +        new_screen = 0;
   3.380 +    }
   3.381 +    if (data->target == data->screens[data->current_screen]) {
   3.382 +        data->target = data->screens[new_screen];
   3.383 +    }
   3.384 +    data->current_screen = new_screen;
   3.385 +}
   3.386 +
   3.387 +void
   3.388 +SDL_SW_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
   3.389 +{
   3.390 +    SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
   3.391 +
   3.392 +    SDL_FreeSurface(surface);
   3.393 +}
   3.394 +
   3.395 +void
   3.396 +SDL_SW_DestroyRenderer(SDL_Renderer * renderer)
   3.397 +{
   3.398 +    SDL_SW_RenderData *data = (SDL_SW_RenderData *) renderer->driverdata;
   3.399 +    int i;
   3.400 +
   3.401 +    if (data) {
   3.402 +        for (i = 0; i < SDL_arraysize(data->screens); ++i) {
   3.403 +            if (data->screens[i]) {
   3.404 +                SDL_FreeSurface(data->screens[i]);
   3.405 +            }
   3.406 +        }
   3.407 +        SDL_free(data);
   3.408 +    }
   3.409 +    SDL_free(renderer);
   3.410 +}
   3.411 +
   3.412 +/* vi: set ts=4 sw=4 expandtab: */
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/src/video/SDL_renderer_sw.h	Mon Jun 12 09:10:06 2006 +0000
     4.3 @@ -0,0 +1,28 @@
     4.4 +/*
     4.5 +    SDL - Simple DirectMedia Layer
     4.6 +    Copyright (C) 1997-2006 Sam Lantinga
     4.7 +
     4.8 +    This library is free software; you can redistribute it and/or
     4.9 +    modify it under the terms of the GNU Lesser General Public
    4.10 +    License as published by the Free Software Foundation; either
    4.11 +    version 2.1 of the License, or (at your option) any later version.
    4.12 +
    4.13 +    This library is distributed in the hope that it will be useful,
    4.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    4.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    4.16 +    Lesser General Public License for more details.
    4.17 +
    4.18 +    You should have received a copy of the GNU Lesser General Public
    4.19 +    License along with this library; if not, write to the Free Software
    4.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    4.21 +
    4.22 +    Sam Lantinga
    4.23 +    slouken@libsdl.org
    4.24 +*/
    4.25 +#include "SDL_config.h"
    4.26 +
    4.27 +/* SDL surface based renderer implementation */
    4.28 +
    4.29 +extern SDL_RenderDriver SDL_SW_RenderDriver;
    4.30 +
    4.31 +/* vi: set ts=4 sw=4 expandtab: */
     5.1 --- a/src/video/SDL_sysvideo.h	Sun Jun 11 07:30:16 2006 +0000
     5.2 +++ b/src/video/SDL_sysvideo.h	Mon Jun 12 09:10:06 2006 +0000
     5.3 @@ -66,22 +66,28 @@
     5.4  /* Define the SDL renderer structure */
     5.5  struct SDL_Renderer
     5.6  {
     5.7 -    int (*CreateTexture) (SDL_Texture * texture);
     5.8 -    int (*UpdateTexture) (SDL_Texture * texture, SDL_Rect * rect,
     5.9 -                          const void *pixels, int pitch);
    5.10 -    int (*LockTexture) (SDL_Texture * texture, SDL_Rect * rect, int markDirty,
    5.11 -                        void **pixels, int *pitch);
    5.12 -    void (*UnlockTexture) (SDL_Texture * texture);
    5.13 -    void (*DirtyTexture) (SDL_Texture * texture, int numrects,
    5.14 -                          SDL_Rect * rects);
    5.15 -    void (*SelectRenderTexture) (SDL_Texture * texture);
    5.16 -    void (*RenderFill) (SDL_Rect * rect, Uint32 color);
    5.17 -    int (*RenderCopy) (SDL_Texture * texture, SDL_Rect * srcrect,
    5.18 -                       SDL_Rect * dstrect, int blendMode, int scaleMode);
    5.19 -    int (*RenderReadPixels) (SDL_Rect * rect, void *pixels, int pitch);
    5.20 -    int (*RenderWritePixels) (SDL_Rect * rect, const void *pixels, int pitch);
    5.21 -    void (*RenderPresent) (void);
    5.22 -    void (*DestroyTexture) (SDL_Texture * texture);
    5.23 +    int (*CreateTexture) (SDL_Renderer * renderer, SDL_Texture * texture);
    5.24 +    int (*UpdateTexture) (SDL_Renderer * renderer, SDL_Texture * texture,
    5.25 +                          SDL_Rect * rect, const void *pixels, int pitch);
    5.26 +    int (*LockTexture) (SDL_Renderer * renderer, SDL_Texture * texture,
    5.27 +                        SDL_Rect * rect, int markDirty, void **pixels,
    5.28 +                        int *pitch);
    5.29 +    void (*UnlockTexture) (SDL_Renderer * renderer, SDL_Texture * texture);
    5.30 +    void (*DirtyTexture) (SDL_Renderer * renderer, SDL_Texture * texture,
    5.31 +                          int numrects, SDL_Rect * rects);
    5.32 +    void (*SelectRenderTexture) (SDL_Renderer * renderer,
    5.33 +                                 SDL_Texture * texture);
    5.34 +    void (*RenderFill) (SDL_Renderer * renderer, SDL_Rect * rect,
    5.35 +                        Uint32 color);
    5.36 +    int (*RenderCopy) (SDL_Renderer * renderer, SDL_Texture * texture,
    5.37 +                       SDL_Rect * srcrect, SDL_Rect * dstrect, int blendMode,
    5.38 +                       int scaleMode);
    5.39 +    int (*RenderReadPixels) (SDL_Renderer * renderer, SDL_Rect * rect,
    5.40 +                             void *pixels, int pitch);
    5.41 +    int (*RenderWritePixels) (SDL_Renderer * renderer, SDL_Rect * rect,
    5.42 +                              const void *pixels, int pitch);
    5.43 +    void (*RenderPresent) (SDL_Renderer * renderer);
    5.44 +    void (*DestroyTexture) (SDL_Renderer * renderer, SDL_Texture * texture);
    5.45  
    5.46      void (*DestroyRenderer) (SDL_Renderer * renderer);
    5.47  
    5.48 @@ -115,6 +121,7 @@
    5.49  
    5.50      Uint16 *gamma;
    5.51  
    5.52 +    SDL_VideoDisplay *display;
    5.53      SDL_Renderer *renderer;
    5.54  
    5.55      void *userdata;
     6.1 --- a/src/video/SDL_video.c	Sun Jun 11 07:30:16 2006 +0000
     6.2 +++ b/src/video/SDL_video.c	Mon Jun 12 09:10:06 2006 +0000
     6.3 @@ -27,6 +27,7 @@
     6.4  #include "SDL_sysvideo.h"
     6.5  #include "SDL_blit.h"
     6.6  #include "SDL_pixels_c.h"
     6.7 +#include "SDL_renderer_sw.h"
     6.8  #include "../events/SDL_sysevents.h"
     6.9  #include "../events/SDL_events_c.h"
    6.10  
    6.11 @@ -274,6 +275,13 @@
    6.12                    sizeof(SDL_DisplayMode), cmpmodes);
    6.13      }
    6.14  
    6.15 +    /* The software renderer is always available */
    6.16 +    for (i = 0; i < _this->num_displays; ++i) {
    6.17 +        if (_this->displays[i].num_render_drivers > 0) {
    6.18 +            SDL_AddRenderDriver(i, &SDL_SW_RenderDriver);
    6.19 +        }
    6.20 +    }
    6.21 +
    6.22      /* Start the event loop */
    6.23      if (SDL_StartEventLoop(flags) < 0) {
    6.24          SDL_VideoQuit();
    6.25 @@ -578,6 +586,7 @@
    6.26      window.w = w;
    6.27      window.h = h;
    6.28      window.flags = (flags & allowed_flags);
    6.29 +    window.display = &SDL_CurrentDisplay;
    6.30  
    6.31      if (_this->CreateWindow && _this->CreateWindow(_this, &window) < 0) {
    6.32          if (window.title) {
    6.33 @@ -620,6 +629,7 @@
    6.34  
    6.35      SDL_zero(window);
    6.36      window.id = _this->next_object_id++;
    6.37 +    window.display = &SDL_CurrentDisplay;
    6.38  
    6.39      if (!_this->CreateWindowFrom ||
    6.40          _this->CreateWindowFrom(_this, &window, data) < 0) {
    6.41 @@ -1088,7 +1098,7 @@
    6.42      texture->h = h;
    6.43      texture->renderer = renderer;
    6.44  
    6.45 -    if (renderer->CreateTexture(texture) < 0) {
    6.46 +    if (renderer->CreateTexture(renderer, texture) < 0) {
    6.47          SDL_free(texture);
    6.48          return 0;
    6.49      }
    6.50 @@ -1286,7 +1296,7 @@
    6.51      if (!renderer->UpdateTexture) {
    6.52          return -1;
    6.53      }
    6.54 -    return renderer->UpdateTexture(texture, rect, pixels, pitch);
    6.55 +    return renderer->UpdateTexture(renderer, texture, rect, pixels, pitch);
    6.56  }
    6.57  
    6.58  int
    6.59 @@ -1304,7 +1314,8 @@
    6.60      if (!renderer->LockTexture) {
    6.61          return -1;
    6.62      }
    6.63 -    return renderer->LockTexture(texture, rect, markDirty, pixels, pitch);
    6.64 +    return renderer->LockTexture(renderer, texture, rect, markDirty, pixels,
    6.65 +                                 pitch);
    6.66  }
    6.67  
    6.68  void
    6.69 @@ -1321,7 +1332,7 @@
    6.70      if (!renderer->UnlockTexture) {
    6.71          return;
    6.72      }
    6.73 -    return renderer->UnlockTexture(texture);
    6.74 +    return renderer->UnlockTexture(renderer, texture);
    6.75  }
    6.76  
    6.77  void
    6.78 @@ -1338,7 +1349,7 @@
    6.79      if (!renderer->DirtyTexture) {
    6.80          return;
    6.81      }
    6.82 -    renderer->DirtyTexture(texture, numrects, rects);
    6.83 +    renderer->DirtyTexture(renderer, texture, numrects, rects);
    6.84  }
    6.85  
    6.86  void
    6.87 @@ -1354,7 +1365,7 @@
    6.88      if (!renderer->SelectRenderTexture) {
    6.89          return;
    6.90      }
    6.91 -    renderer->SelectRenderTexture(texture);
    6.92 +    renderer->SelectRenderTexture(renderer, texture);
    6.93  }
    6.94  
    6.95  int
    6.96 @@ -1371,7 +1382,7 @@
    6.97          return -1;
    6.98      }
    6.99  
   6.100 -    renderer->RenderFill(rect, color);
   6.101 +    renderer->RenderFill(renderer, rect, color);
   6.102  }
   6.103  
   6.104  int
   6.105 @@ -1390,8 +1401,8 @@
   6.106          return -1;
   6.107      }
   6.108  
   6.109 -    return renderer->RenderCopy(texture, srcrect, dstrect, blendMode,
   6.110 -                                scaleMode);
   6.111 +    return renderer->RenderCopy(renderer, texture, srcrect, dstrect,
   6.112 +                                blendMode, scaleMode);
   6.113  }
   6.114  
   6.115  int
   6.116 @@ -1408,7 +1419,7 @@
   6.117          return -1;
   6.118      }
   6.119  
   6.120 -    return renderer->RenderReadPixels(rect, pixels, pitch);
   6.121 +    return renderer->RenderReadPixels(renderer, rect, pixels, pitch);
   6.122  }
   6.123  
   6.124  int
   6.125 @@ -1425,7 +1436,7 @@
   6.126          return -1;
   6.127      }
   6.128  
   6.129 -    return renderer->RenderWritePixels(rect, pixels, pitch);
   6.130 +    return renderer->RenderWritePixels(renderer, rect, pixels, pitch);
   6.131  }
   6.132  
   6.133  void
   6.134 @@ -1442,7 +1453,7 @@
   6.135          return;
   6.136      }
   6.137  
   6.138 -    renderer->RenderPresent();
   6.139 +    renderer->RenderPresent(renderer);
   6.140  }
   6.141  
   6.142  void
   6.143 @@ -1478,7 +1489,7 @@
   6.144  
   6.145      /* Free the texture */
   6.146      renderer = texture->renderer;
   6.147 -    renderer->DestroyTexture(texture);
   6.148 +    renderer->DestroyTexture(renderer, texture);
   6.149      SDL_free(texture);
   6.150  }
   6.151  
   6.152 @@ -1512,7 +1523,7 @@
   6.153                  } else {
   6.154                      SDL_CurrentDisplay.textures[i] = next;
   6.155                  }
   6.156 -                renderer->DestroyTexture(texture);
   6.157 +                renderer->DestroyTexture(renderer, texture);
   6.158                  SDL_free(texture);
   6.159              } else {
   6.160                  prev = texture;
     7.1 --- a/src/video/dummy/SDL_nullevents.c	Sun Jun 11 07:30:16 2006 +0000
     7.2 +++ b/src/video/dummy/SDL_nullevents.c	Mon Jun 12 09:10:06 2006 +0000
     7.3 @@ -37,11 +37,4 @@
     7.4      /* do nothing. */
     7.5  }
     7.6  
     7.7 -void
     7.8 -DUMMY_InitOSKeymap(_THIS)
     7.9 -{
    7.10 -    /* do nothing. */
    7.11 -}
    7.12 -
    7.13 -/* end of SDL_nullevents.c ... */
    7.14  /* vi: set ts=4 sw=4 expandtab: */
     8.1 --- a/src/video/dummy/SDL_nullevents_c.h	Sun Jun 11 07:30:16 2006 +0000
     8.2 +++ b/src/video/dummy/SDL_nullevents_c.h	Mon Jun 12 09:10:06 2006 +0000
     8.3 @@ -23,11 +23,6 @@
     8.4  
     8.5  #include "SDL_nullvideo.h"
     8.6  
     8.7 -/* Variables and functions exported by SDL_sysevents.c to other parts 
     8.8 -   of the native video subsystem (SDL_sysvideo.c)
     8.9 -*/
    8.10 -extern void DUMMY_InitOSKeymap(_THIS);
    8.11  extern void DUMMY_PumpEvents(_THIS);
    8.12  
    8.13 -/* end of SDL_nullevents_c.h ... */
    8.14  /* vi: set ts=4 sw=4 expandtab: */
     9.1 --- a/src/video/dummy/SDL_nullvideo.c	Sun Jun 11 07:30:16 2006 +0000
     9.2 +++ b/src/video/dummy/SDL_nullvideo.c	Mon Jun 12 09:10:06 2006 +0000
     9.3 @@ -101,10 +101,7 @@
     9.4      /* Set the function pointers */
     9.5      device->VideoInit = DUMMY_VideoInit;
     9.6      device->SetDisplayMode = DUMMY_SetDisplayMode;
     9.7 -    device->CreateWindowSurface = DUMMY_CreateWindowSurface;
     9.8 -    device->UpdateWindowSurface = DUMMY_UpdateWindowSurface;
     9.9      device->VideoQuit = DUMMY_VideoQuit;
    9.10 -    device->InitOSKeymap = DUMMY_InitOSKeymap;
    9.11      device->PumpEvents = DUMMY_PumpEvents;
    9.12  
    9.13      device->free = DUMMY_DeleteDevice;
    9.14 @@ -139,35 +136,6 @@
    9.15      return 0;
    9.16  }
    9.17  
    9.18 -static void
    9.19 -DUMMY_CreateWindowSurface(_THIS, SDL_Window * window, Uint32 flags)
    9.20 -{
    9.21 -    int bpp;
    9.22 -    Uint32 Rmask, Gmask, Bmask, Amask;
    9.23 -
    9.24 -    SDL_PixelFormatEnumToMasks(SDL_GetCurrentDisplayMode()->format, &bpp,
    9.25 -                               &Rmask, &Gmask, &Bmask, &Amask);
    9.26 -    window->surface =
    9.27 -        SDL_CreateRGBSurface(flags, window->w, window->h, bpp, Rmask, Gmask,
    9.28 -                             Bmask, Amask);
    9.29 -}
    9.30 -
    9.31 -static void
    9.32 -DUMMY_UpdateWindowSurface(_THIS, SDL_Window * window, int numrects,
    9.33 -                          SDL_Rect * rects)
    9.34 -{
    9.35 -    static int frame_number;
    9.36 -    if (SDL_getenv("SDL_VIDEO_DUMMY_SAVE_FRAMES")) {
    9.37 -        char file[128];
    9.38 -        SDL_snprintf(file, sizeof(file), "SDL_screen-%8.8d.bmp",
    9.39 -                     ++frame_number);
    9.40 -        SDL_SaveBMP(window->surface, file);
    9.41 -    }
    9.42 -}
    9.43 -
    9.44 -/* Note:  If we are terminated, this could be called in the middle of
    9.45 -   another SDL video routine -- notably UpdateRects.
    9.46 -*/
    9.47  void
    9.48  DUMMY_VideoQuit(_THIS)
    9.49  {