Mercurial > sdl-ios-xcode
changeset 1677:5e4c5e095925 SDL-1.3
Added new style dummy renderer
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Tue, 13 Jun 2006 04:37:45 +0000 |
parents | e136f3ffdc1b |
children | 90bf530ced8e |
files | 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 |
diffstat | 7 files changed, 232 insertions(+), 70 deletions(-) [+] |
line wrap: on
line diff
--- a/src/video/SDL_sysvideo.h Mon Jun 12 09:10:06 2006 +0000 +++ b/src/video/SDL_sysvideo.h Tue Jun 13 04:37:45 2006 +0000 @@ -427,8 +427,8 @@ #define SDL_CurrentWindow (SDL_CurrentDisplay.windows[0]) extern SDL_VideoDevice *SDL_GetVideoDevice(); -extern void SDL_AddBasicVideoDisplay(const SDL_DisplayMode * desktop_mode); -extern void SDL_AddVideoDisplay(const SDL_VideoDisplay * display); +extern int SDL_AddBasicVideoDisplay(const SDL_DisplayMode * desktop_mode); +extern int SDL_AddVideoDisplay(const SDL_VideoDisplay * display); extern void SDL_AddDisplayMode(int displayIndex, const SDL_DisplayMode * mode); extern void SDL_AddRenderDriver(int displayIndex,
--- a/src/video/SDL_video.c Mon Jun 12 09:10:06 2006 +0000 +++ b/src/video/SDL_video.c Tue Jun 13 04:37:45 2006 +0000 @@ -307,7 +307,7 @@ return _this; } -void +int SDL_AddBasicVideoDisplay(const SDL_DisplayMode * desktop_mode) { SDL_VideoDisplay display; @@ -318,22 +318,26 @@ } display.current_mode = display.desktop_mode; - SDL_AddVideoDisplay(&display); + return SDL_AddVideoDisplay(&display); } -void +int SDL_AddVideoDisplay(const SDL_VideoDisplay * display) { SDL_VideoDisplay *displays; + int index = -1; displays = SDL_realloc(_this->displays, (_this->num_displays + 1) * sizeof(*displays)); if (displays) { - displays[_this->num_displays] = *display; + index = _this->num_displays++; + displays[index] = *display; _this->displays = displays; - _this->num_displays++; + } else { + SDL_OutOfMemory(); } + return index; } int
--- a/src/video/dummy/SDL_nullmouse.c Mon Jun 12 09:10:06 2006 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,35 +0,0 @@ -/* - SDL - Simple DirectMedia Layer - Copyright (C) 1997-2006 Sam Lantinga - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Sam Lantinga - slouken@libsdl.org -*/ -#include "SDL_config.h" - -#include "SDL_mouse.h" -#include "../../events/SDL_events_c.h" - -#include "SDL_nullmouse_c.h" - - -/* The implementation dependent data for the window manager cursor */ -struct WMcursor -{ - int unused; -}; -/* vi: set ts=4 sw=4 expandtab: */
--- a/src/video/dummy/SDL_nullmouse_c.h Mon Jun 12 09:10:06 2006 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,27 +0,0 @@ -/* - SDL - Simple DirectMedia Layer - Copyright (C) 1997-2006 Sam Lantinga - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Sam Lantinga - slouken@libsdl.org -*/ -#include "SDL_config.h" - -#include "SDL_nullvideo.h" - -/* Functions to be exported */ -/* vi: set ts=4 sw=4 expandtab: */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/video/dummy/SDL_nullrender.c Tue Jun 13 04:37:45 2006 +0000 @@ -0,0 +1,191 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2006 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ +#include "SDL_config.h" + +#include "SDL_video.h" +#include "../SDL_sysvideo.h" + + +/* SDL surface based renderer implementation */ + +static SDL_Renderer *SDL_DUMMY_CreateRenderer(SDL_Window * window, + Uint32 flags); +static int SDL_DUMMY_CreateTexture(SDL_Renderer * renderer, + SDL_Texture * texture); +static int SDL_DUMMY_RenderReadPixels(SDL_Renderer * renderer, + SDL_Rect * rect, void *pixels, + int pitch); +static int SDL_DUMMY_RenderWritePixels(SDL_Renderer * renderer, + SDL_Rect * rect, const void *pixels, + int pitch); +static void SDL_DUMMY_RenderPresent(SDL_Renderer * renderer); +static void SDL_DUMMY_DestroyRenderer(SDL_Renderer * renderer); + + +SDL_RenderDriver SDL_DUMMY_RenderDriver = { + SDL_DUMMY_CreateRenderer, + { + "minimal", + (SDL_Renderer_Minimal | SDL_Renderer_PresentCopy), + SDL_TextureBlendMode_None, + SDL_TextureScaleMode_None, + 0, + {}, + 0, + 0} +}; + +typedef struct +{ + SDL_Surface *screen; +} SDL_DUMMY_RenderData; + +SDL_Renderer * +SDL_DUMMY_CreateRenderer(SDL_Window * window, Uint32 flags) +{ + SDL_DisplayMode *displayMode = &window->display->current_mode; + SDL_Renderer *renderer; + SDL_DUMMY_RenderData *data; + int i, n; + int bpp; + Uint32 Rmask, Gmask, Bmask, Amask; + + if (!SDL_PixelFormatEnumToMasks + (displayMode->format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) { + SDL_SetError("Unknown display format"); + return NULL; + } + + renderer = (SDL_Renderer *) SDL_malloc(sizeof(*renderer)); + if (!renderer) { + SDL_OutOfMemory(); + return NULL; + } + SDL_zerop(renderer); + + data = (SDL_DUMMY_RenderData *) SDL_malloc(sizeof(*data)); + if (!data) { + SDL_DUMMY_DestroyRenderer(renderer); + SDL_OutOfMemory(); + return NULL; + } + SDL_zerop(data); + + renderer->RenderReadPixels = SDL_DUMMY_RenderReadPixels; + renderer->RenderWritePixels = SDL_DUMMY_RenderWritePixels; + renderer->RenderPresent = SDL_DUMMY_RenderPresent; + renderer->DestroyRenderer = SDL_DUMMY_DestroyRenderer; + renderer->info = SDL_DUMMY_RenderDriver.info; + renderer->window = window; + renderer->driverdata = data; + + data->screen = + SDL_CreateRGBSurface(0, window->w, window->h, bpp, Rmask, Gmask, + Bmask, Amask); + if (!data->screen) { + SDL_DUMMY_DestroyRenderer(renderer); + return NULL; + } + + return renderer; +} + +int +SDL_DUMMY_RenderReadPixels(SDL_Renderer * renderer, SDL_Rect * rect, + void *pixels, int pitch) +{ + SDL_DUMMY_RenderData *data = + (SDL_DUMMY_RenderData *) renderer->driverdata; + SDL_Surface *surface = data->screen; + Uint8 *src, *dst; + int row; + size_t length; + + src = + (Uint8 *) surface->pixels + rect->y * surface->pitch + + rect->x * surface->format->BytesPerPixel; + dst = (Uint8 *) pixels; + length = rect->w * surface->format->BytesPerPixel; + for (row = 0; row < rect->h; ++row) { + SDL_memcpy(dst, src, length); + src += surface->pitch; + dst += pitch; + } + return 0; +} + +int +SDL_DUMMY_RenderWritePixels(SDL_Renderer * renderer, SDL_Rect * rect, + const void *pixels, int pitch) +{ + SDL_DUMMY_RenderData *data = + (SDL_DUMMY_RenderData *) renderer->driverdata; + SDL_Surface *surface = data->screen; + Uint8 *src, *dst; + int row; + size_t length; + + src = (Uint8 *) pixels; + dst = + (Uint8 *) surface->pixels + rect->y * surface->pitch + + rect->x * surface->format->BytesPerPixel; + length = rect->w * surface->format->BytesPerPixel; + for (row = 0; row < rect->h; ++row) { + SDL_memcpy(dst, src, length); + src += pitch; + dst += surface->pitch; + } + return 0; +} + +void +SDL_DUMMY_RenderPresent(SDL_Renderer * renderer) +{ + static int frame_number; + SDL_DUMMY_RenderData *data = + (SDL_DUMMY_RenderData *) renderer->driverdata; + SDL_Surface *surface = data->screen; + + if (SDL_getenv("SDL_VIDEO_DUMMY_SAVE_FRAMES")) { + char file[128]; + SDL_snprintf(file, sizeof(file), "SDL_screen-%8.8d.bmp", + ++frame_number); + SDL_SaveBMP(surface, file); + } +} + +void +SDL_DUMMY_DestroyRenderer(SDL_Renderer * renderer) +{ + SDL_DUMMY_RenderData *data = + (SDL_DUMMY_RenderData *) renderer->driverdata; + + if (data) { + if (data->screen) { + SDL_FreeSurface(data->screen); + } + SDL_free(data); + } + SDL_free(renderer); +} + +/* vi: set ts=4 sw=4 expandtab: */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/video/dummy/SDL_nullrender_c.h Tue Jun 13 04:37:45 2006 +0000 @@ -0,0 +1,28 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2006 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ +#include "SDL_config.h" + +/* SDL surface based renderer implementation */ + +extern SDL_RenderDriver SDL_DUMMY_RenderDriver; + +/* vi: set ts=4 sw=4 expandtab: */
--- a/src/video/dummy/SDL_nullvideo.c Mon Jun 12 09:10:06 2006 +0000 +++ b/src/video/dummy/SDL_nullvideo.c Tue Jun 13 04:37:45 2006 +0000 @@ -44,7 +44,7 @@ #include "SDL_nullvideo.h" #include "SDL_nullevents_c.h" -#include "SDL_nullmouse_c.h" +#include "SDL_nullrender_c.h" #define DUMMYVID_DRIVER_NAME "dummy" @@ -121,6 +121,7 @@ SDL_DisplayMode mode; SDL_AddBasicVideoDisplay(NULL); + SDL_AddRenderDriver(0, &SDL_DUMMY_RenderDriver); SDL_zero(mode); SDL_AddDisplayMode(0, &mode);