comparison src/video/x11/SDL_x11render.c @ 3559:5f26a7eb5ff0

Implemented read/write pixels for the X11 renderer
author Sam Lantinga <slouken@libsdl.org>
date Mon, 14 Dec 2009 06:52:17 +0000
parents c2154674c0c1
children f638ded38b8a
comparison
equal deleted inserted replaced
3558:5f038ec1a1af 3559:5f26a7eb5ff0
56 int count); 56 int count);
57 static int X11_RenderRects(SDL_Renderer * renderer, const SDL_Rect ** rects, 57 static int X11_RenderRects(SDL_Renderer * renderer, const SDL_Rect ** rects,
58 int count); 58 int count);
59 static int X11_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, 59 static int X11_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
60 const SDL_Rect * srcrect, const SDL_Rect * dstrect); 60 const SDL_Rect * srcrect, const SDL_Rect * dstrect);
61 static int X11_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
62 Uint32 format, void * pixels, int pitch);
63 static int X11_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect,
64 Uint32 format, const void * pixels, int pitch);
61 static void X11_RenderPresent(SDL_Renderer * renderer); 65 static void X11_RenderPresent(SDL_Renderer * renderer);
62 static void X11_DestroyTexture(SDL_Renderer * renderer, 66 static void X11_DestroyTexture(SDL_Renderer * renderer,
63 SDL_Texture * texture); 67 SDL_Texture * texture);
64 static void X11_DestroyRenderer(SDL_Renderer * renderer); 68 static void X11_DestroyRenderer(SDL_Renderer * renderer);
65 69
206 renderer->SetDrawBlendMode = X11_SetDrawBlendMode; 210 renderer->SetDrawBlendMode = X11_SetDrawBlendMode;
207 renderer->RenderPoints = X11_RenderPoints; 211 renderer->RenderPoints = X11_RenderPoints;
208 renderer->RenderLines = X11_RenderLines; 212 renderer->RenderLines = X11_RenderLines;
209 renderer->RenderRects = X11_RenderRects; 213 renderer->RenderRects = X11_RenderRects;
210 renderer->RenderCopy = X11_RenderCopy; 214 renderer->RenderCopy = X11_RenderCopy;
215 renderer->RenderReadPixels = X11_RenderReadPixels;
216 renderer->RenderWritePixels = X11_RenderWritePixels;
211 renderer->RenderPresent = X11_RenderPresent; 217 renderer->RenderPresent = X11_RenderPresent;
212 renderer->DestroyTexture = X11_DestroyTexture; 218 renderer->DestroyTexture = X11_DestroyTexture;
213 renderer->DestroyRenderer = X11_DestroyRenderer; 219 renderer->DestroyRenderer = X11_DestroyRenderer;
214 renderer->info = X11_RenderDriver.info; 220 renderer->info = X11_RenderDriver.info;
215 renderer->window = window->id; 221 renderer->window = window->id;
935 srcrect->x, srcrect->y); 941 srcrect->x, srcrect->y);
936 } 942 }
937 return 0; 943 return 0;
938 } 944 }
939 945
946 static int
947 X11_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
948 Uint32 format, void * pixels, int pitch)
949 {
950 X11_RenderData *data = (X11_RenderData *) renderer->driverdata;
951 SDL_Window *window = SDL_GetWindowFromID(renderer->window);
952 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
953 Uint32 screen_format = display->current_mode.format;
954 XImage *image;
955
956 image = XGetImage(data->display, data->drawable, rect->x, rect->y,
957 rect->w, rect->h, AllPlanes, ZPixmap);
958
959 SDL_ConvertPixels(rect->w, rect->h,
960 screen_format, image->data, image->bytes_per_line,
961 format, pixels, pitch);
962
963 XDestroyImage(image);
964 return 0;
965 }
966
967 static int
968 X11_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect,
969 Uint32 format, const void * pixels, int pitch)
970 {
971 X11_RenderData *data = (X11_RenderData *) renderer->driverdata;
972 SDL_Window *window = SDL_GetWindowFromID(renderer->window);
973 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
974 Uint32 screen_format = display->current_mode.format;
975 XImage *image;
976 void *image_pixels;
977 int image_pitch;
978
979 image_pitch = rect->w * SDL_BYTESPERPIXEL(screen_format);
980 image_pixels = SDL_malloc(rect->h * image_pitch);
981 if (!image_pixels) {
982 SDL_OutOfMemory();
983 return -1;
984 }
985
986 image = XCreateImage(data->display, data->visual,
987 data->depth, ZPixmap, 0, image_pixels,
988 rect->w, rect->h,
989 SDL_BYTESPERPIXEL(screen_format) * 8,
990 image_pitch);
991 if (!image) {
992 SDL_SetError("XCreateImage() failed");
993 return -1;
994 }
995
996 SDL_ConvertPixels(rect->w, rect->h,
997 format, pixels, pitch,
998 screen_format, image->data, image->bytes_per_line);
999
1000 XPutImage(data->display, data->drawable, data->gc,
1001 image, 0, 0, rect->x, rect->y, rect->w, rect->h);
1002
1003 image->data = NULL;
1004 XDestroyImage(image);
1005
1006 SDL_free(image_pixels);
1007 return 0;
1008 }
1009
940 static void 1010 static void
941 X11_RenderPresent(SDL_Renderer * renderer) 1011 X11_RenderPresent(SDL_Renderer * renderer)
942 { 1012 {
943 X11_RenderData *data = (X11_RenderData *) renderer->driverdata; 1013 X11_RenderData *data = (X11_RenderData *) renderer->driverdata;
944 SDL_DirtyRect *dirty; 1014 SDL_DirtyRect *dirty;