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

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

Issue 1829693002: SkPDF: draw{Image,Bitmap} always serializes early (Closed) Base URL: https://skia.googlesource.com/skia.git@r1823683005
Patch Set: rebase 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
« no previous file with comments | « src/pdf/SkPDFCanon.h ('k') | src/pdf/SkPDFDevice.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 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 "SkImage.h" 8 #include "SkImage.h"
9 #include "SkPDFBitmap.h" 9 #include "SkPDFBitmap.h"
10 #include "SkPDFCanon.h" 10 #include "SkPDFCanon.h"
11 #include "SkPDFFont.h" 11 #include "SkPDFFont.h"
12 #include "SkPDFShader.h" 12 #include "SkPDFShader.h"
13 13
14 //////////////////////////////////////////////////////////////////////////////// 14 ////////////////////////////////////////////////////////////////////////////////
15 15
16 void SkPDFCanon::reset() { 16 void SkPDFCanon::reset() {
17 for (int i = 0; i < fFontRecords.count(); ++i) { 17 for (int i = 0; i < fFontRecords.count(); ++i) {
18 fFontRecords[i].fFont->unref(); 18 fFontRecords[i].fFont->unref();
19 } 19 }
20 fFontRecords.reset(); 20 fFontRecords.reset();
21 fFunctionShaderRecords.unrefAll(); 21 fFunctionShaderRecords.unrefAll();
22 fFunctionShaderRecords.reset(); 22 fFunctionShaderRecords.reset();
23 fAlphaShaderRecords.unrefAll(); 23 fAlphaShaderRecords.unrefAll();
24 fAlphaShaderRecords.reset(); 24 fAlphaShaderRecords.reset();
25 fImageShaderRecords.unrefAll(); 25 fImageShaderRecords.unrefAll();
26 fImageShaderRecords.reset(); 26 fImageShaderRecords.reset();
27 fGraphicStateRecords.foreach ([](WrapGS w) { w.fPtr->unref(); }); 27 fGraphicStateRecords.foreach ([](WrapGS w) { w.fPtr->unref(); });
28 fGraphicStateRecords.reset(); 28 fGraphicStateRecords.reset();
29 29
30 fBitmapToImageMap.foreach( 30 fPDFBitmapMap.foreach([](SkBitmapKey, SkPDFObject** p) { (*p)->unref(); });
31 [](SkBitmapKey, const SkImage** p) { SkSafeUnref(*p); });
32 fBitmapToImageMap.reset();
33
34 fPDFBitmapMap.foreach([](uint32_t, SkPDFObject** p) { SkSafeUnref(*p); });
35 fPDFBitmapMap.reset(); 31 fPDFBitmapMap.reset();
36 } 32 }
37 33
38 //////////////////////////////////////////////////////////////////////////////// 34 ////////////////////////////////////////////////////////////////////////////////
39 35
40 template <class T> T* assert_ptr(T* p) { SkASSERT(p); return p; } 36 template <class T> T* assert_ptr(T* p) { SkASSERT(p); return p; }
41 37
42 // requires `bool T::equals(const U&) const` 38 // requires `bool T::equals(const U&) const`
43 template <typename T, typename U> 39 template <typename T, typename U>
44 T* find_item(const SkTDArray<T*>& ptrArray, const U& object) { 40 T* find_item(const SkTDArray<T*>& ptrArray, const U& object) {
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 116
121 void SkPDFCanon::addGraphicState(const SkPDFGraphicState* state) { 117 void SkPDFCanon::addGraphicState(const SkPDFGraphicState* state) {
122 SkASSERT(state); 118 SkASSERT(state);
123 WrapGS w(SkRef(state)); 119 WrapGS w(SkRef(state));
124 SkASSERT(!fGraphicStateRecords.contains(w)); 120 SkASSERT(!fGraphicStateRecords.contains(w));
125 fGraphicStateRecords.add(w); 121 fGraphicStateRecords.add(w);
126 } 122 }
127 123
128 //////////////////////////////////////////////////////////////////////////////// 124 ////////////////////////////////////////////////////////////////////////////////
129 125
130 SkPDFObject* SkPDFCanon::findPDFBitmap(const SkImage* image) const { 126 sk_sp<SkPDFObject> SkPDFCanon::findPDFBitmap(SkBitmapKey key) const {
131 SkPDFObject** ptr = fPDFBitmapMap.find(image->uniqueID()); 127 SkPDFObject** ptr = fPDFBitmapMap.find(key);
132 return ptr ? *ptr : nullptr; 128 return ptr ? sk_ref_sp(*ptr) : sk_sp<SkPDFObject>();
133 } 129 }
134 130
135 void SkPDFCanon::addPDFBitmap(uint32_t imageUniqueID, SkPDFObject* pdfBitmap) { 131 void SkPDFCanon::addPDFBitmap(SkBitmapKey key, sk_sp<SkPDFObject> pdfBitmap) {
136 fPDFBitmapMap.set(imageUniqueID, SkRef(pdfBitmap)); 132 fPDFBitmapMap.set(key, pdfBitmap.release());
137 } 133 }
138 134
139 const SkImage* SkPDFCanon::bitmapToImage(const SkBitmap& bm) { 135 ////////////////////////////////////////////////////////////////////////////////
140 // reference remains owned by the fBitmapToImageMap!
141 SkBitmapKey key(bm);
142 if (const SkImage** img = fBitmapToImageMap.find(key)) {
143 return *img;
144 }
145 if (SkImage* image = SkImage::MakeFromBitmap(bm).release()) {
146 return *fBitmapToImageMap.set(key, image);
147 }
148 SkBitmap n32bitmap; // SkImage::NewFromBitmap can be finicky.
149 bm.copyTo(&n32bitmap, kN32_SkColorType);
150 return *fBitmapToImageMap.set(key, SkImage::MakeFromBitmap(n32bitmap).releas e());
151 }
152 136
153 sk_sp<SkPDFStream> SkPDFCanon::makeInvertFunction() { 137 sk_sp<SkPDFStream> SkPDFCanon::makeInvertFunction() {
154 if (fInvertFunction) { 138 if (fInvertFunction) {
155 return fInvertFunction; 139 return fInvertFunction;
156 } 140 }
157 fInvertFunction = SkPDFGraphicState::MakeInvertFunction(); 141 fInvertFunction = SkPDFGraphicState::MakeInvertFunction();
158 return fInvertFunction; 142 return fInvertFunction;
159 } 143 }
160 sk_sp<SkPDFDict> SkPDFCanon::makeNoSmaskGraphicState() { 144 sk_sp<SkPDFDict> SkPDFCanon::makeNoSmaskGraphicState() {
161 if (fNoSmaskGraphicState) { 145 if (fNoSmaskGraphicState) {
162 return fNoSmaskGraphicState; 146 return fNoSmaskGraphicState;
163 } 147 }
164 fNoSmaskGraphicState = SkPDFGraphicState::MakeNoSmaskGraphicState(); 148 fNoSmaskGraphicState = SkPDFGraphicState::MakeNoSmaskGraphicState();
165 return fNoSmaskGraphicState; 149 return fNoSmaskGraphicState;
166 } 150 }
167 sk_sp<SkPDFArray> SkPDFCanon::makeRangeObject() { 151 sk_sp<SkPDFArray> SkPDFCanon::makeRangeObject() {
168 if (fRangeObject) { 152 if (fRangeObject) {
169 return fRangeObject; 153 return fRangeObject;
170 } 154 }
171 fRangeObject = SkPDFShader::MakeRangeObject(); 155 fRangeObject = SkPDFShader::MakeRangeObject();
172 return fRangeObject; 156 return fRangeObject;
173 } 157 }
OLDNEW
« no previous file with comments | « src/pdf/SkPDFCanon.h ('k') | src/pdf/SkPDFDevice.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698