зеркало из https://github.com/mozilla/moz-skia.git
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
This commit is contained in:
Родитель
20146b3f73
Коммит
e029440758
|
@ -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 */,
|
||||
|
|
|
@ -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 */,
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
#include "SkString.h"
|
||||
#include "SkTDArray.h"
|
||||
#include "SkTemplates.h"
|
||||
#include "SkTScopedPtr.h"
|
||||
|
||||
/** \class SkAdvancedTypefaceMetrics
|
||||
|
||||
|
@ -90,7 +89,7 @@ public:
|
|||
uint16_t fStartId;
|
||||
uint16_t fEndId;
|
||||
SkTDArray<Data> fAdvance;
|
||||
SkTScopedPtr<AdvanceMetric<Data> > fNext;
|
||||
SkAutoTDelete<AdvanceMetric<Data> > fNext;
|
||||
};
|
||||
|
||||
struct VerticalMetric {
|
||||
|
@ -102,12 +101,12 @@ public:
|
|||
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 @@ void resetRange(SkAdvancedTypefaceMetrics::AdvanceMetric<Data>* range,
|
|||
|
||||
template <typename Data>
|
||||
SkAdvancedTypefaceMetrics::AdvanceMetric<Data>* appendRange(
|
||||
SkTScopedPtr<SkAdvancedTypefaceMetrics::AdvanceMetric<Data> >* nextSlot,
|
||||
SkAutoTDelete<SkAdvancedTypefaceMetrics::AdvanceMetric<Data> >* nextSlot,
|
||||
int startId);
|
||||
|
||||
template <typename Data>
|
||||
|
|
|
@ -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
|
|
@ -98,6 +98,16 @@ private:
|
|||
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) {}
|
||||
|
|
|
@ -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 @@ private:
|
|||
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;
|
||||
|
||||
|
|
|
@ -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 @@ public:
|
|||
int counts[SkAdvancedTypefaceMetrics::kNotEmbeddable_Font + 1]) const;
|
||||
|
||||
private:
|
||||
SkTScopedPtr<SkPDFCatalog> fCatalog;
|
||||
SkAutoTDelete<SkPDFCatalog> fCatalog;
|
||||
int64_t fXRefFileOffset;
|
||||
|
||||
SkTDArray<SkPDFPage*> fPages;
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -72,7 +72,7 @@ void resetRange(SkAdvancedTypefaceMetrics::AdvanceMetric<Data>* range,
|
|||
|
||||
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 @@ SkAdvancedTypefaceMetrics::AdvanceMetric<Data>* getAdvanceData(
|
|||
// 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 @@ SkAdvancedTypefaceMetrics::AdvanceMetric<Data>* getAdvanceData(
|
|||
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 @@ template void resetRange(
|
|||
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 @@ template void resetRange(
|
|||
SkAdvancedTypefaceMetrics::VerticalAdvanceRange* range,
|
||||
int startId);
|
||||
template SkAdvancedTypefaceMetrics::VerticalAdvanceRange* appendRange(
|
||||
SkTScopedPtr<SkAdvancedTypefaceMetrics::VerticalAdvanceRange >*
|
||||
SkAutoTDelete<SkAdvancedTypefaceMetrics::VerticalAdvanceRange >*
|
||||
nextSlot,
|
||||
int startId);
|
||||
template void finishRange<SkAdvancedTypefaceMetrics::VerticalMetric>(
|
||||
|
|
|
@ -580,14 +580,14 @@ SkBaseDevice* SkPDFDevice::onCreateCompatibleDevice(SkBitmap::Config config,
|
|||
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 @@ SkPDFDevice::~SkPDFDevice() {
|
|||
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 @@ ContentEntry* SkPDFDevice::getLastContentEntry() {
|
|||
}
|
||||
}
|
||||
|
||||
SkTScopedPtr<ContentEntry>* SkPDFDevice::getContentEntries() {
|
||||
SkAutoTDelete<ContentEntry>* SkPDFDevice::getContentEntries() {
|
||||
if (fDrawingArea == kContent_DrawingArea) {
|
||||
return &fContentEntries;
|
||||
} else {
|
||||
|
@ -1650,7 +1650,7 @@ ContentEntry* SkPDFDevice::setUpContentEntry(const SkClipStack* clipStack,
|
|||
}
|
||||
|
||||
ContentEntry* entry;
|
||||
SkTScopedPtr<ContentEntry> newEntry;
|
||||
SkAutoTDelete<ContentEntry> newEntry;
|
||||
|
||||
ContentEntry* lastContentEntry = getLastContentEntry();
|
||||
if (lastContentEntry && lastContentEntry->fContent.getOffset() == 0) {
|
||||
|
@ -1667,18 +1667,18 @@ ContentEntry* SkPDFDevice::setUpContentEntry(const SkClipStack* clipStack,
|
|||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -165,7 +165,7 @@ class TestWData {
|
|||
}
|
||||
|
||||
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());
|
||||
|
|
Загрузка…
Ссылка в новой задаче