Add alphaType() to SkImage
Keep isOpaque as a convenience method -- many places really only need to
know that for optimization purposes (SrcOver -> Src, etc...).
In all the places where we pull data back out or convert to another
object and need to supply an SkImageInfo, we can avoid losing information
about premulness.
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2250663002
Review-Url: https://codereview.chromium.org/2250663002
diff --git a/tests/SurfaceTest.cpp b/tests/SurfaceTest.cpp
index 87c3a52..2703b54 100644
--- a/tests/SurfaceTest.cpp
+++ b/tests/SurfaceTest.cpp
@@ -128,32 +128,31 @@
#endif
static void test_snapshot_alphatype(skiatest::Reporter* reporter, const sk_sp<SkSurface>& surface,
- bool expectOpaque) {
+ SkAlphaType expectedAlphaType) {
REPORTER_ASSERT(reporter, surface);
if (surface) {
sk_sp<SkImage> image(surface->makeImageSnapshot());
REPORTER_ASSERT(reporter, image);
if (image) {
- REPORTER_ASSERT(reporter, image->isOpaque() == SkToBool(expectOpaque));
+ REPORTER_ASSERT(reporter, image->alphaType() == expectedAlphaType);
}
}
}
DEF_TEST(SurfaceSnapshotAlphaType, reporter) {
for (auto& surface_func : { &create_surface, &create_direct_surface }) {
- for (auto& isOpaque : { true, false }) {
- SkAlphaType alphaType = isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType;
- auto surface(surface_func(alphaType, nullptr));
- test_snapshot_alphatype(reporter, surface, isOpaque);
+ for (auto& at: { kOpaque_SkAlphaType, kPremul_SkAlphaType, kUnpremul_SkAlphaType }) {
+ auto surface(surface_func(at, nullptr));
+ test_snapshot_alphatype(reporter, surface, at);
}
}
}
#if SK_SUPPORT_GPU
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceSnapshotAlphaType_Gpu, reporter, ctxInfo) {
for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) {
- for (auto& isOpaque : { true, false }) {
- SkAlphaType alphaType = isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType;
- auto surface(surface_func(ctxInfo.grContext(), alphaType, nullptr));
- test_snapshot_alphatype(reporter, surface, isOpaque);
+ // GPU doesn't support creating unpremul surfaces, so only test opaque + premul
+ for (auto& at : { kOpaque_SkAlphaType, kPremul_SkAlphaType }) {
+ auto surface(surface_func(ctxInfo.grContext(), at, nullptr));
+ test_snapshot_alphatype(reporter, surface, at);
}
}
}