comparison src/video/x11/SDL_x11render.c @ 4588:0ddd78496d68

Preliminary support for blending modes on drawing operations.
author Sunny Sachanandani <sunnysachanandani@gmail.com>
date Sun, 27 Jun 2010 09:51:51 +0530
parents 25391ccf16a0
children 8d8a889530eb
comparison
equal deleted inserted replaced
4587:25391ccf16a0 4588:0ddd78496d68
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; 104 Picture mask_pict;
105 int blend_op;
105 XRenderPictFormat* xwindow_pict_fmt; 106 XRenderPictFormat* xwindow_pict_fmt;
106 GC mask_gc; 107 GC mask_gc;
107 SDL_bool use_xrender; 108 SDL_bool use_xrender;
108 #endif 109 #endif
109 int current_pixmap; 110 int current_pixmap;
741 } 742 }
742 743
743 static int 744 static int
744 X11_SetDrawBlendMode(SDL_Renderer * renderer) 745 X11_SetDrawBlendMode(SDL_Renderer * renderer)
745 { 746 {
747 X11_RenderData *data = (X11_RenderData *) renderer->driverdata;
746 switch (renderer->blendMode) { 748 switch (renderer->blendMode) {
747 case SDL_BLENDMODE_NONE: 749 case SDL_BLENDMODE_NONE:
750 #ifdef SDL_VIDEO_DRIVER_X11_XRENDER
751 data->blend_op = PictOpSrc;
748 return 0; 752 return 0;
749 #ifdef SDL_VIDEO_DRIVER_X11_XRENDER
750 case SDL_BLENDMODE_MASK: // Use src pict as mask 753 case SDL_BLENDMODE_MASK: // Use src pict as mask
754 data->blend_op = PictOpSrc;
755 return 0;
751 case SDL_BLENDMODE_ADD: // PictOpAdd 756 case SDL_BLENDMODE_ADD: // PictOpAdd
757 data->blend_op = PictOpAdd;
758 return 0;
752 case SDL_BLENDMODE_BLEND: // PictOpOver 759 case SDL_BLENDMODE_BLEND: // PictOpOver
760 data->blend_op = PictOpOver;
761 return 0;
753 /* FIXME case SDL_BLENDMODE_MOD: */ 762 /* FIXME case SDL_BLENDMODE_MOD: */
763 default: // PictOpSrc
764 SDL_Unsupported();
765 renderer->blendMode = SDL_BLENDMODE_NONE;
766 data->blend_op = PictOpSrc;
767 return -1;
754 #endif 768 #endif
755 return 0; 769 return 0;
756 default: 770 default:
757 SDL_Unsupported(); 771 SDL_Unsupported();
758 renderer->blendMode = SDL_BLENDMODE_NONE; 772 renderer->blendMode = SDL_BLENDMODE_NONE;
838 CoordModeOrigin); 852 CoordModeOrigin);
839 853
840 Picture fill = 854 Picture fill =
841 XRenderCreateSolidFill(data->display, &foreground); 855 XRenderCreateSolidFill(data->display, &foreground);
842 856
843 XRenderComposite(data->display, PictOpOver, fill, data->mask_pict, data->drawable_pict, 857 XRenderComposite(data->display, data->blend_op, fill, data->mask_pict,
844 0, 0, 0, 0, 0, 0, window->w, window->h); 858 data->drawable_pict, 0, 0, 0, 0, 0, 0, window->w, window->h);
845 859
846 XRenderFreePicture(data->display, fill); 860 XRenderFreePicture(data->display, fill);
847 } 861 }
848 else 862 else
849 #endif 863 #endif
1014 } 1028 }
1015 #ifdef SDL_VIDEO_DRIVER_X11_XRENDER 1029 #ifdef SDL_VIDEO_DRIVER_X11_XRENDER
1016 if(data->use_xrender == SDL_TRUE) { 1030 if(data->use_xrender == SDL_TRUE) {
1017 XRenderColor xrforeground = xrenderdrawcolor(renderer); 1031 XRenderColor xrforeground = xrenderdrawcolor(renderer);
1018 Picture fill = XRenderCreateSolidFill(data->display, &xrforeground); 1032 Picture fill = XRenderCreateSolidFill(data->display, &xrforeground);
1019 XRenderComposite(data->display, PictOpOver, fill, data->mask_pict, data->drawable_pict, 1033 XRenderComposite(data->display, data->blend_op, fill, data->mask_pict,
1020 0, 0, 0, 0, 0, 0, window->w, window->h); 1034 data->drawable_pict, 0, 0, 0, 0, 0, 0, window->w, window->h);
1021 XRenderFreePicture(data->display, fill); 1035 XRenderFreePicture(data->display, fill);
1022 } 1036 }
1023 #endif 1037 #endif
1024 SDL_stack_free(xpoints); 1038 SDL_stack_free(xpoints);
1025 1039
1065 XRenderComposite(data->display, PictOpClear, data->mask_pict, None, data->mask_pict, 1079 XRenderComposite(data->display, PictOpClear, data->mask_pict, None, data->mask_pict,
1066 0, 0, 0, 0, 0, 0, window->w, window->h); 1080 0, 0, 0, 0, 0, 0, window->w, window->h);
1067 XDrawRectangles(data->display, data->mask, data->mask_gc, xrects, xcount); 1081 XDrawRectangles(data->display, data->mask, data->mask_gc, xrects, xcount);
1068 Picture fill = 1082 Picture fill =
1069 XRenderCreateSolidFill(data->display, &foreground); 1083 XRenderCreateSolidFill(data->display, &foreground);
1070 XRenderComposite(data->display, PictOpOver, fill, data->mask_pict, data->drawable_pict, 1084 XRenderComposite(data->display, data->blend_op, fill, data->mask_pict,
1071 0, 0, 0, 0, 0, 0, window->w, window->h); 1085 data->drawable_pict, 0, 0, 0, 0, 0, 0, window->w, window->h);
1072 XRenderFreePicture(data->display, fill); 1086 XRenderFreePicture(data->display, fill);
1073 } 1087 }
1074 else 1088 else
1075 #endif 1089 #endif
1076 { 1090 {
1132 0, 0, 0, 0, 0, 0, window->w, window->h); 1146 0, 0, 0, 0, 0, 0, window->w, window->h);
1133 XFillRectangles(data->display, data->mask, data->mask_gc, 1147 XFillRectangles(data->display, data->mask, data->mask_gc,
1134 xrects, xcount); 1148 xrects, xcount);
1135 Picture fill = 1149 Picture fill =
1136 XRenderCreateSolidFill(data->display, &foreground); 1150 XRenderCreateSolidFill(data->display, &foreground);
1137 XRenderComposite(data->display, PictOpOver, fill, data->mask_pict, data->drawable_pict, 1151 XRenderComposite(data->display, data->blend_op, fill, data->mask_pict,
1138 0, 0, 0, 0, 0, 0, window->w, window->h); 1152 data->drawable_pict, 0, 0, 0, 0, 0, 0, window->w, window->h);
1139 XRenderFreePicture(data->display, fill); 1153 XRenderFreePicture(data->display, fill);
1140 } 1154 }
1141 else 1155 else
1142 #endif 1156 #endif
1143 { 1157 {
1390 for (dirty = data->dirty.list; dirty; dirty = dirty->next) { 1404 for (dirty = data->dirty.list; dirty; dirty = dirty->next) {
1391 const SDL_Rect *rect = &dirty->rect; 1405 const SDL_Rect *rect = &dirty->rect;
1392 #ifdef SDL_VIDEO_DRIVER_X11_XRENDER 1406 #ifdef SDL_VIDEO_DRIVER_X11_XRENDER
1393 if(data->use_xrender == SDL_TRUE) 1407 if(data->use_xrender == SDL_TRUE)
1394 { 1408 {
1395 XRenderComposite(data->display, PictOpOver, data->drawable_pict, None, data->xwindow_pict, 1409 if(renderer->blendMode == SDL_BLENDMODE_MASK)
1396 rect->x, rect->y, 0, 0, rect->x, rect->y, rect->w, rect->h); 1410 XRenderComposite(data->display, data->blend_op, data->drawable_pict,
1411 data->drawable_pict, data->xwindow_pict, rect->x, rect->y,
1412 0, 0, rect->x, rect->y, rect->w, rect->h);
1413 else
1414 XRenderComposite(data->display, data->blend_op, data->drawable_pict, None,
1415 data->xwindow_pict, rect->x, rect->y, 0, 0, rect->x, rect->y,
1416 rect->w, rect->h);
1417
1397 } 1418 }
1398 else 1419 else
1399 #endif 1420 #endif
1400 { 1421 {
1401 XCopyArea(data->display, data->drawable, data->xwindow, 1422 XCopyArea(data->display, data->drawable, data->xwindow,