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 <brianosman@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
This commit is contained in:
Brian Salomon 2020-02-28 13:34:16 -05:00 committed by Skia Commit-Bot
parent 9fbba62dc7
commit b62cee315e
8 changed files with 37 additions and 125 deletions

View File

@ -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());
}

View File

@ -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;

View File

@ -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<GrFragmentProcessor> GrYUVAImageTextureMaker::createFragmentProcessor(
const SkMatrix& textureMatrix,
const SkRect& constraintRect,

View File

@ -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<GrFragmentProcessor> 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<GrFragmentProcessor> 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;

View File

@ -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<GrTextureProxy> 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;

View File

@ -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<GrFragmentProcessor> 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;

View File

@ -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;
};

View File

@ -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,