"Fossies" - the Fresh Open Source Software Archive

Member "UXP-2019.10.31/gfx/skia/patches/archive/0005-Bug-777614-Re-apply-bug-687188-Expand-the-gradient-c.patch" (30 Oct 2019, 9409 Bytes) of package /linux/www/UXP-2019.10.31.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Diff source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 From 1ab13a923399aa638388231baca784ba89f2c82b Mon Sep 17 00:00:00 2001
    2 From: George Wright <gw@gwright.org.uk>
    3 Date: Wed, 12 Sep 2012 12:30:29 -0400
    4 Subject: [PATCH 5/9] Bug 777614 - Re-apply bug 687188 - Expand the gradient
    5  cache by 2 to store 0/1 colour stop values for
    6  clamping. r=nrc
    7 
    8 ---
    9  .../src/effects/gradients/SkGradientShader.cpp     | 22 +++++++++++----
   10  .../src/effects/gradients/SkGradientShaderPriv.h   |  5 +++-
   11  .../src/effects/gradients/SkLinearGradient.cpp     | 32 ++++++++++++++++------
   12  .../gradients/SkTwoPointConicalGradient.cpp        | 11 ++++++--
   13  .../effects/gradients/SkTwoPointRadialGradient.cpp | 11 ++++++--
   14  5 files changed, 61 insertions(+), 20 deletions(-)
   15 
   16 diff --git a/gfx/skia/src/effects/gradients/SkGradientShader.cpp b/gfx/skia/src/effects/gradients/SkGradientShader.cpp
   17 index f0dac4d..79e7202 100644
   18 --- a/gfx/skia/src/effects/gradients/SkGradientShader.cpp
   19 +++ b/gfx/skia/src/effects/gradients/SkGradientShader.cpp
   20 @@ -426,15 +426,15 @@ static void complete_32bit_cache(SkPMColor* cache, int stride) {
   21  
   22  const SkPMColor* SkGradientShaderBase::getCache32() const {
   23      if (fCache32 == NULL) {
   24 -        // double the count for dither entries
   25 -        const int entryCount = kCache32Count * 2;
   26 +        // double the count for dither entries, and have an extra two entries for clamp values
   27 +        const int entryCount = kCache32Count * 2 + 2;
   28          const size_t allocSize = sizeof(SkPMColor) * entryCount;
   29  
   30          if (NULL == fCache32PixelRef) {
   31              fCache32PixelRef = SkNEW_ARGS(SkMallocPixelRef,
   32                                            (NULL, allocSize, NULL));
   33          }
   34 -        fCache32 = (SkPMColor*)fCache32PixelRef->getAddr();
   35 +        fCache32 = (SkPMColor*)fCache32PixelRef->getAddr() + 1;
   36          if (fColorCount == 2) {
   37              Build32bitCache(fCache32, fOrigColors[0], fOrigColors[1],
   38                              kGradient32Length, fCacheAlpha);
   39 @@ -458,7 +458,7 @@ const SkPMColor* SkGradientShaderBase::getCache32() const {
   40              SkMallocPixelRef* newPR = SkNEW_ARGS(SkMallocPixelRef,
   41                                                   (NULL, allocSize, NULL));
   42              SkPMColor* linear = fCache32;           // just computed linear data
   43 -            SkPMColor* mapped = (SkPMColor*)newPR->getAddr();    // storage for mapped data
   44 +            SkPMColor* mapped = (SkPMColor*)newPR->getAddr() + 1;    // storage for mapped data
   45              SkUnitMapper* map = fMapper;
   46              for (int i = 0; i < kGradient32Length; i++) {
   47                  int index = map->mapUnit16((i << 8) | i) >> 8;
   48 @@ -467,10 +467,22 @@ const SkPMColor* SkGradientShaderBase::getCache32() const {
   49              }
   50              fCache32PixelRef->unref();
   51              fCache32PixelRef = newPR;
   52 -            fCache32 = (SkPMColor*)newPR->getAddr();
   53 +            fCache32 = (SkPMColor*)newPR->getAddr() + 1;
   54          }
   55          complete_32bit_cache(fCache32, kCache32Count);
   56      }
   57 +
   58 +    // Write the clamp colours into the first and last entries of fCache32
   59 +    fCache32[kCache32ClampLower] = SkPackARGB32(fCacheAlpha,
   60 +                                                SkColorGetR(fOrigColors[0]),
   61 +                                                SkColorGetG(fOrigColors[0]),
   62 +                                                SkColorGetB(fOrigColors[0]));
   63 +
   64 +    fCache32[kCache32ClampUpper] = SkPackARGB32(fCacheAlpha,
   65 +                                                SkColorGetR(fOrigColors[fColorCount - 1]),
   66 +                                                SkColorGetG(fOrigColors[fColorCount - 1]),
   67 +                                                SkColorGetB(fOrigColors[fColorCount - 1]));
   68 +
   69      return fCache32;
   70  }
   71  
   72 diff --git a/gfx/skia/src/effects/gradients/SkGradientShaderPriv.h b/gfx/skia/src/effects/gradients/SkGradientShaderPriv.h
   73 index 0e7c2fc..7427935 100644
   74 --- a/gfx/skia/src/effects/gradients/SkGradientShaderPriv.h
   75 +++ b/gfx/skia/src/effects/gradients/SkGradientShaderPriv.h
   76 @@ -133,7 +133,10 @@ public:
   77          kDitherStride32 = 0,
   78  #endif
   79          kDitherStride16 = kCache16Count,
   80 -        kLerpRemainderMask32 = (1 << (16 - kCache32Bits)) - 1
   81 +        kLerpRemainderMask32 = (1 << (16 - kCache32Bits)) - 1,
   82 +
   83 +        kCache32ClampLower = -1,
   84 +        kCache32ClampUpper = kCache32Count * 2
   85      };
   86  
   87  
   88 diff --git a/gfx/skia/src/effects/gradients/SkLinearGradient.cpp b/gfx/skia/src/effects/gradients/SkLinearGradient.cpp
   89 index bcebc26..d400b4d 100644
   90 --- a/gfx/skia/src/effects/gradients/SkLinearGradient.cpp
   91 +++ b/gfx/skia/src/effects/gradients/SkLinearGradient.cpp
   92 @@ -126,6 +126,17 @@ void shadeSpan_linear_vertical(TileProc proc, SkFixed dx, SkFixed fx,
   93                                 SkPMColor* SK_RESTRICT dstC,
   94                                 const SkPMColor* SK_RESTRICT cache,
   95                                 int toggle, int count) {
   96 +    if (proc == clamp_tileproc) {
   97 +        // No need to lerp or dither for clamp values
   98 +        if (fx < 0) {
   99 +            sk_memset32(dstC, cache[SkGradientShaderBase::kCache32ClampLower], count);
  100 +            return;
  101 +        } else if (fx > 0xffff) {
  102 +            sk_memset32(dstC, cache[SkGradientShaderBase::kCache32ClampUpper], count);
  103 +            return;
  104 +        }
  105 +    }
  106 +
  107      // We're a vertical gradient, so no change in a span.
  108      // If colors change sharply across the gradient, dithering is
  109      // insufficient (it subsamples the color space) and we need to lerp.
  110 @@ -144,6 +155,17 @@ void shadeSpan_linear_vertical_lerp(TileProc proc, SkFixed dx, SkFixed fx,
  111                                      SkPMColor* SK_RESTRICT dstC,
  112                                      const SkPMColor* SK_RESTRICT cache,
  113                                      int toggle, int count) {
  114 +    if (proc == clamp_tileproc) {
  115 +        // No need to lerp or dither for clamp values
  116 +        if (fx < 0) {
  117 +            sk_memset32(dstC, cache[SkGradientShaderBase::kCache32ClampLower], count);
  118 +            return;
  119 +        } else if (fx > 0xffff) {
  120 +            sk_memset32(dstC, cache[SkGradientShaderBase::kCache32ClampUpper], count);
  121 +            return;
  122 +        }
  123 +    }
  124 +
  125      // We're a vertical gradient, so no change in a span.
  126      // If colors change sharply across the gradient, dithering is
  127      // insufficient (it subsamples the color space) and we need to lerp.
  128 @@ -169,10 +191,7 @@ void shadeSpan_linear_clamp(TileProc proc, SkFixed dx, SkFixed fx,
  129      range.init(fx, dx, count, 0, SkGradientShaderBase::kGradient32Length);
  130  
  131      if ((count = range.fCount0) > 0) {
  132 -        sk_memset32_dither(dstC,
  133 -            cache[toggle + range.fV0],
  134 -            cache[(toggle ^ SkGradientShaderBase::kDitherStride32) + range.fV0],
  135 -            count);
  136 +        sk_memset32(dstC, cache[SkGradientShaderBase::kCache32ClampLower], count);
  137          dstC += count;
  138      }
  139      if ((count = range.fCount1) > 0) {
  140 @@ -191,10 +210,7 @@ void shadeSpan_linear_clamp(TileProc proc, SkFixed dx, SkFixed fx,
  141          }
  142      }
  143      if ((count = range.fCount2) > 0) {
  144 -        sk_memset32_dither(dstC,
  145 -            cache[toggle + range.fV1],
  146 -            cache[(toggle ^ SkGradientShaderBase::kDitherStride32) + range.fV1],
  147 -            count);
  148 +        sk_memset32(dstC, cache[SkGradientShaderBase::kCache32ClampUpper], count);
  149      }
  150  }
  151  
  152 diff --git a/gfx/skia/src/effects/gradients/SkTwoPointConicalGradient.cpp b/gfx/skia/src/effects/gradients/SkTwoPointConicalGradient.cpp
  153 index 3466d2c..764a444 100644
  154 --- a/gfx/skia/src/effects/gradients/SkTwoPointConicalGradient.cpp
  155 +++ b/gfx/skia/src/effects/gradients/SkTwoPointConicalGradient.cpp
  156 @@ -123,9 +123,14 @@ static void twopoint_clamp(TwoPtRadial* rec, SkPMColor* SK_RESTRICT dstC,
  157          if (TwoPtRadial::DontDrawT(t)) {
  158              *dstC++ = 0;
  159          } else {
  160 -            SkFixed index = SkClampMax(t, 0xFFFF);
  161 -            SkASSERT(index <= 0xFFFF);
  162 -            *dstC++ = cache[index >> SkGradientShaderBase::kCache32Shift];
  163 +            if (t < 0) {
  164 +                *dstC++ = cache[SkGradientShaderBase::kCache32ClampLower];
  165 +            } else if (t > 0xFFFF) {
  166 +                *dstC++ = cache[SkGradientShaderBase::kCache32ClampUpper];
  167 +            } else {
  168 +                SkASSERT(t <= 0xFFFF);
  169 +                *dstC++ = cache[t >> SkGradientShaderBase::kCache32Shift];
  170 +            }
  171          }
  172      }
  173  }
  174 diff --git a/gfx/skia/src/effects/gradients/SkTwoPointRadialGradient.cpp b/gfx/skia/src/effects/gradients/SkTwoPointRadialGradient.cpp
  175 index 9362ded..22b028e 100644
  176 --- a/gfx/skia/src/effects/gradients/SkTwoPointRadialGradient.cpp
  177 +++ b/gfx/skia/src/effects/gradients/SkTwoPointRadialGradient.cpp
  178 @@ -120,9 +120,14 @@ void shadeSpan_twopoint_clamp(SkScalar fx, SkScalar dx,
  179      for (; count > 0; --count) {
  180          SkFixed t = two_point_radial(b, fx, fy, fSr2D2, foura,
  181                                       fOneOverTwoA, posRoot);
  182 -        SkFixed index = SkClampMax(t, 0xFFFF);
  183 -        SkASSERT(index <= 0xFFFF);
  184 -        *dstC++ = cache[index >> SkGradientShaderBase::kCache32Shift];
  185 +        if (t < 0) {
  186 +            *dstC++ = cache[SkGradientShaderBase::kCache32ClampLower];
  187 +        } else if (t > 0xFFFF) {
  188 +            *dstC++ = cache[SkGradientShaderBase::kCache32ClampUpper];
  189 +        } else {
  190 +            SkASSERT(t <= 0xFFFF);
  191 +            *dstC++ = cache[t >> SkGradientShaderBase::kCache32Shift];
  192 +        }
  193          fx += dx;
  194          fy += dy;
  195          b += db;
  196 -- 
  197 1.7.11.4
  198