Remove SkImageCacherator entirely
It was just the slice of SkImage_Lazy's API that we needed to expose to
GrImageTextureMaker. Instead, give SkImage_Lazy a header, so that the
maker can use it directly.
Change-Id: Iea6198f63e8065b8c987f7c07f3222409cdda439
Reviewed-on: https://skia-review.googlesource.com/153546
Reviewed-by: Mike Klein <mtklein@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
diff --git a/src/image/SkImage_Lazy.cpp b/src/image/SkImage_Lazy.cpp
index 454c867..15722fe 100644
--- a/src/image/SkImage_Lazy.cpp
+++ b/src/image/SkImage_Lazy.cpp
@@ -5,8 +5,7 @@
* found in the LICENSE file.
*/
-#include "SkImage_Base.h"
-#include "SkImageCacherator.h"
+#include "SkImage_Lazy.h"
#include "SkBitmap.h"
#include "SkBitmapCache.h"
@@ -51,104 +50,6 @@
SkMutex fMutex;
};
-class SkImage_Lazy : public SkImage_Base, public SkImageCacherator {
-public:
- struct Validator {
- Validator(sk_sp<SharedGenerator>, const SkIRect* subset, sk_sp<SkColorSpace> colorSpace);
-
- operator bool() const { return fSharedGenerator.get(); }
-
- sk_sp<SharedGenerator> fSharedGenerator;
- SkImageInfo fInfo;
- SkIPoint fOrigin;
- sk_sp<SkColorSpace> fColorSpace;
- uint32_t fUniqueID;
- };
-
- SkImage_Lazy(Validator* validator);
-
- SkImageInfo onImageInfo() const override {
- return fInfo;
- }
- SkColorType onColorType() const override {
- return kUnknown_SkColorType;
- }
- SkAlphaType onAlphaType() const override {
- return fInfo.alphaType();
- }
-
- SkIRect onGetSubset() const override {
- return SkIRect::MakeXYWH(fOrigin.fX, fOrigin.fY, fInfo.width(), fInfo.height());
- }
-
- bool onReadPixels(const SkImageInfo&, void*, size_t, int srcX, int srcY,
- CachingHint) const override;
-#if SK_SUPPORT_GPU
- sk_sp<GrTextureProxy> asTextureProxyRef(GrContext*,
- const GrSamplerState&, SkColorSpace*,
- sk_sp<SkColorSpace>*,
- SkScalar scaleAdjust[2]) const override;
-#endif
- sk_sp<SkData> onRefEncoded() const override;
- sk_sp<SkImage> onMakeSubset(const SkIRect&) const override;
- bool getROPixels(SkBitmap*, SkColorSpace* dstColorSpace, CachingHint) const override;
- bool onIsLazyGenerated() const override { return true; }
- sk_sp<SkImage> onMakeColorSpace(sk_sp<SkColorSpace>, SkColorType) const override;
-
- bool onIsValid(GrContext*) const override;
-
- SkImageCacherator* peekCacherator() const override {
- return const_cast<SkImage_Lazy*>(this);
- }
-
- // Only return true if the generate has already been cached.
- bool lockAsBitmapOnlyIfAlreadyCached(SkBitmap*) const;
- // Call the underlying generator directly
- bool directGeneratePixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRB,
- int srcX, int srcY) const;
-
- // SkImageCacherator interface
-#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,
- SkImage::CachingHint,
- bool willBeMipped,
- SkColorSpace* dstColorSpace,
- GrTextureMaker::AllowedTexGenType genType) override;
-
- // TODO: Need to pass in dstColorSpace to fold into key here?
- void makeCacheKeyFromOrigKey(const GrUniqueKey& origKey, GrUniqueKey* cacheKey) override;
-#endif
-
-private:
- class ScopedGenerator;
-
- /**
- * On success (true), bitmap will point to the pixels for this generator. If this returns
- * false, the bitmap will be reset to empty.
- * TODO: Pass in dstColorSpace to ensure bitmap is compatible?
- */
- bool lockAsBitmap(SkBitmap*, SkImage::CachingHint, const SkImageInfo&) const;
-
- sk_sp<SharedGenerator> fSharedGenerator;
- // Note that fInfo is not necessarily the info from the generator. It may be cropped by
- // onMakeSubset and its color space may be changed by onMakeColorSpace.
- const SkImageInfo fInfo;
- const SkIPoint fOrigin;
-
- uint32_t fUniqueID;
-
- // Repeated calls to onMakeColorSpace will result in a proliferation of unique IDs and
- // SkImage_Lazy instances. Cache the result of the last successful onMakeColorSpace call.
- mutable SkMutex fOnMakeColorSpaceMutex;
- mutable sk_sp<SkColorSpace> fOnMakeColorSpaceTarget;
- mutable sk_sp<SkImage> fOnMakeColorSpaceResult;
-
- typedef SkImage_Base INHERITED;
-};
-
///////////////////////////////////////////////////////////////////////////////
SkImage_Lazy::Validator::Validator(sk_sp<SharedGenerator> gen, const SkIRect* subset,
@@ -224,6 +125,15 @@
fUniqueID = validator->fUniqueID;
}
+SkImage_Lazy::~SkImage_Lazy() {
+#if SK_SUPPORT_GPU
+ for (int i = 0; i < fUniqueKeyInvalidatedMessages.count(); ++i) {
+ SkMessageBus<GrUniqueKeyInvalidatedMessage>::Post(*fUniqueKeyInvalidatedMessages[i]);
+ }
+ fUniqueKeyInvalidatedMessages.deleteAll();
+#endif
+}
+
//////////////////////////////////////////////////////////////////////////////////////////////////
static bool check_output_bitmap(const SkBitmap& bitmap, uint32_t expectedID) {
@@ -428,13 +338,10 @@
//////////////////////////////////////////////////////////////////////////////////////////////////
-/**
- * Implementation of SkImageCacherator interface, as needed by GrImageTextureMaker
- */
-
#if SK_SUPPORT_GPU
-void SkImage_Lazy::makeCacheKeyFromOrigKey(const GrUniqueKey& origKey, GrUniqueKey* cacheKey) {
+void SkImage_Lazy::makeCacheKeyFromOrigKey(const GrUniqueKey& origKey,
+ GrUniqueKey* cacheKey) const {
// TODO: Take dstColorSpace, include hash in key
SkASSERT(!cacheKey->isValid());
if (origKey.isValid()) {
@@ -484,12 +391,13 @@
* 3. Ask the generator to return YUV planes, which the GPU can convert
* 4. Ask the generator to return RGB(A) data, which the GPU can convert
*/
-sk_sp<GrTextureProxy> SkImage_Lazy::lockTextureProxy(GrContext* ctx,
- const GrUniqueKey& origKey,
- SkImage::CachingHint chint,
- bool willBeMipped,
- SkColorSpace* dstColorSpace,
- GrTextureMaker::AllowedTexGenType genType) {
+sk_sp<GrTextureProxy> SkImage_Lazy::lockTextureProxy(
+ GrContext* ctx,
+ const GrUniqueKey& origKey,
+ SkImage::CachingHint chint,
+ bool willBeMipped,
+ SkColorSpace* dstColorSpace,
+ GrTextureMaker::AllowedTexGenType genType) const {
// Values representing the various texture lock paths we can take. Used for logging the path
// taken to a histogram.
enum LockTexturePath {