From df7e075c74110fcfebdc49ca503684162e118af5 Mon Sep 17 00:00:00 2001 From: Brian Osman Date: Wed, 26 Apr 2017 16:20:28 -0400 Subject: Fold SkImageCacherator into SkImage_Lazy SkImageCacherator still exists, but only as an interface implemented (solely) by SkImage_Lazy. The only external clients are GrImageTextureMaker and SkImage_Gpu::getDeferredTextureImageData. This is probably an improvement, but doesn't go as far as I'd hoped. Bug: skia: Change-Id: I6812badfabb6924b025621b21af00cbde9c16cac Reviewed-on: https://skia-review.googlesource.com/14371 Reviewed-by: Matt Sarett Reviewed-by: Mike Reed Commit-Queue: Brian Osman --- src/core/SkImageCacherator.h | 140 ++++++------------------------------------- 1 file changed, 18 insertions(+), 122 deletions(-) (limited to 'src/core/SkImageCacherator.h') diff --git a/src/core/SkImageCacherator.h b/src/core/SkImageCacherator.h index fb07b7646a..358744606e 100644 --- a/src/core/SkImageCacherator.h +++ b/src/core/SkImageCacherator.h @@ -8,30 +8,22 @@ #ifndef SkImageCacherator_DEFINED #define SkImageCacherator_DEFINED -#include "SkImageGenerator.h" -#include "SkMutex.h" -#include "SkTemplates.h" +#include "SkImage.h" +#include "SkImageInfo.h" class GrCaps; class GrContext; -class GrSamplerParams; class GrTextureProxy; class GrUniqueKey; -class SkBitmap; -class SkImage; +class SkColorSpace; /* - * Internal class to manage caching the output of an ImageGenerator. + * Interface used by GrImageTextureMaker to construct textures from instances of SkImage + * (specifically, SkImage_Lazy). */ class SkImageCacherator { public: - static SkImageCacherator* NewFromGenerator(std::unique_ptr, - const SkIRect* subset = nullptr); - - ~SkImageCacherator(); - - const SkImageInfo& info() const { return fInfo; } - uint32_t uniqueID() const { return this->getUniqueID(kLegacy_CachedFormat); } + virtual ~SkImageCacherator() {} enum CachedFormat { kLegacy_CachedFormat, // The format from the generator, with any color space stripped out @@ -42,122 +34,26 @@ public: kNumCachedFormats, }; -#if SK_SUPPORT_GPU - /** - * Returns a ref() on the texture produced by this generator. The caller must call unref() - * when it is done. Will return nullptr on failure. - * - * If not NULL, the client will be notified (->notifyAddedToCache()) when resources are - * added to the cache on its behalf. - * - * The caller is responsible for calling proxy->unref() when they are done. - * - * The scaleAdjust in/out parameter will return any scale adjustment that needs - * to be applied to the absolute texture coordinates in the case where the image - * was resized to meet the sampling requirements (e.g., resized out to the next power of 2). - * It can be null if the caller knows resizing will not be required. - */ - sk_sp lockAsTextureProxy(GrContext*, const GrSamplerParams&, - SkColorSpace* dstColorSpace, - sk_sp* texColorSpace, - const SkImage* client, - SkScalar scaleAdjust[2], - SkImage::CachingHint = SkImage::kAllow_CachingHint); -#endif - - /** - * If the underlying src naturally is represented by an encoded blob (in SkData), this returns - * a ref to that data. If not, it returns null. - */ - SkData* refEncoded(); - - // Only return true if the generate has already been cached. - bool lockAsBitmapOnlyIfAlreadyCached(SkBitmap*, CachedFormat); - // Call the underlying generator directly - bool directGeneratePixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRB, - int srcX, int srcY, SkTransferFunctionBehavior behavior); - -private: - // Ref-counted tuple(SkImageGenerator, SkMutex) which allows sharing of one generator - // among several cacherators. - class SharedGenerator final : public SkNVRefCnt { - public: - static sk_sp Make(std::unique_ptr gen) { - return gen ? sk_sp(new SharedGenerator(std::move(gen))) : nullptr; - } - - private: - explicit SharedGenerator(std::unique_ptr gen) - : fGenerator(std::move(gen)) - { - SkASSERT(fGenerator); - } - - friend class ScopedGenerator; - friend class SkImageCacherator; - - std::unique_ptr fGenerator; - SkMutex fMutex; - }; - class ScopedGenerator; - - struct Validator { - Validator(sk_sp, const SkIRect* subset); - - operator bool() const { return fSharedGenerator.get(); } - - sk_sp fSharedGenerator; - SkImageInfo fInfo; - SkIPoint fOrigin; - uint32_t fUniqueID; - }; - - SkImageCacherator(Validator*); - - CachedFormat chooseCacheFormat(SkColorSpace* dstColorSpace, const GrCaps* = nullptr); - SkImageInfo buildCacheInfo(CachedFormat); - - /** - * On success (true), bitmap will point to the pixels for this generator. If this returns - * false, the bitmap will be reset to empty. - * - * 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, SkImage::CachingHint, CachedFormat, - const SkImageInfo&); + virtual CachedFormat chooseCacheFormat(SkColorSpace* dstColorSpace, + const GrCaps* = nullptr) const = 0; + virtual SkImageInfo buildCacheInfo(CachedFormat) const = 0; #if SK_SUPPORT_GPU // Returns the texture proxy. If the cacherator is generating the texture and wants to cache it, // it should use the passed in key (if the key is valid). - sk_sp lockTextureProxy(GrContext*, - const GrUniqueKey& key, - const SkImage* client, - SkImage::CachingHint, - bool willBeMipped, - SkColorSpace* dstColorSpace); + virtual sk_sp lockTextureProxy(GrContext*, + const GrUniqueKey& key, + SkImage::CachingHint, + bool willBeMipped, + SkColorSpace* dstColorSpace) = 0; + // 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*, SkColorSpace* dstColorSpace); - void makeCacheKeyFromOrigKey(const GrUniqueKey& origKey, CachedFormat, GrUniqueKey* cacheKey); + virtual sk_sp getColorSpace(GrContext*, SkColorSpace* dstColorSpace) = 0; + virtual void makeCacheKeyFromOrigKey(const GrUniqueKey& origKey, CachedFormat, + GrUniqueKey* cacheKey) = 0; #endif - - sk_sp fSharedGenerator; - const SkImageInfo fInfo; - const SkIPoint fOrigin; - - struct IDRec { - SkOnce fOnce; - uint32_t fUniqueID; - }; - mutable IDRec fIDRecs[kNumCachedFormats]; - - uint32_t getUniqueID(CachedFormat) const; - - friend class GrImageTextureMaker; - friend class SkImage; - friend class SkImage_Lazy; }; #endif -- cgit v1.2.3