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

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

Issue 944643002: PDF: Now threadsafe! (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: TODO=DONE Created 5 years, 10 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/SkPDFGraphicState.h ('k') | src/pdf/SkPDFImage.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 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 "SkData.h" 8 #include "SkData.h"
9 #include "SkLazyPtr.h" 9 #include "SkLazyPtr.h"
10 #include "SkPDFCanon.h" 10 #include "SkPDFCanon.h"
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 SkASSERT(bXfermodeString != NULL); 106 SkASSERT(bXfermodeString != NULL);
107 107
108 return strcmp(aXfermodeString, bXfermodeString) == 0; 108 return strcmp(aXfermodeString, bXfermodeString) == 0;
109 } 109 }
110 110
111 bool SkPDFGraphicState::equals(const SkPaint& paint) const { 111 bool SkPDFGraphicState::equals(const SkPaint& paint) const {
112 return equivalent(paint, fPaint); 112 return equivalent(paint, fPaint);
113 } 113 }
114 114
115 SkPDFGraphicState::~SkPDFGraphicState() { 115 SkPDFGraphicState::~SkPDFGraphicState() {
116 SkAutoMutexAcquire lock(SkPDFCanon::GetPaintMutex()); 116 if (fCanon) {
117 if (!fSMask) { 117 fCanon->removeGraphicState(this);
118 SkPDFCanon::GetCanon().removeGraphicState(this);
119 } 118 }
120 } 119 }
121 120
122 void SkPDFGraphicState::emitObject(SkWStream* stream, SkPDFCatalog* catalog) { 121 void SkPDFGraphicState::emitObject(SkWStream* stream, SkPDFCatalog* catalog) {
123 populateDict(); 122 populateDict();
124 SkPDFDict::emitObject(stream, catalog); 123 SkPDFDict::emitObject(stream, catalog);
125 } 124 }
126 125
127 // static 126 // static
128 SkPDFGraphicState* SkPDFGraphicState::GetGraphicStateForPaint( 127 SkPDFGraphicState* SkPDFGraphicState::GetGraphicStateForPaint(
129 const SkPaint& paint) { 128 SkPDFCanon* canon, const SkPaint& paint) {
130 SkAutoMutexAcquire lock(SkPDFCanon::GetPaintMutex()); 129 SkASSERT(canon);
131 SkPDFGraphicState* pdfGraphicState = 130 SkPDFGraphicState* pdfGraphicState = canon->findGraphicState(paint);
132 SkPDFCanon::GetCanon().findGraphicState(paint);
133 if (pdfGraphicState) { 131 if (pdfGraphicState) {
134 return SkRef(pdfGraphicState); 132 return SkRef(pdfGraphicState);
135 } 133 }
136 pdfGraphicState = new SkPDFGraphicState(paint); 134 pdfGraphicState = new SkPDFGraphicState(canon, paint);
137 SkPDFCanon::GetCanon().addGraphicState(pdfGraphicState); 135 canon->addGraphicState(pdfGraphicState);
138 return pdfGraphicState; 136 return pdfGraphicState;
139 } 137 }
140 138
141 namespace { 139 namespace {
142 SkPDFObject* create_invert_function() { 140 SkPDFObject* create_invert_function() {
143 // Acrobat crashes if we use a type 0 function, kpdf crashes if we use 141 // Acrobat crashes if we use a type 0 function, kpdf crashes if we use
144 // a type 2 function, so we use a type 4 function. 142 // a type 2 function, so we use a type 4 function.
145 SkAutoTUnref<SkPDFArray> domainAndRange(new SkPDFArray); 143 SkAutoTUnref<SkPDFArray> domainAndRange(new SkPDFArray);
146 domainAndRange->reserve(2); 144 domainAndRange->reserve(2);
147 domainAndRange->appendInt(0); 145 domainAndRange->appendInt(0);
(...skipping 26 matching lines...) Expand all
174 SkAutoTUnref<SkPDFDict> sMaskDict(new SkPDFDict("Mask")); 172 SkAutoTUnref<SkPDFDict> sMaskDict(new SkPDFDict("Mask"));
175 if (sMaskMode == kAlpha_SMaskMode) { 173 if (sMaskMode == kAlpha_SMaskMode) {
176 sMaskDict->insertName("S", "Alpha"); 174 sMaskDict->insertName("S", "Alpha");
177 } else if (sMaskMode == kLuminosity_SMaskMode) { 175 } else if (sMaskMode == kLuminosity_SMaskMode) {
178 sMaskDict->insertName("S", "Luminosity"); 176 sMaskDict->insertName("S", "Luminosity");
179 } 177 }
180 sMaskDict->insert("G", new SkPDFObjRef(sMask))->unref(); 178 sMaskDict->insert("G", new SkPDFObjRef(sMask))->unref();
181 179
182 SkPDFGraphicState* result = new SkPDFGraphicState; 180 SkPDFGraphicState* result = new SkPDFGraphicState;
183 result->fPopulated = true; 181 result->fPopulated = true;
184 result->fSMask = true;
185 result->insertName("Type", "ExtGState"); 182 result->insertName("Type", "ExtGState");
186 result->insert("SMask", sMaskDict.get()); 183 result->insert("SMask", sMaskDict.get());
187 184
188 if (invert) { 185 if (invert) {
189 sMaskDict->insert("TR", new SkPDFObjRef(invertFunction.get()))->unref(); 186 sMaskDict->insert("TR", new SkPDFObjRef(invertFunction.get()))->unref();
190 } 187 }
191 188
192 return result; 189 return result;
193 } 190 }
194 191
195 SkPDFGraphicState* SkPDFGraphicState::CreateNoSMaskGraphicState() { 192 SkPDFGraphicState* SkPDFGraphicState::CreateNoSMaskGraphicState() {
196 SkPDFGraphicState* noSMaskGS = SkNEW(SkPDFGraphicState); 193 SkPDFGraphicState* noSMaskGS = SkNEW(SkPDFGraphicState);
197 noSMaskGS->fPopulated = true; 194 noSMaskGS->fPopulated = true;
198 noSMaskGS->fSMask = true;
199 noSMaskGS->insertName("Type", "ExtGState"); 195 noSMaskGS->insertName("Type", "ExtGState");
200 noSMaskGS->insertName("SMask", "None"); 196 noSMaskGS->insertName("SMask", "None");
201 return noSMaskGS; 197 return noSMaskGS;
202 } 198 }
203 199
204 SK_DECLARE_STATIC_LAZY_PTR( 200 SK_DECLARE_STATIC_LAZY_PTR(
205 SkPDFGraphicState, noSMaskGraphicState, 201 SkPDFGraphicState, noSMaskGraphicState,
206 SkPDFGraphicState::CreateNoSMaskGraphicState, unref<SkPDFGraphicState>); 202 SkPDFGraphicState::CreateNoSMaskGraphicState, unref<SkPDFGraphicState>);
207 203
208 // static 204 // static
209 SkPDFGraphicState* SkPDFGraphicState::GetNoSMaskGraphicState() { 205 SkPDFGraphicState* SkPDFGraphicState::GetNoSMaskGraphicState() {
210 return SkRef(noSMaskGraphicState.get()); 206 return SkRef(noSMaskGraphicState.get());
211 } 207 }
212 208
213 SkPDFGraphicState::SkPDFGraphicState() 209 SkPDFGraphicState::SkPDFGraphicState()
214 : fPopulated(false), 210 : fCanon(NULL), fPopulated(false) {}
215 fSMask(false) {
216 }
217 211
218 SkPDFGraphicState::SkPDFGraphicState(const SkPaint& paint) 212 SkPDFGraphicState::SkPDFGraphicState(SkPDFCanon* canon, const SkPaint& paint)
219 : fPaint(paint), 213 : fCanon(canon), fPaint(paint), fPopulated(false) {}
220 fPopulated(false),
221 fSMask(false) {
222 }
223 214
224 // populateDict and operator== have to stay in sync with each other. 215 // populateDict and operator== have to stay in sync with each other.
225 void SkPDFGraphicState::populateDict() { 216 void SkPDFGraphicState::populateDict() {
226 if (!fPopulated) { 217 if (!fPopulated) {
227 fPopulated = true; 218 fPopulated = true;
228 insertName("Type", "ExtGState"); 219 insertName("Type", "ExtGState");
229 220
230 SkAutoTUnref<SkPDFScalar> alpha( 221 SkAutoTUnref<SkPDFScalar> alpha(
231 new SkPDFScalar(SkScalarDiv(fPaint.getAlpha(), 0xFF))); 222 new SkPDFScalar(SkScalarDiv(fPaint.getAlpha(), 0xFF)));
232 insert("CA", alpha.get()); 223 insert("CA", alpha.get());
(...skipping 23 matching lines...) Expand all
256 fPaint.getXfermode()->asMode(&xfermode); 247 fPaint.getXfermode()->asMode(&xfermode);
257 // If we don't support the mode, just use kSrcOver_Mode. 248 // If we don't support the mode, just use kSrcOver_Mode.
258 if (xfermode < 0 || xfermode > SkXfermode::kLastMode || 249 if (xfermode < 0 || xfermode > SkXfermode::kLastMode ||
259 as_blend_mode(xfermode) == NULL) { 250 as_blend_mode(xfermode) == NULL) {
260 xfermode = SkXfermode::kSrcOver_Mode; 251 xfermode = SkXfermode::kSrcOver_Mode;
261 NOT_IMPLEMENTED("unsupported xfermode", false); 252 NOT_IMPLEMENTED("unsupported xfermode", false);
262 } 253 }
263 insertName("BM", as_blend_mode(xfermode)); 254 insertName("BM", as_blend_mode(xfermode));
264 } 255 }
265 } 256 }
OLDNEW
« no previous file with comments | « src/pdf/SkPDFGraphicState.h ('k') | src/pdf/SkPDFImage.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698