From 61624f0c716b576706659750d87b6956f4c15722 Mon Sep 17 00:00:00 2001 From: Brian Osman Date: Fri, 9 Dec 2016 14:51:59 -0500 Subject: [PATCH] Plumb dst color space in many places, rather than "mode" This is less to type in most cases, and gives us more information (for things like picture-backed images, where we need to know all about the destination surface). Additionally, strip out the plumbing entirely for bitmap sources, where we don't need to know anything. BUG=skia: Change-Id: I4deff6c7c345fcf62eb08b2aff0560adae4313da Reviewed-on: https://skia-review.googlesource.com/5748 Reviewed-by: Mike Klein Reviewed-by: Brian Salomon Commit-Queue: Brian Osman --- bench/SkBlend_optsBench.cpp | 3 ++- .../SkPerlinNoiseShader2/SkPerlinNoiseShader2.cpp | 8 +++--- gm/image_pict.cpp | 6 ++--- gm/texturedomaineffect.cpp | 3 +-- gm/yuvtorgbeffect.cpp | 18 +++++--------- include/core/SkShader.h | 7 ++---- include/gpu/GrRenderTargetContext.h | 4 --- include/gpu/SkGr.h | 6 ++--- src/core/SkBitmapController.cpp | 7 ++++-- src/core/SkBitmapDevice.cpp | 7 +----- src/core/SkBitmapProvider.cpp | 2 +- src/core/SkBitmapProvider.h | 16 ++++++------ src/core/SkDevice.cpp | 10 ++------ src/core/SkImageCacherator.cpp | 29 ++++++++++------------ src/core/SkImageCacherator.h | 11 ++++---- src/core/SkLocalMatrixShader.cpp | 3 +-- src/core/SkPictureShader.cpp | 3 +-- src/core/SkSpecialImage.cpp | 15 ++++------- src/core/SkSpecialImage.h | 2 +- src/effects/SkImageSource.cpp | 6 +---- src/effects/SkPerlinNoiseShader.cpp | 4 +-- src/effects/SkTableColorFilter.cpp | 3 +-- src/effects/gradients/SkGradientShader.cpp | 4 +-- src/gpu/GrBitmapTextureMaker.cpp | 12 ++++----- src/gpu/GrBitmapTextureMaker.h | 6 ++--- src/gpu/GrImageTextureMaker.cpp | 13 +++++----- src/gpu/GrImageTextureMaker.h | 6 ++--- src/gpu/GrTestUtils.cpp | 3 --- src/gpu/GrTextureAdjuster.cpp | 12 ++++----- src/gpu/GrTextureAdjuster.h | 8 +++--- src/gpu/GrTextureMaker.cpp | 19 +++++++------- src/gpu/GrTextureMaker.h | 13 +++++----- src/gpu/GrTextureProducer.h | 8 +++--- src/gpu/SkGpuDevice.cpp | 27 ++++++++------------ src/gpu/SkGpuDevice_drawTexture.cpp | 2 +- src/gpu/SkGr.cpp | 22 ++++++++-------- src/gpu/SkGrPriv.h | 2 +- src/image/SkImage.cpp | 19 ++++++-------- src/image/SkImageShader.cpp | 11 +++----- src/image/SkImage_Base.h | 6 ++--- src/image/SkImage_Generator.cpp | 22 ++++++++-------- src/image/SkImage_Gpu.cpp | 11 +++----- src/image/SkImage_Gpu.h | 6 ++--- src/image/SkImage_Raster.cpp | 17 ++++++------- src/pdf/SkPDFBitmap.cpp | 6 +++-- src/pdf/SkPDFDevice.cpp | 4 +-- tests/ImageFilterCacheTest.cpp | 8 +++--- tests/SkBlend_optsTest.cpp | 3 ++- tests/SpecialImageTest.cpp | 14 ++++++----- 49 files changed, 195 insertions(+), 262 deletions(-) diff --git a/bench/SkBlend_optsBench.cpp b/bench/SkBlend_optsBench.cpp index b5827ef..d7ba2be 100644 --- a/bench/SkBlend_optsBench.cpp +++ b/bench/SkBlend_optsBench.cpp @@ -146,7 +146,8 @@ protected: if (!fPixmap.addr()) { sk_sp image = GetResourceAsImage(fFileName.c_str()); SkBitmap bm; - if (!as_IB(image)->getROPixels(&bm, SkDestinationSurfaceColorMode::kLegacy)) { + SkColorSpace* legacyColorSpace = nullptr; + if (!as_IB(image)->getROPixels(&bm, legacyColorSpace)) { SkFAIL("Could not read resource"); } bm.peekPixels(&fPixmap); diff --git a/experimental/SkPerlinNoiseShader2/SkPerlinNoiseShader2.cpp b/experimental/SkPerlinNoiseShader2/SkPerlinNoiseShader2.cpp index f304067..6050a5c 100644 --- a/experimental/SkPerlinNoiseShader2/SkPerlinNoiseShader2.cpp +++ b/experimental/SkPerlinNoiseShader2/SkPerlinNoiseShader2.cpp @@ -1323,10 +1323,10 @@ sk_sp SkPerlinNoiseShader2::asFragmentProcessor(const AsFPA GrSamplerParams::FilterMode::kNone_FilterMode); sk_sp permutationsTexture( GrRefCachedBitmapTexture(args.fContext, paintingData->getImprovedPermutationsBitmap(), - textureParams, args.fColorMode)); + textureParams)); sk_sp gradientTexture( GrRefCachedBitmapTexture(args.fContext, paintingData->getGradientBitmap(), - textureParams, args.fColorMode)); + textureParams)); return GrImprovedPerlinNoiseEffect::Make(fNumOctaves, fSeed, paintingData, permutationsTexture.get(), gradientTexture.get(), m); @@ -1350,10 +1350,10 @@ sk_sp SkPerlinNoiseShader2::asFragmentProcessor(const AsFPA sk_sp permutationsTexture( GrRefCachedBitmapTexture(args.fContext, paintingData->getPermutationsBitmap(), - GrSamplerParams::ClampNoFilter(), args.fColorMode)); + GrSamplerParams::ClampNoFilter())); sk_sp noiseTexture( GrRefCachedBitmapTexture(args.fContext, paintingData->getNoiseBitmap(), - GrSamplerParams::ClampNoFilter(), args.fColorMode)); + GrSamplerParams::ClampNoFilter())); if ((permutationsTexture) && (noiseTexture)) { sk_sp inner( diff --git a/gm/image_pict.cpp b/gm/image_pict.cpp index 11a56da..76ea3d9 100644 --- a/gm/image_pict.cpp +++ b/gm/image_pict.cpp @@ -308,8 +308,7 @@ protected: static void draw_as_bitmap(SkCanvas* canvas, SkImageCacherator* cache, SkScalar x, SkScalar y) { SkBitmap bitmap; - cache->lockAsBitmap(&bitmap, nullptr, - SkDestinationSurfaceColorMode::kGammaAndColorSpaceAware); + cache->lockAsBitmap(&bitmap, nullptr, canvas->imageInfo().colorSpace()); canvas->drawBitmap(bitmap, x, y); } @@ -318,8 +317,7 @@ protected: sk_sp texColorSpace; sk_sp texture( cache->lockAsTexture(canvas->getGrContext(), GrSamplerParams::ClampBilerp(), - SkDestinationSurfaceColorMode::kGammaAndColorSpaceAware, - &texColorSpace, nullptr)); + canvas->imageInfo().colorSpace(), &texColorSpace, nullptr)); if (!texture) { // show placeholder if we have no texture SkPaint paint; diff --git a/gm/texturedomaineffect.cpp b/gm/texturedomaineffect.cpp index e51a906..9b46c53 100644 --- a/gm/texturedomaineffect.cpp +++ b/gm/texturedomaineffect.cpp @@ -83,8 +83,7 @@ protected: } sk_sp texture( - GrRefCachedBitmapTexture(context, fBmp, GrSamplerParams::ClampNoFilter(), - SkDestinationSurfaceColorMode::kGammaAndColorSpaceAware)); + GrRefCachedBitmapTexture(context, fBmp, GrSamplerParams::ClampNoFilter())); if (!texture) { return; } diff --git a/gm/yuvtorgbeffect.cpp b/gm/yuvtorgbeffect.cpp index 6b90dad..db0cf1b 100644 --- a/gm/yuvtorgbeffect.cpp +++ b/gm/yuvtorgbeffect.cpp @@ -82,14 +82,11 @@ protected: sk_sp texture[3]; texture[0].reset( - GrRefCachedBitmapTexture(context, fBmp[0], GrSamplerParams::ClampBilerp(), - SkDestinationSurfaceColorMode::kGammaAndColorSpaceAware)); + GrRefCachedBitmapTexture(context, fBmp[0], GrSamplerParams::ClampBilerp())); texture[1].reset( - GrRefCachedBitmapTexture(context, fBmp[1], GrSamplerParams::ClampBilerp(), - SkDestinationSurfaceColorMode::kGammaAndColorSpaceAware)); + GrRefCachedBitmapTexture(context, fBmp[1], GrSamplerParams::ClampBilerp())); texture[2].reset( - GrRefCachedBitmapTexture(context, fBmp[2], GrSamplerParams::ClampBilerp(), - SkDestinationSurfaceColorMode::kGammaAndColorSpaceAware)); + GrRefCachedBitmapTexture(context, fBmp[2], GrSamplerParams::ClampBilerp())); if (!texture[0] || !texture[1] || !texture[2]) { return; @@ -207,14 +204,11 @@ protected: sk_sp texture[3]; texture[0].reset( - GrRefCachedBitmapTexture(context, fBmp[0], GrSamplerParams::ClampBilerp(), - SkDestinationSurfaceColorMode::kGammaAndColorSpaceAware)); + GrRefCachedBitmapTexture(context, fBmp[0], GrSamplerParams::ClampBilerp())); texture[1].reset( - GrRefCachedBitmapTexture(context, fBmp[1], GrSamplerParams::ClampBilerp(), - SkDestinationSurfaceColorMode::kGammaAndColorSpaceAware)); + GrRefCachedBitmapTexture(context, fBmp[1], GrSamplerParams::ClampBilerp())); texture[2].reset( - GrRefCachedBitmapTexture(context, fBmp[1], GrSamplerParams::ClampBilerp(), - SkDestinationSurfaceColorMode::kGammaAndColorSpaceAware)); + GrRefCachedBitmapTexture(context, fBmp[1], GrSamplerParams::ClampBilerp())); if (!texture[0] || !texture[1] || !texture[2]) { return; diff --git a/include/core/SkShader.h b/include/core/SkShader.h index cafeedd..6d24c1a 100644 --- a/include/core/SkShader.h +++ b/include/core/SkShader.h @@ -342,21 +342,18 @@ public: const SkMatrix* viewMatrix, const SkMatrix* localMatrix, SkFilterQuality filterQuality, - SkColorSpace* dstColorSpace, - SkDestinationSurfaceColorMode colorMode) + SkColorSpace* dstColorSpace) : fContext(context) , fViewMatrix(viewMatrix) , fLocalMatrix(localMatrix) , fFilterQuality(filterQuality) - , fDstColorSpace(dstColorSpace) - , fColorMode(colorMode) {} + , fDstColorSpace(dstColorSpace) {} GrContext* fContext; const SkMatrix* fViewMatrix; const SkMatrix* fLocalMatrix; SkFilterQuality fFilterQuality; SkColorSpace* fDstColorSpace; - SkDestinationSurfaceColorMode fColorMode; }; /** diff --git a/include/gpu/GrRenderTargetContext.h b/include/gpu/GrRenderTargetContext.h index 7ef572a..3468528 100644 --- a/include/gpu/GrRenderTargetContext.h +++ b/include/gpu/GrRenderTargetContext.h @@ -344,10 +344,6 @@ public: GrPixelConfig config() const { return fRenderTargetProxy->config(); } int numColorSamples() const { return fRenderTargetProxy->numColorSamples(); } bool isGammaCorrect() const { return SkToBool(fColorSpace.get()); } - SkDestinationSurfaceColorMode colorMode() const { - return this->isGammaCorrect() ? SkDestinationSurfaceColorMode::kGammaAndColorSpaceAware - : SkDestinationSurfaceColorMode::kLegacy; - } const SkSurfaceProps& surfaceProps() const { return fSurfaceProps; } SkColorSpace* getColorSpace() const { return fColorSpace.get(); } GrColorSpaceXform* getColorXformFromSRGB() const { return fColorXformFromSRGB.get(); } diff --git a/include/gpu/SkGr.h b/include/gpu/SkGr.h index 0e58e72..e59720e 100644 --- a/include/gpu/SkGr.h +++ b/include/gpu/SkGr.h @@ -79,11 +79,9 @@ static inline GrColor SkPMColorToGrColor(SkPMColor c) { /** Returns a texture representing the bitmap that is compatible with the GrSamplerParams. The texture is inserted into the cache (unless the bitmap is marked volatile) and can be retrieved again via this function. */ -GrTexture* GrRefCachedBitmapTexture(GrContext*, const SkBitmap&, const GrSamplerParams&, - SkDestinationSurfaceColorMode); +GrTexture* GrRefCachedBitmapTexture(GrContext*, const SkBitmap&, const GrSamplerParams&); -sk_sp GrMakeCachedBitmapTexture(GrContext*, const SkBitmap&, const GrSamplerParams&, - SkDestinationSurfaceColorMode); +sk_sp GrMakeCachedBitmapTexture(GrContext*, const SkBitmap&, const GrSamplerParams&); // TODO: Move SkImageInfo2GrPixelConfig to SkGrPriv.h (requires cleanup to SkWindow its subclasses). GrPixelConfig SkImageInfo2GrPixelConfig(SkColorType, SkAlphaType, const SkColorSpace*, diff --git a/src/core/SkBitmapController.cpp b/src/core/SkBitmapController.cpp index 80af4d7..75c500d 100644 --- a/src/core/SkBitmapController.cpp +++ b/src/core/SkBitmapController.cpp @@ -182,14 +182,17 @@ bool SkDefaultBitmapControllerState::processMediumRequest(const SkBitmapProvider return false; } + SkDestinationSurfaceColorMode colorMode = provider.dstColorSpace() + ? SkDestinationSurfaceColorMode::kGammaAndColorSpaceAware + : SkDestinationSurfaceColorMode::kLegacy; if (invScaleSize.width() > SK_Scalar1 || invScaleSize.height() > SK_Scalar1) { - fCurrMip.reset(SkMipMapCache::FindAndRef(provider.makeCacheDesc(), provider.colorMode())); + fCurrMip.reset(SkMipMapCache::FindAndRef(provider.makeCacheDesc(), colorMode)); if (nullptr == fCurrMip.get()) { SkBitmap orig; if (!provider.asBitmap(&orig)) { return false; } - fCurrMip.reset(SkMipMapCache::AddAndRef(orig, provider.colorMode())); + fCurrMip.reset(SkMipMapCache::AddAndRef(orig, colorMode)); if (nullptr == fCurrMip.get()) { return false; } diff --git a/src/core/SkBitmapDevice.cpp b/src/core/SkBitmapDevice.cpp index f5e2c32..a5dadbb 100644 --- a/src/core/SkBitmapDevice.cpp +++ b/src/core/SkBitmapDevice.cpp @@ -417,13 +417,8 @@ sk_sp SkBitmapDevice::makeSpecial(const SkBitmap& bitmap) { } sk_sp SkBitmapDevice::makeSpecial(const SkImage* image) { - // This is called when we're about to draw the special-ized version of image to *this* device, - // so we can use our own presense/absence of a color space to decide how to decode the image. - SkDestinationSurfaceColorMode decodeColorMode = fBitmap.colorSpace() - ? SkDestinationSurfaceColorMode::kGammaAndColorSpaceAware - : SkDestinationSurfaceColorMode::kLegacy; return SkSpecialImage::MakeFromImage(SkIRect::MakeWH(image->width(), image->height()), - image->makeNonTextureImage(), decodeColorMode); + image->makeNonTextureImage(), fBitmap.colorSpace()); } sk_sp SkBitmapDevice::snapSpecial() { diff --git a/src/core/SkBitmapProvider.cpp b/src/core/SkBitmapProvider.cpp index 20479da..9575ae2 100644 --- a/src/core/SkBitmapProvider.cpp +++ b/src/core/SkBitmapProvider.cpp @@ -45,7 +45,7 @@ void SkBitmapProvider::notifyAddedToCache() const { } bool SkBitmapProvider::asBitmap(SkBitmap* bm) const { - return as_IB(fImage)->getROPixels(bm, fColorMode, SkImage::kAllow_CachingHint); + return as_IB(fImage)->getROPixels(bm, fDstColorSpace, SkImage::kAllow_CachingHint); } bool SkBitmapProvider::accessScaledImage(const SkRect& srcRect, diff --git a/src/core/SkBitmapProvider.h b/src/core/SkBitmapProvider.h index 9ea2442..54f2877 100644 --- a/src/core/SkBitmapProvider.h +++ b/src/core/SkBitmapProvider.h @@ -13,20 +13,20 @@ class SkBitmapProvider { public: - explicit SkBitmapProvider(const SkImage* img, SkDestinationSurfaceColorMode colorMode) + explicit SkBitmapProvider(const SkImage* img, SkColorSpace* dstColorSpace) : fImage(img) - , fColorMode(colorMode) { + , fDstColorSpace(dstColorSpace) { SkASSERT(img); } SkBitmapProvider(const SkBitmapProvider& other) : fImage(other.fImage) - , fColorMode(other.fColorMode) + , fDstColorSpace(other.fDstColorSpace) {} int width() const; int height() const; uint32_t getID() const; - SkDestinationSurfaceColorMode colorMode() const { return fColorMode; } + SkColorSpace* dstColorSpace() const { return fDstColorSpace; } SkImageInfo info() const; bool isVolatile() const; @@ -48,10 +48,10 @@ private: void* operator new(size_t) = delete; void* operator new(size_t, void*) = delete; - // SkBitmapProvider is always short-lived/stack allocated, and the source image is guaranteed - // to outlive its scope => we can store a raw ptr to avoid ref churn. - const SkImage* fImage; - SkDestinationSurfaceColorMode fColorMode; + // SkBitmapProvider is always short-lived/stack allocated, and the source image and destination + // color space are guaranteed to outlive its scope => we can store raw ptrs to avoid ref churn. + const SkImage* fImage; + SkColorSpace* fDstColorSpace; }; #endif diff --git a/src/core/SkDevice.cpp b/src/core/SkDevice.cpp index 741273b..ff99a09 100644 --- a/src/core/SkDevice.cpp +++ b/src/core/SkDevice.cpp @@ -234,11 +234,8 @@ void SkBaseDevice::drawImage(const SkDraw& draw, const SkImage* image, SkScalar return; } - SkDestinationSurfaceColorMode colorMode = this->imageInfo().colorSpace() - ? SkDestinationSurfaceColorMode::kGammaAndColorSpaceAware - : SkDestinationSurfaceColorMode::kLegacy; SkBitmap bm; - if (as_IB(image)->getROPixels(&bm, colorMode)) { + if (as_IB(image)->getROPixels(&bm, this->imageInfo().colorSpace())) { this->drawBitmap(draw, bm, SkMatrix::MakeTrans(x, y), paint); } } @@ -251,11 +248,8 @@ void SkBaseDevice::drawImageRect(const SkDraw& draw, const SkImage* image, const return; } - SkDestinationSurfaceColorMode colorMode = this->imageInfo().colorSpace() - ? SkDestinationSurfaceColorMode::kGammaAndColorSpaceAware - : SkDestinationSurfaceColorMode::kLegacy; SkBitmap bm; - if (as_IB(image)->getROPixels(&bm, colorMode)) { + if (as_IB(image)->getROPixels(&bm, this->imageInfo().colorSpace())) { this->drawBitmapRect(draw, bm, src, dst, paint, constraint); } } diff --git a/src/core/SkImageCacherator.cpp b/src/core/SkImageCacherator.cpp index c614139..03624fd 100644 --- a/src/core/SkImageCacherator.cpp +++ b/src/core/SkImageCacherator.cpp @@ -214,9 +214,9 @@ bool SkImageCacherator::tryLockAsBitmap(SkBitmap* bitmap, const SkImage* client, } bool SkImageCacherator::lockAsBitmap(SkBitmap* bitmap, const SkImage* client, - SkDestinationSurfaceColorMode colorMode, + SkColorSpace* dstColorSpace, SkImage::CachingHint chint) { - CachedFormat format = this->chooseCacheFormat(colorMode); + CachedFormat format = this->chooseCacheFormat(dstColorSpace); SkImageInfo cacheInfo = this->buildCacheInfo(format); if (kNeedNewImageUniqueID == fUniqueIDs[format]) { @@ -302,11 +302,10 @@ struct CacheCaps { const GrCaps* fCaps; }; -SkImageCacherator::CachedFormat SkImageCacherator::chooseCacheFormat( - SkDestinationSurfaceColorMode colorMode, - const GrCaps* grCaps) { +SkImageCacherator::CachedFormat SkImageCacherator::chooseCacheFormat(SkColorSpace* dstColorSpace, + const GrCaps* grCaps) { SkColorSpace* cs = fInfo.colorSpace(); - if (!cs || SkDestinationSurfaceColorMode::kLegacy == colorMode) { + if (!cs || !dstColorSpace) { return kLegacy_CachedFormat; } @@ -491,12 +490,11 @@ static GrTexture* set_key_and_return(GrTexture* tex, const GrUniqueKey& key) { return tex; } -sk_sp SkImageCacherator::getColorSpace(GrContext* ctx, - SkDestinationSurfaceColorMode colorMode) { +sk_sp SkImageCacherator::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(colorMode, ctx->caps()); + CachedFormat format = this->chooseCacheFormat(dstColorSpace, ctx->caps()); SkImageInfo cacheInfo = this->buildCacheInfo(format); return sk_ref_sp(cacheInfo.colorSpace()); } @@ -512,8 +510,7 @@ sk_sp SkImageCacherator::getColorSpace(GrContext* ctx, */ GrTexture* SkImageCacherator::lockTexture(GrContext* ctx, const GrUniqueKey& origKey, const SkImage* client, SkImage::CachingHint chint, - bool willBeMipped, - SkDestinationSurfaceColorMode colorMode) { + bool willBeMipped, SkColorSpace* dstColorSpace) { // Values representing the various texture lock paths we can take. Used for logging the path // taken to a histogram. enum LockTexturePath { @@ -529,7 +526,7 @@ GrTexture* SkImageCacherator::lockTexture(GrContext* ctx, const GrUniqueKey& ori // Determine which cached format we're going to use (which may involve decoding to a different // info than the generator provides). - CachedFormat format = this->chooseCacheFormat(colorMode, ctx->caps()); + CachedFormat format = this->chooseCacheFormat(dstColorSpace, ctx->caps()); // Fold the cache format into our texture key GrUniqueKey key; @@ -592,7 +589,7 @@ GrTexture* SkImageCacherator::lockTexture(GrContext* ctx, const GrUniqueKey& ori if (this->tryLockAsBitmap(&bitmap, client, chint, format, cacheInfo)) { GrTexture* tex = nullptr; if (willBeMipped) { - tex = GrGenerateMipMapsAndUploadToTexture(ctx, bitmap, colorMode); + tex = GrGenerateMipMapsAndUploadToTexture(ctx, bitmap, dstColorSpace); } if (!tex) { tex = GrUploadBitmapToTexture(ctx, bitmap); @@ -611,21 +608,21 @@ GrTexture* SkImageCacherator::lockTexture(GrContext* ctx, const GrUniqueKey& ori /////////////////////////////////////////////////////////////////////////////////////////////////// GrTexture* SkImageCacherator::lockAsTexture(GrContext* ctx, const GrSamplerParams& params, - SkDestinationSurfaceColorMode colorMode, + SkColorSpace* dstColorSpace, sk_sp* texColorSpace, const SkImage* client, SkImage::CachingHint chint) { if (!ctx) { return nullptr; } - return GrImageTextureMaker(ctx, this, client, chint).refTextureForParams(params, colorMode, + return GrImageTextureMaker(ctx, this, client, chint).refTextureForParams(params, dstColorSpace, texColorSpace); } #else GrTexture* SkImageCacherator::lockAsTexture(GrContext* ctx, const GrSamplerParams&, - SkDestinationSurfaceColorMode colorMode, + SkColorSpace* dstColorSpace, sk_sp* texColorSpace, const SkImage* client, SkImage::CachingHint) { return nullptr; diff --git a/src/core/SkImageCacherator.h b/src/core/SkImageCacherator.h index 89ac378..0e37efa 100644 --- a/src/core/SkImageCacherator.h +++ b/src/core/SkImageCacherator.h @@ -48,7 +48,7 @@ public: * If not NULL, the client will be notified (->notifyAddedToCache()) when resources are * added to the cache on its behalf. */ - bool lockAsBitmap(SkBitmap*, const SkImage* client, SkDestinationSurfaceColorMode colorMode, + bool lockAsBitmap(SkBitmap*, const SkImage* client, SkColorSpace* dstColorSpace, SkImage::CachingHint = SkImage::kAllow_CachingHint); /** @@ -60,8 +60,7 @@ public: * * The caller is responsible for calling texture->unref() when they are done. */ - GrTexture* lockAsTexture(GrContext*, const GrSamplerParams&, - SkDestinationSurfaceColorMode colorMode, + GrTexture* lockAsTexture(GrContext*, const GrSamplerParams&, SkColorSpace* dstColorSpace, sk_sp* texColorSpace, const SkImage* client, SkImage::CachingHint = SkImage::kAllow_CachingHint); @@ -116,7 +115,7 @@ private: SkImageCacherator(Validator*); - CachedFormat chooseCacheFormat(SkDestinationSurfaceColorMode, const GrCaps* = nullptr); + CachedFormat chooseCacheFormat(SkColorSpace* dstColorSpace, const GrCaps* = nullptr); SkImageInfo buildCacheInfo(CachedFormat); bool generateBitmap(SkBitmap*, const SkImageInfo&); @@ -126,11 +125,11 @@ private: // Returns the texture. If the cacherator is generating the texture and wants to cache it, // it should use the passed in key (if the key is valid). GrTexture* lockTexture(GrContext*, const GrUniqueKey& key, const SkImage* client, - SkImage::CachingHint, bool willBeMipped, SkDestinationSurfaceColorMode); + SkImage::CachingHint, bool willBeMipped, SkColorSpace* dstColorSpace); // Returns the color space of the texture that would be returned if you called lockTexture. // Separate code path to allow querying of the color space for textures that cached (even // externally). - sk_sp getColorSpace(GrContext*, SkDestinationSurfaceColorMode); + sk_sp getColorSpace(GrContext*, SkColorSpace* dstColorSpace); void makeCacheKeyFromOrigKey(const GrUniqueKey& origKey, CachedFormat, GrUniqueKey* cacheKey); #endif diff --git a/src/core/SkLocalMatrixShader.cpp b/src/core/SkLocalMatrixShader.cpp index fb436d8..8e01c47 100644 --- a/src/core/SkLocalMatrixShader.cpp +++ b/src/core/SkLocalMatrixShader.cpp @@ -18,8 +18,7 @@ sk_sp SkLocalMatrixShader::asFragmentProcessor(const AsFPAr tmp.preConcat(*args.fLocalMatrix); } return fProxyShader->asFragmentProcessor(AsFPArgs( - args.fContext, args.fViewMatrix, &tmp, args.fFilterQuality, args.fDstColorSpace, - args.fColorMode)); + args.fContext, args.fViewMatrix, &tmp, args.fFilterQuality, args.fDstColorSpace)); } #endif diff --git a/src/core/SkPictureShader.cpp b/src/core/SkPictureShader.cpp index 74cce68..23f2e31 100644 --- a/src/core/SkPictureShader.cpp +++ b/src/core/SkPictureShader.cpp @@ -328,7 +328,6 @@ sk_sp SkPictureShader::asFragmentProcessor(const AsFPArgs& return nullptr; } return bitmapShader->asFragmentProcessor(SkShader::AsFPArgs( - args.fContext, args.fViewMatrix, nullptr, args.fFilterQuality, args.fDstColorSpace, - args.fColorMode)); + args.fContext, args.fViewMatrix, nullptr, args.fFilterQuality, args.fDstColorSpace)); } #endif diff --git a/src/core/SkSpecialImage.cpp b/src/core/SkSpecialImage.cpp index fefe5c2..2567bf1 100644 --- a/src/core/SkSpecialImage.cpp +++ b/src/core/SkSpecialImage.cpp @@ -102,8 +102,7 @@ sk_sp SkSpecialImage::makeTextureImage(GrContext* context) { } sk_sp resultTex( - GrRefCachedBitmapTexture(context, bmp, GrSamplerParams::ClampNoFilter(), - SkDestinationSurfaceColorMode::kGammaAndColorSpaceAware)); + GrRefCachedBitmapTexture(context, bmp, GrSamplerParams::ClampNoFilter())); if (!resultTex) { return nullptr; } @@ -181,7 +180,7 @@ static bool rect_fits(const SkIRect& rect, int width, int height) { sk_sp SkSpecialImage::MakeFromImage(const SkIRect& subset, sk_sp image, - SkDestinationSurfaceColorMode colorMode, + SkColorSpace* dstColorSpace, const SkSurfaceProps* props) { SkASSERT(rect_fits(subset, image->width(), image->height())); @@ -193,7 +192,7 @@ sk_sp SkSpecialImage::MakeFromImage(const SkIRect& subset, #endif { SkBitmap bm; - if (as_IB(image)->getROPixels(&bm, colorMode)) { + if (as_IB(image)->getROPixels(&bm, dstColorSpace)) { return MakeFromRaster(subset, bm, props); } } @@ -242,8 +241,7 @@ public: sk_sp onAsTextureRef(GrContext* context) const override { if (context) { return sk_ref_sp( - GrRefCachedBitmapTexture(context, fBitmap, GrSamplerParams::ClampNoFilter(), - SkDestinationSurfaceColorMode::kGammaAndColorSpaceAware)); + GrRefCachedBitmapTexture(context, fBitmap, GrSamplerParams::ClampNoFilter())); } return nullptr; @@ -252,10 +250,7 @@ public: sk_sp onAsTextureProxy(GrContext* context) const override { if (context) { sk_sp tex(sk_ref_sp(GrRefCachedBitmapTexture( - context, - fBitmap, - GrSamplerParams::ClampNoFilter(), - SkDestinationSurfaceColorMode::kGammaAndColorSpaceAware))); + context, fBitmap, GrSamplerParams::ClampNoFilter()))); sk_sp sProxy = GrSurfaceProxy::MakeWrapped(std::move(tex)); return sk_ref_sp(sProxy->asTextureProxy()); } diff --git a/src/core/SkSpecialImage.h b/src/core/SkSpecialImage.h index c6afa1d..bf168f0 100644 --- a/src/core/SkSpecialImage.h +++ b/src/core/SkSpecialImage.h @@ -73,7 +73,7 @@ public: static sk_sp MakeFromImage(const SkIRect& subset, sk_sp, - SkDestinationSurfaceColorMode, + SkColorSpace* dstColorSpace, const SkSurfaceProps* = nullptr); static sk_sp MakeFromRaster(const SkIRect& subset, const SkBitmap&, diff --git a/src/effects/SkImageSource.cpp b/src/effects/SkImageSource.cpp index de84941..0f0160d 100644 --- a/src/effects/SkImageSource.cpp +++ b/src/effects/SkImageSource.cpp @@ -86,12 +86,8 @@ sk_sp SkImageSource::onFilterImage(SkSpecialImage* source, const if (fSrcRect == bounds && dstRect == bounds) { // No regions cropped out or resized; return entire image. offset->fX = offset->fY = 0; - SkDestinationSurfaceColorMode decodeColorMode = ctx.outputProperties().colorSpace() - ? SkDestinationSurfaceColorMode::kGammaAndColorSpaceAware - : SkDestinationSurfaceColorMode::kLegacy; return SkSpecialImage::MakeFromImage(SkIRect::MakeWH(fImage->width(), fImage->height()), - fImage, - decodeColorMode, + fImage, ctx.outputProperties().colorSpace(), &source->props()); } diff --git a/src/effects/SkPerlinNoiseShader.cpp b/src/effects/SkPerlinNoiseShader.cpp index 3f7f721..dc3d9a6 100644 --- a/src/effects/SkPerlinNoiseShader.cpp +++ b/src/effects/SkPerlinNoiseShader.cpp @@ -926,10 +926,10 @@ sk_sp SkPerlinNoiseShader::asFragmentProcessor(const AsFPAr new PaintingData(fTileSize, fSeed, fBaseFrequencyX, fBaseFrequencyY, matrix); sk_sp permutationsTexture( GrRefCachedBitmapTexture(args.fContext, paintingData->getPermutationsBitmap(), - GrSamplerParams::ClampNoFilter(), args.fColorMode)); + GrSamplerParams::ClampNoFilter())); sk_sp noiseTexture( GrRefCachedBitmapTexture(args.fContext, paintingData->getNoiseBitmap(), - GrSamplerParams::ClampNoFilter(), args.fColorMode)); + GrSamplerParams::ClampNoFilter())); SkMatrix m = *args.fViewMatrix; m.setTranslateX(-localMatrix.getTranslateX() + SK_Scalar1); diff --git a/src/effects/SkTableColorFilter.cpp b/src/effects/SkTableColorFilter.cpp index c2683b5..9c74634 100644 --- a/src/effects/SkTableColorFilter.cpp +++ b/src/effects/SkTableColorFilter.cpp @@ -474,8 +474,7 @@ sk_sp ColorTableEffect::Make(GrContext* context, SkBitmap b if (-1 == row) { atlas = nullptr; texture.reset( - GrRefCachedBitmapTexture(context, bitmap, GrSamplerParams::ClampNoFilter(), - SkDestinationSurfaceColorMode::kGammaAndColorSpaceAware)); + GrRefCachedBitmapTexture(context, bitmap, GrSamplerParams::ClampNoFilter())); } else { texture.reset(SkRef(atlas->getTexture())); } diff --git a/src/effects/gradients/SkGradientShader.cpp b/src/effects/gradients/SkGradientShader.cpp index 507fbe4..df78da9 100644 --- a/src/effects/gradients/SkGradientShader.cpp +++ b/src/effects/gradients/SkGradientShader.cpp @@ -1662,9 +1662,7 @@ GrGradientEffect::GrGradientEffect(const CreateArgs& args) { fCoordTransform.reset(*args.fMatrix, fAtlas->getTexture(), params.filterMode()); fTextureSampler.reset(fAtlas->getTexture(), params); } else { - sk_sp texture(GrRefCachedBitmapTexture( - args.fContext, bitmap, params, - SkDestinationSurfaceColorMode::kGammaAndColorSpaceAware)); + sk_sp texture(GrRefCachedBitmapTexture(args.fContext, bitmap, params)); if (!texture) { return; } diff --git a/src/gpu/GrBitmapTextureMaker.cpp b/src/gpu/GrBitmapTextureMaker.cpp index 0f26e51..184640f 100644 --- a/src/gpu/GrBitmapTextureMaker.cpp +++ b/src/gpu/GrBitmapTextureMaker.cpp @@ -27,7 +27,7 @@ GrBitmapTextureMaker::GrBitmapTextureMaker(GrContext* context, const SkBitmap& b } GrTexture* GrBitmapTextureMaker::refOriginalTexture(bool willBeMipped, - SkDestinationSurfaceColorMode colorMode) { + SkColorSpace* dstColorSpace) { GrTexture* tex = nullptr; if (fOriginalKey.isValid()) { @@ -37,7 +37,7 @@ GrTexture* GrBitmapTextureMaker::refOriginalTexture(bool willBeMipped, } } if (willBeMipped) { - tex = GrGenerateMipMapsAndUploadToTexture(this->context(), fBitmap, colorMode); + tex = GrGenerateMipMapsAndUploadToTexture(this->context(), fBitmap, dstColorSpace); } if (!tex) { tex = GrUploadBitmapToTexture(this->context(), fBitmap); @@ -50,8 +50,8 @@ GrTexture* GrBitmapTextureMaker::refOriginalTexture(bool willBeMipped, } void GrBitmapTextureMaker::makeCopyKey(const CopyParams& copyParams, GrUniqueKey* copyKey, - SkDestinationSurfaceColorMode colorMode) { - // Color mode is irrelevant in this case - we always upload the bitmap's contents as-is + SkColorSpace* dstColorSpace) { + // Destination color space is irrelevant - we always upload the bitmap's contents as-is if (fOriginalKey.isValid()) { MakeCopyKeyFromOrigKey(fOriginalKey, copyParams, copyKey); } @@ -65,7 +65,7 @@ SkAlphaType GrBitmapTextureMaker::alphaType() const { return fBitmap.alphaType(); } -sk_sp GrBitmapTextureMaker::getColorSpace(SkDestinationSurfaceColorMode colorMode) { - // Color space doesn't depend on mode - it's just whatever is in the bitmap +sk_sp GrBitmapTextureMaker::getColorSpace(SkColorSpace* dstColorSpace) { + // Color space doesn't depend on destination color space - it's just whatever is in the bitmap return sk_ref_sp(fBitmap.colorSpace()); } diff --git a/src/gpu/GrBitmapTextureMaker.h b/src/gpu/GrBitmapTextureMaker.h index 3314543..abda1d2 100644 --- a/src/gpu/GrBitmapTextureMaker.h +++ b/src/gpu/GrBitmapTextureMaker.h @@ -18,15 +18,15 @@ public: GrBitmapTextureMaker(GrContext* context, const SkBitmap& bitmap); protected: - GrTexture* refOriginalTexture(bool willBeMipped, SkDestinationSurfaceColorMode) override; + GrTexture* refOriginalTexture(bool willBeMipped, SkColorSpace* dstColorSpace) override; void makeCopyKey(const CopyParams& copyParams, GrUniqueKey* copyKey, - SkDestinationSurfaceColorMode colorMode) override; + SkColorSpace* dstColorSpace) override; void didCacheCopy(const GrUniqueKey& copyKey) override; SkAlphaType alphaType() const override; - sk_sp getColorSpace(SkDestinationSurfaceColorMode) override; + sk_sp getColorSpace(SkColorSpace* dstColorSpace) override; private: const SkBitmap fBitmap; diff --git a/src/gpu/GrImageTextureMaker.cpp b/src/gpu/GrImageTextureMaker.cpp index f4a3119..086e40e 100644 --- a/src/gpu/GrImageTextureMaker.cpp +++ b/src/gpu/GrImageTextureMaker.cpp @@ -31,17 +31,16 @@ GrImageTextureMaker::GrImageTextureMaker(GrContext* context, SkImageCacherator* } } -GrTexture* GrImageTextureMaker::refOriginalTexture(bool willBeMipped, - SkDestinationSurfaceColorMode colorMode) { +GrTexture* GrImageTextureMaker::refOriginalTexture(bool willBeMipped, SkColorSpace* dstColorSpace) { return fCacher->lockTexture(this->context(), fOriginalKey, fClient, fCachingHint, willBeMipped, - colorMode); + dstColorSpace); } void GrImageTextureMaker::makeCopyKey(const CopyParams& stretch, GrUniqueKey* paramsCopyKey, - SkDestinationSurfaceColorMode colorMode) { + SkColorSpace* dstColorSpace) { if (fOriginalKey.isValid() && SkImage::kAllow_CachingHint == fCachingHint) { SkImageCacherator::CachedFormat cacheFormat = - fCacher->chooseCacheFormat(colorMode, this->context()->caps()); + fCacher->chooseCacheFormat(dstColorSpace, this->context()->caps()); GrUniqueKey cacheKey; fCacher->makeCacheKeyFromOrigKey(fOriginalKey, cacheFormat, &cacheKey); MakeCopyKeyFromOrigKey(cacheKey, stretch, paramsCopyKey); @@ -57,6 +56,6 @@ void GrImageTextureMaker::didCacheCopy(const GrUniqueKey& copyKey) { SkAlphaType GrImageTextureMaker::alphaType() const { return fCacher->info().alphaType(); } -sk_sp GrImageTextureMaker::getColorSpace(SkDestinationSurfaceColorMode colorMode) { - return fCacher->getColorSpace(this->context(), colorMode); +sk_sp GrImageTextureMaker::getColorSpace(SkColorSpace* dstColorSpace) { + return fCacher->getColorSpace(this->context(), dstColorSpace); } diff --git a/src/gpu/GrImageTextureMaker.h b/src/gpu/GrImageTextureMaker.h index e2f3a5f..e742b90 100644 --- a/src/gpu/GrImageTextureMaker.h +++ b/src/gpu/GrImageTextureMaker.h @@ -25,13 +25,13 @@ protected: // able to efficiently produce a "stretched" texture natively (e.g. picture-backed) // GrTexture* generateTextureForParams(const CopyParams&) override; - GrTexture* refOriginalTexture(bool willBeMipped, SkDestinationSurfaceColorMode) override; + GrTexture* refOriginalTexture(bool willBeMipped, SkColorSpace* dstColorSpace) override; void makeCopyKey(const CopyParams& stretch, GrUniqueKey* paramsCopyKey, - SkDestinationSurfaceColorMode colorMode) override; + SkColorSpace* dstColorSpace) override; void didCacheCopy(const GrUniqueKey& copyKey) override; SkAlphaType alphaType() const override; - sk_sp getColorSpace(SkDestinationSurfaceColorMode) override; + sk_sp getColorSpace(SkColorSpace* dstColorSpace) override; private: SkImageCacherator* fCacher; diff --git a/src/gpu/GrTestUtils.cpp b/src/gpu/GrTestUtils.cpp index 6dfe670..7a3ef59 100644 --- a/src/gpu/GrTestUtils.cpp +++ b/src/gpu/GrTestUtils.cpp @@ -331,9 +331,6 @@ TestAsFPArgs::TestAsFPArgs(GrProcessorTestData* d) { fArgs.fLocalMatrix = nullptr; fArgs.fFilterQuality = kNone_SkFilterQuality; fArgs.fDstColorSpace = fColorSpaceStorage.get(); - fArgs.fColorMode = SkToBool(fArgs.fDstColorSpace) - ? SkDestinationSurfaceColorMode::kGammaAndColorSpaceAware - : SkDestinationSurfaceColorMode::kLegacy; } } // namespace GrTest diff --git a/src/gpu/GrTextureAdjuster.cpp b/src/gpu/GrTextureAdjuster.cpp index 24d050a..7142ab9 100644 --- a/src/gpu/GrTextureAdjuster.cpp +++ b/src/gpu/GrTextureAdjuster.cpp @@ -30,8 +30,8 @@ GrTextureAdjuster::GrTextureAdjuster(GrTexture* original, SkAlphaType alphaType, } void GrTextureAdjuster::makeCopyKey(const CopyParams& params, GrUniqueKey* copyKey, - SkDestinationSurfaceColorMode) { - // Color mode is irrelevant in this case - we already have a texture so we're just sub-setting + SkColorSpace* dstColorSpace) { + // Destination color space is irrelevant - we already have a texture so we're just sub-setting GrUniqueKey baseKey; GrMakeKeyFromImageID(&baseKey, fUniqueID, SkIRect::MakeWH(this->width(), this->height())); MakeCopyKeyFromOrigKey(baseKey, params, copyKey); @@ -46,7 +46,7 @@ GrTexture* GrTextureAdjuster::refCopy(const CopyParams& copyParams) { GrContext* context = texture->getContext(); const SkIRect* contentArea = this->contentAreaOrNull(); GrUniqueKey key; - this->makeCopyKey(copyParams, &key, SkDestinationSurfaceColorMode::kGammaAndColorSpaceAware); + this->makeCopyKey(copyParams, &key, nullptr); if (key.isValid()) { GrTexture* cachedCopy = context->textureProvider()->findAndRefTextureByUniqueKey(key); if (cachedCopy) { @@ -64,7 +64,6 @@ GrTexture* GrTextureAdjuster::refCopy(const CopyParams& copyParams) { } GrTexture* GrTextureAdjuster::refTextureSafeForParams(const GrSamplerParams& params, - SkDestinationSurfaceColorMode colorMode, SkIPoint* outOffset) { GrTexture* texture = this->originalTexture(); GrContext* context = texture->getContext(); @@ -106,8 +105,7 @@ sk_sp GrTextureAdjuster::createFragmentProcessor( FilterConstraint filterConstraint, bool coordsLimitedToConstraintRect, const GrSamplerParams::FilterMode* filterOrNullForBicubic, - SkColorSpace* dstColorSpace, - SkDestinationSurfaceColorMode colorMode) { + SkColorSpace* dstColorSpace) { SkMatrix textureMatrix = origTextureMatrix; const SkIRect* contentArea = this->contentAreaOrNull(); @@ -126,7 +124,7 @@ sk_sp GrTextureAdjuster::createFragmentProcessor( if (filterOrNullForBicubic) { params.setFilterMode(*filterOrNullForBicubic); } - sk_sp texture(this->refTextureSafeForParams(params, colorMode, nullptr)); + sk_sp texture(this->refTextureSafeForParams(params, nullptr)); if (!texture) { return nullptr; } diff --git a/src/gpu/GrTextureAdjuster.h b/src/gpu/GrTextureAdjuster.h index 0e3fe52..e437c80 100644 --- a/src/gpu/GrTextureAdjuster.h +++ b/src/gpu/GrTextureAdjuster.h @@ -23,8 +23,7 @@ public: outOffset will be the top-left corner of the subset if a copy is not made. Otherwise, the copy will be tight to the contents and outOffset will be (0, 0). If the copy's size does not match subset's dimensions then the contents are scaled to fit the copy.*/ - GrTexture* refTextureSafeForParams(const GrSamplerParams&, SkDestinationSurfaceColorMode, - SkIPoint* outOffset); + GrTexture* refTextureSafeForParams(const GrSamplerParams&, SkIPoint* outOffset); sk_sp createFragmentProcessor( const SkMatrix& textureMatrix, @@ -32,8 +31,7 @@ public: FilterConstraint, bool coordsLimitedToConstraintRect, const GrSamplerParams::FilterMode* filterOrNullForBicubic, - SkColorSpace* dstColorSpace, - SkDestinationSurfaceColorMode) override; + SkColorSpace* dstColorSpace) override; // We do not ref the texture nor the colorspace, so the caller must keep them in scope while // this Adjuster is alive. @@ -43,7 +41,7 @@ public: protected: SkAlphaType alphaType() const override { return fAlphaType; } void makeCopyKey(const CopyParams& params, GrUniqueKey* copyKey, - SkDestinationSurfaceColorMode colorMode) override; + SkColorSpace* dstColorSpace) override; void didCacheCopy(const GrUniqueKey& copyKey) override; GrTexture* originalTexture() const { return fOriginal; } diff --git a/src/gpu/GrTextureMaker.cpp b/src/gpu/GrTextureMaker.cpp index d303dcf..7123a66 100644 --- a/src/gpu/GrTextureMaker.cpp +++ b/src/gpu/GrTextureMaker.cpp @@ -11,7 +11,7 @@ #include "GrGpu.h" GrTexture* GrTextureMaker::refTextureForParams(const GrSamplerParams& params, - SkDestinationSurfaceColorMode colorMode, + SkColorSpace* dstColorSpace, sk_sp* texColorSpace) { CopyParams copyParams; bool willBeMipped = params.filterMode() == GrSamplerParams::kMipMap_FilterMode; @@ -21,15 +21,15 @@ GrTexture* GrTextureMaker::refTextureForParams(const GrSamplerParams& params, } if (texColorSpace) { - *texColorSpace = this->getColorSpace(colorMode); + *texColorSpace = this->getColorSpace(dstColorSpace); } if (!fContext->getGpu()->makeCopyForTextureParams(this->width(), this->height(), params, ©Params)) { - return this->refOriginalTexture(willBeMipped, colorMode); + return this->refOriginalTexture(willBeMipped, dstColorSpace); } GrUniqueKey copyKey; - this->makeCopyKey(copyParams, ©Key, colorMode); + this->makeCopyKey(copyParams, ©Key, dstColorSpace); if (copyKey.isValid()) { GrTexture* result = fContext->textureProvider()->findAndRefTextureByUniqueKey(copyKey); if (result) { @@ -37,7 +37,7 @@ GrTexture* GrTextureMaker::refTextureForParams(const GrSamplerParams& params, } } - GrTexture* result = this->generateTextureForParams(copyParams, willBeMipped, colorMode); + GrTexture* result = this->generateTextureForParams(copyParams, willBeMipped, dstColorSpace); if (!result) { return nullptr; } @@ -55,8 +55,7 @@ sk_sp GrTextureMaker::createFragmentProcessor( FilterConstraint filterConstraint, bool coordsLimitedToConstraintRect, const GrSamplerParams::FilterMode* filterOrNullForBicubic, - SkColorSpace* dstColorSpace, - SkDestinationSurfaceColorMode colorMode) { + SkColorSpace* dstColorSpace) { const GrSamplerParams::FilterMode* fmForDetermineDomain = filterOrNullForBicubic; if (filterOrNullForBicubic && GrSamplerParams::kMipMap_FilterMode == *filterOrNullForBicubic && @@ -78,7 +77,7 @@ sk_sp GrTextureMaker::createFragmentProcessor( params.reset(SkShader::kClamp_TileMode, GrSamplerParams::kNone_FilterMode); } sk_sp texColorSpace; - sk_sp texture(this->refTextureForParams(params, colorMode, &texColorSpace)); + sk_sp texture(this->refTextureForParams(params, dstColorSpace, &texColorSpace)); if (!texture) { return nullptr; } @@ -98,8 +97,8 @@ sk_sp GrTextureMaker::createFragmentProcessor( } GrTexture* GrTextureMaker::generateTextureForParams(const CopyParams& copyParams, bool willBeMipped, - SkDestinationSurfaceColorMode colorMode) { - sk_sp original(this->refOriginalTexture(willBeMipped, colorMode)); + SkColorSpace* dstColorSpace) { + sk_sp original(this->refOriginalTexture(willBeMipped, dstColorSpace)); if (!original) { return nullptr; } diff --git a/src/gpu/GrTextureMaker.h b/src/gpu/GrTextureMaker.h index 8c00e21..0ea5f6d 100644 --- a/src/gpu/GrTextureMaker.h +++ b/src/gpu/GrTextureMaker.h @@ -21,7 +21,7 @@ public: * does not match width()/height() then the contents of the original must be scaled to fit * the texture. Places the color space of the texture in (*texColorSpace). */ - GrTexture* refTextureForParams(const GrSamplerParams&, SkDestinationSurfaceColorMode, + GrTexture* refTextureForParams(const GrSamplerParams&, SkColorSpace* dstColorSpace, sk_sp* texColorSpace); sk_sp createFragmentProcessor( @@ -30,8 +30,7 @@ public: FilterConstraint filterConstraint, bool coordsLimitedToConstraintRect, const GrSamplerParams::FilterMode* filterOrNullForBicubic, - SkColorSpace* dstColorSpace, - SkDestinationSurfaceColorMode) override; + SkColorSpace* dstColorSpace) override; protected: GrTextureMaker(GrContext* context, int width, int height, bool isAlphaOnly) @@ -42,13 +41,13 @@ protected: * Return the maker's "original" texture. It is the responsibility of the maker to handle any * caching of the original if desired. */ - virtual GrTexture* refOriginalTexture(bool willBeMipped, SkDestinationSurfaceColorMode) = 0; + virtual GrTexture* refOriginalTexture(bool willBeMipped, SkColorSpace* dstColorSpace) = 0; /** * Returns the color space of the maker's "original" texture, assuming it was retrieved with - * the same destination color mode. + * the same destination color space. */ - virtual sk_sp getColorSpace(SkDestinationSurfaceColorMode) = 0; + virtual sk_sp getColorSpace(SkColorSpace* dstColorSpace) = 0; /** * Return a new (uncached) texture that is the stretch of the maker's original. @@ -61,7 +60,7 @@ protected: * by copying. */ virtual GrTexture* generateTextureForParams(const CopyParams&, bool willBeMipped, - SkDestinationSurfaceColorMode); + SkColorSpace* dstColorSpace); GrContext* context() const { return fContext; } diff --git a/src/gpu/GrTextureProducer.h b/src/gpu/GrTextureProducer.h index 4cae933..2284cb4 100644 --- a/src/gpu/GrTextureProducer.h +++ b/src/gpu/GrTextureProducer.h @@ -61,8 +61,7 @@ public: FilterConstraint filterConstraint, bool coordsLimitedToConstraintRect, const GrSamplerParams::FilterMode* filterOrNullForBicubic, - SkColorSpace* dstColorSpace, - SkDestinationSurfaceColorMode) = 0; + SkColorSpace* dstColorSpace) = 0; virtual ~GrTextureProducer() {} @@ -96,10 +95,11 @@ protected: * return a key that identifies its original content + the CopyParms parameter. If the producer * does not want to cache the stretched version (e.g. the producer is volatile), this should * simply return without initializing the copyKey. If the texture generated by this producer - * depends on colorMode, then that information should also be incorporated in the key. + * depends on the destination color space, then that information should also be incorporated + * in the key. */ virtual void makeCopyKey(const CopyParams&, GrUniqueKey* copyKey, - SkDestinationSurfaceColorMode colorMode) = 0; + SkColorSpace* dstColorSpace) = 0; /** * If a stretched version of the texture is generated, it may be cached (assuming that diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp index 4e91f4a..1b4c56e 100644 --- a/src/gpu/SkGpuDevice.cpp +++ b/src/gpu/SkGpuDevice.cpp @@ -1039,8 +1039,7 @@ void SkGpuDevice::drawBitmapTile(const SkBitmap& bitmap, SkASSERT(bitmap.width() <= fContext->caps()->maxTileSize() && bitmap.height() <= fContext->caps()->maxTileSize()); - sk_sp texture = GrMakeCachedBitmapTexture( - fContext.get(), bitmap, params, fRenderTargetContext->colorMode()); + sk_sp texture = GrMakeCachedBitmapTexture(fContext.get(), bitmap, params); if (nullptr == texture) { return; } @@ -1119,8 +1118,7 @@ void SkGpuDevice::drawSprite(const SkDraw& draw, const SkBitmap& bitmap, // draw sprite neither filters nor tiles. texture.reset( - GrRefCachedBitmapTexture(fContext.get(), bitmap, GrSamplerParams::ClampNoFilter(), - SkDestinationSurfaceColorMode::kGammaAndColorSpaceAware)); + GrRefCachedBitmapTexture(fContext.get(), bitmap, GrSamplerParams::ClampNoFilter())); if (!texture) { return; } @@ -1290,8 +1288,7 @@ sk_sp SkGpuDevice::makeSpecial(const SkBitmap& bitmap) { } sk_sp texture = - GrMakeCachedBitmapTexture(fContext.get(), bitmap, GrSamplerParams::ClampNoFilter(), - SkDestinationSurfaceColorMode::kGammaAndColorSpaceAware); + GrMakeCachedBitmapTexture(fContext.get(), bitmap, GrSamplerParams::ClampNoFilter()); if (!texture) { return nullptr; } @@ -1389,7 +1386,7 @@ void SkGpuDevice::drawImage(const SkDraw& draw, const SkImage* image, SkScalar x if (this->shouldTileImage(image, nullptr, SkCanvas::kFast_SrcRectConstraint, paint.getFilterQuality(), *draw.fMatrix, SkMatrix::I())) { // only support tiling as bitmap at the moment, so force raster-version - if (!as_IB(image)->getROPixels(&bm, fRenderTargetContext->colorMode())) { + if (!as_IB(image)->getROPixels(&bm, fRenderTargetContext->getColorSpace())) { return; } this->drawBitmap(draw, bm, SkMatrix::MakeTrans(x, y), paint); @@ -1398,7 +1395,7 @@ void SkGpuDevice::drawImage(const SkDraw& draw, const SkImage* image, SkScalar x GrImageTextureMaker maker(fContext.get(), cacher, image, SkImage::kAllow_CachingHint); this->drawTextureProducer(&maker, nullptr, nullptr, SkCanvas::kFast_SrcRectConstraint, viewMatrix, fClip, paint); - } else if (as_IB(image)->getROPixels(&bm, fRenderTargetContext->colorMode())) { + } else if (as_IB(image)->getROPixels(&bm, fRenderTargetContext->getColorSpace())) { this->drawBitmap(draw, bm, SkMatrix::MakeTrans(x, y), paint); } } @@ -1423,7 +1420,7 @@ void SkGpuDevice::drawImageRect(const SkDraw& draw, const SkImage* image, const if (this->shouldTileImage(image, src, constraint, paint.getFilterQuality(), *draw.fMatrix, srcToDstRect)) { // only support tiling as bitmap at the moment, so force raster-version - if (!as_IB(image)->getROPixels(&bm, fRenderTargetContext->colorMode())) { + if (!as_IB(image)->getROPixels(&bm, fRenderTargetContext->getColorSpace())) { return; } this->drawBitmapRect(draw, bm, src, dst, paint, constraint); @@ -1431,7 +1428,7 @@ void SkGpuDevice::drawImageRect(const SkDraw& draw, const SkImage* image, const CHECK_SHOULD_DRAW(draw); GrImageTextureMaker maker(fContext.get(), cacher, image, SkImage::kAllow_CachingHint); this->drawTextureProducer(&maker, src, &dst, constraint, *draw.fMatrix, fClip, paint); - } else if (as_IB(image)->getROPixels(&bm, fRenderTargetContext->colorMode())) { + } else if (as_IB(image)->getROPixels(&bm, fRenderTargetContext->getColorSpace())) { this->drawBitmapRect(draw, bm, src, dst, paint, constraint); } } @@ -1464,8 +1461,7 @@ void SkGpuDevice::drawProducerNine(const SkDraw& draw, GrTextureProducer* produc producer->createFragmentProcessor(SkMatrix::I(), SkRect::MakeIWH(producer->width(), producer->height()), GrTextureProducer::kNo_FilterConstraint, true, - &kMode, fRenderTargetContext->getColorSpace(), - fRenderTargetContext->colorMode())); + &kMode, fRenderTargetContext->getColorSpace())); GrPaint grPaint; if (!SkPaintToGrPaintWithTexture(this->context(), fRenderTargetContext.get(), paint, *draw.fMatrix, std::move(fp), producer->isAlphaOnly(), @@ -1493,7 +1489,7 @@ void SkGpuDevice::drawImageNine(const SkDraw& draw, const SkImage* image, if (SkImageCacherator* cacher = as_IB(image)->peekCacherator()) { GrImageTextureMaker maker(fContext.get(), cacher, image, SkImage::kAllow_CachingHint); this->drawProducerNine(draw, &maker, center, dst, paint); - } else if (as_IB(image)->getROPixels(&bm, fRenderTargetContext->colorMode())) { + } else if (as_IB(image)->getROPixels(&bm, fRenderTargetContext->getColorSpace())) { this->drawBitmapNine(draw, bm, center, dst, paint); } } @@ -1518,8 +1514,7 @@ void SkGpuDevice::drawProducerLattice(const SkDraw& draw, GrTextureProducer* pro producer->createFragmentProcessor(SkMatrix::I(), SkRect::MakeIWH(producer->width(), producer->height()), GrTextureProducer::kNo_FilterConstraint, true, - &kMode, fRenderTargetContext->getColorSpace(), - fRenderTargetContext->colorMode())); + &kMode, fRenderTargetContext->getColorSpace())); GrPaint grPaint; if (!SkPaintToGrPaintWithTexture(this->context(), fRenderTargetContext.get(), paint, *draw.fMatrix, std::move(fp), producer->isAlphaOnly(), @@ -1548,7 +1543,7 @@ void SkGpuDevice::drawImageLattice(const SkDraw& draw, const SkImage* image, if (SkImageCacherator* cacher = as_IB(image)->peekCacherator()) { GrImageTextureMaker maker(fContext.get(), cacher, image, SkImage::kAllow_CachingHint); this->drawProducerLattice(draw, &maker, lattice, dst, paint); - } else if (as_IB(image)->getROPixels(&bm, fRenderTargetContext->colorMode())) { + } else if (as_IB(image)->getROPixels(&bm, fRenderTargetContext->getColorSpace())) { this->drawBitmapLattice(draw, bm, lattice, dst, paint); } } diff --git a/src/gpu/SkGpuDevice_drawTexture.cpp b/src/gpu/SkGpuDevice_drawTexture.cpp index 93c9f18..6501fca 100644 --- a/src/gpu/SkGpuDevice_drawTexture.cpp +++ b/src/gpu/SkGpuDevice_drawTexture.cpp @@ -203,7 +203,7 @@ void SkGpuDevice::drawTextureProducerImpl(GrTextureProducer* producer, } sk_sp fp(producer->createFragmentProcessor( *textureMatrix, clippedSrcRect, constraintMode, coordsAllInsideSrcRect, filterMode, - fRenderTargetContext->getColorSpace(), fRenderTargetContext->colorMode())); + fRenderTargetContext->getColorSpace())); if (!fp) { return; } diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp index 6ce9cae..4e04601 100644 --- a/src/gpu/SkGr.cpp +++ b/src/gpu/SkGr.cpp @@ -319,8 +319,12 @@ void GrInstallBitmapUniqueKeyInvalidator(const GrUniqueKey& key, SkPixelRef* pix } GrTexture* GrGenerateMipMapsAndUploadToTexture(GrContext* ctx, const SkBitmap& bitmap, - SkDestinationSurfaceColorMode colorMode) + SkColorSpace* dstColorSpace) { + SkDestinationSurfaceColorMode colorMode = dstColorSpace + ? SkDestinationSurfaceColorMode::kGammaAndColorSpaceAware + : SkDestinationSurfaceColorMode::kLegacy; + GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(bitmap.info(), *ctx->caps()); sk_sp texture(create_texture_from_yuv(ctx, bitmap, desc)); if (texture) { @@ -397,17 +401,15 @@ GrTexture* GrUploadMipMapToTexture(GrContext* ctx, const SkImageInfo& info, } GrTexture* GrRefCachedBitmapTexture(GrContext* ctx, const SkBitmap& bitmap, - const GrSamplerParams& params, - SkDestinationSurfaceColorMode colorMode) { + const GrSamplerParams& params) { // Caller doesn't care about the texture's color space (they can always get it from the bitmap) - return GrBitmapTextureMaker(ctx, bitmap).refTextureForParams(params, colorMode, nullptr); + return GrBitmapTextureMaker(ctx, bitmap).refTextureForParams(params, nullptr, nullptr); } sk_sp GrMakeCachedBitmapTexture(GrContext* ctx, const SkBitmap& bitmap, - const GrSamplerParams& params, - SkDestinationSurfaceColorMode colorMode) { + const GrSamplerParams& params) { // Caller doesn't care about the texture's color space (they can always get it from the bitmap) - GrTexture* tex = GrBitmapTextureMaker(ctx, bitmap).refTextureForParams(params, colorMode, + GrTexture* tex = GrBitmapTextureMaker(ctx, bitmap).refTextureForParams(params, nullptr, nullptr); return sk_sp(tex); } @@ -574,8 +576,7 @@ static inline bool skpaint_to_grpaint_impl(GrContext* context, } else if (const SkShader* shader = skPaint.getShader()) { shaderFP = shader->asFragmentProcessor(SkShader::AsFPArgs(context, &viewM, nullptr, skPaint.getFilterQuality(), - rtc->getColorSpace(), - rtc->colorMode())); + rtc->getColorSpace())); if (!shaderFP) { return false; } @@ -762,8 +763,7 @@ bool SkPaintToGrPaintWithTexture(GrContext* context, &viewM, nullptr, paint.getFilterQuality(), - rtc->getColorSpace(), - rtc->colorMode())); + rtc->getColorSpace())); if (!shaderFP) { return false; } diff --git a/src/gpu/SkGrPriv.h b/src/gpu/SkGrPriv.h index 44ff8e7..c64646b 100644 --- a/src/gpu/SkGrPriv.h +++ b/src/gpu/SkGrPriv.h @@ -131,7 +131,7 @@ GrPixelConfig GrIsCompressedTextureDataSupported(GrContext* ctx, SkData* data, GrTexture* GrUploadBitmapToTexture(GrContext*, const SkBitmap&); GrTexture* GrGenerateMipMapsAndUploadToTexture(GrContext*, const SkBitmap&, - SkDestinationSurfaceColorMode); + SkColorSpace* dstColorSpace); /** * Creates a new texture for the pixmap. diff --git a/src/image/SkImage.cpp b/src/image/SkImage.cpp index baabd56..21523fd 100644 --- a/src/image/SkImage.cpp +++ b/src/image/SkImage.cpp @@ -66,11 +66,8 @@ bool SkImage::scalePixels(const SkPixmap& dst, SkFilterQuality quality, CachingH // Idea: If/when SkImageGenerator supports a native-scaling API (where the generator itself // can scale more efficiently) we should take advantage of it here. // - SkDestinationSurfaceColorMode decodeColorMode = dst.info().colorSpace() - ? SkDestinationSurfaceColorMode::kGammaAndColorSpaceAware - : SkDestinationSurfaceColorMode::kLegacy; SkBitmap bm; - if (as_IB(this)->getROPixels(&bm, decodeColorMode, chint)) { + if (as_IB(this)->getROPixels(&bm, dst.info().colorSpace(), chint)) { bm.lockPixels(); SkPixmap pmap; // Note: By calling the pixmap scaler, we never cache the final result, so the chint @@ -87,7 +84,8 @@ void SkImage::preroll(GrContext* ctx) const { // to produce a cached raster-bitmap form, so that drawing to a raster canvas should be fast. // SkBitmap bm; - if (as_IB(this)->getROPixels(&bm, SkDestinationSurfaceColorMode::kLegacy)) { + SkColorSpace* legacyColorSpace = nullptr; + if (as_IB(this)->getROPixels(&bm, legacyColorSpace)) { bm.lockPixels(); bm.unlockPixels(); } @@ -109,7 +107,8 @@ SkData* SkImage::encode(SkEncodedImageFormat type, int quality) const { // TODO: Right now, the encoders don't handle F16 or linearly premultiplied data. Once they do, // we should decode in "color space aware" mode, then re-encode that. For now, work around this // by asking for a legacy decode (which gives us the raw data in N32). - if (as_IB(this)->getROPixels(&bm, SkDestinationSurfaceColorMode::kLegacy)) { + SkColorSpace* legacyColorSpace = nullptr; + if (as_IB(this)->getROPixels(&bm, legacyColorSpace)) { SkDynamicMemoryWStream buf; return SkEncodeImage(&buf, bm, type, quality) ? buf.detachAsData().release() : nullptr; } @@ -128,7 +127,8 @@ SkData* SkImage::encode(SkPixelSerializer* serializer) const { // TODO: Right now, the encoders don't handle F16 or linearly premultiplied data. Once they do, // we should decode in "color space aware" mode, then re-encode that. For now, work around this // by asking for a legacy decode (which gives us the raw data in N32). - if (as_IB(this)->getROPixels(&bm, SkDestinationSurfaceColorMode::kLegacy) && + SkColorSpace* legacyColorSpace = nullptr; + if (as_IB(this)->getROPixels(&bm, legacyColorSpace) && bm.requestLock(&apu)) { if (serializer) { return serializer->encode(apu.pixmap()); @@ -327,11 +327,8 @@ sk_sp SkImage::makeWithFilter(const SkImageFilter* filter, const SkIRec return nullptr; } SkColorSpace* colorSpace = as_IB(this)->onImageInfo().colorSpace(); - SkDestinationSurfaceColorMode decodeColorMode = colorSpace - ? SkDestinationSurfaceColorMode::kGammaAndColorSpaceAware - : SkDestinationSurfaceColorMode::kLegacy; sk_sp srcSpecialImage = SkSpecialImage::MakeFromImage( - subset, sk_ref_sp(const_cast(this)), decodeColorMode); + subset, sk_ref_sp(const_cast(this)), colorSpace); if (!srcSpecialImage) { return nullptr; } diff --git a/src/image/SkImageShader.cpp b/src/image/SkImageShader.cpp index 719bced..528c572 100644 --- a/src/image/SkImageShader.cpp +++ b/src/image/SkImageShader.cpp @@ -54,11 +54,8 @@ size_t SkImageShader::onContextSize(const ContextRec& rec) const { } SkShader::Context* SkImageShader::onCreateContext(const ContextRec& rec, void* storage) const { - // TODO: This is wrong. We should be plumbing destination color space to context creation, - // and use that to determine the decoding mode of the image. - SkDestinationSurfaceColorMode decodeColorMode = SkMipMap::DeduceColorMode(rec); return SkBitmapProcLegacyShader::MakeContext(*this, fTileModeX, fTileModeY, - SkBitmapProvider(fImage.get(), decodeColorMode), + SkBitmapProvider(fImage.get(), rec.fDstColorSpace), rec, storage); } @@ -218,7 +215,7 @@ sk_sp SkImageShader::asFragmentProcessor(const AsFPArgs& ar &doBicubic); GrSamplerParams params(tm, textureFilterMode); sk_sp texColorSpace; - sk_sp texture(as_IB(fImage)->asTextureRef(args.fContext, params, args.fColorMode, + sk_sp texture(as_IB(fImage)->asTextureRef(args.fContext, params, args.fDstColorSpace, &texColorSpace)); if (!texture) { return nullptr; @@ -281,9 +278,7 @@ bool SkImageShader::onAppendStages(SkRasterPipeline* p, SkColorSpace* dst, SkFal } auto quality = paint.getFilterQuality(); - auto mode = (dst == nullptr) ? SkDestinationSurfaceColorMode::kLegacy - : SkDestinationSurfaceColorMode::kGammaAndColorSpaceAware; - SkBitmapProvider provider(fImage.get(), mode); + SkBitmapProvider provider(fImage.get(), dst); SkDefaultBitmapController controller; std::unique_ptr state { controller.requestBitmap(provider, matrix, quality) diff --git a/src/image/SkImage_Base.h b/src/image/SkImage_Base.h index c955d49..ebb38d4 100644 --- a/src/image/SkImage_Base.h +++ b/src/image/SkImage_Base.h @@ -52,12 +52,12 @@ public: // return a read-only copy of the pixels. We promise to not modify them, // but only inspect them (or encode them). - virtual bool getROPixels(SkBitmap*, SkDestinationSurfaceColorMode, + virtual bool getROPixels(SkBitmap*, SkColorSpace* dstColorSpace, CachingHint = kAllow_CachingHint) const = 0; // Caller must call unref when they are done. - virtual GrTexture* asTextureRef(GrContext*, const GrSamplerParams&, - SkDestinationSurfaceColorMode, sk_sp*) const = 0; + virtual GrTexture* asTextureRef(GrContext*, const GrSamplerParams&, SkColorSpace*, + sk_sp*) const = 0; virtual sk_sp onMakeSubset(const SkIRect&) const = 0; diff --git a/src/image/SkImage_Generator.cpp b/src/image/SkImage_Generator.cpp index efee134..45f04e4 100644 --- a/src/image/SkImage_Generator.cpp +++ b/src/image/SkImage_Generator.cpp @@ -30,9 +30,9 @@ public: SkImageCacherator* peekCacherator() const override { return &fCache; } SkData* onRefEncoded(GrContext*) const override; sk_sp onMakeSubset(const SkIRect&) const override; - bool getROPixels(SkBitmap*, SkDestinationSurfaceColorMode, CachingHint) const override; - GrTexture* asTextureRef(GrContext*, const GrSamplerParams&, - SkDestinationSurfaceColorMode, sk_sp*) const override; + bool getROPixels(SkBitmap*, SkColorSpace* dstColorSpace, CachingHint) const override; + GrTexture* asTextureRef(GrContext*, const GrSamplerParams&, SkColorSpace*, + sk_sp*) const override; bool onIsLazyGenerated() const override { return true; } private: @@ -45,12 +45,10 @@ private: bool SkImage_Generator::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRB, int srcX, int srcY, CachingHint chint) const { - SkDestinationSurfaceColorMode decodeColorMode = dstInfo.colorSpace() - ? SkDestinationSurfaceColorMode::kGammaAndColorSpaceAware - : SkDestinationSurfaceColorMode::kLegacy; + SkColorSpace* dstColorSpace = dstInfo.colorSpace(); SkBitmap bm; if (kDisallow_CachingHint == chint) { - SkImageCacherator::CachedFormat cacheFormat = fCache.chooseCacheFormat(decodeColorMode); + SkImageCacherator::CachedFormat cacheFormat = fCache.chooseCacheFormat(dstColorSpace); if (fCache.lockAsBitmapOnlyIfAlreadyCached(&bm, cacheFormat)) { return bm.readPixels(dstInfo, dstPixels, dstRB, srcX, srcY); } else { @@ -64,7 +62,7 @@ bool SkImage_Generator::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels } } - if (this->getROPixels(&bm, decodeColorMode, chint)) { + if (this->getROPixels(&bm, dstColorSpace, chint)) { return bm.readPixels(dstInfo, dstPixels, dstRB, srcX, srcY); } return false; @@ -74,15 +72,15 @@ SkData* SkImage_Generator::onRefEncoded(GrContext* ctx) const { return fCache.refEncoded(ctx); } -bool SkImage_Generator::getROPixels(SkBitmap* bitmap, SkDestinationSurfaceColorMode colorMode, +bool SkImage_Generator::getROPixels(SkBitmap* bitmap, SkColorSpace* dstColorSpace, CachingHint chint) const { - return fCache.lockAsBitmap(bitmap, this, colorMode, chint); + return fCache.lockAsBitmap(bitmap, this, dstColorSpace, chint); } GrTexture* SkImage_Generator::asTextureRef(GrContext* ctx, const GrSamplerParams& params, - SkDestinationSurfaceColorMode colorMode, + SkColorSpace* dstColorSpace, sk_sp* texColorSpace) const { - return fCache.lockAsTexture(ctx, params, colorMode, texColorSpace, this); + return fCache.lockAsTexture(ctx, params, dstColorSpace, texColorSpace, this); } sk_sp SkImage_Generator::onMakeSubset(const SkIRect& subset) const { diff --git a/src/image/SkImage_Gpu.cpp b/src/image/SkImage_Gpu.cpp index 24e5c1d..ffd3ae0 100644 --- a/src/image/SkImage_Gpu.cpp +++ b/src/image/SkImage_Gpu.cpp @@ -63,7 +63,7 @@ static SkImageInfo make_info(int w, int h, SkAlphaType at, sk_sp c return SkImageInfo::MakeN32(w, h, at, std::move(colorSpace)); } -bool SkImage_Gpu::getROPixels(SkBitmap* dst, SkDestinationSurfaceColorMode, +bool SkImage_Gpu::getROPixels(SkBitmap* dst, SkColorSpace* dstColorSpace, CachingHint chint) const { if (SkBitmapCache::Find(this->uniqueID(), dst)) { SkASSERT(dst->getGenerationID() == this->uniqueID()); @@ -90,14 +90,14 @@ bool SkImage_Gpu::getROPixels(SkBitmap* dst, SkDestinationSurfaceColorMode, } GrTexture* SkImage_Gpu::asTextureRef(GrContext* ctx, const GrSamplerParams& params, - SkDestinationSurfaceColorMode colorMode, + SkColorSpace* dstColorSpace, sk_sp* texColorSpace) const { if (texColorSpace) { *texColorSpace = this->fColorSpace; } GrTextureAdjuster adjuster(this->peekTexture(), this->alphaType(), this->bounds(), this->uniqueID(), this->fColorSpace.get()); - return adjuster.refTextureSafeForParams(params, colorMode, nullptr); + return adjuster.refTextureSafeForParams(params, nullptr); } static void apply_premul(const SkImageInfo& info, void* pixels, size_t rowBytes) { @@ -463,11 +463,8 @@ size_t SkImage::getDeferredTextureImageData(const GrContextThreadSafeProxy& prox } if (SkImageCacherator* cacher = as_IB(this)->peekCacherator()) { // Generator backed image. Tweak info to trigger correct kind of decode. - SkDestinationSurfaceColorMode decodeColorMode = dstColorSpace - ? SkDestinationSurfaceColorMode::kGammaAndColorSpaceAware - : SkDestinationSurfaceColorMode::kLegacy; SkImageCacherator::CachedFormat cacheFormat = cacher->chooseCacheFormat( - decodeColorMode, proxy.fCaps.get()); + dstColorSpace, proxy.fCaps.get()); info = cacher->buildCacheInfo(cacheFormat).makeWH(scaledSize.width(), scaledSize.height()); diff --git a/src/image/SkImage_Gpu.h b/src/image/SkImage_Gpu.h index dcde00a..2098864 100644 --- a/src/image/SkImage_Gpu.h +++ b/src/image/SkImage_Gpu.h @@ -38,9 +38,9 @@ public: } } - bool getROPixels(SkBitmap*, SkDestinationSurfaceColorMode, CachingHint) const override; - GrTexture* asTextureRef(GrContext* ctx, const GrSamplerParams& params, - SkDestinationSurfaceColorMode, sk_sp*) const override; + bool getROPixels(SkBitmap*, SkColorSpace* dstColorSpace, CachingHint) const override; + GrTexture* asTextureRef(GrContext* ctx, const GrSamplerParams& params, SkColorSpace*, + sk_sp*) const override; sk_sp onMakeSubset(const SkIRect&) const override; GrTexture* peekTexture() const override { return fTexture.get(); } diff --git a/src/image/SkImage_Raster.cpp b/src/image/SkImage_Raster.cpp index b781665..b14a06e 100644 --- a/src/image/SkImage_Raster.cpp +++ b/src/image/SkImage_Raster.cpp @@ -87,9 +87,9 @@ public: bool onPeekPixels(SkPixmap*) const override; const SkBitmap* onPeekBitmap() const override { return &fBitmap; } - bool getROPixels(SkBitmap*, SkDestinationSurfaceColorMode, CachingHint) const override; - GrTexture* asTextureRef(GrContext*, const GrSamplerParams&, - SkDestinationSurfaceColorMode, sk_sp*) const override; + bool getROPixels(SkBitmap*, SkColorSpace* dstColorSpace, CachingHint) const override; + GrTexture* asTextureRef(GrContext*, const GrSamplerParams&, SkColorSpace*, + sk_sp*) const override; sk_sp onMakeSubset(const SkIRect&) const override; // exposed for SkSurface_Raster via SkNewImageFromPixelRef @@ -179,13 +179,13 @@ bool SkImage_Raster::onPeekPixels(SkPixmap* pm) const { return fBitmap.peekPixels(pm); } -bool SkImage_Raster::getROPixels(SkBitmap* dst, SkDestinationSurfaceColorMode, CachingHint) const { +bool SkImage_Raster::getROPixels(SkBitmap* dst, SkColorSpace* dstColorSpace, CachingHint) const { *dst = fBitmap; return true; } GrTexture* SkImage_Raster::asTextureRef(GrContext* ctx, const GrSamplerParams& params, - SkDestinationSurfaceColorMode colorMode, + SkColorSpace* dstColorSpace, sk_sp* texColorSpace) const { #if SK_SUPPORT_GPU if (!ctx) { @@ -201,10 +201,10 @@ GrTexture* SkImage_Raster::asTextureRef(GrContext* ctx, const GrSamplerParams& p if (tex) { GrTextureAdjuster adjuster(fPinnedTexture.get(), fBitmap.alphaType(), fBitmap.bounds(), fPinnedUniqueID, fBitmap.colorSpace()); - return adjuster.refTextureSafeForParams(params, colorMode, nullptr); + return adjuster.refTextureSafeForParams(params, nullptr); } - return GrRefCachedBitmapTexture(ctx, fBitmap, params, colorMode); + return GrRefCachedBitmapTexture(ctx, fBitmap, params); #endif return nullptr; @@ -231,8 +231,7 @@ bool SkImage_Raster::onPinAsTexture(GrContext* ctx) const { SkASSERT(fPinnedCount == 0); SkASSERT(fPinnedUniqueID == 0); fPinnedTexture.reset( - GrRefCachedBitmapTexture(ctx, fBitmap, GrSamplerParams::ClampNoFilter(), - SkDestinationSurfaceColorMode::kGammaAndColorSpaceAware)); + GrRefCachedBitmapTexture(ctx, fBitmap, GrSamplerParams::ClampNoFilter())); if (!fPinnedTexture) { return false; } diff --git a/src/pdf/SkPDFBitmap.cpp b/src/pdf/SkPDFBitmap.cpp index ea6887a..511fca8 100644 --- a/src/pdf/SkPDFBitmap.cpp +++ b/src/pdf/SkPDFBitmap.cpp @@ -17,7 +17,8 @@ #include "SkUnPreMultiply.h" void image_get_ro_pixels(const SkImage* image, SkBitmap* dst) { - if(as_IB(image)->getROPixels(dst, SkDestinationSurfaceColorMode::kLegacy) + SkColorSpace* legacyColorSpace = nullptr; + if(as_IB(image)->getROPixels(dst, legacyColorSpace) && dst->dimensions() == image->dimensions()) { if (dst->colorType() != kIndex_8_SkColorType) { return; @@ -502,7 +503,8 @@ sk_sp SkPDFCreateBitmapObject(sk_sp image, if (pixelSerializer) { SkBitmap bm; SkAutoPixmapUnlock apu; - if (as_IB(image.get())->getROPixels(&bm, SkDestinationSurfaceColorMode::kLegacy) && + SkColorSpace* legacyColorSpace = nullptr; + if (as_IB(image.get())->getROPixels(&bm, legacyColorSpace) && bm.requestLock(&apu)) { data.reset(pixelSerializer->encode(apu.pixmap())); if (data && SkIsJFIF(data.get(), &info)) { diff --git a/src/pdf/SkPDFDevice.cpp b/src/pdf/SkPDFDevice.cpp index 7d7196b..5724b1a 100644 --- a/src/pdf/SkPDFDevice.cpp +++ b/src/pdf/SkPDFDevice.cpp @@ -2318,9 +2318,9 @@ sk_sp SkPDFDevice::makeSpecial(const SkImage* image) { // TODO: See comment above in drawSpecial. The color mode we use for decode should be driven // by the destination where we're going to draw thing thing (ie this device). But we don't have // a color space, so we always decode in legacy mode for now. + SkColorSpace* legacyColorSpace = nullptr; return SkSpecialImage::MakeFromImage(SkIRect::MakeWH(image->width(), image->height()), - image->makeNonTextureImage(), - SkDestinationSurfaceColorMode::kLegacy); + image->makeNonTextureImage(), legacyColorSpace); } sk_sp SkPDFDevice::snapSpecial() { diff --git a/tests/ImageFilterCacheTest.cpp b/tests/ImageFilterCacheTest.cpp index e3a652b..e0aceda 100644 --- a/tests/ImageFilterCacheTest.cpp +++ b/tests/ImageFilterCacheTest.cpp @@ -154,14 +154,14 @@ DEF_TEST(ImageFilterCache_RasterBacked, reporter) { // Shared test code for both the raster and gpu-backed image cases static void test_image_backed(skiatest::Reporter* reporter, const sk_sp& srcImage) { const SkIRect& full = SkIRect::MakeWH(kFullSize, kFullSize); + SkColorSpace* legacyColorSpace = nullptr; - sk_sp fullImg( - SkSpecialImage::MakeFromImage(full, srcImage, SkDestinationSurfaceColorMode::kLegacy)); + sk_sp fullImg(SkSpecialImage::MakeFromImage(full, srcImage, legacyColorSpace)); const SkIRect& subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmallerSize); - sk_sp subsetImg( - SkSpecialImage::MakeFromImage(subset, srcImage, SkDestinationSurfaceColorMode::kLegacy)); + sk_sp subsetImg(SkSpecialImage::MakeFromImage(subset, srcImage, + legacyColorSpace)); test_find_existing(reporter, fullImg, subsetImg); test_dont_find_if_diff_key(reporter, fullImg, subsetImg); diff --git a/tests/SkBlend_optsTest.cpp b/tests/SkBlend_optsTest.cpp index 2ae179c..554818a 100644 --- a/tests/SkBlend_optsTest.cpp +++ b/tests/SkBlend_optsTest.cpp @@ -52,7 +52,8 @@ static void test_blender(std::string resourceName, skiatest::Reporter* reporter) return; } SkBitmap bm; - if (!as_IB(image)->getROPixels(&bm, SkDestinationSurfaceColorMode::kGammaAndColorSpaceAware)) { + sk_sp srgbColorSpace = SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named); + if (!as_IB(image)->getROPixels(&bm, srgbColorSpace.get())) { ERRORF(reporter, "Could not read resource"); return; } diff --git a/tests/SpecialImageTest.cpp b/tests/SpecialImageTest.cpp index 8cd874a..b0915f0 100644 --- a/tests/SpecialImageTest.cpp +++ b/tests/SpecialImageTest.cpp @@ -155,20 +155,20 @@ DEF_TEST(SpecialImage_Raster, reporter) { } } -static void test_specialimage_image(skiatest::Reporter* reporter, - SkDestinationSurfaceColorMode colorMode) { +static void test_specialimage_image(skiatest::Reporter* reporter, SkColorSpace* dstColorSpace) { SkBitmap bm = create_bm(); sk_sp fullImage(SkImage::MakeFromBitmap(bm)); sk_sp fullSImage(SkSpecialImage::MakeFromImage( SkIRect::MakeWH(kFullSize, kFullSize), - fullImage, colorMode)); + fullImage, dstColorSpace)); const SkIRect& subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmallerSize); { - sk_sp subSImg1(SkSpecialImage::MakeFromImage(subset, fullImage, colorMode)); + sk_sp subSImg1(SkSpecialImage::MakeFromImage(subset, fullImage, + dstColorSpace)); test_image(subSImg1, reporter, nullptr, false, kPad, kFullSize); } @@ -179,11 +179,13 @@ static void test_specialimage_image(skiatest::Reporter* reporter, } DEF_TEST(SpecialImage_Image_Legacy, reporter) { - test_specialimage_image(reporter, SkDestinationSurfaceColorMode::kLegacy); + SkColorSpace* legacyColorSpace = nullptr; + test_specialimage_image(reporter, legacyColorSpace); } DEF_TEST(SpecialImage_Image_ColorSpaceAware, reporter) { - test_specialimage_image(reporter, SkDestinationSurfaceColorMode::kGammaAndColorSpaceAware); + sk_sp srgbColorSpace = SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named); + test_specialimage_image(reporter, srgbColorSpace.get()); } #if SK_SUPPORT_GPU -- 2.7.4