aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar halcanary <halcanary@google.com>2016-03-08 13:03:55 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2016-03-08 13:03:55 -0800
commit51d04d3c17954f9f8629e7d8a9fe870a7b19962f (patch)
tree0238b33291f8166aacc332d0c0d5df0c0b3e5dcf /src
parent647cc8474828202c98d540f799742e3074a2aace (diff)
Revert of SkPDF: Add sk_sp setters; .release() becomes std::move() (patchset #2 id:20001 of https://codereview.chromium.org/1775043002/ )
Reason for revert: https://build.chromium.org/p/client.skia/builders/Linux%20Builder/builds/6405/steps/compile/logs/stdio Original issue's description: > SkPDF: Add sk_sp setters; .release() becomes std::move() > > Note to reviewers: Start with changes to SkPDFTypes.h > > Many places that had a bare pointer owning a reference are refactored to > use a sk_sp. > > There remain several places where a non-owning pointer `T*` should be > replaced with `const sk_sp<T>&` to eliminate the common pattern > `sk_sp<T>(SkRef(x))`. > > Committed: https://skia.googlesource.com/skia/+/9904c9212074279380e21f96575078734dbbd308 TBR=bungeman@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/1775143002
Diffstat (limited to 'src')
-rw-r--r--src/doc/SkDocument_PDF.cpp91
-rw-r--r--src/pdf/SkPDFBitmap.cpp14
-rw-r--r--src/pdf/SkPDFDevice.cpp52
-rw-r--r--src/pdf/SkPDFDevice.h16
-rw-r--r--src/pdf/SkPDFFont.cpp76
-rw-r--r--src/pdf/SkPDFFormXObject.cpp10
-rw-r--r--src/pdf/SkPDFGraphicState.cpp19
-rw-r--r--src/pdf/SkPDFResourceDict.cpp10
-rw-r--r--src/pdf/SkPDFResourceDict.h2
-rw-r--r--src/pdf/SkPDFShader.cpp29
-rw-r--r--src/pdf/SkPDFTypes.cpp76
-rw-r--r--src/pdf/SkPDFTypes.h39
-rw-r--r--src/pdf/SkPDFUtils.cpp10
-rw-r--r--src/pdf/SkPDFUtils.h4
14 files changed, 236 insertions, 212 deletions
diff --git a/src/doc/SkDocument_PDF.cpp b/src/doc/SkDocument_PDF.cpp
index 101214d7ca..7e5e1a8eba 100644
--- a/src/doc/SkDocument_PDF.cpp
+++ b/src/doc/SkDocument_PDF.cpp
@@ -31,17 +31,17 @@ static void emit_pdf_footer(SkWStream* stream,
SkPDFObject* docCatalog,
int64_t objCount,
int32_t xRefFileOffset,
- sk_sp<SkPDFObject> info,
- sk_sp<SkPDFObject> id) {
+ SkPDFObject* info /* take ownership */,
+ SkPDFObject* id /* take ownership */) {
SkPDFDict trailerDict;
// TODO(http://crbug.com/80908): Linearized format will take a
// Prev entry too.
trailerDict.insertInt("Size", int(objCount));
- trailerDict.insertObjRef("Root", sk_sp<SkPDFObject>(SkRef(docCatalog)));
+ trailerDict.insertObjRef("Root", SkRef(docCatalog));
SkASSERT(info);
- trailerDict.insertObjRef("Info", std::move(info));
+ trailerDict.insertObjRef("Info", info);
if (id) {
- trailerDict.insertObject("ID", std::move(id));
+ trailerDict.insertObject("ID", id);
}
stream->writeText("trailer\n");
trailerDict.emitObject(stream, objNumMap, substitutes);
@@ -51,13 +51,13 @@ static void emit_pdf_footer(SkWStream* stream,
}
static void perform_font_subsetting(
- const SkTArray<sk_sp<const SkPDFDevice>>& pageDevices,
+ const SkTDArray<const SkPDFDevice*>& pageDevices,
SkPDFSubstituteMap* substituteMap) {
SkASSERT(substituteMap);
SkPDFGlyphSetMap usage;
- for (const sk_sp<const SkPDFDevice>& pageDevice : pageDevices) {
- usage.merge(pageDevice->getFontGlyphUsage());
+ for (int i = 0; i < pageDevices.count(); ++i) {
+ usage.merge(pageDevices[i]->getFontGlyphUsage());
}
SkPDFGlyphSetMap::F2BIter iterator(usage);
const SkPDFGlyphSetMap::FontGlyphSetPair* entry = iterator.next();
@@ -71,24 +71,27 @@ static void perform_font_subsetting(
}
}
-static sk_sp<SkPDFDict> create_pdf_page(const SkPDFDevice* pageDevice) {
+static SkPDFObject* create_pdf_page_content(const SkPDFDevice* pageDevice) {
+ SkAutoTDelete<SkStreamAsset> content(pageDevice->content());
+ return new SkPDFStream(content.get());
+}
+
+static SkPDFDict* create_pdf_page(const SkPDFDevice* pageDevice) {
auto page = sk_make_sp<SkPDFDict>("Page");
- page->insertObject("Resources", pageDevice->makeResourceDict());
+ page->insertObject("Resources", pageDevice->createResourceDict());
page->insertObject("MediaBox", pageDevice->copyMediaBox());
auto annotations = sk_make_sp<SkPDFArray>();
pageDevice->appendAnnotations(annotations.get());
if (annotations->size() > 0) {
- page->insertObject("Annots", std::move(annotations));
+ page->insertObject("Annots", annotations.release());
}
- auto content = pageDevice->content();
- page->insertObjRef("Contents", sk_make_sp<SkPDFStream>(content.get()));
- return std::move(page);
+ page->insertObjRef("Contents", create_pdf_page_content(pageDevice));
+ return page.release();
}
-// return root node.
-static sk_sp<SkPDFDict> generate_page_tree(
- const SkTDArray<SkPDFDict*>& pages,
- SkTDArray<SkPDFDict*>* pageTree) {
+static void generate_page_tree(const SkTDArray<SkPDFDict*>& pages,
+ SkTDArray<SkPDFDict*>* pageTree,
+ SkPDFDict** rootNode) {
// PDF wants a tree describing all the pages in the document. We arbitrary
// choose 8 (kNodeSize) as the number of allowed children. The internal
// nodes have type "Pages" with an array of children, a parent pointer, and
@@ -124,8 +127,8 @@ static sk_sp<SkPDFDict> generate_page_tree(
int count = 0;
for (; i < curNodes.count() && count < kNodeSize; i++, count++) {
- curNodes[i]->insertObjRef("Parent", newNode);
- kids->appendObjRef(sk_sp<SkPDFDict>(SkRef(curNodes[i])));
+ curNodes[i]->insertObjRef("Parent", SkRef(newNode.get()));
+ kids->appendObjRef(SkRef(curNodes[i]));
// TODO(vandebo): put the objects in strict access order.
// Probably doesn't matter because they are so small.
@@ -148,7 +151,7 @@ static sk_sp<SkPDFDict> generate_page_tree(
pageCount = ((pages.count() - 1) % treeCapacity) + 1;
}
newNode->insertInt("Count", pageCount);
- newNode->insertObject("Kids", std::move(kids));
+ newNode->insertObject("Kids", kids.release());
nextRoundNodes.push(newNode.release()); // Transfer reference.
}
@@ -158,30 +161,34 @@ static sk_sp<SkPDFDict> generate_page_tree(
} while (curNodes.count() > 1);
pageTree->push(curNodes[0]); // Transfer reference.
- return sk_sp<SkPDFDict>(SkRef(curNodes[0]));
+ if (rootNode) {
+ *rootNode = curNodes[0];
+ }
}
-static bool emit_pdf_document(const SkTArray<sk_sp<const SkPDFDevice>>& pageDevices,
+static bool emit_pdf_document(const SkTDArray<const SkPDFDevice*>& pageDevices,
const SkPDFMetadata& metadata,
SkWStream* stream) {
- if (pageDevices.empty()) {
+ if (pageDevices.isEmpty()) {
return false;
}
- SkTDArray<SkPDFDict*> pages; // TODO: SkTArray<sk_sp<SkPDFDict>>
+ SkTDArray<SkPDFDict*> pages;
auto dests = sk_make_sp<SkPDFDict>();
- for (const sk_sp<const SkPDFDevice>& pageDevice : pageDevices) {
- SkASSERT(pageDevice);
- SkASSERT(pageDevices[0]->getCanon() == pageDevice->getCanon());
- sk_sp<SkPDFDict> page(create_pdf_page(pageDevice.get()));
- pageDevice->appendDestinations(dests.get(), page.get());
+ for (int i = 0; i < pageDevices.count(); i++) {
+ SkASSERT(pageDevices[i]);
+ SkASSERT(i == 0 ||
+ pageDevices[i - 1]->getCanon() == pageDevices[i]->getCanon());
+ sk_sp<SkPDFDict> page(create_pdf_page(pageDevices[i]));
+ pageDevices[i]->appendDestinations(dests.get(), page.get());
pages.push(page.release());
}
auto docCatalog = sk_make_sp<SkPDFDict>("Catalog");
- sk_sp<SkPDFObject> infoDict(metadata.createDocumentInformationDict());
+ sk_sp<SkPDFObject> infoDict(
+ metadata.createDocumentInformationDict());
sk_sp<SkPDFObject> id, xmp;
#ifdef SK_PDF_GENERATE_PDFA
@@ -193,7 +200,7 @@ static bool emit_pdf_document(const SkTArray<sk_sp<const SkPDFDevice>>& pageDevi
// works best with reproducible outputs.
id.reset(SkPDFMetadata::CreatePdfId(uuid, uuid));
xmp.reset(metadata.createXMPObject(uuid, uuid));
- docCatalog->insertObjRef("Metadata", std::move(xmp));
+ docCatalog->insertObjRef("Metadata", xmp.release());
// sRGB is specified by HTML, CSS, and SVG.
auto outputIntent = sk_make_sp<SkPDFDict>("OutputIntent");
@@ -202,17 +209,19 @@ static bool emit_pdf_document(const SkTArray<sk_sp<const SkPDFDevice>>& pageDevi
outputIntent->insertString("OutputConditionIdentifier",
"sRGB IEC61966-2.1");
auto intentArray = sk_make_sp<SkPDFArray>();
- intentArray->appendObject(std::move(outputIntent));
+ intentArray->appendObject(outputIntent.release());
// Don't specify OutputIntents if we are not in PDF/A mode since
// no one has ever asked for this feature.
- docCatalog->insertObject("OutputIntents", std::move(intentArray));
+ docCatalog->insertObject("OutputIntents", intentArray.release());
#endif
SkTDArray<SkPDFDict*> pageTree;
- docCatalog->insertObjRef("Pages", generate_page_tree(pages, &pageTree));
+ SkPDFDict* pageTreeRoot;
+ generate_page_tree(pages, &pageTree, &pageTreeRoot);
+ docCatalog->insertObjRef("Pages", SkRef(pageTreeRoot));
if (dests->size() > 0) {
- docCatalog->insertObjRef("Dests", std::move(dests));
+ docCatalog->insertObjRef("Dests", dests.release());
}
// Build font subsetting info before proceeding.
@@ -253,7 +262,7 @@ static bool emit_pdf_document(const SkTArray<sk_sp<const SkPDFDevice>>& pageDevi
stream->writeText(" 00000 n \n");
}
emit_pdf_footer(stream, objNumMap, substitutes, docCatalog.get(), objCount,
- xRefFileOffset, std::move(infoDict), std::move(id));
+ xRefFileOffset, infoDict.release(), id.release());
// The page tree has both child and parent pointers, so it creates a
// reference cycle. We must clear that cycle to properly reclaim memory.
@@ -335,7 +344,7 @@ protected:
sk_sp<SkPDFDevice> device(
SkPDFDevice::Create(pageSize, fRasterDpi, &fCanon));
fCanvas.reset(new SkCanvas(device.get()));
- fPageDevices.push_back(std::move(device));
+ fPageDevices.push(device.release());
fCanvas->clipRect(trimBox);
fCanvas->translate(trimBox.x(), trimBox.y());
return fCanvas.get();
@@ -351,13 +360,13 @@ protected:
SkASSERT(!fCanvas.get());
bool success = emit_pdf_document(fPageDevices, fMetadata, stream);
- fPageDevices.reset();
+ fPageDevices.unrefAll();
fCanon.reset();
return success;
}
void onAbort() override {
- fPageDevices.reset();
+ fPageDevices.unrefAll();
fCanon.reset();
}
@@ -372,7 +381,7 @@ protected:
private:
SkPDFCanon fCanon;
- SkTArray<sk_sp<const SkPDFDevice>> fPageDevices;
+ SkTDArray<const SkPDFDevice*> fPageDevices;
sk_sp<SkCanvas> fCanvas;
SkScalar fRasterDpi;
SkPDFMetadata fMetadata;
diff --git a/src/pdf/SkPDFBitmap.cpp b/src/pdf/SkPDFBitmap.cpp
index 6c97fbbce0..1e2e26aa71 100644
--- a/src/pdf/SkPDFBitmap.cpp
+++ b/src/pdf/SkPDFBitmap.cpp
@@ -297,8 +297,8 @@ static void bitmap_alpha_to_a8(const SkBitmap& bitmap, SkWStream* out) {
}
}
-static sk_sp<SkPDFArray> make_indexed_color_space(const SkColorTable* table) {
- auto result = sk_make_sp<SkPDFArray>();
+static SkPDFArray* make_indexed_color_space(const SkColorTable* table) {
+ SkPDFArray* result = new SkPDFArray;
result->reserve(4);
result->appendName("Indexed");
result->appendName("DeviceRGB");
@@ -308,7 +308,7 @@ static sk_sp<SkPDFArray> make_indexed_color_space(const SkColorTable* table) {
char shortTableArray[3] = {0, 0, 0};
SkString tableString(shortTableArray, SK_ARRAY_COUNT(shortTableArray));
result->appendString(tableString);
- return std::move(result);
+ return result;
}
result->appendInt(table->count() - 1); // maximum color index.
@@ -324,13 +324,13 @@ static sk_sp<SkPDFArray> make_indexed_color_space(const SkColorTable* table) {
}
SkString tableString(tableArray, 3 * table->count());
result->appendString(tableString);
- return std::move(result);
+ return result;
}
static void emit_image_xobject(SkWStream* stream,
const SkImage* image,
bool alpha,
- const sk_sp<SkPDFObject>& smask,
+ SkPDFObject* smask,
const SkPDFObjNumMap& objNumMap,
const SkPDFSubstituteMap& substitutes) {
SkBitmap bitmap;
@@ -364,7 +364,7 @@ static void emit_image_xobject(SkWStream* stream,
pdfDict.insertName("ColorSpace", "DeviceRGB");
}
if (smask) {
- pdfDict.insertObjRef("SMask", smask);
+ pdfDict.insertObjRef("SMask", SkRef(smask));
}
pdfDict.insertInt("BitsPerComponent", 8);
pdfDict.insertName("Filter", "FlateDecode");
@@ -404,7 +404,7 @@ public:
void emitObject(SkWStream* stream,
const SkPDFObjNumMap& objNumMap,
const SkPDFSubstituteMap& subs) const override {
- emit_image_xobject(stream, fImage.get(), false, fSMask, objNumMap, subs);
+ emit_image_xobject(stream, fImage.get(), false, fSMask.get(), objNumMap, subs);
}
void addResources(SkPDFObjNumMap* catalog,
const SkPDFSubstituteMap& subs) const override {
diff --git a/src/pdf/SkPDFDevice.cpp b/src/pdf/SkPDFDevice.cpp
index 9f7a3700ef..e988112f37 100644
--- a/src/pdf/SkPDFDevice.cpp
+++ b/src/pdf/SkPDFDevice.cpp
@@ -879,7 +879,7 @@ void SkPDFDevice::drawPoints(const SkDraw& d,
}
}
-static sk_sp<SkPDFDict> create_link_annotation(const SkRect& translatedRect) {
+static SkPDFDict* create_link_annotation(const SkRect& translatedRect) {
auto annotation = sk_make_sp<SkPDFDict>("Annot");
annotation->insertName("Subtype", "Link");
@@ -888,7 +888,7 @@ static sk_sp<SkPDFDict> create_link_annotation(const SkRect& translatedRect) {
border->appendInt(0); // Horizontal corner radius.
border->appendInt(0); // Vertical corner radius.
border->appendInt(0); // Width, 0 = no border.
- annotation->insertObject("Border", std::move(border));
+ annotation->insertObject("Border", border.release());
auto rect = sk_make_sp<SkPDFArray>();
rect->reserve(4);
@@ -896,29 +896,30 @@ static sk_sp<SkPDFDict> create_link_annotation(const SkRect& translatedRect) {
rect->appendScalar(translatedRect.fTop);
rect->appendScalar(translatedRect.fRight);
rect->appendScalar(translatedRect.fBottom);
- annotation->insertObject("Rect", std::move(rect));
+ annotation->insertObject("Rect", rect.release());
- return std::move(annotation);
+ return annotation.release();
}
-static sk_sp<SkPDFDict> create_link_to_url(const SkData* urlData, const SkRect& r) {
- auto annotation = create_link_annotation(r);
+static SkPDFDict* create_link_to_url(const SkData* urlData, const SkRect& r) {
+ sk_sp<SkPDFDict> annotation(create_link_annotation(r));
+
SkString url(static_cast<const char *>(urlData->data()),
urlData->size() - 1);
auto action = sk_make_sp<SkPDFDict>("Action");
action->insertName("S", "URI");
action->insertString("URI", url);
- annotation->insertObject("A", std::move(action));
- return std::move(annotation);
+ annotation->insertObject("A", action.release());
+ return annotation.release();
}
-static sk_sp<SkPDFDict> create_link_named_dest(const SkData* nameData,
- const SkRect& r) {
- auto annotation = create_link_annotation(r);
+static SkPDFDict* create_link_named_dest(const SkData* nameData,
+ const SkRect& r) {
+ sk_sp<SkPDFDict> annotation(create_link_annotation(r));
SkString name(static_cast<const char *>(nameData->data()),
nameData->size() - 1);
annotation->insertName("Dest", name);
- return std::move(annotation);
+ return annotation.release();
}
void SkPDFDevice::drawRect(const SkDraw& d,
@@ -1506,13 +1507,13 @@ void SkPDFDevice::setDrawingArea(DrawingArea drawingArea) {
fDrawingArea = drawingArea;
}
-sk_sp<SkPDFDict> SkPDFDevice::makeResourceDict() const {
+SkPDFDict* SkPDFDevice::createResourceDict() const {
SkTDArray<SkPDFObject*> fonts;
fonts.setReserve(fFontResources.count());
for (SkPDFFont* font : fFontResources) {
fonts.push(font);
}
- return SkPDFResourceDict::Make(
+ return SkPDFResourceDict::Create(
&fGraphicStateResources,
&fShaderResources,
&fXObjectResources,
@@ -1523,23 +1524,24 @@ const SkTDArray<SkPDFFont*>& SkPDFDevice::getFontResources() const {
return fFontResources;
}
-sk_sp<SkPDFArray> SkPDFDevice::copyMediaBox() const {
+SkPDFArray* SkPDFDevice::copyMediaBox() const {
+ // should this be a singleton?
+
auto mediaBox = sk_make_sp<SkPDFArray>();
mediaBox->reserve(4);
mediaBox->appendInt(0);
mediaBox->appendInt(0);
- mediaBox->appendInt(fPageSize.width());
- mediaBox->appendInt(fPageSize.height());
- return std::move(mediaBox);
+ mediaBox->appendInt(fPageSize.fWidth);
+ mediaBox->appendInt(fPageSize.fHeight);
+ return mediaBox.release();
}
-skstd::unique_ptr<SkStreamAsset> SkPDFDevice::content() const {
+SkStreamAsset* SkPDFDevice::content() const {
SkDynamicMemoryWStream buffer;
this->writeContent(&buffer);
- return skstd::unique_ptr<SkStreamAsset>(
- buffer.bytesWritten() > 0
- ? buffer.detachAsStream()
- : new SkMemoryStream);
+ return buffer.bytesWritten() > 0
+ ? buffer.detachAsStream()
+ : new SkMemoryStream;
}
void SkPDFDevice::copyContentEntriesToData(ContentEntry* entry,
@@ -1711,14 +1713,14 @@ void SkPDFDevice::appendDestinations(SkPDFDict* dict, SkPDFObject* page) const {
for (const NamedDestination& dest : fNamedDestinations) {
auto pdfDest = sk_make_sp<SkPDFArray>();
pdfDest->reserve(5);
- pdfDest->appendObjRef(sk_sp<SkPDFObject>(SkRef(page)));
+ pdfDest->appendObjRef(SkRef(page));
pdfDest->appendName("XYZ");
SkPoint p = fInitialTransform.mapXY(dest.point.x(), dest.point.y());
pdfDest->appendScalar(p.x());
pdfDest->appendScalar(p.y());
pdfDest->appendInt(0); // Leave zoom unchanged
SkString name(static_cast<const char*>(dest.nameData->data()));
- dict->insertObject(name, std::move(pdfDest));
+ dict->insertObject(name, pdfDest.release());
}
}
diff --git a/src/pdf/SkPDFDevice.h b/src/pdf/SkPDFDevice.h
index b1345a8e3f..310807d86e 100644
--- a/src/pdf/SkPDFDevice.h
+++ b/src/pdf/SkPDFDevice.h
@@ -144,8 +144,9 @@ public:
// PDF specific methods.
- /** Create the resource dictionary for this device. */
- sk_sp<SkPDFDict> makeResourceDict() const;
+ /** Create the resource dictionary for this device.
+ */
+ SkPDFDict* createResourceDict() const;
/** Get the fonts used on this device.
*/
@@ -163,12 +164,15 @@ public:
*/
void appendDestinations(SkPDFDict* dict, SkPDFObject* page) const;
- /** Returns a copy of the media box for this device. */
- sk_sp<SkPDFArray> copyMediaBox() const;
+ /** Returns a copy of the media box for this device. The caller is required
+ * to unref() this when it is finished.
+ */
+ SkPDFArray* copyMediaBox() const;
- /** Returns a SkStream with the page contents.
+ /** Returns a SkStream with the page contents. The caller is responsible
+ * for a deleting the returned value.
*/
- skstd::unique_ptr<SkStreamAsset> content() const;
+ SkStreamAsset* content() const;
/** Writes the page contents to the stream. */
void writeContent(SkWStream*) const;
diff --git a/src/pdf/SkPDFFont.cpp b/src/pdf/SkPDFFont.cpp
index f5fd410ad0..8615db99ec 100644
--- a/src/pdf/SkPDFFont.cpp
+++ b/src/pdf/SkPDFFont.cpp
@@ -297,35 +297,37 @@ void setGlyphWidthAndBoundingBox(SkScalar width, SkIRect box,
content->writeText(" d1\n");
}
-static sk_sp<SkPDFArray> makeFontBBox(SkIRect glyphBBox, uint16_t emSize) {
- auto bbox = sk_make_sp<SkPDFArray>();
+SkPDFArray* makeFontBBox(SkIRect glyphBBox, uint16_t emSize) {
+ SkPDFArray* bbox = new SkPDFArray;
bbox->reserve(4);
bbox->appendScalar(scaleFromFontUnits(glyphBBox.fLeft, emSize));
bbox->appendScalar(scaleFromFontUnits(glyphBBox.fBottom, emSize));
bbox->appendScalar(scaleFromFontUnits(glyphBBox.fRight, emSize));
bbox->appendScalar(scaleFromFontUnits(glyphBBox.fTop, emSize));
- return std::move(bbox);
+ return bbox;
}
-static void appendWidth(const int16_t& width, uint16_t emSize,
+SkPDFArray* appendWidth(const int16_t& width, uint16_t emSize,
SkPDFArray* array) {
array->appendScalar(scaleFromFontUnits(width, emSize));
+ return array;
}
-static void appendVerticalAdvance(
+SkPDFArray* appendVerticalAdvance(
const SkAdvancedTypefaceMetrics::VerticalMetric& advance,
uint16_t emSize, SkPDFArray* array) {
appendWidth(advance.fVerticalAdvance, emSize, array);
appendWidth(advance.fOriginXDisp, emSize, array);
appendWidth(advance.fOriginYDisp, emSize, array);
+ return array;
}
template <typename Data>
SkPDFArray* composeAdvanceData(
SkAdvancedTypefaceMetrics::AdvanceMetric<Data>* advanceInfo,
uint16_t emSize,
- void (*appendAdvance)(const Data& advance, uint16_t emSize,
- SkPDFArray* array),
+ SkPDFArray* (*appendAdvance)(const Data& advance, uint16_t emSize,
+ SkPDFArray* array),
Data* defaultAdvance) {
SkPDFArray* result = new SkPDFArray();
for (; advanceInfo != nullptr; advanceInfo = advanceInfo->fNext.get()) {
@@ -341,7 +343,7 @@ SkPDFArray* composeAdvanceData(
appendAdvance(advanceInfo->fAdvance[j], emSize,
advanceArray.get());
result->appendInt(advanceInfo->fStartId);
- result->appendObject(std::move(advanceArray));
+ result->appendObject(advanceArray.release());
break;
}
case SkAdvancedTypefaceMetrics::WidthRange::kRun: {
@@ -557,7 +559,7 @@ void append_cmap_sections(const SkTDArray<SkUnichar>& glyphToUnicode,
append_bfrange_section(bfrangeEntries, cmap);
}
-static sk_sp<SkPDFStream> generate_tounicode_cmap(
+static SkPDFStream* generate_tounicode_cmap(
const SkTDArray<SkUnichar>& glyphToUnicode,
const SkPDFGlyphSet* subset,
bool multiByteGlyphs,
@@ -573,7 +575,7 @@ static sk_sp<SkPDFStream> generate_tounicode_cmap(
firstGlyphID, lastGlyphID);
append_cmap_footer(&cmap);
sk_sp<SkData> cmapData(cmap.copyToData());
- return sk_make_sp<SkPDFStream>(cmapData.get());
+ return new SkPDFStream(cmapData.get());
}
#if defined (SK_SFNTLY_SUBSETTER)
@@ -1020,8 +1022,8 @@ bool SkPDFType0Font::populate(const SkPDFGlyphSet* subset) {
sk_sp<SkPDFCIDFont> newCIDFont(
new SkPDFCIDFont(fontInfo(), typeface(), subset));
auto descendantFonts = sk_make_sp<SkPDFArray>();
- descendantFonts->appendObjRef(std::move(newCIDFont));
- this->insertObject("DescendantFonts", std::move(descendantFonts));
+ descendantFonts->appendObjRef(newCIDFont.release());
+ this->insertObject("DescendantFonts", descendantFonts.release());
this->populateToUnicodeTable(subset);
@@ -1047,7 +1049,7 @@ bool SkPDFCIDFont::addFontDescriptor(int16_t defaultWidth,
auto descriptor = sk_make_sp<SkPDFDict>("FontDescriptor");
setFontDescriptor(descriptor.get());
if (!addCommonFontDescriptorEntries(defaultWidth)) {
- this->insertObjRef("FontDescriptor", std::move(descriptor));
+ this->insertObjRef("FontDescriptor", descriptor.release());
return false;
}
SkASSERT(this->canEmbed());
@@ -1066,7 +1068,7 @@ bool SkPDFCIDFont::addFontDescriptor(int16_t defaultWidth,
if (rawStream) {
fontStream.reset(rawStream);
fontStream->insertInt("Length1", fontSize);
- descriptor->insertObjRef("FontFile2", std::move(fontStream));
+ descriptor->insertObjRef("FontFile2", fontStream.release());
break;
}
}
@@ -1079,7 +1081,7 @@ bool SkPDFCIDFont::addFontDescriptor(int16_t defaultWidth,
SkASSERT(fontSize > 0);
fontStream.reset(new SkPDFSharedStream(fontData.detach()));
fontStream->dict()->insertInt("Length1", fontSize);
- descriptor->insertObjRef("FontFile2", std::move(fontStream));
+ descriptor->insertObjRef("FontFile2", fontStream.release());
break;
}
case SkAdvancedTypefaceMetrics::kCFF_Font:
@@ -1092,13 +1094,13 @@ bool SkPDFCIDFont::addFontDescriptor(int16_t defaultWidth,
} else {
fontStream->dict()->insertName("Subtype", "CIDFontType0c");
}
- descriptor->insertObjRef("FontFile3", std::move(fontStream));
+ descriptor->insertObjRef("FontFile3", fontStream.release());
break;
}
default:
SkASSERT(false);
}
- this->insertObjRef("FontDescriptor", std::move(descriptor));
+ this->insertObjRef("FontDescriptor", descriptor.release());
return true;
}
@@ -1145,7 +1147,7 @@ bool SkPDFCIDFont::populate(const SkPDFGlyphSet* subset) {
sysInfo->insertString("Registry", "Adobe");
sysInfo->insertString("Ordering", "Identity");
sysInfo->insertInt("Supplement", 0);
- this->insertObject("CIDSystemInfo", std::move(sysInfo));
+ this->insertObject("CIDSystemInfo", sysInfo.release());
if (fontInfo()->fGlyphWidths.get()) {
int16_t defaultWidth = 0;
@@ -1154,7 +1156,7 @@ bool SkPDFCIDFont::populate(const SkPDFGlyphSet* subset) {
fontInfo()->fEmSize, &appendWidth,
&defaultWidth));
if (widths->size())
- this->insertObject("W", std::move(widths));
+ this->insertObject("W", widths.release());
if (defaultWidth != 0) {
this->insertScalar(
"DW",
@@ -1171,15 +1173,14 @@ bool SkPDFCIDFont::populate(const SkPDFGlyphSet* subset) {
fontInfo()->fEmSize, &appendVerticalAdvance,
&defaultAdvance));
if (advances->size())
- this->insertObject("W2", std::move(advances));
+ this->insertObject("W2", advances.release());
if (defaultAdvance.fVerticalAdvance ||
defaultAdvance.fOriginXDisp ||
defaultAdvance.fOriginYDisp) {
- auto array = sk_make_sp<SkPDFArray>();
- appendVerticalAdvance(defaultAdvance,
- fontInfo()->fEmSize,
- array.get());
- this->insertObject("DW2", std::move(array));
+ this->insertObject("DW2",
+ appendVerticalAdvance(defaultAdvance,
+ fontInfo()->fEmSize,
+ new SkPDFArray));
}
}
@@ -1202,8 +1203,7 @@ SkPDFType1Font::~SkPDFType1Font() {}
bool SkPDFType1Font::addFontDescriptor(int16_t defaultWidth) {
if (SkPDFDict* descriptor = getFontDescriptor()) {
- this->insertObjRef("FontDescriptor",
- sk_sp<SkPDFDict>(SkRef(descriptor)));
+ this->insertObjRef("FontDescriptor", SkRef(descriptor));
return true;
}
@@ -1225,9 +1225,9 @@ bool SkPDFType1Font::addFontDescriptor(int16_t defaultWidth) {
fontStream->insertInt("Length1", header);
fontStream->insertInt("Length2", data);
fontStream->insertInt("Length3", trailer);
- descriptor->insertObjRef("FontFile", std::move(fontStream));
+ descriptor->insertObjRef("FontFile", fontStream.release());
- this->insertObjRef("FontDescriptor", std::move(descriptor));
+ this->insertObjRef("FontDescriptor", descriptor.release());
return addCommonFontDescriptorEntries(defaultWidth);
}
@@ -1276,8 +1276,8 @@ bool SkPDFType1Font::populate(int16_t glyphID) {
}
auto encoding = sk_make_sp<SkPDFDict>("Encoding");
- encoding->insertObject("Differences", std::move(encDiffs));
- this->insertObject("Encoding", std::move(encoding));
+ encoding->insertObject("Differences", encDiffs.release());
+ this->insertObject("Encoding", encoding.release());
return true;
}
@@ -1307,7 +1307,7 @@ void SkPDFType1Font::addWidthInfoFromRange(
}
this->insertInt("FirstChar", firstChar);
this->insertInt("LastChar", firstChar + widthArray->size() - 1);
- this->insertObject("Widths", std::move(widthArray));
+ this->insertObject("Widths", widthArray.release());
}
///////////////////////////////////////////////////////////////////////////////
@@ -1376,19 +1376,19 @@ bool SkPDFType3Font::populate(uint16_t glyphID) {
SkAutoTDelete<SkMemoryStream> glyphStream(new SkMemoryStream());
glyphStream->setData(content.copyToData())->unref();
- charProcs->insertObjRef(
- characterName, sk_make_sp<SkPDFStream>(glyphStream.get()));
+ charProcs->insertObjRef(characterName,
+ new SkPDFStream(glyphStream.get()));
}
- encoding->insertObject("Differences", std::move(encDiffs));
+ encoding->insertObject("Differences", encDiffs.release());
- this->insertObject("CharProcs", std::move(charProcs));
- this->insertObject("Encoding", std::move(encoding));
+ this->insertObject("CharProcs", charProcs.release());
+ this->insertObject("Encoding", encoding.release());
this->insertObject("FontBBox", makeFontBBox(bbox, 1000));
this->insertInt("FirstChar", 1);
this->insertInt("LastChar", lastGlyphID() - firstGlyphID() + 1);
- this->insertObject("Widths", std::move(widthArray));
+ this->insertObject("Widths", widthArray.release());
this->insertName("CIDToGIDMap", "Identity");
this->populateToUnicodeTable(nullptr);
diff --git a/src/pdf/SkPDFFormXObject.cpp b/src/pdf/SkPDFFormXObject.cpp
index d565ab81e1..abf331f544 100644
--- a/src/pdf/SkPDFFormXObject.cpp
+++ b/src/pdf/SkPDFFormXObject.cpp
@@ -19,9 +19,9 @@ SkPDFFormXObject::SkPDFFormXObject(SkPDFDevice* device) {
// We don't want to keep around device because we'd have two copies
// of content, so reference or copy everything we need (content and
// resources).
- auto resourceDict = device->makeResourceDict();
+ sk_sp<SkPDFDict> resourceDict(device->createResourceDict());
- auto content = device->content();
+ SkAutoTDelete<SkStreamAsset> content(device->content());
this->setData(content.get());
sk_sp<SkPDFArray> bboxArray(device->copyMediaBox());
@@ -60,8 +60,8 @@ void SkPDFFormXObject::init(const char* colorSpace,
SkPDFDict* resourceDict, SkPDFArray* bbox) {
this->insertName("Type", "XObject");
this->insertName("Subtype", "Form");
- this->insertObject("Resources", sk_sp<SkPDFDict>(SkRef(resourceDict)));
- this->insertObject("BBox", sk_sp<SkPDFArray>(SkRef(bbox)));
+ this->insertObject("Resources", SkRef(resourceDict));
+ this->insertObject("BBox", SkRef(bbox));
// Right now SkPDFFormXObject is only used for saveLayer, which implies
// isolated blending. Do this conditionally if that changes.
@@ -72,7 +72,7 @@ void SkPDFFormXObject::init(const char* colorSpace,
group->insertName("CS", colorSpace);
}
group->insertBool("I", true); // Isolated.
- this->insertObject("Group", std::move(group));
+ this->insertObject("Group", group.release());
}
SkPDFFormXObject::~SkPDFFormXObject() {}
diff --git a/src/pdf/SkPDFGraphicState.cpp b/src/pdf/SkPDFGraphicState.cpp
index 19e9a36d05..7c4c5e30eb 100644
--- a/src/pdf/SkPDFGraphicState.cpp
+++ b/src/pdf/SkPDFGraphicState.cpp
@@ -126,7 +126,7 @@ SkPDFGraphicState* SkPDFGraphicState::GetGraphicStateForPaint(
return pdfGraphicState;
}
-static SkPDFStream* create_invert_function() {
+static SkPDFObject* create_invert_function() {
// Acrobat crashes if we use a type 0 function, kpdf crashes if we use
// a type 2 function, so we use a type 4 function.
auto domainAndRange = sk_make_sp<SkPDFArray>();
@@ -141,17 +141,12 @@ static SkPDFStream* create_invert_function() {
auto invertFunction = sk_make_sp<SkPDFStream>(psInvertStream.get());
invertFunction->insertInt("FunctionType", 4);
- invertFunction->insertObject("Domain", domainAndRange);
- invertFunction->insertObject("Range", std::move(domainAndRange));
+ invertFunction->insertObject("Domain", SkRef(domainAndRange.get()));
+ invertFunction->insertObject("Range", domainAndRange.release());
return invertFunction.release();
}
-SK_DECLARE_STATIC_ONCE_PTR(SkPDFStream, invertFunction);
-
-static sk_sp<SkPDFStream> make_invert_function() {
- return sk_sp<SkPDFStream>(
- SkRef(invertFunction.get(create_invert_function)));
-}
+SK_DECLARE_STATIC_ONCE_PTR(SkPDFObject, invertFunction);
// static
SkPDFDict* SkPDFGraphicState::GetSMaskGraphicState(SkPDFFormXObject* sMask,
@@ -165,13 +160,13 @@ SkPDFDict* SkPDFGraphicState::GetSMaskGraphicState(SkPDFFormXObject* sMask,
} else if (sMaskMode == kLuminosity_SMaskMode) {
sMaskDict->insertName("S", "Luminosity");
}
- sMaskDict->insertObjRef("G", sk_sp<SkPDFFormXObject>(SkRef(sMask)));
+ sMaskDict->insertObjRef("G", SkRef(sMask));
if (invert) {
- sMaskDict->insertObjRef("TR", make_invert_function());
+ sMaskDict->insertObjRef("TR", SkRef(invertFunction.get(create_invert_function)));
}
auto result = sk_make_sp<SkPDFDict>("ExtGState");
- result->insertObject("SMask", std::move(sMaskDict));
+ result->insertObject("SMask", sMaskDict.release());
return result.release();
}
diff --git a/src/pdf/SkPDFResourceDict.cpp b/src/pdf/SkPDFResourceDict.cpp
index 6c7f019c15..d3f4a6d533 100644
--- a/src/pdf/SkPDFResourceDict.cpp
+++ b/src/pdf/SkPDFResourceDict.cpp
@@ -64,12 +64,12 @@ static void add_subdict(
auto resources = sk_make_sp<SkPDFDict>();
for (int i = 0; i < resourceList.count(); i++) {
resources->insertObjRef(SkPDFResourceDict::getResourceName(type, i),
- sk_sp<SkPDFObject>(SkRef(resourceList[i])));
+ SkRef(resourceList[i]));
}
- dst->insertObject(get_resource_type_name(type), std::move(resources));
+ dst->insertObject(get_resource_type_name(type), resources.release());
}
-sk_sp<SkPDFDict> SkPDFResourceDict::Make(
+SkPDFDict* SkPDFResourceDict::Create(
const SkTDArray<SkPDFObject*>* gStateResources,
const SkTDArray<SkPDFObject*>* patternResources,
const SkTDArray<SkPDFObject*>* xObjectResources,
@@ -83,7 +83,7 @@ sk_sp<SkPDFDict> SkPDFResourceDict::Make(
for (size_t i = 0; i < SK_ARRAY_COUNT(kProcs); i++) {
procSets->appendName(kProcs[i]);
}
- dict->insertObject("ProcSets", std::move(procSets));
+ dict->insertObject("ProcSets", procSets.release());
if (gStateResources) {
add_subdict(*gStateResources, kExtGState_ResourceType, dict.get());
@@ -97,5 +97,5 @@ sk_sp<SkPDFDict> SkPDFResourceDict::Make(
if (fontResources) {
add_subdict(*fontResources, kFont_ResourceType, dict.get());
}
- return std::move(dict);
+ return dict.release();
}
diff --git a/src/pdf/SkPDFResourceDict.h b/src/pdf/SkPDFResourceDict.h
index c45b364adc..698823b36c 100644
--- a/src/pdf/SkPDFResourceDict.h
+++ b/src/pdf/SkPDFResourceDict.h
@@ -36,7 +36,7 @@ public:
*
* Any arguments can be nullptr.
*/
- static sk_sp<SkPDFDict> Make(
+ static SkPDFDict* Create(
const SkTDArray<SkPDFObject*>* gStateResources,
const SkTDArray<SkPDFObject*>* patternResources,
const SkTDArray<SkPDFObject*>* xObjectResources,
diff --git a/src/pdf/SkPDFShader.cpp b/src/pdf/SkPDFShader.cpp
index d5f114ec0f..95ef9dcca0 100644
--- a/src/pdf/SkPDFShader.cpp
+++ b/src/pdf/SkPDFShader.cpp
@@ -523,7 +523,7 @@ SkPDFObject* SkPDFShader::GetPDFShader(SkPDFCanon* canon,
return get_pdf_shader_by_state(canon, dpi, &state);
}
-static sk_sp<SkPDFDict> get_gradient_resource_dict(
+static SkPDFDict* get_gradient_resource_dict(
SkPDFObject* functionShader,
SkPDFObject* gState) {
SkTDArray<SkPDFObject*> patterns;
@@ -534,7 +534,7 @@ static sk_sp<SkPDFDict> get_gradient_resource_dict(
if (gState) {
graphicStates.push(gState);
}
- return SkPDFResourceDict::Make(&graphicStates, &patterns, nullptr, nullptr);
+ return SkPDFResourceDict::Create(&graphicStates, &patterns, nullptr, nullptr);
}
static void populate_tiling_pattern_dict(SkPDFDict* pattern,
@@ -552,7 +552,7 @@ static void populate_tiling_pattern_dict(SkPDFDict* pattern,
pattern->insertObject("BBox", SkPDFUtils::RectToArray(bbox));
pattern->insertScalar("XStep", bbox.width());
pattern->insertScalar("YStep", bbox.height());
- pattern->insertObject("Resources", sk_sp<SkPDFDict>(SkRef(resources)));
+ pattern->insertObject("Resources", SkRef(resources));
if (!matrix.isIdentity()) {
pattern->insertObject("Matrix", SkPDFUtils::MatrixToArray(matrix));
}
@@ -592,8 +592,8 @@ static SkPDFObject* create_smask_graphic_state(
SkAutoTDelete<SkStream> alphaStream(create_pattern_fill_content(-1, bbox));
- auto resources =
- get_gradient_resource_dict(luminosityShader.get(), nullptr);
+ sk_sp<SkPDFDict>
+ resources(get_gradient_resource_dict(luminosityShader.get(), nullptr));
sk_sp<SkPDFFormXObject> alphaMask(
new SkPDFFormXObject(alphaStream.get(), bbox, resources.get()));
@@ -627,8 +627,8 @@ SkPDFAlphaFunctionShader* SkPDFAlphaFunctionShader::Create(
SkPDFAlphaFunctionShader* alphaFunctionShader =
new SkPDFAlphaFunctionShader(autoState->detach());
- auto resourceDict =
- get_gradient_resource_dict(colorShader.get(), alphaGs.get());
+ sk_sp<SkPDFDict> resourceDict(
+ get_gradient_resource_dict(colorShader.get(), alphaGs.get()));
SkAutoTDelete<SkStream> colorStream(
create_pattern_fill_content(0, bbox));
@@ -697,8 +697,8 @@ static SkPDFStream* make_ps_function(const SkString& psCode,
SkData::NewWithCopy(psCode.c_str(), psCode.size()));
SkPDFStream* result = new SkPDFStream(funcData.get());
result->insertInt("FunctionType", 4);
- result->insertObject("Domain", sk_sp<SkPDFObject>(SkRef(domain)));
- result->insertObject("Range", sk_sp<SkPDFObject>(SkRef(rangeObject.get(create_range_object))));
+ result->insertObject("Domain", SkRef(domain));
+ result->insertObject("Range", SkRef(rangeObject.get(create_range_object)));
return result;
}
@@ -802,18 +802,18 @@ SkPDFFunctionShader* SkPDFFunctionShader::Create(
auto pdfShader = sk_make_sp<SkPDFDict>();
pdfShader->insertInt("ShadingType", 1);
pdfShader->insertName("ColorSpace", "DeviceRGB");
- pdfShader->insertObject("Domain", sk_sp<SkPDFObject>(SkRef(domain.get())));
+ pdfShader->insertObject("Domain", SkRef(domain.get()));
sk_sp<SkPDFStream> function(
make_ps_function(functionCode, domain.get()));
- pdfShader->insertObjRef("Function", std::move(function));
+ pdfShader->insertObjRef("Function", function.release());
sk_sp<SkPDFFunctionShader> pdfFunctionShader(
new SkPDFFunctionShader(autoState->detach()));
pdfFunctionShader->insertInt("PatternType", 2);
pdfFunctionShader->insertObject("Matrix",
SkPDFUtils::MatrixToArray(finalMatrix));
- pdfFunctionShader->insertObject("Shading", std::move(pdfShader));
+ pdfFunctionShader->insertObject("Shading", pdfShader.release());
canon->addFunctionShader(pdfFunctionShader.get());
return pdfFunctionShader.release();
@@ -1019,12 +1019,13 @@ SkPDFImageShader* SkPDFImageShader::Create(
}
// Put the canvas into the pattern stream (fContent).
- auto content = patternDevice->content();
+ SkAutoTDelete<SkStreamAsset> content(patternDevice->content());
SkPDFImageShader* imageShader = new SkPDFImageShader(autoState->detach());
imageShader->setData(content.get());
- auto resourceDict = patternDevice->makeResourceDict();
+ sk_sp<SkPDFDict> resourceDict(
+ patternDevice->createResourceDict());
populate_tiling_pattern_dict(imageShader, patternBBox,
resourceDict.get(), finalMatrix);
diff --git a/src/pdf/SkPDFTypes.cpp b/src/pdf/SkPDFTypes.cpp
index ced0e381f9..faa08372e5 100644
--- a/src/pdf/SkPDFTypes.cpp
+++ b/src/pdf/SkPDFTypes.cpp
@@ -1,3 +1,4 @@
+
/*
* Copyright 2011 Google Inc.
*
@@ -27,8 +28,7 @@ SkPDFUnion::~SkPDFUnion() {
return;
case Type::kObjRef:
case Type::kObject:
- SkASSERT(fObject);
- fObject->unref();
+ SkSafeUnref(fObject);
return;
default:
return;
@@ -38,7 +38,7 @@ SkPDFUnion::~SkPDFUnion() {
SkPDFUnion& SkPDFUnion::operator=(SkPDFUnion&& other) {
if (this != &other) {
this->~SkPDFUnion();
- new (this) SkPDFUnion(std::move(other));
+ new (this) SkPDFUnion(other.move());
}
return *this;
}
@@ -56,14 +56,14 @@ SkPDFUnion SkPDFUnion::copy() const {
switch (fType) {
case Type::kNameSkS:
case Type::kStringSkS:
- new (pun(u.fSkString)) SkString(*pun(fSkString));
- return std::move(u);
+ new (pun(u.fSkString)) SkString (*pun(fSkString));
+ return u.move();
case Type::kObjRef:
case Type::kObject:
SkRef(u.fObject);
- return std::move(u);
+ return u.move();
default:
- return std::move(u);
+ return u.move();
}
}
SkPDFUnion& SkPDFUnion::operator=(const SkPDFUnion& other) {
@@ -191,19 +191,19 @@ void SkPDFUnion::addResources(SkPDFObjNumMap* objNumMap,
SkPDFUnion SkPDFUnion::Int(int32_t value) {
SkPDFUnion u(Type::kInt);
u.fIntValue = value;
- return std::move(u);
+ return u.move();
}
SkPDFUnion SkPDFUnion::Bool(bool value) {
SkPDFUnion u(Type::kBool);
u.fBoolValue = value;
- return std::move(u);
+ return u.move();
}
SkPDFUnion SkPDFUnion::Scalar(SkScalar value) {
SkPDFUnion u(Type::kScalar);
u.fScalarValue = value;
- return std::move(u);
+ return u.move();
}
SkPDFUnion SkPDFUnion::Name(const char* value) {
@@ -211,40 +211,40 @@ SkPDFUnion SkPDFUnion::Name(const char* value) {
SkASSERT(value);
SkASSERT(is_valid_name(value));
u.fStaticString = value;
- return std::move(u);
+ return u.move();
}
SkPDFUnion SkPDFUnion::String(const char* value) {
SkPDFUnion u(Type::kString);
SkASSERT(value);
u.fStaticString = value;
- return std::move(u);
+ return u.move();
}
SkPDFUnion SkPDFUnion::Name(const SkString& s) {
SkPDFUnion u(Type::kNameSkS);
new (pun(u.fSkString)) SkString(s);
- return std::move(u);
+ return u.move();
}
SkPDFUnion SkPDFUnion::String(const SkString& s) {
SkPDFUnion u(Type::kStringSkS);
new (pun(u.fSkString)) SkString(s);
- return std::move(u);
+ return u.move();
}
-SkPDFUnion SkPDFUnion::ObjRef(sk_sp<SkPDFObject> objSp) {
+SkPDFUnion SkPDFUnion::ObjRef(SkPDFObject* ptr) {
SkPDFUnion u(Type::kObjRef);
- SkASSERT(objSp.get());
- u.fObject = objSp.release(); // take ownership into union{}
- return std::move(u);
+ SkASSERT(ptr);
+ u.fObject = ptr;
+ return u.move();
}
-SkPDFUnion SkPDFUnion::Object(sk_sp<SkPDFObject> objSp) {
+SkPDFUnion SkPDFUnion::Object(SkPDFObject* ptr) {
SkPDFUnion u(Type::kObject);
- SkASSERT(objSp.get());
- u.fObject = objSp.release(); // take ownership into union{}
- return std::move(u);
+ SkASSERT(ptr);
+ u.fObject = ptr;
+ return u.move();
}
////////////////////////////////////////////////////////////////////////////////
@@ -295,9 +295,7 @@ void SkPDFArray::addResources(SkPDFObjNumMap* catalog,
}
}
-void SkPDFArray::append(SkPDFUnion&& value) {
- new (fValues.append()) SkPDFUnion(std::move(value));
-}
+void SkPDFArray::append(SkPDFUnion&& value) { new (fValues.append()) SkPDFUnion(value.move()); }
void SkPDFArray::appendInt(int32_t value) {
this->append(SkPDFUnion::Int(value));
@@ -327,12 +325,12 @@ void SkPDFArray::appendString(const char value[]) {
this->append(SkPDFUnion::String(value));
}
-void SkPDFArray::appendObject(sk_sp<SkPDFObject> objSp) {
- this->append(SkPDFUnion::Object(std::move(objSp)));
+void SkPDFArray::appendObject(SkPDFObject* value) {
+ this->append(SkPDFUnion::Object(value));
}
-void SkPDFArray::appendObjRef(sk_sp<SkPDFObject> objSp) {
- this->append(SkPDFUnion::ObjRef(std::move(objSp)));
+void SkPDFArray::appendObjRef(SkPDFObject* value) {
+ this->append(SkPDFUnion::ObjRef(value));
}
///////////////////////////////////////////////////////////////////////////////
@@ -375,24 +373,24 @@ void SkPDFDict::addResources(SkPDFObjNumMap* catalog,
void SkPDFDict::set(SkPDFUnion&& name, SkPDFUnion&& value) {
Record* rec = fRecords.append();
SkASSERT(name.isName());
- new (&rec->fKey) SkPDFUnion(std::move(name));
- new (&rec->fValue) SkPDFUnion(std::move(value));
+ new (&rec->fKey) SkPDFUnion(name.move());
+ new (&rec->fValue) SkPDFUnion(value.move());
}
int SkPDFDict::size() const { return fRecords.count(); }
-void SkPDFDict::insertObjRef(const char key[], sk_sp<SkPDFObject> objSp) {
- this->set(SkPDFUnion::Name(key), SkPDFUnion::ObjRef(std::move(objSp)));
+void SkPDFDict::insertObjRef(const char key[], SkPDFObject* value) {
+ this->set(SkPDFUnion::Name(key), SkPDFUnion::ObjRef(value));
}
-void SkPDFDict::insertObjRef(const SkString& key, sk_sp<SkPDFObject> objSp) {
- this->set(SkPDFUnion::Name(key), SkPDFUnion::ObjRef(std::move(objSp)));
+void SkPDFDict::insertObjRef(const SkString& key, SkPDFObject* value) {
+ this->set(SkPDFUnion::Name(key), SkPDFUnion::ObjRef(value));
}
-void SkPDFDict::insertObject(const char key[], sk_sp<SkPDFObject> objSp) {
- this->set(SkPDFUnion::Name(key), SkPDFUnion::Object(std::move(objSp)));
+void SkPDFDict::insertObject(const char key[], SkPDFObject* value) {
+ this->set(SkPDFUnion::Name(key), SkPDFUnion::Object(value));
}
-void SkPDFDict::insertObject(const SkString& key, sk_sp<SkPDFObject> objSp) {
- this->set(SkPDFUnion::Name(key), SkPDFUnion::Object(std::move(objSp)));
+void SkPDFDict::insertObject(const SkString& key, SkPDFObject* value) {
+ this->set(SkPDFUnion::Name(key), SkPDFUnion::Object(value));
}
void SkPDFDict::insertBool(const char key[], bool value) {
diff --git a/src/pdf/SkPDFTypes.h b/src/pdf/SkPDFTypes.h
index f93b030465..a6a3e12ee6 100644
--- a/src/pdf/SkPDFTypes.h
+++ b/src/pdf/SkPDFTypes.h
@@ -39,6 +39,7 @@ public:
* @param catalog The object catalog to use.
* @param stream The writable output stream to send the output to.
*/
+ // TODO(halcanary): make this method const
virtual void emitObject(SkWStream* stream,
const SkPDFObjNumMap& objNumMap,
const SkPDFSubstituteMap& substitutes) const = 0;
@@ -64,6 +65,8 @@ private:
*/
class SkPDFUnion {
public:
+ // u.move() is analogous to std::move(u). It returns an rvalue.
+ SkPDFUnion move() { return static_cast<SkPDFUnion&&>(*this); }
// Move contstructor and assignemnt operator destroy the argument
// and steal their references (if needed).
SkPDFUnion(SkPDFUnion&& other);
@@ -82,7 +85,7 @@ public:
static SkPDFUnion Scalar(SkScalar);
- /** These two functions do NOT take ownership of char*, and do NOT
+ /** These two functions do NOT take ownership of ptr, and do NOT
copy the string. Suitable for passing in static const
strings. For example:
SkPDFUnion n = SkPDFUnion::Name("Length");
@@ -105,8 +108,17 @@ public:
/** SkPDFUnion::String will encode the passed string. */
static SkPDFUnion String(const SkString&);
- static SkPDFUnion Object(sk_sp<SkPDFObject>);
- static SkPDFUnion ObjRef(sk_sp<SkPDFObject>);
+ /** This function DOES take ownership of the object. E.g.
+ auto dict = sk_make_sp<SkPDFDict>();
+ dict->insert(.....);
+ SkPDFUnion u = SkPDFUnion::Object(dict.detach()) */
+ static SkPDFUnion Object(SkPDFObject*);
+
+ /** This function DOES take ownership of the object. E.g.
+ sk_sp<SkPDFBitmap> image(
+ SkPDFBitmap::Create(fCanon, bitmap));
+ SkPDFUnion u = SkPDFUnion::ObjRef(image.detach()) */
+ static SkPDFUnion ObjRef(SkPDFObject*);
/** These two non-virtual methods mirror SkPDFObject's
corresponding virtuals. */
@@ -162,7 +174,7 @@ public:
const SkPDFObjNumMap& objNumMap,
const SkPDFSubstituteMap& substitutes) final;
void addResources(SkPDFObjNumMap*, const SkPDFSubstituteMap&) const final;
- SkPDFAtom(SkPDFUnion&& v) : fValue(std::move(v) {}
+ SkPDFAtom(SkPDFUnion&& v) : fValue(v.move()) {}
private:
const SkPDFUnion fValue;
@@ -211,8 +223,9 @@ public:
void appendName(const SkString&);
void appendString(const char[]);
void appendString(const SkString&);
- void appendObject(sk_sp<SkPDFObject>);
- void appendObjRef(sk_sp<SkPDFObject>);
+ /** appendObject and appendObjRef take ownership of the passed object */
+ void appendObject(SkPDFObject*);
+ void appendObjRef(SkPDFObject*);
private:
SkTDArray<SkPDFUnion> fValues;
@@ -248,14 +261,15 @@ public:
*/
int size() const;
- /** Add the value to the dictionary with the given key.
+ /** Add the value to the dictionary with the given key. Takes
+ * ownership of the object.
* @param key The text of the key for this dictionary entry.
* @param value The value for this dictionary entry.
*/
- void insertObject(const char key[], sk_sp<SkPDFObject>);
- void insertObject(const SkString& key, sk_sp<SkPDFObject>);
- void insertObjRef(const char key[], sk_sp<SkPDFObject>);
- void insertObjRef(const SkString& key, sk_sp<SkPDFObject>);
+ void insertObject(const char key[], SkPDFObject* value);
+ void insertObject(const SkString& key, SkPDFObject* value);
+ void insertObjRef(const char key[], SkPDFObject* value);
+ void insertObjRef(const SkString& key, SkPDFObject* value);
/** Add the value to the dictionary with the given key.
* @param key The text of the key for this dictionary entry.
@@ -303,8 +317,7 @@ private:
class SkPDFSharedStream final : public SkPDFObject {
public:
// Takes ownership of asset.
- SkPDFSharedStream(SkStreamAsset* data)
- : fAsset(data), fDict(new SkPDFDict) { SkASSERT(data); }
+ SkPDFSharedStream(SkStreamAsset* data) : fAsset(data), fDict(new SkPDFDict) { SkASSERT(data); }
SkPDFDict* dict() { return fDict.get(); }
void emitObject(SkWStream*,
const SkPDFObjNumMap&,
diff --git a/src/pdf/SkPDFUtils.cpp b/src/pdf/SkPDFUtils.cpp
index f305765389..30d6ee7d68 100644
--- a/src/pdf/SkPDFUtils.cpp
+++ b/src/pdf/SkPDFUtils.cpp
@@ -18,8 +18,9 @@
#include <cmath>
-sk_sp<SkPDFArray> SkPDFUtils::RectToArray(const SkRect& rect) {
- auto result = sk_make_sp<SkPDFArray>();
+//static
+SkPDFArray* SkPDFUtils::RectToArray(const SkRect& rect) {
+ SkPDFArray* result = new SkPDFArray();
result->reserve(4);
result->appendScalar(rect.fLeft);
result->appendScalar(rect.fTop);
@@ -28,13 +29,14 @@ sk_sp<SkPDFArray> SkPDFUtils::RectToArray(const SkRect& rect) {
return result;
}
-sk_sp<SkPDFArray> SkPDFUtils::MatrixToArray(const SkMatrix& matrix) {
+// static
+SkPDFArray* SkPDFUtils::MatrixToArray(const SkMatrix& matrix) {
SkScalar values[6];
if (!matrix.asAffine(values)) {
SkMatrix::SetAffineIdentity(values);
}
- auto result = sk_make_sp<SkPDFArray>();
+ SkPDFArray* result = new SkPDFArray;
result->reserve(6);
for (size_t i = 0; i < SK_ARRAY_COUNT(values); i++) {
result->appendScalar(values[i]);
diff --git a/src/pdf/SkPDFUtils.h b/src/pdf/SkPDFUtils.h
index 0dec80077c..814d77193c 100644
--- a/src/pdf/SkPDFUtils.h
+++ b/src/pdf/SkPDFUtils.h
@@ -35,8 +35,8 @@ class SkWStream;
class SkPDFUtils {
public:
- static sk_sp<SkPDFArray> RectToArray(const SkRect& rect);
- static sk_sp<SkPDFArray> MatrixToArray(const SkMatrix& matrix);
+ static SkPDFArray* RectToArray(const SkRect& rect);
+ static SkPDFArray* MatrixToArray(const SkMatrix& matrix);
static void AppendTransform(const SkMatrix& matrix, SkWStream* content);
static void MoveTo(SkScalar x, SkScalar y, SkWStream* content);