SkMakeUnique.h defines skstd::make_unique<T>(Args...)
BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2293963002 Review-Url: https://codereview.chromium.org/2293963002
This commit is contained in:
parent
233eb0adc7
commit
022c2bd37a
23
src/core/SkMakeUnique.h
Normal file
23
src/core/SkMakeUnique.h
Normal file
@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright 2016 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#ifndef SkMakeUnique_DEFINED
|
||||
#define SkMakeUnique_DEFINED
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace skstd {
|
||||
|
||||
// std::make_unique is in C++14
|
||||
template<typename T, typename... Args>
|
||||
std::unique_ptr<T> make_unique(Args&&... args) {
|
||||
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif // SkMakeUnique_DEFINED
|
@ -8,6 +8,7 @@
|
||||
|
||||
#include "SkData.h"
|
||||
#include "SkDeflate.h"
|
||||
#include "SkMakeUnique.h"
|
||||
|
||||
#include "zlib.h"
|
||||
|
||||
@ -62,7 +63,7 @@ struct SkDeflateWStream::Impl {
|
||||
SkDeflateWStream::SkDeflateWStream(SkWStream* out,
|
||||
int compressionLevel,
|
||||
bool gzip)
|
||||
: fImpl(new SkDeflateWStream::Impl) {
|
||||
: fImpl(skstd::make_unique<SkDeflateWStream::Impl>()) {
|
||||
fImpl->fOut = out;
|
||||
fImpl->fInBufferIndex = 0;
|
||||
if (!fImpl->fOut) {
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include "SkColorFilter.h"
|
||||
#include "SkDraw.h"
|
||||
#include "SkGlyphCache.h"
|
||||
#include "SkMakeUnique.h"
|
||||
#include "SkPath.h"
|
||||
#include "SkPathEffect.h"
|
||||
#include "SkPathOps.h"
|
||||
@ -1344,11 +1345,11 @@ std::unique_ptr<SkStreamAsset> SkPDFDevice::content() const {
|
||||
entry.fContent.writeToStream(&buffer);
|
||||
}
|
||||
gsState.drainStack();
|
||||
|
||||
return std::unique_ptr<SkStreamAsset>(
|
||||
buffer.bytesWritten() > 0
|
||||
? buffer.detachAsStream()
|
||||
: new SkMemoryStream);
|
||||
if (buffer.bytesWritten() > 0) {
|
||||
return std::unique_ptr<SkStreamAsset>(buffer.detachAsStream());
|
||||
} else {
|
||||
return skstd::make_unique<SkMemoryStream>();
|
||||
}
|
||||
}
|
||||
|
||||
/* Draws an inverse filled path by using Path Ops to compute the positive
|
||||
|
@ -5,6 +5,7 @@
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "SkMakeUnique.h"
|
||||
#include "SkPDFCanon.h"
|
||||
#include "SkPDFCanvas.h"
|
||||
#include "SkPDFDevice.h"
|
||||
@ -167,7 +168,6 @@ static sk_sp<SkPDFDict> generate_page_tree(SkTArray<sk_sp<SkPDFDict>>* pages) {
|
||||
return std::move(curNodes[0]);
|
||||
}
|
||||
|
||||
template <typename T> static T* clone(const T* o) { return o ? new T(*o) : nullptr; }
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
SkPDFDocument::SkPDFDocument(SkWStream* stream,
|
||||
@ -466,7 +466,7 @@ sk_sp<SkDocument> SkPDFMakeDocument(SkWStream* stream,
|
||||
|
||||
sk_sp<SkDocument> SkDocument::MakePDF(const char path[], SkScalar dpi) {
|
||||
auto delete_wstream = [](SkWStream* stream, bool) { delete stream; };
|
||||
std::unique_ptr<SkFILEWStream> stream(new SkFILEWStream(path));
|
||||
auto stream = skstd::make_unique<SkFILEWStream>(path);
|
||||
return stream->isValid()
|
||||
? SkPDFMakeDocument(stream.release(), delete_wstream, dpi,
|
||||
SkDocument::PDFMetadata(), nullptr,
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
#include "SkData.h"
|
||||
#include "SkDeflate.h"
|
||||
#include "SkMakeUnique.h"
|
||||
#include "SkPDFTypes.h"
|
||||
#include "SkPDFUtils.h"
|
||||
#include "SkStream.h"
|
||||
@ -506,8 +507,7 @@ void SkPDFSharedStream::addResources(
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
SkPDFStream:: SkPDFStream(sk_sp<SkData> data) {
|
||||
this->setData(std::unique_ptr<SkStreamAsset>(
|
||||
new SkMemoryStream(std::move(data))));
|
||||
this->setData(skstd::make_unique<SkMemoryStream>(std::move(data)));
|
||||
}
|
||||
|
||||
SkPDFStream::SkPDFStream(std::unique_ptr<SkStreamAsset> stream) {
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include "SkDocument.h"
|
||||
#include "SkDeflate.h"
|
||||
#include "SkImageEncoder.h"
|
||||
#include "SkMakeUnique.h"
|
||||
#include "SkMatrix.h"
|
||||
#include "SkPDFCanon.h"
|
||||
#include "SkPDFDevice.h"
|
||||
@ -75,8 +76,8 @@ static void assert_emit_eq(skiatest::Reporter* reporter,
|
||||
|
||||
static void TestPDFStream(skiatest::Reporter* reporter) {
|
||||
char streamBytes[] = "Test\nFoo\tBar";
|
||||
std::unique_ptr<SkStreamAsset> streamData(new SkMemoryStream(
|
||||
streamBytes, strlen(streamBytes), true));
|
||||
auto streamData = skstd::make_unique<SkMemoryStream>(
|
||||
streamBytes, strlen(streamBytes), true);
|
||||
auto stream = sk_make_sp<SkPDFStream>(std::move(streamData));
|
||||
assert_emit_eq(reporter,
|
||||
*stream,
|
||||
|
Loading…
Reference in New Issue
Block a user