From 052ef695708eddeaa81c3fcf5747824c1f0ad073 Mon Sep 17 00:00:00 2001 From: Brian Osman Date: Tue, 27 Mar 2018 09:56:31 -0400 Subject: Pin color type when a cross-context image is constructed Fixes issues with gray images that may be incorrectly re-interpreted as alpha when re-wrapped. (https://github.com/flutter/flutter/issues/15600) Change-Id: I4a78466073e14d212108d168eed0b2df1bc92ffe Reviewed-on: https://skia-review.googlesource.com/116484 Commit-Queue: Brian Osman Reviewed-by: Greg Daniel --- tests/ImageTest.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'tests/ImageTest.cpp') diff --git a/tests/ImageTest.cpp b/tests/ImageTest.cpp index 726a06adc3..98c2f03c2e 100644 --- a/tests/ImageTest.cpp +++ b/tests/ImageTest.cpp @@ -1021,6 +1021,35 @@ DEF_GPUTEST(SkImage_MakeCrossContextFromPixmapRelease, reporter, options) { }); } +DEF_GPUTEST(SkImage_CrossContextGrayAlphaConfigs, reporter, options) { + + for (SkColorType ct : { kGray_8_SkColorType, kAlpha_8_SkColorType }) { + SkAutoPixmapStorage pixmap; + pixmap.alloc(SkImageInfo::Make(4, 4, ct, kPremul_SkAlphaType)); + + for (int i = 0; i < GrContextFactory::kContextTypeCnt; ++i) { + GrContextFactory testFactory(options); + GrContextFactory::ContextType ctxType = static_cast(i); + ContextInfo ctxInfo = testFactory.getContextInfo(ctxType); + GrContext* ctx = ctxInfo.grContext(); + if (!ctx || !ctx->caps()->crossContextTextureSupport()) { + continue; + } + + sk_sp image = SkImage::MakeCrossContextFromPixmap(ctx, pixmap, false, nullptr); + REPORTER_ASSERT(reporter, image); + + sk_sp texColorSpace; + sk_sp proxy = as_IB(image)->asTextureProxyRef( + ctx, GrSamplerState::ClampNearest(), nullptr, &texColorSpace, nullptr); + REPORTER_ASSERT(reporter, proxy); + + bool expectAlpha = kAlpha_8_SkColorType == ct; + REPORTER_ASSERT(reporter, expectAlpha == GrPixelConfigIsAlphaOnly(proxy->config())); + } + } +} + static uint32_t GetIdForBackendObject(GrContext* ctx, GrBackendObject object) { if (!object) { return 0; -- cgit v1.2.3