| 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 #ifdef SK_SUPPORT_LEGACY_LAYERDRAWLOOPER_PAINTFLAGS |
| 19 fFlagsMask = 0; // ignore layerinfo's paint flags |
| 20 #endif |
| 19 fPaintBits = 0; // ignore our paint fields | 21 fPaintBits = 0; // ignore our paint fields |
| 20 fColorMode = SkXfermode::kDst_Mode; // ignore our color | 22 fColorMode = SkXfermode::kDst_Mode; // ignore our color |
| 21 fOffset.set(0, 0); | 23 fOffset.set(0, 0); |
| 22 fPostTranslate = false; | 24 fPostTranslate = false; |
| 23 } | 25 } |
| 24 | 26 |
| 25 SkLayerDrawLooper::SkLayerDrawLooper() | 27 SkLayerDrawLooper::SkLayerDrawLooper() |
| 26 : fRecs(NULL), | 28 : fRecs(NULL), |
| 27 fTopRec(NULL), | 29 fTopRec(NULL), |
| 28 fCount(0), | 30 fCount(0), |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 } | 97 } |
| 96 } | 98 } |
| 97 } | 99 } |
| 98 | 100 |
| 99 // Even with kEntirePaint_Bits, we always ensure that the master paint's | 101 // Even with kEntirePaint_Bits, we always ensure that the master paint's |
| 100 // text-encoding is respected, since that controls how we interpret the | 102 // text-encoding is respected, since that controls how we interpret the |
| 101 // text/length parameters of a draw[Pos]Text call. | 103 // text/length parameters of a draw[Pos]Text call. |
| 102 void SkLayerDrawLooper::ApplyInfo(SkPaint* dst, const SkPaint& src, | 104 void SkLayerDrawLooper::ApplyInfo(SkPaint* dst, const SkPaint& src, |
| 103 const LayerInfo& info) { | 105 const LayerInfo& info) { |
| 104 | 106 |
| 107 #ifdef SK_SUPPORT_LEGACY_LAYERDRAWLOOPER_PAINTFLAGS |
| 105 uint32_t mask = info.fFlagsMask; | 108 uint32_t mask = info.fFlagsMask; |
| 106 dst->setFlags((dst->getFlags() & ~mask) | (src.getFlags() & mask)); | 109 dst->setFlags((dst->getFlags() & ~mask) | (src.getFlags() & mask)); |
| 110 #endif |
| 107 dst->setColor(xferColor(src.getColor(), dst->getColor(), info.fColorMode)); | 111 dst->setColor(xferColor(src.getColor(), dst->getColor(), info.fColorMode)); |
| 108 | 112 |
| 109 BitFlags bits = info.fPaintBits; | 113 BitFlags bits = info.fPaintBits; |
| 110 SkPaint::TextEncoding encoding = dst->getTextEncoding(); | 114 SkPaint::TextEncoding encoding = dst->getTextEncoding(); |
| 111 | 115 |
| 112 if (0 == bits) { | 116 if (0 == bits) { |
| 113 return; | 117 return; |
| 114 } | 118 } |
| 115 if (kEntirePaint_Bits == bits) { | 119 if (kEntirePaint_Bits == bits) { |
| 116 // we've already computed these, so save it from the assignment | 120 // we've already computed these, so save it from the assignment |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 count += 1; | 208 count += 1; |
| 205 } | 209 } |
| 206 SkASSERT(count == fCount); | 210 SkASSERT(count == fCount); |
| 207 } | 211 } |
| 208 #endif | 212 #endif |
| 209 | 213 |
| 210 buffer.writeInt(fCount); | 214 buffer.writeInt(fCount); |
| 211 | 215 |
| 212 Rec* rec = fRecs; | 216 Rec* rec = fRecs; |
| 213 for (int i = 0; i < fCount; i++) { | 217 for (int i = 0; i < fCount; i++) { |
| 218 #ifdef SK_SUPPORT_LEGACY_LAYERDRAWLOOPER_PAINTFLAGS |
| 214 buffer.writeInt(rec->fInfo.fFlagsMask); | 219 buffer.writeInt(rec->fInfo.fFlagsMask); |
| 220 #else |
| 221 buffer.writeInt(0); // remove eventually, when we can bump the version |
| 222 #endif |
| 215 buffer.writeInt(rec->fInfo.fPaintBits); | 223 buffer.writeInt(rec->fInfo.fPaintBits); |
| 216 buffer.writeInt(rec->fInfo.fColorMode); | 224 buffer.writeInt(rec->fInfo.fColorMode); |
| 217 buffer.writePoint(rec->fInfo.fOffset); | 225 buffer.writePoint(rec->fInfo.fOffset); |
| 218 buffer.writeBool(rec->fInfo.fPostTranslate); | 226 buffer.writeBool(rec->fInfo.fPostTranslate); |
| 219 buffer.writePaint(rec->fPaint); | 227 buffer.writePaint(rec->fPaint); |
| 220 rec = rec->fNext; | 228 rec = rec->fNext; |
| 221 } | 229 } |
| 222 } | 230 } |
| 223 | 231 |
| 224 SkFlattenable* SkLayerDrawLooper::CreateProc(SkReadBuffer& buffer) { | 232 SkFlattenable* SkLayerDrawLooper::CreateProc(SkReadBuffer& buffer) { |
| 225 int count = buffer.readInt(); | 233 int count = buffer.readInt(); |
| 226 | 234 |
| 227 Builder builder; | 235 Builder builder; |
| 228 for (int i = 0; i < count; i++) { | 236 for (int i = 0; i < count; i++) { |
| 229 LayerInfo info; | 237 LayerInfo info; |
| 238 #ifdef SK_SUPPORT_LEGACY_LAYERDRAWLOOPER_PAINTFLAGS |
| 230 info.fFlagsMask = buffer.readInt(); | 239 info.fFlagsMask = buffer.readInt(); |
| 240 #else |
| 241 (void)buffer.readInt(); |
| 242 #endif |
| 231 info.fPaintBits = buffer.readInt(); | 243 info.fPaintBits = buffer.readInt(); |
| 232 info.fColorMode = (SkXfermode::Mode)buffer.readInt(); | 244 info.fColorMode = (SkXfermode::Mode)buffer.readInt(); |
| 233 buffer.readPoint(&info.fOffset); | 245 buffer.readPoint(&info.fOffset); |
| 234 info.fPostTranslate = buffer.readBool(); | 246 info.fPostTranslate = buffer.readBool(); |
| 235 buffer.readPaint(builder.addLayerOnTop(info)); | 247 buffer.readPaint(builder.addLayerOnTop(info)); |
| 236 } | 248 } |
| 237 SkLayerDrawLooper* looper = builder.detachLooper(); | 249 SkLayerDrawLooper* looper = builder.detachLooper(); |
| 238 SkASSERT(count == looper->fCount); | 250 SkASSERT(count == looper->fCount); |
| 239 | 251 |
| 240 #ifdef SK_DEBUG | 252 #ifdef SK_DEBUG |
| (...skipping 12 matching lines...) Expand all Loading... |
| 253 } | 265 } |
| 254 | 266 |
| 255 #ifdef SK_DEVELOPER | 267 #ifdef SK_DEVELOPER |
| 256 void SkLayerDrawLooper::toString(SkString* str) const { | 268 void SkLayerDrawLooper::toString(SkString* str) const { |
| 257 str->appendf("SkLayerDrawLooper (%d): ", fCount); | 269 str->appendf("SkLayerDrawLooper (%d): ", fCount); |
| 258 | 270 |
| 259 Rec* rec = fRecs; | 271 Rec* rec = fRecs; |
| 260 for (int i = 0; i < fCount; i++) { | 272 for (int i = 0; i < fCount; i++) { |
| 261 str->appendf("%d: ", i); | 273 str->appendf("%d: ", i); |
| 262 | 274 |
| 275 #ifdef SK_SUPPORT_LEGACY_LAYERDRAWLOOPER_PAINTFLAGS |
| 263 str->append("flagsMask: ("); | 276 str->append("flagsMask: ("); |
| 264 if (0 == rec->fInfo.fFlagsMask) { | 277 if (0 == rec->fInfo.fFlagsMask) { |
| 265 str->append("None"); | 278 str->append("None"); |
| 266 } else { | 279 } else { |
| 267 bool needSeparator = false; | 280 bool needSeparator = false; |
| 268 SkAddFlagToString(str, SkToBool(SkPaint::kAntiAlias_Flag & rec->fInf
o.fFlagsMask), | 281 SkAddFlagToString(str, SkToBool(SkPaint::kAntiAlias_Flag & rec->fInf
o.fFlagsMask), |
| 269 "AntiAlias", &needSeparator); | 282 "AntiAlias", &needSeparator); |
| 270 // SkAddFlagToString(str, SkToBool(SkPaint::kFilterBitmap_Flag & rec-
>fInfo.fFlagsMask), "FilterBitmap", &needSeparator); | 283 // SkAddFlagToString(str, SkToBool(SkPaint::kFilterBitmap_Flag & rec-
>fInfo.fFlagsMask), "FilterBitmap", &needSeparator); |
| 271 SkAddFlagToString(str, SkToBool(SkPaint::kDither_Flag & rec->fInfo.f
FlagsMask), | 284 SkAddFlagToString(str, SkToBool(SkPaint::kDither_Flag & rec->fInfo.f
FlagsMask), |
| 272 "Dither", &needSeparator); | 285 "Dither", &needSeparator); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 286 "LCDRenderText", &needSeparator); | 299 "LCDRenderText", &needSeparator); |
| 287 SkAddFlagToString(str, SkToBool(SkPaint::kEmbeddedBitmapText_Flag &
rec->fInfo.fFlagsMask), | 300 SkAddFlagToString(str, SkToBool(SkPaint::kEmbeddedBitmapText_Flag &
rec->fInfo.fFlagsMask), |
| 288 "EmbeddedBitmapText", &needSeparator); | 301 "EmbeddedBitmapText", &needSeparator); |
| 289 SkAddFlagToString(str, SkToBool(SkPaint::kAutoHinting_Flag & rec->fI
nfo.fFlagsMask), | 302 SkAddFlagToString(str, SkToBool(SkPaint::kAutoHinting_Flag & rec->fI
nfo.fFlagsMask), |
| 290 "Autohinted", &needSeparator); | 303 "Autohinted", &needSeparator); |
| 291 SkAddFlagToString(str, SkToBool(SkPaint::kVerticalText_Flag & rec->f
Info.fFlagsMask), | 304 SkAddFlagToString(str, SkToBool(SkPaint::kVerticalText_Flag & rec->f
Info.fFlagsMask), |
| 292 "VerticalText", &needSeparator); | 305 "VerticalText", &needSeparator); |
| 293 SkAddFlagToString(str, SkToBool(SkPaint::kGenA8FromLCD_Flag & rec->f
Info.fFlagsMask), | 306 SkAddFlagToString(str, SkToBool(SkPaint::kGenA8FromLCD_Flag & rec->f
Info.fFlagsMask), |
| 294 "GenA8FromLCD", &needSeparator); | 307 "GenA8FromLCD", &needSeparator); |
| 295 } | 308 } |
| 309 #endif |
| 296 str->append(") "); | 310 str->append(") "); |
| 297 | 311 |
| 298 str->append("paintBits: ("); | 312 str->append("paintBits: ("); |
| 299 if (0 == rec->fInfo.fPaintBits) { | 313 if (0 == rec->fInfo.fPaintBits) { |
| 300 str->append("None"); | 314 str->append("None"); |
| 301 } else if (kEntirePaint_Bits == rec->fInfo.fPaintBits) { | 315 } else if (kEntirePaint_Bits == rec->fInfo.fPaintBits) { |
| 302 str->append("EntirePaint"); | 316 str->append("EntirePaint"); |
| 303 } else { | 317 } else { |
| 304 bool needSeparator = false; | 318 bool needSeparator = false; |
| 305 SkAddFlagToString(str, SkToBool(kStyle_Bit & rec->fInfo.fPaintBits),
"Style", | 319 SkAddFlagToString(str, SkToBool(kStyle_Bit & rec->fInfo.fPaintBits),
"Style", |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 404 SkLayerDrawLooper* looper = SkNEW(SkLayerDrawLooper); | 418 SkLayerDrawLooper* looper = SkNEW(SkLayerDrawLooper); |
| 405 looper->fCount = fCount; | 419 looper->fCount = fCount; |
| 406 looper->fRecs = fRecs; | 420 looper->fRecs = fRecs; |
| 407 | 421 |
| 408 fCount = 0; | 422 fCount = 0; |
| 409 fRecs = NULL; | 423 fRecs = NULL; |
| 410 fTopRec = NULL; | 424 fTopRec = NULL; |
| 411 | 425 |
| 412 return looper; | 426 return looper; |
| 413 } | 427 } |
| OLD | NEW |