aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/ports
diff options
context:
space:
mode:
authorGravatar bungeman <bungeman@google.com>2016-09-16 06:24:20 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-09-16 06:24:20 -0700
commitf93d71122e4fcfcdc674a0163455990b13855f2f (patch)
treeb3713fad2da586bf997264247961c1a91453c383 /src/ports
parentf560ef86813f712eff70feb9b00b70d0fe92c3cd (diff)
SkFontData to use smart pointers.
The SkFontData type is not exposed externally, so any method which uses it can be updated to use smart pointers without affecting external users. Updating this first will make updating the public API much easier. This also updates SkStreamAsset* SkStream::NewFromFile(const char*) to std::unique_ptr<SkStreamAsset> SkStream::MakeFromFile(const char*). It appears that no one outside Skia is currently using SkStream::NewfromFile so this is a good time to update it as well. GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2339273002 Committed: https://skia.googlesource.com/skia/+/d8c2476a8b1e1e1a1771b17e8dd4db8645914f8c Review-Url: https://codereview.chromium.org/2339273002
Diffstat (limited to 'src/ports')
-rw-r--r--src/ports/SkFontConfigInterface_direct.cpp2
-rw-r--r--src/ports/SkFontConfigTypeface.h2
-rw-r--r--src/ports/SkFontHost_FreeType.cpp20
-rw-r--r--src/ports/SkFontHost_FreeType_common.h6
-rw-r--r--src/ports/SkFontHost_mac.cpp33
-rw-r--r--src/ports/SkFontHost_win.cpp2
-rw-r--r--src/ports/SkFontMgr_FontConfigInterface.cpp31
-rw-r--r--src/ports/SkFontMgr_android.cpp56
-rw-r--r--src/ports/SkFontMgr_custom.cpp50
-rw-r--r--src/ports/SkFontMgr_fontconfig.cpp41
-rw-r--r--src/ports/SkFontMgr_win_dw.cpp2
11 files changed, 126 insertions, 119 deletions
diff --git a/src/ports/SkFontConfigInterface_direct.cpp b/src/ports/SkFontConfigInterface_direct.cpp
index 8fe9898bc7..cdd420c38c 100644
--- a/src/ports/SkFontConfigInterface_direct.cpp
+++ b/src/ports/SkFontConfigInterface_direct.cpp
@@ -702,7 +702,7 @@ bool SkFontConfigInterfaceDirect::matchFamilyName(const char familyName[],
}
SkStreamAsset* SkFontConfigInterfaceDirect::openStream(const FontIdentity& identity) {
- return SkStream::NewFromFile(identity.fString.c_str());
+ return SkStream::MakeFromFile(identity.fString.c_str()).release();
}
///////////////////////////////////////////////////////////////////////////////
diff --git a/src/ports/SkFontConfigTypeface.h b/src/ports/SkFontConfigTypeface.h
index b636052c47..1a59d7c1ed 100644
--- a/src/ports/SkFontConfigTypeface.h
+++ b/src/ports/SkFontConfigTypeface.h
@@ -60,7 +60,7 @@ protected:
void onGetFamilyName(SkString* familyName) const override { *familyName = fFamilyName; }
void onGetFontDescriptor(SkFontDescriptor*, bool*) const override;
SkStreamAsset* onOpenStream(int* ttcIndex) const override;
- SkFontData* onCreateFontData() const override;
+ std::unique_ptr<SkFontData> onMakeFontData() const override;
private:
typedef SkTypeface_FreeType INHERITED;
diff --git a/src/ports/SkFontHost_FreeType.cpp b/src/ports/SkFontHost_FreeType.cpp
index 84a74af469..71ce865f08 100644
--- a/src/ports/SkFontHost_FreeType.cpp
+++ b/src/ports/SkFontHost_FreeType.cpp
@@ -234,12 +234,11 @@ struct SkFaceRec {
SkFaceRec* fNext;
FT_Face fFace;
FT_StreamRec fFTStream;
- SkAutoTDelete<SkStreamAsset> fSkStream;
+ std::unique_ptr<SkStreamAsset> fSkStream;
uint32_t fRefCnt;
uint32_t fFontID;
- // assumes ownership of the stream, will delete when its done
- SkFaceRec(SkStreamAsset* strm, uint32_t fontID);
+ SkFaceRec(std::unique_ptr<SkStreamAsset> stream, uint32_t fontID);
};
extern "C" {
@@ -262,12 +261,12 @@ extern "C" {
static void sk_ft_stream_close(FT_Stream) {}
}
-SkFaceRec::SkFaceRec(SkStreamAsset* stream, uint32_t fontID)
- : fNext(nullptr), fSkStream(stream), fRefCnt(1), fFontID(fontID)
+SkFaceRec::SkFaceRec(std::unique_ptr<SkStreamAsset> stream, uint32_t fontID)
+ : fNext(nullptr), fSkStream(std::move(stream)), fRefCnt(1), fFontID(fontID)
{
sk_bzero(&fFTStream, sizeof(fFTStream));
fFTStream.size = fSkStream->getLength();
- fFTStream.descriptor.pointer = fSkStream;
+ fFTStream.descriptor.pointer = fSkStream.get();
fFTStream.read = sk_ft_stream_io;
fFTStream.close = sk_ft_stream_close;
}
@@ -319,12 +318,11 @@ static FT_Face ref_ft_face(const SkTypeface* typeface) {
rec = rec->fNext;
}
- SkAutoTDelete<SkFontData> data(typeface->createFontData());
+ std::unique_ptr<SkFontData> data = typeface->makeFontData();
if (nullptr == data || !data->hasStream()) {
return nullptr;
}
- // this passes ownership of stream to the rec
rec = new SkFaceRec(data->detachStream(), fontID);
FT_Open_Args args;
@@ -1564,7 +1562,7 @@ SkTypeface_FreeType::Scanner::~Scanner() {
}
}
-FT_Face SkTypeface_FreeType::Scanner::openFace(SkStream* stream, int ttcIndex,
+FT_Face SkTypeface_FreeType::Scanner::openFace(SkStreamAsset* stream, int ttcIndex,
FT_Stream ftStream) const
{
if (fLibrary == nullptr) {
@@ -1598,7 +1596,7 @@ FT_Face SkTypeface_FreeType::Scanner::openFace(SkStream* stream, int ttcIndex,
return face;
}
-bool SkTypeface_FreeType::Scanner::recognizedFont(SkStream* stream, int* numFaces) const {
+bool SkTypeface_FreeType::Scanner::recognizedFont(SkStreamAsset* stream, int* numFaces) const {
SkAutoMutexAcquire libraryLock(fLibraryMutex);
FT_StreamRec streamRec;
@@ -1615,7 +1613,7 @@ bool SkTypeface_FreeType::Scanner::recognizedFont(SkStream* stream, int* numFace
#include "SkTSearch.h"
bool SkTypeface_FreeType::Scanner::scanFont(
- SkStream* stream, int ttcIndex,
+ SkStreamAsset* stream, int ttcIndex,
SkString* name, SkFontStyle* style, bool* isFixedPitch, AxisDefinitions* axes) const
{
SkAutoMutexAcquire libraryLock(fLibraryMutex);
diff --git a/src/ports/SkFontHost_FreeType_common.h b/src/ports/SkFontHost_FreeType_common.h
index 6b50af27ab..21e7748662 100644
--- a/src/ports/SkFontHost_FreeType_common.h
+++ b/src/ports/SkFontHost_FreeType_common.h
@@ -53,8 +53,8 @@ public:
SkFixed fMaximum;
};
using AxisDefinitions = SkSTArray<4, AxisDefinition, true>;
- bool recognizedFont(SkStream* stream, int* numFonts) const;
- bool scanFont(SkStream* stream, int ttcIndex,
+ bool recognizedFont(SkStreamAsset* stream, int* numFonts) const;
+ bool scanFont(SkStreamAsset* stream, int ttcIndex,
SkString* name, SkFontStyle* style, bool* isFixedPitch,
AxisDefinitions* axes) const;
static void computeAxisValues(
@@ -64,7 +64,7 @@ public:
const SkString& name);
private:
- FT_Face openFace(SkStream* stream, int ttcIndex, FT_Stream ftStream) const;
+ FT_Face openFace(SkStreamAsset* stream, int ttcIndex, FT_Stream ftStream) const;
FT_Library fLibrary;
mutable SkMutex fLibraryMutex;
};
diff --git a/src/ports/SkFontHost_mac.cpp b/src/ports/SkFontHost_mac.cpp
index 0c2e5c2628..7d1ef750bd 100644
--- a/src/ports/SkFontHost_mac.cpp
+++ b/src/ports/SkFontHost_mac.cpp
@@ -28,6 +28,7 @@
#include "SkFontDescriptor.h"
#include "SkFontMgr.h"
#include "SkGlyph.h"
+#include "SkMakeUnique.h"
#include "SkMaskGamma.h"
#include "SkMathPriv.h"
#include "SkMutex.h"
@@ -511,7 +512,7 @@ public:
protected:
int onGetUPEM() const override;
SkStreamAsset* onOpenStream(int* ttcIndex) const override;
- SkFontData* onCreateFontData() const override;
+ std::unique_ptr<SkFontData> onMakeFontData() const override;
void onGetFamilyName(SkString* familyName) const override;
SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const override;
int onGetTableTags(SkFontTableTag tags[]) const override;
@@ -1885,16 +1886,17 @@ static bool get_variations(CTFontRef fFontRef, CFIndex* cgAxisCount,
return true;
}
-SkFontData* SkTypeface_Mac::onCreateFontData() const {
+std::unique_ptr<SkFontData> SkTypeface_Mac::onMakeFontData() const {
int index;
- SkAutoTDelete<SkStreamAsset> stream(this->onOpenStream(&index));
+ std::unique_ptr<SkStreamAsset> stream(this->onOpenStream(&index));
CFIndex cgAxisCount;
SkAutoSTMalloc<4, SkFixed> axisValues;
if (get_variations(fFontRef, &cgAxisCount, &axisValues)) {
- return new SkFontData(stream.release(), index, axisValues.get(), cgAxisCount);
+ return skstd::make_unique<SkFontData>(std::move(stream), index,
+ axisValues.get(), cgAxisCount);
}
- return new SkFontData(stream.release(), index, nullptr, 0);
+ return skstd::make_unique<SkFontData>(std::move(stream), index, nullptr, 0);
}
///////////////////////////////////////////////////////////////////////////////
@@ -2367,15 +2369,16 @@ protected:
}
SkTypeface* onCreateFromData(SkData* data, int ttcIndex) const override {
- AutoCFRelease<CGDataProviderRef> pr(SkCreateDataProviderFromData(data));
+ AutoCFRelease<CGDataProviderRef> pr(SkCreateDataProviderFromData(sk_ref_sp(data)));
if (nullptr == pr) {
return nullptr;
}
return create_from_dataProvider(pr);
}
- SkTypeface* onCreateFromStream(SkStreamAsset* stream, int ttcIndex) const override {
- AutoCFRelease<CGDataProviderRef> pr(SkCreateDataProviderFromStream(stream));
+ SkTypeface* onCreateFromStream(SkStreamAsset* bareStream, int ttcIndex) const override {
+ std::unique_ptr<SkStreamAsset> stream(bareStream);
+ AutoCFRelease<CGDataProviderRef> pr(SkCreateDataProviderFromStream(std::move(stream)));
if (nullptr == pr) {
return nullptr;
}
@@ -2493,8 +2496,9 @@ protected:
}
return dict;
}
- SkTypeface* onCreateFromStream(SkStreamAsset* s, const FontParameters& params) const override {
- AutoCFRelease<CGDataProviderRef> provider(SkCreateDataProviderFromStream(s));
+ SkTypeface* onCreateFromStream(SkStreamAsset* bs, const FontParameters& params) const override {
+ std::unique_ptr<SkStreamAsset> s(bs);
+ AutoCFRelease<CGDataProviderRef> provider(SkCreateDataProviderFromStream(std::move(s)));
if (nullptr == provider) {
return nullptr;
}
@@ -2574,10 +2578,9 @@ protected:
}
return dict;
}
- SkTypeface* onCreateFromFontData(SkFontData* data) const override {
- SkAutoTDelete<SkFontData> fontData(data);
- SkStreamAsset* stream = fontData->detachStream();
- AutoCFRelease<CGDataProviderRef> provider(SkCreateDataProviderFromStream(stream));
+ SkTypeface* onCreateFromFontData(std::unique_ptr<SkFontData> fontData) const override {
+ AutoCFRelease<CGDataProviderRef> provider(
+ SkCreateDataProviderFromStream(fontData->detachStream()));
if (nullptr == provider) {
return nullptr;
}
@@ -2586,7 +2589,7 @@ protected:
return nullptr;
}
- AutoCFRelease<CFDictionaryRef> cgVariations(get_axes(cg, fontData));
+ AutoCFRelease<CFDictionaryRef> cgVariations(get_axes(cg, fontData.get()));
// The CGFontRef returned by CGFontCreateCopyWithVariations when the passed CGFontRef was
// created from a data provider does not appear to have any ownership of the underlying
// data. The original CGFontRef must be kept alive until the copy will no longer be used.
diff --git a/src/ports/SkFontHost_win.cpp b/src/ports/SkFontHost_win.cpp
index ca80baec4f..0e878bee03 100644
--- a/src/ports/SkFontHost_win.cpp
+++ b/src/ports/SkFontHost_win.cpp
@@ -2463,7 +2463,7 @@ protected:
SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const override {
// could be in base impl
- return this->createFromStream(SkStream::NewFromFile(path));
+ return this->createFromStream(SkStream::MakeFromFile(path).release());
}
SkTypeface* onLegacyCreateTypeface(const char familyName[], SkFontStyle style) const override {
diff --git a/src/ports/SkFontMgr_FontConfigInterface.cpp b/src/ports/SkFontMgr_FontConfigInterface.cpp
index c432a6b93f..a6a055a9d2 100644
--- a/src/ports/SkFontMgr_FontConfigInterface.cpp
+++ b/src/ports/SkFontMgr_FontConfigInterface.cpp
@@ -10,6 +10,7 @@
#include "SkFontDescriptor.h"
#include "SkFontMgr.h"
#include "SkFontStyle.h"
+#include "SkMakeUnique.h"
#include "SkMutex.h"
#include "SkString.h"
#include "SkTypeface.h"
@@ -30,13 +31,14 @@ SkStreamAsset* SkTypeface_FCI::onOpenStream(int* ttcIndex) const {
return fFCI->openStream(this->getIdentity());
}
-SkFontData* SkTypeface_FCI::onCreateFontData() const {
+std::unique_ptr<SkFontData> SkTypeface_FCI::onMakeFontData() const {
if (fFontData) {
- return new SkFontData(*fFontData.get());
+ return skstd::make_unique<SkFontData>(*fFontData);
}
const SkFontConfigInterface::FontIdentity& id = this->getIdentity();
- return new SkFontData( fFCI->openStream(id), id.fTTCIndex, nullptr, 0);
+ return skstd::make_unique<SkFontData>(std::unique_ptr<SkStreamAsset>(fFCI->openStream(id)),
+ id.fTTCIndex, nullptr, 0);
}
void SkTypeface_FCI::onGetFontDescriptor(SkFontDescriptor* desc, bool* isLocalStream) const {
@@ -199,7 +201,7 @@ protected:
SkTypeface* onCreateFromData(SkData*, int ttcIndex) const override { return nullptr; }
SkTypeface* onCreateFromStream(SkStreamAsset* bareStream, int ttcIndex) const override {
- SkAutoTDelete<SkStreamAsset> stream(bareStream);
+ std::unique_ptr<SkStreamAsset> stream(bareStream);
const size_t length = stream->getLength();
if (!length) {
return nullptr;
@@ -211,18 +213,17 @@ protected:
// TODO should the caller give us the style or should we get it from freetype?
SkFontStyle style;
bool isFixedPitch = false;
- if (!fScanner.scanFont(stream, 0, nullptr, &style, &isFixedPitch, nullptr)) {
+ if (!fScanner.scanFont(stream.get(), 0, nullptr, &style, &isFixedPitch, nullptr)) {
return nullptr;
}
- std::unique_ptr<SkFontData> fontData(new SkFontData(stream.release(), ttcIndex,
- nullptr, 0));
+ auto fontData = skstd::make_unique<SkFontData>(std::move(stream), ttcIndex, nullptr, 0);
return SkTypeface_FCI::Create(std::move(fontData), style, isFixedPitch);
}
SkTypeface* onCreateFromStream(SkStreamAsset* s, const FontParameters& params) const override {
using Scanner = SkTypeface_FreeType::Scanner;
- SkAutoTDelete<SkStreamAsset> stream(s);
+ std::unique_ptr<SkStreamAsset> stream(s);
const size_t length = stream->getLength();
if (!length) {
return nullptr;
@@ -235,8 +236,8 @@ protected:
SkFontStyle style;
SkString name;
Scanner::AxisDefinitions axisDefinitions;
- if (!fScanner.scanFont(stream, params.getCollectionIndex(), &name, &style, &isFixedPitch,
- &axisDefinitions))
+ if (!fScanner.scanFont(stream.get(), params.getCollectionIndex(),
+ &name, &style, &isFixedPitch, &axisDefinitions))
{
return nullptr;
}
@@ -246,15 +247,15 @@ protected:
SkAutoSTMalloc<4, SkFixed> axisValues(axisDefinitions.count());
Scanner::computeAxisValues(axisDefinitions, paramAxes, paramAxisCount, axisValues, name);
- std::unique_ptr<SkFontData> fontData(new SkFontData(stream.release(),
- params.getCollectionIndex(),
- axisValues.get(),
- axisDefinitions.count()));
+ auto fontData = skstd::make_unique<SkFontData>(std::move(stream),
+ params.getCollectionIndex(),
+ axisValues.get(),
+ axisDefinitions.count());
return SkTypeface_FCI::Create(std::move(fontData), style, isFixedPitch);
}
SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const override {
- SkAutoTDelete<SkStreamAsset> stream(SkStream::NewFromFile(path));
+ std::unique_ptr<SkStreamAsset> stream = SkStream::MakeFromFile(path);
return stream.get() ? this->createFromStream(stream.release(), ttcIndex) : nullptr;
}
diff --git a/src/ports/SkFontMgr_android.cpp b/src/ports/SkFontMgr_android.cpp
index 8a1916a59b..3a84ecad8b 100644
--- a/src/ports/SkFontMgr_android.cpp
+++ b/src/ports/SkFontMgr_android.cpp
@@ -15,6 +15,7 @@
#include "SkFontMgr_android.h"
#include "SkFontMgr_android_parser.h"
#include "SkFontStyle.h"
+#include "SkMakeUnique.h"
#include "SkOSFile.h"
#include "SkPaint.h"
#include "SkRefCnt.h"
@@ -73,12 +74,12 @@ public:
}
}
- SkStreamAsset* createStream() const {
+ std::unique_ptr<SkStreamAsset> makeStream() const {
if (fFile) {
sk_sp<SkData> data(SkData::MakeFromFILE(fFile));
- return data ? new SkMemoryStream(std::move(data)) : nullptr;
+ return data ? skstd::make_unique<SkMemoryStream>(std::move(data)) : nullptr;
}
- return SkStream::NewFromFile(fPathName.c_str());
+ return SkStream::MakeFromFile(fPathName.c_str());
}
virtual void onGetFontDescriptor(SkFontDescriptor* desc, bool* serialize) const override {
@@ -90,10 +91,11 @@ public:
}
SkStreamAsset* onOpenStream(int* ttcIndex) const override {
*ttcIndex = fIndex;
- return this->createStream();
+ return this->makeStream().release();
}
- SkFontData* onCreateFontData() const override {
- return new SkFontData(this->createStream(), fIndex, fAxes.begin(), fAxes.count());
+ std::unique_ptr<SkFontData> onMakeFontData() const override {
+ return skstd::make_unique<SkFontData>(this->makeStream(), fIndex,
+ fAxes.begin(), fAxes.count());
}
const SkString fPathName;
@@ -108,12 +110,12 @@ public:
class SkTypeface_AndroidStream : public SkTypeface_Android {
public:
- SkTypeface_AndroidStream(SkFontData* data,
+ SkTypeface_AndroidStream(std::unique_ptr<SkFontData> data,
const SkFontStyle& style,
bool isFixedPitch,
const SkString& familyName)
: INHERITED(style, isFixedPitch, familyName)
- , fData(data)
+ , fData(std::move(data))
{ }
virtual void onGetFontDescriptor(SkFontDescriptor* desc,
@@ -126,15 +128,15 @@ public:
SkStreamAsset* onOpenStream(int* ttcIndex) const override {
*ttcIndex = fData->getIndex();
- return fData->duplicateStream();
+ return fData->getStream()->duplicate();
}
- SkFontData* onCreateFontData() const override {
- return new SkFontData(*fData.get());
+ std::unique_ptr<SkFontData> onMakeFontData() const override {
+ return skstd::make_unique<SkFontData>(*fData);
}
private:
- const SkAutoTDelete<const SkFontData> fData;
+ const std::unique_ptr<const SkFontData> fData;
typedef SkTypeface_Android INHERITED;
};
@@ -155,8 +157,8 @@ public:
SkString pathName(family.fBasePath);
pathName.append(fontFile.fFileName);
- SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(pathName.c_str()));
- if (!stream.get()) {
+ std::unique_ptr<SkStreamAsset> stream = SkStream::MakeFromFile(pathName.c_str());
+ if (!stream) {
SkDEBUGF(("Requested font file %s does not exist or cannot be opened.\n",
pathName.c_str()));
continue;
@@ -410,31 +412,31 @@ protected:
}
SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const override {
- SkAutoTDelete<SkStreamAsset> stream(SkStream::NewFromFile(path));
+ std::unique_ptr<SkStreamAsset> stream = SkStream::MakeFromFile(path);
return stream.get() ? this->createFromStream(stream.release(), ttcIndex) : nullptr;
}
SkTypeface* onCreateFromStream(SkStreamAsset* bareStream, int ttcIndex) const override {
- SkAutoTDelete<SkStreamAsset> stream(bareStream);
+ std::unique_ptr<SkStreamAsset> stream(bareStream);
bool isFixedPitch;
SkFontStyle style;
SkString name;
- if (!fScanner.scanFont(stream, ttcIndex, &name, &style, &isFixedPitch, nullptr)) {
+ if (!fScanner.scanFont(stream.get(), ttcIndex, &name, &style, &isFixedPitch, nullptr)) {
return nullptr;
}
- SkFontData* data(new SkFontData(stream.release(), ttcIndex, nullptr, 0));
- return new SkTypeface_AndroidStream(data, style, isFixedPitch, name);
+ auto data = skstd::make_unique<SkFontData>(std::move(stream), ttcIndex, nullptr, 0);
+ return new SkTypeface_AndroidStream(std::move(data), style, isFixedPitch, name);
}
SkTypeface* onCreateFromStream(SkStreamAsset* s, const FontParameters& params) const override {
using Scanner = SkTypeface_FreeType::Scanner;
- SkAutoTDelete<SkStreamAsset> stream(s);
+ std::unique_ptr<SkStreamAsset> stream(s);
bool isFixedPitch;
SkFontStyle style;
SkString name;
Scanner::AxisDefinitions axisDefinitions;
- if (!fScanner.scanFont(stream, params.getCollectionIndex(), &name, &style, &isFixedPitch,
- &axisDefinitions))
+ if (!fScanner.scanFont(stream.get(), params.getCollectionIndex(),
+ &name, &style, &isFixedPitch, &axisDefinitions))
{
return nullptr;
}
@@ -444,12 +446,12 @@ protected:
SkAutoSTMalloc<4, SkFixed> axisValues(axisDefinitions.count());
Scanner::computeAxisValues(axisDefinitions, paramAxes, paramAxisCount, axisValues, name);
- SkFontData* data(new SkFontData(stream.release(), params.getCollectionIndex(),
- axisValues.get(), axisDefinitions.count()));
- return new SkTypeface_AndroidStream(data, style, isFixedPitch, name);
+ auto data = skstd::make_unique<SkFontData>(std::move(stream), params.getCollectionIndex(),
+ axisValues.get(), axisDefinitions.count());
+ return new SkTypeface_AndroidStream(std::move(data), style, isFixedPitch, name);
}
- SkTypeface* onCreateFromFontData(SkFontData* data) const override {
+ SkTypeface* onCreateFromFontData(std::unique_ptr<SkFontData> data) const override {
SkStreamAsset* stream(data->getStream());
bool isFixedPitch;
SkFontStyle style;
@@ -457,7 +459,7 @@ protected:
if (!fScanner.scanFont(stream, data->getIndex(), &name, &style, &isFixedPitch, nullptr)) {
return nullptr;
}
- return new SkTypeface_AndroidStream(data, style, isFixedPitch, name);
+ return new SkTypeface_AndroidStream(std::move(data), style, isFixedPitch, name);
}
SkTypeface* onLegacyCreateTypeface(const char familyName[], SkFontStyle style) const override {
diff --git a/src/ports/SkFontMgr_custom.cpp b/src/ports/SkFontMgr_custom.cpp
index 97489de50d..9a8aa4946f 100644
--- a/src/ports/SkFontMgr_custom.cpp
+++ b/src/ports/SkFontMgr_custom.cpp
@@ -10,6 +10,7 @@
#include "SkFontMgr.h"
#include "SkFontMgr_custom.h"
#include "SkFontStyle.h"
+#include "SkMakeUnique.h"
#include "SkOSFile.h"
#include "SkRefCnt.h"
#include "SkStream.h"
@@ -84,15 +85,15 @@ public:
protected:
SkStreamAsset* onOpenStream(int* ttcIndex) const override {
*ttcIndex = fData->getIndex();
- return fData->duplicateStream();
+ return fData->getStream()->duplicate();
}
- SkFontData* onCreateFontData() const override {
- return new SkFontData(*fData.get());
+ std::unique_ptr<SkFontData> onMakeFontData() const override {
+ return skstd::make_unique<SkFontData>(*fData);
}
private:
- std::unique_ptr<const SkFontData> fData;
+ const std::unique_ptr<const SkFontData> fData;
typedef SkTypeface_Custom INHERITED;
};
@@ -109,7 +110,7 @@ public:
protected:
SkStreamAsset* onOpenStream(int* ttcIndex) const override {
*ttcIndex = this->getIndex();
- return SkStream::NewFromFile(fPath.c_str());
+ return SkStream::MakeFromFile(fPath.c_str()).release();
}
private:
@@ -270,13 +271,13 @@ protected:
SkTypeface* onCreateFromStream(SkStreamAsset* s, const FontParameters& params) const override {
using Scanner = SkTypeface_FreeType::Scanner;
- SkAutoTDelete<SkStreamAsset> stream(s);
+ std::unique_ptr<SkStreamAsset> stream(s);
bool isFixedPitch;
SkFontStyle style;
SkString name;
Scanner::AxisDefinitions axisDefinitions;
- if (!fScanner.scanFont(stream, params.getCollectionIndex(), &name, &style, &isFixedPitch,
- &axisDefinitions))
+ if (!fScanner.scanFont(stream.get(), params.getCollectionIndex(),
+ &name, &style, &isFixedPitch, &axisDefinitions))
{
return nullptr;
}
@@ -286,13 +287,12 @@ protected:
SkAutoSTMalloc<4, SkFixed> axisValues(axisDefinitions.count());
Scanner::computeAxisValues(axisDefinitions, paramAxes, paramAxisCount, axisValues, name);
- std::unique_ptr<SkFontData> data(new SkFontData(stream.release(),
- params.getCollectionIndex(),
- axisValues.get(), axisDefinitions.count()));
+ auto data = skstd::make_unique<SkFontData>(std::move(stream), params.getCollectionIndex(),
+ axisValues.get(), axisDefinitions.count());
return new SkTypeface_Stream(std::move(data), style, isFixedPitch, false, name);
}
- SkTypeface* onCreateFromFontData(SkFontData* data) const override {
+ SkTypeface* onCreateFromFontData(std::unique_ptr<SkFontData> data) const override {
bool isFixedPitch;
SkFontStyle style;
SkString name;
@@ -301,12 +301,11 @@ protected:
{
return nullptr;
}
- std::unique_ptr<SkFontData> unique_data(data);
- return new SkTypeface_Stream(std::move(unique_data), style, isFixedPitch, false, name);
+ return new SkTypeface_Stream(std::move(data), style, isFixedPitch, false, name);
}
SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const override {
- SkAutoTDelete<SkStreamAsset> stream(SkStream::NewFromFile(path));
+ std::unique_ptr<SkStreamAsset> stream = SkStream::MakeFromFile(path);
return stream.get() ? this->createFromStream(stream.release(), ttcIndex) : nullptr;
}
@@ -372,14 +371,14 @@ private:
while (iter.next(&name, false)) {
SkString filename(SkOSPath::Join(directory.c_str(), name.c_str()));
- SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(filename.c_str()));
- if (!stream.get()) {
+ std::unique_ptr<SkStreamAsset> stream = SkStream::MakeFromFile(filename.c_str());
+ if (!stream) {
SkDebugf("---- failed to open <%s>\n", filename.c_str());
continue;
}
int numFaces;
- if (!scanner.recognizedFont(stream, &numFaces)) {
+ if (!scanner.recognizedFont(stream.get(), &numFaces)) {
SkDebugf("---- failed to open <%s> as a font\n", filename.c_str());
continue;
}
@@ -388,7 +387,9 @@ private:
bool isFixedPitch;
SkString realname;
SkFontStyle style = SkFontStyle(); // avoid uninitialized warning
- if (!scanner.scanFont(stream, faceIndex, &realname, &style, &isFixedPitch, nullptr)) {
+ if (!scanner.scanFont(stream.get(), faceIndex,
+ &realname, &style, &isFixedPitch, nullptr))
+ {
SkDebugf("---- failed to open <%s> <%d> as a font\n",
filename.c_str(), faceIndex);
continue;
@@ -462,10 +463,10 @@ private:
const uint8_t* data, size_t size, int index,
SkFontMgr_Custom::Families* families)
{
- SkAutoTDelete<SkMemoryStream> stream(new SkMemoryStream(data, size, false));
+ auto stream = skstd::make_unique<SkMemoryStream>(data, size, false);
int numFaces;
- if (!scanner.recognizedFont(stream, &numFaces)) {
+ if (!scanner.recognizedFont(stream.get(), &numFaces)) {
SkDebugf("---- failed to open <%d> as a font\n", index);
return;
}
@@ -474,7 +475,9 @@ private:
bool isFixedPitch;
SkString realname;
SkFontStyle style = SkFontStyle(); // avoid uninitialized warning
- if (!scanner.scanFont(stream, faceIndex, &realname, &style, &isFixedPitch, nullptr)) {
+ if (!scanner.scanFont(stream.get(), faceIndex,
+ &realname, &style, &isFixedPitch, nullptr))
+ {
SkDebugf("---- failed to open <%d> <%d> as a font\n", index, faceIndex);
return;
}
@@ -484,8 +487,7 @@ private:
addTo = new SkFontStyleSet_Custom(realname);
families->push_back().reset(addTo);
}
- std::unique_ptr<SkFontData> data(
- new SkFontData(stream.release(), faceIndex, nullptr, 0));
+ auto data = skstd::make_unique<SkFontData>(std::move(stream), faceIndex, nullptr, 0);
addTo->appendTypeface(sk_make_sp<SkTypeface_Stream>(std::move(data),
style, isFixedPitch,
true, realname));
diff --git a/src/ports/SkFontMgr_fontconfig.cpp b/src/ports/SkFontMgr_fontconfig.cpp
index 5cfd81e411..1e17cb6774 100644
--- a/src/ports/SkFontMgr_fontconfig.cpp
+++ b/src/ports/SkFontMgr_fontconfig.cpp
@@ -12,6 +12,7 @@
#include "SkFontHost_FreeType_common.h"
#include "SkFontMgr.h"
#include "SkFontStyle.h"
+#include "SkMakeUnique.h"
#include "SkMath.h"
#include "SkMutex.h"
#include "SkOSFile.h"
@@ -405,9 +406,9 @@ static void fcpattern_from_skfontstyle(SkFontStyle style, FcPattern* pattern) {
class SkTypeface_stream : public SkTypeface_FreeType {
public:
/** @param data takes ownership of the font data.*/
- SkTypeface_stream(SkFontData* data, const SkFontStyle& style, bool fixedWidth)
+ SkTypeface_stream(std::unique_ptr<SkFontData> data, const SkFontStyle& style, bool fixedWidth)
: INHERITED(style, fixedWidth)
- , fData(data)
+ , fData(std::move(data))
{ };
void onGetFamilyName(SkString* familyName) const override {
@@ -420,15 +421,15 @@ public:
SkStreamAsset* onOpenStream(int* ttcIndex) const override {
*ttcIndex = fData->getIndex();
- return fData->duplicateStream();
+ return fData->getStream()->duplicate();
}
- SkFontData* onCreateFontData() const override {
- return new SkFontData(*fData.get());
+ std::unique_ptr<SkFontData> onMakeFontData() const override {
+ return skstd::make_unique<SkFontData>(*fData);
}
private:
- const SkAutoTDelete<const SkFontData> fData;
+ const std::unique_ptr<const SkFontData> fData;
typedef SkTypeface_FreeType INHERITED;
};
@@ -457,7 +458,7 @@ public:
SkStreamAsset* onOpenStream(int* ttcIndex) const override {
FCLocker lock;
*ttcIndex = get_int(fPattern, FC_INDEX, 0);
- return SkStream::NewFromFile(get_string(fPattern, FC_FILE));
+ return SkStream::MakeFromFile(get_string(fPattern, FC_FILE)).release();
}
void onFilterRec(SkScalerContextRec* rec) const override {
@@ -878,7 +879,7 @@ protected:
}
SkTypeface* onCreateFromStream(SkStreamAsset* bareStream, int ttcIndex) const override {
- SkAutoTDelete<SkStreamAsset> stream(bareStream);
+ std::unique_ptr<SkStreamAsset> stream(bareStream);
const size_t length = stream->getLength();
if (length <= 0 || (1u << 30) < length) {
return nullptr;
@@ -886,23 +887,23 @@ protected:
SkFontStyle style;
bool isFixedWidth = false;
- if (!fScanner.scanFont(stream, ttcIndex, nullptr, &style, &isFixedWidth, nullptr)) {
+ if (!fScanner.scanFont(stream.get(), ttcIndex, nullptr, &style, &isFixedWidth, nullptr)) {
return nullptr;
}
- return new SkTypeface_stream(new SkFontData(stream.release(), ttcIndex, nullptr, 0), style,
- isFixedWidth);
+ auto data = skstd::make_unique<SkFontData>(std::move(stream), ttcIndex, nullptr, 0);
+ return new SkTypeface_stream(std::move(data), style, isFixedWidth);
}
SkTypeface* onCreateFromStream(SkStreamAsset* s, const FontParameters& params) const override {
using Scanner = SkTypeface_FreeType::Scanner;
- SkAutoTDelete<SkStreamAsset> stream(s);
+ std::unique_ptr<SkStreamAsset> stream(s);
bool isFixedPitch;
SkFontStyle style;
SkString name;
Scanner::AxisDefinitions axisDefinitions;
- if (!fScanner.scanFont(stream, params.getCollectionIndex(), &name, &style, &isFixedPitch,
- &axisDefinitions))
+ if (!fScanner.scanFont(stream.get(), params.getCollectionIndex(),
+ &name, &style, &isFixedPitch, &axisDefinitions))
{
return nullptr;
}
@@ -912,9 +913,9 @@ protected:
SkAutoSTMalloc<4, SkFixed> axisValues(axisDefinitions.count());
Scanner::computeAxisValues(axisDefinitions, paramAxes, paramAxisCount, axisValues, name);
- SkFontData* data(new SkFontData(stream.release(), params.getCollectionIndex(),
- axisValues.get(), axisDefinitions.count()));
- return new SkTypeface_stream(data, style, isFixedPitch);
+ auto data = skstd::make_unique<SkFontData>(std::move(stream), params.getCollectionIndex(),
+ axisValues.get(), axisDefinitions.count());
+ return new SkTypeface_stream(std::move(data), style, isFixedPitch);
}
SkTypeface* onCreateFromData(SkData* data, int ttcIndex) const override {
@@ -922,10 +923,10 @@ protected:
}
SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const override {
- return this->createFromStream(SkStream::NewFromFile(path), ttcIndex);
+ return this->createFromStream(SkStream::MakeFromFile(path).release(), ttcIndex);
}
- SkTypeface* onCreateFromFontData(SkFontData* fontData) const override {
+ SkTypeface* onCreateFromFontData(std::unique_ptr<SkFontData> fontData) const override {
SkStreamAsset* stream(fontData->getStream());
const size_t length = stream->getLength();
if (length <= 0 || (1u << 30) < length) {
@@ -939,7 +940,7 @@ protected:
return nullptr;
}
- return new SkTypeface_stream(fontData, style, isFixedWidth);
+ return new SkTypeface_stream(std::move(fontData), style, isFixedWidth);
}
SkTypeface* onLegacyCreateTypeface(const char familyName[], SkFontStyle style) const override {
diff --git a/src/ports/SkFontMgr_win_dw.cpp b/src/ports/SkFontMgr_win_dw.cpp
index 833f95bb0e..7201dc10b0 100644
--- a/src/ports/SkFontMgr_win_dw.cpp
+++ b/src/ports/SkFontMgr_win_dw.cpp
@@ -933,7 +933,7 @@ SkTypeface* SkFontMgr_DirectWrite::onCreateFromData(SkData* data, int ttcIndex)
}
SkTypeface* SkFontMgr_DirectWrite::onCreateFromFile(const char path[], int ttcIndex) const {
- return this->createFromStream(SkStream::NewFromFile(path), ttcIndex);
+ return this->createFromStream(SkStream::MakeFromFile(path).release(), ttcIndex);
}
HRESULT SkFontMgr_DirectWrite::getByFamilyName(const WCHAR wideFamilyName[],