Mercurial > sdl-ios-xcode
comparison src/video/x11/SDL_x11render.c @ 4589:8d8a889530eb
Fix blending modes for primitives.
author | Sunny Sachanandani <sunnysachanandani@gmail.com> |
---|---|
date | Thu, 01 Jul 2010 07:35:15 +0530 |
parents | 0ddd78496d68 |
children | 1ad70fb49fcb |
comparison
equal
deleted
inserted
replaced
4588:0ddd78496d68 | 4589:8d8a889530eb |
---|---|
229 if(!data->xwindow_pict) { | 229 if(!data->xwindow_pict) { |
230 data->use_xrender = SDL_FALSE; | 230 data->use_xrender = SDL_FALSE; |
231 goto fallback; | 231 goto fallback; |
232 } | 232 } |
233 // Create a 1 bit depth mask | 233 // Create a 1 bit depth mask |
234 data->mask = XCreatePixmap(data->display, data->xwindow, window->w, window->h, 1); | 234 data->mask = XCreatePixmap(data->display, data->xwindow, |
235 window->w, window->h, 1); | |
235 data->mask_pict = XRenderCreatePicture(data->display, data->mask, | 236 data->mask_pict = XRenderCreatePicture(data->display, data->mask, |
236 XRenderFindStandardFormat(data->display, PictStandardA1), | 237 XRenderFindStandardFormat(data->display, |
238 PictStandardA1), | |
237 0, NULL); | 239 0, NULL); |
238 XGCValues gcv_mask; | 240 XGCValues gcv_mask; |
239 gcv_mask.foreground = 1; | 241 gcv_mask.foreground = 1; |
240 gcv_mask.background = 0; | 242 gcv_mask.background = 0; |
241 data->mask_gc = XCreateGC(data->display, data->mask, GCBackground | GCForeground, &gcv_mask); | 243 data->mask_gc = XCreateGC(data->display, data->mask, GCBackground | GCForeground, &gcv_mask); |
299 XRenderCreatePicture(data->display, data->pixmaps[i], data->xwindow_pict_fmt, | 301 XRenderCreatePicture(data->display, data->pixmaps[i], data->xwindow_pict_fmt, |
300 0, None); | 302 0, None); |
301 if(!data->pixmap_picts[i]) { | 303 if(!data->pixmap_picts[i]) { |
302 data->use_xrender = SDL_FALSE; | 304 data->use_xrender = SDL_FALSE; |
303 } | 305 } |
304 XRenderComposite(data->display, PictOpClear, data->pixmap_picts[i], None, data->pixmap_picts[i], | 306 XRenderComposite(data->display, PictOpClear, |
307 data->pixmap_picts[i], None, data->pixmap_picts[i], | |
305 0, 0, 0, 0, 0, 0, window->w, window->h); | 308 0, 0, 0, 0, 0, 0, window->w, window->h); |
306 } | 309 } |
307 #endif | 310 #endif |
308 } | 311 } |
309 if (n > 0) { | 312 if (n > 0) { |
385 XRenderCreatePicture(data->display, data->pixmaps[i], data->xwindow_pict_fmt, | 388 XRenderCreatePicture(data->display, data->pixmaps[i], data->xwindow_pict_fmt, |
386 0, None); | 389 0, None); |
387 if(!data->pixmap_picts[i]) { | 390 if(!data->pixmap_picts[i]) { |
388 data->use_xrender = SDL_FALSE; | 391 data->use_xrender = SDL_FALSE; |
389 } | 392 } |
390 XRenderComposite(data->display, PictOpClear, data->pixmap_picts[i], None, data->pixmap_picts[i], | 393 XRenderComposite(data->display, PictOpClear, |
394 data->pixmap_picts[i], None, data->pixmap_picts[i], | |
391 0, 0, 0, 0, 0, 0, window->w, window->h); | 395 0, 0, 0, 0, 0, 0, window->w, window->h); |
392 } | 396 } |
393 #endif | 397 #endif |
394 } | 398 } |
395 if (n > 0) { | 399 if (n > 0) { |
568 } | 572 } |
569 } | 573 } |
570 #ifdef SDL_VIDEO_DRIVER_X11_XRENDER | 574 #ifdef SDL_VIDEO_DRIVER_X11_XRENDER |
571 if(renderdata->use_xrender && data->pixmap) { | 575 if(renderdata->use_xrender && data->pixmap) { |
572 data->use_xrender = SDL_TRUE; | 576 data->use_xrender = SDL_TRUE; |
573 /*unsigned long x11_fmt_mask; // Format mask | |
574 XRenderPictFormat x11_templ_fmt; // Format template | |
575 x11_fmt_mask = | |
576 (PictFormatRedMask | PictFormatGreenMask | |
577 | PictFormatBlueMask | PictFormatAlphaMask); | |
578 Uint32 Rmask, Gmask, Bmask, Amask; | |
579 int bpp; | |
580 SDL_PixelFormatEnumToMasks(data->format, &bpp, &Rmask, &Gmask, &Bmask, &Amask); | |
581 x11_templ_fmt.depth = bpp; | |
582 x11_templ_fmt.type = PictTypeDirect; | |
583 x11_templ_fmt.direct.red = Rmask / 0xff; | |
584 x11_templ_fmt.direct.green = Gmask / 0xff; | |
585 x11_templ_fmt.direct.blue = Bmask / 0xff; | |
586 x11_templ_fmt.direct.alpha = Amask / 0xff; | |
587 printf("%d %d %d %d\n", Rmask/0xff, Gmask/0xff, Bmask/0xff, Amask/0xff); | |
588 // Return a matching XRenderPictFormat | |
589 data->picture_fmt = | 577 data->picture_fmt = |
590 XRenderFindFormat(renderdata->display, x11_fmt_mask, &x11_templ_fmt, 0);*/ | 578 XRenderFindVisualFormat(renderdata->display, renderdata->visual); |
591 data->picture_fmt = | |
592 XRenderFindVisualFormat(renderdata->display, renderdata->visual); | |
593 if(!data->picture_fmt) { | 579 if(!data->picture_fmt) { |
594 printf("XRenderFindFormat failed!\n"); | 580 printf("XRenderFindFormat failed!\n"); |
595 data->use_xrender = SDL_FALSE; | 581 data->use_xrender = SDL_FALSE; |
596 } | 582 } |
597 data->picture = | 583 data->picture = |
758 return 0; | 744 return 0; |
759 case SDL_BLENDMODE_BLEND: // PictOpOver | 745 case SDL_BLENDMODE_BLEND: // PictOpOver |
760 data->blend_op = PictOpOver; | 746 data->blend_op = PictOpOver; |
761 return 0; | 747 return 0; |
762 /* FIXME case SDL_BLENDMODE_MOD: */ | 748 /* 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; | |
768 #endif | 749 #endif |
769 return 0; | 750 return 0; |
770 default: | 751 default: |
771 SDL_Unsupported(); | 752 SDL_Unsupported(); |
772 renderer->blendMode = SDL_BLENDMODE_NONE; | 753 renderer->blendMode = SDL_BLENDMODE_NONE; |
754 #ifdef SDL_VIDEO_DRIVER_X11_XRENDER | |
755 data->blend_op = PictOpSrc; | |
756 #endif | |
773 return -1; | 757 return -1; |
774 } | 758 } |
775 } | 759 } |
776 | 760 |
777 static Uint32 | 761 static Uint32 |
840 ++xcount; | 824 ++xcount; |
841 } | 825 } |
842 #ifdef SDL_VIDEO_DRIVER_X11_XRENDER | 826 #ifdef SDL_VIDEO_DRIVER_X11_XRENDER |
843 if (data->use_xrender == SDL_TRUE) { | 827 if (data->use_xrender == SDL_TRUE) { |
844 XRenderColor foreground; | 828 XRenderColor foreground; |
829 XRenderPictureAttributes attributes; | |
830 unsigned long valuemask; | |
845 | 831 |
846 foreground = xrenderdrawcolor(renderer); | 832 foreground = xrenderdrawcolor(renderer); |
833 /* Set the clip mask to restrict rendering to | |
834 * the primitive being drawn | |
835 */ | |
836 attributes.clip_mask = data->mask; | |
837 valuemask = CPClipMask; | |
847 | 838 |
848 XRenderComposite(data->display, PictOpClear, data->mask_pict, None, data->mask_pict, | 839 XRenderComposite(data->display, PictOpClear, data->mask_pict, None, data->mask_pict, |
849 0, 0, 0, 0, 0, 0, window->w, window->h); | 840 0, 0, 0, 0, 0, 0, window->w, window->h); |
850 | 841 |
851 XDrawPoints(data->display, data->mask, data->mask_gc, xpoints, xcount, | 842 XDrawPoints(data->display, data->mask, data->mask_gc, xpoints, xcount, |
852 CoordModeOrigin); | 843 CoordModeOrigin); |
853 | 844 XRenderChangePicture(data->display, data->drawable_pict, valuemask, &attributes); |
854 Picture fill = | 845 Picture fill = |
855 XRenderCreateSolidFill(data->display, &foreground); | 846 XRenderCreateSolidFill(data->display, &foreground); |
856 | 847 |
857 XRenderComposite(data->display, data->blend_op, fill, data->mask_pict, | 848 XRenderComposite(data->display, data->blend_op, fill, data->mask_pict, |
858 data->drawable_pict, 0, 0, 0, 0, 0, 0, window->w, window->h); | 849 data->drawable_pict, 0, 0, 0, 0, 0, 0, window->w, window->h); |
859 | 850 |
851 // Reset the clip_mask | |
852 attributes.clip_mask = None; | |
853 XRenderChangePicture(data->display, data->drawable_pict, valuemask, &attributes); | |
860 XRenderFreePicture(data->display, fill); | 854 XRenderFreePicture(data->display, fill); |
861 } | 855 } |
862 else | 856 else |
863 #endif | 857 #endif |
864 { | 858 { |
1027 } | 1021 } |
1028 } | 1022 } |
1029 #ifdef SDL_VIDEO_DRIVER_X11_XRENDER | 1023 #ifdef SDL_VIDEO_DRIVER_X11_XRENDER |
1030 if(data->use_xrender == SDL_TRUE) { | 1024 if(data->use_xrender == SDL_TRUE) { |
1031 XRenderColor xrforeground = xrenderdrawcolor(renderer); | 1025 XRenderColor xrforeground = xrenderdrawcolor(renderer); |
1026 XRenderPictureAttributes attributes; | |
1027 attributes.clip_mask = data->mask; | |
1028 unsigned long valuemask = CPClipMask; | |
1029 XRenderChangePicture(data->display, data->drawable_pict, valuemask, &attributes); | |
1032 Picture fill = XRenderCreateSolidFill(data->display, &xrforeground); | 1030 Picture fill = XRenderCreateSolidFill(data->display, &xrforeground); |
1033 XRenderComposite(data->display, data->blend_op, fill, data->mask_pict, | 1031 XRenderComposite(data->display, data->blend_op, fill, data->mask_pict, |
1034 data->drawable_pict, 0, 0, 0, 0, 0, 0, window->w, window->h); | 1032 data->drawable_pict, 0, 0, 0, 0, 0, 0, window->w, window->h); |
1033 attributes.clip_mask = None; | |
1034 XRenderChangePicture(data->display, data->drawable_pict, valuemask, &attributes); | |
1035 XRenderFreePicture(data->display, fill); | 1035 XRenderFreePicture(data->display, fill); |
1036 } | 1036 } |
1037 #endif | 1037 #endif |
1038 SDL_stack_free(xpoints); | 1038 SDL_stack_free(xpoints); |
1039 | 1039 |
1072 clip.h = window->h; | 1072 clip.h = window->h; |
1073 | 1073 |
1074 #ifdef SDL_VIDEO_DRIVER_X11_XRENDER | 1074 #ifdef SDL_VIDEO_DRIVER_X11_XRENDER |
1075 if(data->use_xrender == SDL_TRUE) { | 1075 if(data->use_xrender == SDL_TRUE) { |
1076 XRenderColor foreground; | 1076 XRenderColor foreground; |
1077 XRenderPictureAttributes attributes; | |
1078 unsigned long valuemask; | |
1079 | |
1077 foreground = xrenderdrawcolor(renderer); | 1080 foreground = xrenderdrawcolor(renderer); |
1081 valuemask = CPClipMask; | |
1082 attributes.clip_mask = data->mask; | |
1078 | 1083 |
1079 XRenderComposite(data->display, PictOpClear, data->mask_pict, None, data->mask_pict, | 1084 XRenderComposite(data->display, PictOpClear, data->mask_pict, None, data->mask_pict, |
1080 0, 0, 0, 0, 0, 0, window->w, window->h); | 1085 0, 0, 0, 0, 0, 0, window->w, window->h); |
1081 XDrawRectangles(data->display, data->mask, data->mask_gc, xrects, xcount); | 1086 XDrawRectangles(data->display, data->mask, data->mask_gc, xrects, xcount); |
1087 XRenderChangePicture(data->display, data->drawable_pict, valuemask, &attributes); | |
1082 Picture fill = | 1088 Picture fill = |
1083 XRenderCreateSolidFill(data->display, &foreground); | 1089 XRenderCreateSolidFill(data->display, &foreground); |
1084 XRenderComposite(data->display, data->blend_op, fill, data->mask_pict, | 1090 XRenderComposite(data->display, data->blend_op, fill, data->mask_pict, |
1085 data->drawable_pict, 0, 0, 0, 0, 0, 0, window->w, window->h); | 1091 data->drawable_pict, 0, 0, 0, 0, 0, 0, window->w, window->h); |
1092 attributes.clip_mask = None; | |
1093 XRenderChangePicture(data->display, data->drawable_pict, valuemask, &attributes); | |
1086 XRenderFreePicture(data->display, fill); | 1094 XRenderFreePicture(data->display, fill); |
1087 } | 1095 } |
1088 else | 1096 else |
1089 #endif | 1097 #endif |
1090 { | 1098 { |
1137 } | 1145 } |
1138 | 1146 |
1139 #ifdef SDL_VIDEO_DRIVER_X11_XRENDER | 1147 #ifdef SDL_VIDEO_DRIVER_X11_XRENDER |
1140 if(data->use_xrender == SDL_TRUE) { | 1148 if(data->use_xrender == SDL_TRUE) { |
1141 XRenderColor foreground; | 1149 XRenderColor foreground; |
1150 XRenderPictureAttributes attributes; | |
1151 unsigned long valuemask; | |
1142 | 1152 |
1143 foreground = xrenderdrawcolor(renderer); | 1153 foreground = xrenderdrawcolor(renderer); |
1144 | 1154 attributes.clip_mask = data->mask; |
1155 valuemask = CPClipMask; | |
1156 attributes.clip_mask = data->mask; | |
1157 | |
1145 XRenderComposite(data->display, PictOpClear, data->mask_pict, None, data->mask_pict, | 1158 XRenderComposite(data->display, PictOpClear, data->mask_pict, None, data->mask_pict, |
1146 0, 0, 0, 0, 0, 0, window->w, window->h); | 1159 0, 0, 0, 0, 0, 0, window->w, window->h); |
1147 XFillRectangles(data->display, data->mask, data->mask_gc, | 1160 XFillRectangles(data->display, data->mask, data->mask_gc, |
1148 xrects, xcount); | 1161 xrects, xcount); |
1162 | |
1163 XRenderChangePicture(data->display, data->drawable_pict, valuemask, &attributes); | |
1164 | |
1149 Picture fill = | 1165 Picture fill = |
1150 XRenderCreateSolidFill(data->display, &foreground); | 1166 XRenderCreateSolidFill(data->display, &foreground); |
1151 XRenderComposite(data->display, data->blend_op, fill, data->mask_pict, | 1167 XRenderComposite(data->display, data->blend_op, fill, data->mask_pict, |
1152 data->drawable_pict, 0, 0, 0, 0, 0, 0, window->w, window->h); | 1168 data->drawable_pict, 0, 0, 0, 0, 0, 0, window->w, window->h); |
1169 attributes.clip_mask = None; | |
1170 XRenderChangePicture(data->display, data->drawable_pict, valuemask, &attributes); | |
1153 XRenderFreePicture(data->display, fill); | 1171 XRenderFreePicture(data->display, fill); |
1154 } | 1172 } |
1155 else | 1173 else |
1156 #endif | 1174 #endif |
1157 { | 1175 { |