Chromium Code Reviews| Index: include/core/SkPixelRef.h |
| diff --git a/include/core/SkPixelRef.h b/include/core/SkPixelRef.h |
| index 64e08765bed8a3c1e1b9f3f1a652e9959b0a1865..fa918cb8723d34309585407ee9e32ad967a2599a 100644 |
| --- a/include/core/SkPixelRef.h |
| +++ b/include/core/SkPixelRef.h |
| @@ -14,6 +14,7 @@ |
| #include "SkRefCnt.h" |
| #include "SkString.h" |
| #include "SkFlattenable.h" |
| +#include "SkTDArray.h" |
| #ifdef SK_DEBUG |
| /** |
| @@ -49,6 +50,7 @@ public: |
| SK_DECLARE_INST_COUNT(SkPixelRef) |
| explicit SkPixelRef(SkBaseMutex* mutex = NULL); |
| + virtual ~SkPixelRef(); |
| /** Return the pixel memory returned from lockPixels, or null if the |
| lockCount is 0. |
| @@ -207,6 +209,22 @@ public: |
| virtual void globalUnref(); |
| #endif |
| + // Register a listener that may be called the next time our generation ID changes. |
| + // |
| + // We'll only call the listener if we're confident that we are the only SkPixelRef with this |
| + // generation ID. If our generation ID changes and we decide not to call the listener, we'll |
| + // never call it: you must add a new listener for each generation ID change. We also won't call |
| + // the listener when we're certain no one knows what our generation ID is. |
| + // |
| + // This can be used to invalidate caches keyed by SkPixelRef generation ID. |
|
bsalomon
2013/10/23 15:32:28
clear to me
scroggo
2013/10/23 15:39:19
Thanks for the new comments, which are much cleare
mtklein
2013/10/23 16:07:10
Changed all the names to variants of GenIDChangeLi
|
| + struct InvalidationListener { |
| + virtual ~InvalidationListener() {} |
| + virtual void onInvalidate() = 0; |
| + }; |
| + |
| + // Takes ownership of listener. |
| + void addInvalidationListener(InvalidationListener* listener); |
| + |
| protected: |
| /** Called when the lockCount goes from 0 to 1. The caller will have already |
| acquire a mutex for thread safety, so this method need not do that. |
| @@ -252,17 +270,15 @@ protected: |
| void setPreLocked(void* pixels, SkColorTable* ctable); |
| private: |
| - |
| SkBaseMutex* fMutex; // must remain in scope for the life of this object |
| void* fPixels; |
| SkColorTable* fColorTable; // we do not track ownership, subclass does |
| int fLockCount; |
| mutable uint32_t fGenerationID; |
| + mutable bool fUniqueGenerationID; |
| - // SkBitmap is only a friend so that when copying, it can modify the new SkPixelRef to have the |
| - // same fGenerationID as the original. |
| - friend class SkBitmap; |
| + SkTDArray<InvalidationListener*> fInvalidationListeners; // pointers are owned |
| SkString fURI; |
| @@ -271,8 +287,16 @@ private: |
| // only ever set in constructor, const after that |
| bool fPreLocked; |
| + void needsNewGenID(); |
| + void callInvalidationListeners(); |
|
scroggo
2013/10/23 15:39:19
+1 to the new name (unless you change the name of
|
| + |
| void setMutex(SkBaseMutex* mutex); |
| + // When copying a bitmap to another with the same shape and config, we can safely |
| + // clone the pixelref generation ID too, which makes them equivalent under caching. |
| + friend class SkBitmap; // only for cloneGenID |
| + void cloneGenID(const SkPixelRef&); |
| + |
| typedef SkFlattenable INHERITED; |
| }; |