comparison src/video/x11/SDL_x11render.c @ 4606:4e145485971b

Implement support for setting texture scale mode.
author Sunny Sachanandani <sunnysachanandani@gmail.com>
date Tue, 20 Jul 2010 11:43:13 +0530
parents 0b3a509c53a0
children 9e9ec5e3be95
comparison
equal deleted inserted replaced
4605:0b3a509c53a0 4606:4e145485971b
133 GC gc; 133 GC gc;
134 #ifdef SDL_VIDEO_DRIVER_X11_XRENDER 134 #ifdef SDL_VIDEO_DRIVER_X11_XRENDER
135 Picture picture; 135 Picture picture;
136 XRenderPictFormat* picture_fmt; 136 XRenderPictFormat* picture_fmt;
137 int blend_op; 137 int blend_op;
138 const char* filter;
138 #endif 139 #endif
139 XImage *image; 140 XImage *image;
140 #ifndef NO_SHARED_MEMORY 141 #ifndef NO_SHARED_MEMORY
141 /* MIT shared memory extension information */ 142 /* MIT shared memory extension information */
142 XShmSegmentInfo shminfo; 143 XShmSegmentInfo shminfo;
374 0, 0, 375 0, 0,
375 0, 0, 376 0, 0,
376 window->w, window->h); 377 window->w, window->h);
377 /* Add some blending modes to the list of supported blending modes */ 378 /* Add some blending modes to the list of supported blending modes */
378 renderer->info.blend_modes |= 379 renderer->info.blend_modes |=
379 (SDL_BLENDMODE_BLEND | SDL_BLENDMODE_ADD | SDL_BLENDMODE_MASK); 380 (SDL_BLENDMODE_BLEND | SDL_BLENDMODE_ADD | SDL_BLENDMODE_MASK | SDL_BLENDMODE_MOD);
380 /* Create a clip mask that is used for rendering primitives. */ 381 /* Create a clip mask that is used for rendering primitives. */
381 data->stencil = XCreatePixmap(data->display, data->xwindow, 382 data->stencil = XCreatePixmap(data->display, data->xwindow,
382 window->w, window->h, 8); 383 window->w, window->h, 8);
383 384
384 /* Create the GC for the clip mask. */ 385 /* Create the GC for the clip mask. */
922 923
923 static int 924 static int
924 X11_SetTextureBlendMode(SDL_Renderer * renderer, SDL_Texture * texture) 925 X11_SetTextureBlendMode(SDL_Renderer * renderer, SDL_Texture * texture)
925 { 926 {
926 X11_TextureData *data = (X11_TextureData *) texture->driverdata; 927 X11_TextureData *data = (X11_TextureData *) texture->driverdata;
928 X11_RenderData *renderdata = (X11_RenderData *) renderer->driverdata;
927 switch (texture->blendMode) { 929 switch (texture->blendMode) {
928 case SDL_BLENDMODE_NONE: 930 case SDL_BLENDMODE_NONE:
929 #ifdef SDL_VIDEO_DRIVER_X11_XRENDER 931 #ifdef SDL_VIDEO_DRIVER_X11_XRENDER
930 data->blend_op = PictOpSrc; 932 if (renderdata->use_xrender) {
933 data->blend_op = PictOpSrc;
934 return 0;
935 }
936 case SDL_BLENDMODE_MOD:
937 if (renderdata->use_xrender) {
938 data->blend_op = PictOpSrc;
939 return 0;
940 }
941 case SDL_BLENDMODE_MASK:
942 case SDL_BLENDMODE_BLEND:
943 if (renderdata->use_xrender) {
944 data->blend_op = PictOpOver;
945 return 0;
946 }
947 case SDL_BLENDMODE_ADD:
948 if (renderdata->use_xrender) {
949 data->blend_op = PictOpAdd;
950 return 0;
951 }
952 #endif
931 return 0; 953 return 0;
932 case SDL_BLENDMODE_BLEND:
933 data->blend_op = PictOpOver;
934 return 0;
935 case SDL_BLENDMODE_ADD:
936 data->blend_op = PictOpAdd;
937 return 0;
938 #endif
939 default: 954 default:
940 SDL_Unsupported(); 955 SDL_Unsupported();
941 texture->blendMode = SDL_BLENDMODE_NONE; 956 texture->blendMode = SDL_BLENDMODE_NONE;
942 #ifdef SDL_VIDEO_DRIVER_X11_XRENDER 957 #ifdef SDL_VIDEO_DRIVER_X11_XRENDER
943 texture->blendMode = SDL_BLENDMODE_BLEND; 958 if (renderdata->use_xrender) {
944 data->blend_op = PictOpOver; 959 texture->blendMode = SDL_BLENDMODE_BLEND;
960 data->blend_op = PictOpOver;
961 }
945 #endif 962 #endif
946 return -1; 963 return -1;
947 } 964 }
948 } 965 }
949 966
950 static int 967 static int
951 X11_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture) 968 X11_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture)
952 { 969 {
953 X11_TextureData *data = (X11_TextureData *) texture->driverdata; 970 X11_TextureData *data = (X11_TextureData *) texture->driverdata;
971 X11_RenderData *renderdata = (X11_RenderData *) renderer->driverdata;
954 972
955 switch (texture->scaleMode) { 973 switch (texture->scaleMode) {
956 case SDL_TEXTURESCALEMODE_NONE: 974 case SDL_TEXTURESCALEMODE_NONE:
957 return 0; 975 return 0;
958 case SDL_TEXTURESCALEMODE_FAST: 976 case SDL_TEXTURESCALEMODE_FAST:
959 /* We can sort of fake it for streaming textures */ 977 /* We can sort of fake it for streaming textures */
960 if (data->yuv || texture->access == SDL_TEXTUREACCESS_STREAMING) { 978 if (data->yuv || texture->access == SDL_TEXTUREACCESS_STREAMING) {
961 return 0; 979 return 0;
962 } 980 }
963 /* Fall through to unsupported case */ 981 #ifdef SDL_VIDEO_DRIVER_X11_XRENDER
982 if (renderdata->use_xrender) {
983 data->filter = FilterFast;
984 return 0;
985 }
986 case SDL_TEXTURESCALEMODE_SLOW:
987 if (renderdata->use_xrender) {
988 data->filter = FilterGood;
989 return 0;
990 }
991 case SDL_TEXTURESCALEMODE_BEST:
992 if (renderdata->use_xrender) {
993 data->filter = FilterBest;
994 return 0;
995 }
996 #endif
997 /* Fall through to unsupported case */
964 default: 998 default:
965 SDL_Unsupported(); 999 SDL_Unsupported();
966 texture->scaleMode = SDL_TEXTURESCALEMODE_NONE; 1000 #ifdef SDL_VIDEO_DRIVER_X11_XRENDER
1001 if (renderdata->use_xrender) {
1002 texture->scaleMode = SDL_TEXTURESCALEMODE_FAST;
1003 data->filter = FilterFast;
1004 }
1005 else
1006 #endif
1007 texture->scaleMode = SDL_TEXTURESCALEMODE_NONE;
967 return -1; 1008 return -1;
968 } 1009 }
969 return 0; 1010 return 0;
970 } 1011 }
971 1012
1052 case SDL_BLENDMODE_NONE: 1093 case SDL_BLENDMODE_NONE:
1053 #ifdef SDL_VIDEO_DRIVER_X11_XRENDER 1094 #ifdef SDL_VIDEO_DRIVER_X11_XRENDER
1054 //PictOpSrc 1095 //PictOpSrc
1055 data->blend_op = PictOpSrc; 1096 data->blend_op = PictOpSrc;
1056 return 0; 1097 return 0;
1098 case SDL_BLENDMODE_MOD:
1099 case SDL_BLENDMODE_MASK:
1057 case SDL_BLENDMODE_BLEND: // PictOpOver 1100 case SDL_BLENDMODE_BLEND: // PictOpOver
1058 data->blend_op = PictOpOver; 1101 data->blend_op = PictOpOver;
1059 return 0; 1102 return 0;
1060 case SDL_BLENDMODE_ADD: // PictOpAdd 1103 case SDL_BLENDMODE_ADD: // PictOpAdd
1061 data->blend_op = PictOpAdd; 1104 data->blend_op = PictOpAdd;
1112 (unsigned short) ((renderer->r / 255.0) * alphad * 0xFFFF); 1155 (unsigned short) ((renderer->r / 255.0) * alphad * 0xFFFF);
1113 xrender_color.green = 1156 xrender_color.green =
1114 (unsigned short) ((renderer->g / 255.0) * alphad * 0xFFFF); 1157 (unsigned short) ((renderer->g / 255.0) * alphad * 0xFFFF);
1115 xrender_color.blue = 1158 xrender_color.blue =
1116 (unsigned short) ((renderer->b / 255.0) * alphad * 0xFFFF); 1159 (unsigned short) ((renderer->b / 255.0) * alphad * 0xFFFF);
1160
1117 return xrender_color; 1161 return xrender_color;
1118 } 1162 }
1119 1163
1120 static int 1164 static int
1121 X11_RenderDrawPoints(SDL_Renderer * renderer, const SDL_Point * points, 1165 X11_RenderDrawPoints(SDL_Renderer * renderer, const SDL_Point * points,
1165 (renderer->blendMode != SDL_BLENDMODE_NONE) && 1209 (renderer->blendMode != SDL_BLENDMODE_NONE) &&
1166 !(renderer->a == 0xFF && 1210 !(renderer->a == 0xFF &&
1167 renderer->blendMode != SDL_BLENDMODE_ADD && 1211 renderer->blendMode != SDL_BLENDMODE_ADD &&
1168 renderer->blendMode != SDL_BLENDMODE_MOD)) 1212 renderer->blendMode != SDL_BLENDMODE_MOD))
1169 { 1213 {
1170 XSetForeground(data->display, data->stencil_gc, 0x00); 1214 XSetForeground(data->display, data->stencil_gc, 0x00000000);
1171 #ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE 1215 #ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE
1172 if (data->use_xdamage) 1216 if (data->use_xdamage)
1173 { 1217 {
1174 /* Update only those parts which were changed 1218 /* Update only those parts which were changed
1175 * in the previous drawing operation */ 1219 * in the previous drawing operation */
1277 renderer->blendMode != SDL_BLENDMODE_MOD)) 1321 renderer->blendMode != SDL_BLENDMODE_MOD))
1278 { 1322 {
1279 drawable = data->stencil; 1323 drawable = data->stencil;
1280 gc = data->stencil_gc; 1324 gc = data->stencil_gc;
1281 1325
1282 XSetForeground(data->display, data->stencil_gc, 0x00); 1326 XSetForeground(data->display, data->stencil_gc, 0x00000000);
1283 #ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE 1327 #ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE
1284 if (data->use_xdamage) 1328 if (data->use_xdamage)
1285 XFixesSetGCClipRegion(data->display, data->stencil_gc, 1329 XFixesSetGCClipRegion(data->display, data->stencil_gc,
1286 0, 0, data->stencil_parts); 1330 0, 0, data->stencil_parts);
1287 #endif 1331 #endif
1490 (renderer->blendMode != SDL_BLENDMODE_NONE) && 1534 (renderer->blendMode != SDL_BLENDMODE_NONE) &&
1491 !(renderer->a == 0xFF && 1535 !(renderer->a == 0xFF &&
1492 renderer->blendMode != SDL_BLENDMODE_ADD && 1536 renderer->blendMode != SDL_BLENDMODE_ADD &&
1493 renderer->blendMode != SDL_BLENDMODE_MOD)) 1537 renderer->blendMode != SDL_BLENDMODE_MOD))
1494 { 1538 {
1495 XSetForeground(data->display, data->stencil_gc, 0x00); 1539 XSetForeground(data->display, data->stencil_gc, 0x00000000);
1496 #ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE 1540 #ifdef SDL_VIDEO_DRIVER_X11_XDAMAGE
1497 if (data->use_xdamage) 1541 if (data->use_xdamage)
1498 XFixesSetGCClipRegion(data->display, data->stencil_gc, 1542 XFixesSetGCClipRegion(data->display, data->stencil_gc,
1499 0, 0, data->stencil_parts); 1543 0, 0, data->stencil_parts);
1500 #endif 1544 #endif
1649 XPutImage(data->display, texturedata->pixmap, data->gc, 1693 XPutImage(data->display, texturedata->pixmap, data->gc,
1650 texturedata->image, srcrect->x, srcrect->y, dstrect->x, 1694 texturedata->image, srcrect->x, srcrect->y, dstrect->x,
1651 dstrect->y, srcrect->w, srcrect->h); 1695 dstrect->y, srcrect->w, srcrect->h);
1652 } 1696 }
1653 } 1697 }
1654 Picture pict; 1698 Picture src, mask, dst;
1655 if(texture->blendMode == SDL_BLENDMODE_NONE) 1699 XRenderPictureAttributes attr;
1656 pict = None; 1700 if(texture->blendMode == SDL_BLENDMODE_NONE) {
1657 else 1701 src = texturedata->picture;
1658 pict = texturedata->picture; 1702 mask = None;
1703 dst = data->drawable_pict;
1704 }
1705 /*else if (texture->blendMode == SDL_BLENDMODE_MOD) {
1706 src = data->drawable_pict;
1707 mask = texturedata->picture;
1708 dst = data->drawable_pict;
1709 attr.alpha_map = mask;
1710 }*/
1711 else {
1712 src = texturedata->picture;
1713 mask = texturedata->picture;
1714 dst = data->drawable_pict;
1715 }
1659 if(srcrect->w == dstrect->w && srcrect->h == dstrect->h) { 1716 if(srcrect->w == dstrect->w && srcrect->h == dstrect->h) {
1660 XRenderComposite(data->display, texturedata->blend_op, texturedata->picture, 1717 /*if (texture->blendMode == SDL_BLENDMODE_MOD) {
1661 pict, data->drawable_pict, srcrect->x, srcrect->y, 1718 attr.component_alpha = True;
1662 srcrect->x, srcrect->y, dstrect->x, dstrect->y, 1719 XRenderChangePicture(data->display, texturedata->picture,
1663 srcrect->w, srcrect->h); 1720 CPComponentAlpha, &attr);
1721 XRenderChangePicture(data->display, src, CPAlphaMap, &attr);
1722 }*/
1723 XRenderComposite(data->display, texturedata->blend_op, src,
1724 mask, dst, srcrect->x, srcrect->y,
1725 srcrect->x, srcrect->y, dstrect->x, dstrect->y,
1726 srcrect->w, srcrect->h);
1664 } else { 1727 } else {
1665 double xscale = ((double) dstrect->w) / srcrect->w; 1728 double xscale = ((double) dstrect->w) / srcrect->w;
1666 double yscale = ((double) dstrect->h) / srcrect->h; 1729 double yscale = ((double) dstrect->h) / srcrect->h;
1667 XTransform xform = {{ 1730 XTransform xform = {{
1668 {XDoubleToFixed(xscale), XDoubleToFixed(0), XDoubleToFixed(0)}, 1731 {XDoubleToFixed(xscale), XDoubleToFixed(0), XDoubleToFixed(0)},
1669 {XDoubleToFixed(0), XDoubleToFixed(yscale), XDoubleToFixed(0)}, 1732 {XDoubleToFixed(0), XDoubleToFixed(yscale), XDoubleToFixed(0)},
1670 {XDoubleToFixed(0), XDoubleToFixed(0), XDoubleToFixed(xscale * yscale)}}}; 1733 {XDoubleToFixed(0), XDoubleToFixed(0), XDoubleToFixed(xscale * yscale)}}};
1671 XRenderSetPictureTransform(data->display, texturedata->picture, &xform); 1734 XRenderSetPictureTransform(data->display, texturedata->picture, &xform);
1735
1736 /*if (texture->blendMode == SDL_BLENDMODE_MOD) {
1737 attr.component_alpha = True;
1738 XRenderChangePicture(data->display, texturedata->picture,
1739 CPComponentAlpha, &attr);
1740 XRenderChangePicture(data->display, src, CPAlphaMap, &attr);
1741 }*/
1742
1743 XRenderSetPictureFilter(data->display, texturedata->picture,
1744 texturedata->filter, 0, 0);
1672 1745
1673 XRenderComposite(data->display, texturedata->blend_op, 1746 XRenderComposite(data->display, texturedata->blend_op,
1674 texturedata->picture, pict, data->drawable_pict, 1747 src, mask, dst,
1675 0, 0, 0, 0, dstrect->x, dstrect->y, 1748 srcrect->x, srcrect->y, srcrect->x, srcrect->y,
1676 dstrect->w, dstrect->h); 1749 dstrect->x, dstrect->y, dstrect->w, dstrect->h);
1677 1750
1678 XTransform identity = {{ 1751 XTransform identity = {{
1679 {XDoubleToFixed(1), XDoubleToFixed(0), XDoubleToFixed(0)}, 1752 {XDoubleToFixed(1), XDoubleToFixed(0), XDoubleToFixed(0)},
1680 {XDoubleToFixed(0), XDoubleToFixed(1), XDoubleToFixed(0)}, 1753 {XDoubleToFixed(0), XDoubleToFixed(1), XDoubleToFixed(0)},
1681 {XDoubleToFixed(0), XDoubleToFixed(0), XDoubleToFixed(1)}}}; 1754 {XDoubleToFixed(0), XDoubleToFixed(0), XDoubleToFixed(1)}}};
1682 XRenderSetPictureTransform(data->display, texturedata->picture, &identity); 1755 XRenderSetPictureTransform(data->display, texturedata->picture, &identity);
1683 } 1756 }
1757 /*if (renderer->blendMode == SDL_BLENDMODE_MOD) {
1758 attr.component_alpha = False;
1759 XRenderChangePicture(data->display, texturedata->picture,
1760 CPComponentAlpha, &attr);
1761 attr.alpha_map = None;
1762 XRenderChangePicture(data->display, data->drawable_pict,
1763 CPAlphaMap, &attr);
1764 }*/
1684 } 1765 }
1685 else 1766 else
1686 #endif 1767 #endif
1687 { 1768 {
1688 if (srcrect->w == dstrect->w && srcrect->h == dstrect->h) { 1769 if (srcrect->w == dstrect->w && srcrect->h == dstrect->h) {