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

Side by Side Diff: src/pdf/SkPDFDevice.cpp

Issue 1837553002: SkPDF s/SkAutoTDelete/std::unique_ptr/ (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2011 Google Inc. 2 * Copyright 2011 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkPDFDevice.h" 8 #include "SkPDFDevice.h"
9 9
10 #include "SkAnnotationKeys.h" 10 #include "SkAnnotationKeys.h"
(...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 SkISize size = SkISize::Make(cinfo.fInfo.width(), cinfo.fInfo.height()); 585 SkISize size = SkISize::Make(cinfo.fInfo.width(), cinfo.fInfo.height());
586 return SkPDFDevice::Create(size, fRasterDpi, fDocument); 586 return SkPDFDevice::Create(size, fRasterDpi, fDocument);
587 } 587 }
588 588
589 SkPDFCanon* SkPDFDevice::getCanon() const { return fDocument->canon(); } 589 SkPDFCanon* SkPDFDevice::getCanon() const { return fDocument->canon(); }
590 590
591 591
592 struct ContentEntry { 592 struct ContentEntry {
593 GraphicStateEntry fState; 593 GraphicStateEntry fState;
594 SkDynamicMemoryWStream fContent; 594 SkDynamicMemoryWStream fContent;
595 SkAutoTDelete<ContentEntry> fNext; 595 std::unique_ptr<ContentEntry> fNext;
bungeman-skia 2016/03/25 19:54:22 Hopefully this doesn't break the Android NDK build
hal.canary 2016/03/28 14:23:32 I'll hold off on these. This should be a linked l
596 596
597 // If the stack is too deep we could get Stack Overflow. 597 // If the stack is too deep we could get Stack Overflow.
598 // So we manually destruct the object. 598 // So we manually destruct the object.
599 ~ContentEntry() { 599 ~ContentEntry() {
600 ContentEntry* val = fNext.release(); 600 ContentEntry* val = fNext.release();
601 while (val != nullptr) { 601 while (val != nullptr) {
602 ContentEntry* valNext = val->fNext.release(); 602 ContentEntry* valNext = val->fNext.release();
603 // When the destructor is called, fNext is nullptr and exits. 603 // When the destructor is called, fNext is nullptr and exits.
604 delete val; 604 delete val;
605 val = valNext; 605 val = valNext;
(...skipping 804 matching lines...) Expand 10 before | Expand all | Expand 10 after
1410 } 1410 }
1411 1411
1412 ContentEntry* SkPDFDevice::getLastContentEntry() { 1412 ContentEntry* SkPDFDevice::getLastContentEntry() {
1413 if (fDrawingArea == kContent_DrawingArea) { 1413 if (fDrawingArea == kContent_DrawingArea) {
1414 return fLastContentEntry; 1414 return fLastContentEntry;
1415 } else { 1415 } else {
1416 return fLastMarginContentEntry; 1416 return fLastMarginContentEntry;
1417 } 1417 }
1418 } 1418 }
1419 1419
1420 SkAutoTDelete<ContentEntry>* SkPDFDevice::getContentEntries() { 1420 std::unique_ptr<ContentEntry>* SkPDFDevice::getContentEntries() {
1421 if (fDrawingArea == kContent_DrawingArea) { 1421 if (fDrawingArea == kContent_DrawingArea) {
1422 return &fContentEntries; 1422 return &fContentEntries;
1423 } else { 1423 } else {
1424 return &fMarginContentEntries; 1424 return &fMarginContentEntries;
1425 } 1425 }
1426 } 1426 }
1427 1427
1428 void SkPDFDevice::setLastContentEntry(ContentEntry* contentEntry) { 1428 void SkPDFDevice::setLastContentEntry(ContentEntry* contentEntry) {
1429 if (fDrawingArea == kContent_DrawingArea) { 1429 if (fDrawingArea == kContent_DrawingArea) {
1430 fLastContentEntry = contentEntry; 1430 fLastContentEntry = contentEntry;
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
1755 } 1755 }
1756 // TODO(vandebo): Figure out how/if we can handle the following modes: 1756 // TODO(vandebo): Figure out how/if we can handle the following modes:
1757 // Xor, Plus. 1757 // Xor, Plus.
1758 1758
1759 // Dst xfer mode doesn't draw source at all. 1759 // Dst xfer mode doesn't draw source at all.
1760 if (xfermode == SkXfermode::kDst_Mode) { 1760 if (xfermode == SkXfermode::kDst_Mode) {
1761 return nullptr; 1761 return nullptr;
1762 } 1762 }
1763 1763
1764 ContentEntry* entry; 1764 ContentEntry* entry;
1765 SkAutoTDelete<ContentEntry> newEntry; 1765 std::unique_ptr<ContentEntry> newEntry;
1766 1766
1767 ContentEntry* lastContentEntry = getLastContentEntry(); 1767 ContentEntry* lastContentEntry = getLastContentEntry();
1768 if (lastContentEntry && lastContentEntry->fContent.getOffset() == 0) { 1768 if (lastContentEntry && lastContentEntry->fContent.getOffset() == 0) {
1769 entry = lastContentEntry; 1769 entry = lastContentEntry;
1770 } else { 1770 } else {
1771 newEntry.reset(new ContentEntry); 1771 newEntry.reset(new ContentEntry);
1772 entry = newEntry.get(); 1772 entry = newEntry.get();
1773 } 1773 }
1774 1774
1775 populateGraphicStateEntryFromPaint(matrix, *clipStack, clipRegion, paint, 1775 populateGraphicStateEntryFromPaint(matrix, *clipStack, clipRegion, paint,
1776 hasText, &entry->fState); 1776 hasText, &entry->fState);
1777 if (lastContentEntry && xfermode != SkXfermode::kDstOver_Mode && 1777 if (lastContentEntry && xfermode != SkXfermode::kDstOver_Mode &&
1778 entry->fState.compareInitialState(lastContentEntry->fState)) { 1778 entry->fState.compareInitialState(lastContentEntry->fState)) {
1779 return lastContentEntry; 1779 return lastContentEntry;
1780 } 1780 }
1781 1781
1782 SkAutoTDelete<ContentEntry>* contentEntries = getContentEntries(); 1782 std::unique_ptr<ContentEntry>* contentEntries = getContentEntries();
1783 if (!lastContentEntry) { 1783 if (!lastContentEntry) {
1784 contentEntries->reset(entry); 1784 contentEntries->reset(entry);
1785 setLastContentEntry(entry); 1785 setLastContentEntry(entry);
1786 } else if (xfermode == SkXfermode::kDstOver_Mode) { 1786 } else if (xfermode == SkXfermode::kDstOver_Mode) {
1787 entry->fNext.reset(contentEntries->release()); 1787 entry->fNext.reset(contentEntries->release());
1788 contentEntries->reset(entry); 1788 contentEntries->reset(entry);
1789 } else { 1789 } else {
1790 lastContentEntry->fNext.reset(entry); 1790 lastContentEntry->fNext.reset(entry);
1791 setLastContentEntry(entry); 1791 setLastContentEntry(entry);
1792 } 1792 }
(...skipping 17 matching lines...) Expand all
1810 SkASSERT(!dst); 1810 SkASSERT(!dst);
1811 return; 1811 return;
1812 } 1812 }
1813 if (xfermode == SkXfermode::kDstOver_Mode) { 1813 if (xfermode == SkXfermode::kDstOver_Mode) {
1814 SkASSERT(!dst); 1814 SkASSERT(!dst);
1815 ContentEntry* firstContentEntry = getContentEntries()->get(); 1815 ContentEntry* firstContentEntry = getContentEntries()->get();
1816 if (firstContentEntry->fContent.getOffset() == 0) { 1816 if (firstContentEntry->fContent.getOffset() == 0) {
1817 // For DstOver, an empty content entry was inserted before the rest 1817 // For DstOver, an empty content entry was inserted before the rest
1818 // of the content entries. If nothing was drawn, it needs to be 1818 // of the content entries. If nothing was drawn, it needs to be
1819 // removed. 1819 // removed.
1820 SkAutoTDelete<ContentEntry>* contentEntries = getContentEntries(); 1820 std::unique_ptr<ContentEntry>* contentEntries = getContentEntries();
1821 contentEntries->reset(firstContentEntry->fNext.release()); 1821 contentEntries->reset(firstContentEntry->fNext.release());
1822 } 1822 }
1823 return; 1823 return;
1824 } 1824 }
1825 if (!dst) { 1825 if (!dst) {
1826 SkASSERT(xfermode == SkXfermode::kSrc_Mode || 1826 SkASSERT(xfermode == SkXfermode::kSrc_Mode ||
1827 xfermode == SkXfermode::kSrcOut_Mode); 1827 xfermode == SkXfermode::kSrcOut_Mode);
1828 return; 1828 return;
1829 } 1829 }
1830 1830
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after
2260 if (!pdfimage) { 2260 if (!pdfimage) {
2261 return; 2261 return;
2262 } 2262 }
2263 fDocument->serialize(pdfimage); // serialize images early. 2263 fDocument->serialize(pdfimage); // serialize images early.
2264 fDocument->canon()->addPDFBitmap(key, pdfimage); 2264 fDocument->canon()->addPDFBitmap(key, pdfimage);
2265 } 2265 }
2266 // TODO(halcanary): addXObjectResource() should take a sk_sp<SkPDFObject> 2266 // TODO(halcanary): addXObjectResource() should take a sk_sp<SkPDFObject>
2267 SkPDFUtils::DrawFormXObject(this->addXObjectResource(pdfimage.get()), 2267 SkPDFUtils::DrawFormXObject(this->addXObjectResource(pdfimage.get()),
2268 &content.entry()->fContent); 2268 &content.entry()->fContent);
2269 } 2269 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698