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 | 22 |
23 // TODO(humper): The density threshold here is somewhat arbitrary; need a | 23 // 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 | 24 // way to set // this from the command line so we can write a benchmark |
25 // script and find a sweet spot. | 25 // script and find a sweet spot. |
26 const float kDensityThreshold = 0.5f; | 26 const float kDensityThreshold = 0.5f; |
27 | 27 |
28 bool rect_sort_y(const gfx::Rect &r1, const gfx::Rect &r2) { | 28 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()); | 29 return r1.y() < r2.y() || (r1.y() == r2.y() && r1.x() < r2.x()); |
30 } | 30 } |
31 | 31 |
32 bool rect_sort_x(const gfx::Rect &r1, const gfx::Rect &r2) { | 32 bool rect_sort_x(const gfx::Rect& r1, const gfx::Rect& r2) { |
33 return r1.x() < r2.x() || (r1.x() == r2.x() && r1.y() < r2.y()); | 33 return r1.x() < r2.x() || (r1.x() == r2.x() && r1.y() < r2.y()); |
34 } | 34 } |
35 | 35 |
36 float do_clustering(const std::vector<gfx::Rect>& tiles, | 36 float PerformClustering(const std::vector<gfx::Rect>& tiles, |
37 std::vector<gfx::Rect>* clustered_rects) { | 37 std::vector<gfx::Rect>* clustered_rects) { |
38 // These variables track the record area and invalid area | 38 // These variables track the record area and invalid area |
39 // for the entire clustering | 39 // for the entire clustering |
40 int total_record_area = 0; | 40 int total_record_area = 0; |
41 int total_invalid_area = 0; | 41 int total_invalid_area = 0; |
42 | 42 |
43 // These variables track the record area and invalid area | 43 // These variables track the record area and invalid area |
44 // for the current cluster being constructed. | 44 // for the current cluster being constructed. |
45 gfx::Rect cur_record_rect; | 45 gfx::Rect cur_record_rect; |
46 int cluster_record_area = 0, cluster_invalid_area = 0; | 46 int cluster_record_area = 0, cluster_invalid_area = 0; |
47 | 47 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 } | 82 } |
83 | 83 |
84 DCHECK(!cur_record_rect.IsEmpty()); | 84 DCHECK(!cur_record_rect.IsEmpty()); |
85 clustered_rects->push_back(cur_record_rect); | 85 clustered_rects->push_back(cur_record_rect); |
86 total_record_area += cluster_record_area;; | 86 total_record_area += cluster_record_area;; |
87 | 87 |
88 DCHECK_NE(total_record_area, 0); | 88 DCHECK_NE(total_record_area, 0); |
89 | 89 |
90 return static_cast<float>(total_invalid_area) / | 90 return static_cast<float>(total_invalid_area) / |
91 static_cast<float>(total_record_area); | 91 static_cast<float>(total_record_area); |
92 } | 92 } |
93 | 93 |
94 float ClusterTiles(const std::vector<gfx::Rect>& invalid_tiles, | 94 float ClusterTiles(const std::vector<gfx::Rect>& invalid_tiles, |
95 std::vector<gfx::Rect>* record_rects) { | 95 std::vector<gfx::Rect>* record_rects) { |
96 TRACE_EVENT1("cc", "ClusterTiles", | 96 TRACE_EVENT1("cc", "ClusterTiles", |
97 "count", | 97 "count", |
98 invalid_tiles.size()); | 98 invalid_tiles.size()); |
99 | 99 |
100 if (invalid_tiles.size() <= 1) { | 100 if (invalid_tiles.size() <= 1) { |
101 // Quickly handle the special case for common | 101 // Quickly handle the special case for common |
102 // single-invalidation update, and also the less common | 102 // single-invalidation update, and also the less common |
103 // case of no tiles passed in. | 103 // case of no tiles passed in. |
104 *record_rects = invalid_tiles; | 104 *record_rects = invalid_tiles; |
105 return 1; | 105 return 1; |
106 } | 106 } |
107 | 107 |
108 // Sort the invalid tiles by y coordinate. | 108 // Sort the invalid tiles by y coordinate. |
109 std::vector<gfx::Rect> invalid_tiles_vertical = invalid_tiles; | 109 std::vector<gfx::Rect> invalid_tiles_vertical = invalid_tiles; |
110 std::sort(invalid_tiles_vertical.begin(), | 110 std::sort(invalid_tiles_vertical.begin(), |
111 invalid_tiles_vertical.end(), | 111 invalid_tiles_vertical.end(), |
112 rect_sort_y); | 112 rect_sort_y); |
113 | 113 |
114 float vertical_density; | 114 float vertical_density; |
115 std::vector<gfx::Rect> vertical_clustering; | 115 std::vector<gfx::Rect> vertical_clustering; |
116 vertical_density = do_clustering(invalid_tiles_vertical, | 116 vertical_density = PerformClustering(invalid_tiles_vertical, |
117 &vertical_clustering); | 117 &vertical_clustering); |
118 | 118 |
119 // Now try again with a horizontal sort, see which one is best | 119 // Now try again with a horizontal sort, see which one is best |
120 // TODO(humper): Heuristics for skipping this step? | 120 // TODO(humper): Heuristics for skipping this step? |
121 std::vector<gfx::Rect> invalid_tiles_horizontal = invalid_tiles; | 121 std::vector<gfx::Rect> invalid_tiles_horizontal = invalid_tiles; |
122 std::sort(invalid_tiles_vertical.begin(), | 122 std::sort(invalid_tiles_vertical.begin(), |
123 invalid_tiles_vertical.end(), | 123 invalid_tiles_vertical.end(), |
124 rect_sort_x); | 124 rect_sort_x); |
125 | 125 |
126 float horizontal_density; | 126 float horizontal_density; |
127 std::vector<gfx::Rect> horizontal_clustering; | 127 std::vector<gfx::Rect> horizontal_clustering; |
128 horizontal_density = do_clustering(invalid_tiles_vertical, | 128 horizontal_density = PerformClustering(invalid_tiles_vertical, |
129 &horizontal_clustering); | 129 &horizontal_clustering); |
130 | 130 |
131 if (vertical_density < horizontal_density) { | 131 if (vertical_density < horizontal_density) { |
132 *record_rects = horizontal_clustering; | 132 *record_rects = horizontal_clustering; |
133 return horizontal_density; | 133 return horizontal_density; |
134 } | 134 } |
135 | 135 |
136 *record_rects = vertical_clustering; | 136 *record_rects = vertical_clustering; |
137 return vertical_density; | 137 return vertical_density; |
138 } | 138 } |
139 | 139 |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 } | 304 } |
305 DCHECK(found_tile_for_recorded_picture); | 305 DCHECK(found_tile_for_recorded_picture); |
306 } | 306 } |
307 | 307 |
308 has_any_recordings_ = true; | 308 has_any_recordings_ = true; |
309 DCHECK(CanRasterSlowTileCheck(recorded_viewport_)); | 309 DCHECK(CanRasterSlowTileCheck(recorded_viewport_)); |
310 return true; | 310 return true; |
311 } | 311 } |
312 | 312 |
313 } // namespace cc | 313 } // namespace cc |
OLD | NEW |