comparison src/video/x11/SDL_x11render.c @ 4630:02895e9c796b

Added some comments.
author Sunny Sachanandani <sunnysachanandani@gmail.com>
date Mon, 02 Aug 2010 17:14:09 +0530
parents 44fd1f0b895a
children 066ce836b80e
comparison
equal deleted inserted replaced
4629:44fd1f0b895a 4630:02895e9c796b
1884 XSync(data->display, False); 1884 XSync(data->display, False);
1885 } 1885 }
1886 Picture src, mask; 1886 Picture src, mask;
1887 XRenderPictureAttributes attr; 1887 XRenderPictureAttributes attr;
1888 const SDL_Rect *mrect; 1888 const SDL_Rect *mrect;
1889 /* mrect is the rectangular area of the mask
1890 * picture that is aligned with the source. */
1889 1891
1890 if (texture->modMode == SDL_TEXTUREMODULATE_NONE) { 1892 if (texture->modMode == SDL_TEXTUREMODULATE_NONE) {
1891 src = texturedata->picture; 1893 src = texturedata->picture;
1892 } 1894 }
1893 else { 1895 else {
1899 mask = None; 1901 mask = None;
1900 mrect = srcrect; 1902 mrect = srcrect;
1901 } 1903 }
1902 else if (texture->blendMode == SDL_BLENDMODE_MOD) 1904 else if (texture->blendMode == SDL_BLENDMODE_MOD)
1903 { 1905 {
1906 /* SDL_BLENDMODE_MOD requires a temporary buffer
1907 * i.e. stencil_pict */
1904 mask = data->stencil_pict; 1908 mask = data->stencil_pict;
1905 mrect = dstrect; 1909 mrect = dstrect;
1906 } 1910 }
1907 else 1911 else
1908 { 1912 {
1913 /* This trick allows on-the-fly multiplication
1914 * of the src color channels with it's alpha
1915 * channel. */
1909 mask = src; 1916 mask = src;
1910 mrect = srcrect; 1917 mrect = srcrect;
1911 } 1918 }
1912 1919
1913 if(srcrect->w == dstrect->w && srcrect->h == dstrect->h) { 1920 if(srcrect->w == dstrect->w && srcrect->h == dstrect->h) {
1923 XRenderComposite(data->display, texturedata->blend_op, 1930 XRenderComposite(data->display, texturedata->blend_op,
1924 src, mask, data->drawable_pict, srcrect->x, srcrect->y, 1931 src, mask, data->drawable_pict, srcrect->x, srcrect->y,
1925 mrect->x, mrect->y, dstrect->x, dstrect->y, 1932 mrect->x, mrect->y, dstrect->x, dstrect->y,
1926 dstrect->w, dstrect->h); 1933 dstrect->w, dstrect->h);
1927 } else { 1934 } else {
1935 /* The transformation is from the dst to src picture. */
1928 double xscale = ((double) srcrect->w) / dstrect->w; 1936 double xscale = ((double) srcrect->w) / dstrect->w;
1929 double yscale = ((double) srcrect->h) / dstrect->h; 1937 double yscale = ((double) srcrect->h) / dstrect->h;
1930 XTransform xform = {{ 1938 XTransform xform = {{
1931 {XDoubleToFixed(xscale), XDoubleToFixed(0), XDoubleToFixed(0)}, 1939 {XDoubleToFixed(xscale), XDoubleToFixed(0), XDoubleToFixed(0)},
1932 {XDoubleToFixed(0), XDoubleToFixed(yscale), XDoubleToFixed(0)}, 1940 {XDoubleToFixed(0), XDoubleToFixed(yscale), XDoubleToFixed(0)},
1933 {XDoubleToFixed(0), XDoubleToFixed(0), XDoubleToFixed(xscale * yscale)}}}; 1941 {XDoubleToFixed(0), XDoubleToFixed(0), XDoubleToFixed(xscale * yscale)}}};
1934 XRenderSetPictureTransform(data->display, src, &xform); 1942 XRenderSetPictureTransform(data->display, src, &xform);
1935 1943
1944 /* Black magic follows. */
1936 if (texture->blendMode == SDL_BLENDMODE_MOD) { 1945 if (texture->blendMode == SDL_BLENDMODE_MOD) {
1946 /* Copy the dst to a temp buffer. */
1937 XRenderComposite(data->display, PictOpSrc, data->drawable_pict, 1947 XRenderComposite(data->display, PictOpSrc, data->drawable_pict,
1938 src, data->stencil_pict, 1948 src, data->stencil_pict,
1939 dstrect->x, dstrect->y, srcrect->x, srcrect->y, 1949 dstrect->x, dstrect->y, srcrect->x, srcrect->y,
1940 dstrect->x, dstrect->y, dstrect->w, dstrect->h); 1950 dstrect->x, dstrect->y, dstrect->w, dstrect->h);
1951 /* Set the compnent alpha flag on the temp buffer. */
1941 attr.component_alpha = True; 1952 attr.component_alpha = True;
1942 XRenderChangePicture(data->display, data->stencil_pict, 1953 XRenderChangePicture(data->display, data->stencil_pict,
1943 CPComponentAlpha, &attr); 1954 CPComponentAlpha, &attr);
1944 } 1955 }
1945 1956
1957 /* Set the picture filter only if a scaling mode is set. */
1946 if (texture->scaleMode != SDL_TEXTURESCALEMODE_NONE) { 1958 if (texture->scaleMode != SDL_TEXTURESCALEMODE_NONE) {
1947 XRenderSetPictureFilter(data->display, src, 1959 XRenderSetPictureFilter(data->display, src,
1948 texturedata->filter, 0, 0); 1960 texturedata->filter, 0, 0);
1949 } 1961 }
1950 1962
1951 XRenderComposite(data->display, texturedata->blend_op, 1963 XRenderComposite(data->display, texturedata->blend_op,
1952 src, mask, data->drawable_pict, 1964 src, mask, data->drawable_pict,
1953 srcrect->x, srcrect->y, mrect->x, mrect->y, 1965 srcrect->x, srcrect->y, mrect->x, mrect->y,
1954 dstrect->x, dstrect->y, dstrect->w, dstrect->h); 1966 dstrect->x, dstrect->y, dstrect->w, dstrect->h);
1955 1967 /* Set the texture transformation back to the identity matrix. */
1956 XTransform identity = {{ 1968 XTransform identity = {{
1957 {XDoubleToFixed(1), XDoubleToFixed(0), XDoubleToFixed(0)}, 1969 {XDoubleToFixed(1), XDoubleToFixed(0), XDoubleToFixed(0)},
1958 {XDoubleToFixed(0), XDoubleToFixed(1), XDoubleToFixed(0)}, 1970 {XDoubleToFixed(0), XDoubleToFixed(1), XDoubleToFixed(0)},
1959 {XDoubleToFixed(0), XDoubleToFixed(0), XDoubleToFixed(1)}}}; 1971 {XDoubleToFixed(0), XDoubleToFixed(0), XDoubleToFixed(1)}}};
1960 XRenderSetPictureTransform(data->display, src, &identity); 1972 XRenderSetPictureTransform(data->display, src, &identity);
1961 } 1973 }
1962 1974
1975 /* Reset the component alpha flag only when
1976 * the blending mode is SDL_BLENDMODE_MOD. */
1963 if (renderer->blendMode == SDL_BLENDMODE_MOD) { 1977 if (renderer->blendMode == SDL_BLENDMODE_MOD) {
1964 attr.component_alpha = False; 1978 attr.component_alpha = False;
1965 XRenderChangePicture(data->display, data->stencil_pict, 1979 XRenderChangePicture(data->display, data->stencil_pict,
1966 CPComponentAlpha, &attr); 1980 CPComponentAlpha, &attr);
1967 } 1981 }