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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 const char* bXfermodeString = as_blend_mode(bXfermodeName); | 105 const char* bXfermodeString = as_blend_mode(bXfermodeName); |
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 if (fCanon) { | |
117 fCanon->removeGraphicState(this); | |
118 } | |
119 } | |
120 | 116 |
121 void SkPDFGraphicState::emitObject(SkWStream* stream, SkPDFCatalog* catalog) { | 117 void SkPDFGraphicState::emitObject(SkWStream* stream, SkPDFCatalog* catalog) { |
122 populateDict(); | 118 populateDict(); |
123 SkPDFDict::emitObject(stream, catalog); | 119 SkPDFDict::emitObject(stream, catalog); |
124 } | 120 } |
125 | 121 |
126 // static | 122 // static |
127 SkPDFGraphicState* SkPDFGraphicState::GetGraphicStateForPaint( | 123 SkPDFGraphicState* SkPDFGraphicState::GetGraphicStateForPaint( |
128 SkPDFCanon* canon, const SkPaint& paint) { | 124 SkPDFCanon* canon, const SkPaint& paint) { |
129 SkASSERT(canon); | 125 SkASSERT(canon); |
130 SkPDFGraphicState* pdfGraphicState = canon->findGraphicState(paint); | 126 SkPDFGraphicState* pdfGraphicState = canon->findGraphicState(paint); |
131 if (pdfGraphicState) { | 127 if (pdfGraphicState) { |
132 return SkRef(pdfGraphicState); | 128 return SkRef(pdfGraphicState); |
133 } | 129 } |
134 pdfGraphicState = new SkPDFGraphicState(canon, paint); | 130 pdfGraphicState = new SkPDFGraphicState(paint); |
135 canon->addGraphicState(pdfGraphicState); | 131 canon->addGraphicState(pdfGraphicState); |
136 return pdfGraphicState; | 132 return pdfGraphicState; |
137 } | 133 } |
138 | 134 |
139 namespace { | 135 namespace { |
140 SkPDFObject* create_invert_function() { | 136 SkPDFObject* create_invert_function() { |
141 // Acrobat crashes if we use a type 0 function, kpdf crashes if we use | 137 // Acrobat crashes if we use a type 0 function, kpdf crashes if we use |
142 // a type 2 function, so we use a type 4 function. | 138 // a type 2 function, so we use a type 4 function. |
143 SkAutoTUnref<SkPDFArray> domainAndRange(new SkPDFArray); | 139 SkAutoTUnref<SkPDFArray> domainAndRange(new SkPDFArray); |
144 domainAndRange->reserve(2); | 140 domainAndRange->reserve(2); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 SK_DECLARE_STATIC_LAZY_PTR( | 196 SK_DECLARE_STATIC_LAZY_PTR( |
201 SkPDFGraphicState, noSMaskGraphicState, | 197 SkPDFGraphicState, noSMaskGraphicState, |
202 SkPDFGraphicState::CreateNoSMaskGraphicState, unref<SkPDFGraphicState>); | 198 SkPDFGraphicState::CreateNoSMaskGraphicState, unref<SkPDFGraphicState>); |
203 | 199 |
204 // static | 200 // static |
205 SkPDFGraphicState* SkPDFGraphicState::GetNoSMaskGraphicState() { | 201 SkPDFGraphicState* SkPDFGraphicState::GetNoSMaskGraphicState() { |
206 return SkRef(noSMaskGraphicState.get()); | 202 return SkRef(noSMaskGraphicState.get()); |
207 } | 203 } |
208 | 204 |
209 SkPDFGraphicState::SkPDFGraphicState() | 205 SkPDFGraphicState::SkPDFGraphicState() |
210 : fCanon(NULL), fPopulated(false) {} | 206 : fPopulated(false) {} |
211 | 207 |
212 SkPDFGraphicState::SkPDFGraphicState(SkPDFCanon* canon, const SkPaint& paint) | 208 SkPDFGraphicState::SkPDFGraphicState(const SkPaint& paint) |
213 : fCanon(canon), fPaint(paint), fPopulated(false) {} | 209 : fPaint(paint), fPopulated(false) {} |
214 | 210 |
215 // populateDict and operator== have to stay in sync with each other. | 211 // populateDict and operator== have to stay in sync with each other. |
216 void SkPDFGraphicState::populateDict() { | 212 void SkPDFGraphicState::populateDict() { |
217 if (!fPopulated) { | 213 if (!fPopulated) { |
218 fPopulated = true; | 214 fPopulated = true; |
219 insertName("Type", "ExtGState"); | 215 insertName("Type", "ExtGState"); |
220 | 216 |
221 SkAutoTUnref<SkPDFScalar> alpha( | 217 SkAutoTUnref<SkPDFScalar> alpha( |
222 new SkPDFScalar(SkScalarDiv(fPaint.getAlpha(), 0xFF))); | 218 new SkPDFScalar(SkScalarDiv(fPaint.getAlpha(), 0xFF))); |
223 insert("CA", alpha.get()); | 219 insert("CA", alpha.get()); |
(...skipping 23 matching lines...) Expand all Loading... |
247 fPaint.getXfermode()->asMode(&xfermode); | 243 fPaint.getXfermode()->asMode(&xfermode); |
248 // If we don't support the mode, just use kSrcOver_Mode. | 244 // If we don't support the mode, just use kSrcOver_Mode. |
249 if (xfermode < 0 || xfermode > SkXfermode::kLastMode || | 245 if (xfermode < 0 || xfermode > SkXfermode::kLastMode || |
250 as_blend_mode(xfermode) == NULL) { | 246 as_blend_mode(xfermode) == NULL) { |
251 xfermode = SkXfermode::kSrcOver_Mode; | 247 xfermode = SkXfermode::kSrcOver_Mode; |
252 NOT_IMPLEMENTED("unsupported xfermode", false); | 248 NOT_IMPLEMENTED("unsupported xfermode", false); |
253 } | 249 } |
254 insertName("BM", as_blend_mode(xfermode)); | 250 insertName("BM", as_blend_mode(xfermode)); |
255 } | 251 } |
256 } | 252 } |
OLD | NEW |