Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1027)

Unified Diff: src/ports/SkFontHost_mac.cpp

Issue 2339273002: SkFontData to use smart pointers. (Closed)
Patch Set: Add trivial bodies to the trivial implementations. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/ports/SkFontHost_FreeType_common.h ('k') | src/ports/SkFontHost_win.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/ports/SkFontHost_mac.cpp
diff --git a/src/ports/SkFontHost_mac.cpp b/src/ports/SkFontHost_mac.cpp
index 0c2e5c26281851030e53f41930f3406722310c90..7d1ef750bd5d3f74336fe7e0a14d25c942103f53 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.
« no previous file with comments | « src/ports/SkFontHost_FreeType_common.h ('k') | src/ports/SkFontHost_win.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698