Replace SkTScopedPtr with SkAutoTDelete in Skia.
BUG=
R=djsollen@google.com, reed@google.com, vandebo@chromium.org
Author: mtklein@google.com
Review URL: https://chromiumcodereview.appspot.com/23621005
git-svn-id: http://skia.googlecode.com/svn/trunk@11016 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/experimental/SimpleiOSApp/SimpleiOSApp.xcodeproj/project.pbxproj b/experimental/SimpleiOSApp/SimpleiOSApp.xcodeproj/project.pbxproj
index 977f6da..4c1a9a3 100755
--- a/experimental/SimpleiOSApp/SimpleiOSApp.xcodeproj/project.pbxproj
+++ b/experimental/SimpleiOSApp/SimpleiOSApp.xcodeproj/project.pbxproj
@@ -612,7 +612,6 @@
26D90D2A140D51290036A311 /* SkTDStack.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SkTDStack.h; path = core/SkTDStack.h; sourceTree = "<group>"; };
26D90D2B140D51290036A311 /* SkTDict.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SkTDict.h; path = core/SkTDict.h; sourceTree = "<group>"; };
26D90D2C140D51290036A311 /* SkTRegistry.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SkTRegistry.h; path = core/SkTRegistry.h; sourceTree = "<group>"; };
- 26D90D2D140D51290036A311 /* SkTScopedPtr.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SkTScopedPtr.h; path = core/SkTScopedPtr.h; sourceTree = "<group>"; };
26D90D2E140D51290036A311 /* SkTSearch.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SkTSearch.h; path = core/SkTSearch.h; sourceTree = "<group>"; };
26D90D2F140D51290036A311 /* SkTemplates.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SkTemplates.h; path = core/SkTemplates.h; sourceTree = "<group>"; };
26D90D30140D51290036A311 /* SkThread.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SkThread.h; path = core/SkThread.h; sourceTree = "<group>"; };
@@ -1486,7 +1485,6 @@
26D90D2A140D51290036A311 /* SkTDStack.h */,
26D90D2B140D51290036A311 /* SkTDict.h */,
26D90D2C140D51290036A311 /* SkTRegistry.h */,
- 26D90D2D140D51290036A311 /* SkTScopedPtr.h */,
26D90D2E140D51290036A311 /* SkTSearch.h */,
26D90D2F140D51290036A311 /* SkTemplates.h */,
26D90D30140D51290036A311 /* SkThread.h */,
diff --git a/experimental/iOSSampleApp/iOSSampleApp.xcodeproj/project.pbxproj b/experimental/iOSSampleApp/iOSSampleApp.xcodeproj/project.pbxproj
index f4516cd..b0016f8 100755
--- a/experimental/iOSSampleApp/iOSSampleApp.xcodeproj/project.pbxproj
+++ b/experimental/iOSSampleApp/iOSSampleApp.xcodeproj/project.pbxproj
@@ -661,7 +661,6 @@
260E01F713B1225D0064D447 /* SkTDStack.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SkTDStack.h; path = core/SkTDStack.h; sourceTree = "<group>"; };
260E01F813B1225D0064D447 /* SkTDict.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SkTDict.h; path = core/SkTDict.h; sourceTree = "<group>"; };
260E01F913B1225D0064D447 /* SkTRegistry.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SkTRegistry.h; path = core/SkTRegistry.h; sourceTree = "<group>"; };
- 260E01FA13B1225D0064D447 /* SkTScopedPtr.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SkTScopedPtr.h; path = core/SkTScopedPtr.h; sourceTree = "<group>"; };
260E01FB13B1225D0064D447 /* SkTSearch.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SkTSearch.h; path = core/SkTSearch.h; sourceTree = "<group>"; };
260E01FC13B1225D0064D447 /* SkTemplates.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SkTemplates.h; path = core/SkTemplates.h; sourceTree = "<group>"; };
260E01FD13B1225D0064D447 /* SkThread.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SkThread.h; path = core/SkThread.h; sourceTree = "<group>"; };
@@ -1675,7 +1674,6 @@
260E01F713B1225D0064D447 /* SkTDStack.h */,
260E01F813B1225D0064D447 /* SkTDict.h */,
260E01F913B1225D0064D447 /* SkTRegistry.h */,
- 260E01FA13B1225D0064D447 /* SkTScopedPtr.h */,
260E01FB13B1225D0064D447 /* SkTSearch.h */,
260E01FC13B1225D0064D447 /* SkTemplates.h */,
260E01FD13B1225D0064D447 /* SkThread.h */,
diff --git a/gyp/core.gypi b/gyp/core.gypi
index dbc3291..c9deb06 100644
--- a/gyp/core.gypi
+++ b/gyp/core.gypi
@@ -284,7 +284,6 @@
'<(skia_include_path)/core/SkTInternalLList.h',
'<(skia_include_path)/core/SkTileGridPicture.h',
'<(skia_include_path)/core/SkTRegistry.h',
- '<(skia_include_path)/core/SkTScopedPtr.h',
'<(skia_include_path)/core/SkTSearch.h',
'<(skia_include_path)/core/SkTemplates.h',
'<(skia_include_path)/core/SkThread.h',
diff --git a/gyp/public_headers.gypi b/gyp/public_headers.gypi
index 472fe29..d770349 100644
--- a/gyp/public_headers.gypi
+++ b/gyp/public_headers.gypi
@@ -209,7 +209,6 @@
'core/SkCanvas.h',
'core/SkPicture.h',
'core/SkClipStack.h',
- 'core/SkTScopedPtr.h',
'core/SkXfermode.h',
'core/SkColorFilter.h',
'core/SkRegion.h',
diff --git a/include/core/SkAdvancedTypefaceMetrics.h b/include/core/SkAdvancedTypefaceMetrics.h
index acfd86e..e75365b 100755
--- a/include/core/SkAdvancedTypefaceMetrics.h
+++ b/include/core/SkAdvancedTypefaceMetrics.h
@@ -15,7 +15,6 @@
#include "SkString.h"
#include "SkTDArray.h"
#include "SkTemplates.h"
-#include "SkTScopedPtr.h"
/** \class SkAdvancedTypefaceMetrics
@@ -90,7 +89,7 @@
uint16_t fStartId;
uint16_t fEndId;
SkTDArray<Data> fAdvance;
- SkTScopedPtr<AdvanceMetric<Data> > fNext;
+ SkAutoTDelete<AdvanceMetric<Data> > fNext;
};
struct VerticalMetric {
@@ -102,12 +101,12 @@
typedef AdvanceMetric<VerticalMetric> VerticalAdvanceRange;
// This is indexed by glyph id.
- SkTScopedPtr<WidthRange> fGlyphWidths;
+ SkAutoTDelete<WidthRange> fGlyphWidths;
// Only used for Vertical CID fonts.
- SkTScopedPtr<VerticalAdvanceRange> fVerticalMetrics;
+ SkAutoTDelete<VerticalAdvanceRange> fVerticalMetrics;
// The names of each glyph, only populated for postscript fonts.
- SkTScopedPtr<SkAutoTArray<SkString> > fGlyphNames;
+ SkAutoTDelete<SkAutoTArray<SkString> > fGlyphNames;
// The mapping from glyph to Unicode, only populated if
// kToUnicode_PerGlyphInfo is passed to GetAdvancedTypefaceMetrics.
@@ -125,7 +124,7 @@
template <typename Data>
SkAdvancedTypefaceMetrics::AdvanceMetric<Data>* appendRange(
- SkTScopedPtr<SkAdvancedTypefaceMetrics::AdvanceMetric<Data> >* nextSlot,
+ SkAutoTDelete<SkAdvancedTypefaceMetrics::AdvanceMetric<Data> >* nextSlot,
int startId);
template <typename Data>
diff --git a/include/core/SkTScopedPtr.h b/include/core/SkTScopedPtr.h
deleted file mode 100644
index 580d72f..0000000
--- a/include/core/SkTScopedPtr.h
+++ /dev/null
@@ -1,76 +0,0 @@
-
-/*
- * Copyright 2011 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-
-#ifndef SkTScopedPtr_DEFINED
-#define SkTScopedPtr_DEFINED
-
-#include "SkTypes.h"
-
-/** \class SkTScopedPtr
- A SkTScopedPtr<T> is like a T*, except that the destructor of SkTScopedPtr<T>
- automatically deletes the pointer it holds (if any). That is, SkTScopedPtr<T>
- owns the T object that it points to. Like a T*, a SkTScopedPtr<T> may hold
- either NULL or a pointer to a T object. Also like T*, SkTScopedPtr<T> is
- thread-compatible, and once you dereference it, you get the threadsafety
- guarantees of T.
-
- The size of a SkTScopedPtr is small: sizeof(SkTScopedPtr<T>) == sizeof(T*)
-*/
-template <typename T> class SkTScopedPtr : SkNoncopyable {
-public:
- explicit SkTScopedPtr(T* o = NULL) : fObj(o) {}
- ~SkTScopedPtr() {
- enum { kTypeMustBeComplete = sizeof(T) };
- delete fObj;
- }
-
- /** Delete the current object, if any. Then take ownership of the
- passed object.
- */
- void reset(T* o = NULL) {
- if (o != fObj) {
- enum { kTypeMustBeComplete = sizeof(T) };
- delete fObj;
- fObj = o;
- }
- }
-
- /** Without deleting the current object, return it and forget about it.
- Similar to calling get() and reset(), but the object is not deleted.
- */
- T* release() {
- T* retVal = fObj;
- fObj = NULL;
- return retVal;
- }
-
- T& operator*() const {
- SkASSERT(fObj != NULL);
- return *fObj;
- }
- T* operator->() const {
- SkASSERT(fObj != NULL);
- return fObj;
- }
- T* get() const { return fObj; }
-
- bool operator==(T* o) const { return fObj == o; }
- bool operator!=(T* o) const { return fObj != o; }
-
-private:
- T* fObj;
-
- // Forbid comparison of SkTScopedPtr types. If T2 != T, it doesn't make
- // sense, and if T2 == T, it still doesn't make sense because the same
- // object can't be owned by two different scoped_ptrs.
- template <class T2> bool operator==(SkTScopedPtr<T2> const& o2) const;
- template <class T2> bool operator!=(SkTScopedPtr<T2> const& o2) const;
-};
-
-#endif
diff --git a/include/core/SkTemplates.h b/include/core/SkTemplates.h
index e49cc47..c63a114 100644
--- a/include/core/SkTemplates.h
+++ b/include/core/SkTemplates.h
@@ -98,6 +98,16 @@
T* fObj;
};
+/** \class SkAutoTDelete
+ An SkAutoTDelete<T> is like a T*, except that the destructor of SkAutoTDelete<T>
+ automatically deletes the pointer it holds (if any). That is, SkAutoTDelete<T>
+ owns the T object that it points to. Like a T*, an SkAutoTDelete<T> may hold
+ either NULL or a pointer to a T object. Also like T*, SkAutoTDelete<T> is
+ thread-compatible, and once you dereference it, you get the threadsafety
+ guarantees of T.
+
+ The size of a SkAutoTDelete is small: sizeof(SkAutoTDelete<T>) == sizeof(T*)
+*/
template <typename T> class SkAutoTDelete : SkNoncopyable {
public:
SkAutoTDelete(T* obj = NULL) : fObj(obj) {}
diff --git a/include/pdf/SkPDFDevice.h b/include/pdf/SkPDFDevice.h
index 978dc1e..8ac227d 100644
--- a/include/pdf/SkPDFDevice.h
+++ b/include/pdf/SkPDFDevice.h
@@ -18,7 +18,7 @@
#include "SkRefCnt.h"
#include "SkStream.h"
#include "SkTDArray.h"
-#include "SkTScopedPtr.h"
+#include "SkTemplates.h"
class SkPDFArray;
class SkPDFDevice;
@@ -216,21 +216,21 @@
SkTDArray<SkPDFFont*> fFontResources;
SkTDArray<SkPDFObject*> fShaderResources;
- SkTScopedPtr<ContentEntry> fContentEntries;
+ SkAutoTDelete<ContentEntry> fContentEntries;
ContentEntry* fLastContentEntry;
- SkTScopedPtr<ContentEntry> fMarginContentEntries;
+ SkAutoTDelete<ContentEntry> fMarginContentEntries;
ContentEntry* fLastMarginContentEntry;
DrawingArea fDrawingArea;
const SkClipStack* fClipStack;
// Accessor and setter functions based on the current DrawingArea.
- SkTScopedPtr<ContentEntry>* getContentEntries();
+ SkAutoTDelete<ContentEntry>* getContentEntries();
ContentEntry* getLastContentEntry();
void setLastContentEntry(ContentEntry* contentEntry);
// Glyph ids used for each font on this device.
- SkTScopedPtr<SkPDFGlyphSetMap> fFontGlyphUsage;
+ SkAutoTDelete<SkPDFGlyphSetMap> fFontGlyphUsage;
EncodeToDCTStream fEncoder;
diff --git a/include/pdf/SkPDFDocument.h b/include/pdf/SkPDFDocument.h
index 31c6f9b..9f651fd 100644
--- a/include/pdf/SkPDFDocument.h
+++ b/include/pdf/SkPDFDocument.h
@@ -13,7 +13,7 @@
#include "SkAdvancedTypefaceMetrics.h"
#include "SkRefCnt.h"
#include "SkTDArray.h"
-#include "SkTScopedPtr.h"
+#include "SkTemplates.h"
class SkPDFCatalog;
class SkPDFDevice;
@@ -74,7 +74,7 @@
int counts[SkAdvancedTypefaceMetrics::kNotEmbeddable_Font + 1]) const;
private:
- SkTScopedPtr<SkPDFCatalog> fCatalog;
+ SkAutoTDelete<SkPDFCatalog> fCatalog;
int64_t fXRefFileOffset;
SkTDArray<SkPDFPage*> fPages;
diff --git a/include/utils/win/SkTScopedComPtr.h b/include/utils/win/SkTScopedComPtr.h
index 8f3c22a..8f18a42 100644
--- a/include/utils/win/SkTScopedComPtr.h
+++ b/include/utils/win/SkTScopedComPtr.h
@@ -6,8 +6,8 @@
* found in the LICENSE file.
*/
-#ifndef SkSkTScopedPtr_DEFINED
-#define SkSkTScopedPtr_DEFINED
+#ifndef SkTScopedComPtr_DEFINED
+#define SkTScopedComPtr_DEFINED
#include "SkTypes.h"
#include "SkTemplates.h"
diff --git a/src/core/SkAdvancedTypefaceMetrics.cpp b/src/core/SkAdvancedTypefaceMetrics.cpp
index defe68c..c7ed34d 100644
--- a/src/core/SkAdvancedTypefaceMetrics.cpp
+++ b/src/core/SkAdvancedTypefaceMetrics.cpp
@@ -72,7 +72,7 @@
template <typename Data>
SkAdvancedTypefaceMetrics::AdvanceMetric<Data>* appendRange(
- SkTScopedPtr<SkAdvancedTypefaceMetrics::AdvanceMetric<Data> >* nextSlot,
+ SkAutoTDelete<SkAdvancedTypefaceMetrics::AdvanceMetric<Data> >* nextSlot,
int startId) {
nextSlot->reset(new SkAdvancedTypefaceMetrics::AdvanceMetric<Data>);
resetRange(nextSlot->get(), startId);
@@ -148,7 +148,7 @@
// d. Removing a leading 0/don't cares is a win because it is omitted
// e. Removing 2 repeating advances is a win
- SkTScopedPtr<SkAdvancedTypefaceMetrics::AdvanceMetric<Data> > result;
+ SkAutoTDelete<SkAdvancedTypefaceMetrics::AdvanceMetric<Data> > result;
SkAdvancedTypefaceMetrics::AdvanceMetric<Data>* curRange;
SkAdvancedTypefaceMetrics::AdvanceMetric<Data>* prevRange = NULL;
Data lastAdvance = kInvalidAdvance;
@@ -245,12 +245,12 @@
if (curRange->fStartId == lastIndex) {
SkASSERT(prevRange);
SkASSERT(prevRange->fNext->fStartId == lastIndex);
- prevRange->fNext.reset();
+ prevRange->fNext.free();
} else {
finishRange(curRange, lastIndex - 1,
SkAdvancedTypefaceMetrics::WidthRange::kRange);
}
- return result.release();
+ return result.detach();
}
// Make AdvanceMetric template functions available for linking with typename
@@ -287,7 +287,7 @@
SkAdvancedTypefaceMetrics::WidthRange* range,
int startId);
template SkAdvancedTypefaceMetrics::WidthRange* appendRange(
- SkTScopedPtr<SkAdvancedTypefaceMetrics::WidthRange >* nextSlot,
+ SkAutoTDelete<SkAdvancedTypefaceMetrics::WidthRange >* nextSlot,
int startId);
template void finishRange<int16_t>(
SkAdvancedTypefaceMetrics::WidthRange* range,
@@ -298,7 +298,7 @@
SkAdvancedTypefaceMetrics::VerticalAdvanceRange* range,
int startId);
template SkAdvancedTypefaceMetrics::VerticalAdvanceRange* appendRange(
- SkTScopedPtr<SkAdvancedTypefaceMetrics::VerticalAdvanceRange >*
+ SkAutoTDelete<SkAdvancedTypefaceMetrics::VerticalAdvanceRange >*
nextSlot,
int startId);
template void finishRange<SkAdvancedTypefaceMetrics::VerticalMetric>(
diff --git a/src/pdf/SkPDFDevice.cpp b/src/pdf/SkPDFDevice.cpp
index 02dda02..bd26311 100644
--- a/src/pdf/SkPDFDevice.cpp
+++ b/src/pdf/SkPDFDevice.cpp
@@ -580,14 +580,14 @@
struct ContentEntry {
GraphicStateEntry fState;
SkDynamicMemoryWStream fContent;
- SkTScopedPtr<ContentEntry> fNext;
+ SkAutoTDelete<ContentEntry> fNext;
// If the stack is too deep we could get Stack Overflow.
// So we manually destruct the object.
~ContentEntry() {
- ContentEntry* val = fNext.release();
+ ContentEntry* val = fNext.detach();
while (val != NULL) {
- ContentEntry* valNext = val->fNext.release();
+ ContentEntry* valNext = val->fNext.detach();
// When the destructor is called, fNext is NULL and exits.
delete val;
val = valNext;
@@ -715,12 +715,12 @@
void SkPDFDevice::init() {
fAnnotations = NULL;
fResourceDict = NULL;
- fContentEntries.reset();
+ fContentEntries.free();
fLastContentEntry = NULL;
- fMarginContentEntries.reset();
+ fMarginContentEntries.free();
fLastMarginContentEntry = NULL;
fDrawingArea = kContent_DrawingArea;
- if (fFontGlyphUsage == NULL) {
+ if (fFontGlyphUsage.get() == NULL) {
fFontGlyphUsage.reset(new SkPDFGlyphSetMap());
}
}
@@ -1204,7 +1204,7 @@
}
}
-SkTScopedPtr<ContentEntry>* SkPDFDevice::getContentEntries() {
+SkAutoTDelete<ContentEntry>* SkPDFDevice::getContentEntries() {
if (fDrawingArea == kContent_DrawingArea) {
return &fContentEntries;
} else {
@@ -1650,7 +1650,7 @@
}
ContentEntry* entry;
- SkTScopedPtr<ContentEntry> newEntry;
+ SkAutoTDelete<ContentEntry> newEntry;
ContentEntry* lastContentEntry = getLastContentEntry();
if (lastContentEntry && lastContentEntry->fContent.getOffset() == 0) {
@@ -1667,18 +1667,18 @@
return lastContentEntry;
}
- SkTScopedPtr<ContentEntry>* contentEntries = getContentEntries();
+ SkAutoTDelete<ContentEntry>* contentEntries = getContentEntries();
if (!lastContentEntry) {
contentEntries->reset(entry);
setLastContentEntry(entry);
} else if (xfermode == SkXfermode::kDstOver_Mode) {
- entry->fNext.reset(contentEntries->release());
+ entry->fNext.reset(contentEntries->detach());
contentEntries->reset(entry);
} else {
lastContentEntry->fNext.reset(entry);
setLastContentEntry(entry);
}
- newEntry.release();
+ newEntry.detach();
return entry;
}
diff --git a/tests/WArrayTest.cpp b/tests/WArrayTest.cpp
index 4a5b879..bb196ef 100644
--- a/tests/WArrayTest.cpp
+++ b/tests/WArrayTest.cpp
@@ -165,7 +165,7 @@
}
bool RunTest() {
- SkTScopedPtr<SkAdvancedTypefaceMetrics::AdvanceMetric<int16_t> > result;
+ SkAutoTDelete<SkAdvancedTypefaceMetrics::AdvanceMetric<int16_t> > result;
result.reset(getAdvanceData((void*)this, fAdvancesLen, fSubset, fSubsetLen, getAdvance));
SkString stringResult = stringify_advance_data(result.get());