Mercurial > sdl-ios-xcode
comparison src/video/x11/SDL_x11render.c @ 4583:5c925d4f220f
X11_DrawRects now uses a very hacky way of drawing rectangles with XRender. This will be improved in some time.
author | Sunny Sachanandani <sunnysachanandani@gmail.com> |
---|---|
date | Tue, 08 Jun 2010 19:26:32 +0530 |
parents | a17fbd25767b |
children | 9907c8cc6015 |
comparison
equal
deleted
inserted
replaced
4582:a17fbd25767b | 4583:5c925d4f220f |
---|---|
220 data->xrender_available = SDL_TRUE; | 220 data->xrender_available = SDL_TRUE; |
221 data->xwindow_pict_fmt = XRenderFindVisualFormat(data->display, data->visual); | 221 data->xwindow_pict_fmt = XRenderFindVisualFormat(data->display, data->visual); |
222 if(!data->xwindow_pict_fmt) { | 222 if(!data->xwindow_pict_fmt) { |
223 data->xrender_available = SDL_FALSE; | 223 data->xrender_available = SDL_FALSE; |
224 } | 224 } |
225 data->xwindow_pict_attr.graphics_exposures = False; | |
226 data->xwindow_pict_attr_valuemask = CPGraphicsExposure; | |
227 data->xwindow_pict = XRenderCreatePicture(data->display, data->xwindow, data->xwindow_pict_fmt, | 225 data->xwindow_pict = XRenderCreatePicture(data->display, data->xwindow, data->xwindow_pict_fmt, |
228 data->xwindow_pict_attr_valuemask, &data->xwindow_pict_attr); | 226 0, None); |
229 if(!data->xwindow_pict) { | 227 if(!data->xwindow_pict) { |
230 data->xrender_available = SDL_FALSE; | 228 data->xrender_available = SDL_FALSE; |
231 } | 229 } |
232 } | 230 } |
233 else { | 231 else { |
284 } | 282 } |
285 #ifdef SDL_VIDEO_DRIVER_X11_XRENDER | 283 #ifdef SDL_VIDEO_DRIVER_X11_XRENDER |
286 if(data->xrender_available == SDL_TRUE) { | 284 if(data->xrender_available == SDL_TRUE) { |
287 data->pixmap_picts[i] = | 285 data->pixmap_picts[i] = |
288 XRenderCreatePicture(data->display, data->pixmaps[i], data->xwindow_pict_fmt, | 286 XRenderCreatePicture(data->display, data->pixmaps[i], data->xwindow_pict_fmt, |
289 data->xwindow_pict_attr_valuemask, &data->xwindow_pict_attr); | 287 0, None); |
290 if(!data->pixmap_picts[i]) { | 288 if(!data->pixmap_picts[i]) { |
291 data->xrender_available = SDL_FALSE; | 289 data->xrender_available = SDL_FALSE; |
292 } | 290 } |
293 XRenderComposite(data->display, PictOpClear, data->pixmap_picts[i], None, data->pixmap_picts[i], | 291 XRenderComposite(data->display, PictOpClear, data->pixmap_picts[i], None, data->pixmap_picts[i], |
294 0, 0, 0, 0, 0, 0, window->w, window->h); | 292 0, 0, 0, 0, 0, 0, window->w, window->h); |
370 } | 368 } |
371 #ifdef SDL_VIDEO_DRIVER_X11_XRENDER | 369 #ifdef SDL_VIDEO_DRIVER_X11_XRENDER |
372 if(data->xrender_available == SDL_TRUE) { | 370 if(data->xrender_available == SDL_TRUE) { |
373 data->pixmap_picts[i] = | 371 data->pixmap_picts[i] = |
374 XRenderCreatePicture(data->display, data->pixmaps[i], data->xwindow_pict_fmt, | 372 XRenderCreatePicture(data->display, data->pixmaps[i], data->xwindow_pict_fmt, |
375 data->xwindow_pict_attr_valuemask, &data->xwindow_pict_attr); | 373 0, None); |
376 if(!data->pixmap_picts[i]) { | 374 if(!data->pixmap_picts[i]) { |
377 data->xrender_available = SDL_FALSE; | 375 data->xrender_available = SDL_FALSE; |
378 } | 376 } |
379 XRenderComposite(data->display, PictOpClear, data->pixmap_picts[i], None, data->pixmap_picts[i], | 377 XRenderComposite(data->display, PictOpClear, data->pixmap_picts[i], None, data->pixmap_picts[i], |
380 0, 0, 0, 0, 0, 0, window->w, window->h); | 378 0, 0, 0, 0, 0, 0, window->w, window->h); |
765 return SDL_MapRGBA(&data->format, ((int) r * (int) a) / 255, | 763 return SDL_MapRGBA(&data->format, ((int) r * (int) a) / 255, |
766 ((int) g * (int) a) / 255, | 764 ((int) g * (int) a) / 255, |
767 ((int) b * (int) a) / 255, 255); | 765 ((int) b * (int) a) / 255, 255); |
768 else | 766 else |
769 return SDL_MapRGBA(&data->format, r, g, b, a); | 767 return SDL_MapRGBA(&data->format, r, g, b, a); |
768 } | |
769 | |
770 static XRenderColor | |
771 xrenderdrawcolor(SDL_Renderer *renderer) | |
772 { | |
773 // Premultiply the color channels as well as modulate them to a 16 bit color space | |
774 XRenderColor xrender_color; | |
775 xrender_color.red = ((unsigned short)renderer->r + 1) * ((unsigned short)renderer->a + 1) - 1; | |
776 xrender_color.green = ((unsigned short)renderer->g + 1) * ((unsigned short)renderer->a + 1) - 1; | |
777 xrender_color.blue = ((unsigned short)renderer->b + 1) * ((unsigned short)renderer->a + 1) - 1; | |
778 xrender_color.alpha = ((unsigned short)renderer->a + 1) * ((unsigned short)renderer->a + 1) - 1; | |
779 return xrender_color; | |
770 } | 780 } |
771 | 781 |
772 static int | 782 static int |
773 X11_RenderDrawPoints(SDL_Renderer * renderer, const SDL_Point * points, | 783 X11_RenderDrawPoints(SDL_Renderer * renderer, const SDL_Point * points, |
774 int count) | 784 int count) |
971 clip.x = 0; | 981 clip.x = 0; |
972 clip.y = 0; | 982 clip.y = 0; |
973 clip.w = window->w; | 983 clip.w = window->w; |
974 clip.h = window->h; | 984 clip.h = window->h; |
975 | 985 |
986 #ifdef SDL_VIDEO_DRIVER_X11_XRENDER | |
987 if(data->xrender_available == SDL_TRUE) { | |
988 XRenderColor xrender_foreground; | |
989 xrender_foreground = xrenderdrawcolor(renderer); | |
990 | |
991 xrects = SDL_stack_alloc(XRectangle, 4*count); | |
992 xcount = 0; | |
993 for(i = 0; i < 4*count; i+=4) { | |
994 if(!SDL_IntersectRect(rects[i], &clip, &rect)) { | |
995 continue; | |
996 } | |
997 | |
998 xrects[xcount].x = rect.x; | |
999 xrects[xcount].y = rect.y; | |
1000 xrects[xcount].width = 1; | |
1001 xrects[xcount].height = rect.h; | |
1002 ++xcount; | |
1003 xrects[xcount].x = rect.x; | |
1004 xrects[xcount].y = rect.y+rect.h; | |
1005 xrects[xcount].width = rect.w; | |
1006 xrects[xcount].height = 1; | |
1007 ++xcount; | |
1008 xrects[xcount].x = rect.x+rect.w; | |
1009 xrects[xcount].y = rect.y; | |
1010 xrects[xcount].width = 1; | |
1011 xrects[xcount].height = rect.h; | |
1012 ++xcount; | |
1013 xrects[xcount].x = rect.x; | |
1014 xrects[xcount].y = rect.y; | |
1015 xrects[xcount].width = rect.w; | |
1016 xrects[xcount].height = 1; | |
1017 ++xcount; | |
1018 if(data->makedirty) { | |
1019 SDL_AddDirtyRect(&data->dirty, &rect); | |
1020 } | |
1021 } | |
1022 XRenderFillRectangles(data->display, PictOpOver, data->drawable_pict, | |
1023 &xrender_foreground, xrects, xcount); | |
1024 } | |
1025 else | |
1026 #endif | |
1027 { | |
1028 foreground = renderdrawcolor(renderer, 1); | |
1029 XSetForeground(data->display, data->gc, foreground); | |
1030 | |
1031 xrect = xrects = SDL_stack_alloc(XRectangle, count); | |
1032 xcount = 0; | |
1033 for (i = 0; i < count; ++i) { | |
1034 if (!SDL_IntersectRect(rects[i], &clip, &rect)) { | |
1035 continue; | |
1036 } | |
1037 | |
1038 xrect->x = (short)rect.x; | |
1039 xrect->y = (short)rect.y; | |
1040 xrect->width = (unsigned short)rect.w; | |
1041 xrect->height = (unsigned short)rect.h; | |
1042 ++xrect; | |
1043 ++xcount; | |
1044 | |
1045 if (data->makedirty) { | |
1046 SDL_AddDirtyRect(&data->dirty, &rect); | |
1047 } | |
1048 } | |
1049 if (xcount > 0) { | |
1050 XDrawRectangles(data->display, data->drawable, data->gc, | |
1051 xrects, xcount); | |
1052 } | |
1053 } | |
1054 SDL_stack_free(xrects); | |
1055 | |
1056 return 0; | |
1057 } | |
1058 | |
1059 static int | |
1060 X11_RenderFillRects(SDL_Renderer * renderer, const SDL_Rect ** rects, int count) | |
1061 { | |
1062 X11_RenderData *data = (X11_RenderData *) renderer->driverdata; | |
1063 SDL_Window *window = renderer->window; | |
1064 SDL_Rect clip, rect; | |
1065 unsigned long foreground; | |
1066 XRectangle *xrects, *xrect; | |
1067 int i, xcount; | |
1068 | |
1069 clip.x = 0; | |
1070 clip.y = 0; | |
1071 clip.w = window->w; | |
1072 clip.h = window->h; | |
1073 | |
976 foreground = renderdrawcolor(renderer, 1); | 1074 foreground = renderdrawcolor(renderer, 1); |
977 XSetForeground(data->display, data->gc, foreground); | 1075 XSetForeground(data->display, data->gc, foreground); |
978 | 1076 |
979 xrect = xrects = SDL_stack_alloc(XRectangle, count); | 1077 xrect = xrects = SDL_stack_alloc(XRectangle, count); |
980 xcount = 0; | 1078 xcount = 0; |
993 if (data->makedirty) { | 1091 if (data->makedirty) { |
994 SDL_AddDirtyRect(&data->dirty, &rect); | 1092 SDL_AddDirtyRect(&data->dirty, &rect); |
995 } | 1093 } |
996 } | 1094 } |
997 if (xcount > 0) { | 1095 if (xcount > 0) { |
998 XDrawRectangles(data->display, data->drawable, data->gc, | |
999 xrects, xcount); | |
1000 } | |
1001 SDL_stack_free(xpoints); | |
1002 | |
1003 return 0; | |
1004 } | |
1005 | |
1006 static int | |
1007 X11_RenderFillRects(SDL_Renderer * renderer, const SDL_Rect ** rects, int count) | |
1008 { | |
1009 X11_RenderData *data = (X11_RenderData *) renderer->driverdata; | |
1010 SDL_Window *window = renderer->window; | |
1011 SDL_Rect clip, rect; | |
1012 unsigned long foreground; | |
1013 XRectangle *xrects, *xrect; | |
1014 int i, xcount; | |
1015 | |
1016 clip.x = 0; | |
1017 clip.y = 0; | |
1018 clip.w = window->w; | |
1019 clip.h = window->h; | |
1020 | |
1021 foreground = renderdrawcolor(renderer, 1); | |
1022 XSetForeground(data->display, data->gc, foreground); | |
1023 | |
1024 xrect = xrects = SDL_stack_alloc(XRectangle, count); | |
1025 xcount = 0; | |
1026 for (i = 0; i < count; ++i) { | |
1027 if (!SDL_IntersectRect(rects[i], &clip, &rect)) { | |
1028 continue; | |
1029 } | |
1030 | |
1031 xrect->x = (short)rect.x; | |
1032 xrect->y = (short)rect.y; | |
1033 xrect->width = (unsigned short)rect.w; | |
1034 xrect->height = (unsigned short)rect.h; | |
1035 ++xrect; | |
1036 ++xcount; | |
1037 | |
1038 if (data->makedirty) { | |
1039 SDL_AddDirtyRect(&data->dirty, &rect); | |
1040 } | |
1041 } | |
1042 if (xcount > 0) { | |
1043 #ifdef SDL_VIDEO_DRIVER_X11_XRENDER | 1096 #ifdef SDL_VIDEO_DRIVER_X11_XRENDER |
1044 if(data->xrender_available == SDL_TRUE) | 1097 if(data->xrender_available == SDL_TRUE) |
1045 { | 1098 { |
1046 XRenderColor xrender_foreground_color; | 1099 XRenderColor xrender_foreground_color; |
1047 // Premultiply the color channels as well as modulate them to a 16 bit color space | 1100 xrender_foreground_color = xrenderdrawcolor(renderer); |
1048 xrender_foreground_color.red = ((unsigned short)renderer->r + 1) * ((unsigned short)renderer->a + 1) - 1; | |
1049 xrender_foreground_color.green = ((unsigned short)renderer->g + 1) * ((unsigned short)renderer->a + 1) - 1; | |
1050 xrender_foreground_color.blue = ((unsigned short)renderer->b + 1) * ((unsigned short)renderer->a + 1) - 1; | |
1051 xrender_foreground_color.alpha = ((unsigned short)renderer->a + 1) * ((unsigned short)renderer->a + 1) - 1; | |
1052 XRenderFillRectangles(data->display, PictOpOver, data->drawable_pict, | 1101 XRenderFillRectangles(data->display, PictOpOver, data->drawable_pict, |
1053 &xrender_foreground_color, xrects, xcount); | 1102 &xrender_foreground_color, xrects, xcount); |
1054 } | 1103 } |
1055 else | 1104 else |
1056 #endif | 1105 #endif |
1251 const SDL_Rect *rect = &dirty->rect; | 1300 const SDL_Rect *rect = &dirty->rect; |
1252 #ifdef SDL_VIDEO_DRIVER_X11_XRENDER | 1301 #ifdef SDL_VIDEO_DRIVER_X11_XRENDER |
1253 if(data->xrender_available == SDL_TRUE) | 1302 if(data->xrender_available == SDL_TRUE) |
1254 { | 1303 { |
1255 XRenderComposite(data->display, PictOpOver, data->drawable_pict, None, data->xwindow_pict, | 1304 XRenderComposite(data->display, PictOpOver, data->drawable_pict, None, data->xwindow_pict, |
1256 rect->x, rect->y, 0, 0, rect->x, rect->y, rect->w, rect->h); | 1305 rect->x, rect->y, 0, 0, rect->x, rect->y, rect->w+1, rect->h+1); |
1257 } | 1306 } |
1258 else | 1307 else |
1259 #endif | 1308 #endif |
1260 { | 1309 { |
1261 XCopyArea(data->display, data->drawable, data->xwindow, | 1310 XCopyArea(data->display, data->drawable, data->xwindow, |