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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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); |
184 | 188 |
185 if (!isForcedNotSolid_ && SkColorGetA(color) == 255) { | 189 if (!isForcedNotSolid_ && SkColorGetA(color) == 255) { |
186 isSolidColor_ = true; | 190 isSolidColor_ = true; |
187 color_ = color; | 191 color_ = color; |
enne (OOO)
2013/04/05 21:39:36
Do you need to set hasText_ here? Can you add a t
alokp
2013/04/05 22:50:11
Good catch. Done. Added Tests.
| |
188 } | 192 } |
189 else { | 193 else { |
190 isSolidColor_ = false; | 194 isSolidColor_ = false; |
191 } | 195 } |
192 } | 196 } |
193 | 197 |
194 void AnalysisDevice::drawPaint(const SkDraw&, const SkPaint& paint) { | 198 void AnalysisDevice::drawPaint(const SkDraw&, const SkPaint& paint) { |
195 estimatedCost_ += kUnknownExpensiveCost; | 199 estimatedCost_ += kUnknownExpensiveCost; |
196 if (hasBitmap(paint)) { | 200 if (hasBitmap(paint)) { |
197 estimatedCost_ += kUnknownBitmapCost; | 201 estimatedCost_ += kUnknownBitmapCost; |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
339 | 343 |
340 void AnalysisDevice::drawText(const SkDraw&, const void* text, size_t len, | 344 void AnalysisDevice::drawText(const SkDraw&, const void* text, size_t len, |
341 SkScalar x, SkScalar y, const SkPaint& paint) { | 345 SkScalar x, SkScalar y, const SkPaint& paint) { |
342 estimatedCost_ += 1 + len / kSimpleTextCharPerUS; | 346 estimatedCost_ += 1 + len / kSimpleTextCharPerUS; |
343 if (hasBitmap(paint)) { | 347 if (hasBitmap(paint)) { |
344 estimatedCost_ += kUnknownBitmapCost; | 348 estimatedCost_ += kUnknownBitmapCost; |
345 addBitmapFromPaint(paint); | 349 addBitmapFromPaint(paint); |
346 } | 350 } |
347 isSolidColor_ = false; | 351 isSolidColor_ = false; |
348 isTransparent_ = false; | 352 isTransparent_ = false; |
353 hasText_ = true; | |
349 } | 354 } |
350 | 355 |
351 void AnalysisDevice::drawPosText(const SkDraw& draw, const void* text, | 356 void AnalysisDevice::drawPosText(const SkDraw& draw, const void* text, |
352 size_t len, | 357 size_t len, |
353 const SkScalar pos[], SkScalar constY, | 358 const SkScalar pos[], SkScalar constY, |
354 int scalarsPerPos, const SkPaint& paint) { | 359 int scalarsPerPos, const SkPaint& paint) { |
355 // FIXME: On Z620, every glyph cache miss costs us about 10us. | 360 // FIXME: On Z620, every glyph cache miss costs us about 10us. |
356 // We don't have a good mechanism for predicting glyph cache misses. | 361 // We don't have a good mechanism for predicting glyph cache misses. |
357 estimatedCost_ += 1 + len / kSimpleTextCharPerUS; | 362 estimatedCost_ += 1 + len / kSimpleTextCharPerUS; |
358 if (hasBitmap(paint)) { | 363 if (hasBitmap(paint)) { |
359 estimatedCost_ += kUnknownBitmapCost; | 364 estimatedCost_ += kUnknownBitmapCost; |
360 addBitmapFromPaint(paint); | 365 addBitmapFromPaint(paint); |
361 } | 366 } |
362 isSolidColor_ = false; | 367 isSolidColor_ = false; |
363 isTransparent_ = false; | 368 isTransparent_ = false; |
369 hasText_ = true; | |
364 } | 370 } |
365 | 371 |
366 void AnalysisDevice::drawTextOnPath(const SkDraw&, const void* text, | 372 void AnalysisDevice::drawTextOnPath(const SkDraw&, const void* text, |
367 size_t len, | 373 size_t len, |
368 const SkPath& path, const SkMatrix* matrix, | 374 const SkPath& path, const SkMatrix* matrix, |
369 const SkPaint& paint) { | 375 const SkPaint& paint) { |
370 estimatedCost_ += 1 + len / kSimpleTextCharPerUS; | 376 estimatedCost_ += 1 + len / kSimpleTextCharPerUS; |
371 if (hasBitmap(paint)) { | 377 if (hasBitmap(paint)) { |
372 estimatedCost_ += kUnknownBitmapCost; | 378 estimatedCost_ += kUnknownBitmapCost; |
373 addBitmapFromPaint(paint); | 379 addBitmapFromPaint(paint); |
374 } | 380 } |
375 isSolidColor_ = false; | 381 isSolidColor_ = false; |
376 isTransparent_ = false; | 382 isTransparent_ = false; |
383 hasText_ = true; | |
377 } | 384 } |
378 | 385 |
379 #ifdef SK_BUILD_FOR_ANDROID | 386 #ifdef SK_BUILD_FOR_ANDROID |
380 void AnalysisDevice::drawPosTextOnPath(const SkDraw& draw, const void* text, | 387 void AnalysisDevice::drawPosTextOnPath(const SkDraw& draw, const void* text, |
381 size_t len, | 388 size_t len, |
382 const SkPoint pos[], const SkPaint& paint, | 389 const SkPoint pos[], const SkPaint& paint, |
383 const SkPath& path, const SkMatrix* matrix) { | 390 const SkPath& path, const SkMatrix* matrix) { |
384 estimatedCost_ += 1 + len / kSimpleTextCharPerUS; | 391 estimatedCost_ += 1 + len / kSimpleTextCharPerUS; |
385 if (hasBitmap(paint)) { | 392 if (hasBitmap(paint)) { |
386 estimatedCost_ += kUnknownBitmapCost; | 393 estimatedCost_ += kUnknownBitmapCost; |
387 addBitmapFromPaint(paint); | 394 addBitmapFromPaint(paint); |
388 } | 395 } |
389 isSolidColor_ = false; | 396 isSolidColor_ = false; |
390 isTransparent_ = false; | 397 isTransparent_ = false; |
398 hasText_ = true; | |
391 } | 399 } |
392 #endif | 400 #endif |
393 | 401 |
394 void AnalysisDevice::drawVertices(const SkDraw&, SkCanvas::VertexMode, | 402 void AnalysisDevice::drawVertices(const SkDraw&, SkCanvas::VertexMode, |
395 int vertexCount, | 403 int vertexCount, |
396 const SkPoint verts[], const SkPoint texs[], | 404 const SkPoint verts[], const SkPoint texs[], |
397 const SkColor colors[], SkXfermode* xmode, | 405 const SkColor colors[], SkXfermode* xmode, |
398 const uint16_t indices[], int indexCount, | 406 const uint16_t indices[], int indexCount, |
399 const SkPaint& paint) { | 407 const SkPaint& paint) { |
400 estimatedCost_ += kUnknownExpensiveCost; | 408 estimatedCost_ += kUnknownExpensiveCost; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
434 } | 442 } |
435 | 443 |
436 bool AnalysisCanvas::getColorIfSolid(SkColor* color) const { | 444 bool AnalysisCanvas::getColorIfSolid(SkColor* color) const { |
437 return (static_cast<AnalysisDevice*>(getDevice()))->getColorIfSolid(color); | 445 return (static_cast<AnalysisDevice*>(getDevice()))->getColorIfSolid(color); |
438 } | 446 } |
439 | 447 |
440 bool AnalysisCanvas::isTransparent() const { | 448 bool AnalysisCanvas::isTransparent() const { |
441 return (static_cast<AnalysisDevice*>(getDevice()))->isTransparent(); | 449 return (static_cast<AnalysisDevice*>(getDevice()))->isTransparent(); |
442 } | 450 } |
443 | 451 |
452 bool AnalysisCanvas::hasText() const { | |
453 return (static_cast<AnalysisDevice*>(getDevice()))->hasText(); | |
454 } | |
455 | |
444 int AnalysisCanvas::getEstimatedCost() const { | 456 int AnalysisCanvas::getEstimatedCost() const { |
445 return (static_cast<AnalysisDevice*>(getDevice()))->getEstimatedCost(); | 457 return (static_cast<AnalysisDevice*>(getDevice()))->getEstimatedCost(); |
446 } | 458 } |
447 | 459 |
448 void AnalysisCanvas::consumeLazyPixelRefs(LazyPixelRefList* pixelRefs) { | 460 void AnalysisCanvas::consumeLazyPixelRefs(LazyPixelRefList* pixelRefs) { |
449 static_cast<AnalysisDevice*>(getDevice())->consumeLazyPixelRefs(pixelRefs); | 461 static_cast<AnalysisDevice*>(getDevice())->consumeLazyPixelRefs(pixelRefs); |
450 } | 462 } |
451 | 463 |
452 bool AnalysisCanvas::clipRect(const SkRect& rect, SkRegion::Op op, | 464 bool AnalysisCanvas::clipRect(const SkRect& rect, SkRegion::Op op, |
453 bool doAA) { | 465 bool doAA) { |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
544 if (savedStackSize_ < forceNotTransparentStackLevel_) { | 556 if (savedStackSize_ < forceNotTransparentStackLevel_) { |
545 (static_cast<AnalysisDevice*>(getDevice()))->setForceNotTransparent(false) ; | 557 (static_cast<AnalysisDevice*>(getDevice()))->setForceNotTransparent(false) ; |
546 forceNotTransparentStackLevel_ = kNoLayer; | 558 forceNotTransparentStackLevel_ = kNoLayer; |
547 } | 559 } |
548 } | 560 } |
549 } | 561 } |
550 | 562 |
551 } // namespace skia | 563 } // namespace skia |
552 | 564 |
553 | 565 |
OLD | NEW |