comparison src/video/dummy/SDL_nullrender.c @ 1682:7ae8018b2e5d SDL-1.3

Default palette entries to white, instead of black. More palettized video mode support...
author Sam Lantinga <slouken@libsdl.org>
date Fri, 16 Jun 2006 06:00:31 +0000
parents 90bf530ced8e
children 396a35389351
comparison
equal deleted inserted replaced
1681:80a5e6a4e1e2 1682:7ae8018b2e5d
30 static SDL_Renderer *SDL_DUMMY_CreateRenderer(SDL_Window * window, 30 static SDL_Renderer *SDL_DUMMY_CreateRenderer(SDL_Window * window,
31 Uint32 flags); 31 Uint32 flags);
32 static int SDL_DUMMY_CreateTexture(SDL_Renderer * renderer, 32 static int SDL_DUMMY_CreateTexture(SDL_Renderer * renderer,
33 SDL_Texture * texture); 33 SDL_Texture * texture);
34 static int SDL_DUMMY_RenderReadPixels(SDL_Renderer * renderer, 34 static int SDL_DUMMY_RenderReadPixels(SDL_Renderer * renderer,
35 SDL_Rect * rect, void *pixels, 35 const SDL_Rect * rect, void *pixels,
36 int pitch); 36 int pitch);
37 static int SDL_DUMMY_RenderWritePixels(SDL_Renderer * renderer, 37 static int SDL_DUMMY_RenderWritePixels(SDL_Renderer * renderer,
38 SDL_Rect * rect, const void *pixels, 38 const SDL_Rect * rect,
39 int pitch); 39 const void *pixels, int pitch);
40 static void SDL_DUMMY_RenderPresent(SDL_Renderer * renderer); 40 static void SDL_DUMMY_RenderPresent(SDL_Renderer * renderer);
41 static void SDL_DUMMY_DestroyRenderer(SDL_Renderer * renderer); 41 static void SDL_DUMMY_DestroyRenderer(SDL_Renderer * renderer);
42 42
43 43
44 SDL_RenderDriver SDL_DUMMY_RenderDriver = { 44 SDL_RenderDriver SDL_DUMMY_RenderDriver = {
55 0} 55 0}
56 }; 56 };
57 57
58 typedef struct 58 typedef struct
59 { 59 {
60 SDL_Surface *screen; 60 SDL_Surface *surface;
61 } SDL_DUMMY_RenderData; 61 } SDL_DUMMY_RenderData;
62 62
63 SDL_Renderer * 63 SDL_Renderer *
64 SDL_DUMMY_CreateRenderer(SDL_Window * window, Uint32 flags) 64 SDL_DUMMY_CreateRenderer(SDL_Window * window, Uint32 flags)
65 { 65 {
97 renderer->DestroyRenderer = SDL_DUMMY_DestroyRenderer; 97 renderer->DestroyRenderer = SDL_DUMMY_DestroyRenderer;
98 renderer->info = SDL_DUMMY_RenderDriver.info; 98 renderer->info = SDL_DUMMY_RenderDriver.info;
99 renderer->window = window; 99 renderer->window = window;
100 renderer->driverdata = data; 100 renderer->driverdata = data;
101 101
102 data->screen = 102 data->surface =
103 SDL_CreateRGBSurface(0, window->w, window->h, bpp, Rmask, Gmask, 103 SDL_CreateRGBSurface(0, window->w, window->h, bpp, Rmask, Gmask,
104 Bmask, Amask); 104 Bmask, Amask);
105 if (!data->screen) { 105 if (!data->surface) {
106 SDL_DUMMY_DestroyRenderer(renderer); 106 SDL_DUMMY_DestroyRenderer(renderer);
107 return NULL; 107 return NULL;
108 } 108 }
109 109
110 /* If the display has a palette, use it for the window surfaces */
111 if (window->display->palette.ncolors) {
112 SDL_PixelFormat *format = data->surface->format;
113 if (format->palette->colors) {
114 SDL_free(format->palette->colors);
115 }
116 SDL_free(format->palette);
117 format->palette = &window->display->palette;
118 }
119
110 return renderer; 120 return renderer;
111 } 121 }
112 122
113 int 123 int
114 SDL_DUMMY_RenderReadPixels(SDL_Renderer * renderer, SDL_Rect * rect, 124 SDL_DUMMY_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
115 void *pixels, int pitch) 125 void *pixels, int pitch)
116 { 126 {
117 SDL_DUMMY_RenderData *data = 127 SDL_DUMMY_RenderData *data =
118 (SDL_DUMMY_RenderData *) renderer->driverdata; 128 (SDL_DUMMY_RenderData *) renderer->driverdata;
119 SDL_Surface *surface = data->screen; 129 SDL_Surface *surface = data->surface;
120 Uint8 *src, *dst; 130 Uint8 *src, *dst;
121 int row; 131 int row;
122 size_t length; 132 size_t length;
123 133
124 src = 134 src =
133 } 143 }
134 return 0; 144 return 0;
135 } 145 }
136 146
137 int 147 int
138 SDL_DUMMY_RenderWritePixels(SDL_Renderer * renderer, SDL_Rect * rect, 148 SDL_DUMMY_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect,
139 const void *pixels, int pitch) 149 const void *pixels, int pitch)
140 { 150 {
141 SDL_DUMMY_RenderData *data = 151 SDL_DUMMY_RenderData *data =
142 (SDL_DUMMY_RenderData *) renderer->driverdata; 152 (SDL_DUMMY_RenderData *) renderer->driverdata;
143 SDL_Surface *surface = data->screen; 153 SDL_Surface *surface = data->surface;
144 Uint8 *src, *dst; 154 Uint8 *src, *dst;
145 int row; 155 int row;
146 size_t length; 156 size_t length;
147 157
148 src = (Uint8 *) pixels; 158 src = (Uint8 *) pixels;
162 SDL_DUMMY_RenderPresent(SDL_Renderer * renderer) 172 SDL_DUMMY_RenderPresent(SDL_Renderer * renderer)
163 { 173 {
164 static int frame_number; 174 static int frame_number;
165 SDL_DUMMY_RenderData *data = 175 SDL_DUMMY_RenderData *data =
166 (SDL_DUMMY_RenderData *) renderer->driverdata; 176 (SDL_DUMMY_RenderData *) renderer->driverdata;
167 SDL_Surface *surface = data->screen; 177 SDL_Surface *surface = data->surface;
168 178
169 if (SDL_getenv("SDL_VIDEO_DUMMY_SAVE_FRAMES")) { 179 if (SDL_getenv("SDL_VIDEO_DUMMY_SAVE_FRAMES")) {
170 char file[128]; 180 char file[128];
171 SDL_snprintf(file, sizeof(file), "SDL_frame-%8.8d.bmp", 181 SDL_snprintf(file, sizeof(file), "SDL_frame-%8.8d.bmp",
172 ++frame_number); 182 ++frame_number);
179 { 189 {
180 SDL_DUMMY_RenderData *data = 190 SDL_DUMMY_RenderData *data =
181 (SDL_DUMMY_RenderData *) renderer->driverdata; 191 (SDL_DUMMY_RenderData *) renderer->driverdata;
182 192
183 if (data) { 193 if (data) {
184 if (data->screen) { 194 if (data->surface) {
185 SDL_FreeSurface(data->screen); 195 data->surface->format->palette = NULL;
196 SDL_FreeSurface(data->surface);
186 } 197 }
187 SDL_free(data); 198 SDL_free(data);
188 } 199 }
189 SDL_free(renderer); 200 SDL_free(renderer);
190 } 201 }