comparison src/video/SDL_renderer_sw.c @ 2227:b252359547ed

Exported the software renderer texture functions to make easier to create a renderer based on a framebuffer. Fixed an initialization bug with the dummy video display mode.
author Sam Lantinga <slouken@libsdl.org>
date Sat, 11 Aug 2007 23:26:03 +0000
parents 926294b2bb4e
children bee005ace1bf
comparison
equal deleted inserted replaced
2226:0e70b4b8cf84 2227:b252359547ed
159 } 159 }
160 } 160 }
161 return 0; 161 return 0;
162 } 162 }
163 163
164 SDL_Renderer * 164 void
165 SW_CreateRenderer(SDL_Window * window, Uint32 flags) 165 Setup_SoftwareRenderer(SDL_Renderer * renderer)
166 { 166 {
167 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
168 SDL_DisplayMode *displayMode = &display->current_mode;
169 SDL_Renderer *renderer;
170 SW_RenderData *data;
171 int i, n;
172 int bpp;
173 Uint32 Rmask, Gmask, Bmask, Amask;
174 Uint32 renderer_flags;
175 const char *desired_driver;
176
177 if (!SDL_PixelFormatEnumToMasks
178 (displayMode->format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) {
179 SDL_SetError("Unknown display format");
180 return NULL;
181 }
182
183 renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
184 if (!renderer) {
185 SDL_OutOfMemory();
186 return NULL;
187 }
188
189 data = (SW_RenderData *) SDL_calloc(1, sizeof(*data));
190 if (!data) {
191 SW_DestroyRenderer(renderer);
192 SDL_OutOfMemory();
193 return NULL;
194 }
195 renderer->ActivateRenderer = SW_ActivateRenderer;
196 renderer->DisplayModeChanged = SW_DisplayModeChanged;
197 renderer->CreateTexture = SW_CreateTexture; 167 renderer->CreateTexture = SW_CreateTexture;
198 renderer->QueryTexturePixels = SW_QueryTexturePixels; 168 renderer->QueryTexturePixels = SW_QueryTexturePixels;
199 renderer->SetTexturePalette = SW_SetTexturePalette; 169 renderer->SetTexturePalette = SW_SetTexturePalette;
200 renderer->GetTexturePalette = SW_GetTexturePalette; 170 renderer->GetTexturePalette = SW_GetTexturePalette;
201 renderer->SetTextureColorMod = SW_SetTextureColorMod; 171 renderer->SetTextureColorMod = SW_SetTextureColorMod;
204 renderer->SetTextureScaleMode = SW_SetTextureScaleMode; 174 renderer->SetTextureScaleMode = SW_SetTextureScaleMode;
205 renderer->UpdateTexture = SW_UpdateTexture; 175 renderer->UpdateTexture = SW_UpdateTexture;
206 renderer->LockTexture = SW_LockTexture; 176 renderer->LockTexture = SW_LockTexture;
207 renderer->UnlockTexture = SW_UnlockTexture; 177 renderer->UnlockTexture = SW_UnlockTexture;
208 renderer->DirtyTexture = SW_DirtyTexture; 178 renderer->DirtyTexture = SW_DirtyTexture;
179 renderer->DestroyTexture = SW_DestroyTexture;
180
181 renderer->info.mod_modes = SW_RenderDriver.info.mod_modes;
182 renderer->info.blend_modes = SW_RenderDriver.info.blend_modes;
183 renderer->info.scale_modes = SW_RenderDriver.info.scale_modes;
184 renderer->info.num_texture_formats =
185 SW_RenderDriver.info.num_texture_formats;
186 SDL_memcpy(renderer->info.texture_formats,
187 SW_RenderDriver.info.texture_formats,
188 sizeof(renderer->info.texture_formats));;
189 renderer->info.max_texture_width = SW_RenderDriver.info.max_texture_width;
190 renderer->info.max_texture_height =
191 SW_RenderDriver.info.max_texture_height;
192 }
193
194 SDL_Renderer *
195 SW_CreateRenderer(SDL_Window * window, Uint32 flags)
196 {
197 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
198 SDL_DisplayMode *displayMode = &display->current_mode;
199 SDL_Renderer *renderer;
200 SW_RenderData *data;
201 int i, n;
202 int bpp;
203 Uint32 Rmask, Gmask, Bmask, Amask;
204 Uint32 renderer_flags;
205 const char *desired_driver;
206
207 if (!SDL_PixelFormatEnumToMasks
208 (displayMode->format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) {
209 SDL_SetError("Unknown display format");
210 return NULL;
211 }
212
213 renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
214 if (!renderer) {
215 SDL_OutOfMemory();
216 return NULL;
217 }
218
219 data = (SW_RenderData *) SDL_calloc(1, sizeof(*data));
220 if (!data) {
221 SW_DestroyRenderer(renderer);
222 SDL_OutOfMemory();
223 return NULL;
224 }
225 renderer->ActivateRenderer = SW_ActivateRenderer;
226 renderer->DisplayModeChanged = SW_DisplayModeChanged;
209 renderer->RenderFill = SW_RenderFill; 227 renderer->RenderFill = SW_RenderFill;
210 renderer->RenderCopy = SW_RenderCopy; 228 renderer->RenderCopy = SW_RenderCopy;
211 renderer->RenderPresent = SW_RenderPresent; 229 renderer->RenderPresent = SW_RenderPresent;
212 renderer->DestroyTexture = SW_DestroyTexture;
213 renderer->DestroyRenderer = SW_DestroyRenderer; 230 renderer->DestroyRenderer = SW_DestroyRenderer;
214 renderer->info = SW_RenderDriver.info; 231 renderer->info.name = SW_RenderDriver.info.name;
232 renderer->info.flags = 0;
215 renderer->window = window->id; 233 renderer->window = window->id;
216 renderer->driverdata = data; 234 renderer->driverdata = data;
217 235 Setup_SoftwareRenderer(renderer);
218 renderer->info.flags = 0;
219 236
220 if (flags & SDL_RENDERER_PRESENTFLIP2) { 237 if (flags & SDL_RENDERER_PRESENTFLIP2) {
221 renderer->info.flags |= SDL_RENDERER_PRESENTFLIP2; 238 renderer->info.flags |= SDL_RENDERER_PRESENTFLIP2;
222 n = 2; 239 n = 2;
223 } else if (flags & SDL_RENDERER_PRESENTFLIP3) { 240 } else if (flags & SDL_RENDERER_PRESENTFLIP3) {
415 } 432 }
416 433
417 static void 434 static void
418 SW_UpdateRenderCopyFunc(SDL_Renderer * renderer, SDL_Texture * texture) 435 SW_UpdateRenderCopyFunc(SDL_Renderer * renderer, SDL_Texture * texture)
419 { 436 {
420 SW_RenderData *data = (SW_RenderData *) renderer->driverdata; 437 SDL_Window *window = SDL_GetWindowFromID(renderer->window);
438 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
439 SDL_DisplayMode *displayMode = &display->current_mode;
421 SDL_Surface *surface = (SDL_Surface *) texture->driverdata; 440 SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
422 441
423 /* We only need a special copy function for advanced features */ 442 /* We only need a special copy function for advanced features */
424 if (texture->modMode 443 if (texture->modMode
425 || (texture-> 444 || (texture->
426 blendMode & (SDL_TEXTUREBLENDMODE_ADD | SDL_TEXTUREBLENDMODE_MOD)) 445 blendMode & (SDL_TEXTUREBLENDMODE_ADD | SDL_TEXTUREBLENDMODE_MOD))
427 || texture->scaleMode) { 446 || texture->scaleMode) {
428 surface->userdata = 447 surface->userdata =
429 SDL_GetRenderCopyFunc(texture->format, data->format, 448 SDL_GetRenderCopyFunc(texture->format, displayMode->format,
430 texture->modMode, texture->blendMode, 449 texture->modMode, texture->blendMode,
431 texture->scaleMode); 450 texture->scaleMode);
432 } else { 451 } else {
433 surface->userdata = NULL; 452 surface->userdata = NULL;
434 } 453 }