aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Brian Osman <brianosman@google.com>2018-03-27 09:56:31 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-03-27 14:45:14 +0000
commit052ef695708eddeaa81c3fcf5747824c1f0ad073 (patch)
tree1122ad13a7fe3a97d2e6bf4b160f5b9582e679de
parentf830443814fb21bd4b1009186b23680e3a38935e (diff)
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 <brianosman@google.com> Reviewed-by: Greg Daniel <egdaniel@google.com>
-rw-r--r--src/gpu/GrBackendTextureImageGenerator.cpp14
-rw-r--r--src/gpu/GrBackendTextureImageGenerator.h2
-rw-r--r--src/image/SkImage_Gpu.cpp7
-rw-r--r--tests/GrMipMappedTest.cpp3
-rw-r--r--tests/ImageTest.cpp29
5 files changed, 45 insertions, 10 deletions
diff --git a/src/gpu/GrBackendTextureImageGenerator.cpp b/src/gpu/GrBackendTextureImageGenerator.cpp
index 73f19b0199..90a251865a 100644
--- a/src/gpu/GrBackendTextureImageGenerator.cpp
+++ b/src/gpu/GrBackendTextureImageGenerator.cpp
@@ -33,13 +33,8 @@ GrBackendTextureImageGenerator::RefHelper::~RefHelper() {
std::unique_ptr<SkImageGenerator>
GrBackendTextureImageGenerator::Make(sk_sp<GrTexture> texture, GrSurfaceOrigin origin,
- sk_sp<GrSemaphore> semaphore,
+ sk_sp<GrSemaphore> semaphore, SkColorType colorType,
SkAlphaType alphaType, sk_sp<SkColorSpace> colorSpace) {
- SkColorType colorType = kUnknown_SkColorType;
- if (!GrPixelConfigToColorType(texture->config(), &colorType)) {
- return nullptr;
- }
-
GrContext* context = texture->getContext();
// Attach our texture to this context's resource cache. This ensures that deletion will happen
@@ -48,6 +43,10 @@ GrBackendTextureImageGenerator::Make(sk_sp<GrTexture> texture, GrSurfaceOrigin o
context->contextPriv().getResourceCache()->insertCrossContextGpuResource(texture.get());
GrBackendTexture backendTexture = texture->getBackendTexture();
+ if (!context->caps()->validateBackendTexture(backendTexture, colorType,
+ &backendTexture.fConfig)) {
+ return nullptr;
+ }
SkImageInfo info = SkImageInfo::Make(texture->width(), texture->height(), colorType, alphaType,
std::move(colorSpace));
@@ -93,6 +92,9 @@ sk_sp<GrTextureProxy> GrBackendTextureImageGenerator::onGenerateTexture(
if (context->contextPriv().getBackend() != fBackendTexture.backend()) {
return nullptr;
}
+ if (info.colorType() != this->getInfo().colorType()) {
+ return nullptr;
+ }
auto proxyProvider = context->contextPriv().proxyProvider();
diff --git a/src/gpu/GrBackendTextureImageGenerator.h b/src/gpu/GrBackendTextureImageGenerator.h
index 59f0d510da..5197d32273 100644
--- a/src/gpu/GrBackendTextureImageGenerator.h
+++ b/src/gpu/GrBackendTextureImageGenerator.h
@@ -29,7 +29,7 @@ class GrSemaphore;
class GrBackendTextureImageGenerator : public SkImageGenerator {
public:
static std::unique_ptr<SkImageGenerator> Make(sk_sp<GrTexture>, GrSurfaceOrigin,
- sk_sp<GrSemaphore>,
+ sk_sp<GrSemaphore>, SkColorType,
SkAlphaType, sk_sp<SkColorSpace>);
~GrBackendTextureImageGenerator() override;
diff --git a/src/image/SkImage_Gpu.cpp b/src/image/SkImage_Gpu.cpp
index 4733cae06e..3c05f1d219 100644
--- a/src/image/SkImage_Gpu.cpp
+++ b/src/image/SkImage_Gpu.cpp
@@ -723,7 +723,9 @@ sk_sp<SkImage> SkImage::MakeCrossContextFromEncoded(GrContext* context, sk_sp<Sk
sk_sp<GrSemaphore> sema = gpu->prepareTextureForCrossContextUsage(texture.get());
auto gen = GrBackendTextureImageGenerator::Make(std::move(texture), proxy->origin(),
- std::move(sema), codecImage->alphaType(),
+ std::move(sema),
+ as_IB(codecImage)->onImageInfo().colorType(),
+ codecImage->alphaType(),
std::move(texColorSpace));
return SkImage::MakeFromGenerator(std::move(gen));
}
@@ -778,7 +780,8 @@ sk_sp<SkImage> SkImage::MakeCrossContextFromPixmap(GrContext* context, const SkP
sk_sp<GrSemaphore> sema = gpu->prepareTextureForCrossContextUsage(texture.get());
auto gen = GrBackendTextureImageGenerator::Make(std::move(texture), proxy->origin(),
- std::move(sema), pixmap.alphaType(),
+ std::move(sema), pixmap.colorType(),
+ pixmap.alphaType(),
pixmap.info().refColorSpace());
return SkImage::MakeFromGenerator(std::move(gen));
}
diff --git a/tests/GrMipMappedTest.cpp b/tests/GrMipMappedTest.cpp
index d71dda8dc0..4e8179950d 100644
--- a/tests/GrMipMappedTest.cpp
+++ b/tests/GrMipMappedTest.cpp
@@ -136,7 +136,8 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrBackendTextureImageMipMappedTest, reporter,
}
std::unique_ptr<SkImageGenerator> imageGen = GrBackendTextureImageGenerator::Make(
- texture, kTopLeft_GrSurfaceOrigin, nullptr, kPremul_SkAlphaType, nullptr);
+ texture, kTopLeft_GrSurfaceOrigin, nullptr, kRGBA_8888_SkColorType,
+ kPremul_SkAlphaType, nullptr);
REPORTER_ASSERT(reporter, imageGen);
if (!imageGen) {
gpu->deleteTestingOnlyBackendTexture(backendTex);
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<GrContextFactory::ContextType>(i);
+ ContextInfo ctxInfo = testFactory.getContextInfo(ctxType);
+ GrContext* ctx = ctxInfo.grContext();
+ if (!ctx || !ctx->caps()->crossContextTextureSupport()) {
+ continue;
+ }
+
+ sk_sp<SkImage> image = SkImage::MakeCrossContextFromPixmap(ctx, pixmap, false, nullptr);
+ REPORTER_ASSERT(reporter, image);
+
+ sk_sp<SkColorSpace> texColorSpace;
+ sk_sp<GrTextureProxy> 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;