comparison src/video/SDL_renderer_sw.c @ 3427:36cf454ba065

Work in progress on implementation of SDL_RenderReadPixels() and SDL_RenderWritePixels(), code untested.
author Sam Lantinga <slouken@libsdl.org>
date Mon, 09 Nov 2009 05:20:11 +0000
parents aa34d1180d30
children 9f62f47d989b
comparison
equal deleted inserted replaced
3426:ee0178f1c507 3427:36cf454ba065
63 static int SW_RenderLine(SDL_Renderer * renderer, int x1, int y1, int x2, 63 static int SW_RenderLine(SDL_Renderer * renderer, int x1, int y1, int x2,
64 int y2); 64 int y2);
65 static int SW_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect); 65 static int SW_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect);
66 static int SW_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, 66 static int SW_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
67 const SDL_Rect * srcrect, const SDL_Rect * dstrect); 67 const SDL_Rect * srcrect, const SDL_Rect * dstrect);
68 static int SW_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
69 void * pixels, int pitch);
70 static int SW_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect,
71 const void * pixels, int pitch);
68 static void SW_RenderPresent(SDL_Renderer * renderer); 72 static void SW_RenderPresent(SDL_Renderer * renderer);
69 static void SW_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture); 73 static void SW_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture);
70 static void SW_DestroyRenderer(SDL_Renderer * renderer); 74 static void SW_DestroyRenderer(SDL_Renderer * renderer);
71 75
72 76
226 230
227 renderer->RenderPoint = SW_RenderPoint; 231 renderer->RenderPoint = SW_RenderPoint;
228 renderer->RenderLine = SW_RenderLine; 232 renderer->RenderLine = SW_RenderLine;
229 renderer->RenderFill = SW_RenderFill; 233 renderer->RenderFill = SW_RenderFill;
230 renderer->RenderCopy = SW_RenderCopy; 234 renderer->RenderCopy = SW_RenderCopy;
235 renderer->RenderReadPixels = SW_RenderReadPixels;
236 renderer->RenderWritePixels = SW_RenderWritePixels;
231 renderer->RenderPresent = SW_RenderPresent; 237 renderer->RenderPresent = SW_RenderPresent;
232 renderer->DestroyRenderer = SW_DestroyRenderer; 238 renderer->DestroyRenderer = SW_DestroyRenderer;
233 renderer->info.name = SW_RenderDriver.info.name; 239 renderer->info.name = SW_RenderDriver.info.name;
234 renderer->info.flags = 0; 240 renderer->info.flags = 0;
235 renderer->window = window->id; 241 renderer->window = window->id;
726 data->renderer->UnlockTexture(data->renderer, 732 data->renderer->UnlockTexture(data->renderer,
727 data->texture[data->current_texture]); 733 data->texture[data->current_texture]);
728 return status; 734 return status;
729 } 735 }
730 736
737 static int
738 SW_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
739 void * pixels, int pitch)
740 {
741 SW_RenderData *data = (SW_RenderData *) renderer->driverdata;
742 const Uint8 *src;
743 Uint8 *dst;
744 int src_pitch, dst_pitch, w, h;
745
746 if (data->renderer->LockTexture(data->renderer,
747 data->texture[data->current_texture],
748 rect, 0, &data->surface.pixels,
749 &data->surface.pitch) < 0) {
750 return -1;
751 }
752
753 src = data->surface.pixels;
754 src_pitch = data->surface.pitch;
755 dst = pixels;
756 dst_pitch = pitch;
757 h = rect->h;
758 w = rect->w * data->surface.format->BytesPerPixel;
759 while (h--) {
760 SDL_memcpy(dst, src, w);
761 src += src_pitch;
762 dst += dst_pitch;
763 }
764
765 data->renderer->UnlockTexture(data->renderer,
766 data->texture[data->current_texture]);
767 return 0;
768 }
769
770 static int
771 SW_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect,
772 const void * pixels, int pitch)
773 {
774 SW_RenderData *data = (SW_RenderData *) renderer->driverdata;
775 const Uint8 *src;
776 Uint8 *dst;
777 int src_pitch, dst_pitch, w, h;
778
779 if (data->renderer->info.flags & SDL_RENDERER_PRESENTCOPY) {
780 SDL_AddDirtyRect(&data->dirty, rect);
781 }
782
783 if (data->renderer->LockTexture(data->renderer,
784 data->texture[data->current_texture],
785 rect, 1, &data->surface.pixels,
786 &data->surface.pitch) < 0) {
787 return -1;
788 }
789
790 src = pixels;
791 src_pitch = pitch;
792 dst = data->surface.pixels;
793 dst_pitch = data->surface.pitch;
794 h = rect->h;
795 w = rect->w * data->surface.format->BytesPerPixel;
796 while (h--) {
797 SDL_memcpy(dst, src, w);
798 src += src_pitch;
799 dst += dst_pitch;
800 }
801
802 data->renderer->UnlockTexture(data->renderer,
803 data->texture[data->current_texture]);
804 return 0;
805 }
806
731 static void 807 static void
732 SW_RenderPresent(SDL_Renderer * renderer) 808 SW_RenderPresent(SDL_Renderer * renderer)
733 { 809 {
734 SW_RenderData *data = (SW_RenderData *) renderer->driverdata; 810 SW_RenderData *data = (SW_RenderData *) renderer->driverdata;
735 SDL_Texture *texture = data->texture[data->current_texture]; 811 SDL_Texture *texture = data->texture[data->current_texture];