aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkImageCacherator.h
diff options
context:
space:
mode:
authorGravatar Brian Osman <brianosman@google.com>2017-04-26 16:20:28 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-04-27 18:31:19 +0000
commitdf7e075c74110fcfebdc49ca503684162e118af5 (patch)
tree4d4f55d2867115102a2d2460096c9fe8ce0ecb51 /src/core/SkImageCacherator.h
parent0aa742f15a400433bafe6350c20523b4dd062f64 (diff)
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 <msarett@google.com> Reviewed-by: Mike Reed <reed@google.com> Commit-Queue: Brian Osman <brianosman@google.com>
Diffstat (limited to 'src/core/SkImageCacherator.h')
-rw-r--r--src/core/SkImageCacherator.h140
1 files changed, 18 insertions, 122 deletions
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<SkImageGenerator>,
- 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<GrTextureProxy> lockAsTextureProxy(GrContext*, const GrSamplerParams&,
- SkColorSpace* dstColorSpace,
- sk_sp<SkColorSpace>* 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<SharedGenerator> {
- public:
- static sk_sp<SharedGenerator> Make(std::unique_ptr<SkImageGenerator> gen) {
- return gen ? sk_sp<SharedGenerator>(new SharedGenerator(std::move(gen))) : nullptr;
- }
-
- private:
- explicit SharedGenerator(std::unique_ptr<SkImageGenerator> gen)
- : fGenerator(std::move(gen))
- {
- SkASSERT(fGenerator);
- }
-
- friend class ScopedGenerator;
- friend class SkImageCacherator;
-
- std::unique_ptr<SkImageGenerator> fGenerator;
- SkMutex fMutex;
- };
- class ScopedGenerator;
-
- struct Validator {
- Validator(sk_sp<SharedGenerator>, const SkIRect* subset);
-
- operator bool() const { return fSharedGenerator.get(); }
-
- sk_sp<SharedGenerator> 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<GrTextureProxy> lockTextureProxy(GrContext*,
- const GrUniqueKey& key,
- const SkImage* client,
- SkImage::CachingHint,
- bool willBeMipped,
- SkColorSpace* dstColorSpace);
+ virtual sk_sp<GrTextureProxy> 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<SkColorSpace> getColorSpace(GrContext*, SkColorSpace* dstColorSpace);
- void makeCacheKeyFromOrigKey(const GrUniqueKey& origKey, CachedFormat, GrUniqueKey* cacheKey);
+ virtual sk_sp<SkColorSpace> getColorSpace(GrContext*, SkColorSpace* dstColorSpace) = 0;
+ virtual void makeCacheKeyFromOrigKey(const GrUniqueKey& origKey, CachedFormat,
+ GrUniqueKey* cacheKey) = 0;
#endif
-
- sk_sp<SharedGenerator> 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