comparison src/video/x11/SDL_x11render.c @ 4602:4fbf64d504cf

Use XDamage to optimise drawing operations.
author Sunny Sachanandani <sunnysachanandani@gmail.com>
date Mon, 19 Jul 2010 17:46:37 +0530
parents 8b22d33d8260
children dffa432f0e2b
comparison
equal deleted inserted replaced
4601:cd2523c69d3e 4602:4fbf64d504cf
28 28
29 #include "SDL_x11video.h" 29 #include "SDL_x11video.h"
30 #include "../SDL_rect_c.h" 30 #include "../SDL_rect_c.h"
31 #include "../SDL_pixels_c.h" 31 #include "../SDL_pixels_c.h"
32 #include "../SDL_yuv_sw_c.h" 32 #include "../SDL_yuv_sw_c.h"
33
34 #include <X11/extensions/Xdamage.h>
35 #include <X11/extensions/Xfixes.h>
33 36
34 /* X11 renderer implementation */ 37 /* X11 renderer implementation */
35 38
36 static SDL_Renderer *X11_CreateRenderer(SDL_Window * window, Uint32 flags); 39 static SDL_Renderer *X11_CreateRenderer(SDL_Window * window, Uint32 flags);
37 static int X11_DisplayModeChanged(SDL_Renderer * renderer); 40 static int X11_DisplayModeChanged(SDL_Renderer * renderer);
106 Picture stencil_pict; 109 Picture stencil_pict;
107 int blend_op; 110 int blend_op;
108 XRenderPictFormat* xwindow_pict_fmt; 111 XRenderPictFormat* xwindow_pict_fmt;
109 GC stencil_gc; 112 GC stencil_gc;
110 SDL_bool use_xrender; 113 SDL_bool use_xrender;
114 Damage stencil_damage;
115 XserverRegion stencil_parts;
111 #endif 116 #endif
112 int current_pixmap; 117 int current_pixmap;
113 Drawable drawable; 118 Drawable drawable;
114 SDL_PixelFormat format; 119 SDL_PixelFormat format;
115 GC gc; 120 GC gc;
293 298
294 // Create the GC for the clip mask. 299 // Create the GC for the clip mask.
295 data->stencil_gc = XCreateGC(data->display, data->stencil, 300 data->stencil_gc = XCreateGC(data->display, data->stencil,
296 GCGraphicsExposures, &gcv); 301 GCGraphicsExposures, &gcv);
297 XSetBackground(data->display, data->stencil_gc, 0x00); 302 XSetBackground(data->display, data->stencil_gc, 0x00);
303 XSetForeground(data->display, data->stencil_gc, 0x00);
304 XFillRectangle(data->display, data->stencil, data->stencil_gc,
305 0, 0, window->w, window->h);
298 XSetForeground(data->display, data->stencil_gc, 0xFF); 306 XSetForeground(data->display, data->stencil_gc, 0xFF);
299 data->stencil_pict = 307 data->stencil_pict =
300 XRenderCreatePicture(data->display, data->stencil, 308 XRenderCreatePicture(data->display, data->stencil,
301 XRenderFindStandardFormat(data->display, 309 XRenderFindStandardFormat(data->display,
302 PictStandardA8), 310 PictStandardA8),
303 0, NULL); 311 0, NULL);
312 data->stencil_damage =
313 XDamageCreate(data->display, data->stencil, XDamageReportNonEmpty);
314 XDamageSubtract(data->display, data->stencil_damage, None, data->stencil_parts);
304 data->brush = 315 data->brush =
305 XCreatePixmap(data->display, data->xwindow, 1, 1, 32); 316 XCreatePixmap(data->display, data->xwindow, 1, 1, 32);
306 XRenderPictureAttributes brush_attr; 317 XRenderPictureAttributes brush_attr;
307 brush_attr.repeat = RepeatNormal; 318 brush_attr.repeat = RepeatNormal;
308 data->brush_pict = 319 data->brush_pict =
999 X11_RenderData *data = (X11_RenderData *) renderer->driverdata; 1010 X11_RenderData *data = (X11_RenderData *) renderer->driverdata;
1000 SDL_Window *window = renderer->window; 1011 SDL_Window *window = renderer->window;
1001 XPoint *xpoints, *xpoint; 1012 XPoint *xpoints, *xpoint;
1002 int i, xcount; 1013 int i, xcount;
1003 SDL_Rect clip, rect; 1014 SDL_Rect clip, rect;
1015 /*Damage damage;
1016 XserverRegion parts;*/
1004 1017
1005 clip.x = 0; 1018 clip.x = 0;
1006 clip.y = 0; 1019 clip.y = 0;
1007 clip.w = window->w; 1020 clip.w = window->w;
1008 clip.h = window->h; 1021 clip.h = window->h;
1031 xpoint->x = (short)x; 1044 xpoint->x = (short)x;
1032 xpoint->y = (short)y; 1045 xpoint->y = (short)y;
1033 ++xpoint; 1046 ++xpoint;
1034 ++xcount; 1047 ++xcount;
1035 } 1048 }
1036 /* 1049
1037 #ifdef SDL_VIDEO_DRIVER_X11_XRENDER 1050 #ifdef SDL_VIDEO_DRIVER_X11_XRENDER
1038 if (data->use_xrender) { 1051 if (data->use_xrender) {
1039 XSetForeground(data->display, data->stencil_gc, 0x00); 1052 XSetForeground(data->display, data->stencil_gc, 0x00);
1053 XFixesSetGCClipRegion(data->display, data->stencil_gc, 0, 0, data->stencil_parts);
1040 XFillRectangle(data->display, data->stencil, data->stencil_gc, 1054 XFillRectangle(data->display, data->stencil, data->stencil_gc,
1041 rect.x, rect.y, rect.w, rect.h); 1055 rect.x, rect.y, rect.w, rect.h);
1056 XFixesSetGCClipRegion(data->display, data->stencil_gc, 0, 0, None);
1042 XSetForeground(data->display, data->stencil_gc, 0xFF); 1057 XSetForeground(data->display, data->stencil_gc, 0xFF);
1058 /*damage =
1059 XDamageCreate(data->display, data->stencil, XDamageReportRawRectangles);*/
1043 XDrawPoints(data->display, data->stencil, data->stencil_gc, xpoints, xcount, 1060 XDrawPoints(data->display, data->stencil, data->stencil_gc, xpoints, xcount,
1044 CoordModeOrigin); 1061 CoordModeOrigin);
1045 } 1062 XDamageSubtract(data->display, data->stencil_damage, None, data->stencil_parts);
1046 #endif*/ 1063 }
1047 } 1064 #endif
1048 /* 1065 }
1066
1049 #ifdef SDL_VIDEO_DRIVER_X11_XRENDER 1067 #ifdef SDL_VIDEO_DRIVER_X11_XRENDER
1050 if (data->use_xrender) { 1068 if (data->use_xrender) {
1051 XRenderColor foreground; 1069 XRenderColor foreground;
1052 foreground = xrenderdrawcolor(renderer); 1070 foreground = xrenderdrawcolor(renderer);
1053 XRenderFillRectangle(data->display, PictOpSrc, data->brush_pict, 1071 XRenderFillRectangle(data->display, PictOpSrc, data->brush_pict,
1054 &foreground, 0, 0, 1, 1); 1072 &foreground, 0, 0, 1, 1);
1073 XFixesSetPictureClipRegion(data->display, data->drawable_pict, 0, 0, data->stencil_parts);
1055 XRenderComposite(data->display, data->blend_op, data->brush_pict, 1074 XRenderComposite(data->display, data->blend_op, data->brush_pict,
1056 data->stencil_pict, data->drawable_pict, 1075 data->stencil_pict, data->drawable_pict,
1057 rect.x, rect.y, rect.x, rect.y, rect.x, rect.y, rect.w, rect.h); 1076 rect.x, rect.y, rect.x, rect.y, rect.x, rect.y, rect.w, rect.h);
1077 XFixesSetPictureClipRegion(data->display, data->drawable_pict, 0, 0, None);
1078 //XDamageDestroy(data->display, damage);
1058 } 1079 }
1059 else 1080 else
1060 #endif 1081 #endif
1061 */
1062 { 1082 {
1063 unsigned long foreground = renderdrawcolor(renderer, 1); 1083 unsigned long foreground = renderdrawcolor(renderer, 1);
1064 XSetForeground(data->display, data->gc, foreground); 1084 XSetForeground(data->display, data->gc, foreground);
1065 1085
1066 1086
1085 unsigned long foreground; 1105 unsigned long foreground;
1086 XPoint *xpoints, *xpoint; 1106 XPoint *xpoints, *xpoint;
1087 int i, xcount; 1107 int i, xcount;
1088 int minx, miny; 1108 int minx, miny;
1089 int maxx, maxy; 1109 int maxx, maxy;
1110 XserverRegion parts;
1111 Damage damage;
1090 1112
1091 clip.x = 0; 1113 clip.x = 0;
1092 clip.y = 0; 1114 clip.y = 0;
1093 clip.w = window->w; 1115 clip.w = window->w;
1094 clip.h = window->h; 1116 clip.h = window->h;
1095 { 1117 {
1096 Pixmap drawable; 1118 Pixmap drawable;
1097 GC gc; 1119 GC gc;
1098 /*
1099 #ifdef SDL_VIDEO_DRIVER_X11_XRENDER 1120 #ifdef SDL_VIDEO_DRIVER_X11_XRENDER
1100 if (data->use_xrender) { 1121 if (data->use_xrender) {
1101 drawable = data->stencil; 1122 drawable = data->stencil;
1102 gc = data->stencil_gc; 1123 gc = data->stencil_gc;
1103 XSetForeground(data->display, data->stencil_gc, 0x00); 1124 XSetForeground(data->display, data->stencil_gc, 0x00);
1125 XFixesSetGCClipRegion(data->display, data->stencil_gc, 0, 0, data->stencil_parts);
1104 XFillRectangle(data->display, data->stencil, data->stencil_gc, 1126 XFillRectangle(data->display, data->stencil, data->stencil_gc,
1105 0, 0, window->w, window->h); 1127 0, 0, window->w, window->h);
1128 XFixesSetGCClipRegion(data->display, data->stencil_gc, 0, 0, None);
1106 XSetForeground(data->display, data->stencil_gc, 0xFF); 1129 XSetForeground(data->display, data->stencil_gc, 0xFF);
1130 /*damage =
1131 XDamageCreate(data->display, data->stencil, XDamageReportRawRectangles);*/
1107 } 1132 }
1108 else 1133 else
1109 #endif 1134 #endif
1110 */
1111 { 1135 {
1112 drawable = data->drawable; 1136 drawable = data->drawable;
1113 gc = data->gc; 1137 gc = data->gc;
1114 } 1138 }
1115 1139
1228 rect.h = (maxy - miny) + 1; 1252 rect.h = (maxy - miny) + 1;
1229 SDL_AddDirtyRect(&data->dirty, &rect); 1253 SDL_AddDirtyRect(&data->dirty, &rect);
1230 } 1254 }
1231 } 1255 }
1232 } 1256 }
1233 /*
1234 #ifdef SDL_VIDEO_DRIVER_X11_XRENDER 1257 #ifdef SDL_VIDEO_DRIVER_X11_XRENDER
1235 if (data->use_xrender) { 1258 if (data->use_xrender) {
1236 XRenderColor xrforeground = xrenderdrawcolor(renderer); 1259 XRenderColor xrforeground = xrenderdrawcolor(renderer);
1237 XRenderFillRectangle(data->display, PictOpSrc, data->brush_pict, 1260 XRenderFillRectangle(data->display, PictOpSrc, data->brush_pict,
1238 &xrforeground, 0, 0, 1, 1); 1261 &xrforeground, 0, 0, 1, 1);
1262 XDamageSubtract(data->display, data->stencil_damage, None, data->stencil_parts);
1263 XFixesSetPictureClipRegion(data->display, data->drawable_pict, 0, 0, data->stencil_parts);
1239 XRenderComposite(data->display, data->blend_op, data->brush_pict, 1264 XRenderComposite(data->display, data->blend_op, data->brush_pict,
1240 data->stencil_pict, data->drawable_pict, 1265 data->stencil_pict, data->drawable_pict,
1241 0, 0, 0, 0, 0, 0, window->w, window->h); 1266 0, 0, 0, 0, 0, 0, window->w, window->h);
1242 } 1267 XFixesSetPictureClipRegion(data->display, data->drawable_pict, 0, 0, None);
1243 #endif 1268 //XDamageDestroy(data->display, damage);
1244 */ 1269 }
1270 #endif
1245 SDL_stack_free(xpoints); 1271 SDL_stack_free(xpoints);
1246 1272
1247 return 0; 1273 return 0;
1248 } 1274 }
1249 1275