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 |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 | 139 |
140 } // namespace | 140 } // namespace |
141 | 141 |
142 namespace cc { | 142 namespace cc { |
143 | 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::Update(ContentLayerClient* painter, |
150 ContentLayerClient* painter, | 150 SkColor background_color, |
151 Region* invalidation, | 151 bool contents_opaque, |
152 SkColor background_color, | 152 bool contents_fill_bounds_completely, |
153 bool contents_opaque, | 153 const Region& invalidation, |
154 bool contents_fill_bounds_completely, | 154 const gfx::Rect& visible_layer_rect, |
155 const gfx::Rect& visible_layer_rect, | 155 int frame_number, |
156 int frame_number, | 156 Picture::RecordingMode recording_mode, |
157 Picture::RecordingMode recording_mode, | 157 RenderingStatsInstrumentation* stats_instrumentation) { |
158 RenderingStatsInstrumentation* stats_instrumentation) { | |
159 background_color_ = background_color; | 158 background_color_ = background_color; |
160 contents_opaque_ = contents_opaque; | 159 contents_opaque_ = contents_opaque; |
161 contents_fill_bounds_completely_ = contents_fill_bounds_completely; | 160 contents_fill_bounds_completely_ = contents_fill_bounds_completely; |
162 | 161 |
163 gfx::Rect interest_rect = visible_layer_rect; | 162 gfx::Rect interest_rect = visible_layer_rect; |
164 interest_rect.Inset( | 163 interest_rect.Inset( |
165 -kPixelDistanceToRecord, | 164 -kPixelDistanceToRecord, |
166 -kPixelDistanceToRecord, | 165 -kPixelDistanceToRecord, |
167 -kPixelDistanceToRecord, | 166 -kPixelDistanceToRecord, |
168 -kPixelDistanceToRecord); | 167 -kPixelDistanceToRecord); |
169 recorded_viewport_ = interest_rect; | 168 recorded_viewport_ = interest_rect; |
170 recorded_viewport_.Intersect(tiling_rect()); | 169 recorded_viewport_.Intersect(tiling_rect()); |
171 | 170 |
172 gfx::Rect interest_rect_over_tiles = | |
173 tiling_.ExpandRectToTileBounds(interest_rect); | |
174 | |
175 bool invalidated = false; | 171 bool invalidated = false; |
176 for (Region::Iterator i(*invalidation); i.has_rect(); i.next()) { | 172 for (Region::Iterator i(invalidation); i.has_rect(); i.next()) { |
177 gfx::Rect invalid_rect = i.rect(); | 173 gfx::Rect invalidation = i.rect(); |
178 // Split this inflated invalidation across tile boundaries and apply it | 174 // Split this inflated invalidation across tile boundaries and apply it |
179 // to all tiles that it touches. | 175 // to all tiles that it touches. |
180 bool include_borders = true; | 176 bool include_borders = true; |
181 for (TilingData::Iterator iter(&tiling_, invalid_rect, include_borders); | 177 for (TilingData::Iterator iter(&tiling_, invalidation, include_borders); |
182 iter; | 178 iter; |
183 ++iter) { | 179 ++iter) { |
184 const PictureMapKey& key = iter.index(); | 180 const PictureMapKey& key = iter.index(); |
185 | 181 |
186 PictureMap::iterator picture_it = picture_map_.find(key); | 182 PictureMap::iterator picture_it = picture_map_.find(key); |
187 if (picture_it == picture_map_.end()) | 183 if (picture_it == picture_map_.end()) |
188 continue; | 184 continue; |
189 | 185 |
190 // Inform the grid cell that it has been invalidated in this frame. | 186 // Inform the grid cell that it has been invalidated in this frame. |
191 invalidated = picture_it->second.Invalidate(frame_number) || invalidated; | 187 invalidated = picture_it->second.Invalidate(frame_number) || invalidated; |
192 } | 188 } |
193 | |
194 // Expand invalidation that is outside tiles that intersect the interest | |
195 // rect. These tiles are no longer valid and should be considerered fully | |
196 // invalid, so we can know to not keep around raster tiles that intersect | |
197 // with these recording tiles. | |
198 gfx::Rect invalid_rect_outside_interest_rect_tiles = invalid_rect; | |
199 // TODO(danakj): We should have a Rect-subtract-Rect-to-2-rects operator | |
200 // instead of using Rect::Subtract which gives you the bounding box of the | |
201 // subtraction. | |
202 invalid_rect_outside_interest_rect_tiles.Subtract(interest_rect_over_tiles); | |
203 invalidation->Union(tiling_.ExpandRectToTileBounds( | |
204 invalid_rect_outside_interest_rect_tiles)); | |
205 } | 189 } |
206 | 190 |
207 // Make a list of all invalid tiles; we will attempt to | 191 // Make a list of all invalid tiles; we will attempt to |
208 // cluster these into multiple invalidation regions. | 192 // cluster these into multiple invalidation regions. |
209 std::vector<gfx::Rect> invalid_tiles; | 193 std::vector<gfx::Rect> invalid_tiles; |
210 bool include_borders = true; | 194 bool include_borders = true; |
211 for (TilingData::Iterator it(&tiling_, interest_rect, include_borders); it; | 195 for (TilingData::Iterator it(&tiling_, interest_rect, include_borders); it; |
212 ++it) { | 196 ++it) { |
213 const PictureMapKey& key = it.index(); | 197 const PictureMapKey& key = it.index(); |
214 PictureInfo& info = picture_map_[key]; | 198 PictureInfo& info = picture_map_[key]; |
215 | 199 |
216 gfx::Rect rect = PaddedRect(key); | 200 gfx::Rect rect = PaddedRect(key); |
217 int distance_to_visible = | 201 int distance_to_visible = |
218 rect.ManhattanInternalDistance(visible_layer_rect); | 202 rect.ManhattanInternalDistance(visible_layer_rect); |
219 | 203 |
220 if (info.NeedsRecording(frame_number, distance_to_visible)) { | 204 if (info.NeedsRecording(frame_number, distance_to_visible)) { |
221 gfx::Rect tile = tiling_.TileBounds(key.first, key.second); | 205 gfx::Rect tile = tiling_.TileBounds(key.first, key.second); |
222 invalid_tiles.push_back(tile); | 206 invalid_tiles.push_back(tile); |
223 } else if (!info.GetPicture()) { | 207 } else if (!info.GetPicture() && recorded_viewport_.Intersects(rect)) { |
224 if (recorded_viewport_.Intersects(rect)) { | 208 // Recorded viewport is just an optimization for a fully recorded |
225 // Recorded viewport is just an optimization for a fully recorded | 209 // interest rect. In this case, a tile in that rect has declined |
226 // interest rect. In this case, a tile in that rect has declined | 210 // to be recorded (probably due to frequent invalidations). |
227 // to be recorded (probably due to frequent invalidations). | 211 // TODO(enne): Shrink the recorded_viewport_ rather than clearing. |
228 // TODO(enne): Shrink the recorded_viewport_ rather than clearing. | 212 recorded_viewport_ = gfx::Rect(); |
229 recorded_viewport_ = gfx::Rect(); | |
230 } | |
231 | |
232 // If a tile in the interest rect is not recorded, the entire tile needs | |
233 // to be considered invalid, so that we know not to keep around raster | |
234 // tiles that intersect this recording tile. | |
235 invalidation->Union(tiling_.TileBounds(it.index_x(), it.index_y())); | |
236 } | 213 } |
237 } | 214 } |
238 | 215 |
239 std::vector<gfx::Rect> record_rects; | 216 std::vector<gfx::Rect> record_rects; |
240 ClusterTiles(invalid_tiles, &record_rects); | 217 ClusterTiles(invalid_tiles, &record_rects); |
241 | 218 |
242 if (record_rects.empty()) | 219 if (record_rects.empty()) |
243 return invalidated; | 220 return invalidated; |
244 | 221 |
245 for (std::vector<gfx::Rect>::iterator it = record_rects.begin(); | 222 for (std::vector<gfx::Rect>::iterator it = record_rects.begin(); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 } | 277 } |
301 DCHECK(found_tile_for_recorded_picture); | 278 DCHECK(found_tile_for_recorded_picture); |
302 } | 279 } |
303 | 280 |
304 has_any_recordings_ = true; | 281 has_any_recordings_ = true; |
305 DCHECK(CanRasterSlowTileCheck(recorded_viewport_)); | 282 DCHECK(CanRasterSlowTileCheck(recorded_viewport_)); |
306 return true; | 283 return true; |
307 } | 284 } |
308 | 285 |
309 } // namespace cc | 286 } // namespace cc |
OLD | NEW |