Added new style dummy renderer SDL-1.3
authorSam Lantinga <slouken@libsdl.org>
Tue, 13 Jun 2006 04:37:45 +0000
branchSDL-1.3
changeset 16775e4c5e095925
parent 1676 e136f3ffdc1b
child 1678 90bf530ced8e
Added new style dummy renderer
src/video/SDL_sysvideo.h
src/video/SDL_video.c
src/video/dummy/SDL_nullmouse.c
src/video/dummy/SDL_nullmouse_c.h
src/video/dummy/SDL_nullrender.c
src/video/dummy/SDL_nullrender_c.h
src/video/dummy/SDL_nullvideo.c
     1.1 --- a/src/video/SDL_sysvideo.h	Mon Jun 12 09:10:06 2006 +0000
     1.2 +++ b/src/video/SDL_sysvideo.h	Tue Jun 13 04:37:45 2006 +0000
     1.3 @@ -427,8 +427,8 @@
     1.4  #define SDL_CurrentWindow	(SDL_CurrentDisplay.windows[0])
     1.5  
     1.6  extern SDL_VideoDevice *SDL_GetVideoDevice();
     1.7 -extern void SDL_AddBasicVideoDisplay(const SDL_DisplayMode * desktop_mode);
     1.8 -extern void SDL_AddVideoDisplay(const SDL_VideoDisplay * display);
     1.9 +extern int SDL_AddBasicVideoDisplay(const SDL_DisplayMode * desktop_mode);
    1.10 +extern int SDL_AddVideoDisplay(const SDL_VideoDisplay * display);
    1.11  extern void SDL_AddDisplayMode(int displayIndex,
    1.12                                 const SDL_DisplayMode * mode);
    1.13  extern void SDL_AddRenderDriver(int displayIndex,
     2.1 --- a/src/video/SDL_video.c	Mon Jun 12 09:10:06 2006 +0000
     2.2 +++ b/src/video/SDL_video.c	Tue Jun 13 04:37:45 2006 +0000
     2.3 @@ -307,7 +307,7 @@
     2.4      return _this;
     2.5  }
     2.6  
     2.7 -void
     2.8 +int
     2.9  SDL_AddBasicVideoDisplay(const SDL_DisplayMode * desktop_mode)
    2.10  {
    2.11      SDL_VideoDisplay display;
    2.12 @@ -318,22 +318,26 @@
    2.13      }
    2.14      display.current_mode = display.desktop_mode;
    2.15  
    2.16 -    SDL_AddVideoDisplay(&display);
    2.17 +    return SDL_AddVideoDisplay(&display);
    2.18  }
    2.19  
    2.20 -void
    2.21 +int
    2.22  SDL_AddVideoDisplay(const SDL_VideoDisplay * display)
    2.23  {
    2.24      SDL_VideoDisplay *displays;
    2.25 +    int index = -1;
    2.26  
    2.27      displays =
    2.28          SDL_realloc(_this->displays,
    2.29                      (_this->num_displays + 1) * sizeof(*displays));
    2.30      if (displays) {
    2.31 -        displays[_this->num_displays] = *display;
    2.32 +        index = _this->num_displays++;
    2.33 +        displays[index] = *display;
    2.34          _this->displays = displays;
    2.35 -        _this->num_displays++;
    2.36 +    } else {
    2.37 +        SDL_OutOfMemory();
    2.38      }
    2.39 +    return index;
    2.40  }
    2.41  
    2.42  int
     3.1 --- a/src/video/dummy/SDL_nullmouse.c	Mon Jun 12 09:10:06 2006 +0000
     3.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.3 @@ -1,35 +0,0 @@
     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_mouse.h"
    3.28 -#include "../../events/SDL_events_c.h"
    3.29 -
    3.30 -#include "SDL_nullmouse_c.h"
    3.31 -
    3.32 -
    3.33 -/* The implementation dependent data for the window manager cursor */
    3.34 -struct WMcursor
    3.35 -{
    3.36 -    int unused;
    3.37 -};
    3.38 -/* vi: set ts=4 sw=4 expandtab: */
     4.1 --- a/src/video/dummy/SDL_nullmouse_c.h	Mon Jun 12 09:10:06 2006 +0000
     4.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.3 @@ -1,27 +0,0 @@
     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 -#include "SDL_nullvideo.h"
    4.28 -
    4.29 -/* Functions to be exported */
    4.30 -/* vi: set ts=4 sw=4 expandtab: */
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/src/video/dummy/SDL_nullrender.c	Tue Jun 13 04:37:45 2006 +0000
     5.3 @@ -0,0 +1,191 @@
     5.4 +/*
     5.5 +    SDL - Simple DirectMedia Layer
     5.6 +    Copyright (C) 1997-2006 Sam Lantinga
     5.7 +
     5.8 +    This library is free software; you can redistribute it and/or
     5.9 +    modify it under the terms of the GNU Lesser General Public
    5.10 +    License as published by the Free Software Foundation; either
    5.11 +    version 2.1 of the License, or (at your option) any later version.
    5.12 +
    5.13 +    This library is distributed in the hope that it will be useful,
    5.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    5.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    5.16 +    Lesser General Public License for more details.
    5.17 +
    5.18 +    You should have received a copy of the GNU Lesser General Public
    5.19 +    License along with this library; if not, write to the Free Software
    5.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    5.21 +
    5.22 +    Sam Lantinga
    5.23 +    slouken@libsdl.org
    5.24 +*/
    5.25 +#include "SDL_config.h"
    5.26 +
    5.27 +#include "SDL_video.h"
    5.28 +#include "../SDL_sysvideo.h"
    5.29 +
    5.30 +
    5.31 +/* SDL surface based renderer implementation */
    5.32 +
    5.33 +static SDL_Renderer *SDL_DUMMY_CreateRenderer(SDL_Window * window,
    5.34 +                                              Uint32 flags);
    5.35 +static int SDL_DUMMY_CreateTexture(SDL_Renderer * renderer,
    5.36 +                                   SDL_Texture * texture);
    5.37 +static int SDL_DUMMY_RenderReadPixels(SDL_Renderer * renderer,
    5.38 +                                      SDL_Rect * rect, void *pixels,
    5.39 +                                      int pitch);
    5.40 +static int SDL_DUMMY_RenderWritePixels(SDL_Renderer * renderer,
    5.41 +                                       SDL_Rect * rect, const void *pixels,
    5.42 +                                       int pitch);
    5.43 +static void SDL_DUMMY_RenderPresent(SDL_Renderer * renderer);
    5.44 +static void SDL_DUMMY_DestroyRenderer(SDL_Renderer * renderer);
    5.45 +
    5.46 +
    5.47 +SDL_RenderDriver SDL_DUMMY_RenderDriver = {
    5.48 +    SDL_DUMMY_CreateRenderer,
    5.49 +    {
    5.50 +     "minimal",
    5.51 +     (SDL_Renderer_Minimal | SDL_Renderer_PresentCopy),
    5.52 +     SDL_TextureBlendMode_None,
    5.53 +     SDL_TextureScaleMode_None,
    5.54 +     0,
    5.55 +     {},
    5.56 +     0,
    5.57 +     0}
    5.58 +};
    5.59 +
    5.60 +typedef struct
    5.61 +{
    5.62 +    SDL_Surface *screen;
    5.63 +} SDL_DUMMY_RenderData;
    5.64 +
    5.65 +SDL_Renderer *
    5.66 +SDL_DUMMY_CreateRenderer(SDL_Window * window, Uint32 flags)
    5.67 +{
    5.68 +    SDL_DisplayMode *displayMode = &window->display->current_mode;
    5.69 +    SDL_Renderer *renderer;
    5.70 +    SDL_DUMMY_RenderData *data;
    5.71 +    int i, n;
    5.72 +    int bpp;
    5.73 +    Uint32 Rmask, Gmask, Bmask, Amask;
    5.74 +
    5.75 +    if (!SDL_PixelFormatEnumToMasks
    5.76 +        (displayMode->format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) {
    5.77 +        SDL_SetError("Unknown display format");
    5.78 +        return NULL;
    5.79 +    }
    5.80 +
    5.81 +    renderer = (SDL_Renderer *) SDL_malloc(sizeof(*renderer));
    5.82 +    if (!renderer) {
    5.83 +        SDL_OutOfMemory();
    5.84 +        return NULL;
    5.85 +    }
    5.86 +    SDL_zerop(renderer);
    5.87 +
    5.88 +    data = (SDL_DUMMY_RenderData *) SDL_malloc(sizeof(*data));
    5.89 +    if (!data) {
    5.90 +        SDL_DUMMY_DestroyRenderer(renderer);
    5.91 +        SDL_OutOfMemory();
    5.92 +        return NULL;
    5.93 +    }
    5.94 +    SDL_zerop(data);
    5.95 +
    5.96 +    renderer->RenderReadPixels = SDL_DUMMY_RenderReadPixels;
    5.97 +    renderer->RenderWritePixels = SDL_DUMMY_RenderWritePixels;
    5.98 +    renderer->RenderPresent = SDL_DUMMY_RenderPresent;
    5.99 +    renderer->DestroyRenderer = SDL_DUMMY_DestroyRenderer;
   5.100 +    renderer->info = SDL_DUMMY_RenderDriver.info;
   5.101 +    renderer->window = window;
   5.102 +    renderer->driverdata = data;
   5.103 +
   5.104 +    data->screen =
   5.105 +        SDL_CreateRGBSurface(0, window->w, window->h, bpp, Rmask, Gmask,
   5.106 +                             Bmask, Amask);
   5.107 +    if (!data->screen) {
   5.108 +        SDL_DUMMY_DestroyRenderer(renderer);
   5.109 +        return NULL;
   5.110 +    }
   5.111 +
   5.112 +    return renderer;
   5.113 +}
   5.114 +
   5.115 +int
   5.116 +SDL_DUMMY_RenderReadPixels(SDL_Renderer * renderer, SDL_Rect * rect,
   5.117 +                           void *pixels, int pitch)
   5.118 +{
   5.119 +    SDL_DUMMY_RenderData *data =
   5.120 +        (SDL_DUMMY_RenderData *) renderer->driverdata;
   5.121 +    SDL_Surface *surface = data->screen;
   5.122 +    Uint8 *src, *dst;
   5.123 +    int row;
   5.124 +    size_t length;
   5.125 +
   5.126 +    src =
   5.127 +        (Uint8 *) surface->pixels + rect->y * surface->pitch +
   5.128 +        rect->x * surface->format->BytesPerPixel;
   5.129 +    dst = (Uint8 *) pixels;
   5.130 +    length = rect->w * surface->format->BytesPerPixel;
   5.131 +    for (row = 0; row < rect->h; ++row) {
   5.132 +        SDL_memcpy(dst, src, length);
   5.133 +        src += surface->pitch;
   5.134 +        dst += pitch;
   5.135 +    }
   5.136 +    return 0;
   5.137 +}
   5.138 +
   5.139 +int
   5.140 +SDL_DUMMY_RenderWritePixels(SDL_Renderer * renderer, SDL_Rect * rect,
   5.141 +                            const void *pixels, int pitch)
   5.142 +{
   5.143 +    SDL_DUMMY_RenderData *data =
   5.144 +        (SDL_DUMMY_RenderData *) renderer->driverdata;
   5.145 +    SDL_Surface *surface = data->screen;
   5.146 +    Uint8 *src, *dst;
   5.147 +    int row;
   5.148 +    size_t length;
   5.149 +
   5.150 +    src = (Uint8 *) pixels;
   5.151 +    dst =
   5.152 +        (Uint8 *) surface->pixels + rect->y * surface->pitch +
   5.153 +        rect->x * surface->format->BytesPerPixel;
   5.154 +    length = rect->w * surface->format->BytesPerPixel;
   5.155 +    for (row = 0; row < rect->h; ++row) {
   5.156 +        SDL_memcpy(dst, src, length);
   5.157 +        src += pitch;
   5.158 +        dst += surface->pitch;
   5.159 +    }
   5.160 +    return 0;
   5.161 +}
   5.162 +
   5.163 +void
   5.164 +SDL_DUMMY_RenderPresent(SDL_Renderer * renderer)
   5.165 +{
   5.166 +    static int frame_number;
   5.167 +    SDL_DUMMY_RenderData *data =
   5.168 +        (SDL_DUMMY_RenderData *) renderer->driverdata;
   5.169 +    SDL_Surface *surface = data->screen;
   5.170 +
   5.171 +    if (SDL_getenv("SDL_VIDEO_DUMMY_SAVE_FRAMES")) {
   5.172 +        char file[128];
   5.173 +        SDL_snprintf(file, sizeof(file), "SDL_screen-%8.8d.bmp",
   5.174 +                     ++frame_number);
   5.175 +        SDL_SaveBMP(surface, file);
   5.176 +    }
   5.177 +}
   5.178 +
   5.179 +void
   5.180 +SDL_DUMMY_DestroyRenderer(SDL_Renderer * renderer)
   5.181 +{
   5.182 +    SDL_DUMMY_RenderData *data =
   5.183 +        (SDL_DUMMY_RenderData *) renderer->driverdata;
   5.184 +
   5.185 +    if (data) {
   5.186 +        if (data->screen) {
   5.187 +            SDL_FreeSurface(data->screen);
   5.188 +        }
   5.189 +        SDL_free(data);
   5.190 +    }
   5.191 +    SDL_free(renderer);
   5.192 +}
   5.193 +
   5.194 +/* vi: set ts=4 sw=4 expandtab: */
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/src/video/dummy/SDL_nullrender_c.h	Tue Jun 13 04:37:45 2006 +0000
     6.3 @@ -0,0 +1,28 @@
     6.4 +/*
     6.5 +    SDL - Simple DirectMedia Layer
     6.6 +    Copyright (C) 1997-2006 Sam Lantinga
     6.7 +
     6.8 +    This library is free software; you can redistribute it and/or
     6.9 +    modify it under the terms of the GNU Lesser General Public
    6.10 +    License as published by the Free Software Foundation; either
    6.11 +    version 2.1 of the License, or (at your option) any later version.
    6.12 +
    6.13 +    This library is distributed in the hope that it will be useful,
    6.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    6.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    6.16 +    Lesser General Public License for more details.
    6.17 +
    6.18 +    You should have received a copy of the GNU Lesser General Public
    6.19 +    License along with this library; if not, write to the Free Software
    6.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    6.21 +
    6.22 +    Sam Lantinga
    6.23 +    slouken@libsdl.org
    6.24 +*/
    6.25 +#include "SDL_config.h"
    6.26 +
    6.27 +/* SDL surface based renderer implementation */
    6.28 +
    6.29 +extern SDL_RenderDriver SDL_DUMMY_RenderDriver;
    6.30 +
    6.31 +/* vi: set ts=4 sw=4 expandtab: */
     7.1 --- a/src/video/dummy/SDL_nullvideo.c	Mon Jun 12 09:10:06 2006 +0000
     7.2 +++ b/src/video/dummy/SDL_nullvideo.c	Tue Jun 13 04:37:45 2006 +0000
     7.3 @@ -44,7 +44,7 @@
     7.4  
     7.5  #include "SDL_nullvideo.h"
     7.6  #include "SDL_nullevents_c.h"
     7.7 -#include "SDL_nullmouse_c.h"
     7.8 +#include "SDL_nullrender_c.h"
     7.9  
    7.10  #define DUMMYVID_DRIVER_NAME "dummy"
    7.11  
    7.12 @@ -121,6 +121,7 @@
    7.13      SDL_DisplayMode mode;
    7.14  
    7.15      SDL_AddBasicVideoDisplay(NULL);
    7.16 +    SDL_AddRenderDriver(0, &SDL_DUMMY_RenderDriver);
    7.17  
    7.18      SDL_zero(mode);
    7.19      SDL_AddDisplayMode(0, &mode);