Mercurial > sdl-ios-xcode
comparison src/video/x11/SDL_x11render.c @ 4596:dc26c37ad70e
Got testsprite2 to work reasonably.
author | Sunny Sachanandani <sunnysachanandani@gmail.com> |
---|---|
date | Sun, 18 Jul 2010 08:28:35 +0530 |
parents | 73eeadf7ed8e |
children | 95be206b3cb7 |
comparison
equal
deleted
inserted
replaced
4595:73eeadf7ed8e | 4596:dc26c37ad70e |
---|---|
99 #ifdef SDL_VIDEO_DRIVER_X11_XRENDER | 99 #ifdef SDL_VIDEO_DRIVER_X11_XRENDER |
100 Pixmap mask; | 100 Pixmap mask; |
101 Picture xwindow_pict; | 101 Picture xwindow_pict; |
102 Picture pixmap_picts[3]; | 102 Picture pixmap_picts[3]; |
103 Picture drawable_pict; | 103 Picture drawable_pict; |
104 Picture mask_pict; | |
105 int blend_op; | 104 int blend_op; |
106 XRenderPictFormat* xwindow_pict_fmt; | 105 XRenderPictFormat* xwindow_pict_fmt; |
107 GC mask_gc; | 106 GC mask_gc; |
108 SDL_bool use_xrender; | 107 SDL_bool use_xrender; |
109 #endif | 108 #endif |
180 info->texture_formats[info->num_texture_formats++] = SDL_PIXELFORMAT_YV12; | 179 info->texture_formats[info->num_texture_formats++] = SDL_PIXELFORMAT_YV12; |
181 info->texture_formats[info->num_texture_formats++] = SDL_PIXELFORMAT_IYUV; | 180 info->texture_formats[info->num_texture_formats++] = SDL_PIXELFORMAT_IYUV; |
182 info->texture_formats[info->num_texture_formats++] = SDL_PIXELFORMAT_YUY2; | 181 info->texture_formats[info->num_texture_formats++] = SDL_PIXELFORMAT_YUY2; |
183 info->texture_formats[info->num_texture_formats++] = SDL_PIXELFORMAT_UYVY; | 182 info->texture_formats[info->num_texture_formats++] = SDL_PIXELFORMAT_UYVY; |
184 info->texture_formats[info->num_texture_formats++] = SDL_PIXELFORMAT_YVYU; | 183 info->texture_formats[info->num_texture_formats++] = SDL_PIXELFORMAT_YVYU; |
184 info->texture_formats[info->num_texture_formats++] = SDL_PIXELFORMAT_ARGB8888; | |
185 | 185 |
186 for (i = 0; i < _this->num_displays; ++i) { | 186 for (i = 0; i < _this->num_displays; ++i) { |
187 SDL_AddRenderDriver(&_this->displays[i], &X11_RenderDriver); | 187 SDL_AddRenderDriver(&_this->displays[i], &X11_RenderDriver); |
188 } | 188 } |
189 } | 189 } |
195 SDL_DisplayData *displaydata = (SDL_DisplayData *) display->driverdata; | 195 SDL_DisplayData *displaydata = (SDL_DisplayData *) display->driverdata; |
196 SDL_WindowData *windowdata = (SDL_WindowData *) window->driverdata; | 196 SDL_WindowData *windowdata = (SDL_WindowData *) window->driverdata; |
197 SDL_Renderer *renderer; | 197 SDL_Renderer *renderer; |
198 X11_RenderData *data; | 198 X11_RenderData *data; |
199 XGCValues gcv; | 199 XGCValues gcv; |
200 gcv.graphics_exposures = False; | |
200 int i, n; | 201 int i, n; |
201 int bpp; | 202 int bpp; |
202 Uint32 Rmask, Gmask, Bmask, Amask; | 203 Uint32 Rmask, Gmask, Bmask, Amask; |
203 | 204 |
204 renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer)); | 205 renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer)); |
289 window->w, window->h, 1); | 290 window->w, window->h, 1); |
290 if (!data->mask) { | 291 if (!data->mask) { |
291 SDL_SetError("XCreatePixmap() failed"); | 292 SDL_SetError("XCreatePixmap() failed"); |
292 return NULL; | 293 return NULL; |
293 } | 294 } |
294 data->mask_pict = | |
295 XRenderCreatePicture(data->display, data->mask, | |
296 XRenderFindStandardFormat(data->display, | |
297 PictStandardA1), | |
298 0, NULL); | |
299 if (!data->mask_pict) { | |
300 SDL_SetError("XRenderCreatePicture() failed"); | |
301 return NULL; | |
302 } | |
303 // Create the GC for the clip mask. | 295 // Create the GC for the clip mask. |
304 XGCValues gcv_mask; | |
305 gcv_mask.foreground = 1; | |
306 gcv_mask.background = 0; | |
307 data->mask_gc = XCreateGC(data->display, data->mask, | 296 data->mask_gc = XCreateGC(data->display, data->mask, |
308 GCBackground | GCForeground, &gcv_mask); | 297 GCGraphicsExposures, &gcv); |
309 if (!data->mask_gc) { | 298 if (!data->mask_gc) { |
310 SDL_SetError("XCreateGC() failed"); | 299 SDL_SetError("XCreateGC() failed"); |
311 return NULL; | 300 return NULL; |
312 } | 301 } |
302 XSetBackground(data->display, data->mask_gc, 0); | |
303 XSetForeground(data->display, data->mask_gc, 1); | |
313 // Set the default blending mode. | 304 // Set the default blending mode. |
314 renderer->blendMode = SDL_BLENDMODE_BLEND; | 305 renderer->blendMode = SDL_BLENDMODE_BLEND; |
315 data->blend_op = PictOpOver; | 306 data->blend_op = PictOpOver; |
316 } | 307 } |
317 #endif | 308 #endif |
423 { | 414 { |
424 X11_RenderData *data = (X11_RenderData *) renderer->driverdata; | 415 X11_RenderData *data = (X11_RenderData *) renderer->driverdata; |
425 SDL_Window *window = renderer->window; | 416 SDL_Window *window = renderer->window; |
426 int i, n; | 417 int i, n; |
427 | 418 |
419 #ifdef SDL_VIDEO_DRIVER_X11_XRENDER | |
420 if (data->use_xrender) { | |
421 XRenderFreePicture(data->display, data->xwindow_pict); | |
422 data->xwindow_pict_fmt = | |
423 XRenderFindVisualFormat(data->display, data->visual); | |
424 data->xwindow_pict = | |
425 XRenderCreatePicture(data->display, data->xwindow, | |
426 data->xwindow_pict_fmt, 0, NULL); | |
427 } | |
428 #endif | |
428 if (renderer->info.flags & SDL_RENDERER_SINGLEBUFFER) { | 429 if (renderer->info.flags & SDL_RENDERER_SINGLEBUFFER) { |
429 n = 0; | 430 n = 0; |
430 } else if (renderer->info.flags & SDL_RENDERER_PRESENTFLIP2) { | 431 } else if (renderer->info.flags & SDL_RENDERER_PRESENTFLIP2) { |
431 n = 2; | 432 n = 2; |
432 } else if (renderer->info.flags & SDL_RENDERER_PRESENTFLIP3) { | 433 } else if (renderer->info.flags & SDL_RENDERER_PRESENTFLIP3) { |
437 for (i = 0; i < n; ++i) { | 438 for (i = 0; i < n; ++i) { |
438 if (data->pixmaps[i] != None) { | 439 if (data->pixmaps[i] != None) { |
439 XFreePixmap(data->display, data->pixmaps[i]); | 440 XFreePixmap(data->display, data->pixmaps[i]); |
440 data->pixmaps[i] = None; | 441 data->pixmaps[i] = None; |
441 #ifdef SDL_VIDEO_DRIVER_X11_XRENDER | 442 #ifdef SDL_VIDEO_DRIVER_X11_XRENDER |
443 XRenderFreePicture(data->display, data->pixmap_picts[i]); | |
442 data->pixmap_picts[i] = None; | 444 data->pixmap_picts[i] = None; |
443 #endif | 445 #endif |
444 } | 446 } |
445 } | 447 } |
446 for (i = 0; i < n; ++i) { | 448 for (i = 0; i < n; ++i) { |
1036 /* Set the clip mask to restrict rendering to | 1038 /* Set the clip mask to restrict rendering to |
1037 * the primitive being drawn | 1039 * the primitive being drawn |
1038 */ | 1040 */ |
1039 attributes.clip_mask = data->mask; | 1041 attributes.clip_mask = data->mask; |
1040 valuemask = CPClipMask; | 1042 valuemask = CPClipMask; |
1041 | 1043 |
1042 XRenderComposite(data->display, PictOpClear, data->mask_pict, None, data->mask_pict, | 1044 XSetForeground(data->display, data->mask_gc, 0); |
1043 0, 0, 0, 0, 0, 0, window->w, window->h); | 1045 XFillRectangle(data->display, data->mask, data->mask_gc, |
1046 0, 0, window->w, window->h); | |
1047 XSetForeground(data->display, data->mask_gc, 1); | |
1044 | 1048 |
1045 XDrawPoints(data->display, data->mask, data->mask_gc, xpoints, xcount, | 1049 XDrawPoints(data->display, data->mask, data->mask_gc, xpoints, xcount, |
1046 CoordModeOrigin); | 1050 CoordModeOrigin); |
1047 XRenderChangePicture(data->display, data->drawable_pict, valuemask, &attributes); | 1051 XRenderChangePicture(data->display, data->drawable_pict, valuemask, &attributes); |
1048 Picture fill = | 1052 /*XRenderFillRectangle(data->display, data->blend_op, data->drawable_pict, |
1049 XRenderCreateSolidFill(data->display, &foreground); | 1053 &foreground, 0, 0, window->w, window->h);*/ |
1050 if (!fill) { | |
1051 SDL_SetError("XRenderCreateSolidFill() failed"); | |
1052 return -1; | |
1053 } | |
1054 | |
1055 XRenderComposite(data->display, data->blend_op, fill, data->mask_pict, | |
1056 data->drawable_pict, 0, 0, 0, 0, 0, 0, window->w, window->h); | |
1057 | |
1058 // Reset the clip_mask | 1054 // Reset the clip_mask |
1059 attributes.clip_mask = None; | 1055 attributes.clip_mask = None; |
1060 XRenderChangePicture(data->display, data->drawable_pict, valuemask, &attributes); | 1056 XRenderChangePicture(data->display, data->drawable_pict, valuemask, &attributes); |
1061 XRenderFreePicture(data->display, fill); | |
1062 } | 1057 } |
1063 else | 1058 else |
1064 #endif | 1059 #endif |
1065 { | 1060 { |
1066 unsigned long foreground = renderdrawcolor(renderer, 1); | 1061 unsigned long foreground = renderdrawcolor(renderer, 1); |
1099 GC gc; | 1094 GC gc; |
1100 #ifdef SDL_VIDEO_DRIVER_X11_XRENDER | 1095 #ifdef SDL_VIDEO_DRIVER_X11_XRENDER |
1101 if (data->use_xrender == SDL_TRUE) { | 1096 if (data->use_xrender == SDL_TRUE) { |
1102 drawable = data->mask; | 1097 drawable = data->mask; |
1103 gc = data->mask_gc; | 1098 gc = data->mask_gc; |
1104 XRenderComposite(data->display, PictOpClear, data->mask_pict, None, data->mask_pict, | 1099 XSetForeground(data->display, data->mask_gc, 0); |
1105 0, 0, 0, 0, 0, 0, window->w, window->h); | 1100 XFillRectangle(data->display, data->mask, data->mask_gc, |
1101 0, 0, window->w, window->h); | |
1102 XSetForeground(data->display, data->mask_gc, 1); | |
1106 } | 1103 } |
1107 else | 1104 else |
1108 #endif | 1105 #endif |
1109 { | 1106 { |
1110 drawable = data->drawable; | 1107 drawable = data->drawable; |
1232 XRenderColor xrforeground = xrenderdrawcolor(renderer); | 1229 XRenderColor xrforeground = xrenderdrawcolor(renderer); |
1233 XRenderPictureAttributes attributes; | 1230 XRenderPictureAttributes attributes; |
1234 attributes.clip_mask = data->mask; | 1231 attributes.clip_mask = data->mask; |
1235 unsigned long valuemask = CPClipMask; | 1232 unsigned long valuemask = CPClipMask; |
1236 XRenderChangePicture(data->display, data->drawable_pict, valuemask, &attributes); | 1233 XRenderChangePicture(data->display, data->drawable_pict, valuemask, &attributes); |
1237 Picture fill = XRenderCreateSolidFill(data->display, &xrforeground); | 1234 /*XRenderFillRectangle(data->display, data->blend_op, data->drawable_pict, |
1238 if (!fill) { | 1235 &xrforeground, 0, 0, window->w, window->h);*/ |
1239 SDL_SetError("XRenderCreateSolidFill() failed"); | |
1240 return -1; | |
1241 } | |
1242 XRenderComposite(data->display, data->blend_op, fill, data->mask_pict, | |
1243 data->drawable_pict, 0, 0, 0, 0, 0, 0, window->w, window->h); | |
1244 attributes.clip_mask = None; | 1236 attributes.clip_mask = None; |
1245 XRenderChangePicture(data->display, data->drawable_pict, valuemask, &attributes); | 1237 XRenderChangePicture(data->display, data->drawable_pict, valuemask, &attributes); |
1246 XRenderFreePicture(data->display, fill); | |
1247 } | 1238 } |
1248 #endif | 1239 #endif |
1249 SDL_stack_free(xpoints); | 1240 SDL_stack_free(xpoints); |
1250 | 1241 |
1251 return 0; | 1242 return 0; |
1292 | 1283 |
1293 foreground = xrenderdrawcolor(renderer); | 1284 foreground = xrenderdrawcolor(renderer); |
1294 valuemask = CPClipMask; | 1285 valuemask = CPClipMask; |
1295 attributes.clip_mask = data->mask; | 1286 attributes.clip_mask = data->mask; |
1296 | 1287 |
1297 XRenderComposite(data->display, PictOpClear, data->mask_pict, None, data->mask_pict, | 1288 XSetForeground(data->display, data->mask_gc, 0); |
1298 0, 0, 0, 0, 0, 0, window->w, window->h); | 1289 XFillRectangle(data->display, data->mask, data->mask_gc, |
1290 0, 0, window->w, window->h); | |
1291 XSetForeground(data->display, data->mask_gc, 1); | |
1292 | |
1299 XDrawRectangles(data->display, data->mask, data->mask_gc, xrects, xcount); | 1293 XDrawRectangles(data->display, data->mask, data->mask_gc, xrects, xcount); |
1300 XRenderChangePicture(data->display, data->drawable_pict, valuemask, &attributes); | 1294 XRenderChangePicture(data->display, data->drawable_pict, valuemask, &attributes); |
1301 Picture fill = | 1295 /*XRenderFillRectangle(data->display, data->blend_op, data->drawable_pict, |
1302 XRenderCreateSolidFill(data->display, &foreground); | 1296 &foreground, 0, 0, window->w, window->h);*/ |
1303 if (!fill) { | |
1304 SDL_SetError("XRenderCreateSolidFill() failed"); | |
1305 return -1; | |
1306 } | |
1307 XRenderComposite(data->display, data->blend_op, fill, data->mask_pict, | |
1308 data->drawable_pict, 0, 0, 0, 0, 0, 0, window->w, window->h); | |
1309 attributes.clip_mask = None; | 1297 attributes.clip_mask = None; |
1310 XRenderChangePicture(data->display, data->drawable_pict, valuemask, &attributes); | 1298 XRenderChangePicture(data->display, data->drawable_pict, valuemask, &attributes); |
1311 XRenderFreePicture(data->display, fill); | |
1312 } | 1299 } |
1313 else | 1300 else |
1314 #endif | 1301 #endif |
1315 { | 1302 { |
1316 unsigned long foreground; | 1303 unsigned long foreground; |
1367 XRenderPictureAttributes attributes; | 1354 XRenderPictureAttributes attributes; |
1368 | 1355 |
1369 foreground = xrenderdrawcolor(renderer); | 1356 foreground = xrenderdrawcolor(renderer); |
1370 attributes.clip_mask = data->mask; | 1357 attributes.clip_mask = data->mask; |
1371 | 1358 |
1372 XRenderComposite(data->display, PictOpClear, data->mask_pict, None, data->mask_pict, | 1359 XSetForeground(data->display, data->mask_gc, 0); |
1373 0, 0, 0, 0, 0, 0, window->w, window->h); | 1360 XFillRectangle(data->display, data->mask, data->mask_gc, |
1361 0, 0, window->w, window->h); | |
1362 XSetForeground(data->display, data->mask_gc, 1); | |
1363 | |
1374 XFillRectangles(data->display, data->mask, data->mask_gc, | 1364 XFillRectangles(data->display, data->mask, data->mask_gc, |
1375 xrects, xcount); | 1365 xrects, xcount); |
1376 | 1366 |
1377 XRenderChangePicture(data->display, data->drawable_pict, CPClipMask, &attributes); | 1367 XRenderChangePicture(data->display, data->drawable_pict, CPClipMask, &attributes); |
1378 Picture fill = XRenderCreateSolidFill(data->display, | 1368 /*XRenderFillRectangle(data->display, data->blend_op, data->drawable_pict, |
1379 &foreground); | 1369 &foreground, 0, 0, window->w, window->h);*/ |
1380 if (!fill) { | |
1381 SDL_SetError("XRenderCreateSolidFill() failed"); | |
1382 return -1; | |
1383 } | |
1384 XRenderComposite(data->display, data->blend_op, fill, None, | |
1385 data->drawable_pict, 0, 0, 0, 0, 0, 0, window->w, window->h); | |
1386 attributes.clip_mask = None; | 1370 attributes.clip_mask = None; |
1387 XRenderChangePicture(data->display, data->drawable_pict, CPClipMask, &attributes); | 1371 XRenderChangePicture(data->display, data->drawable_pict, CPClipMask, &attributes); |
1388 XRenderFreePicture(data->display, fill); | |
1389 } | 1372 } |
1390 else | 1373 else |
1391 #endif | 1374 #endif |
1392 { | 1375 { |
1393 unsigned long foreground; | 1376 unsigned long foreground; |
1744 } | 1727 } |
1745 #ifdef SDL_VIDEO_DRIVER_X11_XRENDER | 1728 #ifdef SDL_VIDEO_DRIVER_X11_XRENDER |
1746 if (data->mask_gc) { | 1729 if (data->mask_gc) { |
1747 XFreeGC(data->display, data->mask_gc); | 1730 XFreeGC(data->display, data->mask_gc); |
1748 } | 1731 } |
1749 if (data->mask_pict) { | |
1750 XRenderFreePicture(data->display, data->mask_pict); | |
1751 } | |
1752 if (data->mask) { | 1732 if (data->mask) { |
1753 XFreePixmap(data->display, data->mask); | 1733 XFreePixmap(data->display, data->mask); |
1754 } | 1734 } |
1755 if (data->drawable_pict) { | 1735 if (data->drawable_pict) { |
1756 XRenderFreePicture(data->display, data->drawable_pict); | 1736 XRenderFreePicture(data->display, data->drawable_pict); |