comparison src/video/x11/SDL_x11render.c @ 4629:44fd1f0b895a

Fixed a huge bug with texture scaling.
author Sunny Sachanandani <sunnysachanandani@gmail.com>
date Mon, 02 Aug 2010 11:13:40 +0530
parents b70b99ab75b8
children 02895e9c796b
comparison
equal deleted inserted replaced
4624:b70b99ab75b8 4629:44fd1f0b895a
1019 X11_DestroyTexture(renderer, texture); 1019 X11_DestroyTexture(renderer, texture);
1020 SDL_SetError("XRenderCreatePicture() failed"); 1020 SDL_SetError("XRenderCreatePicture() failed");
1021 return -1; 1021 return -1;
1022 } 1022 }
1023 texture->blendMode = SDL_BLENDMODE_NONE; 1023 texture->blendMode = SDL_BLENDMODE_NONE;
1024 texture->scaleMode = SDL_TEXTURESCALEMODE_NONE;
1024 data->blend_op = PictOpSrc; 1025 data->blend_op = PictOpSrc;
1025 data->filter = "fast"; 1026 data->filter = NULL;
1026 } 1027 }
1027 #endif 1028 #endif
1028 return 0; 1029 return 0;
1029 } 1030 }
1030 1031
1157 X11_TextureData *data = (X11_TextureData *) texture->driverdata; 1158 X11_TextureData *data = (X11_TextureData *) texture->driverdata;
1158 X11_RenderData *renderdata = (X11_RenderData *) renderer->driverdata; 1159 X11_RenderData *renderdata = (X11_RenderData *) renderer->driverdata;
1159 1160
1160 switch (texture->scaleMode) { 1161 switch (texture->scaleMode) {
1161 case SDL_TEXTURESCALEMODE_NONE: 1162 case SDL_TEXTURESCALEMODE_NONE:
1163 #ifdef SDL_VIDEO_DRIVER_X11_XRENDER
1164 if (renderdata->use_xrender) {
1165 data->filter = NULL;
1166 }
1167 #endif
1162 return 0; 1168 return 0;
1163 case SDL_TEXTURESCALEMODE_FAST: 1169 case SDL_TEXTURESCALEMODE_FAST:
1164 /* We can sort of fake it for streaming textures */ 1170 /* We can sort of fake it for streaming textures */
1165 if (data->yuv || texture->access == SDL_TEXTUREACCESS_STREAMING) { 1171 if (data->yuv || texture->access == SDL_TEXTUREACCESS_STREAMING) {
1166 return 0; 1172 return 0;
1184 /* Fall through to unsupported case */ 1190 /* Fall through to unsupported case */
1185 default: 1191 default:
1186 SDL_Unsupported(); 1192 SDL_Unsupported();
1187 #ifdef SDL_VIDEO_DRIVER_X11_XRENDER 1193 #ifdef SDL_VIDEO_DRIVER_X11_XRENDER
1188 if (renderdata->use_xrender) { 1194 if (renderdata->use_xrender) {
1189 texture->scaleMode = SDL_TEXTURESCALEMODE_FAST; 1195 texture->scaleMode = SDL_TEXTURESCALEMODE_NONE;
1190 data->filter = FilterFast; 1196 data->filter = NULL;
1191 } 1197 }
1192 else 1198 else
1193 #endif 1199 #endif
1194 texture->scaleMode = SDL_TEXTURESCALEMODE_NONE; 1200 texture->scaleMode = SDL_TEXTURESCALEMODE_NONE;
1195 return -1; 1201 return -1;
1898 mask = data->stencil_pict; 1904 mask = data->stencil_pict;
1899 mrect = dstrect; 1905 mrect = dstrect;
1900 } 1906 }
1901 else 1907 else
1902 { 1908 {
1903 mask = texturedata->picture; 1909 mask = src;
1904 mrect = srcrect; 1910 mrect = srcrect;
1905 } 1911 }
1906 1912
1907 if(srcrect->w == dstrect->w && srcrect->h == dstrect->h) { 1913 if(srcrect->w == dstrect->w && srcrect->h == dstrect->h) {
1908 if (texture->blendMode == SDL_BLENDMODE_MOD) { 1914 if (texture->blendMode == SDL_BLENDMODE_MOD) {
1917 XRenderComposite(data->display, texturedata->blend_op, 1923 XRenderComposite(data->display, texturedata->blend_op,
1918 src, mask, data->drawable_pict, srcrect->x, srcrect->y, 1924 src, mask, data->drawable_pict, srcrect->x, srcrect->y,
1919 mrect->x, mrect->y, dstrect->x, dstrect->y, 1925 mrect->x, mrect->y, dstrect->x, dstrect->y,
1920 dstrect->w, dstrect->h); 1926 dstrect->w, dstrect->h);
1921 } else { 1927 } else {
1922 double xscale = ((double) dstrect->w) / srcrect->w; 1928 double xscale = ((double) srcrect->w) / dstrect->w;
1923 double yscale = ((double) dstrect->h) / srcrect->h; 1929 double yscale = ((double) srcrect->h) / dstrect->h;
1924 XTransform xform = {{ 1930 XTransform xform = {{
1925 {XDoubleToFixed(xscale), XDoubleToFixed(0), XDoubleToFixed(0)}, 1931 {XDoubleToFixed(xscale), XDoubleToFixed(0), XDoubleToFixed(0)},
1926 {XDoubleToFixed(0), XDoubleToFixed(yscale), XDoubleToFixed(0)}, 1932 {XDoubleToFixed(0), XDoubleToFixed(yscale), XDoubleToFixed(0)},
1927 {XDoubleToFixed(0), XDoubleToFixed(0), XDoubleToFixed(xscale * yscale)}}}; 1933 {XDoubleToFixed(0), XDoubleToFixed(0), XDoubleToFixed(xscale * yscale)}}};
1928 XRenderSetPictureTransform(data->display, src, &xform); 1934 XRenderSetPictureTransform(data->display, src, &xform);
1935 attr.component_alpha = True; 1941 attr.component_alpha = True;
1936 XRenderChangePicture(data->display, data->stencil_pict, 1942 XRenderChangePicture(data->display, data->stencil_pict,
1937 CPComponentAlpha, &attr); 1943 CPComponentAlpha, &attr);
1938 } 1944 }
1939 1945
1940 XRenderSetPictureFilter(data->display, src, 1946 if (texture->scaleMode != SDL_TEXTURESCALEMODE_NONE) {
1941 texturedata->filter, 0, 0); 1947 XRenderSetPictureFilter(data->display, src,
1948 texturedata->filter, 0, 0);
1949 }
1942 1950
1943 XRenderComposite(data->display, texturedata->blend_op, 1951 XRenderComposite(data->display, texturedata->blend_op,
1944 src, mask, data->drawable_pict, 1952 src, mask, data->drawable_pict,
1945 srcrect->x, srcrect->y, mrect->x, mrect->y, 1953 srcrect->x, srcrect->y, mrect->x, mrect->y,
1946 dstrect->x, dstrect->y, dstrect->w, dstrect->h); 1954 dstrect->x, dstrect->y, dstrect->w, dstrect->h);
1949 {XDoubleToFixed(1), XDoubleToFixed(0), XDoubleToFixed(0)}, 1957 {XDoubleToFixed(1), XDoubleToFixed(0), XDoubleToFixed(0)},
1950 {XDoubleToFixed(0), XDoubleToFixed(1), XDoubleToFixed(0)}, 1958 {XDoubleToFixed(0), XDoubleToFixed(1), XDoubleToFixed(0)},
1951 {XDoubleToFixed(0), XDoubleToFixed(0), XDoubleToFixed(1)}}}; 1959 {XDoubleToFixed(0), XDoubleToFixed(0), XDoubleToFixed(1)}}};
1952 XRenderSetPictureTransform(data->display, src, &identity); 1960 XRenderSetPictureTransform(data->display, src, &identity);
1953 } 1961 }
1962
1954 if (renderer->blendMode == SDL_BLENDMODE_MOD) { 1963 if (renderer->blendMode == SDL_BLENDMODE_MOD) {
1955 attr.component_alpha = False; 1964 attr.component_alpha = False;
1956 XRenderChangePicture(data->display, data->stencil_pict, 1965 XRenderChangePicture(data->display, data->stencil_pict,
1957 CPComponentAlpha, &attr); 1966 CPComponentAlpha, &attr);
1958 } 1967 }