Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(174)

Side by Side Diff: cc/resources/picture_pile.cc

Issue 375403003: cc: Refactor in picture_pile.cc (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 cc {
enne (OOO) 2014/07/09 17:38:34 No need for this. These are all local to this fil
hyunki 2014/07/09 17:47:26 Done.
18
17 namespace { 19 namespace {
18 // Layout pixel buffer around the visible layer rect to record. Any base 20 // Layout pixel buffer around the visible layer rect to record. Any base
19 // picture that intersects the visible layer rect expanded by this distance 21 // picture that intersects the visible layer rect expanded by this distance
20 // will be recorded. 22 // will be recorded.
21 const int kPixelDistanceToRecord = 8000; 23 const int kPixelDistanceToRecord = 8000;
22 24
23 // TODO(humper): The density threshold here is somewhat arbitrary; need a 25 // 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 26 // way to set // this from the command line so we can write a benchmark
25 // script and find a sweet spot. 27 // script and find a sweet spot.
26 const float kDensityThreshold = 0.5f; 28 const float kDensityThreshold = 0.5f;
27 29
28 bool rect_sort_y(const gfx::Rect &r1, const gfx::Rect &r2) { 30 bool SortRectY(const gfx::Rect& r1, const gfx::Rect& r2) {
enne (OOO) 2014/07/09 17:38:34 This name is also correct. No need to rename it.
hyunki 2014/07/09 17:47:26 Done.
29 return r1.y() < r2.y() || (r1.y() == r2.y() && r1.x() < r2.x()); 31 return r1.y() < r2.y() || (r1.y() == r2.y() && r1.x() < r2.x());
30 } 32 }
31 33
32 bool rect_sort_x(const gfx::Rect &r1, const gfx::Rect &r2) { 34 bool SortRectX(const gfx::Rect& r1, const gfx::Rect& r2) {
33 return r1.x() < r2.x() || (r1.x() == r2.x() && r1.y() < r2.y()); 35 return r1.x() < r2.x() || (r1.x() == r2.x() && r1.y() < r2.y());
34 } 36 }
35 37
36 float do_clustering(const std::vector<gfx::Rect>& tiles, 38 float PerformClustering(const std::vector<gfx::Rect>& tiles,
37 std::vector<gfx::Rect>* clustered_rects) { 39 std::vector<gfx::Rect>* clustered_rects) {
38 // These variables track the record area and invalid area 40 // These variables track the record area and invalid area
39 // for the entire clustering 41 // for the entire clustering
40 int total_record_area = 0; 42 int total_record_area = 0;
41 int total_invalid_area = 0; 43 int total_invalid_area = 0;
42 44
43 // These variables track the record area and invalid area 45 // These variables track the record area and invalid area
44 // for the current cluster being constructed. 46 // for the current cluster being constructed.
45 gfx::Rect cur_record_rect; 47 gfx::Rect cur_record_rect;
46 int cluster_record_area = 0, cluster_invalid_area = 0; 48 int cluster_record_area = 0, cluster_invalid_area = 0;
47 49
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 } 84 }
83 85
84 DCHECK(!cur_record_rect.IsEmpty()); 86 DCHECK(!cur_record_rect.IsEmpty());
85 clustered_rects->push_back(cur_record_rect); 87 clustered_rects->push_back(cur_record_rect);
86 total_record_area += cluster_record_area;; 88 total_record_area += cluster_record_area;;
87 89
88 DCHECK_NE(total_record_area, 0); 90 DCHECK_NE(total_record_area, 0);
89 91
90 return static_cast<float>(total_invalid_area) / 92 return static_cast<float>(total_invalid_area) /
91 static_cast<float>(total_record_area); 93 static_cast<float>(total_record_area);
92 } 94 }
93 95
94 float ClusterTiles(const std::vector<gfx::Rect>& invalid_tiles, 96 float ClusterTiles(const std::vector<gfx::Rect>& invalid_tiles,
95 std::vector<gfx::Rect>* record_rects) { 97 std::vector<gfx::Rect>* record_rects) {
96 TRACE_EVENT1("cc", "ClusterTiles", 98 TRACE_EVENT1("cc", "ClusterTiles",
97 "count", 99 "count",
98 invalid_tiles.size()); 100 invalid_tiles.size());
99 101
100 if (invalid_tiles.size() <= 1) { 102 if (invalid_tiles.size() <= 1) {
101 // Quickly handle the special case for common 103 // Quickly handle the special case for common
102 // single-invalidation update, and also the less common 104 // single-invalidation update, and also the less common
103 // case of no tiles passed in. 105 // case of no tiles passed in.
104 *record_rects = invalid_tiles; 106 *record_rects = invalid_tiles;
105 return 1; 107 return 1;
106 } 108 }
107 109
108 // Sort the invalid tiles by y coordinate. 110 // Sort the invalid tiles by y coordinate.
109 std::vector<gfx::Rect> invalid_tiles_vertical = invalid_tiles; 111 std::vector<gfx::Rect> invalid_tiles_vertical = invalid_tiles;
110 std::sort(invalid_tiles_vertical.begin(), 112 std::sort(invalid_tiles_vertical.begin(),
111 invalid_tiles_vertical.end(), 113 invalid_tiles_vertical.end(),
112 rect_sort_y); 114 SortRectY);
113 115
114 float vertical_density; 116 float vertical_density;
115 std::vector<gfx::Rect> vertical_clustering; 117 std::vector<gfx::Rect> vertical_clustering;
116 vertical_density = do_clustering(invalid_tiles_vertical, 118 vertical_density = PerformClustering(invalid_tiles_vertical,
117 &vertical_clustering); 119 &vertical_clustering);
118 120
119 // Now try again with a horizontal sort, see which one is best 121 // Now try again with a horizontal sort, see which one is best
120 // TODO(humper): Heuristics for skipping this step? 122 // TODO(humper): Heuristics for skipping this step?
121 std::vector<gfx::Rect> invalid_tiles_horizontal = invalid_tiles; 123 std::vector<gfx::Rect> invalid_tiles_horizontal = invalid_tiles;
122 std::sort(invalid_tiles_vertical.begin(), 124 std::sort(invalid_tiles_vertical.begin(),
123 invalid_tiles_vertical.end(), 125 invalid_tiles_vertical.end(),
124 rect_sort_x); 126 SortRectX);
125 127
126 float horizontal_density; 128 float horizontal_density;
127 std::vector<gfx::Rect> horizontal_clustering; 129 std::vector<gfx::Rect> horizontal_clustering;
128 horizontal_density = do_clustering(invalid_tiles_vertical, 130 horizontal_density = PerformClustering(invalid_tiles_vertical,
129 &horizontal_clustering); 131 &horizontal_clustering);
130 132
131 if (vertical_density < horizontal_density) { 133 if (vertical_density < horizontal_density) {
132 *record_rects = horizontal_clustering; 134 *record_rects = horizontal_clustering;
133 return horizontal_density; 135 return horizontal_density;
134 } 136 }
135 137
136 *record_rects = vertical_clustering; 138 *record_rects = vertical_clustering;
137 return vertical_density; 139 return vertical_density;
138 } 140 }
139 141
140 } // namespace 142 } // namespace
141 143
142 namespace cc {
143
144 PicturePile::PicturePile() : is_suitable_for_gpu_rasterization_(true) {} 144 PicturePile::PicturePile() : is_suitable_for_gpu_rasterization_(true) {}
145 145
146 PicturePile::~PicturePile() { 146 PicturePile::~PicturePile() {
147 } 147 }
148 148
149 bool PicturePile::UpdateAndExpandInvalidation( 149 bool PicturePile::UpdateAndExpandInvalidation(
150 ContentLayerClient* painter, 150 ContentLayerClient* painter,
151 Region* invalidation, 151 Region* invalidation,
152 SkColor background_color, 152 SkColor background_color,
153 bool contents_opaque, 153 bool contents_opaque,
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698