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 "cc/resources/picture_pile.h" | 5 #include "cc/resources/picture_pile.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "cc/base/region.h" | 11 #include "cc/base/region.h" |
12 #include "cc/debug/rendering_stats_instrumentation.h" | 12 #include "cc/debug/rendering_stats_instrumentation.h" |
13 #include "cc/resources/picture_pile_impl.h" | 13 #include "cc/resources/picture_pile_impl.h" |
14 #include "cc/resources/raster_worker_pool.h" | 14 #include "cc/resources/raster_worker_pool.h" |
15 #include "cc/resources/tile_priority.h" | 15 #include "cc/resources/tile_priority.h" |
16 | 16 |
17 namespace { | 17 namespace { |
18 // Layout pixel buffer around the visible layer rect to record. Any base | 18 // Layout pixel buffer around the visible layer rect to record. Any base |
19 // picture that intersects the visible layer rect expanded by this distance | 19 // picture that intersects the visible layer rect expanded by this distance |
20 // will be recorded. | 20 // will be recorded. |
21 const int kPixelDistanceToRecord = 8000; | 21 const int kPixelDistanceToRecord = 8000; |
22 // We don't perform solid color analysis on images that have more than 10 skia | |
23 // operations. | |
24 const int kOpCountThatIsOkToAnalyze = 10; | |
22 | 25 |
23 // TODO(humper): The density threshold here is somewhat arbitrary; need a | 26 // TODO(humper): The density threshold here is somewhat arbitrary; need a |
24 // way to set // this from the command line so we can write a benchmark | 27 // way to set // this from the command line so we can write a benchmark |
25 // script and find a sweet spot. | 28 // script and find a sweet spot. |
26 const float kDensityThreshold = 0.5f; | 29 const float kDensityThreshold = 0.5f; |
27 | 30 |
28 bool rect_sort_y(const gfx::Rect& r1, const gfx::Rect& r2) { | 31 bool rect_sort_y(const gfx::Rect& r1, const gfx::Rect& r2) { |
29 return r1.y() < r2.y() || (r1.y() == r2.y() && r1.x() < r2.x()); | 32 return r1.y() < r2.y() || (r1.y() == r2.y() && r1.x() < r2.x()); |
30 } | 33 } |
31 | 34 |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
139 } | 142 } |
140 | 143 |
141 *record_rects = vertical_clustering; | 144 *record_rects = vertical_clustering; |
142 return vertical_density; | 145 return vertical_density; |
143 } | 146 } |
144 | 147 |
145 } // namespace | 148 } // namespace |
146 | 149 |
147 namespace cc { | 150 namespace cc { |
148 | 151 |
149 PicturePile::PicturePile() : is_suitable_for_gpu_rasterization_(true) {} | 152 PicturePile::PicturePile() |
153 : is_suitable_for_gpu_rasterization_(true), | |
154 is_solid_color_(true), | |
155 solid_color_(SK_ColorTRANSPARENT) { | |
156 } | |
150 | 157 |
151 PicturePile::~PicturePile() { | 158 PicturePile::~PicturePile() { |
152 } | 159 } |
153 | 160 |
154 bool PicturePile::UpdateAndExpandInvalidation( | 161 bool PicturePile::UpdateAndExpandInvalidation( |
155 ContentLayerClient* painter, | 162 ContentLayerClient* painter, |
156 Region* invalidation, | 163 Region* invalidation, |
157 SkColor background_color, | 164 SkColor background_color, |
158 bool contents_opaque, | 165 bool contents_opaque, |
159 bool contents_fill_bounds_completely, | 166 bool contents_fill_bounds_completely, |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
494 for (TilingData::Iterator it(&tiling_, record_rect, include_borders); it; | 501 for (TilingData::Iterator it(&tiling_, record_rect, include_borders); it; |
495 ++it) { | 502 ++it) { |
496 const PictureMapKey& key = it.index(); | 503 const PictureMapKey& key = it.index(); |
497 gfx::Rect tile = PaddedRect(key); | 504 gfx::Rect tile = PaddedRect(key); |
498 if (record_rect.Contains(tile)) { | 505 if (record_rect.Contains(tile)) { |
499 PictureInfo& info = picture_map_[key]; | 506 PictureInfo& info = picture_map_[key]; |
500 info.SetPicture(picture); | 507 info.SetPicture(picture); |
501 found_tile_for_recorded_picture = true; | 508 found_tile_for_recorded_picture = true; |
502 } | 509 } |
503 } | 510 } |
511 DetermineIfSolidColor(); | |
504 DCHECK(found_tile_for_recorded_picture); | 512 DCHECK(found_tile_for_recorded_picture); |
505 } | 513 } |
506 | 514 |
507 has_any_recordings_ = true; | 515 has_any_recordings_ = true; |
508 DCHECK(CanRasterSlowTileCheck(recorded_viewport_)); | 516 DCHECK(CanRasterSlowTileCheck(recorded_viewport_)); |
509 return true; | 517 return true; |
510 } | 518 } |
511 | 519 |
512 void PicturePile::SetEmptyBounds() { | 520 void PicturePile::SetEmptyBounds() { |
513 tiling_.SetTilingSize(gfx::Size()); | 521 tiling_.SetTilingSize(gfx::Size()); |
514 picture_map_.clear(); | 522 picture_map_.clear(); |
515 has_any_recordings_ = false; | 523 has_any_recordings_ = false; |
516 recorded_viewport_ = gfx::Rect(); | 524 recorded_viewport_ = gfx::Rect(); |
517 } | 525 } |
518 | 526 |
527 void PicturePile::DetermineIfSolidColor() { | |
528 is_solid_color_ = false; | |
529 solid_color_ = SK_ColorTRANSPARENT; | |
530 | |
531 // Determine if the entire picture map is pointing to the same image. | |
532 if (picture_map_.empty()) { | |
533 is_solid_color_ = true; // No pictures? Then we're solid 100% transparent. | |
enne (OOO)
2014/08/25 23:21:07
Is this true? I think the map being empty is maybe
hendrikw
2014/08/26 00:12:38
I don't think we should ever rasterize a picture_p
| |
534 return; | |
535 } | |
536 | |
537 PictureMap::const_iterator it = picture_map_.begin(); | |
538 const Picture* picture = it->second.GetPicture(); | |
539 | |
540 // There are situations where the first picture is NULL, we'll assume not | |
enne (OOO)
2014/08/25 23:21:07
"There are situations where the first picture is N
hendrikw
2014/08/26 00:12:37
Done.
| |
541 // solid in this case. | |
542 if (!picture) | |
543 return; | |
544 | |
545 // Don't bother doing more work if the first image is too complicated. | |
546 if (picture->ApproximateOpCount() > kOpCountThatIsOkToAnalyze) | |
547 return; | |
548 | |
549 // Make sure all of the mapped images point to the same picture. | |
550 for (++it; it != picture_map_.end(); ++it) { | |
551 if (it->second.GetPicture() != picture) | |
552 return; | |
553 } | |
554 skia::AnalysisCanvas canvas(recorded_viewport_.width(), | |
555 recorded_viewport_.height()); | |
556 picture->Raster(&canvas, NULL, Region(), 1.0f); | |
557 is_solid_color_ = canvas.GetColorIfSolid(&solid_color_); | |
558 } | |
559 | |
519 } // namespace cc | 560 } // namespace cc |
OLD | NEW |