Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 #include "SkCanvas.h" | 8 #include "SkCanvas.h" |
| 9 #include "SkColor.h" | 9 #include "SkColor.h" |
| 10 #include "SkReadBuffer.h" | 10 #include "SkReadBuffer.h" |
| 11 #include "SkWriteBuffer.h" | 11 #include "SkWriteBuffer.h" |
| 12 #include "SkLayerDrawLooper.h" | 12 #include "SkLayerDrawLooper.h" |
| 13 #include "SkString.h" | 13 #include "SkString.h" |
| 14 #include "SkStringUtils.h" | 14 #include "SkStringUtils.h" |
| 15 #include "SkUnPreMultiply.h" | 15 #include "SkUnPreMultiply.h" |
| 16 | 16 |
| 17 SkLayerDrawLooper::LayerInfo::LayerInfo() { | 17 SkLayerDrawLooper::LayerInfo::LayerInfo() { |
| 18 fFlagsMask = 0; // ignore our paint flags | 18 fFlagsMask = 0; // ignore our paint flags |
| 19 fPaintBits = 0; // ignore our paint fields | 19 fPaintBits = 0; // ignore our paint fields |
| 20 fColorMode = SkXfermode::kDst_Mode; // ignore our color | 20 fColorMode = SkXfermode::kDst_Mode; // ignore our color |
| 21 fOffset.set(0, 0); | 21 fOffset.set(0, 0); |
| 22 fPostTranslate = false; | 22 fPostTranslate = false; |
| 23 } | 23 } |
| 24 | 24 |
| 25 SkLayerDrawLooper::SkLayerDrawLooper() | 25 SkLayerDrawLooper::SkLayerDrawLooper() |
| 26 : fRecs(NULL), | 26 : fRecs(NULL), |
| 27 fTopRec(NULL), | 27 fTopRec(NULL), |
| 28 fCount(0), | 28 fCount(0) { |
| 29 fCurrRec(NULL) { | |
| 30 } | 29 } |
| 31 | 30 |
| 32 SkLayerDrawLooper::~SkLayerDrawLooper() { | 31 SkLayerDrawLooper::~SkLayerDrawLooper() { |
| 33 Rec* rec = fRecs; | 32 Rec* rec = fRecs; |
| 34 while (rec) { | 33 while (rec) { |
| 35 Rec* next = rec->fNext; | 34 Rec* next = rec->fNext; |
| 36 SkDELETE(rec); | 35 SkDELETE(rec); |
| 37 rec = next; | 36 rec = next; |
| 38 } | 37 } |
| 39 } | 38 } |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 69 fRecs = rec; | 68 fRecs = rec; |
| 70 } else { | 69 } else { |
| 71 SkASSERT(NULL != fTopRec); | 70 SkASSERT(NULL != fTopRec); |
| 72 fTopRec->fNext = rec; | 71 fTopRec->fNext = rec; |
| 73 } | 72 } |
| 74 fTopRec = rec; | 73 fTopRec = rec; |
| 75 | 74 |
| 76 return &rec->fPaint; | 75 return &rec->fPaint; |
| 77 } | 76 } |
| 78 | 77 |
| 79 void SkLayerDrawLooper::init(SkCanvas* canvas) { | 78 SkLayerDrawLooper::DrawContext* SkLayerDrawLooper::init(SkCanvas* canvas) |
| 80 fCurrRec = fRecs; | 79 const { |
| 80 SkLayerDrawLooperContext* context = new SkLayerDrawLooperContext(this); | |
|
scroggo
2014/02/06 17:57:13
SkNEW_ARGS
| |
| 81 canvas->save(SkCanvas::kMatrix_SaveFlag); | 81 canvas->save(SkCanvas::kMatrix_SaveFlag); |
| 82 return context; | |
| 82 } | 83 } |
| 83 | 84 |
| 84 static SkColor xferColor(SkColor src, SkColor dst, SkXfermode::Mode mode) { | 85 static SkColor xferColor(SkColor src, SkColor dst, SkXfermode::Mode mode) { |
| 85 switch (mode) { | 86 switch (mode) { |
| 86 case SkXfermode::kSrc_Mode: | 87 case SkXfermode::kSrc_Mode: |
| 87 return src; | 88 return src; |
| 88 case SkXfermode::kDst_Mode: | 89 case SkXfermode::kDst_Mode: |
| 89 return dst; | 90 return dst; |
| 90 default: { | 91 default: { |
| 91 SkPMColor pmS = SkPreMultiplyColor(src); | 92 SkPMColor pmS = SkPreMultiplyColor(src); |
| 92 SkPMColor pmD = SkPreMultiplyColor(dst); | 93 SkPMColor pmD = SkPreMultiplyColor(dst); |
| 93 SkPMColor result = SkXfermode::GetProc(mode)(pmS, pmD); | 94 SkPMColor result = SkXfermode::GetProc(mode)(pmS, pmD); |
| 94 return SkUnPreMultiply::PMColorToColor(result); | 95 return SkUnPreMultiply::PMColorToColor(result); |
| 95 } | 96 } |
| 96 } | 97 } |
| 97 } | 98 } |
| 98 | 99 |
| 100 SkLayerDrawLooper::SkLayerDrawLooperContext::SkLayerDrawLooperContext( | |
| 101 const SkLayerDrawLooper* looper) : fCurrRec(looper->fRecs) {} | |
| 102 | |
| 99 // Even with kEntirePaint_Bits, we always ensure that the master paint's | 103 // Even with kEntirePaint_Bits, we always ensure that the master paint's |
| 100 // text-encoding is respected, since that controls how we interpret the | 104 // text-encoding is respected, since that controls how we interpret the |
| 101 // text/length parameters of a draw[Pos]Text call. | 105 // text/length parameters of a draw[Pos]Text call. |
| 102 void SkLayerDrawLooper::ApplyInfo(SkPaint* dst, const SkPaint& src, | 106 void SkLayerDrawLooper::ApplyInfo(SkPaint* dst, const SkPaint& src, |
| 103 const LayerInfo& info) { | 107 const LayerInfo& info) { |
| 104 | 108 |
| 105 uint32_t mask = info.fFlagsMask; | 109 uint32_t mask = info.fFlagsMask; |
| 106 dst->setFlags((dst->getFlags() & ~mask) | (src.getFlags() & mask)); | 110 dst->setFlags((dst->getFlags() & ~mask) | (src.getFlags() & mask)); |
| 107 dst->setColor(xferColor(src.getColor(), dst->getColor(), info.fColorMode)); | 111 dst->setColor(xferColor(src.getColor(), dst->getColor(), info.fColorMode)); |
| 108 | 112 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 163 #endif | 167 #endif |
| 164 } | 168 } |
| 165 | 169 |
| 166 // Should we add this to canvas? | 170 // Should we add this to canvas? |
| 167 static void postTranslate(SkCanvas* canvas, SkScalar dx, SkScalar dy) { | 171 static void postTranslate(SkCanvas* canvas, SkScalar dx, SkScalar dy) { |
| 168 SkMatrix m = canvas->getTotalMatrix(); | 172 SkMatrix m = canvas->getTotalMatrix(); |
| 169 m.postTranslate(dx, dy); | 173 m.postTranslate(dx, dy); |
| 170 canvas->setMatrix(m); | 174 canvas->setMatrix(m); |
| 171 } | 175 } |
| 172 | 176 |
| 173 bool SkLayerDrawLooper::next(SkCanvas* canvas, SkPaint* paint) { | 177 bool SkLayerDrawLooper::next_internal(SkCanvas* canvas, SkPaint* paint, |
| 178 SkDrawLooper::DrawContext* context) const { | |
| 179 SkLayerDrawLooperContext* layerContext = | |
| 180 static_cast<SkLayerDrawLooperContext*>(context); | |
| 181 | |
| 174 canvas->restore(); | 182 canvas->restore(); |
| 175 if (NULL == fCurrRec) { | 183 if (NULL == layerContext->fCurrRec) { |
| 176 return false; | 184 return false; |
| 177 } | 185 } |
| 178 | 186 |
| 179 ApplyInfo(paint, fCurrRec->fPaint, fCurrRec->fInfo); | 187 ApplyInfo(paint, layerContext->fCurrRec->fPaint, |
| 188 layerContext->fCurrRec->fInfo); | |
| 180 | 189 |
| 181 canvas->save(SkCanvas::kMatrix_SaveFlag); | 190 canvas->save(SkCanvas::kMatrix_SaveFlag); |
| 182 if (fCurrRec->fInfo.fPostTranslate) { | 191 if (layerContext->fCurrRec->fInfo.fPostTranslate) { |
| 183 postTranslate(canvas, fCurrRec->fInfo.fOffset.fX, | 192 postTranslate(canvas, layerContext->fCurrRec->fInfo.fOffset.fX, |
| 184 fCurrRec->fInfo.fOffset.fY); | 193 layerContext->fCurrRec->fInfo.fOffset.fY); |
| 185 } else { | 194 } else { |
| 186 canvas->translate(fCurrRec->fInfo.fOffset.fX, fCurrRec->fInfo.fOffset.fY ); | 195 canvas->translate(layerContext->fCurrRec->fInfo.fOffset.fX, |
| 196 layerContext->fCurrRec->fInfo.fOffset.fY); | |
| 187 } | 197 } |
| 188 fCurrRec = fCurrRec->fNext; | 198 layerContext->fCurrRec = layerContext->fCurrRec->fNext; |
| 189 | 199 |
| 190 return true; | 200 return true; |
| 191 } | 201 } |
| 192 | 202 |
| 193 /////////////////////////////////////////////////////////////////////////////// | 203 /////////////////////////////////////////////////////////////////////////////// |
| 194 | 204 |
| 195 void SkLayerDrawLooper::flatten(SkWriteBuffer& buffer) const { | 205 void SkLayerDrawLooper::flatten(SkWriteBuffer& buffer) const { |
| 196 this->INHERITED::flatten(buffer); | 206 this->INHERITED::flatten(buffer); |
| 197 | 207 |
| 198 #ifdef SK_DEBUG | 208 #ifdef SK_DEBUG |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 218 buffer.writeBool(rec->fInfo.fPostTranslate); | 228 buffer.writeBool(rec->fInfo.fPostTranslate); |
| 219 buffer.writePaint(rec->fPaint); | 229 buffer.writePaint(rec->fPaint); |
| 220 rec = rec->fNext; | 230 rec = rec->fNext; |
| 221 } | 231 } |
| 222 } | 232 } |
| 223 | 233 |
| 224 SkLayerDrawLooper::SkLayerDrawLooper(SkReadBuffer& buffer) | 234 SkLayerDrawLooper::SkLayerDrawLooper(SkReadBuffer& buffer) |
| 225 : INHERITED(buffer), | 235 : INHERITED(buffer), |
| 226 fRecs(NULL), | 236 fRecs(NULL), |
| 227 fTopRec(NULL), | 237 fTopRec(NULL), |
| 228 fCount(0), | 238 fCount(0) { |
| 229 fCurrRec(NULL) { | |
| 230 int count = buffer.readInt(); | 239 int count = buffer.readInt(); |
| 231 | 240 |
| 232 for (int i = 0; i < count; i++) { | 241 for (int i = 0; i < count; i++) { |
| 233 LayerInfo info; | 242 LayerInfo info; |
| 234 info.fFlagsMask = buffer.readInt(); | 243 info.fFlagsMask = buffer.readInt(); |
| 235 info.fPaintBits = buffer.readInt(); | 244 info.fPaintBits = buffer.readInt(); |
| 236 info.fColorMode = (SkXfermode::Mode)buffer.readInt(); | 245 info.fColorMode = (SkXfermode::Mode)buffer.readInt(); |
| 237 buffer.readPoint(&info.fOffset); | 246 buffer.readPoint(&info.fOffset); |
| 238 info.fPostTranslate = buffer.readBool(); | 247 info.fPostTranslate = buffer.readBool(); |
| 239 buffer.readPaint(this->addLayerOnTop(info)); | 248 buffer.readPaint(this->addLayerOnTop(info)); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 340 str->append("true "); | 349 str->append("true "); |
| 341 } else { | 350 } else { |
| 342 str->append("false "); | 351 str->append("false "); |
| 343 } | 352 } |
| 344 | 353 |
| 345 rec->fPaint.toString(str); | 354 rec->fPaint.toString(str); |
| 346 rec = rec->fNext; | 355 rec = rec->fNext; |
| 347 } | 356 } |
| 348 } | 357 } |
| 349 #endif | 358 #endif |
| OLD | NEW |