Mercurial > sdl-ios-xcode
comparison src/video/dummy/SDL_nullframebuffer.c @ 5169:4d39eeaad00b
Added a way to get a framebuffer interface for a window, and also a way to create a software renderer for an arbitrary surface.
The software renderer has been re-routed to use the framebuffer interface, which makes it possible to have software rendering available even on simple ports.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Thu, 03 Feb 2011 15:49:37 -0800 |
parents | |
children | b530ef003506 |
comparison
equal
deleted
inserted
replaced
5168:2b1989f59674 | 5169:4d39eeaad00b |
---|---|
1 /* | |
2 SDL - Simple DirectMedia Layer | |
3 Copyright (C) 1997-2010 Sam Lantinga | |
4 | |
5 This library is free software; you can redistribute it and/or | |
6 modify it under the terms of the GNU Lesser General Public | |
7 License as published by the Free Software Foundation; either | |
8 version 2.1 of the License, or (at your option) any later version. | |
9 | |
10 This library is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 Lesser General Public License for more details. | |
14 | |
15 You should have received a copy of the GNU Lesser General Public | |
16 License along with this library; if not, write to the Free Software | |
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
18 | |
19 Sam Lantinga | |
20 slouken@libsdl.org | |
21 */ | |
22 #include "SDL_config.h" | |
23 | |
24 #include "../SDL_sysvideo.h" | |
25 | |
26 | |
27 #define DUMMY_SURFACE "_SDL_DummySurface" | |
28 | |
29 int SDL_DUMMY_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch) | |
30 { | |
31 SDL_Surface *surface; | |
32 const Uint32 surface_format = SDL_PIXELFORMAT_RGB888; | |
33 int w, h; | |
34 int bpp; | |
35 Uint32 Rmask, Gmask, Bmask, Amask; | |
36 | |
37 /* Free the old framebuffer surface */ | |
38 surface = (SDL_Surface *) SDL_GetWindowData(window, DUMMY_SURFACE); | |
39 if (surface) { | |
40 SDL_FreeSurface(surface); | |
41 } | |
42 | |
43 /* Create a new one */ | |
44 SDL_PixelFormatEnumToMasks(surface_format, &bpp, &Rmask, &Gmask, &Bmask, &Amask); | |
45 SDL_GetWindowSize(window, &w, &h); | |
46 surface = SDL_CreateRGBSurface(0, w, h, bpp, Rmask, Gmask, Bmask, Amask); | |
47 if (!surface) { | |
48 return -1; | |
49 } | |
50 | |
51 /* Save the info and return! */ | |
52 SDL_SetWindowData(window, DUMMY_SURFACE, surface); | |
53 *format = surface_format; | |
54 *pixels = surface->pixels; | |
55 *pitch = surface->pitch; | |
56 return 0; | |
57 } | |
58 | |
59 int SDL_DUMMY_UpdateWindowFramebuffer(_THIS, SDL_Window * window, int numrects, SDL_Rect * rects) | |
60 { | |
61 static int frame_number; | |
62 SDL_Surface *surface; | |
63 | |
64 surface = (SDL_Surface *) SDL_GetWindowData(window, DUMMY_SURFACE); | |
65 if (!surface) { | |
66 SDL_SetError("Couldn't find dummy surface for window"); | |
67 return -1; | |
68 } | |
69 | |
70 /* Send the data to the display */ | |
71 if (SDL_getenv("SDL_VIDEO_DUMMY_SAVE_FRAMES")) { | |
72 char file[128]; | |
73 SDL_snprintf(file, sizeof(file), "SDL_window%d-%8.8d.bmp", | |
74 SDL_GetWindowID(window), ++frame_number); | |
75 SDL_SaveBMP(surface, file); | |
76 } | |
77 return 0; | |
78 } | |
79 | |
80 void SDL_DUMMY_DestroyWindowFramebuffer(_THIS, SDL_Window * window) | |
81 { | |
82 SDL_Surface *surface; | |
83 | |
84 surface = (SDL_Surface *) SDL_SetWindowData(window, DUMMY_SURFACE, NULL); | |
85 if (surface) { | |
86 SDL_FreeSurface(surface); | |
87 } | |
88 } | |
89 | |
90 /* vi: set ts=4 sw=4 expandtab: */ |