OLD | NEW |
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 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
588 | 588 |
589 | 589 |
590 struct ContentEntry { | 590 struct ContentEntry { |
591 GraphicStateEntry fState; | 591 GraphicStateEntry fState; |
592 SkDynamicMemoryWStream fContent; | 592 SkDynamicMemoryWStream fContent; |
593 SkAutoTDelete<ContentEntry> fNext; | 593 SkAutoTDelete<ContentEntry> fNext; |
594 | 594 |
595 // If the stack is too deep we could get Stack Overflow. | 595 // If the stack is too deep we could get Stack Overflow. |
596 // So we manually destruct the object. | 596 // So we manually destruct the object. |
597 ~ContentEntry() { | 597 ~ContentEntry() { |
598 ContentEntry* val = fNext.detach(); | 598 ContentEntry* val = fNext.release(); |
599 while (val != nullptr) { | 599 while (val != nullptr) { |
600 ContentEntry* valNext = val->fNext.detach(); | 600 ContentEntry* valNext = val->fNext.release(); |
601 // When the destructor is called, fNext is nullptr and exits. | 601 // When the destructor is called, fNext is nullptr and exits. |
602 delete val; | 602 delete val; |
603 val = valNext; | 603 val = valNext; |
604 } | 604 } |
605 } | 605 } |
606 }; | 606 }; |
607 | 607 |
608 // A helper class to automatically finish a ContentEntry at the end of a | 608 // A helper class to automatically finish a ContentEntry at the end of a |
609 // drawing method and maintain the state needed between set up and finish. | 609 // drawing method and maintain the state needed between set up and finish. |
610 class ScopedContentEntry { | 610 class ScopedContentEntry { |
(...skipping 1233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1844 if (lastContentEntry && xfermode != SkXfermode::kDstOver_Mode && | 1844 if (lastContentEntry && xfermode != SkXfermode::kDstOver_Mode && |
1845 entry->fState.compareInitialState(lastContentEntry->fState)) { | 1845 entry->fState.compareInitialState(lastContentEntry->fState)) { |
1846 return lastContentEntry; | 1846 return lastContentEntry; |
1847 } | 1847 } |
1848 | 1848 |
1849 SkAutoTDelete<ContentEntry>* contentEntries = getContentEntries(); | 1849 SkAutoTDelete<ContentEntry>* contentEntries = getContentEntries(); |
1850 if (!lastContentEntry) { | 1850 if (!lastContentEntry) { |
1851 contentEntries->reset(entry); | 1851 contentEntries->reset(entry); |
1852 setLastContentEntry(entry); | 1852 setLastContentEntry(entry); |
1853 } else if (xfermode == SkXfermode::kDstOver_Mode) { | 1853 } else if (xfermode == SkXfermode::kDstOver_Mode) { |
1854 entry->fNext.reset(contentEntries->detach()); | 1854 entry->fNext.reset(contentEntries->release()); |
1855 contentEntries->reset(entry); | 1855 contentEntries->reset(entry); |
1856 } else { | 1856 } else { |
1857 lastContentEntry->fNext.reset(entry); | 1857 lastContentEntry->fNext.reset(entry); |
1858 setLastContentEntry(entry); | 1858 setLastContentEntry(entry); |
1859 } | 1859 } |
1860 newEntry.release(); | 1860 newEntry.release(); |
1861 return entry; | 1861 return entry; |
1862 } | 1862 } |
1863 | 1863 |
1864 void SkPDFDevice::finishContentEntry(SkXfermode::Mode xfermode, | 1864 void SkPDFDevice::finishContentEntry(SkXfermode::Mode xfermode, |
(...skipping 13 matching lines...) Expand all Loading... |
1878 return; | 1878 return; |
1879 } | 1879 } |
1880 if (xfermode == SkXfermode::kDstOver_Mode) { | 1880 if (xfermode == SkXfermode::kDstOver_Mode) { |
1881 SkASSERT(!dst); | 1881 SkASSERT(!dst); |
1882 ContentEntry* firstContentEntry = getContentEntries()->get(); | 1882 ContentEntry* firstContentEntry = getContentEntries()->get(); |
1883 if (firstContentEntry->fContent.getOffset() == 0) { | 1883 if (firstContentEntry->fContent.getOffset() == 0) { |
1884 // For DstOver, an empty content entry was inserted before the rest | 1884 // For DstOver, an empty content entry was inserted before the rest |
1885 // of the content entries. If nothing was drawn, it needs to be | 1885 // of the content entries. If nothing was drawn, it needs to be |
1886 // removed. | 1886 // removed. |
1887 SkAutoTDelete<ContentEntry>* contentEntries = getContentEntries(); | 1887 SkAutoTDelete<ContentEntry>* contentEntries = getContentEntries(); |
1888 contentEntries->reset(firstContentEntry->fNext.detach()); | 1888 contentEntries->reset(firstContentEntry->fNext.release()); |
1889 } | 1889 } |
1890 return; | 1890 return; |
1891 } | 1891 } |
1892 if (!dst) { | 1892 if (!dst) { |
1893 SkASSERT(xfermode == SkXfermode::kSrc_Mode || | 1893 SkASSERT(xfermode == SkXfermode::kSrc_Mode || |
1894 xfermode == SkXfermode::kSrcOut_Mode); | 1894 xfermode == SkXfermode::kSrcOut_Mode); |
1895 return; | 1895 return; |
1896 } | 1896 } |
1897 | 1897 |
1898 ContentEntry* contentEntries = getContentEntries()->get(); | 1898 ContentEntry* contentEntries = getContentEntries()->get(); |
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2329 pdfimage.reset(SkPDFCreateBitmapObject( | 2329 pdfimage.reset(SkPDFCreateBitmapObject( |
2330 image, fCanon->getPixelSerializer())); | 2330 image, fCanon->getPixelSerializer())); |
2331 if (!pdfimage) { | 2331 if (!pdfimage) { |
2332 return; | 2332 return; |
2333 } | 2333 } |
2334 fCanon->addPDFBitmap(image->uniqueID(), pdfimage.get()); | 2334 fCanon->addPDFBitmap(image->uniqueID(), pdfimage.get()); |
2335 } | 2335 } |
2336 SkPDFUtils::DrawFormXObject(this->addXObjectResource(pdfimage.get()), | 2336 SkPDFUtils::DrawFormXObject(this->addXObjectResource(pdfimage.get()), |
2337 &content.entry()->fContent); | 2337 &content.entry()->fContent); |
2338 } | 2338 } |
OLD | NEW |