diff options
author | 2017-09-07 10:19:08 -0400 | |
---|---|---|
committer | 2017-09-07 15:34:21 +0000 | |
commit | a8ac92418807e3d46a45413459e6895160134c1d (patch) | |
tree | d1ac55f13ab8a7c90f92d7512b02e4d2c1e22b62 /src/image | |
parent | da669f150690e5e3d54099b18adb75420068582e (diff) |
Make SkImage_Lazy always report the color space of its data
Legacy clients are likely to ignore this information, but there are
cases (using SkColorSpaceXformCanvas) where getting accurate information
is important.
Bug: skia:
Change-Id: Ia56170559c82299375021c813424098ffc627b02
Reviewed-on: https://skia-review.googlesource.com/43562
Reviewed-by: Mike Klein <mtklein@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
Diffstat (limited to 'src/image')
-rw-r--r-- | src/image/SkImage_Gpu.cpp | 14 | ||||
-rw-r--r-- | src/image/SkImage_Lazy.cpp | 16 |
2 files changed, 22 insertions, 8 deletions
diff --git a/src/image/SkImage_Gpu.cpp b/src/image/SkImage_Gpu.cpp index d5dc4a2e32..3458075321 100644 --- a/src/image/SkImage_Gpu.cpp +++ b/src/image/SkImage_Gpu.cpp @@ -203,9 +203,19 @@ bool SkImage_Gpu::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, size flags = GrContextPriv::kUnpremul_PixelOpsFlag; } + // This hack allows us to call makeNonTextureImage on images with arbitrary color spaces. + // Otherwise, we'll be unable to create a render target context. + // TODO: This shouldn't be necessary - we need more robust support for images (and surfaces) + // with arbitrary color spaces. Unfortunately, this is one spot where we go from image to + // surface (rather than the opposite), and our lenient image rules break our (currently) more + // strict surface rules. + sk_sp<SkColorSpace> surfaceColorSpace = fColorSpace; + if (!flags && SkColorSpace::Equals(fColorSpace.get(), dstInfo.colorSpace())) { + surfaceColorSpace = nullptr; + } + sk_sp<GrSurfaceContext> sContext = fContext->contextPriv().makeWrappedSurfaceContext( - fProxy, - fColorSpace); + fProxy, surfaceColorSpace); if (!sContext) { return false; } diff --git a/src/image/SkImage_Lazy.cpp b/src/image/SkImage_Lazy.cpp index aff19f8d79..14c8e199be 100644 --- a/src/image/SkImage_Lazy.cpp +++ b/src/image/SkImage_Lazy.cpp @@ -703,12 +703,16 @@ static void set_key_on_proxy(GrResourceProvider* resourceProvider, } sk_sp<SkColorSpace> SkImage_Lazy::getColorSpace(GrContext* ctx, SkColorSpace* dstColorSpace) { - // TODO: This isn't always correct. Picture generator currently produces textures in N32, - // and will (soon) emit them in an arbitrary (destination) space. We will need to stash that - // information in/on the key so we can return the correct space in case #1 of lockTexture. - CachedFormat format = this->chooseCacheFormat(dstColorSpace, ctx->caps()); - SkImageInfo cacheInfo = this->buildCacheInfo(format); - return sk_ref_sp(cacheInfo.colorSpace()); + if (!dstColorSpace) { + // In legacy mode, we do no modification to the image's color space or encoding. + // Subsequent legacy drawing is likely to ignore the color space, but some clients + // may want to know what space the image data is in, so return it. + return fInfo.refColorSpace(); + } else { + CachedFormat format = this->chooseCacheFormat(dstColorSpace, ctx->caps()); + SkImageInfo cacheInfo = this->buildCacheInfo(format); + return cacheInfo.refColorSpace(); + } } /* |