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
diff --git a/src/core/SkFlattenable.cpp b/src/core/SkFlattenable.cpp
index dcdaa92..7ad1472 100644
--- a/src/core/SkFlattenable.cpp
+++ b/src/core/SkFlattenable.cpp
@@ -117,48 +117,45 @@
 SkFlattenableWriteBuffer::SkFlattenableWriteBuffer(size_t minSize) :
         INHERITED(minSize) {
     fFlags = (Flags)0;
-    fRCRecorder = NULL;
-    fTFRecorder = NULL;
-    fFactoryRecorder = NULL;
+    fRCSet = NULL;
+    fTFSet = NULL;
+    fFactorySet = NULL;
 }
 
 SkFlattenableWriteBuffer::~SkFlattenableWriteBuffer() {
-    SkSafeUnref(fRCRecorder);
-    SkSafeUnref(fTFRecorder);
-    SkSafeUnref(fFactoryRecorder);
+    SkSafeUnref(fRCSet);
+    SkSafeUnref(fTFSet);
+    SkSafeUnref(fFactorySet);
 }
 
-SkRefCntRecorder* SkFlattenableWriteBuffer::setRefCntRecorder(
-                                                    SkRefCntRecorder* rec) {
-    SkRefCnt_SafeAssign(fRCRecorder, rec);
+SkRefCntSet* SkFlattenableWriteBuffer::setRefCntRecorder(SkRefCntSet* rec) {
+    SkRefCnt_SafeAssign(fRCSet, rec);
     return rec;
 }
 
-SkRefCntRecorder* SkFlattenableWriteBuffer::setTypefaceRecorder(
-                                                    SkRefCntRecorder* rec) {
-    SkRefCnt_SafeAssign(fTFRecorder, rec);
+SkRefCntSet* SkFlattenableWriteBuffer::setTypefaceRecorder(SkRefCntSet* rec) {
+    SkRefCnt_SafeAssign(fTFSet, rec);
     return rec;
 }
 
-SkFactoryRecorder* SkFlattenableWriteBuffer::setFactoryRecorder(
-                                                    SkFactoryRecorder* rec) {
-    SkRefCnt_SafeAssign(fFactoryRecorder, rec);
+SkFactorySet* SkFlattenableWriteBuffer::setFactoryRecorder(SkFactorySet* rec) {
+    SkRefCnt_SafeAssign(fFactorySet, rec);
     return rec;
 }
 
 void SkFlattenableWriteBuffer::writeTypeface(SkTypeface* obj) {
-    if (NULL == obj || NULL == fTFRecorder) {
+    if (NULL == obj || NULL == fTFSet) {
         this->write32(0);
     } else {
-        this->write32(fTFRecorder->record(obj));
+        this->write32(fTFSet->add(obj));
     }
 }
 
 void SkFlattenableWriteBuffer::writeRefCnt(SkRefCnt* obj) {
-    if (NULL == obj || NULL == fRCRecorder) {
+    if (NULL == obj || NULL == fRCSet) {
         this->write32(0);
     } else {
-        this->write32(fRCRecorder->record(obj));
+        this->write32(fRCSet->add(obj));
     }
 }
 
@@ -168,8 +165,8 @@
         factory = flattenable->getFactory();
     }
 
-    if (fFactoryRecorder) {
-        this->write32(fFactoryRecorder->record(factory));
+    if (fFactorySet) {
+        this->write32(fFactorySet->add(factory));
     } else {
         this->writeFunctionPtr((void*)factory);
     }
@@ -193,16 +190,16 @@
 
 ///////////////////////////////////////////////////////////////////////////////
 
-SkRefCntRecorder::~SkRefCntRecorder() {
+SkRefCntSet::~SkRefCntSet() {
     // call this now, while our decPtr() is sill in scope
     this->reset();
 }
 
-void SkRefCntRecorder::incPtr(void* ptr) {
+void SkRefCntSet::incPtr(void* ptr) {
     ((SkRefCnt*)ptr)->ref();
 }
 
-void SkRefCntRecorder::decPtr(void* ptr) {
+void SkRefCntSet::decPtr(void* ptr) {
     ((SkRefCnt*)ptr)->unref();
 }
 
diff --git a/src/core/SkPictureFlat.cpp b/src/core/SkPictureFlat.cpp
index 3b02752..5c5ea0b 100644
--- a/src/core/SkPictureFlat.cpp
+++ b/src/core/SkPictureFlat.cpp
@@ -16,7 +16,7 @@
 }
 
 SkFlatBitmap* SkFlatBitmap::Flatten(SkChunkAlloc* heap, const SkBitmap& bitmap,
-                                    int index, SkRefCntRecorder* rec) {
+                                    int index, SkRefCntSet* rec) {
     SkFlattenableWriteBuffer buffer(1024);
     buffer.setRefCntRecorder(rec);
     
@@ -82,8 +82,8 @@
 ///////////////////////////////////////////////////////////////////////////////
 
 SkFlatPaint* SkFlatPaint::Flatten(SkChunkAlloc* heap, const SkPaint& paint,
-                                  int index, SkRefCntRecorder* rec,
-                                  SkRefCntRecorder* faceRecorder) {
+                                  int index, SkRefCntSet* rec,
+                                  SkRefCntSet* faceRecorder) {
     SkFlattenableWriteBuffer buffer(2*sizeof(SkPaint));
     buffer.setRefCntRecorder(rec);
     buffer.setTypefaceRecorder(faceRecorder);
@@ -221,7 +221,7 @@
     this->reset(NULL);
 }
 
-void SkRefCntPlayback::reset(const SkRefCntRecorder* rec) {
+void SkRefCntPlayback::reset(const SkRefCntSet* rec) {
     for (int i = 0; i < fCount; i++) {
         SkASSERT(fArray[i]);
         fArray[i]->unref();
@@ -231,7 +231,7 @@
     if (rec) {
         fCount = rec->count();
         fArray = SkNEW_ARRAY(SkRefCnt*, fCount);
-        rec->get(fArray);
+        rec->copyToArray(fArray);
         for (int i = 0; i < fCount; i++) {
             fArray[i]->ref();
         }
diff --git a/src/core/SkPictureFlat.h b/src/core/SkPictureFlat.h
index 54a02fb..dae7b8a 100644
--- a/src/core/SkPictureFlat.h
+++ b/src/core/SkPictureFlat.h
@@ -57,7 +57,7 @@
     
     int count() const { return fCount; }
     
-    void reset(const SkRefCntRecorder*);
+    void reset(const SkRefCntSet*);
 
     void setCount(int count);
     SkRefCnt* set(int index, SkRefCnt*);
@@ -121,7 +121,7 @@
 class SkFlatBitmap : public SkFlatData {
 public:
     static SkFlatBitmap* Flatten(SkChunkAlloc*, const SkBitmap&, int index,
-                                 SkRefCntRecorder*);
+                                 SkRefCntSet*);
 
     void unflatten(SkBitmap* bitmap, SkRefCntPlayback* rcp) const {
         SkFlattenableReadBuffer buffer(fBitmapData);
@@ -168,8 +168,8 @@
 class SkFlatPaint : public SkFlatData {
 public:
     static SkFlatPaint* Flatten(SkChunkAlloc* heap, const SkPaint& paint,
-                                int index, SkRefCntRecorder*,
-                                SkRefCntRecorder* faceRecorder);
+                                int index, SkRefCntSet*,
+                                SkRefCntSet* faceRecorder);
     
     void unflatten(SkPaint* result, SkRefCntPlayback* rcp,
                    SkTypefacePlayback* facePlayback) const {
diff --git a/src/core/SkPicturePlayback.cpp b/src/core/SkPicturePlayback.cpp
index a7e2d16..67b6865 100644
--- a/src/core/SkPicturePlayback.cpp
+++ b/src/core/SkPicturePlayback.cpp
@@ -65,10 +65,10 @@
 
     // copy over the refcnt dictionary to our reader
     //
-    fRCPlayback.reset(&record.fRCRecorder);
+    fRCPlayback.reset(&record.fRCSet);
     fRCPlayback.setupBuffer(fReader);
 
-    fTFPlayback.reset(&record.fTFRecorder);
+    fTFPlayback.reset(&record.fTFSet);
     fTFPlayback.setupBuffer(fReader);
 
     const SkTDArray<const SkFlatBitmap* >& bitmaps = record.getBitmaps();
@@ -297,14 +297,14 @@
     stream->write32(size);
 }
 
-static void writeFactories(SkWStream* stream, const SkFactoryRecorder& rec) {
+static void writeFactories(SkWStream* stream, const SkFactorySet& rec) {
     int count = rec.count();
 
     writeTagSize(stream, PICT_FACTORY_TAG, count);
 
     SkAutoSTMalloc<16, SkFlattenable::Factory> storage(count);
     SkFlattenable::Factory* array = (SkFlattenable::Factory*)storage.get();
-    rec.get(array);
+    rec.copyToArray(array);
 
     for (int i = 0; i < count; i++) {
         const char* name = SkFlattenable::FactoryToName(array[i]);
@@ -319,14 +319,14 @@
     }
 }
 
-static void writeTypefaces(SkWStream* stream, const SkRefCntRecorder& rec) {
+static void writeTypefaces(SkWStream* stream, const SkRefCntSet& rec) {
     int count = rec.count();
 
     writeTagSize(stream, PICT_TYPEFACE_TAG, count);
 
     SkAutoSTMalloc<16, SkTypeface*> storage(count);
     SkTypeface** array = (SkTypeface**)storage.get();
-    rec.get((SkRefCnt**)array);
+    rec.copyToArray((SkRefCnt**)array);
 
     for (int i = 0; i < count; i++) {
         array[i]->serialize(stream);
@@ -337,14 +337,14 @@
     writeTagSize(stream, PICT_READER_TAG, fReader.size());
     stream->write(fReader.base(), fReader.size());
 
-    SkRefCntRecorder  typefaceRecorder;
-    SkFactoryRecorder factRecorder;
+    SkRefCntSet  typefaceSet;
+    SkFactorySet factSet;
 
     SkFlattenableWriteBuffer buffer(1024);
 
     buffer.setFlags(SkFlattenableWriteBuffer::kCrossProcess_Flag);
-    buffer.setTypefaceRecorder(&typefaceRecorder);
-    buffer.setFactoryRecorder(&factRecorder);
+    buffer.setTypefaceRecorder(&typefaceSet);
+    buffer.setFactoryRecorder(&factSet);
 
     int i;
 
@@ -385,8 +385,8 @@
 
     // now we can write to the stream again
 
-    writeFactories(stream, factRecorder);
-    writeTypefaces(stream, typefaceRecorder);
+    writeFactories(stream, factSet);
+    writeTypefaces(stream, typefaceSet);
 
     writeTagSize(stream, PICT_PICTURE_TAG, fPictureCount);
     for (i = 0; i < fPictureCount; i++) {
diff --git a/src/core/SkPictureRecord.cpp b/src/core/SkPictureRecord.cpp
index a48d0e4..6b2b330 100644
--- a/src/core/SkPictureRecord.cpp
+++ b/src/core/SkPictureRecord.cpp
@@ -440,8 +440,8 @@
     fRestoreOffsetStack.setCount(1);
     fRestoreOffsetStack.top() = 0;
 
-    fRCRecorder.reset();
-    fTFRecorder.reset();
+    fRCSet.reset();
+    fTFSet.reset();
 }
 
 void SkPictureRecord::addBitmap(const SkBitmap& bitmap) {
@@ -544,7 +544,7 @@
 
 int SkPictureRecord::find(SkTDArray<const SkFlatBitmap* >& bitmaps, const SkBitmap& bitmap) {
     SkFlatBitmap* flat = SkFlatBitmap::Flatten(&fHeap, bitmap, fBitmapIndex,
-                                               &fRCRecorder);
+                                               &fRCSet);
     int index = SkTSearch<SkFlatData>((const SkFlatData**) bitmaps.begin(),
         bitmaps.count(), (SkFlatData*) flat, sizeof(flat), &SkFlatData::Compare);
     if (index >= 0) {
@@ -577,7 +577,7 @@
     }
 
     SkFlatPaint* flat = SkFlatPaint::Flatten(&fHeap, *paint, fPaintIndex,
-                                             &fRCRecorder, &fTFRecorder);
+                                             &fRCSet, &fTFSet);
     int index = SkTSearch<SkFlatData>((const SkFlatData**) paints.begin(),
         paints.count(), (SkFlatData*) flat, sizeof(flat), &SkFlatData::Compare);
     if (index >= 0) {
diff --git a/src/core/SkPictureRecord.h b/src/core/SkPictureRecord.h
index 14d1ffd..e0d6a50 100644
--- a/src/core/SkPictureRecord.h
+++ b/src/core/SkPictureRecord.h
@@ -175,8 +175,8 @@
     SkTDArray<SkPicture*> fPictureRefs;
     SkTDArray<SkShape*> fShapes;
 
-    SkRefCntRecorder fRCRecorder;
-    SkRefCntRecorder fTFRecorder;
+    SkRefCntSet fRCSet;
+    SkRefCntSet fTFSet;
     
     uint32_t fRecordFlags;
 
diff --git a/src/core/SkPtrRecorder.cpp b/src/core/SkPtrRecorder.cpp
index 4f774ec..fa640cb 100644
--- a/src/core/SkPtrRecorder.cpp
+++ b/src/core/SkPtrRecorder.cpp
@@ -1,7 +1,7 @@
 #include "SkPtrRecorder.h"
 #include "SkTSearch.h"
 
-void SkPtrRecorder::reset() {
+void SkPtrSet::reset() {
     Pair* p = fList.begin();
     Pair* stop = fList.end();
     while (p < stop) {
@@ -11,11 +11,11 @@
     fList.reset();
 }
 
-int SkPtrRecorder::Cmp(const Pair& a, const Pair& b) {
+int SkPtrSet::Cmp(const Pair& a, const Pair& b) {
     return (char*)a.fPtr - (char*)b.fPtr;
 }
 
-uint32_t SkPtrRecorder::recordPtr(void* ptr) {
+uint32_t SkPtrSet::add(void* ptr) {
     if (NULL == ptr) {
         return 0;
     }
@@ -36,7 +36,7 @@
     }
 }
 
-void SkPtrRecorder::getPtrs(void* array[]) const {
+void SkPtrSet::copyToArray(void* array[]) const {
     int count = fList.count();
     if (count > 0) {
         SkASSERT(array);