aboutsummaryrefslogtreecommitdiffhomepage
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
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
-rw-r--r--bench/nanobench.cpp4
-rw-r--r--dm/DMSrcSink.cpp14
-rw-r--r--include/core/SkStream.h6
-rw-r--r--include/core/SkTypeface.h12
-rw-r--r--include/ports/SkFontMgr.h5
-rw-r--r--include/utils/mac/SkCGUtils.h14
-rw-r--r--samplecode/SampleAnimator.cpp6
-rw-r--r--src/animator/SkAnimateMaker.cpp6
-rw-r--r--src/animator/SkAnimator.cpp6
-rw-r--r--src/core/SkFontDescriptor.cpp11
-rw-r--r--src/core/SkFontDescriptor.h21
-rw-r--r--src/core/SkFontMgr.cpp10
-rw-r--r--src/core/SkStream.cpp15
-rw-r--r--src/core/SkTypeface.cpp21
-rw-r--r--src/images/SkMovie.cpp4
-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
-rw-r--r--src/utils/SkWhitelistTypefaces.cpp8
-rw-r--r--src/utils/mac/SkCreateCGImageRef.cpp65
-rw-r--r--src/utils/mac/SkStream_mac.cpp12
-rw-r--r--tests/BadIcoTest.cpp6
-rw-r--r--tests/CodecTest.cpp45
-rw-r--r--tests/ColorSpaceTest.cpp7
-rw-r--r--tests/ExifTest.cpp9
-rw-r--r--tests/SerializationTest.cpp5
-rw-r--r--tests/YUVTest.cpp8
-rw-r--r--tools/Resources.cpp5
-rw-r--r--tools/dump_record.cpp4
-rw-r--r--tools/get_images_from_skps.cpp6
-rw-r--r--tools/lua/lua_pictures.cpp4
-rw-r--r--tools/viewer/SKPSlide.cpp4
40 files changed, 345 insertions, 243 deletions
diff --git a/bench/nanobench.cpp b/bench/nanobench.cpp
index 433cfa89d9..5db5137ffd 100644
--- a/bench/nanobench.cpp
+++ b/bench/nanobench.cpp
@@ -645,8 +645,8 @@ public:
return nullptr;
}
- std::unique_ptr<SkStream> stream = SkStream::MakeFromFile(path);
- if (!stream) {
+ SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(path));
+ if (stream.get() == nullptr) {
SkDebugf("Could not read %s.\n", path);
return nullptr;
}
diff --git a/dm/DMSrcSink.cpp b/dm/DMSrcSink.cpp
index e35bbad24e..26d90f2460 100644
--- a/dm/DMSrcSink.cpp
+++ b/dm/DMSrcSink.cpp
@@ -997,15 +997,15 @@ static const SkRect kSKPViewport = {0,0, 1000,1000};
SKPSrc::SKPSrc(Path path) : fPath(path) {}
Error SKPSrc::draw(SkCanvas* canvas) const {
- std::unique_ptr<SkStream> stream = SkStream::MakeFromFile(fPath.c_str());
+ SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(fPath.c_str()));
if (!stream) {
return SkStringPrintf("Couldn't read %s.", fPath.c_str());
}
- sk_sp<SkPicture> pic(SkPicture::MakeFromStream(stream.get()));
+ sk_sp<SkPicture> pic(SkPicture::MakeFromStream(stream));
if (!pic) {
return SkStringPrintf("Couldn't decode %s as a picture.", fPath.c_str());
}
- stream = nullptr; // Might as well drop this when we're done with it.
+ stream.reset((SkStream*)nullptr); // Might as well drop this when we're done with it.
canvas->clipRect(kSKPViewport);
canvas->drawPicture(pic);
@@ -1013,12 +1013,12 @@ Error SKPSrc::draw(SkCanvas* canvas) const {
}
SkISize SKPSrc::size() const {
- std::unique_ptr<SkStream> stream = SkStream::MakeFromFile(fPath.c_str());
+ SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(fPath.c_str()));
if (!stream) {
return SkISize::Make(0,0);
}
SkPictInfo info;
- if (!SkPicture::InternalOnly_StreamIsSKP(stream.get(), &info)) {
+ if (!SkPicture::InternalOnly_StreamIsSKP(stream, &info)) {
return SkISize::Make(0,0);
}
SkRect viewport = kSKPViewport;
@@ -1072,7 +1072,7 @@ bool SVGSrc::veto(SinkFlags flags) const {
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
MSKPSrc::MSKPSrc(Path path) : fPath(path) {
- std::unique_ptr<SkStreamAsset> stream = SkStream::MakeFromFile(fPath.c_str());
+ std::unique_ptr<SkStreamAsset> stream(SkStream::NewFromFile(fPath.c_str()));
(void)fReader.init(stream.get());
}
@@ -1083,7 +1083,7 @@ SkISize MSKPSrc::size(int i) const { return fReader.pageSize(i).toCeil(); }
Error MSKPSrc::draw(SkCanvas* c) const { return this->draw(0, c); }
Error MSKPSrc::draw(int i, SkCanvas* canvas) const {
- std::unique_ptr<SkStreamAsset> stream = SkStream::MakeFromFile(fPath.c_str());
+ std::unique_ptr<SkStreamAsset> stream(SkStream::NewFromFile(fPath.c_str()));
if (!stream) {
return SkStringPrintf("Unable to open file: %s", fPath.c_str());
}
diff --git a/include/core/SkStream.h b/include/core/SkStream.h
index 7afce71240..48ac577070 100644
--- a/include/core/SkStream.h
+++ b/include/core/SkStream.h
@@ -40,9 +40,11 @@ public:
virtual ~SkStream() {}
/**
- * Attempts to open the specified file as a stream, returns nullptr on failure.
+ * Attempts to open the specified file, and return a stream to it (using
+ * mmap if available). On success, the caller is responsible for deleting.
+ * On failure, returns NULL.
*/
- static std::unique_ptr<SkStreamAsset> MakeFromFile(const char path[]);
+ static SkStreamAsset* NewFromFile(const char path[]);
/** Reads or skips size number of bytes.
* If buffer == NULL, skip size bytes, return how many were skipped.
diff --git a/include/core/SkTypeface.h b/include/core/SkTypeface.h
index 61618697e8..b2c288ebcd 100644
--- a/include/core/SkTypeface.h
+++ b/include/core/SkTypeface.h
@@ -150,9 +150,10 @@ public:
#endif
/** Return a new typeface given font data and configuration. If the data
- is not valid font data, returns nullptr.
+ is not valid font data, returns nullptr. Ownership of the font data is
+ transferred, so the caller must not reference it again.
*/
- static sk_sp<SkTypeface> MakeFromFontData(std::unique_ptr<SkFontData>);
+ static sk_sp<SkTypeface> MakeFromFontData(SkFontData*);
/** Write a unique signature to a stream, sufficient to reconstruct a
typeface referencing the same font when Deserialize is called.
@@ -299,9 +300,10 @@ public:
SkStreamAsset* openStream(int* ttcIndex) const;
/**
- * Return the font data, or nullptr on failure.
+ * Return the font data, or NULL on failure.
+ * The caller is responsible for deleting the font data.
*/
- std::unique_ptr<SkFontData> makeFontData() const;
+ SkFontData* createFontData() const;
/**
* Return a scalercontext for the given descriptor. If this fails, then
@@ -359,7 +361,7 @@ protected:
virtual SkStreamAsset* onOpenStream(int* ttcIndex) const = 0;
// TODO: make pure virtual.
- virtual std::unique_ptr<SkFontData> onMakeFontData() const;
+ virtual SkFontData* onCreateFontData() const;
virtual void onGetFontDescriptor(SkFontDescriptor*, bool* isLocal) const = 0;
diff --git a/include/ports/SkFontMgr.h b/include/ports/SkFontMgr.h
index afadeaaa97..a5b78c6241 100644
--- a/include/ports/SkFontMgr.h
+++ b/include/ports/SkFontMgr.h
@@ -150,10 +150,11 @@ public:
/**
* Create a typeface from the specified font data.
+ * Takes ownership of the font data, so the caller should not reference it again.
* Will return NULL if the typeface could not be created.
* The caller must call unref() on the returned object if it is not null.
*/
- SkTypeface* createFromFontData(std::unique_ptr<SkFontData>) const;
+ SkTypeface* createFromFontData(SkFontData*) const;
/**
* Create a typeface for the specified fileName and TTC index
@@ -191,7 +192,7 @@ protected:
virtual SkTypeface* onCreateFromStream(SkStreamAsset*, int ttcIndex) const = 0;
// TODO: make pure virtual.
virtual SkTypeface* onCreateFromStream(SkStreamAsset*, const FontParameters&) const;
- virtual SkTypeface* onCreateFromFontData(std::unique_ptr<SkFontData>) const;
+ virtual SkTypeface* onCreateFromFontData(SkFontData*) const;
virtual SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const = 0;
virtual SkTypeface* onLegacyCreateTypeface(const char familyName[], SkFontStyle) const = 0;
diff --git a/include/utils/mac/SkCGUtils.h b/include/utils/mac/SkCGUtils.h
index a8f86de35b..3d9aff4451 100644
--- a/include/utils/mac/SkCGUtils.h
+++ b/include/utils/mac/SkCGUtils.h
@@ -65,12 +65,20 @@ static inline CGImageRef SkCreateCGImageRef(const SkBitmap& bm) {
void SkCGDrawBitmap(CGContextRef, const SkBitmap&, float x, float y);
/**
- * Return a provider that wraps the specified stream.
+ * Create an SkBitmap drawing of the encoded PDF document, returning true on
+ * success. Deletes the stream when finished.
+ */
+bool SkPDFDocumentToBitmap(SkStream* stream, SkBitmap* output);
+
+/**
+ * Return a provider that wraps the specified stream. It will become the only
+ * owner of the stream, so the caller must stop referring to the stream.
+ *
* When the provider is finally deleted, it will delete the stream.
*/
-CGDataProviderRef SkCreateDataProviderFromStream(std::unique_ptr<SkStream>);
+CGDataProviderRef SkCreateDataProviderFromStream(SkStream*);
-CGDataProviderRef SkCreateDataProviderFromData(sk_sp<SkData>);
+CGDataProviderRef SkCreateDataProviderFromData(SkData*);
#endif // defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)
#endif // SkCGUtils_DEFINED
diff --git a/samplecode/SampleAnimator.cpp b/samplecode/SampleAnimator.cpp
index a3ec83afe6..d4a4cdd288 100644
--- a/samplecode/SampleAnimator.cpp
+++ b/samplecode/SampleAnimator.cpp
@@ -12,8 +12,6 @@
#include "SkStream.h"
#include "SkDOM.h"
-#include <memory>
-
///////////////////////////////////////////////////////////////////////////////
class SkAnimatorView : public SkView {
@@ -52,8 +50,8 @@ void SkAnimatorView::setURIBase(const char dir[]) {
}
bool SkAnimatorView::decodeFile(const char path[]) {
- std::unique_ptr<SkStream> is = SkStream::MakeFromFile(path);
- return is && this->decodeStream(is.get());
+ SkAutoTDelete<SkStream> is(SkStream::NewFromFile(path));
+ return is.get() != nullptr && this->decodeStream(is);
}
bool SkAnimatorView::decodeMemory(const void* buffer, size_t size) {
diff --git a/src/animator/SkAnimateMaker.cpp b/src/animator/SkAnimateMaker.cpp
index 066f877a9b..5186da04d8 100644
--- a/src/animator/SkAnimateMaker.cpp
+++ b/src/animator/SkAnimateMaker.cpp
@@ -99,9 +99,9 @@ bool SkAnimateMaker::decodeURI(const char uri[]) {
// SkDebugf("animator decode %s\n", uri);
// SkStream* stream = SkStream::GetURIStream(fPrefix.c_str(), uri);
- std::unique_ptr<SkStream> stream = SkStream::MakeFromFile(uri);
- if (stream) {
- bool success = decodeStream(stream.get());
+ SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(uri));
+ if (stream.get()) {
+ bool success = decodeStream(stream);
if (hasError() && fError.hasNoun() == false)
fError.setNoun(uri);
return success;
diff --git a/src/animator/SkAnimator.cpp b/src/animator/SkAnimator.cpp
index c5aabbba4b..ee75ab14af 100644
--- a/src/animator/SkAnimator.cpp
+++ b/src/animator/SkAnimator.cpp
@@ -82,10 +82,10 @@ bool SkAnimator::decodeURI(const char uri[]) {
// SkDebugf("animator decode %s\n", uri);
// SkStream* stream = SkStream::GetURIStream(fMaker->fPrefix.c_str(), uri);
- std::unique_ptr<SkStream> stream = SkStream::MakeFromFile(uri);
- if (stream) {
+ SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(uri));
+ if (stream.get()) {
this->setURIBase(uri);
- return decodeStream(stream.get());
+ return decodeStream(stream);
} else {
return false;
}
diff --git a/src/core/SkFontDescriptor.cpp b/src/core/SkFontDescriptor.cpp
index 73ea2058ce..85629efa7e 100644
--- a/src/core/SkFontDescriptor.cpp
+++ b/src/core/SkFontDescriptor.cpp
@@ -6,7 +6,6 @@
*/
#include "SkFontDescriptor.h"
-#include "SkMakeUnique.h"
#include "SkStream.h"
#include "SkData.h"
@@ -107,8 +106,8 @@ bool SkFontDescriptor::Deserialize(SkStream* stream, SkFontDescriptor* result) {
if (length > 0) {
sk_sp<SkData> data(SkData::MakeUninitialized(length));
if (stream->read(data->writable_data(), length) == length) {
- result->fFontData = skstd::make_unique<SkFontData>(
- skstd::make_unique<SkMemoryStream>(data), index, axis, axisCount);
+ result->fFontData.reset(new SkFontData(new SkMemoryStream(data),
+ index, axis, axisCount));
} else {
SkDEBUGFAIL("Could not read font data");
return false;
@@ -139,10 +138,10 @@ void SkFontDescriptor::serialize(SkWStream* stream) {
stream->writePackedUInt(kSentinel);
if (fFontData.get() && fFontData->hasStream()) {
- std::unique_ptr<SkStreamAsset> fontStream = fFontData->detachStream();
- size_t length = fontStream->getLength();
+ SkAutoTDelete<SkStreamAsset> fontData(fFontData->detachStream());
+ size_t length = fontData->getLength();
stream->writePackedUInt(length);
- stream->writeStream(fontStream.get(), length);
+ stream->writeStream(fontData, length);
} else {
stream->writePackedUInt(0);
}
diff --git a/src/core/SkFontDescriptor.h b/src/core/SkFontDescriptor.h
index de1462177b..cb8d2f4f03 100644
--- a/src/core/SkFontDescriptor.h
+++ b/src/core/SkFontDescriptor.h
@@ -15,9 +15,9 @@
class SkFontData {
public:
- /** Makes a copy of the data in 'axis'. */
- SkFontData(std::unique_ptr<SkStreamAsset> stream, int index, const SkFixed axis[],int axisCount)
- : fStream(std::move(stream)), fIndex(index), fAxisCount(axisCount), fAxis(axisCount)
+ /** This takes ownership of 'stream'. Makes a copy of the data in 'axis'. */
+ SkFontData(SkStreamAsset* stream, int index, const SkFixed axis[], int axisCount)
+ : fStream(stream), fIndex(index), fAxisCount(axisCount), fAxis(axisCount)
{
for (int i = 0; i < axisCount; ++i) {
fAxis[i] = axis[i];
@@ -34,15 +34,15 @@ public:
}
}
bool hasStream() const { return fStream.get() != nullptr; }
- std::unique_ptr<SkStreamAsset> detachStream() { return std::move(fStream); }
+ SkStreamAsset* duplicateStream() const { return fStream->duplicate(); }
+ SkStreamAsset* detachStream() { return fStream.release(); }
SkStreamAsset* getStream() { return fStream.get(); }
- SkStreamAsset const* getStream() const { return fStream.get(); }
int getIndex() const { return fIndex; }
int getAxisCount() const { return fAxisCount; }
const SkFixed* getAxis() const { return fAxis.get(); }
private:
- std::unique_ptr<SkStreamAsset> fStream;
+ SkAutoTDelete<SkStreamAsset> fStream;
int fIndex;
int fAxisCount;
SkAutoSTMalloc<4, SkFixed> fAxis;
@@ -63,19 +63,20 @@ public:
const char* getFullName() const { return fFullName.c_str(); }
const char* getPostscriptName() const { return fPostscriptName.c_str(); }
bool hasFontData() const { return fFontData.get() != nullptr; }
- std::unique_ptr<SkFontData> detachFontData() { return std::move(fFontData); }
+ SkFontData* detachFontData() { return fFontData.release(); }
void setFamilyName(const char* name) { fFamilyName.set(name); }
void setFullName(const char* name) { fFullName.set(name); }
void setPostscriptName(const char* name) { fPostscriptName.set(name); }
- /** Set the font data only if it is necessary for serialization. */
- void setFontData(std::unique_ptr<SkFontData> data) { fFontData = std::move(data); }
+ /** Set the font data only if it is necessary for serialization.
+ * This method takes ownership of the font data. */
+ void setFontData(SkFontData* data) { fFontData.reset(data); }
private:
SkString fFamilyName;
SkString fFullName;
SkString fPostscriptName;
- std::unique_ptr<SkFontData> fFontData;
+ SkAutoTDelete<SkFontData> fFontData;
SkFontStyle fStyle;
};
diff --git a/src/core/SkFontMgr.cpp b/src/core/SkFontMgr.cpp
index 57f82b03ba..0f00667926 100644
--- a/src/core/SkFontMgr.cpp
+++ b/src/core/SkFontMgr.cpp
@@ -139,11 +139,11 @@ SkTypeface* SkFontMgr::createFromStream(SkStreamAsset* stream, const FontParamet
return this->onCreateFromStream(stream, params);
}
-SkTypeface* SkFontMgr::createFromFontData(std::unique_ptr<SkFontData> data) const {
+SkTypeface* SkFontMgr::createFromFontData(SkFontData* data) const {
if (nullptr == data) {
return nullptr;
}
- return this->onCreateFromFontData(std::move(data));
+ return this->onCreateFromFontData(data);
}
// This implementation is temporary until it can be made pure virtual.
@@ -152,8 +152,10 @@ SkTypeface* SkFontMgr::onCreateFromStream(SkStreamAsset* stream, const FontParam
}
// This implementation is temporary until it can be made pure virtual.
-SkTypeface* SkFontMgr::onCreateFromFontData(std::unique_ptr<SkFontData> data) const {
- return this->createFromStream(data->detachStream().release(), data->getIndex());
+SkTypeface* SkFontMgr::onCreateFromFontData(SkFontData* data) const {
+ SkTypeface* ret = this->createFromStream(data->detachStream(), data->getIndex());
+ delete data;
+ return ret;
}
SkTypeface* SkFontMgr::createFromFile(const char path[], int ttcIndex) const {
diff --git a/src/core/SkStream.cpp b/src/core/SkStream.cpp
index e7b3a7a7e5..48eb92cae5 100644
--- a/src/core/SkStream.cpp
+++ b/src/core/SkStream.cpp
@@ -10,7 +10,6 @@
#include "SkStreamPriv.h"
#include "SkData.h"
#include "SkFixed.h"
-#include "SkMakeUnique.h"
#include "SkString.h"
#include "SkOSFile.h"
#include "SkTypes.h"
@@ -855,18 +854,20 @@ static sk_sp<SkData> mmap_filename(const char path[]) {
return data;
}
-std::unique_ptr<SkStreamAsset> SkStream::MakeFromFile(const char path[]) {
+SkStreamAsset* SkStream::NewFromFile(const char path[]) {
auto data(mmap_filename(path));
if (data) {
- return skstd::make_unique<SkMemoryStream>(std::move(data));
+ return new SkMemoryStream(std::move(data));
}
- // If we get here, then our attempt at using mmap failed, so try normal file access.
- auto stream = skstd::make_unique<SkFILEStream>(path);
+ // If we get here, then our attempt at using mmap failed, so try normal
+ // file access.
+ SkFILEStream* stream = new SkFILEStream(path);
if (!stream->isValid()) {
- return nullptr;
+ delete stream;
+ stream = nullptr;
}
- return std::move(stream);
+ return stream;
}
// Declared in SkStreamPriv.h:
diff --git a/src/core/SkTypeface.cpp b/src/core/SkTypeface.cpp
index 3c4f5cb7e7..0c960d5915 100644
--- a/src/core/SkTypeface.cpp
+++ b/src/core/SkTypeface.cpp
@@ -9,7 +9,6 @@
#include "SkEndian.h"
#include "SkFontDescriptor.h"
#include "SkFontMgr.h"
-#include "SkMakeUnique.h"
#include "SkMutex.h"
#include "SkOTTable_OS_2.h"
#include "SkOnce.h"
@@ -151,9 +150,9 @@ sk_sp<SkTypeface> SkTypeface::MakeFromStream(SkStreamAsset* stream, int index) {
return sk_sp<SkTypeface>(fm->createFromStream(stream, index));
}
-sk_sp<SkTypeface> SkTypeface::MakeFromFontData(std::unique_ptr<SkFontData> data) {
+sk_sp<SkTypeface> SkTypeface::MakeFromFontData(SkFontData* data) {
SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault());
- return sk_sp<SkTypeface>(fm->createFromFontData(std::move(data)));
+ return sk_sp<SkTypeface>(fm->createFromFontData(data));
}
sk_sp<SkTypeface> SkTypeface::MakeFromFile(const char path[], int index) {
@@ -174,7 +173,7 @@ void SkTypeface::serialize(SkWStream* wstream) const {
// Embed font data if it's a local font.
if (isLocal && !desc.hasFontData()) {
- desc.setFontData(this->onMakeFontData());
+ desc.setFontData(this->onCreateFontData());
}
desc.serialize(wstream);
}
@@ -189,9 +188,9 @@ sk_sp<SkTypeface> SkTypeface::MakeDeserialize(SkStream* stream) {
return nullptr;
}
- std::unique_ptr<SkFontData> data = desc.detachFontData();
+ SkFontData* data = desc.detachFontData();
if (data) {
- sk_sp<SkTypeface> typeface(SkTypeface::MakeFromFontData(std::move(data)));
+ sk_sp<SkTypeface> typeface(SkTypeface::MakeFromFontData(data));
if (typeface) {
return typeface;
}
@@ -228,15 +227,15 @@ SkStreamAsset* SkTypeface::openStream(int* ttcIndex) const {
return this->onOpenStream(ttcIndex);
}
-std::unique_ptr<SkFontData> SkTypeface::makeFontData() const {
- return this->onMakeFontData();
+SkFontData* SkTypeface::createFontData() const {
+ return this->onCreateFontData();
}
// This implementation is temporary until this method can be made pure virtual.
-std::unique_ptr<SkFontData> SkTypeface::onMakeFontData() const {
+SkFontData* SkTypeface::onCreateFontData() const {
int index;
- std::unique_ptr<SkStreamAsset> stream(this->onOpenStream(&index));
- return skstd::make_unique<SkFontData>(std::move(stream), index, nullptr, 0);
+ SkAutoTDelete<SkStreamAsset> stream(this->onOpenStream(&index));
+ return new SkFontData(stream.release(), index, nullptr, 0);
};
int SkTypeface::charsToGlyphs(const void* chars, Encoding encoding,
diff --git a/src/images/SkMovie.cpp b/src/images/SkMovie.cpp
index a0a37dcffa..bf94f281c8 100644
--- a/src/images/SkMovie.cpp
+++ b/src/images/SkMovie.cpp
@@ -89,6 +89,6 @@ SkMovie* SkMovie::DecodeMemory(const void* data, size_t length) {
}
SkMovie* SkMovie::DecodeFile(const char path[]) {
- std::unique_ptr<SkStreamRewindable> stream = SkStream::MakeFromFile(path);
- return stream ? SkMovie::DecodeStream(stream.get()) : nullptr;
+ SkAutoTDelete<SkStreamRewindable> stream(SkStream::NewFromFile(path));
+ return stream.get() ? SkMovie::DecodeStream(stream) : nullptr;
}
diff --git a/src/ports/SkFontConfigInterface_direct.cpp b/src/ports/SkFontConfigInterface_direct.cpp
index cdd420c38c..8fe9898bc7 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::MakeFromFile(identity.fString.c_str()).release();
+ return SkStream::NewFromFile(identity.fString.c_str());
}
///////////////////////////////////////////////////////////////////////////////
diff --git a/src/ports/SkFontConfigTypeface.h b/src/ports/SkFontConfigTypeface.h
index 1a59d7c1ed..b636052c47 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;
- std::unique_ptr<SkFontData> onMakeFontData() const override;
+ SkFontData* onCreateFontData() const override;
private:
typedef SkTypeface_FreeType INHERITED;
diff --git a/src/ports/SkFontHost_FreeType.cpp b/src/ports/SkFontHost_FreeType.cpp
index 71ce865f08..84a74af469 100644
--- a/src/ports/SkFontHost_FreeType.cpp
+++ b/src/ports/SkFontHost_FreeType.cpp
@@ -234,11 +234,12 @@ struct SkFaceRec {
SkFaceRec* fNext;
FT_Face fFace;
FT_StreamRec fFTStream;
- std::unique_ptr<SkStreamAsset> fSkStream;
+ SkAutoTDelete<SkStreamAsset> fSkStream;
uint32_t fRefCnt;
uint32_t fFontID;
- SkFaceRec(std::unique_ptr<SkStreamAsset> stream, uint32_t fontID);
+ // assumes ownership of the stream, will delete when its done
+ SkFaceRec(SkStreamAsset* strm, uint32_t fontID);
};
extern "C" {
@@ -261,12 +262,12 @@ extern "C" {
static void sk_ft_stream_close(FT_Stream) {}
}
-SkFaceRec::SkFaceRec(std::unique_ptr<SkStreamAsset> stream, uint32_t fontID)
- : fNext(nullptr), fSkStream(std::move(stream)), fRefCnt(1), fFontID(fontID)
+SkFaceRec::SkFaceRec(SkStreamAsset* stream, uint32_t fontID)
+ : fNext(nullptr), fSkStream(stream), fRefCnt(1), fFontID(fontID)
{
sk_bzero(&fFTStream, sizeof(fFTStream));
fFTStream.size = fSkStream->getLength();
- fFTStream.descriptor.pointer = fSkStream.get();
+ fFTStream.descriptor.pointer = fSkStream;
fFTStream.read = sk_ft_stream_io;
fFTStream.close = sk_ft_stream_close;
}
@@ -318,11 +319,12 @@ static FT_Face ref_ft_face(const SkTypeface* typeface) {
rec = rec->fNext;
}
- std::unique_ptr<SkFontData> data = typeface->makeFontData();
+ SkAutoTDelete<SkFontData> data(typeface->createFontData());
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;
@@ -1562,7 +1564,7 @@ SkTypeface_FreeType::Scanner::~Scanner() {
}
}
-FT_Face SkTypeface_FreeType::Scanner::openFace(SkStreamAsset* stream, int ttcIndex,
+FT_Face SkTypeface_FreeType::Scanner::openFace(SkStream* stream, int ttcIndex,
FT_Stream ftStream) const
{
if (fLibrary == nullptr) {
@@ -1596,7 +1598,7 @@ FT_Face SkTypeface_FreeType::Scanner::openFace(SkStreamAsset* stream, int ttcInd
return face;
}
-bool SkTypeface_FreeType::Scanner::recognizedFont(SkStreamAsset* stream, int* numFaces) const {
+bool SkTypeface_FreeType::Scanner::recognizedFont(SkStream* stream, int* numFaces) const {
SkAutoMutexAcquire libraryLock(fLibraryMutex);
FT_StreamRec streamRec;
@@ -1613,7 +1615,7 @@ bool SkTypeface_FreeType::Scanner::recognizedFont(SkStreamAsset* stream, int* nu
#include "SkTSearch.h"
bool SkTypeface_FreeType::Scanner::scanFont(
- SkStreamAsset* stream, int ttcIndex,
+ SkStream* 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 21e7748662..6b50af27ab 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(SkStreamAsset* stream, int* numFonts) const;
- bool scanFont(SkStreamAsset* stream, int ttcIndex,
+ bool recognizedFont(SkStream* stream, int* numFonts) const;
+ bool scanFont(SkStream* 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(SkStreamAsset* stream, int ttcIndex, FT_Stream ftStream) const;
+ FT_Face openFace(SkStream* 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 7d1ef750bd..0c2e5c2628 100644
--- a/src/ports/SkFontHost_mac.cpp
+++ b/src/ports/SkFontHost_mac.cpp
@@ -28,7 +28,6 @@
#include "SkFontDescriptor.h"
#include "SkFontMgr.h"
#include "SkGlyph.h"
-#include "SkMakeUnique.h"
#include "SkMaskGamma.h"
#include "SkMathPriv.h"
#include "SkMutex.h"
@@ -512,7 +511,7 @@ public:
protected:
int onGetUPEM() const override;
SkStreamAsset* onOpenStream(int* ttcIndex) const override;
- std::unique_ptr<SkFontData> onMakeFontData() const override;
+ SkFontData* onCreateFontData() const override;
void onGetFamilyName(SkString* familyName) const override;
SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const override;
int onGetTableTags(SkFontTableTag tags[]) const override;
@@ -1886,17 +1885,16 @@ static bool get_variations(CTFontRef fFontRef, CFIndex* cgAxisCount,
return true;
}
-std::unique_ptr<SkFontData> SkTypeface_Mac::onMakeFontData() const {
+SkFontData* SkTypeface_Mac::onCreateFontData() const {
int index;
- std::unique_ptr<SkStreamAsset> stream(this->onOpenStream(&index));
+ SkAutoTDelete<SkStreamAsset> stream(this->onOpenStream(&index));
CFIndex cgAxisCount;
SkAutoSTMalloc<4, SkFixed> axisValues;
if (get_variations(fFontRef, &cgAxisCount, &axisValues)) {
- return skstd::make_unique<SkFontData>(std::move(stream), index,
- axisValues.get(), cgAxisCount);
+ return new SkFontData(stream.release(), index, axisValues.get(), cgAxisCount);
}
- return skstd::make_unique<SkFontData>(std::move(stream), index, nullptr, 0);
+ return new SkFontData(stream.release(), index, nullptr, 0);
}
///////////////////////////////////////////////////////////////////////////////
@@ -2369,16 +2367,15 @@ protected:
}
SkTypeface* onCreateFromData(SkData* data, int ttcIndex) const override {
- AutoCFRelease<CGDataProviderRef> pr(SkCreateDataProviderFromData(sk_ref_sp(data)));
+ AutoCFRelease<CGDataProviderRef> pr(SkCreateDataProviderFromData(data));
if (nullptr == pr) {
return nullptr;
}
return create_from_dataProvider(pr);
}
- SkTypeface* onCreateFromStream(SkStreamAsset* bareStream, int ttcIndex) const override {
- std::unique_ptr<SkStreamAsset> stream(bareStream);
- AutoCFRelease<CGDataProviderRef> pr(SkCreateDataProviderFromStream(std::move(stream)));
+ SkTypeface* onCreateFromStream(SkStreamAsset* stream, int ttcIndex) const override {
+ AutoCFRelease<CGDataProviderRef> pr(SkCreateDataProviderFromStream(stream));
if (nullptr == pr) {
return nullptr;
}
@@ -2496,9 +2493,8 @@ protected:
}
return dict;
}
- SkTypeface* onCreateFromStream(SkStreamAsset* bs, const FontParameters& params) const override {
- std::unique_ptr<SkStreamAsset> s(bs);
- AutoCFRelease<CGDataProviderRef> provider(SkCreateDataProviderFromStream(std::move(s)));
+ SkTypeface* onCreateFromStream(SkStreamAsset* s, const FontParameters& params) const override {
+ AutoCFRelease<CGDataProviderRef> provider(SkCreateDataProviderFromStream(s));
if (nullptr == provider) {
return nullptr;
}
@@ -2578,9 +2574,10 @@ protected:
}
return dict;
}
- SkTypeface* onCreateFromFontData(std::unique_ptr<SkFontData> fontData) const override {
- AutoCFRelease<CGDataProviderRef> provider(
- SkCreateDataProviderFromStream(fontData->detachStream()));
+ SkTypeface* onCreateFromFontData(SkFontData* data) const override {
+ SkAutoTDelete<SkFontData> fontData(data);
+ SkStreamAsset* stream = fontData->detachStream();
+ AutoCFRelease<CGDataProviderRef> provider(SkCreateDataProviderFromStream(stream));
if (nullptr == provider) {
return nullptr;
}
@@ -2589,7 +2586,7 @@ protected:
return nullptr;
}
- AutoCFRelease<CFDictionaryRef> cgVariations(get_axes(cg, fontData.get()));
+ AutoCFRelease<CFDictionaryRef> cgVariations(get_axes(cg, fontData));
// 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 0e878bee03..ca80baec4f 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::MakeFromFile(path).release());
+ return this->createFromStream(SkStream::NewFromFile(path));
}
SkTypeface* onLegacyCreateTypeface(const char familyName[], SkFontStyle style) const override {
diff --git a/src/ports/SkFontMgr_FontConfigInterface.cpp b/src/ports/SkFontMgr_FontConfigInterface.cpp
index a6a055a9d2..c432a6b93f 100644
--- a/src/ports/SkFontMgr_FontConfigInterface.cpp
+++ b/src/ports/SkFontMgr_FontConfigInterface.cpp
@@ -10,7 +10,6 @@
#include "SkFontDescriptor.h"
#include "SkFontMgr.h"
#include "SkFontStyle.h"
-#include "SkMakeUnique.h"
#include "SkMutex.h"
#include "SkString.h"
#include "SkTypeface.h"
@@ -31,14 +30,13 @@ SkStreamAsset* SkTypeface_FCI::onOpenStream(int* ttcIndex) const {
return fFCI->openStream(this->getIdentity());
}
-std::unique_ptr<SkFontData> SkTypeface_FCI::onMakeFontData() const {
+SkFontData* SkTypeface_FCI::onCreateFontData() const {
if (fFontData) {
- return skstd::make_unique<SkFontData>(*fFontData);
+ return new SkFontData(*fFontData.get());
}
const SkFontConfigInterface::FontIdentity& id = this->getIdentity();
- return skstd::make_unique<SkFontData>(std::unique_ptr<SkStreamAsset>(fFCI->openStream(id)),
- id.fTTCIndex, nullptr, 0);
+ return new SkFontData( fFCI->openStream(id), id.fTTCIndex, nullptr, 0);
}
void SkTypeface_FCI::onGetFontDescriptor(SkFontDescriptor* desc, bool* isLocalStream) const {
@@ -201,7 +199,7 @@ protected:
SkTypeface* onCreateFromData(SkData*, int ttcIndex) const override { return nullptr; }
SkTypeface* onCreateFromStream(SkStreamAsset* bareStream, int ttcIndex) const override {
- std::unique_ptr<SkStreamAsset> stream(bareStream);
+ SkAutoTDelete<SkStreamAsset> stream(bareStream);
const size_t length = stream->getLength();
if (!length) {
return nullptr;
@@ -213,17 +211,18 @@ 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.get(), 0, nullptr, &style, &isFixedPitch, nullptr)) {
+ if (!fScanner.scanFont(stream, 0, nullptr, &style, &isFixedPitch, nullptr)) {
return nullptr;
}
- auto fontData = skstd::make_unique<SkFontData>(std::move(stream), ttcIndex, nullptr, 0);
+ std::unique_ptr<SkFontData> fontData(new SkFontData(stream.release(), 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;
- std::unique_ptr<SkStreamAsset> stream(s);
+ SkAutoTDelete<SkStreamAsset> stream(s);
const size_t length = stream->getLength();
if (!length) {
return nullptr;
@@ -236,8 +235,8 @@ protected:
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;
}
@@ -247,15 +246,15 @@ protected:
SkAutoSTMalloc<4, SkFixed> axisValues(axisDefinitions.count());
Scanner::computeAxisValues(axisDefinitions, paramAxes, paramAxisCount, axisValues, name);
- auto fontData = skstd::make_unique<SkFontData>(std::move(stream),
- params.getCollectionIndex(),
- axisValues.get(),
- axisDefinitions.count());
+ std::unique_ptr<SkFontData> fontData(new SkFontData(stream.release(),
+ params.getCollectionIndex(),
+ axisValues.get(),
+ axisDefinitions.count()));
return SkTypeface_FCI::Create(std::move(fontData), style, isFixedPitch);
}
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;
}
diff --git a/src/ports/SkFontMgr_android.cpp b/src/ports/SkFontMgr_android.cpp
index 3a84ecad8b..8a1916a59b 100644
--- a/src/ports/SkFontMgr_android.cpp
+++ b/src/ports/SkFontMgr_android.cpp
@@ -15,7 +15,6 @@
#include "SkFontMgr_android.h"
#include "SkFontMgr_android_parser.h"
#include "SkFontStyle.h"
-#include "SkMakeUnique.h"
#include "SkOSFile.h"
#include "SkPaint.h"
#include "SkRefCnt.h"
@@ -74,12 +73,12 @@ public:
}
}
- std::unique_ptr<SkStreamAsset> makeStream() const {
+ SkStreamAsset* createStream() const {
if (fFile) {
sk_sp<SkData> data(SkData::MakeFromFILE(fFile));
- return data ? skstd::make_unique<SkMemoryStream>(std::move(data)) : nullptr;
+ return data ? new SkMemoryStream(std::move(data)) : nullptr;
}
- return SkStream::MakeFromFile(fPathName.c_str());
+ return SkStream::NewFromFile(fPathName.c_str());
}
virtual void onGetFontDescriptor(SkFontDescriptor* desc, bool* serialize) const override {
@@ -91,11 +90,10 @@ public:
}
SkStreamAsset* onOpenStream(int* ttcIndex) const override {
*ttcIndex = fIndex;
- return this->makeStream().release();
+ return this->createStream();
}
- std::unique_ptr<SkFontData> onMakeFontData() const override {
- return skstd::make_unique<SkFontData>(this->makeStream(), fIndex,
- fAxes.begin(), fAxes.count());
+ SkFontData* onCreateFontData() const override {
+ return new SkFontData(this->createStream(), fIndex, fAxes.begin(), fAxes.count());
}
const SkString fPathName;
@@ -110,12 +108,12 @@ public:
class SkTypeface_AndroidStream : public SkTypeface_Android {
public:
- SkTypeface_AndroidStream(std::unique_ptr<SkFontData> data,
+ SkTypeface_AndroidStream(SkFontData* data,
const SkFontStyle& style,
bool isFixedPitch,
const SkString& familyName)
: INHERITED(style, isFixedPitch, familyName)
- , fData(std::move(data))
+ , fData(data)
{ }
virtual void onGetFontDescriptor(SkFontDescriptor* desc,
@@ -128,15 +126,15 @@ public:
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;
+ const SkAutoTDelete<const SkFontData> fData;
typedef SkTypeface_Android INHERITED;
};
@@ -157,8 +155,8 @@ public:
SkString pathName(family.fBasePath);
pathName.append(fontFile.fFileName);
- std::unique_ptr<SkStreamAsset> stream = SkStream::MakeFromFile(pathName.c_str());
- if (!stream) {
+ SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(pathName.c_str()));
+ if (!stream.get()) {
SkDEBUGF(("Requested font file %s does not exist or cannot be opened.\n",
pathName.c_str()));
continue;
@@ -412,31 +410,31 @@ protected:
}
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;
}
SkTypeface* onCreateFromStream(SkStreamAsset* bareStream, int ttcIndex) const override {
- std::unique_ptr<SkStreamAsset> stream(bareStream);
+ SkAutoTDelete<SkStreamAsset> stream(bareStream);
bool isFixedPitch;
SkFontStyle style;
SkString name;
- if (!fScanner.scanFont(stream.get(), ttcIndex, &name, &style, &isFixedPitch, nullptr)) {
+ if (!fScanner.scanFont(stream, ttcIndex, &name, &style, &isFixedPitch, nullptr)) {
return nullptr;
}
- auto data = skstd::make_unique<SkFontData>(std::move(stream), ttcIndex, nullptr, 0);
- return new SkTypeface_AndroidStream(std::move(data), style, isFixedPitch, name);
+ SkFontData* data(new SkFontData(stream.release(), ttcIndex, nullptr, 0));
+ return new SkTypeface_AndroidStream(data, style, isFixedPitch, name);
}
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;
}
@@ -446,12 +444,12 @@ 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());
- return new SkTypeface_AndroidStream(std::move(data), style, isFixedPitch, name);
+ SkFontData* data(new SkFontData(stream.release(), params.getCollectionIndex(),
+ axisValues.get(), axisDefinitions.count()));
+ return new SkTypeface_AndroidStream(data, style, isFixedPitch, name);
}
- SkTypeface* onCreateFromFontData(std::unique_ptr<SkFontData> data) const override {
+ SkTypeface* onCreateFromFontData(SkFontData* data) const override {
SkStreamAsset* stream(data->getStream());
bool isFixedPitch;
SkFontStyle style;
@@ -459,7 +457,7 @@ protected:
if (!fScanner.scanFont(stream, data->getIndex(), &name, &style, &isFixedPitch, nullptr)) {
return nullptr;
}
- return new SkTypeface_AndroidStream(std::move(data), style, isFixedPitch, name);
+ return new SkTypeface_AndroidStream(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 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));
diff --git a/src/ports/SkFontMgr_fontconfig.cpp b/src/ports/SkFontMgr_fontconfig.cpp
index 1e17cb6774..5cfd81e411 100644
--- a/src/ports/SkFontMgr_fontconfig.cpp
+++ b/src/ports/SkFontMgr_fontconfig.cpp
@@ -12,7 +12,6 @@
#include "SkFontHost_FreeType_common.h"
#include "SkFontMgr.h"
#include "SkFontStyle.h"
-#include "SkMakeUnique.h"
#include "SkMath.h"
#include "SkMutex.h"
#include "SkOSFile.h"
@@ -406,9 +405,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(std::unique_ptr<SkFontData> data, const SkFontStyle& style, bool fixedWidth)
+ SkTypeface_stream(SkFontData* data, const SkFontStyle& style, bool fixedWidth)
: INHERITED(style, fixedWidth)
- , fData(std::move(data))
+ , fData(data)
{ };
void onGetFamilyName(SkString* familyName) const override {
@@ -421,15 +420,15 @@ public:
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;
+ const SkAutoTDelete<const SkFontData> fData;
typedef SkTypeface_FreeType INHERITED;
};
@@ -458,7 +457,7 @@ public:
SkStreamAsset* onOpenStream(int* ttcIndex) const override {
FCLocker lock;
*ttcIndex = get_int(fPattern, FC_INDEX, 0);
- return SkStream::MakeFromFile(get_string(fPattern, FC_FILE)).release();
+ return SkStream::NewFromFile(get_string(fPattern, FC_FILE));
}
void onFilterRec(SkScalerContextRec* rec) const override {
@@ -879,7 +878,7 @@ protected:
}
SkTypeface* onCreateFromStream(SkStreamAsset* bareStream, int ttcIndex) const override {
- std::unique_ptr<SkStreamAsset> stream(bareStream);
+ SkAutoTDelete<SkStreamAsset> stream(bareStream);
const size_t length = stream->getLength();
if (length <= 0 || (1u << 30) < length) {
return nullptr;
@@ -887,23 +886,23 @@ protected:
SkFontStyle style;
bool isFixedWidth = false;
- if (!fScanner.scanFont(stream.get(), ttcIndex, nullptr, &style, &isFixedWidth, nullptr)) {
+ if (!fScanner.scanFont(stream, ttcIndex, nullptr, &style, &isFixedWidth, nullptr)) {
return nullptr;
}
- auto data = skstd::make_unique<SkFontData>(std::move(stream), ttcIndex, nullptr, 0);
- return new SkTypeface_stream(std::move(data), style, isFixedWidth);
+ return new SkTypeface_stream(new SkFontData(stream.release(), ttcIndex, nullptr, 0), style,
+ isFixedWidth);
}
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;
}
@@ -913,9 +912,9 @@ 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());
- return new SkTypeface_stream(std::move(data), style, isFixedPitch);
+ SkFontData* data(new SkFontData(stream.release(), params.getCollectionIndex(),
+ axisValues.get(), axisDefinitions.count()));
+ return new SkTypeface_stream(data, style, isFixedPitch);
}
SkTypeface* onCreateFromData(SkData* data, int ttcIndex) const override {
@@ -923,10 +922,10 @@ protected:
}
SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const override {
- return this->createFromStream(SkStream::MakeFromFile(path).release(), ttcIndex);
+ return this->createFromStream(SkStream::NewFromFile(path), ttcIndex);
}
- SkTypeface* onCreateFromFontData(std::unique_ptr<SkFontData> fontData) const override {
+ SkTypeface* onCreateFromFontData(SkFontData* fontData) const override {
SkStreamAsset* stream(fontData->getStream());
const size_t length = stream->getLength();
if (length <= 0 || (1u << 30) < length) {
@@ -940,7 +939,7 @@ protected:
return nullptr;
}
- return new SkTypeface_stream(std::move(fontData), style, isFixedWidth);
+ return new SkTypeface_stream(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 7201dc10b0..833f95bb0e 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::MakeFromFile(path).release(), ttcIndex);
+ return this->createFromStream(SkStream::NewFromFile(path), ttcIndex);
}
HRESULT SkFontMgr_DirectWrite::getByFamilyName(const WCHAR wideFamilyName[],
diff --git a/src/utils/SkWhitelistTypefaces.cpp b/src/utils/SkWhitelistTypefaces.cpp
index 007def6d8b..139e697ca0 100644
--- a/src/utils/SkWhitelistTypefaces.cpp
+++ b/src/utils/SkWhitelistTypefaces.cpp
@@ -63,7 +63,7 @@ static int whitelist_name_index(const SkTypeface* tf) {
}
static uint32_t compute_checksum(const SkTypeface* tf) {
- std::unique_ptr<SkFontData> fontData = tf->makeFontData();
+ SkFontData* fontData = tf->createFontData();
if (!fontData) {
return 0;
}
@@ -118,7 +118,7 @@ static void serialize_full(const SkTypeface* tf, SkWStream* wstream) {
// Embed font data if it's a local font.
if (isLocal && !desc.hasFontData()) {
- desc.setFontData(tf->makeFontData());
+ desc.setFontData(tf->createFontData());
}
desc.serialize(wstream);
}
@@ -190,9 +190,9 @@ sk_sp<SkTypeface> WhitelistDeserializeTypeface(SkStream* stream) {
return nullptr;
}
- std::unique_ptr<SkFontData> data = desc.detachFontData();
+ SkFontData* data = desc.detachFontData();
if (data) {
- sk_sp<SkTypeface> typeface(SkTypeface::MakeFromFontData(std::move(data)));
+ sk_sp<SkTypeface> typeface(SkTypeface::MakeFromFontData(data));
if (typeface) {
return typeface;
}
diff --git a/src/utils/mac/SkCreateCGImageRef.cpp b/src/utils/mac/SkCreateCGImageRef.cpp
index d9cdb86e49..7f15ed7090 100644
--- a/src/utils/mac/SkCreateCGImageRef.cpp
+++ b/src/utils/mac/SkCreateCGImageRef.cpp
@@ -176,6 +176,71 @@ void SkCGDrawBitmap(CGContextRef cg, const SkBitmap& bm, float x, float y) {
}
}
+///////////////////////////////////////////////////////////////////////////////
+
+#include "SkStream.h"
+
+class SkAutoPDFRelease {
+public:
+ SkAutoPDFRelease(CGPDFDocumentRef doc) : fDoc(doc) {}
+ ~SkAutoPDFRelease() {
+ if (fDoc) {
+ CGPDFDocumentRelease(fDoc);
+ }
+ }
+private:
+ CGPDFDocumentRef fDoc;
+};
+#define SkAutoPDFRelease(...) SK_REQUIRE_LOCAL_VAR(SkAutoPDFRelease)
+
+bool SkPDFDocumentToBitmap(SkStream* stream, SkBitmap* output) {
+ CGDataProviderRef data = SkCreateDataProviderFromStream(stream);
+ if (nullptr == data) {
+ return false;
+ }
+
+ CGPDFDocumentRef pdf = CGPDFDocumentCreateWithProvider(data);
+ CGDataProviderRelease(data);
+ if (nullptr == pdf) {
+ return false;
+ }
+ SkAutoPDFRelease releaseMe(pdf);
+
+ CGPDFPageRef page = CGPDFDocumentGetPage(pdf, 1);
+ if (nullptr == page) {
+ return false;
+ }
+
+ CGRect bounds = CGPDFPageGetBoxRect(page, kCGPDFMediaBox);
+
+ int w = (int)CGRectGetWidth(bounds);
+ int h = (int)CGRectGetHeight(bounds);
+
+ SkBitmap bitmap;
+ if (!bitmap.tryAllocN32Pixels(w, h)) {
+ return false;
+ }
+ bitmap.eraseColor(SK_ColorWHITE);
+
+ size_t bitsPerComponent;
+ CGBitmapInfo info;
+ getBitmapInfo(bitmap, &bitsPerComponent, &info, nullptr);
+
+ CGColorSpaceRef cs = CGColorSpaceCreateDeviceRGB();
+ CGContextRef ctx = CGBitmapContextCreate(bitmap.getPixels(), w, h,
+ bitsPerComponent, bitmap.rowBytes(),
+ cs, info);
+ CGColorSpaceRelease(cs);
+
+ if (ctx) {
+ CGContextDrawPDFPage(ctx, page);
+ CGContextRelease(ctx);
+ }
+
+ output->swap(bitmap);
+ return true;
+}
+
///////////////////////////////////////////////////////////////////////////////////////////////////
SK_API bool SkCopyPixelsFromCGImage(const SkImageInfo& info, size_t rowBytes, void* pixels,
diff --git a/src/utils/mac/SkStream_mac.cpp b/src/utils/mac/SkStream_mac.cpp
index a1d63b5fd6..36e5194a19 100644
--- a/src/utils/mac/SkStream_mac.cpp
+++ b/src/utils/mac/SkStream_mac.cpp
@@ -48,13 +48,13 @@ static void release_info_proc(void* info) {
delete (SkStream*)info;
}
-CGDataProviderRef SkCreateDataProviderFromStream(std::unique_ptr<SkStream> stream) {
+CGDataProviderRef SkCreateDataProviderFromStream(SkStream* stream) {
// TODO: Replace with SkStream::getData() when that is added. Then we only
// have one version of CGDataProviderCreateWithData (i.e. same release proc)
const void* addr = stream->getMemoryBase();
if (addr) {
// special-case when the stream is just a block of ram
- return CGDataProviderCreateWithData(stream.release(), addr, stream->getLength(),
+ return CGDataProviderCreateWithData(stream, addr, stream->getLength(),
delete_stream_proc);
}
@@ -65,15 +65,17 @@ CGDataProviderRef SkCreateDataProviderFromStream(std::unique_ptr<SkStream> strea
rec.skipForward = skip_forward_proc;
rec.rewind = rewind_proc;
rec.releaseInfo = release_info_proc;
- return CGDataProviderCreateSequential(stream.release(), &rec);
+ return CGDataProviderCreateSequential(stream, &rec);
}
///////////////////////////////////////////////////////////////////////////////
#include "SkData.h"
-CGDataProviderRef SkCreateDataProviderFromData(sk_sp<SkData> data) {
- return CGDataProviderCreateWithData(data.release(), data->data(), data->size(), unref_proc);
+CGDataProviderRef SkCreateDataProviderFromData(SkData* data) {
+ data->ref();
+ return CGDataProviderCreateWithData(data, data->data(), data->size(),
+ unref_proc);
}
#endif//defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)
diff --git a/tests/BadIcoTest.cpp b/tests/BadIcoTest.cpp
index 4affa85b7b..5c01490f9b 100644
--- a/tests/BadIcoTest.cpp
+++ b/tests/BadIcoTest.cpp
@@ -26,9 +26,11 @@ DEF_TEST(BadImage, reporter) {
const char* badImagesFolder = "invalid_images";
+ SkString resourcePath = GetResourcePath(badImagesFolder);
+
for (size_t i = 0; i < SK_ARRAY_COUNT(badImages); ++i) {
- SkString resourcePath = SkOSPath::Join(badImagesFolder, badImages[i]);
- SkAutoTDelete<SkStream> stream(GetResourceAsStream(resourcePath.c_str()));
+ SkString fullPath = SkOSPath::Join(resourcePath.c_str(), badImages[i]);
+ SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(fullPath.c_str()));
SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream.release()));
// These images are corrupt. It's not important whether we succeed/fail in codec
diff --git a/tests/CodecTest.cpp b/tests/CodecTest.cpp
index 341433b379..044c2fd6b4 100644
--- a/tests/CodecTest.cpp
+++ b/tests/CodecTest.cpp
@@ -22,6 +22,11 @@
#include "png.h"
+static SkStreamAsset* resource(const char path[]) {
+ SkString fullPath = GetResourcePath(path);
+ return SkStream::NewFromFile(fullPath.c_str());
+}
+
static void md5(const SkBitmap& bm, SkMD5::Digest* digest) {
SkAutoLockPixels autoLockPixels(bm);
SkASSERT(bm.getPixels());
@@ -194,8 +199,9 @@ static void check(skiatest::Reporter* r,
bool supportsSubsetDecoding,
bool supportsIncomplete = true) {
- SkAutoTDelete<SkStream> stream(GetResourceAsStream(path));
+ SkAutoTDelete<SkStream> stream(resource(path));
if (!stream) {
+ SkDebugf("Missing resource '%s'\n", path);
return;
}
@@ -323,8 +329,9 @@ static void check(skiatest::Reporter* r,
// SkAndroidCodec tests
if (supportsScanlineDecoding || supportsSubsetDecoding) {
- SkAutoTDelete<SkStream> stream(GetResourceAsStream(path));
+ SkAutoTDelete<SkStream> stream(resource(path));
if (!stream) {
+ SkDebugf("Missing resource '%s'\n", path);
return;
}
@@ -349,7 +356,7 @@ static void check(skiatest::Reporter* r,
if (!isIncomplete) {
// Test SkCodecImageGenerator
- SkAutoTDelete<SkStream> stream(GetResourceAsStream(path));
+ SkAutoTDelete<SkStream> stream(resource(path));
sk_sp<SkData> fullData(SkData::MakeFromStream(stream, stream->getLength()));
SkAutoTDelete<SkImageGenerator> gen(
SkCodecImageGenerator::NewFromEncodedCodec(fullData.get()));
@@ -442,10 +449,9 @@ DEF_TEST(Codec, r) {
// Test interlaced PNG in stripes, similar to DM's kStripe_Mode
DEF_TEST(Codec_stripes, r) {
const char * path = "plane_interlaced.png";
- SkAutoTDelete<SkStream> stream(GetResourceAsStream(path));
- REPORTER_ASSERT(r, stream);
+ SkAutoTDelete<SkStream> stream(resource(path));
if (!stream) {
- return;
+ SkDebugf("Missing resource '%s'\n", path);
}
SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream.release()));
@@ -576,8 +582,9 @@ DEF_TEST(Codec_null, r) {
static void test_dimensions(skiatest::Reporter* r, const char path[]) {
// Create the codec from the resource file
- SkAutoTDelete<SkStream> stream(GetResourceAsStream(path));
+ SkAutoTDelete<SkStream> stream(resource(path));
if (!stream) {
+ SkDebugf("Missing resource '%s'\n", path);
return;
}
SkAutoTDelete<SkAndroidCodec> codec(SkAndroidCodec::NewFromStream(stream.release()));
@@ -640,8 +647,9 @@ DEF_TEST(Codec_Dimensions, r) {
}
static void test_invalid(skiatest::Reporter* r, const char path[]) {
- SkAutoTDelete<SkStream> stream(GetResourceAsStream(path));
+ SkAutoTDelete<SkStream> stream(resource(path));
if (!stream) {
+ SkDebugf("Missing resource '%s'\n", path);
return;
}
SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream.release()));
@@ -665,8 +673,9 @@ DEF_TEST(Codec_Empty, r) {
}
static void test_invalid_parameters(skiatest::Reporter* r, const char path[]) {
- SkAutoTDelete<SkStream> stream(GetResourceAsStream(path));
+ SkAutoTDelete<SkStream> stream(resource(path));
if (!stream) {
+ SkDebugf("Missing resource '%s'\n", path);
return;
}
SkAutoTDelete<SkCodec> decoder(SkCodec::NewFromStream(stream.release()));
@@ -956,8 +965,9 @@ DEF_TEST(Codec_webp_peek, r) {
// Test that SkCodec now supports an image with these bits set.
DEF_TEST(Codec_wbmp, r) {
const char* path = "mandrill.wbmp";
- SkAutoTDelete<SkStream> stream(GetResourceAsStream(path));
+ SkAutoTDelete<SkStream> stream(resource(path));
if (!stream) {
+ SkDebugf("Missing resource '%s'\n", path);
return;
}
@@ -1006,8 +1016,9 @@ DEF_TEST(Codec_wbmp_max_size, r) {
DEF_TEST(Codec_jpeg_rewind, r) {
const char* path = "mandrill_512_q075.jpg";
- SkAutoTDelete<SkStream> stream(GetResourceAsStream(path));
+ SkAutoTDelete<SkStream> stream(resource(path));
if (!stream) {
+ SkDebugf("Missing resource '%s'\n", path);
return;
}
SkAutoTDelete<SkAndroidCodec> codec(SkAndroidCodec::NewFromStream(stream.release()));
@@ -1033,7 +1044,7 @@ DEF_TEST(Codec_jpeg_rewind, r) {
}
static void check_color_xform(skiatest::Reporter* r, const char* path) {
- SkAutoTDelete<SkAndroidCodec> codec(SkAndroidCodec::NewFromStream(GetResourceAsStream(path)));
+ SkAutoTDelete<SkAndroidCodec> codec(SkAndroidCodec::NewFromStream(resource(path)));
SkAndroidCodec::AndroidOptions opts;
opts.fSampleSize = 3;
@@ -1119,7 +1130,7 @@ static void check_round_trip(skiatest::Reporter* r, SkCodec* origCodec, const Sk
DEF_TEST(Codec_PngRoundTrip, r) {
const char* path = "mandrill_512_q075.jpg";
- SkAutoTDelete<SkStream> stream(GetResourceAsStream(path));
+ SkAutoTDelete<SkStream> stream(resource(path));
SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream.release()));
SkColorType colorTypesOpaque[] = {
@@ -1131,12 +1142,12 @@ DEF_TEST(Codec_PngRoundTrip, r) {
}
path = "grayscale.jpg";
- stream.reset(GetResourceAsStream(path));
+ stream.reset(resource(path));
codec.reset(SkCodec::NewFromStream(stream.release()));
check_round_trip(r, codec.get(), codec->getInfo());
path = "yellow_rose.png";
- stream.reset(GetResourceAsStream(path));
+ stream.reset(resource(path));
codec.reset(SkCodec::NewFromStream(stream.release()));
SkColorType colorTypesWithAlpha[] = {
@@ -1156,7 +1167,7 @@ DEF_TEST(Codec_PngRoundTrip, r) {
}
path = "index8.png";
- stream.reset(GetResourceAsStream(path));
+ stream.reset(resource(path));
codec.reset(SkCodec::NewFromStream(stream.release()));
for (SkAlphaType alphaType : alphaTypes) {
@@ -1168,7 +1179,7 @@ DEF_TEST(Codec_PngRoundTrip, r) {
static void test_conversion_possible(skiatest::Reporter* r, const char* path,
bool testScanlineDecoder) {
- SkAutoTDelete<SkStream> stream(GetResourceAsStream(path));
+ SkAutoTDelete<SkStream> stream(resource(path));
SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream.release()));
SkImageInfo infoF16 = codec->getInfo().makeColorType(kRGBA_F16_SkColorType);
diff --git a/tests/ColorSpaceTest.cpp b/tests/ColorSpaceTest.cpp
index 7e247d304d..4a64460370 100644
--- a/tests/ColorSpaceTest.cpp
+++ b/tests/ColorSpaceTest.cpp
@@ -40,10 +40,15 @@ static void test_space(skiatest::Reporter* r, SkColorSpace* space,
}
}
+static SkStreamAsset* resource(const char path[]) {
+ SkString fullPath = GetResourcePath(path);
+ return SkStream::NewFromFile(fullPath.c_str());
+}
+
static void test_path(skiatest::Reporter* r, const char* path,
const float red[], const float green[], const float blue[],
const SkGammaNamed expectedGamma) {
- SkAutoTDelete<SkStream> stream(GetResourceAsStream(path));
+ SkAutoTDelete<SkStream> stream(resource(path));
REPORTER_ASSERT(r, nullptr != stream);
if (!stream) {
return;
diff --git a/tests/ExifTest.cpp b/tests/ExifTest.cpp
index 4aac487064..7fcd8b861d 100644
--- a/tests/ExifTest.cpp
+++ b/tests/ExifTest.cpp
@@ -9,8 +9,13 @@
#include "SkCodec.h"
#include "Test.h"
+static SkStreamAsset* resource(const char path[]) {
+ SkString fullPath = GetResourcePath(path);
+ return SkStream::NewFromFile(fullPath.c_str());
+}
+
DEF_TEST(ExifOrientation, r) {
- SkAutoTDelete<SkStream> stream(GetResourceAsStream("exif-orientation-2-ur.jpg"));
+ SkAutoTDelete<SkStream> stream(resource("exif-orientation-2-ur.jpg"));
REPORTER_ASSERT(r, nullptr != stream);
if (!stream) {
return;
@@ -21,7 +26,7 @@ DEF_TEST(ExifOrientation, r) {
SkCodec::Origin origin = codec->getOrigin();
REPORTER_ASSERT(r, SkCodec::kTopRight_Origin == origin);
- stream.reset(GetResourceAsStream("mandrill_512_q075.jpg"));
+ stream.reset(resource("mandrill_512_q075.jpg"));
codec.reset(SkCodec::NewFromStream(stream.release()));
REPORTER_ASSERT(r, nullptr != codec);
origin = codec->getOrigin();
diff --git a/tests/SerializationTest.cpp b/tests/SerializationTest.cpp
index bc2770ebda..ff9b342074 100644
--- a/tests/SerializationTest.cpp
+++ b/tests/SerializationTest.cpp
@@ -13,7 +13,6 @@
#include "SkImage.h"
#include "SkImageSource.h"
#include "SkLightingShader.h"
-#include "SkMakeUnique.h"
#include "SkMallocPixelRef.h"
#include "SkNormalSource.h"
#include "SkOSFile.h"
@@ -371,13 +370,13 @@ static void TestPictureTypefaceSerialization(skiatest::Reporter* reporter) {
{
// Load typeface as stream to create with axis settings.
- std::unique_ptr<SkStreamAsset> distortable(GetResourceAsStream("/fonts/Distortable.ttf"));
+ SkAutoTDelete<SkStreamAsset> distortable(GetResourceAsStream("/fonts/Distortable.ttf"));
if (!distortable) {
INFOF(reporter, "Could not run fontstream test because Distortable.ttf not found.");
} else {
SkFixed axis = SK_FixedSqrt2;
sk_sp<SkTypeface> typeface(SkTypeface::MakeFromFontData(
- skstd::make_unique<SkFontData>(std::move(distortable), 0, &axis, 1)));
+ new SkFontData(distortable.release(), 0, &axis, 1)));
if (!typeface) {
INFOF(reporter, "Could not run fontstream test because Distortable.ttf not created.");
} else {
diff --git a/tests/YUVTest.cpp b/tests/YUVTest.cpp
index d3b9167843..f7b3306b98 100644
--- a/tests/YUVTest.cpp
+++ b/tests/YUVTest.cpp
@@ -12,11 +12,17 @@
#include "SkYUVSizeInfo.h"
#include "Test.h"
+static SkStreamAsset* resource(const char path[]) {
+ SkString fullPath = GetResourcePath(path);
+ return SkStream::NewFromFile(fullPath.c_str());
+}
+
static void codec_yuv(skiatest::Reporter* reporter,
const char path[],
SkISize expectedSizes[3]) {
- SkAutoTDelete<SkStream> stream(GetResourceAsStream(path));
+ SkAutoTDelete<SkStream> stream(resource(path));
if (!stream) {
+ INFOF(reporter, "Missing resource '%s'\n", path);
return;
}
SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream.release()));
diff --git a/tools/Resources.cpp b/tools/Resources.cpp
index 9c12a67c20..899f5d2bc4 100644
--- a/tools/Resources.cpp
+++ b/tools/Resources.cpp
@@ -41,11 +41,12 @@ sk_sp<SkImage> GetResourceAsImage(const char* resource) {
SkStreamAsset* GetResourceAsStream(const char* resource) {
SkString resourcePath = GetResourcePath(resource);
SkAutoTDelete<SkFILEStream> stream(new SkFILEStream(resourcePath.c_str()));
- if (!stream->isValid()) {
+ if (stream->isValid()) {
+ return stream.release();
+ } else {
SkDebugf("Resource %s not found.\n", resource);
return nullptr;
}
- return stream.release();
}
sk_sp<SkTypeface> MakeResourceAsTypeface(const char* resource) {
diff --git a/tools/dump_record.cpp b/tools/dump_record.cpp
index 03ef93e581..5d54f4d561 100644
--- a/tools/dump_record.cpp
+++ b/tools/dump_record.cpp
@@ -46,12 +46,12 @@ int tool_main(int argc, char** argv) {
continue;
}
- std::unique_ptr<SkStream> stream = SkStream::MakeFromFile(FLAGS_skps[i]);
+ SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(FLAGS_skps[i]));
if (!stream) {
SkDebugf("Could not read %s.\n", FLAGS_skps[i]);
return 1;
}
- sk_sp<SkPicture> src(SkPicture::MakeFromStream(stream.get()));
+ sk_sp<SkPicture> src(SkPicture::MakeFromStream(stream));
if (!src) {
SkDebugf("Could not read %s as an SkPicture.\n", FLAGS_skps[i]);
return 1;
diff --git a/tools/get_images_from_skps.cpp b/tools/get_images_from_skps.cpp
index e38a245915..1ec70b3531 100644
--- a/tools/get_images_from_skps.cpp
+++ b/tools/get_images_from_skps.cpp
@@ -128,9 +128,9 @@ int main(int argc, char** argv) {
SkOSFile::Iter iter(inputs, "skp");
for (SkString file; iter.next(&file); ) {
- std::unique_ptr<SkStream> stream =
- SkStream::MakeFromFile(SkOSPath::Join(inputs, file.c_str()).c_str());
- sk_sp<SkPicture> picture(SkPicture::MakeFromStream(stream.get()));
+ SkAutoTDelete<SkStream> stream =
+ SkStream::NewFromFile(SkOSPath::Join(inputs, file.c_str()).c_str());
+ sk_sp<SkPicture> picture(SkPicture::MakeFromStream(stream));
SkDynamicMemoryWStream scratch;
Sniffer sniff(file.c_str());
diff --git a/tools/lua/lua_pictures.cpp b/tools/lua/lua_pictures.cpp
index 58983f4d58..eee7088f0d 100644
--- a/tools/lua/lua_pictures.cpp
+++ b/tools/lua/lua_pictures.cpp
@@ -39,8 +39,8 @@ DEFINE_string2(tailFunc, s, "", "Optional lua function to call at end");
DEFINE_bool2(quiet, q, false, "Silence all non-error related output");
static sk_sp<SkPicture> load_picture(const char path[]) {
- std::unique_ptr<SkStream> stream = SkStream::MakeFromFile(path);
- if (stream) {
+ SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(path));
+ if (stream.get()) {
return SkPicture::MakeFromStream(stream.get());
}
return nullptr;
diff --git a/tools/viewer/SKPSlide.cpp b/tools/viewer/SKPSlide.cpp
index e24e1fdb04..9419253f0c 100644
--- a/tools/viewer/SKPSlide.cpp
+++ b/tools/viewer/SKPSlide.cpp
@@ -35,8 +35,8 @@ void SKPSlide::draw(SkCanvas* canvas) {
}
static sk_sp<SkPicture> read_picture(const char path[]) {
- std::unique_ptr<SkStream> stream = SkStream::MakeFromFile(path);
- if (!stream) {
+ SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(path));
+ if (stream.get() == nullptr) {
SkDebugf("Could not read %s.\n", path);
return nullptr;
}