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