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