aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/core
diff options
context:
space:
mode:
authorGravatar mike@reedtribe.org <mike@reedtribe.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-04-29 01:44:52 +0000
committerGravatar mike@reedtribe.org <mike@reedtribe.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-04-29 01:44:52 +0000
commite9e08cc7b29f97ee9e823e68c3daf0f55c84b21a (patch)
tree960da7d152e641e3715444198e42b7a0bfeb5265 /include/core
parente8f754a41ccaa87719839a5112e59e1b9a63a037 (diff)
rename SkPtrRecorder and related wrappers to SkPtrSet, since that is the pattern
is it providing. Also add a templated wrapper to handle typecasting of ptr types. git-svn-id: http://skia.googlecode.com/svn/trunk@1214 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'include/core')
-rw-r--r--include/core/SkFlattenable.h64
-rw-r--r--include/core/SkPtrRecorder.h32
2 files changed, 44 insertions, 52 deletions
diff --git a/include/core/SkFlattenable.h b/include/core/SkFlattenable.h
index ad4062fa9a..553eb6cbe0 100644
--- a/include/core/SkFlattenable.h
+++ b/include/core/SkFlattenable.h
@@ -118,48 +118,22 @@ private:
#include "SkPtrRecorder.h"
-class SkRefCntRecorder : public SkPtrRecorder {
+/**
+ * Subclass of SkTPtrSet specialed to call ref() and unref() when the
+ * base class's incPtr() and decPtr() are called. This makes it a valid owner
+ * of each ptr, which is released when the set is reset or destroyed.
+ */
+class SkRefCntSet : public SkTPtrSet<SkRefCnt*> {
public:
- virtual ~SkRefCntRecorder();
-
- /** Add a refcnt object to the set and ref it if not already present,
- or if it is already present, do nothing. Either way, returns 0 if obj
- is null, or a base-1 index if obj is not null.
- */
- uint32_t record(SkRefCnt* ref) {
- return this->recordPtr(ref);
- }
-
- // This does not change the owner counts on the objects
- void get(SkRefCnt* array[]) const {
- this->getPtrs((void**)array);
- }
-
+ virtual ~SkRefCntSet();
+
protected:
// overrides
virtual void incPtr(void*);
virtual void decPtr(void*);
-
-private:
- typedef SkPtrRecorder INHERITED;
};
-class SkFactoryRecorder : public SkPtrRecorder {
-public:
- /** Add a factory to the set. If it is null return 0, otherwise return a
- base-1 index for the factory.
- */
- uint32_t record(SkFlattenable::Factory fact) {
- return this->recordPtr((void*)fact);
- }
-
- void get(SkFlattenable::Factory array[]) const {
- this->getPtrs((void**)array);
- }
-
-private:
- typedef SkPtrRecorder INHERITED;
-};
+class SkFactorySet : public SkTPtrSet<SkFlattenable::Factory> {};
class SkFlattenableWriteBuffer : public SkWriter32 {
public:
@@ -171,14 +145,14 @@ public:
void writeFunctionPtr(void*);
void writeFlattenable(SkFlattenable* flattenable);
- SkRefCntRecorder* getTypefaceRecorder() const { return fTFRecorder; }
- SkRefCntRecorder* setTypefaceRecorder(SkRefCntRecorder*);
+ SkRefCntSet* getTypefaceRecorder() const { return fTFSet; }
+ SkRefCntSet* setTypefaceRecorder(SkRefCntSet*);
- SkRefCntRecorder* getRefCntRecorder() const { return fRCRecorder; }
- SkRefCntRecorder* setRefCntRecorder(SkRefCntRecorder*);
+ SkRefCntSet* getRefCntRecorder() const { return fRCSet; }
+ SkRefCntSet* setRefCntRecorder(SkRefCntSet*);
- SkFactoryRecorder* getFactoryRecorder() const { return fFactoryRecorder; }
- SkFactoryRecorder* setFactoryRecorder(SkFactoryRecorder*);
+ SkFactorySet* getFactoryRecorder() const { return fFactorySet; }
+ SkFactorySet* setFactoryRecorder(SkFactorySet*);
enum Flags {
kCrossProcess_Flag = 0x01
@@ -195,10 +169,10 @@ public:
bool persistTypeface() const { return (fFlags & kCrossProcess_Flag) != 0; }
private:
- Flags fFlags;
- SkRefCntRecorder* fTFRecorder;
- SkRefCntRecorder* fRCRecorder;
- SkFactoryRecorder* fFactoryRecorder;
+ Flags fFlags;
+ SkRefCntSet* fTFSet;
+ SkRefCntSet* fRCSet;
+ SkFactorySet* fFactorySet;
typedef SkWriter32 INHERITED;
};
diff --git a/include/core/SkPtrRecorder.h b/include/core/SkPtrRecorder.h
index 66950601a0..e6e8f55da5 100644
--- a/include/core/SkPtrRecorder.h
+++ b/include/core/SkPtrRecorder.h
@@ -14,8 +14,8 @@
* limitations under the License.
*/
-#ifndef SkPtrRecorder_DEFINED
-#define SkPtrRecorder_DEFINED
+#ifndef SkPtrSet_DEFINED
+#define SkPtrSet_DEFINED
#include "SkRefCnt.h"
#include "SkTDArray.h"
@@ -26,15 +26,15 @@
* and decPtr(). incPtr() is called each time a unique ptr is added ot the
* set. decPtr() is called on each ptr when the set is destroyed or reset.
*/
-class SkPtrRecorder : public SkRefCnt {
+class SkPtrSet : public SkRefCnt {
public:
/**
* Add the specified ptr to the set, returning a unique 32bit ID for it
* [1...N]. Duplicate ptrs will return the same ID.
*
- * If the ptr is NULL, it is not recorded, and 0 is returned.
+ * If the ptr is NULL, it is not added, and 0 is returned.
*/
- uint32_t recordPtr(void*);
+ uint32_t add(void*);
/**
* Return the number of (non-null) ptrs in the set.
@@ -48,7 +48,7 @@ public:
*
* incPtr() and decPtr() are not called during this operation.
*/
- void getPtrs(void* array[]) const;
+ void copyToArray(void* array[]) const;
/**
* Call decPtr() on each ptr in the set, and the reset the size of the set
@@ -67,7 +67,7 @@ private:
};
// we store the ptrs in sorted-order (using Cmp) so that we can efficiently
- // detect duplicates when recordPtr() is called. Hence we need to store the
+ // detect duplicates when add() is called. Hence we need to store the
// ptr and its ID/fIndex explicitly, since the ptr's position in the array
// is not related to its "index".
SkTDArray<Pair> fList;
@@ -77,4 +77,22 @@ private:
typedef SkRefCnt INHERITED;
};
+/**
+ * Templated wrapper for SkPtrSet, just meant to automate typecasting
+ * parameters to and from void* (which the base class expects).
+ */
+template <typename T> class SkTPtrSet : public SkPtrSet {
+public:
+ uint32_t add(T ptr) {
+ return this->INHERITED::add((void*)ptr);
+ }
+
+ void copyToArray(T* array) const {
+ this->INHERITED::copyToArray((void**)array);
+ }
+
+private:
+ typedef SkPtrSet INHERITED;
+};
+
#endif