Added some comments.
authorSunny Sachanandani <sunnysachanandani@gmail.com>
Mon, 02 Aug 2010 17:14:09 +0530
changeset 463002895e9c796b
parent 4629 44fd1f0b895a
child 4631 0a3bfd46c4db
Added some comments.
src/video/x11/SDL_x11render.c
     1.1 --- a/src/video/x11/SDL_x11render.c	Mon Aug 02 11:13:40 2010 +0530
     1.2 +++ b/src/video/x11/SDL_x11render.c	Mon Aug 02 17:14:09 2010 +0530
     1.3 @@ -1886,6 +1886,8 @@
     1.4          Picture src, mask;
     1.5          XRenderPictureAttributes attr;
     1.6          const SDL_Rect *mrect;
     1.7 +        /* mrect is the rectangular area of the mask
     1.8 +         * picture that is aligned with the source. */
     1.9  
    1.10          if (texture->modMode == SDL_TEXTUREMODULATE_NONE) {
    1.11              src = texturedata->picture;
    1.12 @@ -1901,11 +1903,16 @@
    1.13          }
    1.14          else if (texture->blendMode == SDL_BLENDMODE_MOD)
    1.15          {
    1.16 +            /* SDL_BLENDMODE_MOD requires a temporary buffer
    1.17 +             * i.e. stencil_pict */
    1.18              mask = data->stencil_pict;
    1.19              mrect = dstrect;
    1.20          }
    1.21          else
    1.22          {
    1.23 +            /* This trick allows on-the-fly multiplication
    1.24 +             * of the src color channels with it's alpha
    1.25 +             * channel. */
    1.26              mask = src;
    1.27              mrect = srcrect;
    1.28          }
    1.29 @@ -1925,6 +1932,7 @@
    1.30                              mrect->x, mrect->y, dstrect->x, dstrect->y,
    1.31                              dstrect->w, dstrect->h);
    1.32          } else {
    1.33 +            /* The transformation is from the dst to src picture. */
    1.34              double xscale = ((double) srcrect->w) / dstrect->w;
    1.35              double yscale = ((double) srcrect->h) / dstrect->h;
    1.36              XTransform xform = {{
    1.37 @@ -1933,16 +1941,20 @@
    1.38                      {XDoubleToFixed(0), XDoubleToFixed(0), XDoubleToFixed(xscale * yscale)}}};
    1.39              XRenderSetPictureTransform(data->display, src, &xform);
    1.40              
    1.41 +            /* Black magic follows. */
    1.42              if (texture->blendMode == SDL_BLENDMODE_MOD) {
    1.43 +                /* Copy the dst to a temp buffer. */
    1.44                  XRenderComposite(data->display, PictOpSrc, data->drawable_pict,
    1.45                               src, data->stencil_pict,
    1.46                               dstrect->x, dstrect->y, srcrect->x, srcrect->y,
    1.47                               dstrect->x, dstrect->y, dstrect->w, dstrect->h);
    1.48 +                /* Set the compnent alpha flag on the temp buffer. */
    1.49                  attr.component_alpha = True;
    1.50                  XRenderChangePicture(data->display, data->stencil_pict,
    1.51                                       CPComponentAlpha, &attr);
    1.52              }
    1.53  
    1.54 +            /* Set the picture filter only if a scaling mode is set. */
    1.55              if (texture->scaleMode != SDL_TEXTURESCALEMODE_NONE) {
    1.56                  XRenderSetPictureFilter(data->display, src,
    1.57                                          texturedata->filter, 0, 0);
    1.58 @@ -1952,14 +1964,16 @@
    1.59                               src, mask, data->drawable_pict,
    1.60                               srcrect->x, srcrect->y, mrect->x, mrect->y,
    1.61                               dstrect->x, dstrect->y, dstrect->w, dstrect->h);
    1.62 -            
    1.63 +           /* Set the texture transformation back to the identity matrix. */ 
    1.64              XTransform identity = {{
    1.65                      {XDoubleToFixed(1), XDoubleToFixed(0), XDoubleToFixed(0)},
    1.66                      {XDoubleToFixed(0), XDoubleToFixed(1), XDoubleToFixed(0)},
    1.67                      {XDoubleToFixed(0), XDoubleToFixed(0), XDoubleToFixed(1)}}};
    1.68              XRenderSetPictureTransform(data->display, src, &identity);
    1.69          }
    1.70 -
    1.71 +        
    1.72 +        /* Reset the component alpha flag only when
    1.73 +         * the blending mode is SDL_BLENDMODE_MOD. */
    1.74          if (renderer->blendMode == SDL_BLENDMODE_MOD) {
    1.75              attr.component_alpha = False;
    1.76              XRenderChangePicture(data->display, data->stencil_pict,