From b62cee315e5d889effe4e7d822ac59e59890c32c Mon Sep 17 00:00:00 2001 From: Brian Salomon Date: Fri, 28 Feb 2020 13:34:16 -0500 Subject: [PATCH] Simplifications to GrTextureProducers Move all MIP map code directly into GrTextureAdjust, not used by makers. Make GrTextureAdjuster final. Make some virtuals private Change-Id: I12dc7d8fa015dc85aaca3f7d5e58e094bb859518 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/274045 Reviewed-by: Brian Osman Commit-Queue: Brian Salomon --- src/gpu/GrBitmapTextureMaker.cpp | 12 --------- src/gpu/GrBitmapTextureMaker.h | 5 +--- src/gpu/GrImageTextureMaker.cpp | 18 ------------- src/gpu/GrImageTextureMaker.h | 33 ++++++++---------------- src/gpu/GrTextureAdjuster.cpp | 44 ++++++++++++-------------------- src/gpu/GrTextureAdjuster.h | 21 +++++---------- src/gpu/GrTextureMaker.h | 4 +-- src/gpu/GrTextureProducer.h | 25 ------------------ 8 files changed, 37 insertions(+), 125 deletions(-) diff --git a/src/gpu/GrBitmapTextureMaker.cpp b/src/gpu/GrBitmapTextureMaker.cpp index 5c7a85acb1..baff879de8 100644 --- a/src/gpu/GrBitmapTextureMaker.cpp +++ b/src/gpu/GrBitmapTextureMaker.cpp @@ -116,15 +116,3 @@ GrSurfaceProxyView GrBitmapTextureMaker::refOriginalTextureProxyView(bool willBe } return {}; } - -void GrBitmapTextureMaker::makeMipMappedKey(GrUniqueKey* mipMappedKey) { - // Destination color space is irrelevant - we always upload the bitmap's contents as-is - if (fOriginalKey.isValid()) { - MakeMipMappedKeyFromOriginalKey(fOriginalKey, mipMappedKey); - } -} - -void GrBitmapTextureMaker::didCacheMipMappedCopy(const GrUniqueKey& mipMappedKey, - uint32_t contextUniqueID) { - GrInstallBitmapUniqueKeyInvalidator(mipMappedKey, contextUniqueID, fBitmap.pixelRef()); -} diff --git a/src/gpu/GrBitmapTextureMaker.h b/src/gpu/GrBitmapTextureMaker.h index 63955d76b8..311bacb09f 100644 --- a/src/gpu/GrBitmapTextureMaker.h +++ b/src/gpu/GrBitmapTextureMaker.h @@ -14,7 +14,7 @@ /** This class manages the conversion of SW-backed bitmaps to GrTextures. If the input bitmap is non-volatile the texture is cached using a key created from the pixels' image id and the subset of the pixelref specified by the bitmap. */ -class GrBitmapTextureMaker : public GrTextureMaker { +class GrBitmapTextureMaker final : public GrTextureMaker { public: enum class Cached { kNo, kYes }; @@ -25,9 +25,6 @@ public: private: GrSurfaceProxyView refOriginalTextureProxyView(bool willBeMipped) override; - void makeMipMappedKey(GrUniqueKey* mipMappedKey) override; - void didCacheMipMappedCopy(const GrUniqueKey& mipMappedKey, uint32_t contextUniqueID) override; - const SkBitmap fBitmap; const SkBackingFit fFit; GrUniqueKey fOriginalKey; diff --git a/src/gpu/GrImageTextureMaker.cpp b/src/gpu/GrImageTextureMaker.cpp index 4cfeabf287..892140fdfb 100644 --- a/src/gpu/GrImageTextureMaker.cpp +++ b/src/gpu/GrImageTextureMaker.cpp @@ -37,14 +37,6 @@ GrSurfaceProxyView GrImageTextureMaker::refOriginalTextureProxyView(bool willBeM return fImage->lockTextureProxyView(this->context(), fOriginalKey, fCachingHint, willBeMipped); } -void GrImageTextureMaker::makeMipMappedKey(GrUniqueKey* mipMappedKey) { - if (fOriginalKey.isValid() && SkImage::kAllow_CachingHint == fCachingHint) { - GrUniqueKey cacheKey; - fImage->makeCacheKeyFromOrigKey(fOriginalKey, &cacheKey); - MakeMipMappedKeyFromOriginalKey(cacheKey, mipMappedKey); - } -} - ///////////////////////////////////////////////////////////////////////////////////////////////// GrYUVAImageTextureMaker::GrYUVAImageTextureMaker(GrContext* context, const SkImage* client, @@ -67,16 +59,6 @@ GrSurfaceProxyView GrYUVAImageTextureMaker::refOriginalTextureProxyView(bool wil } } -void GrYUVAImageTextureMaker::makeMipMappedKey(GrUniqueKey* mipMappedKey) { - // TODO: Do we ever want to disable caching? - if (fOriginalKey.isValid()) { - GrUniqueKey cacheKey; - static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain(); - GrUniqueKey::Builder builder(&cacheKey, fOriginalKey, kDomain, 0, "Image"); - MakeMipMappedKeyFromOriginalKey(cacheKey, mipMappedKey); - } -} - std::unique_ptr GrYUVAImageTextureMaker::createFragmentProcessor( const SkMatrix& textureMatrix, const SkRect& constraintRect, diff --git a/src/gpu/GrImageTextureMaker.h b/src/gpu/GrImageTextureMaker.h index 7ec0a219f2..908e232e00 100644 --- a/src/gpu/GrImageTextureMaker.h +++ b/src/gpu/GrImageTextureMaker.h @@ -16,7 +16,7 @@ class SkImage_GpuYUVA; /** This class manages the conversion of generator-backed images to GrTextures. If the caching hint is kAllow the image's ID is used for the cache key. */ -class GrImageTextureMaker : public GrTextureMaker { +class GrImageTextureMaker final : public GrTextureMaker { public: GrImageTextureMaker(GrRecordingContext* context, const SkImage* client, SkImage::CachingHint chint, bool useDecal = false); @@ -24,10 +24,6 @@ public: private: GrSurfaceProxyView refOriginalTextureProxyView(bool willBeMipped) override; - void makeMipMappedKey(GrUniqueKey* mipMappedKey) override; - void didCacheMipMappedCopy(const GrUniqueKey& mipMappedKey, uint32_t contextUniqueID) override { - } - const SkImage_Lazy* fImage; GrUniqueKey fOriginalKey; SkImage::CachingHint fCachingHint; @@ -36,31 +32,24 @@ private: }; /** This class manages the conversion of generator-backed YUVA images to GrTextures. */ -class GrYUVAImageTextureMaker : public GrTextureMaker { +class GrYUVAImageTextureMaker final : public GrTextureMaker { public: GrYUVAImageTextureMaker(GrContext* context, const SkImage* client, bool useDecal = false); + std::unique_ptr createFragmentProcessor( + const SkMatrix& textureMatrix, + const SkRect& constraintRect, + FilterConstraint filterConstraint, + bool coordsLimitedToConstraintRect, + const GrSamplerState::Filter* filterOrNullForBicubic) override; + // This could be made more nuanced and compare all of the texture proxy resolutions, but // it's probably not worth the effort. bool hasMixedResolutions() const override { return true; } -protected: - // TODO: consider overriding this, for the case where the underlying generator might be - // able to efficiently produce a "stretched" texture natively (e.g. picture-backed) - // GrTexture* generateTextureForParams(const CopyParams&) override; - GrSurfaceProxyView refOriginalTextureProxyView(bool willBeMipped) override; - - void makeMipMappedKey(GrUniqueKey* mipMappedKey) override; - void didCacheMipMappedCopy(const GrUniqueKey& mipMappedKey, uint32_t contextUniqueID) override { - } - - std::unique_ptr createFragmentProcessor( - const SkMatrix& textureMatrix, - const SkRect& constraintRect, - FilterConstraint filterConstraint, - bool coordsLimitedToConstraintRect, - const GrSamplerState::Filter* filterOrNullForBicubic) override; private: + GrSurfaceProxyView refOriginalTextureProxyView(bool willBeMipped) override; + const SkImage_GpuYUVA* fImage; GrUniqueKey fOriginalKey; diff --git a/src/gpu/GrTextureAdjuster.cpp b/src/gpu/GrTextureAdjuster.cpp index 6d4628acbf..1653e6685e 100644 --- a/src/gpu/GrTextureAdjuster.cpp +++ b/src/gpu/GrTextureAdjuster.cpp @@ -22,41 +22,32 @@ GrTextureAdjuster::GrTextureAdjuster(GrRecordingContext* context, , fOriginal(std::move(original)) , fUniqueID(uniqueID) {} -void GrTextureAdjuster::makeMipMappedKey(GrUniqueKey* mipMappedKey) { - // Destination color space is irrelevant - we already have a texture so we're just sub-setting - GrUniqueKey baseKey; - GrMakeKeyFromImageID(&baseKey, fUniqueID, SkIRect::MakeSize(this->dimensions())); - MakeMipMappedKeyFromOriginalKey(baseKey, mipMappedKey); -} - -void GrTextureAdjuster::didCacheMipMappedCopy(const GrUniqueKey& mipMappedKey, - uint32_t contextUniqueID) { - // We don't currently have a mechanism for notifications on Images! -} - GrSurfaceProxyView GrTextureAdjuster::makeMippedCopy() { GrProxyProvider* proxyProvider = this->context()->priv().proxyProvider(); - GrUniqueKey key; - this->makeMipMappedKey(&key); + GrUniqueKey baseKey, mipMappedKey; + GrMakeKeyFromImageID(&baseKey, fUniqueID, SkIRect::MakeSize(this->dimensions())); + if (baseKey.isValid()) { + static const GrUniqueKey::Domain kMipMappedDomain = GrUniqueKey::GenerateDomain(); + GrUniqueKey::Builder builder(&mipMappedKey, baseKey, kMipMappedDomain, 0); + } sk_sp cachedCopy; - const GrSurfaceProxyView& originalView = this->originalProxyView(); - if (key.isValid()) { - cachedCopy = proxyProvider->findOrCreateProxyByUniqueKey(key, this->colorType()); + if (mipMappedKey.isValid()) { + cachedCopy = proxyProvider->findOrCreateProxyByUniqueKey(mipMappedKey, this->colorType()); if (cachedCopy) { - return {std::move(cachedCopy), originalView.origin(), originalView.swizzle()}; + return {std::move(cachedCopy), fOriginal.origin(), fOriginal.swizzle()}; } } GrSurfaceProxyView copyView = GrCopyBaseMipMapToTextureProxy( - this->context(), originalView.proxy(), originalView.origin(), this->colorType()); + this->context(), fOriginal.proxy(), fOriginal.origin(), this->colorType()); if (!copyView) { return {}; } - if (key.isValid()) { - SkASSERT(copyView.origin() == originalView.origin()); - proxyProvider->assignUniqueKeyToProxy(key, copyView.asTextureProxy()); - this->didCacheMipMappedCopy(key, proxyProvider->contextID()); + if (mipMappedKey.isValid()) { + SkASSERT(copyView.origin() == fOriginal.origin()); + // TODO: If we move listeners up from SkImage_Lazy to SkImage_Base then add one here. + proxyProvider->assignUniqueKeyToProxy(mipMappedKey, copyView.asTextureProxy()); } return copyView; } @@ -71,11 +62,10 @@ GrSurfaceProxyView GrTextureAdjuster::onRefTextureProxyViewForParams(GrSamplerSt SkASSERT(this->width() <= this->context()->priv().caps()->maxTextureSize() && this->height() <= this->context()->priv().caps()->maxTextureSize()); - GrSurfaceProxyView view = this->originalProxyViewRef(); - GrTextureProxy* texProxy = view.asTextureProxy(); + GrTextureProxy* texProxy = fOriginal.asTextureProxy(); SkASSERT(texProxy); if (!GrGpu::IsACopyNeededForMips(this->context()->priv().caps(), texProxy, params.filter())) { - return view; + return fOriginal; } GrSurfaceProxyView copy = this->makeMippedCopy(); @@ -83,7 +73,7 @@ GrSurfaceProxyView GrTextureAdjuster::onRefTextureProxyViewForParams(GrSamplerSt // If we were unable to make a copy and we only needed a copy for mips, then we will return // the source texture here and require that the GPU backend is able to fall back to using // bilerp if mips are required. - return view; + return fOriginal; } SkASSERT(copy.asTextureProxy()); return copy; diff --git a/src/gpu/GrTextureAdjuster.h b/src/gpu/GrTextureAdjuster.h index d52e517e56..08ce0307ad 100644 --- a/src/gpu/GrTextureAdjuster.h +++ b/src/gpu/GrTextureAdjuster.h @@ -15,13 +15,14 @@ class GrRecordingContext; /** - * Base class for sources that start out as textures. Optionally allows for a content area subrect. - * The intent is not to use content area for subrect rendering. Rather, the pixels outside the - * content area have undefined values and shouldn't be read *regardless* of filtering mode or - * the SkCanvas::SrcRectConstraint used for subrect draws. + * GrTextureProducer subclass that can be used when the user already has a texture that represents + * image contents. */ -class GrTextureAdjuster : public GrTextureProducer { +class GrTextureAdjuster final : public GrTextureProducer { public: + GrTextureAdjuster(GrRecordingContext*, GrSurfaceProxyView, const GrColorInfo&, + uint32_t uniqueID, bool useDecal = false); + std::unique_ptr createFragmentProcessor( const SkMatrix& textureMatrix, const SkRect& constraintRect, @@ -29,16 +30,6 @@ public: bool coordsLimitedToConstraintRect, const GrSamplerState::Filter* filterOrNullForBicubic) override; - GrTextureAdjuster(GrRecordingContext*, GrSurfaceProxyView, const GrColorInfo&, - uint32_t uniqueID, bool useDecal = false); - -protected: - void makeMipMappedKey(GrUniqueKey* mipMappedKey) override; - void didCacheMipMappedCopy(const GrUniqueKey& mipMappedKey, uint32_t contextUniqueID) override; - - const GrSurfaceProxyView& originalProxyView() const { return fOriginal; } - GrSurfaceProxyView originalProxyViewRef() const { return fOriginal; } - private: GrSurfaceProxyView onRefTextureProxyViewForParams(GrSamplerState, bool willBeMipped) override; diff --git a/src/gpu/GrTextureMaker.h b/src/gpu/GrTextureMaker.h index b3f9e47946..20352f6f97 100644 --- a/src/gpu/GrTextureMaker.h +++ b/src/gpu/GrTextureMaker.h @@ -27,6 +27,7 @@ protected: GrTextureMaker(GrRecordingContext* context, const GrImageInfo& info, bool domainNeedsLocal) : INHERITED(context, info, domainNeedsLocal) {} +private: /** * Return the maker's "original" texture. It is the responsibility of the maker to handle any * caching of the original if desired. @@ -36,8 +37,7 @@ protected: */ virtual GrSurfaceProxyView refOriginalTextureProxyView(bool willBeMipped) = 0; -private: - GrSurfaceProxyView onRefTextureProxyViewForParams(GrSamplerState, bool willBeMipped) override; + GrSurfaceProxyView onRefTextureProxyViewForParams(GrSamplerState, bool willBeMipped) final; typedef GrTextureProducer INHERITED; }; diff --git a/src/gpu/GrTextureProducer.h b/src/gpu/GrTextureProducer.h index 726531adb4..0d05a30500 100644 --- a/src/gpu/GrTextureProducer.h +++ b/src/gpu/GrTextureProducer.h @@ -104,31 +104,6 @@ protected: GrColorType colorType() const { return fImageInfo.colorType(); } - /** Helper for creating a key for a copy from an original key. */ - static void MakeMipMappedKeyFromOriginalKey(const GrUniqueKey& origKey, - GrUniqueKey* mipMappedKey) { - SkASSERT(!mipMappedKey->isValid()); - if (origKey.isValid()) { - static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain(); - GrUniqueKey::Builder builder(mipMappedKey, origKey, kDomain, 0); - } - } - - /** - * If we need to make a copy with MIP maps the producer is asked to return a key that identifies - * the original conteny + the addition of MIP map levels. If the producer does not want to cache - * the copy it can simply leave the key uninitialized. - */ - virtual void makeMipMappedKey(GrUniqueKey* mipMappedKey) = 0; - - /** - * If a stretched version of the texture is generated, it may be cached (assuming that - * makeMipMappedKey() returns true). In that case, the maker is notified in case it - * wants to note that for when the maker is destroyed. - */ - virtual void didCacheMipMappedCopy(const GrUniqueKey& mipMappedKey, - uint32_t contextUniqueID) = 0; - enum DomainMode { kNoDomain_DomainMode, kDomain_DomainMode,