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 "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 Loading... | |
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 SkASSERT((fSMask || fCanon) && !(fSMask && fCanon)); |
mtklein
2015/02/19 23:50:38
My head asplode. Can we write this as
if (fCanon
hal.canary
2015/02/20 01:22:28
Not exactly. Is this more readable?
SkASSERT((
mtklein
2015/02/20 14:55:41
Yes that was actually my first thought too, until
| |
117 if (!fSMask) { | 117 if (!fSMask) { |
118 SkPDFCanon::GetCanon().removeGraphicState(this); | 118 fCanon->removeGraphicState(this); |
119 } | 119 } |
120 } | 120 } |
121 | 121 |
122 void SkPDFGraphicState::emitObject(SkWStream* stream, SkPDFCatalog* catalog) { | 122 void SkPDFGraphicState::emitObject(SkWStream* stream, SkPDFCatalog* catalog) { |
123 populateDict(); | 123 populateDict(); |
124 SkPDFDict::emitObject(stream, catalog); | 124 SkPDFDict::emitObject(stream, catalog); |
125 } | 125 } |
126 | 126 |
127 // static | 127 // static |
128 SkPDFGraphicState* SkPDFGraphicState::GetGraphicStateForPaint( | 128 SkPDFGraphicState* SkPDFGraphicState::GetGraphicStateForPaint( |
129 const SkPaint& paint) { | 129 SkPDFCanon* canon, const SkPaint& paint) { |
130 SkAutoMutexAcquire lock(SkPDFCanon::GetPaintMutex()); | 130 SkASSERT(canon); |
131 SkPDFGraphicState* pdfGraphicState = | 131 SkPDFGraphicState* pdfGraphicState = canon->findGraphicState(paint); |
132 SkPDFCanon::GetCanon().findGraphicState(paint); | |
133 if (pdfGraphicState) { | 132 if (pdfGraphicState) { |
134 return SkRef(pdfGraphicState); | 133 return SkRef(pdfGraphicState); |
135 } | 134 } |
136 pdfGraphicState = new SkPDFGraphicState(paint); | 135 pdfGraphicState = new SkPDFGraphicState(canon, paint); |
137 SkPDFCanon::GetCanon().addGraphicState(pdfGraphicState); | 136 canon->addGraphicState(pdfGraphicState); |
138 return pdfGraphicState; | 137 return pdfGraphicState; |
139 } | 138 } |
140 | 139 |
141 namespace { | 140 namespace { |
142 SkPDFObject* create_invert_function() { | 141 SkPDFObject* create_invert_function() { |
143 // Acrobat crashes if we use a type 0 function, kpdf crashes if we use | 142 // 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. | 143 // a type 2 function, so we use a type 4 function. |
145 SkAutoTUnref<SkPDFArray> domainAndRange(new SkPDFArray); | 144 SkAutoTUnref<SkPDFArray> domainAndRange(new SkPDFArray); |
146 domainAndRange->reserve(2); | 145 domainAndRange->reserve(2); |
147 domainAndRange->appendInt(0); | 146 domainAndRange->appendInt(0); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
204 SK_DECLARE_STATIC_LAZY_PTR( | 203 SK_DECLARE_STATIC_LAZY_PTR( |
205 SkPDFGraphicState, noSMaskGraphicState, | 204 SkPDFGraphicState, noSMaskGraphicState, |
206 SkPDFGraphicState::CreateNoSMaskGraphicState, unref<SkPDFGraphicState>); | 205 SkPDFGraphicState::CreateNoSMaskGraphicState, unref<SkPDFGraphicState>); |
207 | 206 |
208 // static | 207 // static |
209 SkPDFGraphicState* SkPDFGraphicState::GetNoSMaskGraphicState() { | 208 SkPDFGraphicState* SkPDFGraphicState::GetNoSMaskGraphicState() { |
210 return SkRef(noSMaskGraphicState.get()); | 209 return SkRef(noSMaskGraphicState.get()); |
211 } | 210 } |
212 | 211 |
213 SkPDFGraphicState::SkPDFGraphicState() | 212 SkPDFGraphicState::SkPDFGraphicState() |
214 : fPopulated(false), | 213 : fCanon(NULL), fPopulated(false), fSMask(false) {} |
215 fSMask(false) { | |
216 } | |
217 | 214 |
218 SkPDFGraphicState::SkPDFGraphicState(const SkPaint& paint) | 215 SkPDFGraphicState::SkPDFGraphicState(SkPDFCanon* canon, const SkPaint& paint) |
219 : fPaint(paint), | 216 : fCanon(canon), fPaint(paint), fPopulated(false), fSMask(false) {} |
220 fPopulated(false), | |
221 fSMask(false) { | |
222 } | |
223 | 217 |
224 // populateDict and operator== have to stay in sync with each other. | 218 // populateDict and operator== have to stay in sync with each other. |
225 void SkPDFGraphicState::populateDict() { | 219 void SkPDFGraphicState::populateDict() { |
226 if (!fPopulated) { | 220 if (!fPopulated) { |
227 fPopulated = true; | 221 fPopulated = true; |
228 insertName("Type", "ExtGState"); | 222 insertName("Type", "ExtGState"); |
229 | 223 |
230 SkAutoTUnref<SkPDFScalar> alpha( | 224 SkAutoTUnref<SkPDFScalar> alpha( |
231 new SkPDFScalar(SkScalarDiv(fPaint.getAlpha(), 0xFF))); | 225 new SkPDFScalar(SkScalarDiv(fPaint.getAlpha(), 0xFF))); |
232 insert("CA", alpha.get()); | 226 insert("CA", alpha.get()); |
(...skipping 23 matching lines...) Expand all Loading... | |
256 fPaint.getXfermode()->asMode(&xfermode); | 250 fPaint.getXfermode()->asMode(&xfermode); |
257 // If we don't support the mode, just use kSrcOver_Mode. | 251 // If we don't support the mode, just use kSrcOver_Mode. |
258 if (xfermode < 0 || xfermode > SkXfermode::kLastMode || | 252 if (xfermode < 0 || xfermode > SkXfermode::kLastMode || |
259 as_blend_mode(xfermode) == NULL) { | 253 as_blend_mode(xfermode) == NULL) { |
260 xfermode = SkXfermode::kSrcOver_Mode; | 254 xfermode = SkXfermode::kSrcOver_Mode; |
261 NOT_IMPLEMENTED("unsupported xfermode", false); | 255 NOT_IMPLEMENTED("unsupported xfermode", false); |
262 } | 256 } |
263 insertName("BM", as_blend_mode(xfermode)); | 257 insertName("BM", as_blend_mode(xfermode)); |
264 } | 258 } |
265 } | 259 } |
OLD | NEW |