Fix some bugs around opaque color types and computeIsOpaque
Spun out from: https://skia-review.googlesource.com/c/skia/+/161423
Bug: skia:
Change-Id: I7f3a7e10faa844271235f3b064576d43bab8e554
Reviewed-on: https://skia-review.googlesource.com/c/161480
Reviewed-by: Mike Klein <mtklein@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index b29454c..596fa66 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -565,7 +565,9 @@
if (kUnknown_SkColorType == srcSkColorType || kUnknown_SkColorType == dstSkColorType) {
return false;
}
- auto srcAlphaType = premul ? kUnpremul_SkAlphaType : kPremul_SkAlphaType;
+ auto srcAlphaType = SkColorTypeIsAlwaysOpaque(srcSkColorType)
+ ? kOpaque_SkAlphaType
+ : (premul ? kUnpremul_SkAlphaType : kPremul_SkAlphaType);
SkPixmap src(SkImageInfo::Make(width, height, srcSkColorType, srcAlphaType,
sk_ref_sp(srcColorSpace)),
buffer, rowBytes);
@@ -738,15 +740,16 @@
if (convert) {
SkColorType srcSkColorType = GrColorTypeToSkColorType(allowedColorType);
SkColorType dstSkColorType = GrColorTypeToSkColorType(dstColorType);
+ bool srcAlwaysOpaque = SkColorTypeIsAlwaysOpaque(srcSkColorType);
+ bool dstAlwaysOpaque = SkColorTypeIsAlwaysOpaque(dstSkColorType);
if (kUnknown_SkColorType == srcSkColorType || kUnknown_SkColorType == dstSkColorType) {
return false;
}
- auto tempAT = SkColorTypeIsAlwaysOpaque(srcSkColorType) ? kOpaque_SkAlphaType
- : kPremul_SkAlphaType;
+ auto tempAT = srcAlwaysOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType;
auto tempII = SkImageInfo::Make(width, height, srcSkColorType, tempAT,
src->colorSpaceInfo().refColorSpace());
- SkASSERT(!unpremul || !SkColorTypeIsAlwaysOpaque(dstSkColorType));
- auto finalAT = SkColorTypeIsAlwaysOpaque(srcSkColorType)
+ SkASSERT(!unpremul || !dstAlwaysOpaque);
+ auto finalAT = (srcAlwaysOpaque || dstAlwaysOpaque)
? kOpaque_SkAlphaType
: unpremul ? kUnpremul_SkAlphaType : kPremul_SkAlphaType;
auto finalII =