diff options
author | Brian Osman <brianosman@google.com> | 2018-03-27 09:56:31 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2018-03-27 14:45:14 +0000 |
commit | 052ef695708eddeaa81c3fcf5747824c1f0ad073 (patch) | |
tree | 1122ad13a7fe3a97d2e6bf4b160f5b9582e679de /src | |
parent | f830443814fb21bd4b1009186b23680e3a38935e (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>
Diffstat (limited to 'src')
-rw-r--r-- | src/gpu/GrBackendTextureImageGenerator.cpp | 14 | ||||
-rw-r--r-- | src/gpu/GrBackendTextureImageGenerator.h | 2 | ||||
-rw-r--r-- | src/image/SkImage_Gpu.cpp | 7 |
3 files changed, 14 insertions, 9 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)); } |