Have SkImage_Base send out UniqueKey invalidations to GPU backend when destroyed.
This CL currently only adds invalidation messages for texture proxies created through SkImage_Lazy. Bug: skia: Change-Id: I7f53e5b4d40e9fdb4941edc80656c86690e4e4a9 Reviewed-on: https://skia-review.googlesource.com/152323 Commit-Queue: Greg Daniel <egdaniel@google.com> Reviewed-by: Brian Salomon <bsalomon@google.com>
This commit is contained in:
parent
7b429aed84
commit
2ad0820b23
@ -201,6 +201,13 @@ 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,
|
||||
|
@ -13,9 +13,10 @@
|
||||
#include <atomic>
|
||||
|
||||
#if SK_SUPPORT_GPU
|
||||
#include "GrTextureProxy.h"
|
||||
#include "GrTextureProxy.h"
|
||||
#include "SkTDArray.h"
|
||||
|
||||
class GrTexture;
|
||||
class GrTexture;
|
||||
#endif
|
||||
|
||||
#include <new>
|
||||
@ -96,6 +97,13 @@ 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;
|
||||
|
@ -572,6 +572,8 @@ sk_sp<GrTextureProxy> SkImage_Lazy::lockTextureProxy(GrContext* ctx,
|
||||
kLockTexturePathCount);
|
||||
set_key_on_proxy(proxyProvider, proxy.get(), nullptr, key);
|
||||
if (!willBeMipped || GrMipMapped::kYes == proxy->mipMapped()) {
|
||||
*fUniqueKeyInvalidatedMessages.append() =
|
||||
new GrUniqueKeyInvalidatedMessage(key, ctx->uniqueID());
|
||||
return proxy;
|
||||
}
|
||||
}
|
||||
@ -600,6 +602,8 @@ sk_sp<GrTextureProxy> SkImage_Lazy::lockTextureProxy(GrContext* ctx,
|
||||
SK_HISTOGRAM_ENUMERATION("LockTexturePath", kYUV_LockTexturePath,
|
||||
kLockTexturePathCount);
|
||||
set_key_on_proxy(proxyProvider, proxy.get(), nullptr, key);
|
||||
*fUniqueKeyInvalidatedMessages.append() =
|
||||
new GrUniqueKeyInvalidatedMessage(key, ctx->uniqueID());
|
||||
return proxy;
|
||||
}
|
||||
}
|
||||
@ -618,6 +622,8 @@ sk_sp<GrTextureProxy> SkImage_Lazy::lockTextureProxy(GrContext* ctx,
|
||||
SK_HISTOGRAM_ENUMERATION("LockTexturePath", kRGBA_LockTexturePath,
|
||||
kLockTexturePathCount);
|
||||
set_key_on_proxy(proxyProvider, proxy.get(), nullptr, key);
|
||||
*fUniqueKeyInvalidatedMessages.append() =
|
||||
new GrUniqueKeyInvalidatedMessage(key, ctx->uniqueID());
|
||||
return proxy;
|
||||
}
|
||||
}
|
||||
@ -629,6 +635,8 @@ sk_sp<GrTextureProxy> SkImage_Lazy::lockTextureProxy(GrContext* ctx,
|
||||
// generate the rest of the mips.
|
||||
SkASSERT(willBeMipped);
|
||||
SkASSERT(GrMipMapped::kNo == proxy->mipMapped());
|
||||
*fUniqueKeyInvalidatedMessages.append() =
|
||||
new GrUniqueKeyInvalidatedMessage(key, ctx->uniqueID());
|
||||
if (auto mippedProxy = GrCopyBaseMipMapToTextureProxy(ctx, proxy.get())) {
|
||||
set_key_on_proxy(proxyProvider, mippedProxy.get(), proxy.get(), key);
|
||||
return mippedProxy;
|
||||
|
Loading…
Reference in New Issue
Block a user