aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/ports/SkFontMgr_custom.cpp
diff options
context:
space:
mode:
authorGravatar bungeman <bungeman@google.com>2016-09-15 10:57:38 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-09-15 10:57:39 -0700
commit606add3dfb2f6d1dc3ee4921876e7c9fa01643f9 (patch)
treef358bd464a80b6739601ef2c653ce78c532f3a7c /src/ports/SkFontMgr_custom.cpp
parenta846c7223c531a634a549e7e6ed7d28eeec95bef (diff)
Revert of SkFontData to use smart pointers. (patchset #3 id:40001 of https://codereview.chromium.org/2339273002/ )
Reason for revert: Killing Mac Original issue's description: > 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 TBR=mtklein@chromium.org,halcanary@google.com,mtklein@google.com,reed@google.com # Skipping CQ checks because original CL landed less than 1 days ago. NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true Review-Url: https://codereview.chromium.org/2343933002
Diffstat (limited to 'src/ports/SkFontMgr_custom.cpp')
-rw-r--r--src/ports/SkFontMgr_custom.cpp50
1 files changed, 24 insertions, 26 deletions
diff --git a/src/ports/SkFontMgr_custom.cpp b/src/ports/SkFontMgr_custom.cpp
index 9a8aa4946f..97489de50d 100644
--- a/src/ports/SkFontMgr_custom.cpp
+++ b/src/ports/SkFontMgr_custom.cpp
@@ -10,7 +10,6 @@
#include "SkFontMgr.h"
#include "SkFontMgr_custom.h"
#include "SkFontStyle.h"
-#include "SkMakeUnique.h"
#include "SkOSFile.h"
#include "SkRefCnt.h"
#include "SkStream.h"
@@ -85,15 +84,15 @@ public:
protected:
SkStreamAsset* onOpenStream(int* ttcIndex) const override {
*ttcIndex = fData->getIndex();
- return fData->getStream()->duplicate();
+ return fData->duplicateStream();
}
- std::unique_ptr<SkFontData> onMakeFontData() const override {
- return skstd::make_unique<SkFontData>(*fData);
+ SkFontData* onCreateFontData() const override {
+ return new SkFontData(*fData.get());
}
private:
- const std::unique_ptr<const SkFontData> fData;
+ std::unique_ptr<const SkFontData> fData;
typedef SkTypeface_Custom INHERITED;
};
@@ -110,7 +109,7 @@ public:
protected:
SkStreamAsset* onOpenStream(int* ttcIndex) const override {
*ttcIndex = this->getIndex();
- return SkStream::MakeFromFile(fPath.c_str()).release();
+ return SkStream::NewFromFile(fPath.c_str());
}
private:
@@ -271,13 +270,13 @@ protected:
SkTypeface* onCreateFromStream(SkStreamAsset* s, const FontParameters& params) const override {
using Scanner = SkTypeface_FreeType::Scanner;
- std::unique_ptr<SkStreamAsset> stream(s);
+ SkAutoTDelete<SkStreamAsset> stream(s);
bool isFixedPitch;
SkFontStyle style;
SkString name;
Scanner::AxisDefinitions axisDefinitions;
- if (!fScanner.scanFont(stream.get(), params.getCollectionIndex(),
- &name, &style, &isFixedPitch, &axisDefinitions))
+ if (!fScanner.scanFont(stream, params.getCollectionIndex(), &name, &style, &isFixedPitch,
+ &axisDefinitions))
{
return nullptr;
}
@@ -287,12 +286,13 @@ protected:
SkAutoSTMalloc<4, SkFixed> axisValues(axisDefinitions.count());
Scanner::computeAxisValues(axisDefinitions, paramAxes, paramAxisCount, axisValues, name);
- auto data = skstd::make_unique<SkFontData>(std::move(stream), params.getCollectionIndex(),
- axisValues.get(), axisDefinitions.count());
+ std::unique_ptr<SkFontData> data(new SkFontData(stream.release(),
+ params.getCollectionIndex(),
+ axisValues.get(), axisDefinitions.count()));
return new SkTypeface_Stream(std::move(data), style, isFixedPitch, false, name);
}
- SkTypeface* onCreateFromFontData(std::unique_ptr<SkFontData> data) const override {
+ SkTypeface* onCreateFromFontData(SkFontData* data) const override {
bool isFixedPitch;
SkFontStyle style;
SkString name;
@@ -301,11 +301,12 @@ protected:
{
return nullptr;
}
- return new SkTypeface_Stream(std::move(data), style, isFixedPitch, false, name);
+ std::unique_ptr<SkFontData> unique_data(data);
+ return new SkTypeface_Stream(std::move(unique_data), style, isFixedPitch, false, name);
}
SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const override {
- std::unique_ptr<SkStreamAsset> stream = SkStream::MakeFromFile(path);
+ SkAutoTDelete<SkStreamAsset> stream(SkStream::NewFromFile(path));
return stream.get() ? this->createFromStream(stream.release(), ttcIndex) : nullptr;
}
@@ -371,14 +372,14 @@ private:
while (iter.next(&name, false)) {
SkString filename(SkOSPath::Join(directory.c_str(), name.c_str()));
- std::unique_ptr<SkStreamAsset> stream = SkStream::MakeFromFile(filename.c_str());
- if (!stream) {
+ SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(filename.c_str()));
+ if (!stream.get()) {
SkDebugf("---- failed to open <%s>\n", filename.c_str());
continue;
}
int numFaces;
- if (!scanner.recognizedFont(stream.get(), &numFaces)) {
+ if (!scanner.recognizedFont(stream, &numFaces)) {
SkDebugf("---- failed to open <%s> as a font\n", filename.c_str());
continue;
}
@@ -387,9 +388,7 @@ private:
bool isFixedPitch;
SkString realname;
SkFontStyle style = SkFontStyle(); // avoid uninitialized warning
- if (!scanner.scanFont(stream.get(), faceIndex,
- &realname, &style, &isFixedPitch, nullptr))
- {
+ if (!scanner.scanFont(stream, faceIndex, &realname, &style, &isFixedPitch, nullptr)) {
SkDebugf("---- failed to open <%s> <%d> as a font\n",
filename.c_str(), faceIndex);
continue;
@@ -463,10 +462,10 @@ private:
const uint8_t* data, size_t size, int index,
SkFontMgr_Custom::Families* families)
{
- auto stream = skstd::make_unique<SkMemoryStream>(data, size, false);
+ SkAutoTDelete<SkMemoryStream> stream(new SkMemoryStream(data, size, false));
int numFaces;
- if (!scanner.recognizedFont(stream.get(), &numFaces)) {
+ if (!scanner.recognizedFont(stream, &numFaces)) {
SkDebugf("---- failed to open <%d> as a font\n", index);
return;
}
@@ -475,9 +474,7 @@ private:
bool isFixedPitch;
SkString realname;
SkFontStyle style = SkFontStyle(); // avoid uninitialized warning
- if (!scanner.scanFont(stream.get(), faceIndex,
- &realname, &style, &isFixedPitch, nullptr))
- {
+ if (!scanner.scanFont(stream, faceIndex, &realname, &style, &isFixedPitch, nullptr)) {
SkDebugf("---- failed to open <%d> <%d> as a font\n", index, faceIndex);
return;
}
@@ -487,7 +484,8 @@ private:
addTo = new SkFontStyleSet_Custom(realname);
families->push_back().reset(addTo);
}
- auto data = skstd::make_unique<SkFontData>(std::move(stream), faceIndex, nullptr, 0);
+ std::unique_ptr<SkFontData> data(
+ new SkFontData(stream.release(), faceIndex, nullptr, 0));
addTo->appendTypeface(sk_make_sp<SkTypeface_Stream>(std::move(data),
style, isFixedPitch,
true, realname));