diff options
author | 2017-05-18 22:23:34 -0400 | |
---|---|---|
committer | 2017-05-19 15:47:39 +0000 | |
commit | 7346a1f3b74e10c6daf7973177ad7f7f575e9b97 (patch) | |
tree | 37ff4af9e1de3713b67a30e2cde05b453e1e3def /src | |
parent | b091c930e37214108385c5d801f7eb093d5960fa (diff) |
detect (and preserve) if patch colors are opaque
Bug: skia:
Change-Id: Ida3a1ff3f78db2498a6dfc655d8be4de8ad912c7
Reviewed-on: https://skia-review.googlesource.com/17380
Reviewed-by: Jim Van Verth <jvanverth@google.com>
Commit-Queue: Mike Reed <reed@google.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/utils/SkPatchUtils.cpp | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/src/utils/SkPatchUtils.cpp b/src/utils/SkPatchUtils.cpp index 9a789ea80f..119f734a24 100644 --- a/src/utils/SkPatchUtils.cpp +++ b/src/utils/SkPatchUtils.cpp @@ -242,15 +242,19 @@ sk_sp<SkVertices> SkPatchUtils::MakeVertices(const SkPoint cubics[12], const SkC SkPoint* texs = builder.texCoords(); SkColor* colors = builder.colors(); uint16_t* indices = builder.indices(); + bool is_opaque = false; // if colors is not null then create array for colors SkPMColor colorsPM[kNumCorners]; if (srcColors) { + SkColor c = ~0; // premultiply colors to avoid color bleeding. for (int i = 0; i < kNumCorners; i++) { colorsPM[i] = SkPreMultiplyColor(srcColors[i]); + c &= srcColors[i]; } srcColors = colorsPM; + is_opaque = (SkColorGetA(c) == 0xFF); } SkPoint pts[kNumPtsCubic]; @@ -294,11 +298,16 @@ sk_sp<SkVertices> SkPatchUtils::MakeVertices(const SkPoint cubics[12], const SkC pos[dataIndex] = s0 + s1 - s2; if (colors) { - uint8_t a = uint8_t(bilerp(u, v, - SkScalar(SkColorGetA(colorsPM[kTopLeft_Corner])), - SkScalar(SkColorGetA(colorsPM[kTopRight_Corner])), - SkScalar(SkColorGetA(colorsPM[kBottomLeft_Corner])), - SkScalar(SkColorGetA(colorsPM[kBottomRight_Corner])))); + uint8_t a = 0xFF; + // We do the opaque check for speed, and to ensure that opaque stays opaque, + // in case we lose precision in the bilerp. + if (!is_opaque) { + a = uint8_t(bilerp(u, v, + SkScalar(SkColorGetA(colorsPM[kTopLeft_Corner])), + SkScalar(SkColorGetA(colorsPM[kTopRight_Corner])), + SkScalar(SkColorGetA(colorsPM[kBottomLeft_Corner])), + SkScalar(SkColorGetA(colorsPM[kBottomRight_Corner])))); + } uint8_t r = uint8_t(bilerp(u, v, SkScalar(SkColorGetR(colorsPM[kTopLeft_Corner])), SkScalar(SkColorGetR(colorsPM[kTopRight_Corner])), |