comparison src/video/SDL_renderer_sw.c @ 2267:c785543d1843

Okay, still some bugs, but everything builds again...
author Sam Lantinga <slouken@libsdl.org>
date Sat, 18 Aug 2007 05:39:09 +0000
parents bee005ace1bf
children e1da92da346c
comparison
equal deleted inserted replaced
2266:e61ad15a205f 2267:c785543d1843
24 #include "SDL_video.h" 24 #include "SDL_video.h"
25 #include "SDL_sysvideo.h" 25 #include "SDL_sysvideo.h"
26 #include "SDL_pixels_c.h" 26 #include "SDL_pixels_c.h"
27 #include "SDL_rect_c.h" 27 #include "SDL_rect_c.h"
28 #include "SDL_yuv_sw_c.h" 28 #include "SDL_yuv_sw_c.h"
29 #include "SDL_rendercopy.h"
30 29
31 30
32 /* SDL surface based renderer implementation */ 31 /* SDL surface based renderer implementation */
33 32
34 static SDL_Renderer *SW_CreateRenderer(SDL_Window * window, Uint32 flags); 33 static SDL_Renderer *SW_CreateRenderer(SDL_Window * window, Uint32 flags);
429 ncolors * sizeof(*colors)); 428 ncolors * sizeof(*colors));
430 return 0; 429 return 0;
431 } 430 }
432 } 431 }
433 432
434 static void 433 static int
435 SW_UpdateRenderCopyFunc(SDL_Renderer * renderer, SDL_Texture * texture) 434 SW_SetTextureColorMod(SDL_Renderer * renderer, SDL_Texture * texture)
436 { 435 {
437 SDL_Window *window = SDL_GetWindowFromID(renderer->window);
438 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
439 SDL_DisplayMode *displayMode = &display->current_mode;
440 SDL_Surface *surface = (SDL_Surface *) texture->driverdata; 436 SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
441 437 return SDL_SetSurfaceColorMod(surface, texture->r, texture->g,
442 /* We only need a special copy function for advanced features */ 438 texture->b);
443 if (texture->modMode
444 || (texture->
445 blendMode & (SDL_TEXTUREBLENDMODE_ADD | SDL_TEXTUREBLENDMODE_MOD))
446 || texture->scaleMode) {
447 surface->userdata =
448 SDL_GetRenderCopyFunc(texture->format, displayMode->format,
449 texture->modMode, texture->blendMode,
450 texture->scaleMode);
451 } else {
452 surface->userdata = NULL;
453 }
454 }
455
456 static int
457 SW_SetTextureColorMod(SDL_Renderer * renderer, SDL_Texture * texture)
458 {
459 SW_UpdateRenderCopyFunc(renderer, texture);
460 return 0;
461 } 439 }
462 440
463 static int 441 static int
464 SW_SetTextureAlphaMod(SDL_Renderer * renderer, SDL_Texture * texture) 442 SW_SetTextureAlphaMod(SDL_Renderer * renderer, SDL_Texture * texture)
465 { 443 {
466 SW_UpdateRenderCopyFunc(renderer, texture); 444 SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
467 return 0; 445 return SDL_SetSurfaceAlphaMod(surface, texture->a);
468 } 446 }
469 447
470 static int 448 static int
471 SW_SetTextureBlendMode(SDL_Renderer * renderer, SDL_Texture * texture) 449 SW_SetTextureBlendMode(SDL_Renderer * renderer, SDL_Texture * texture)
472 { 450 {
473 switch (texture->blendMode) { 451 SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
474 case SDL_TEXTUREBLENDMODE_NONE: 452 return SDL_SetSurfaceBlendMode(surface, texture->blendMode);
475 case SDL_TEXTUREBLENDMODE_MASK:
476 case SDL_TEXTUREBLENDMODE_BLEND:
477 case SDL_TEXTUREBLENDMODE_ADD:
478 case SDL_TEXTUREBLENDMODE_MOD:
479 SW_UpdateRenderCopyFunc(renderer, texture);
480 return 0;
481 default:
482 SDL_Unsupported();
483 texture->blendMode = SDL_TEXTUREBLENDMODE_NONE;
484 SW_UpdateRenderCopyFunc(renderer, texture);
485 return -1;
486 }
487 } 453 }
488 454
489 static int 455 static int
490 SW_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture) 456 SW_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture)
491 { 457 {
492 switch (texture->scaleMode) { 458 SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
493 case SDL_TEXTURESCALEMODE_NONE: 459 return SDL_SetSurfaceBlendMode(surface, texture->scaleMode);
494 case SDL_TEXTURESCALEMODE_FAST:
495 SW_UpdateRenderCopyFunc(renderer, texture);
496 return 0;
497 case SDL_TEXTURESCALEMODE_SLOW:
498 case SDL_TEXTURESCALEMODE_BEST:
499 SDL_Unsupported();
500 texture->scaleMode = SDL_TEXTURESCALEMODE_FAST;
501 SW_UpdateRenderCopyFunc(renderer, texture);
502 return -1;
503 default:
504 SDL_Unsupported();
505 texture->scaleMode = SDL_TEXTURESCALEMODE_NONE;
506 SW_UpdateRenderCopyFunc(renderer, texture);
507 return -1;
508 }
509 } 460 }
510 461
511 static int 462 static int
512 SW_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, 463 SW_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
513 const SDL_Rect * rect, const void *pixels, int pitch) 464 const SDL_Rect * rect, const void *pixels, int pitch)
627 SDL_SW_CopyYUVToRGB((SDL_SW_YUVTexture *) texture->driverdata, 578 SDL_SW_CopyYUVToRGB((SDL_SW_YUVTexture *) texture->driverdata,
628 srcrect, data->format, dstrect->w, dstrect->h, 579 srcrect, data->format, dstrect->w, dstrect->h,
629 data->surface.pixels, data->surface.pitch); 580 data->surface.pixels, data->surface.pitch);
630 } else { 581 } else {
631 SDL_Surface *surface = (SDL_Surface *) texture->driverdata; 582 SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
632 SDL_RenderCopyFunc copyfunc = (SDL_RenderCopyFunc) surface->userdata; 583 SDL_Rect real_srcrect = *srcrect;
633 584 SDL_Rect real_dstrect;
634 if (copyfunc) { 585
635 SDL_RenderCopyData copydata; 586 data->surface.w = dstrect->w;
636 587 data->surface.h = dstrect->h;
637 copydata.src = 588 data->surface.clip_rect.w = dstrect->w;
638 (Uint8 *) surface->pixels + srcrect->y * surface->pitch + 589 data->surface.clip_rect.h = dstrect->h;
639 srcrect->x * surface->format->BytesPerPixel; 590 real_dstrect = data->surface.clip_rect;
640 copydata.src_w = srcrect->w; 591
641 copydata.src_h = srcrect->h; 592 status =
642 copydata.src_pitch = surface->pitch; 593 SDL_LowerBlit(surface, &real_srcrect, &data->surface,
643 copydata.dst = (Uint8 *) data->surface.pixels; 594 &real_dstrect);
644 copydata.dst_w = dstrect->w;
645 copydata.dst_h = dstrect->h;
646 copydata.dst_pitch = data->surface.pitch;
647 copydata.flags = 0;
648 if (texture->modMode & SDL_TEXTUREMODULATE_COLOR) {
649 copydata.flags |= SDL_RENDERCOPY_MODULATE_COLOR;
650 copydata.r = texture->r;
651 copydata.g = texture->g;
652 copydata.b = texture->b;
653 }
654 if (texture->modMode & SDL_TEXTUREMODULATE_ALPHA) {
655 copydata.flags |= SDL_RENDERCOPY_MODULATE_ALPHA;
656 copydata.a = texture->a;
657 }
658 if (texture->blendMode & SDL_TEXTUREBLENDMODE_MASK) {
659 copydata.flags |= SDL_RENDERCOPY_MASK;
660 } else if (texture->blendMode & SDL_TEXTUREBLENDMODE_BLEND) {
661 copydata.flags |= SDL_RENDERCOPY_BLEND;
662 } else if (texture->blendMode & SDL_TEXTUREBLENDMODE_ADD) {
663 copydata.flags |= SDL_RENDERCOPY_ADD;
664 } else if (texture->blendMode & SDL_TEXTUREBLENDMODE_MOD) {
665 copydata.flags |= SDL_RENDERCOPY_MOD;
666 }
667 if (texture->scaleMode) {
668 copydata.flags |= SDL_RENDERCOPY_NEAREST;
669 }
670 copyfunc(&copydata);
671 status = 0;
672 } else {
673 SDL_Rect real_srcrect = *srcrect;
674 SDL_Rect real_dstrect;
675
676 data->surface.w = dstrect->w;
677 data->surface.h = dstrect->h;
678 data->surface.clip_rect.w = dstrect->w;
679 data->surface.clip_rect.h = dstrect->h;
680 real_dstrect = data->surface.clip_rect;
681
682 status =
683 SDL_LowerBlit(surface, &real_srcrect, &data->surface,
684 &real_dstrect);
685 }
686 } 595 }
687 data->renderer->UnlockTexture(data->renderer, 596 data->renderer->UnlockTexture(data->renderer,
688 data->texture[data->current_texture]); 597 data->texture[data->current_texture]);
689 return status; 598 return status;
690 } 599 }