comparison src/video/SDL_renderer_sw.c @ 1735:8dd28c4ef746 SDL-1.3

SDL_Rect now uses int for position and size. Added a few more rectangle functions. Added a dirty rectangle list implementation.
author Sam Lantinga <slouken@libsdl.org>
date Mon, 10 Jul 2006 07:34:50 +0000
parents a1ebb17f9c52
children
comparison
equal deleted inserted replaced
1734:f7c667ded87d 1735:8dd28c4ef746
21 */ 21 */
22 #include "SDL_config.h" 22 #include "SDL_config.h"
23 23
24 #include "SDL_video.h" 24 #include "SDL_video.h"
25 #include "SDL_sysvideo.h" 25 #include "SDL_sysvideo.h"
26 #include "SDL_rect_c.h"
26 #include "SDL_yuv_sw_c.h" 27 #include "SDL_yuv_sw_c.h"
27 28
28 29
29 /* SDL surface based renderer implementation */ 30 /* SDL surface based renderer implementation */
30 31
94 SDL_PixelFormat_RGBA8888, 95 SDL_PixelFormat_RGBA8888,
95 SDL_PixelFormat_ABGR8888, 96 SDL_PixelFormat_ABGR8888,
96 SDL_PixelFormat_BGRA8888, 97 SDL_PixelFormat_BGRA8888,
97 SDL_PixelFormat_YUY2, 98 SDL_PixelFormat_YUY2,
98 SDL_PixelFormat_UYVY}, 99 SDL_PixelFormat_UYVY},
99 32768, 100 0,
100 32768} 101 0}
101 }; 102 };
102 103
103 typedef struct 104 typedef struct
104 { 105 {
105 int current_screen; 106 int current_screen;
106 SDL_Surface *screens[3]; 107 SDL_Surface *screens[3];
107 SDL_Surface *target; 108 SDL_Surface *target;
108 SDL_Renderer *renderer; 109 SDL_Renderer *renderer;
110 SDL_DirtyRectList dirty;
109 } SDL_SW_RenderData; 111 } SDL_SW_RenderData;
110 112
111 SDL_Renderer * 113 SDL_Renderer *
112 SDL_SW_CreateRenderer(SDL_Window * window, Uint32 flags) 114 SDL_SW_CreateRenderer(SDL_Window * window, Uint32 flags)
113 { 115 {
123 (displayMode->format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) { 125 (displayMode->format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) {
124 SDL_SetError("Unknown display format"); 126 SDL_SetError("Unknown display format");
125 return NULL; 127 return NULL;
126 } 128 }
127 129
128 renderer = (SDL_Renderer *) SDL_malloc(sizeof(*renderer)); 130 renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
129 if (!renderer) { 131 if (!renderer) {
130 SDL_OutOfMemory(); 132 SDL_OutOfMemory();
131 return NULL; 133 return NULL;
132 } 134 }
133 SDL_zerop(renderer);
134 135
135 data = (SDL_SW_RenderData *) SDL_malloc(sizeof(*data)); 136 data = (SDL_SW_RenderData *) SDL_malloc(sizeof(*data));
136 if (!data) { 137 if (!data) {
137 SDL_SW_DestroyRenderer(renderer); 138 SDL_SW_DestroyRenderer(renderer);
138 SDL_OutOfMemory(); 139 SDL_OutOfMemory();
361 { 362 {
362 SDL_SW_RenderData *data = (SDL_SW_RenderData *) renderer->driverdata; 363 SDL_SW_RenderData *data = (SDL_SW_RenderData *) renderer->driverdata;
363 SDL_Rect real_rect = *rect; 364 SDL_Rect real_rect = *rect;
364 Uint8 r, g, b, a; 365 Uint8 r, g, b, a;
365 366
367 SDL_AddDirtyRect(&data->dirty, rect);
368
366 a = (Uint8) ((color >> 24) & 0xFF); 369 a = (Uint8) ((color >> 24) & 0xFF);
367 r = (Uint8) ((color >> 16) & 0xFF); 370 r = (Uint8) ((color >> 16) & 0xFF);
368 g = (Uint8) ((color >> 8) & 0xFF); 371 g = (Uint8) ((color >> 8) & 0xFF);
369 b = (Uint8) (color & 0xFF); 372 b = (Uint8) (color & 0xFF);
370 color = SDL_MapRGBA(data->target->format, r, g, b, a); 373 color = SDL_MapRGBA(data->target->format, r, g, b, a);
378 int blendMode, int scaleMode) 381 int blendMode, int scaleMode)
379 { 382 {
380 SDL_SW_RenderData *data = (SDL_SW_RenderData *) renderer->driverdata; 383 SDL_SW_RenderData *data = (SDL_SW_RenderData *) renderer->driverdata;
381 SDL_Window *window = SDL_GetWindowFromID(renderer->window); 384 SDL_Window *window = SDL_GetWindowFromID(renderer->window);
382 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window); 385 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
386
387 SDL_AddDirtyRect(&data->dirty, dstrect);
383 388
384 if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) { 389 if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
385 SDL_Surface *target = data->target; 390 SDL_Surface *target = data->target;
386 void *pixels = 391 void *pixels =
387 (Uint8 *) target->pixels + dstrect->y * target->pitch + 392 (Uint8 *) target->pixels + dstrect->y * target->pitch +
443 SDL_Surface *surface = data->target; 448 SDL_Surface *surface = data->target;
444 Uint8 *src, *dst; 449 Uint8 *src, *dst;
445 int row; 450 int row;
446 size_t length; 451 size_t length;
447 452
453 SDL_AddDirtyRect(&data->dirty, rect);
454
448 src = (Uint8 *) pixels; 455 src = (Uint8 *) pixels;
449 dst = 456 dst =
450 (Uint8 *) surface->pixels + rect->y * surface->pitch + 457 (Uint8 *) surface->pixels + rect->y * surface->pitch +
451 rect->x * surface->format->BytesPerPixel; 458 rect->x * surface->format->BytesPerPixel;
452 length = rect->w * surface->format->BytesPerPixel; 459 length = rect->w * surface->format->BytesPerPixel;
461 static void 468 static void
462 SDL_SW_RenderPresent(SDL_Renderer * renderer) 469 SDL_SW_RenderPresent(SDL_Renderer * renderer)
463 { 470 {
464 SDL_SW_RenderData *data = (SDL_SW_RenderData *) renderer->driverdata; 471 SDL_SW_RenderData *data = (SDL_SW_RenderData *) renderer->driverdata;
465 SDL_Surface *surface = data->screens[data->current_screen]; 472 SDL_Surface *surface = data->screens[data->current_screen];
466 SDL_Rect rect; 473 SDL_DirtyRect *dirty;
467 int new_screen; 474 int new_screen;
468 475
469 /* Send the data to the display */ 476 /* Send the data to the display */
470 /* FIXME: implement dirty rect updates */ 477 for (dirty = data->dirty.list; dirty; dirty = dirty->next) {
471 rect.x = 0; 478 void *pixels =
472 rect.y = 0; 479 (void *) ((Uint8 *) surface->pixels +
473 rect.w = surface->w; 480 dirty->rect.y * surface->pitch +
474 rect.h = surface->h; 481 dirty->rect.x * surface->format->BytesPerPixel);
475 data->renderer->RenderWritePixels(data->renderer, &rect, surface->pixels, 482 data->renderer->RenderWritePixels(data->renderer, &dirty->rect,
476 surface->pitch); 483 pixels, surface->pitch);
484 }
485 SDL_ClearDirtyRects(&data->dirty);
477 data->renderer->RenderPresent(data->renderer); 486 data->renderer->RenderPresent(data->renderer);
487
478 488
479 /* Update the flipping chain, if any */ 489 /* Update the flipping chain, if any */
480 if (renderer->info.flags & SDL_Renderer_PresentFlip2) { 490 if (renderer->info.flags & SDL_Renderer_PresentFlip2) {
481 new_screen = (data->current_screen + 1) % 2; 491 new_screen = (data->current_screen + 1) % 2;
482 } else if (renderer->info.flags & SDL_Renderer_PresentFlip3) { 492 } else if (renderer->info.flags & SDL_Renderer_PresentFlip3) {
512 for (i = 0; i < SDL_arraysize(data->screens); ++i) { 522 for (i = 0; i < SDL_arraysize(data->screens); ++i) {
513 if (data->screens[i]) { 523 if (data->screens[i]) {
514 SDL_FreeSurface(data->screens[i]); 524 SDL_FreeSurface(data->screens[i]);
515 } 525 }
516 } 526 }
527 SDL_FreeDirtyRects(&data->dirty);
517 SDL_free(data); 528 SDL_free(data);
518 } 529 }
519 SDL_free(renderer); 530 SDL_free(renderer);
520 } 531 }
521 532