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/core/SkImageCacherator.h b/src/core/SkImageCacherator.h
deleted file mode 100644
index 5ba4e68..0000000
--- a/src/core/SkImageCacherator.h
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright 2015 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#ifndef SkImageCacherator_DEFINED
-#define SkImageCacherator_DEFINED
-
-#include "SkImage.h"
-#include "SkImageInfo.h"
-
-#if SK_SUPPORT_GPU
-#include "GrTextureMaker.h"
-#endif
-
-class GrCaps;
-class GrContext;
-class GrTextureProxy;
-class GrUniqueKey;
-class SkColorSpace;
-
-/*
- * Interface used by GrImageTextureMaker to construct textures from instances of SkImage
- * (specifically, SkImage_Lazy).
- */
-class SkImageCacherator {
-public:
- virtual ~SkImageCacherator() {}
-
-#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).
- // If "genType" argument equals AllowedTexGenType::kCheap and the texture is not trivial to
- // construct then refOriginalTextureProxy should return nullptr (for example if texture is made
- // by drawing into a render target).
- virtual sk_sp<GrTextureProxy> lockTextureProxy(GrContext*, const GrUniqueKey& key,
- SkImage::CachingHint, bool willBeMipped,
- SkColorSpace* dstColorSpace,
- GrTextureMaker::AllowedTexGenType genType) = 0;
-
-
- virtual void makeCacheKeyFromOrigKey(const GrUniqueKey& origKey, GrUniqueKey* cacheKey) = 0;
-#endif
-};
-
-#endif
diff --git a/src/gpu/GrImageTextureMaker.cpp b/src/gpu/GrImageTextureMaker.cpp
index a86cefd..0de2573 100644
--- a/src/gpu/GrImageTextureMaker.cpp
+++ b/src/gpu/GrImageTextureMaker.cpp
@@ -6,21 +6,15 @@
*/
#include "GrImageTextureMaker.h"
-#include "GrContext.h"
-#include "GrContextPriv.h"
-#include "GrGpuResourcePriv.h"
#include "SkGr.h"
-#include "SkImageCacherator.h"
-#include "SkImage_Base.h"
-#include "SkPixelRef.h"
+#include "SkImage_Lazy.h"
GrImageTextureMaker::GrImageTextureMaker(GrContext* context, const SkImage* client,
SkImage::CachingHint chint)
: INHERITED(context, client->width(), client->height(), client->isAlphaOnly())
- , fCacher(as_IB(client)->peekCacherator())
- , fClient(client)
+ , fImage(static_cast<const SkImage_Lazy*>(client))
, fCachingHint(chint) {
- SkASSERT(fCacher);
+ SkASSERT(client->isLazyGenerated());
GrMakeKeyFromImageID(&fOriginalKey, client->uniqueID(),
SkIRect::MakeWH(this->width(), this->height()));
}
@@ -28,21 +22,21 @@
sk_sp<GrTextureProxy> GrImageTextureMaker::refOriginalTextureProxy(bool willBeMipped,
SkColorSpace* dstColorSpace,
AllowedTexGenType onlyIfFast) {
- return fCacher->lockTextureProxy(this->context(), fOriginalKey, fCachingHint,
- willBeMipped, dstColorSpace, onlyIfFast);
+ return fImage->lockTextureProxy(this->context(), fOriginalKey, fCachingHint,
+ willBeMipped, dstColorSpace, onlyIfFast);
}
void GrImageTextureMaker::makeCopyKey(const CopyParams& stretch, GrUniqueKey* paramsCopyKey) {
if (fOriginalKey.isValid() && SkImage::kAllow_CachingHint == fCachingHint) {
GrUniqueKey cacheKey;
- fCacher->makeCacheKeyFromOrigKey(fOriginalKey, &cacheKey);
+ fImage->makeCacheKeyFromOrigKey(fOriginalKey, &cacheKey);
MakeCopyKeyFromOrigKey(cacheKey, stretch, paramsCopyKey);
}
}
SkAlphaType GrImageTextureMaker::alphaType() const {
- return fClient->alphaType();
+ return fImage->alphaType();
}
sk_sp<SkColorSpace> GrImageTextureMaker::getColorSpace(SkColorSpace* dstColorSpace) {
- return fClient->refColorSpace();
+ return fImage->refColorSpace();
}
diff --git a/src/gpu/GrImageTextureMaker.h b/src/gpu/GrImageTextureMaker.h
index f1f647b..bb3e830 100644
--- a/src/gpu/GrImageTextureMaker.h
+++ b/src/gpu/GrImageTextureMaker.h
@@ -11,7 +11,7 @@
#include "GrTextureMaker.h"
#include "SkImage.h"
-class SkImageCacherator;
+class SkImage_Lazy;
/** 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. */
@@ -34,8 +34,7 @@
sk_sp<SkColorSpace> getColorSpace(SkColorSpace* dstColorSpace) override;
private:
- SkImageCacherator* fCacher;
- const SkImage* fClient;
+ const SkImage_Lazy* fImage;
GrUniqueKey fOriginalKey;
SkImage::CachingHint fCachingHint;
diff --git a/src/image/SkImage.cpp b/src/image/SkImage.cpp
index b857a35..3be9f37 100644
--- a/src/image/SkImage.cpp
+++ b/src/image/SkImage.cpp
@@ -201,13 +201,6 @@
if (fAddedToRasterCache.load()) {
SkNotifyBitmapGenIDIsStale(this->uniqueID());
}
-
-#if SK_SUPPORT_GPU
- for (int i = 0; i < fUniqueKeyInvalidatedMessages.count(); ++i) {
- SkMessageBus<GrUniqueKeyInvalidatedMessage>::Post(*fUniqueKeyInvalidatedMessages[i]);
- }
- fUniqueKeyInvalidatedMessages.deleteAll();
-#endif
}
GrBackendTexture SkImage_Base::onGetBackendTexture(bool flushPendingGrContextIO,
diff --git a/src/image/SkImage_Base.h b/src/image/SkImage_Base.h
index e6598f8..d9c738a 100644
--- a/src/image/SkImage_Base.h
+++ b/src/image/SkImage_Base.h
@@ -22,7 +22,6 @@
#include <new>
class GrSamplerState;
-class SkImageCacherator;
enum {
kNeedNewImageUniqueID = 0
@@ -66,8 +65,6 @@
virtual GrBackendTexture onGetBackendTexture(bool flushPendingGrContextIO,
GrSurfaceOrigin* origin) const;
- virtual SkImageCacherator* peekCacherator() const { return nullptr; }
-
// return a read-only copy of the pixels. We promise to not modify them,
// but only inspect them (or encode them).
virtual bool getROPixels(SkBitmap*, SkColorSpace* dstColorSpace,
@@ -97,13 +94,6 @@
protected:
SkImage_Base(int width, int height, uint32_t uniqueID);
-#if SK_SUPPORT_GPU
- // When the SkImage_Base goes away, we will iterate over all the unique keys we've used and
- // send messages to the GrContexts to say the unique keys are no longer valid. The GrContexts
- // can then release the resources, conntected with the those unique keys, from their caches.
- SkTDArray<GrUniqueKeyInvalidatedMessage*> fUniqueKeyInvalidatedMessages;
-#endif
-
private:
// Set true by caches when they cache content that's derived from the current pixels.
mutable std::atomic<bool> fAddedToRasterCache;
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 {
diff --git a/src/image/SkImage_Lazy.h b/src/image/SkImage_Lazy.h
new file mode 100644
index 0000000..b13cd16
--- /dev/null
+++ b/src/image/SkImage_Lazy.h
@@ -0,0 +1,122 @@
+/*
+ * Copyright 2018 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef SkImage_Lazy_DEFINED
+#define SkImage_Lazy_DEFINED
+
+#include "SkImage_Base.h"
+#include "SkMutex.h"
+
+#if SK_SUPPORT_GPU
+#include "GrTextureMaker.h"
+#endif
+
+class SharedGenerator;
+
+class SkImage_Lazy : public SkImage_Base {
+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);
+ ~SkImage_Lazy() override;
+
+ 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;
+
+ // 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;
+
+#if SK_SUPPORT_GPU
+ // Returns the texture proxy. If we're going to generate and cache the texture, we should use
+ // the passed in key (if the key is valid). If genType is AllowedTexGenType::kCheap and the
+ // texture is not trivial to construct, returns nullptr.
+ sk_sp<GrTextureProxy> lockTextureProxy(GrContext*,
+ const GrUniqueKey& key,
+ SkImage::CachingHint,
+ bool willBeMipped,
+ SkColorSpace* dstColorSpace,
+ GrTextureMaker::AllowedTexGenType genType) const;
+
+ // TODO: Need to pass in dstColorSpace to fold into key here?
+ void makeCacheKeyFromOrigKey(const GrUniqueKey& origKey, GrUniqueKey* cacheKey) const;
+#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;
+
+#if SK_SUPPORT_GPU
+ // When the SkImage_Lazy goes away, we will iterate over all the unique keys we've used and
+ // send messages to the GrContexts to say the unique keys are no longer valid. The GrContexts
+ // can then release the resources, conntected with the those unique keys, from their caches.
+ mutable SkTDArray<GrUniqueKeyInvalidatedMessage*> fUniqueKeyInvalidatedMessages;
+#endif
+
+ typedef SkImage_Base INHERITED;
+};
+
+#endif
diff --git a/src/shaders/SkPictureShader.cpp b/src/shaders/SkPictureShader.cpp
index 14ebae7..7320f7e 100644
--- a/src/shaders/SkPictureShader.cpp
+++ b/src/shaders/SkPictureShader.cpp
@@ -89,7 +89,7 @@
const Key& getKey() const override { return fKey; }
size_t bytesUsed() const override {
- // Just the record overhead -- the actual pixels are accounted by SkImageCacherator.
+ // Just the record overhead -- the actual pixels are accounted by SkImage_Lazy.
return sizeof(fKey) + sizeof(SkImageShader);
}
const char* getCategory() const override { return "bitmap-shader"; }