Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1548)

Unified Diff: src/gpu/SkGr.cpp

Issue 26734003: Proactive SkPixelRef invalidation (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: tweaks Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/gpu/SkGr.cpp
diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp
index 9cafbf69c0d030a281f4629c503cb52bcc61e0b1..7be53663cdbcdd7ba8cc67066279cd05b6ebcbc1 100644
--- a/src/gpu/SkGr.cpp
+++ b/src/gpu/SkGr.cpp
@@ -7,6 +7,9 @@
#include "SkGr.h"
#include "SkConfig8888.h"
+#include "SkMessageBus.h"
+#include "SkPixelRef.h"
+#include "GrResourceCache.h"
/* Fill out buffer with the compressed format Ganesh expects from a colortable
based bitmap. [palette (colortable) + indices].
@@ -86,6 +89,30 @@ static void generate_bitmap_texture_desc(const SkBitmap& bitmap, GrTextureDesc*
desc->fSampleCnt = 0;
}
+namespace {
+
+// When the SkPixelRef is invalidated, invalidate a corresponding GrResource described by key.
+class GrResourceInvalidator : public SkPixelRef::InvalidationListener {
+public:
+ explicit GrResourceInvalidator(GrResourceKey key) : fKey(key) {}
+private:
+ GrResourceKey fKey;
+
+ virtual void onInvalidate() SK_OVERRIDE {
+ const GrResourceInvalidatedMessage message = { fKey };
+ SkMessageBus<GrResourceInvalidatedMessage>::post(message);
+ }
+};
+
+} // namespace
+
+static void add_invalidation_listener(GrResourceKey key, SkPixelRef* pixelRef) {
+ SkASSERT(NULL != pixelRef);
+ if (pixelRef->addingAnInvalidationListenerMakesSense()) {
+ pixelRef->addInvalidationListener(SkNEW_ARGS(GrResourceInvalidator, (key)));
+ }
+}
+
static GrTexture* sk_gr_create_bitmap_texture(GrContext* ctx,
bool cache,
const GrTextureParams* params,
@@ -112,7 +139,12 @@ static GrTexture* sk_gr_create_bitmap_texture(GrContext* ctx,
if (cache) {
GrCacheID cacheID;
generate_bitmap_cache_id(origBitmap, &cacheID);
- return ctx->createTexture(params, desc, cacheID, storage.get(), bitmap->width());
+
+ GrResourceKey key;
+ GrTexture* result = ctx->createTexture(params, desc, cacheID,
+ storage.get(), bitmap->width(), &key);
+ add_invalidation_listener(key, origBitmap.pixelRef());
+ return result;
} else {
GrTexture* result = ctx->lockAndRefScratchTexture(desc,
GrContext::kExact_ScratchTexMatch);
@@ -137,8 +169,13 @@ static GrTexture* sk_gr_create_bitmap_texture(GrContext* ctx,
// This texture is likely to be used again so leave it in the cache
GrCacheID cacheID;
generate_bitmap_cache_id(origBitmap, &cacheID);
- return ctx->createTexture(params, desc, cacheID, bitmap->getPixels(), bitmap->rowBytes());
- } else {
+
+ GrResourceKey key;
+ GrTexture* result = ctx->createTexture(params, desc, cacheID,
+ bitmap->getPixels(), bitmap->rowBytes(), &key);
+ add_invalidation_listener(key, origBitmap.pixelRef());
+ return result;
+ } else {
// This texture is unlikely to be used again (in its present form) so
// just use a scratch texture. This will remove the texture from the
// cache so no one else can find it. Additionally, once unlocked, the

Powered by Google App Engine
This is Rietveld 408576698