diff options
author | Brian Salomon <bsalomon@google.com> | 2018-05-09 16:33:09 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2018-05-09 22:36:11 +0000 |
commit | 1fcac055694780d37e392e1929342d08ee0e009d (patch) | |
tree | 90681f8cafb271cac2fad945764e09529ffdb427 /src/gpu/GrResourceProvider.cpp | |
parent | d813f9cdc75879639b990b2068deb5a755954e58 (diff) |
Fix extra texture creation in GrResourceProvider::createTexture() with SRGB data.
We would make a temporary surface context around a scratch texture with
a SRGB color space and then attempt writePixels with a src SkImageInfo
with no color space. Then we'd fall back to creating a texture with
initial data.
Now we will make the src SkImageInfo have a SRGB color space and then
assume success.
Bug: b/78866720
Change-Id: I541a3b73c72f610533cfbc6892b2782c90e5121d
Reviewed-on: https://skia-review.googlesource.com/127130
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
Diffstat (limited to 'src/gpu/GrResourceProvider.cpp')
-rw-r--r-- | src/gpu/GrResourceProvider.cpp | 56 |
1 files changed, 24 insertions, 32 deletions
diff --git a/src/gpu/GrResourceProvider.cpp b/src/gpu/GrResourceProvider.cpp index 2d2b3a7bc9..2145190ee2 100644 --- a/src/gpu/GrResourceProvider.cpp +++ b/src/gpu/GrResourceProvider.cpp @@ -95,16 +95,6 @@ sk_sp<GrTexture> GrResourceProvider::getExactScratch(const GrSurfaceDesc& desc, return tex; } -static bool make_info(int w, int h, GrPixelConfig config, SkImageInfo* ii) { - SkColorType colorType; - if (!GrPixelConfigToColorType(config, &colorType)) { - return false; - } - - *ii = SkImageInfo::Make(w, h, colorType, kUnknown_SkAlphaType, nullptr); - return true; -} - sk_sp<GrTexture> GrResourceProvider::createTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted, SkBackingFit fit, @@ -126,34 +116,36 @@ sk_sp<GrTexture> GrResourceProvider::createTexture(const GrSurfaceDesc& desc, GrContext* context = fGpu->getContext(); GrProxyProvider* proxyProvider = context->contextPriv().proxyProvider(); - SkImageInfo srcInfo; - - if (make_info(desc.fWidth, desc.fHeight, desc.fConfig, &srcInfo)) { + SkColorType colorType; + if (GrPixelConfigToColorType(desc.fConfig, &colorType)) { // DDL TODO: remove this use of createInstantiatedProxy and convert it to a testing-only // method. sk_sp<GrTextureProxy> proxy = proxyProvider->createInstantiatedProxy( desc, kTopLeft_GrSurfaceOrigin, fit, budgeted); - if (proxy) { - // We use an ephemeral surface context to do the write pixels. Here it isn't clear what - // color space to tag it with. That's ok because GrSurfaceContext::writePixels doesn't - // do any color space conversions. Though, that is likely to change. However, if the - // pixel config is sRGB then the passed color space here must have sRGB gamma or - // GrSurfaceContext creation fails. - sk_sp<SkColorSpace> colorSpace; - if (GrPixelConfigIsSRGB(desc.fConfig)) { - colorSpace = SkColorSpace::MakeSRGB(); - } - sk_sp<GrSurfaceContext> sContext = context->contextPriv().makeWrappedSurfaceContext( - std::move(proxy), std::move(colorSpace)); - if (sContext) { - if (sContext->writePixels(srcInfo, mipLevel.fPixels, mipLevel.fRowBytes, 0, 0)) { - return sk_ref_sp(sContext->asTextureProxy()->priv().peekTexture()); - } - } + if (!proxy) { + return nullptr; } + // We use an ephemeral surface context to do the write pixels. Here it isn't clear what + // color space to tag it with. That's ok because GrSurfaceContext::writePixels doesn't + // do any color space conversions. Though, that is likely to change. However, if the + // pixel config is sRGB then the passed color space here must have sRGB gamma or + // GrSurfaceContext creation fails. + sk_sp<SkColorSpace> colorSpace; + if (GrPixelConfigIsSRGB(desc.fConfig)) { + colorSpace = SkColorSpace::MakeSRGB(); + } + auto srcInfo = SkImageInfo::Make(desc.fWidth, desc.fHeight, colorType, + kUnknown_SkAlphaType, colorSpace); + sk_sp<GrSurfaceContext> sContext = context->contextPriv().makeWrappedSurfaceContext( + std::move(proxy), std::move(colorSpace)); + if (!sContext) { + return nullptr; + } + SkAssertResult(sContext->writePixels(srcInfo, mipLevel.fPixels, mipLevel.fRowBytes, 0, 0)); + return sk_ref_sp(sContext->asTextureProxy()->priv().peekTexture()); + } else { + return fGpu->createTexture(desc, budgeted, &mipLevel, 1); } - - return fGpu->createTexture(desc, budgeted, &mipLevel, 1); } sk_sp<GrTexture> GrResourceProvider::createTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted, |