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/logging.h" | 5 #include "base/logging.h" |
6 #include "base/trace_event/trace_event.h" | 6 #include "base/trace_event/trace_event.h" |
7 #include "skia/ext/analysis_canvas.h" | 7 #include "skia/ext/analysis_canvas.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/SkPath.h" | 9 #include "third_party/skia/include/core/SkPath.h" |
10 #include "third_party/skia/include/core/SkRRect.h" | 10 #include "third_party/skia/include/core/SkRRect.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 | 47 |
48 // Returns true if the specified drawn_rect will cover the entire canvas, and | 48 // Returns true if the specified drawn_rect will cover the entire canvas, and |
49 // that the canvas is not clipped (i.e. it covers ALL of the canvas). | 49 // that the canvas is not clipped (i.e. it covers ALL of the canvas). |
50 bool IsFullQuad(SkCanvas* canvas, const SkRect& drawn_rect) { | 50 bool IsFullQuad(SkCanvas* canvas, const SkRect& drawn_rect) { |
51 if (!canvas->isClipRect()) | 51 if (!canvas->isClipRect()) |
52 return false; | 52 return false; |
53 | 53 |
54 SkIRect clip_irect; | 54 SkIRect clip_irect; |
55 if (!canvas->getClipDeviceBounds(&clip_irect)) | 55 if (!canvas->getClipDeviceBounds(&clip_irect)) |
56 return false; | 56 return false; |
57 | 57 |
58 // if the clip is smaller than the canvas, we're partly clipped, so abort. | 58 // if the clip is smaller than the canvas, we're partly clipped, so abort. |
59 if (!clip_irect.contains(SkIRect::MakeSize(canvas->getBaseLayerSize()))) | 59 if (!clip_irect.contains(SkIRect::MakeSize(canvas->getBaseLayerSize()))) |
60 return false; | 60 return false; |
61 | 61 |
62 const SkMatrix& matrix = canvas->getTotalMatrix(); | 62 const SkMatrix& matrix = canvas->getTotalMatrix(); |
63 // If the transform results in a non-axis aligned | 63 // If the transform results in a non-axis aligned |
64 // rect, then be conservative and return false. | 64 // rect, then be conservative and return false. |
65 if (!matrix.rectStaysRect()) | 65 if (!matrix.rectStaysRect()) |
66 return false; | 66 return false; |
67 | 67 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 } | 106 } |
107 | 107 |
108 void AnalysisCanvas::onDrawRect(const SkRect& rect, const SkPaint& paint) { | 108 void AnalysisCanvas::onDrawRect(const SkRect& rect, const SkPaint& paint) { |
109 TRACE_EVENT0("disabled-by-default-skia", "AnalysisCanvas::onDrawRect"); | 109 TRACE_EVENT0("disabled-by-default-skia", "AnalysisCanvas::onDrawRect"); |
110 // This recreates the early-exit logic in SkCanvas.cpp. | 110 // This recreates the early-exit logic in SkCanvas.cpp. |
111 SkRect scratch; | 111 SkRect scratch; |
112 if (paint.canComputeFastBounds() && | 112 if (paint.canComputeFastBounds() && |
113 quickReject(paint.computeFastBounds(rect, &scratch))) { | 113 quickReject(paint.computeFastBounds(rect, &scratch))) { |
114 TRACE_EVENT_INSTANT0("disabled-by-default-skia", "Quick reject.", | 114 TRACE_EVENT_INSTANT0("disabled-by-default-skia", "Quick reject.", |
115 TRACE_EVENT_SCOPE_THREAD); | 115 TRACE_EVENT_SCOPE_THREAD); |
| 116 ++rejected_op_count_; |
116 return; | 117 return; |
117 } | 118 } |
118 | 119 |
119 // An extra no-op check SkCanvas.cpp doesn't do. | 120 // An extra no-op check SkCanvas.cpp doesn't do. |
120 if (paint.nothingToDraw()) { | 121 if (paint.nothingToDraw()) { |
121 TRACE_EVENT_INSTANT0("disabled-by-default-skia", "Nothing to draw.", | 122 TRACE_EVENT_INSTANT0("disabled-by-default-skia", "Nothing to draw.", |
122 TRACE_EVENT_SCOPE_THREAD); | 123 TRACE_EVENT_SCOPE_THREAD); |
123 return; | 124 return; |
124 } | 125 } |
125 | 126 |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 AnalysisCanvas::AnalysisCanvas(int width, int height) | 343 AnalysisCanvas::AnalysisCanvas(int width, int height) |
343 : INHERITED(MakeEmptyBitmap(width, height)), | 344 : INHERITED(MakeEmptyBitmap(width, height)), |
344 saved_stack_size_(0), | 345 saved_stack_size_(0), |
345 force_not_solid_stack_level_(kNoLayer), | 346 force_not_solid_stack_level_(kNoLayer), |
346 force_not_transparent_stack_level_(kNoLayer), | 347 force_not_transparent_stack_level_(kNoLayer), |
347 is_forced_not_solid_(false), | 348 is_forced_not_solid_(false), |
348 is_forced_not_transparent_(false), | 349 is_forced_not_transparent_(false), |
349 is_solid_color_(true), | 350 is_solid_color_(true), |
350 color_(SK_ColorTRANSPARENT), | 351 color_(SK_ColorTRANSPARENT), |
351 is_transparent_(true), | 352 is_transparent_(true), |
352 draw_op_count_(0) { | 353 draw_op_count_(0), |
| 354 rejected_op_count_(0) { |
353 } | 355 } |
354 | 356 |
355 AnalysisCanvas::~AnalysisCanvas() {} | 357 AnalysisCanvas::~AnalysisCanvas() {} |
356 | 358 |
357 bool AnalysisCanvas::GetColorIfSolid(SkColor* color) const { | 359 bool AnalysisCanvas::GetColorIfSolid(SkColor* color) const { |
358 if (is_transparent_) { | 360 if (is_transparent_) { |
359 *color = SK_ColorTRANSPARENT; | 361 *color = SK_ColorTRANSPARENT; |
360 return true; | 362 return true; |
361 } | 363 } |
362 if (is_solid_color_) { | 364 if (is_solid_color_) { |
363 *color = color_; | 365 *color = color_; |
364 return true; | 366 return true; |
365 } | 367 } |
366 return false; | 368 return false; |
367 } | 369 } |
368 | 370 |
369 bool AnalysisCanvas::abort() { | 371 bool AnalysisCanvas::abort() { |
370 // Early out as soon as we have more than one draw op. | 372 // Early out as soon as we have more than 1 draw op or 5 rejected ops. |
371 // TODO(vmpstr): Investigate if 1 is the correct metric here. We need to | 373 // TODO(vmpstr): Investigate if 1 and 5 are the correct metrics here. We need |
372 // balance the amount of time we spend analyzing vs how many tiles would be | 374 // to balance the amount of time we spend analyzing vs how many tiles would be |
373 // solid if the number was higher. | 375 // solid if the numbers were higher. |
374 if (draw_op_count_ > 1) { | 376 if (draw_op_count_ > 1 || rejected_op_count_ > 5) { |
375 TRACE_EVENT0("disabled-by-default-skia", | 377 TRACE_EVENT0("disabled-by-default-skia", |
376 "AnalysisCanvas::abort() -- aborting"); | 378 "AnalysisCanvas::abort() -- aborting"); |
377 // We have to reset solid/transparent state to false since we don't | 379 // We have to reset solid/transparent state to false since we don't |
378 // know whether consequent operations will make this false. | 380 // know whether consequent operations will make this false. |
379 is_solid_color_ = false; | 381 is_solid_color_ = false; |
380 is_transparent_ = false; | 382 is_transparent_ = false; |
381 return true; | 383 return true; |
382 } | 384 } |
383 return false; | 385 return false; |
384 } | 386 } |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
486 force_not_transparent_stack_level_ = kNoLayer; | 488 force_not_transparent_stack_level_ = kNoLayer; |
487 } | 489 } |
488 } | 490 } |
489 | 491 |
490 INHERITED::willRestore(); | 492 INHERITED::willRestore(); |
491 } | 493 } |
492 | 494 |
493 } // namespace skia | 495 } // namespace skia |
494 | 496 |
495 | 497 |
OLD | NEW |