diff options
-rw-r--r-- | gn/core.gni | 2 | ||||
-rw-r--r-- | src/core/SkImageCacherator.h | 48 | ||||
-rw-r--r-- | src/gpu/GrImageTextureMaker.cpp | 22 | ||||
-rw-r--r-- | src/gpu/GrImageTextureMaker.h | 5 | ||||
-rw-r--r-- | src/image/SkImage.cpp | 7 | ||||
-rw-r--r-- | src/image/SkImage_Base.h | 10 | ||||
-rw-r--r-- | src/image/SkImage_Lazy.cpp | 130 | ||||
-rw-r--r-- | src/image/SkImage_Lazy.h | 122 | ||||
-rw-r--r-- | src/shaders/SkPictureShader.cpp | 2 |
9 files changed, 153 insertions, 195 deletions
diff --git a/gn/core.gni b/gn/core.gni index f8e955b4f7..4da77cb864 100644 --- a/gn/core.gni +++ b/gn/core.gni @@ -160,7 +160,6 @@ skia_core_sources = [ "$_src/core/SkImageFilterCache.cpp", "$_src/core/SkImageFilterCache.h", "$_src/core/SkImageInfo.cpp", - "$_src/core/SkImageCacherator.h", "$_src/core/SkImageGenerator.cpp", "$_src/core/SkLights.cpp", "$_src/core/SkLineClipper.cpp", @@ -350,6 +349,7 @@ skia_core_sources = [ # "$_src/image/SkImage_Gpu.cpp", "$_src/image/SkImage_Lazy.cpp", + "$_src/image/SkImage_Lazy.h", "$_src/image/SkImage_Raster.cpp", "$_src/image/SkSurface.cpp", "$_src/image/SkSurface_Base.h", diff --git a/src/core/SkImageCacherator.h b/src/core/SkImageCacherator.h deleted file mode 100644 index 5ba4e6857c..0000000000 --- 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 a86cefd72e..0de25739be 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 @@ GrImageTextureMaker::GrImageTextureMaker(GrContext* context, const SkImage* clie 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 f1f647bac8..bb3e830176 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 @@ protected: 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 b857a3588a..3be9f3791e 100644 --- a/src/image/SkImage.cpp +++ b/src/image/SkImage.cpp @@ -201,13 +201,6 @@ SkImage_Base::~SkImage_Base() { 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 e6598f8d06..d9c738a719 100644 --- a/src/image/SkImage_Base.h +++ b/src/image/SkImage_Base.h @@ -22,7 +22,6 @@ class GrTexture; #include <new> class GrSamplerState; -class SkImageCacherator; enum { kNeedNewImageUniqueID = 0 @@ -66,8 +65,6 @@ public: 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 @@ public: 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 454c867a01..15722fe4e0 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 @@ private: 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 @@ SkImage_Lazy::SkImage_Lazy(Validator* validator) 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 @@ sk_sp<SkImage> SkImage::MakeFromGenerator(std::unique_ptr<SkImageGenerator> gene ////////////////////////////////////////////////////////////////////////////////////////////////// -/** - * 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 @@ static void set_key_on_proxy(GrProxyProvider* proxyProvider, * 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 0000000000..b13cd1653f --- /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 14ebae7a26..7320f7eb67 100644 --- a/src/shaders/SkPictureShader.cpp +++ b/src/shaders/SkPictureShader.cpp @@ -89,7 +89,7 @@ struct BitmapShaderRec : public SkResourceCache::Rec { 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"; } |