OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 <algorithm> | 5 #include <algorithm> |
6 #include <limits> | 6 #include <limits> |
7 | 7 |
8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
9 #include "cc/base/region.h" | 9 #include "cc/base/region.h" |
10 #include "cc/debug/debug_colors.h" | 10 #include "cc/debug/debug_colors.h" |
11 #include "cc/resources/picture_pile_impl.h" | 11 #include "cc/resources/picture_pile_impl.h" |
12 #include "skia/ext/analysis_canvas.h" | 12 #include "skia/ext/analysis_canvas.h" |
13 #include "third_party/skia/include/core/SkCanvas.h" | 13 #include "third_party/skia/include/core/SkCanvas.h" |
14 #include "third_party/skia/include/core/SkPictureRecorder.h" | 14 #include "third_party/skia/include/core/SkPictureRecorder.h" |
15 #include "ui/gfx/geometry/rect_conversions.h" | 15 #include "ui/gfx/geometry/rect_conversions.h" |
16 | 16 |
| 17 namespace { |
| 18 |
| 19 #ifdef NDEBUG |
| 20 const bool kDefaultClearCanvasSetting = false; |
| 21 #else |
| 22 const bool kDefaultClearCanvasSetting = true; |
| 23 #endif |
| 24 |
| 25 } // namespace |
| 26 |
17 namespace cc { | 27 namespace cc { |
18 | 28 |
19 scoped_refptr<PicturePileImpl> PicturePileImpl::Create() { | 29 scoped_refptr<PicturePileImpl> PicturePileImpl::Create() { |
20 return make_scoped_refptr(new PicturePileImpl); | 30 return make_scoped_refptr(new PicturePileImpl); |
21 } | 31 } |
22 | 32 |
23 scoped_refptr<PicturePileImpl> PicturePileImpl::CreateFromPicturePile( | 33 scoped_refptr<PicturePileImpl> PicturePileImpl::CreateFromPicturePile( |
24 const PicturePile* other) { | 34 const PicturePile* other) { |
25 return make_scoped_refptr(new PicturePileImpl(other)); | 35 return make_scoped_refptr(new PicturePileImpl(other)); |
26 } | 36 } |
27 | 37 |
28 PicturePileImpl::PicturePileImpl() | 38 PicturePileImpl::PicturePileImpl() |
29 : background_color_(SK_ColorTRANSPARENT), | 39 : background_color_(SK_ColorTRANSPARENT), |
30 contents_opaque_(false), | 40 requires_clear_(true), |
31 contents_fill_bounds_completely_(false), | |
32 is_solid_color_(false), | 41 is_solid_color_(false), |
33 solid_color_(SK_ColorTRANSPARENT), | 42 solid_color_(SK_ColorTRANSPARENT), |
34 has_any_recordings_(false), | 43 has_any_recordings_(false), |
35 is_mask_(false), | 44 clear_canvas_with_debug_color_(kDefaultClearCanvasSetting), |
36 clear_canvas_with_debug_color_(false), | |
37 min_contents_scale_(0.f), | 45 min_contents_scale_(0.f), |
38 slow_down_raster_scale_factor_for_debug_(0), | 46 slow_down_raster_scale_factor_for_debug_(0), |
39 should_attempt_to_use_distance_field_text_(false) { | 47 should_attempt_to_use_distance_field_text_(false) { |
40 } | 48 } |
41 | 49 |
42 PicturePileImpl::PicturePileImpl(const PicturePile* other) | 50 PicturePileImpl::PicturePileImpl(const PicturePile* other) |
43 : picture_map_(other->picture_map_), | 51 : picture_map_(other->picture_map_), |
44 tiling_(other->tiling_), | 52 tiling_(other->tiling_), |
45 background_color_(other->background_color_), | 53 background_color_(SK_ColorTRANSPARENT), |
46 contents_opaque_(other->contents_opaque_), | 54 requires_clear_(true), |
47 contents_fill_bounds_completely_(other->contents_fill_bounds_completely_), | |
48 is_solid_color_(other->is_solid_color_), | 55 is_solid_color_(other->is_solid_color_), |
49 solid_color_(other->solid_color_), | 56 solid_color_(other->solid_color_), |
50 recorded_viewport_(other->recorded_viewport_), | 57 recorded_viewport_(other->recorded_viewport_), |
51 has_any_recordings_(other->has_any_recordings_), | 58 has_any_recordings_(other->has_any_recordings_), |
52 is_mask_(other->is_mask_), | 59 clear_canvas_with_debug_color_(kDefaultClearCanvasSetting), |
53 clear_canvas_with_debug_color_(other->clear_canvas_with_debug_color_), | |
54 min_contents_scale_(other->min_contents_scale_), | 60 min_contents_scale_(other->min_contents_scale_), |
55 slow_down_raster_scale_factor_for_debug_( | 61 slow_down_raster_scale_factor_for_debug_( |
56 other->slow_down_raster_scale_factor_for_debug_), | 62 other->slow_down_raster_scale_factor_for_debug_), |
57 should_attempt_to_use_distance_field_text_(false) { | 63 should_attempt_to_use_distance_field_text_(false) { |
58 } | 64 } |
59 | 65 |
60 PicturePileImpl::~PicturePileImpl() { | 66 PicturePileImpl::~PicturePileImpl() { |
61 } | 67 } |
62 | 68 |
63 void PicturePileImpl::PlaybackToSharedCanvas(SkCanvas* canvas, | 69 void PicturePileImpl::PlaybackToSharedCanvas(SkCanvas* canvas, |
(...skipping 17 matching lines...) Expand all Loading... |
81 float contents_scale) const { | 87 float contents_scale) const { |
82 canvas->discard(); | 88 canvas->discard(); |
83 if (clear_canvas_with_debug_color_) { | 89 if (clear_canvas_with_debug_color_) { |
84 // Any non-painted areas in the content bounds will be left in this color. | 90 // Any non-painted areas in the content bounds will be left in this color. |
85 canvas->clear(DebugColors::NonPaintedFillColor()); | 91 canvas->clear(DebugColors::NonPaintedFillColor()); |
86 } | 92 } |
87 | 93 |
88 // If this picture has opaque contents, it is guaranteeing that it will | 94 // If this picture has opaque contents, it is guaranteeing that it will |
89 // draw an opaque rect the size of the layer. If it is not, then we must | 95 // draw an opaque rect the size of the layer. If it is not, then we must |
90 // clear this canvas ourselves. | 96 // clear this canvas ourselves. |
91 if (contents_opaque_ || contents_fill_bounds_completely_) { | 97 if (requires_clear_) { |
| 98 TRACE_EVENT_INSTANT0("cc", "SkCanvas::clear", TRACE_EVENT_SCOPE_THREAD); |
| 99 // Clearing is about ~4x faster than drawing a rect even if the content |
| 100 // isn't covering a majority of the canvas. |
| 101 canvas->clear(SK_ColorTRANSPARENT); |
| 102 } else { |
92 // Even if completely covered, for rasterizations that touch the edge of the | 103 // Even if completely covered, for rasterizations that touch the edge of the |
93 // layer, we also need to raster the background color underneath the last | 104 // layer, we also need to raster the background color underneath the last |
94 // texel (since the recording won't cover it) and outside the last texel | 105 // texel (since the recording won't cover it) and outside the last texel |
95 // (due to linear filtering when using this texture). | 106 // (due to linear filtering when using this texture). |
96 gfx::Rect content_tiling_rect = gfx::ToEnclosingRect( | 107 gfx::Rect content_tiling_rect = gfx::ToEnclosingRect( |
97 gfx::ScaleRect(gfx::Rect(tiling_.tiling_size()), contents_scale)); | 108 gfx::ScaleRect(gfx::Rect(tiling_.tiling_size()), contents_scale)); |
98 | 109 |
99 // The final texel of content may only be partially covered by a | 110 // The final texel of content may only be partially covered by a |
100 // rasterization; this rect represents the content rect that is fully | 111 // rasterization; this rect represents the content rect that is fully |
101 // covered by content. | 112 // covered by content. |
(...skipping 20 matching lines...) Expand all Loading... |
122 canvas->translate(-canvas_rect.x(), -canvas_rect.y()); | 133 canvas->translate(-canvas_rect.x(), -canvas_rect.y()); |
123 gfx::Rect inflated_content_tiling_rect = content_tiling_rect; | 134 gfx::Rect inflated_content_tiling_rect = content_tiling_rect; |
124 inflated_content_tiling_rect.Inset(0, 0, -1, -1); | 135 inflated_content_tiling_rect.Inset(0, 0, -1, -1); |
125 canvas->clipRect(gfx::RectToSkRect(inflated_content_tiling_rect), | 136 canvas->clipRect(gfx::RectToSkRect(inflated_content_tiling_rect), |
126 SkRegion::kReplace_Op); | 137 SkRegion::kReplace_Op); |
127 canvas->clipRect(gfx::RectToSkRect(deflated_content_tiling_rect), | 138 canvas->clipRect(gfx::RectToSkRect(deflated_content_tiling_rect), |
128 SkRegion::kDifference_Op); | 139 SkRegion::kDifference_Op); |
129 canvas->drawColor(background_color_, SkXfermode::kSrc_Mode); | 140 canvas->drawColor(background_color_, SkXfermode::kSrc_Mode); |
130 canvas->restore(); | 141 canvas->restore(); |
131 } | 142 } |
132 } else { | |
133 TRACE_EVENT_INSTANT0("cc", "SkCanvas::clear", TRACE_EVENT_SCOPE_THREAD); | |
134 // Clearing is about ~4x faster than drawing a rect even if the content | |
135 // isn't covering a majority of the canvas. | |
136 canvas->clear(SK_ColorTRANSPARENT); | |
137 } | 143 } |
138 | 144 |
139 RasterCommon(canvas, | 145 RasterCommon(canvas, |
140 NULL, | 146 NULL, |
141 canvas_rect, | 147 canvas_rect, |
142 contents_scale, | 148 contents_scale, |
143 false); | 149 false); |
144 } | 150 } |
145 | 151 |
146 void PicturePileImpl::CoalesceRasters(const gfx::Rect& canvas_rect, | 152 void PicturePileImpl::CoalesceRasters(const gfx::Rect& canvas_rect, |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 if (!map_iter->second.GetPicture()) | 400 if (!map_iter->second.GetPicture()) |
395 return false; | 401 return false; |
396 } | 402 } |
397 return true; | 403 return true; |
398 } | 404 } |
399 | 405 |
400 void PicturePileImpl::SetShouldAttemptToUseDistanceFieldText() { | 406 void PicturePileImpl::SetShouldAttemptToUseDistanceFieldText() { |
401 should_attempt_to_use_distance_field_text_ = true; | 407 should_attempt_to_use_distance_field_text_ = true; |
402 } | 408 } |
403 | 409 |
| 410 void PicturePileImpl::SetBackgoundColor(SkColor background_color) { |
| 411 background_color_ = background_color; |
| 412 } |
| 413 |
| 414 void PicturePileImpl::SetRequiresClear(bool requires_clear) { |
| 415 requires_clear_ = requires_clear; |
| 416 } |
| 417 |
404 bool PicturePileImpl::ShouldAttemptToUseDistanceFieldText() const { | 418 bool PicturePileImpl::ShouldAttemptToUseDistanceFieldText() const { |
405 return should_attempt_to_use_distance_field_text_; | 419 return should_attempt_to_use_distance_field_text_; |
406 } | 420 } |
407 | 421 |
408 void PicturePileImpl::AsValueInto(base::debug::TracedValue* pictures) const { | 422 void PicturePileImpl::AsValueInto(base::debug::TracedValue* pictures) const { |
409 gfx::Rect tiling_rect(tiling_.tiling_size()); | 423 gfx::Rect tiling_rect(tiling_.tiling_size()); |
410 std::set<const void*> appended_pictures; | 424 std::set<const void*> appended_pictures; |
411 bool include_borders = true; | 425 bool include_borders = true; |
412 for (TilingData::Iterator tile_iter(&tiling_, tiling_rect, include_borders); | 426 for (TilingData::Iterator tile_iter(&tiling_, tiling_rect, include_borders); |
413 tile_iter; ++tile_iter) { | 427 tile_iter; ++tile_iter) { |
414 PictureMap::const_iterator map_iter = picture_map_.find(tile_iter.index()); | 428 PictureMap::const_iterator map_iter = picture_map_.find(tile_iter.index()); |
415 if (map_iter == picture_map_.end()) | 429 if (map_iter == picture_map_.end()) |
416 continue; | 430 continue; |
417 | 431 |
418 const Picture* picture = map_iter->second.GetPicture(); | 432 const Picture* picture = map_iter->second.GetPicture(); |
419 if (picture && (appended_pictures.count(picture) == 0)) { | 433 if (picture && (appended_pictures.count(picture) == 0)) { |
420 appended_pictures.insert(picture); | 434 appended_pictures.insert(picture); |
421 TracedValue::AppendIDRef(picture, pictures); | 435 TracedValue::AppendIDRef(picture, pictures); |
422 } | 436 } |
423 } | 437 } |
424 } | 438 } |
425 | 439 |
426 bool PicturePileImpl::IsMask() const { | |
427 return is_mask_; | |
428 } | |
429 | |
430 PicturePileImpl::PixelRefIterator::PixelRefIterator( | 440 PicturePileImpl::PixelRefIterator::PixelRefIterator( |
431 const gfx::Rect& content_rect, | 441 const gfx::Rect& content_rect, |
432 float contents_scale, | 442 float contents_scale, |
433 const PicturePileImpl* picture_pile) | 443 const PicturePileImpl* picture_pile) |
434 : picture_pile_(picture_pile), | 444 : picture_pile_(picture_pile), |
435 layer_rect_( | 445 layer_rect_( |
436 gfx::ScaleToEnclosingRect(content_rect, 1.f / contents_scale)), | 446 gfx::ScaleToEnclosingRect(content_rect, 1.f / contents_scale)), |
437 tile_iterator_(&picture_pile_->tiling_, | 447 tile_iterator_(&picture_pile_->tiling_, |
438 layer_rect_, | 448 layer_rect_, |
439 false /* include_borders */) { | 449 false /* include_borders */) { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
484 ++it) { | 494 ++it) { |
485 const Picture* picture = it->second.GetPicture(); | 495 const Picture* picture = it->second.GetPicture(); |
486 if (picture && (processed_pictures.count(picture) == 0)) { | 496 if (picture && (processed_pictures.count(picture) == 0)) { |
487 picture->EmitTraceSnapshot(); | 497 picture->EmitTraceSnapshot(); |
488 processed_pictures.insert(picture); | 498 processed_pictures.insert(picture); |
489 } | 499 } |
490 } | 500 } |
491 } | 501 } |
492 | 502 |
493 } // namespace cc | 503 } // namespace cc |
OLD | NEW |