comparison src/video/dummy/SDL_nullrender.c @ 1912:8d384b647307

Setting up the OpenGL support
author Sam Lantinga <slouken@libsdl.org>
date Sun, 16 Jul 2006 09:34:01 +0000
parents e079dafea2bf
children a788656ca29a
comparison
equal deleted inserted replaced
1911:7577fd11cee4 1912:8d384b647307
26 #include "../SDL_yuv_sw_c.h" 26 #include "../SDL_yuv_sw_c.h"
27 27
28 28
29 /* SDL surface based renderer implementation */ 29 /* SDL surface based renderer implementation */
30 30
31 static SDL_Renderer *SDL_DUMMY_CreateRenderer(SDL_Window * window, Uint32 flags); 31 static SDL_Renderer *SDL_DUMMY_CreateRenderer(SDL_Window * window,
32 Uint32 flags);
32 static int SDL_DUMMY_CreateTexture(SDL_Renderer * renderer, 33 static int SDL_DUMMY_CreateTexture(SDL_Renderer * renderer,
33 SDL_Texture * texture); 34 SDL_Texture * texture);
34 static int SDL_DUMMY_QueryTexturePixels(SDL_Renderer * renderer, 35 static int SDL_DUMMY_QueryTexturePixels(SDL_Renderer * renderer,
35 SDL_Texture * texture, void **pixels, 36 SDL_Texture * texture, void **pixels,
36 int *pitch); 37 int *pitch);
37 static int SDL_DUMMY_SetTexturePalette(SDL_Renderer * renderer, 38 static int SDL_DUMMY_SetTexturePalette(SDL_Renderer * renderer,
38 SDL_Texture * texture, 39 SDL_Texture * texture,
39 const SDL_Color * colors, int firstcolor, 40 const SDL_Color * colors,
40 int ncolors); 41 int firstcolor, int ncolors);
41 static int SDL_DUMMY_GetTexturePalette(SDL_Renderer * renderer, 42 static int SDL_DUMMY_GetTexturePalette(SDL_Renderer * renderer,
42 SDL_Texture * texture, SDL_Color * colors, 43 SDL_Texture * texture,
43 int firstcolor, int ncolors); 44 SDL_Color * colors, int firstcolor,
45 int ncolors);
44 static int SDL_DUMMY_UpdateTexture(SDL_Renderer * renderer, 46 static int SDL_DUMMY_UpdateTexture(SDL_Renderer * renderer,
45 SDL_Texture * texture, const SDL_Rect * rect, 47 SDL_Texture * texture,
46 const void *pixels, int pitch); 48 const SDL_Rect * rect, const void *pixels,
47 static int SDL_DUMMY_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, 49 int pitch);
48 const SDL_Rect * rect, int markDirty, 50 static int SDL_DUMMY_LockTexture(SDL_Renderer * renderer,
49 void **pixels, int *pitch); 51 SDL_Texture * texture, const SDL_Rect * rect,
52 int markDirty, void **pixels, int *pitch);
50 static void SDL_DUMMY_UnlockTexture(SDL_Renderer * renderer, 53 static void SDL_DUMMY_UnlockTexture(SDL_Renderer * renderer,
51 SDL_Texture * texture); 54 SDL_Texture * texture);
52 static void SDL_DUMMY_DirtyTexture(SDL_Renderer * renderer, 55 static void SDL_DUMMY_DirtyTexture(SDL_Renderer * renderer,
53 SDL_Texture * texture, int numrects, 56 SDL_Texture * texture, int numrects,
54 const SDL_Rect * rects); 57 const SDL_Rect * rects);
55 static void SDL_DUMMY_SelectRenderTexture(SDL_Renderer * renderer, 58 static void SDL_DUMMY_SelectRenderTexture(SDL_Renderer * renderer,
56 SDL_Texture * texture); 59 SDL_Texture * texture);
57 static int SDL_DUMMY_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect, 60 static int SDL_DUMMY_RenderFill(SDL_Renderer * renderer,
58 Uint32 color); 61 const SDL_Rect * rect, Uint32 color);
59 static int SDL_DUMMY_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, 62 static int SDL_DUMMY_RenderCopy(SDL_Renderer * renderer,
60 const SDL_Rect * srcrect, 63 SDL_Texture * texture,
61 const SDL_Rect * dstrect, int blendMode, 64 const SDL_Rect * srcrect,
62 int scaleMode); 65 const SDL_Rect * dstrect, int blendMode,
66 int scaleMode);
63 static int SDL_DUMMY_RenderReadPixels(SDL_Renderer * renderer, 67 static int SDL_DUMMY_RenderReadPixels(SDL_Renderer * renderer,
64 const SDL_Rect * rect, void *pixels, 68 const SDL_Rect * rect, void *pixels,
65 int pitch); 69 int pitch);
66 static int SDL_DUMMY_RenderWritePixels(SDL_Renderer * renderer, 70 static int SDL_DUMMY_RenderWritePixels(SDL_Renderer * renderer,
67 const SDL_Rect * rect, const void *pixels, 71 const SDL_Rect * rect,
68 int pitch); 72 const void *pixels, int pitch);
69 static void SDL_DUMMY_RenderPresent(SDL_Renderer * renderer); 73 static void SDL_DUMMY_RenderPresent(SDL_Renderer * renderer);
70 static void SDL_DUMMY_DestroyTexture(SDL_Renderer * renderer, 74 static void SDL_DUMMY_DestroyTexture(SDL_Renderer * renderer,
71 SDL_Texture * texture); 75 SDL_Texture * texture);
72 static void SDL_DUMMY_DestroyRenderer(SDL_Renderer * renderer); 76 static void SDL_DUMMY_DestroyRenderer(SDL_Renderer * renderer);
73 77
74 78
75 SDL_RenderDriver SDL_DUMMY_RenderDriver = { 79 SDL_RenderDriver SDL_DUMMY_RenderDriver = {
76 SDL_DUMMY_CreateRenderer, 80 SDL_DUMMY_CreateRenderer,
193 (texture->format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) { 197 (texture->format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) {
194 SDL_SetError("Unknown texture format"); 198 SDL_SetError("Unknown texture format");
195 return -1; 199 return -1;
196 } 200 }
197 201
198 texture->driverdata = SDL_CreateRGBSurface(0, texture->w, texture->h, bpp, Rmask, Gmask, Bmask, Amask); 202 texture->driverdata =
203 SDL_CreateRGBSurface(0, texture->w, texture->h, bpp, Rmask, Gmask,
204 Bmask, Amask);
199 } 205 }
200 206
201 if (!texture->driverdata) { 207 if (!texture->driverdata) {
202 return -1; 208 return -1;
203 } 209 }
204 return 0; 210 return 0;
205 } 211 }
206 212
207 static int 213 static int
208 SDL_DUMMY_QueryTexturePixels(SDL_Renderer * renderer, SDL_Texture * texture, 214 SDL_DUMMY_QueryTexturePixels(SDL_Renderer * renderer, SDL_Texture * texture,
209 void **pixels, int *pitch) 215 void **pixels, int *pitch)
210 { 216 {
211 if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) { 217 if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
212 return SDL_SW_QueryYUVTexturePixels((SDL_SW_YUVTexture *) texture->driverdata, pixels, pitch); 218 return SDL_SW_QueryYUVTexturePixels((SDL_SW_YUVTexture *) texture->
219 driverdata, pixels, pitch);
213 } else { 220 } else {
214 SDL_Surface *surface = (SDL_Surface *) texture->driverdata; 221 SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
215 222
216 *pixels = surface->pixels; 223 *pixels = surface->pixels;
217 *pitch = surface->pitch; 224 *pitch = surface->pitch;
219 } 226 }
220 } 227 }
221 228
222 static int 229 static int
223 SDL_DUMMY_SetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture, 230 SDL_DUMMY_SetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture,
224 const SDL_Color * colors, int firstcolor, 231 const SDL_Color * colors, int firstcolor,
225 int ncolors) 232 int ncolors)
226 { 233 {
227 if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) { 234 if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
228 SDL_SetError("YUV textures don't have a palette"); 235 SDL_SetError("YUV textures don't have a palette");
229 return -1; 236 return -1;
230 } else { 237 } else {
235 } 242 }
236 } 243 }
237 244
238 static int 245 static int
239 SDL_DUMMY_GetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture, 246 SDL_DUMMY_GetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture,
240 SDL_Color * colors, int firstcolor, int ncolors) 247 SDL_Color * colors, int firstcolor, int ncolors)
241 { 248 {
242 if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) { 249 if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
243 SDL_SetError("YUV textures don't have a palette"); 250 SDL_SetError("YUV textures don't have a palette");
244 return -1; 251 return -1;
245 } else { 252 } else {
251 } 258 }
252 } 259 }
253 260
254 static int 261 static int
255 SDL_DUMMY_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, 262 SDL_DUMMY_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
256 const SDL_Rect * rect, const void *pixels, int pitch) 263 const SDL_Rect * rect, const void *pixels, int pitch)
257 { 264 {
258 if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) { 265 if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
259 return SDL_SW_UpdateYUVTexture((SDL_SW_YUVTexture *) texture-> 266 return SDL_SW_UpdateYUVTexture((SDL_SW_YUVTexture *) texture->
260 driverdata, rect, pixels, pitch); 267 driverdata, rect, pixels, pitch);
261 } else { 268 } else {
278 } 285 }
279 } 286 }
280 287
281 static int 288 static int
282 SDL_DUMMY_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, 289 SDL_DUMMY_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
283 const SDL_Rect * rect, int markDirty, void **pixels, 290 const SDL_Rect * rect, int markDirty, void **pixels,
284 int *pitch) 291 int *pitch)
285 { 292 {
286 if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) { 293 if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
287 return SDL_SW_LockYUVTexture((SDL_SW_YUVTexture *) texture-> 294 return SDL_SW_LockYUVTexture((SDL_SW_YUVTexture *) texture->
288 driverdata, rect, markDirty, pixels, 295 driverdata, rect, markDirty, pixels,
289 pitch); 296 pitch);
306 } 313 }
307 } 314 }
308 315
309 static void 316 static void
310 SDL_DUMMY_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture, 317 SDL_DUMMY_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture,
311 int numrects, const SDL_Rect * rects) 318 int numrects, const SDL_Rect * rects)
312 { 319 {
313 } 320 }
314 321
315 static int 322 static int
316 SDL_DUMMY_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect, 323 SDL_DUMMY_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect,
317 Uint32 color) 324 Uint32 color)
318 { 325 {
319 SDL_DUMMY_RenderData *data = (SDL_DUMMY_RenderData *) renderer->driverdata; 326 SDL_DUMMY_RenderData *data =
327 (SDL_DUMMY_RenderData *) renderer->driverdata;
320 SDL_Surface *target = data->screens[data->current_screen]; 328 SDL_Surface *target = data->screens[data->current_screen];
321 SDL_Rect real_rect = *rect; 329 SDL_Rect real_rect = *rect;
322 Uint8 r, g, b, a; 330 Uint8 r, g, b, a;
323 331
324 a = (Uint8) ((color >> 24) & 0xFF); 332 a = (Uint8) ((color >> 24) & 0xFF);
330 return SDL_FillRect(target, &real_rect, color); 338 return SDL_FillRect(target, &real_rect, color);
331 } 339 }
332 340
333 static int 341 static int
334 SDL_DUMMY_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, 342 SDL_DUMMY_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
335 const SDL_Rect * srcrect, const SDL_Rect * dstrect, 343 const SDL_Rect * srcrect, const SDL_Rect * dstrect,
336 int blendMode, int scaleMode) 344 int blendMode, int scaleMode)
337 { 345 {
338 SDL_DUMMY_RenderData *data = (SDL_DUMMY_RenderData *) renderer->driverdata; 346 SDL_DUMMY_RenderData *data =
347 (SDL_DUMMY_RenderData *) renderer->driverdata;
339 SDL_Window *window = SDL_GetWindowFromID(renderer->window); 348 SDL_Window *window = SDL_GetWindowFromID(renderer->window);
340 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window); 349 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
341 350
342 if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) { 351 if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
343 SDL_Surface *target = data->screens[data->current_screen]; 352 SDL_Surface *target = data->screens[data->current_screen];
360 } else { 369 } else {
361 SDL_SetAlpha(surface, 0, 0); 370 SDL_SetAlpha(surface, 0, 0);
362 } 371 }
363 if (scaleMode != SDL_TextureScaleMode_None && 372 if (scaleMode != SDL_TextureScaleMode_None &&
364 (srcrect->w != dstrect->w || srcrect->h != dstrect->h)) { 373 (srcrect->w != dstrect->w || srcrect->h != dstrect->h)) {
365 return SDL_SoftStretch(surface, &real_srcrect, target, &real_dstrect); 374 return SDL_SoftStretch(surface, &real_srcrect, target,
375 &real_dstrect);
366 } else { 376 } else {
367 return SDL_LowerBlit(surface, &real_srcrect, target, &real_dstrect); 377 return SDL_LowerBlit(surface, &real_srcrect, target,
378 &real_dstrect);
368 } 379 }
369 } 380 }
370 } 381 }
371 382
372 static void 383 static void
373 SDL_DUMMY_RenderPresent(SDL_Renderer * renderer) 384 SDL_DUMMY_RenderPresent(SDL_Renderer * renderer)
374 { 385 {
375 static int frame_number; 386 static int frame_number;
376 SDL_DUMMY_RenderData *data = (SDL_DUMMY_RenderData *) renderer->driverdata; 387 SDL_DUMMY_RenderData *data =
388 (SDL_DUMMY_RenderData *) renderer->driverdata;
377 389
378 /* Send the data to the display */ 390 /* Send the data to the display */
379 if (SDL_getenv("SDL_VIDEO_DUMMY_SAVE_FRAMES")) { 391 if (SDL_getenv("SDL_VIDEO_DUMMY_SAVE_FRAMES")) {
380 char file[128]; 392 char file[128];
381 SDL_snprintf(file, sizeof(file), "SDL_window%d-%8.8d.bmp", 393 SDL_snprintf(file, sizeof(file), "SDL_window%d-%8.8d.bmp",
404 } 416 }
405 417
406 static void 418 static void
407 SDL_DUMMY_DestroyRenderer(SDL_Renderer * renderer) 419 SDL_DUMMY_DestroyRenderer(SDL_Renderer * renderer)
408 { 420 {
409 SDL_DUMMY_RenderData *data = (SDL_DUMMY_RenderData *) renderer->driverdata; 421 SDL_DUMMY_RenderData *data =
422 (SDL_DUMMY_RenderData *) renderer->driverdata;
410 int i; 423 int i;
411 424
412 if (data) { 425 if (data) {
413 for (i = 0; i < SDL_arraysize(data->screens); ++i) { 426 for (i = 0; i < SDL_arraysize(data->screens); ++i) {
414 if (data->screens[i]) { 427 if (data->screens[i]) {