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 =
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp
index 94d2206..6239477 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -136,7 +136,6 @@
, fRenderTargetContext(std::move(renderTargetContext))
{
fSize.set(width, height);
- fOpaque = SkToBool(flags & kIsOpaque_Flag);
if (flags & kNeedClear_Flag) {
this->clearAll();
diff --git a/src/gpu/SkGpuDevice.h b/src/gpu/SkGpuDevice.h
index a1a6606..c0dec29 100644
--- a/src/gpu/SkGpuDevice.h
+++ b/src/gpu/SkGpuDevice.h
@@ -129,7 +129,6 @@
sk_sp<GrRenderTargetContext> fRenderTargetContext;
SkISize fSize;
- bool fOpaque;
enum Flags {
kNeedClear_Flag = 1 << 0, //!< Surface requires an initial clear