| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/debug/trace_event.h" | 5 #include "base/debug/trace_event.h" |
| 6 #include "skia/ext/analysis_canvas.h" | 6 #include "skia/ext/analysis_canvas.h" |
| 7 #include "third_party/skia/include/core/SkDevice.h" | 7 #include "third_party/skia/include/core/SkDevice.h" |
| 8 #include "third_party/skia/include/core/SkDraw.h" | 8 #include "third_party/skia/include/core/SkDraw.h" |
| 9 #include "third_party/skia/include/core/SkRRect.h" | 9 #include "third_party/skia/include/core/SkRRect.h" |
| 10 #include "third_party/skia/include/core/SkShader.h" | 10 #include "third_party/skia/include/core/SkShader.h" |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 } // namespace | 89 } // namespace |
| 90 | 90 |
| 91 namespace skia { | 91 namespace skia { |
| 92 | 92 |
| 93 AnalysisDevice::AnalysisDevice(const SkBitmap& bm) | 93 AnalysisDevice::AnalysisDevice(const SkBitmap& bm) |
| 94 : INHERITED(bm) | 94 : INHERITED(bm) |
| 95 , estimatedCost_(0) | 95 , estimatedCost_(0) |
| 96 , isForcedNotSolid_(false) | 96 , isForcedNotSolid_(false) |
| 97 , isForcedNotTransparent_(false) | 97 , isForcedNotTransparent_(false) |
| 98 , isSolidColor_(false) | 98 , isSolidColor_(false) |
| 99 , isTransparent_(false) { | 99 , isTransparent_(false) |
| 100 | 100 , hasText_(false) { |
| 101 } | 101 } |
| 102 | 102 |
| 103 AnalysisDevice::~AnalysisDevice() { | 103 AnalysisDevice::~AnalysisDevice() { |
| 104 | 104 |
| 105 } | 105 } |
| 106 | 106 |
| 107 int AnalysisDevice::getEstimatedCost() const { | 107 int AnalysisDevice::getEstimatedCost() const { |
| 108 return estimatedCost_; | 108 return estimatedCost_; |
| 109 } | 109 } |
| 110 | 110 |
| 111 bool AnalysisDevice::getColorIfSolid(SkColor* color) const { | 111 bool AnalysisDevice::getColorIfSolid(SkColor* color) const { |
| 112 if (isSolidColor_) | 112 if (isSolidColor_) |
| 113 *color = color_; | 113 *color = color_; |
| 114 return isSolidColor_; | 114 return isSolidColor_; |
| 115 } | 115 } |
| 116 | 116 |
| 117 bool AnalysisDevice::isTransparent() const { | 117 bool AnalysisDevice::isTransparent() const { |
| 118 return isTransparent_; | 118 return isTransparent_; |
| 119 } | 119 } |
| 120 | 120 |
| 121 bool AnalysisDevice::hasText() const { |
| 122 return hasText_; |
| 123 } |
| 124 |
| 121 void AnalysisDevice::setForceNotSolid(bool flag) { | 125 void AnalysisDevice::setForceNotSolid(bool flag) { |
| 122 isForcedNotSolid_ = flag; | 126 isForcedNotSolid_ = flag; |
| 123 if (isForcedNotSolid_) | 127 if (isForcedNotSolid_) |
| 124 isSolidColor_ = false; | 128 isSolidColor_ = false; |
| 125 } | 129 } |
| 126 | 130 |
| 127 void AnalysisDevice::setForceNotTransparent(bool flag) { | 131 void AnalysisDevice::setForceNotTransparent(bool flag) { |
| 128 isForcedNotTransparent_ = flag; | 132 isForcedNotTransparent_ = flag; |
| 129 if (isForcedNotTransparent_) | 133 if (isForcedNotTransparent_) |
| 130 isTransparent_ = false; | 134 isTransparent_ = false; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 DCHECK(pixelRefs->empty()); | 178 DCHECK(pixelRefs->empty()); |
| 175 lazyPixelRefs_.swap(*pixelRefs); | 179 lazyPixelRefs_.swap(*pixelRefs); |
| 176 existingPixelRefIDs_.clear(); | 180 existingPixelRefIDs_.clear(); |
| 177 } | 181 } |
| 178 | 182 |
| 179 void AnalysisDevice::clear(SkColor color) { | 183 void AnalysisDevice::clear(SkColor color) { |
| 180 // FIXME: cost here should be simple rect of device size | 184 // FIXME: cost here should be simple rect of device size |
| 181 estimatedCost_ += kUnknownExpensiveCost; | 185 estimatedCost_ += kUnknownExpensiveCost; |
| 182 | 186 |
| 183 isTransparent_ = (!isForcedNotTransparent_ && SkColorGetA(color) == 0); | 187 isTransparent_ = (!isForcedNotTransparent_ && SkColorGetA(color) == 0); |
| 188 hasText_ = false; |
| 184 | 189 |
| 185 if (!isForcedNotSolid_ && SkColorGetA(color) == 255) { | 190 if (!isForcedNotSolid_ && SkColorGetA(color) == 255) { |
| 186 isSolidColor_ = true; | 191 isSolidColor_ = true; |
| 187 color_ = color; | 192 color_ = color; |
| 188 } | 193 } |
| 189 else { | 194 else { |
| 190 isSolidColor_ = false; | 195 isSolidColor_ = false; |
| 191 } | 196 } |
| 192 } | 197 } |
| 193 | 198 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 // - Transfer mode is clear (0 color, 0 alpha) | 244 // - Transfer mode is clear (0 color, 0 alpha) |
| 240 // | 245 // |
| 241 // If the paint alpha is not 0, or if the transfrer mode is | 246 // If the paint alpha is not 0, or if the transfrer mode is |
| 242 // not src, then this canvas will not be transparent. | 247 // not src, then this canvas will not be transparent. |
| 243 // | 248 // |
| 244 // In all other cases, we keep the current transparent value | 249 // In all other cases, we keep the current transparent value |
| 245 if (doesCoverCanvas && | 250 if (doesCoverCanvas && |
| 246 !isForcedNotTransparent_ && | 251 !isForcedNotTransparent_ && |
| 247 xferMode == SkXfermode::kClear_Mode) { | 252 xferMode == SkXfermode::kClear_Mode) { |
| 248 isTransparent_ = true; | 253 isTransparent_ = true; |
| 254 hasText_ = false; |
| 249 } | 255 } |
| 250 else if (paint.getAlpha() != 0 || | 256 else if (paint.getAlpha() != 0 || |
| 251 xferMode != SkXfermode::kSrc_Mode) { | 257 xferMode != SkXfermode::kSrc_Mode) { |
| 252 isTransparent_ = false; | 258 isTransparent_ = false; |
| 253 } | 259 } |
| 254 | 260 |
| 255 // This bitmap is solid if and only if the following holds. | 261 // This bitmap is solid if and only if the following holds. |
| 256 // Note that this might be overly conservative: | 262 // Note that this might be overly conservative: |
| 257 // - We're not in "forced not solid" mode | 263 // - We're not in "forced not solid" mode |
| 258 // - Paint is solid color | 264 // - Paint is solid color |
| 259 // - The quad is a full tile quad | 265 // - The quad is a full tile quad |
| 260 if (!isForcedNotSolid_ && | 266 if (!isForcedNotSolid_ && |
| 261 isSolidColorPaint(paint) && | 267 isSolidColorPaint(paint) && |
| 262 doesCoverCanvas) { | 268 doesCoverCanvas) { |
| 263 isSolidColor_ = true; | 269 isSolidColor_ = true; |
| 264 color_ = paint.getColor(); | 270 color_ = paint.getColor(); |
| 271 hasText_ = false; |
| 265 } | 272 } |
| 266 else { | 273 else { |
| 267 isSolidColor_ = false; | 274 isSolidColor_ = false; |
| 268 } | 275 } |
| 269 } | 276 } |
| 270 | 277 |
| 271 void AnalysisDevice::drawOval(const SkDraw&, const SkRect& oval, | 278 void AnalysisDevice::drawOval(const SkDraw&, const SkRect& oval, |
| 272 const SkPaint& paint) { | 279 const SkPaint& paint) { |
| 273 estimatedCost_ += kUnknownExpensiveCost; | 280 estimatedCost_ += kUnknownExpensiveCost; |
| 274 if (hasBitmap(paint)) { | 281 if (hasBitmap(paint)) { |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 | 346 |
| 340 void AnalysisDevice::drawText(const SkDraw&, const void* text, size_t len, | 347 void AnalysisDevice::drawText(const SkDraw&, const void* text, size_t len, |
| 341 SkScalar x, SkScalar y, const SkPaint& paint) { | 348 SkScalar x, SkScalar y, const SkPaint& paint) { |
| 342 estimatedCost_ += 1 + len / kSimpleTextCharPerUS; | 349 estimatedCost_ += 1 + len / kSimpleTextCharPerUS; |
| 343 if (hasBitmap(paint)) { | 350 if (hasBitmap(paint)) { |
| 344 estimatedCost_ += kUnknownBitmapCost; | 351 estimatedCost_ += kUnknownBitmapCost; |
| 345 addBitmapFromPaint(paint); | 352 addBitmapFromPaint(paint); |
| 346 } | 353 } |
| 347 isSolidColor_ = false; | 354 isSolidColor_ = false; |
| 348 isTransparent_ = false; | 355 isTransparent_ = false; |
| 356 hasText_ = true; |
| 349 } | 357 } |
| 350 | 358 |
| 351 void AnalysisDevice::drawPosText(const SkDraw& draw, const void* text, | 359 void AnalysisDevice::drawPosText(const SkDraw& draw, const void* text, |
| 352 size_t len, | 360 size_t len, |
| 353 const SkScalar pos[], SkScalar constY, | 361 const SkScalar pos[], SkScalar constY, |
| 354 int scalarsPerPos, const SkPaint& paint) { | 362 int scalarsPerPos, const SkPaint& paint) { |
| 355 // FIXME: On Z620, every glyph cache miss costs us about 10us. | 363 // FIXME: On Z620, every glyph cache miss costs us about 10us. |
| 356 // We don't have a good mechanism for predicting glyph cache misses. | 364 // We don't have a good mechanism for predicting glyph cache misses. |
| 357 estimatedCost_ += 1 + len / kSimpleTextCharPerUS; | 365 estimatedCost_ += 1 + len / kSimpleTextCharPerUS; |
| 358 if (hasBitmap(paint)) { | 366 if (hasBitmap(paint)) { |
| 359 estimatedCost_ += kUnknownBitmapCost; | 367 estimatedCost_ += kUnknownBitmapCost; |
| 360 addBitmapFromPaint(paint); | 368 addBitmapFromPaint(paint); |
| 361 } | 369 } |
| 362 isSolidColor_ = false; | 370 isSolidColor_ = false; |
| 363 isTransparent_ = false; | 371 isTransparent_ = false; |
| 372 hasText_ = true; |
| 364 } | 373 } |
| 365 | 374 |
| 366 void AnalysisDevice::drawTextOnPath(const SkDraw&, const void* text, | 375 void AnalysisDevice::drawTextOnPath(const SkDraw&, const void* text, |
| 367 size_t len, | 376 size_t len, |
| 368 const SkPath& path, const SkMatrix* matrix, | 377 const SkPath& path, const SkMatrix* matrix, |
| 369 const SkPaint& paint) { | 378 const SkPaint& paint) { |
| 370 estimatedCost_ += 1 + len / kSimpleTextCharPerUS; | 379 estimatedCost_ += 1 + len / kSimpleTextCharPerUS; |
| 371 if (hasBitmap(paint)) { | 380 if (hasBitmap(paint)) { |
| 372 estimatedCost_ += kUnknownBitmapCost; | 381 estimatedCost_ += kUnknownBitmapCost; |
| 373 addBitmapFromPaint(paint); | 382 addBitmapFromPaint(paint); |
| 374 } | 383 } |
| 375 isSolidColor_ = false; | 384 isSolidColor_ = false; |
| 376 isTransparent_ = false; | 385 isTransparent_ = false; |
| 386 hasText_ = true; |
| 377 } | 387 } |
| 378 | 388 |
| 379 #ifdef SK_BUILD_FOR_ANDROID | 389 #ifdef SK_BUILD_FOR_ANDROID |
| 380 void AnalysisDevice::drawPosTextOnPath(const SkDraw& draw, const void* text, | 390 void AnalysisDevice::drawPosTextOnPath(const SkDraw& draw, const void* text, |
| 381 size_t len, | 391 size_t len, |
| 382 const SkPoint pos[], const SkPaint& paint, | 392 const SkPoint pos[], const SkPaint& paint, |
| 383 const SkPath& path, const SkMatrix* matrix) { | 393 const SkPath& path, const SkMatrix* matrix) { |
| 384 estimatedCost_ += 1 + len / kSimpleTextCharPerUS; | 394 estimatedCost_ += 1 + len / kSimpleTextCharPerUS; |
| 385 if (hasBitmap(paint)) { | 395 if (hasBitmap(paint)) { |
| 386 estimatedCost_ += kUnknownBitmapCost; | 396 estimatedCost_ += kUnknownBitmapCost; |
| 387 addBitmapFromPaint(paint); | 397 addBitmapFromPaint(paint); |
| 388 } | 398 } |
| 389 isSolidColor_ = false; | 399 isSolidColor_ = false; |
| 390 isTransparent_ = false; | 400 isTransparent_ = false; |
| 401 hasText_ = true; |
| 391 } | 402 } |
| 392 #endif | 403 #endif |
| 393 | 404 |
| 394 void AnalysisDevice::drawVertices(const SkDraw&, SkCanvas::VertexMode, | 405 void AnalysisDevice::drawVertices(const SkDraw&, SkCanvas::VertexMode, |
| 395 int vertexCount, | 406 int vertexCount, |
| 396 const SkPoint verts[], const SkPoint texs[], | 407 const SkPoint verts[], const SkPoint texs[], |
| 397 const SkColor colors[], SkXfermode* xmode, | 408 const SkColor colors[], SkXfermode* xmode, |
| 398 const uint16_t indices[], int indexCount, | 409 const uint16_t indices[], int indexCount, |
| 399 const SkPaint& paint) { | 410 const SkPaint& paint) { |
| 400 estimatedCost_ += kUnknownExpensiveCost; | 411 estimatedCost_ += kUnknownExpensiveCost; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 } | 445 } |
| 435 | 446 |
| 436 bool AnalysisCanvas::getColorIfSolid(SkColor* color) const { | 447 bool AnalysisCanvas::getColorIfSolid(SkColor* color) const { |
| 437 return (static_cast<AnalysisDevice*>(getDevice()))->getColorIfSolid(color); | 448 return (static_cast<AnalysisDevice*>(getDevice()))->getColorIfSolid(color); |
| 438 } | 449 } |
| 439 | 450 |
| 440 bool AnalysisCanvas::isTransparent() const { | 451 bool AnalysisCanvas::isTransparent() const { |
| 441 return (static_cast<AnalysisDevice*>(getDevice()))->isTransparent(); | 452 return (static_cast<AnalysisDevice*>(getDevice()))->isTransparent(); |
| 442 } | 453 } |
| 443 | 454 |
| 455 bool AnalysisCanvas::hasText() const { |
| 456 return (static_cast<AnalysisDevice*>(getDevice()))->hasText(); |
| 457 } |
| 458 |
| 444 int AnalysisCanvas::getEstimatedCost() const { | 459 int AnalysisCanvas::getEstimatedCost() const { |
| 445 return (static_cast<AnalysisDevice*>(getDevice()))->getEstimatedCost(); | 460 return (static_cast<AnalysisDevice*>(getDevice()))->getEstimatedCost(); |
| 446 } | 461 } |
| 447 | 462 |
| 448 void AnalysisCanvas::consumeLazyPixelRefs(LazyPixelRefList* pixelRefs) { | 463 void AnalysisCanvas::consumeLazyPixelRefs(LazyPixelRefList* pixelRefs) { |
| 449 static_cast<AnalysisDevice*>(getDevice())->consumeLazyPixelRefs(pixelRefs); | 464 static_cast<AnalysisDevice*>(getDevice())->consumeLazyPixelRefs(pixelRefs); |
| 450 } | 465 } |
| 451 | 466 |
| 452 bool AnalysisCanvas::clipRect(const SkRect& rect, SkRegion::Op op, | 467 bool AnalysisCanvas::clipRect(const SkRect& rect, SkRegion::Op op, |
| 453 bool doAA) { | 468 bool doAA) { |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 544 if (savedStackSize_ < forceNotTransparentStackLevel_) { | 559 if (savedStackSize_ < forceNotTransparentStackLevel_) { |
| 545 (static_cast<AnalysisDevice*>(getDevice()))->setForceNotTransparent(false)
; | 560 (static_cast<AnalysisDevice*>(getDevice()))->setForceNotTransparent(false)
; |
| 546 forceNotTransparentStackLevel_ = kNoLayer; | 561 forceNotTransparentStackLevel_ = kNoLayer; |
| 547 } | 562 } |
| 548 } | 563 } |
| 549 } | 564 } |
| 550 | 565 |
| 551 } // namespace skia | 566 } // namespace skia |
| 552 | 567 |
| 553 | 568 |
| OLD | NEW |