Chromium Code Reviews| 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_layer_tiling.h" | 5 #include "cc/resources/picture_layer_tiling.h" | 
| 6 | 6 | 
| 7 #include <algorithm> | 7 #include <algorithm> | 
| 8 #include <cmath> | 8 #include <cmath> | 
| 9 #include <limits> | 9 #include <limits> | 
| 10 | 10 | 
| 11 #include "base/debug/trace_event.h" | 11 #include "base/debug/trace_event.h" | 
| 12 #include "cc/base/math_util.h" | 12 #include "cc/base/math_util.h" | 
| 13 #include "ui/gfx/point_conversions.h" | 13 #include "ui/gfx/point_conversions.h" | 
| 14 #include "ui/gfx/rect_conversions.h" | 14 #include "ui/gfx/rect_conversions.h" | 
| 15 #include "ui/gfx/safe_integer_conversions.h" | 15 #include "ui/gfx/safe_integer_conversions.h" | 
| 16 #include "ui/gfx/size_conversions.h" | 16 #include "ui/gfx/size_conversions.h" | 
| 17 | 17 | 
| 18 namespace cc { | 18 namespace cc { | 
| 19 | 19 | 
| 20 namespace { | |
| 21 | |
| 22 const int kTileBundleWidth = 2; | |
| 23 const int kTileBundleHeight = 2; | |
| 24 | |
| 25 std::pair<int, int> ComputeTileBundleIndex(int i, int j) { | |
| 26 return std::make_pair(i / kTileBundleWidth, j / kTileBundleHeight); | |
| 27 } | |
| 28 | |
| 29 } | |
| 30 | |
| 20 scoped_ptr<PictureLayerTiling> PictureLayerTiling::Create( | 31 scoped_ptr<PictureLayerTiling> PictureLayerTiling::Create( | 
| 21 float contents_scale, | 32 float contents_scale, | 
| 22 gfx::Size layer_bounds, | 33 gfx::Size layer_bounds, | 
| 23 PictureLayerTilingClient* client) { | 34 PictureLayerTilingClient* client) { | 
| 24 return make_scoped_ptr(new PictureLayerTiling(contents_scale, | 35 return make_scoped_ptr(new PictureLayerTiling(contents_scale, | 
| 25 layer_bounds, | 36 layer_bounds, | 
| 26 client)); | 37 client)); | 
| 27 } | 38 } | 
| 28 | 39 | 
| 29 PictureLayerTiling::PictureLayerTiling(float contents_scale, | 40 PictureLayerTiling::PictureLayerTiling(float contents_scale, | 
| 30 gfx::Size layer_bounds, | 41 gfx::Size layer_bounds, | 
| 31 PictureLayerTilingClient* client) | 42 PictureLayerTilingClient* client) | 
| 32 : contents_scale_(contents_scale), | 43 : contents_scale_(contents_scale), | 
| 33 layer_bounds_(layer_bounds), | 44 layer_bounds_(layer_bounds), | 
| 34 resolution_(NON_IDEAL_RESOLUTION), | 45 resolution_(NON_IDEAL_RESOLUTION), | 
| 35 client_(client), | 46 client_(client), | 
| 36 tiling_data_(gfx::Size(), gfx::Size(), true), | 47 tiling_data_(gfx::Size(), gfx::Size(), true), | 
| 48 bundle_tiling_data_(gfx::Size(), gfx::Size(), true), | |
| 37 last_impl_frame_time_in_seconds_(0.0) { | 49 last_impl_frame_time_in_seconds_(0.0) { | 
| 38 gfx::Size content_bounds = | 50 gfx::Size content_bounds = | 
| 39 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds, contents_scale)); | 51 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds, contents_scale)); | 
| 40 gfx::Size tile_size = client_->CalculateTileSize(content_bounds); | 52 gfx::Size tile_size = client_->CalculateTileSize(content_bounds); | 
| 41 | 53 | 
| 42 DCHECK(!gfx::ToFlooredSize( | 54 DCHECK(!gfx::ToFlooredSize( | 
| 43 gfx::ScaleSize(layer_bounds, contents_scale)).IsEmpty()) << | 55 gfx::ScaleSize(layer_bounds, contents_scale)).IsEmpty()) << | 
| 44 "Tiling created with scale too small as contents become empty." << | 56 "Tiling created with scale too small as contents become empty." << | 
| 45 " Layer bounds: " << layer_bounds.ToString() << | 57 " Layer bounds: " << layer_bounds.ToString() << | 
| 46 " Contents scale: " << contents_scale; | 58 " Contents scale: " << contents_scale; | 
| 47 | 59 | 
| 48 tiling_data_.SetTotalSize(content_bounds); | 60 tiling_data_.SetTotalSize(content_bounds); | 
| 49 tiling_data_.SetMaxTextureSize(tile_size); | 61 tiling_data_.SetMaxTextureSize(tile_size); | 
| 62 bundle_tiling_data_.SetTotalSize(content_bounds); | |
| 63 bundle_tiling_data_.SetMaxTextureSize( | |
| 64 gfx::Size(tile_size.width() * kTileBundleWidth, | |
| 65 tile_size.height() * kTileBundleHeight)); | |
| 50 } | 66 } | 
| 51 | 67 | 
| 52 PictureLayerTiling::~PictureLayerTiling() { | 68 PictureLayerTiling::~PictureLayerTiling() { | 
| 53 } | 69 } | 
| 54 | 70 | 
| 55 void PictureLayerTiling::SetClient(PictureLayerTilingClient* client) { | 71 void PictureLayerTiling::SetClient(PictureLayerTilingClient* client) { | 
| 56 client_ = client; | 72 client_ = client; | 
| 57 } | 73 } | 
| 58 | 74 | 
| 59 gfx::Rect PictureLayerTiling::ContentRect() const { | 75 gfx::Rect PictureLayerTiling::ContentRect() const { | 
| 60 return gfx::Rect(tiling_data_.total_size()); | 76 return gfx::Rect(tiling_data_.total_size()); | 
| 61 } | 77 } | 
| 62 | 78 | 
| 63 gfx::SizeF PictureLayerTiling::ContentSizeF() const { | 79 gfx::SizeF PictureLayerTiling::ContentSizeF() const { | 
| 64 return gfx::ScaleSize(layer_bounds_, contents_scale_); | 80 return gfx::ScaleSize(layer_bounds_, contents_scale_); | 
| 65 } | 81 } | 
| 66 | 82 | 
| 67 Tile* PictureLayerTiling::TileAt(int i, int j) const { | 83 TileBundle* PictureLayerTiling::CreateBundleForTileAt( | 
| 68 TileMap::const_iterator iter = tiles_.find(TileMapKey(i, j)); | 84 int i, | 
| 69 if (iter == tiles_.end()) | 85 int j, | 
| 70 return NULL; | 86 const PictureLayerTiling* twin_tiling) { | 
| 71 return iter->second.get(); | 87 TileBundleMapKey key = ComputeTileBundleIndex(i, j); | 
| 88 DCHECK(tile_bundles_.find(key) == tile_bundles_.end()); | |
| 89 | |
| 90 scoped_refptr<TileBundle> candidate_bundle = NULL; | |
| 91 | |
| 92 // Always try to get the twin bundle first. TileBundles are always shared | |
| 93 // between trees. | |
| 94 if (twin_tiling && | |
| 95 tiling_data_.max_texture_size() == | |
| 96 twin_tiling->tiling_data_.max_texture_size()) { | |
| 97 candidate_bundle = twin_tiling->TileBundleAt(key.first, key.second); | |
| 98 } | |
| 99 | |
| 100 // If we couldn't get a tile bundle, create a new one. | |
| 101 if (!candidate_bundle) { | |
| 102 candidate_bundle = | |
| 103 client_->CreateTileBundle(kTileBundleWidth, | |
| 104 kTileBundleHeight, | |
| 105 key.first * kTileBundleWidth, | |
| 106 key.second * kTileBundleHeight); | |
| 107 } | |
| 108 tile_bundles_[key] = candidate_bundle; | |
| 109 return candidate_bundle.get(); | |
| 72 } | 110 } | 
| 73 | 111 | 
| 74 void PictureLayerTiling::CreateTile(int i, | 112 TileBundle* PictureLayerTiling::TileBundleContainingTileAt(int i, int j) const { | 
| 113 TileBundleMapKey key = ComputeTileBundleIndex(i, j); | |
| 114 return TileBundleAt(key.first, key.second); | |
| 115 } | |
| 116 | |
| 117 TileBundle* PictureLayerTiling::TileBundleAt(int i, int j) const { | |
| 118 TileBundleMapKey key(i, j); | |
| 119 TileBundleMap::const_iterator it = tile_bundles_.find(key); | |
| 120 if (it == tile_bundles_.end()) | |
| 121 return NULL; | |
| 122 return it->second.get(); | |
| 123 } | |
| 124 | |
| 125 Tile* PictureLayerTiling::TileAt(WhichTree tree, int i, int j) const { | |
| 126 TileBundle* bundle = TileBundleContainingTileAt(i, j); | |
| 127 if (!bundle) | |
| 128 return NULL; | |
| 129 return bundle->TileAt(tree, i, j); | |
| 130 } | |
| 131 | |
| 132 void PictureLayerTiling::CreateTile(WhichTree tree, | |
| 133 int i, | |
| 75 int j, | 134 int j, | 
| 76 const PictureLayerTiling* twin_tiling) { | 135 const PictureLayerTiling* twin_tiling) { | 
| 77 TileMapKey key(i, j); | 136 TileBundle* bundle = TileBundleContainingTileAt(i, j); | 
| 78 DCHECK(tiles_.find(key) == tiles_.end()); | 137 if (!bundle) | 
| 138 bundle = CreateBundleForTileAt(i, j, twin_tiling); | |
| 79 | 139 | 
| 80 gfx::Rect paint_rect = tiling_data_.TileBoundsWithBorder(i, j); | 140 gfx::Rect paint_rect = tiling_data_.TileBoundsWithBorder(i, j); | 
| 81 gfx::Rect tile_rect = paint_rect; | 141 gfx::Rect tile_rect = paint_rect; | 
| 82 tile_rect.set_size(tiling_data_.max_texture_size()); | 142 tile_rect.set_size(tiling_data_.max_texture_size()); | 
| 83 | 143 | 
| 84 // Check our twin for a valid tile. | 144 // Check our twin for a valid tile. | 
| 85 if (twin_tiling && | 145 WhichTree twin_tree = (tree == ACTIVE_TREE) ? PENDING_TREE : ACTIVE_TREE; | 
| 86 tiling_data_.max_texture_size() == | 146 if (Tile* candidate_tile = bundle->TileAt(twin_tree, i, j)) { | 
| 87 twin_tiling->tiling_data_.max_texture_size()) { | 147 gfx::Rect rect = | 
| 88 if (Tile* candidate_tile = twin_tiling->TileAt(i, j)) { | 148 gfx::ScaleToEnclosingRect(paint_rect, 1.0f / contents_scale_); | 
| 89 gfx::Rect rect = | 149 if (!client_->GetInvalidation()->Intersects(rect)) { | 
| 90 gfx::ScaleToEnclosingRect(paint_rect, 1.0f / contents_scale_); | 150 bundle->AddTileAt(tree, i, j, candidate_tile); | 
| 91 if (!client_->GetInvalidation()->Intersects(rect)) { | 151 return; | 
| 92 tiles_[key] = candidate_tile; | |
| 93 return; | |
| 94 } | |
| 95 } | 152 } | 
| 96 } | 153 } | 
| 97 | 154 | 
| 98 // Create a new tile because our twin didn't have a valid one. | 155 // Create a new tile because our twin didn't have a valid one. | 
| 99 scoped_refptr<Tile> tile = client_->CreateTile(this, tile_rect); | 156 scoped_refptr<Tile> tile = client_->CreateTile(this, tile_rect); | 
| 100 if (tile.get()) | 157 if (tile.get()) | 
| 101 tiles_[key] = tile; | 158 bundle->AddTileAt(tree, i, j, tile); | 
| 159 } | |
| 160 | |
| 161 bool PictureLayerTiling::RemoveTile(WhichTree tree, int i, int j) { | |
| 162 TileBundleMapKey key = ComputeTileBundleIndex(i, j); | |
| 163 TileBundleMap::iterator it = tile_bundles_.find(key); | |
| 164 if (it == tile_bundles_.end()) | |
| 165 return false; | |
| 166 | |
| 167 return it->second->RemoveTileAt(tree, i, j); | |
| 168 } | |
| 169 | |
| 170 void PictureLayerTiling::RemoveBundleIfEmptyContainingTileAt(int i, int j) { | |
| 171 TileBundleMapKey key = ComputeTileBundleIndex(i, j); | |
| 172 TileBundleMap::iterator it = tile_bundles_.find(key); | |
| 173 if (it == tile_bundles_.end()) | |
| 174 return; | |
| 175 | |
| 176 if (it->second->IsEmpty()) | |
| 177 tile_bundles_.erase(it); | |
| 102 } | 178 } | 
| 103 | 179 | 
| 104 Region PictureLayerTiling::OpaqueRegionInContentRect( | 180 Region PictureLayerTiling::OpaqueRegionInContentRect( | 
| 105 gfx::Rect content_rect) const { | 181 gfx::Rect content_rect) const { | 
| 106 Region opaque_region; | 182 Region opaque_region; | 
| 107 // TODO(enne): implement me | 183 // TODO(enne): implement me | 
| 108 return opaque_region; | 184 return opaque_region; | 
| 109 } | 185 } | 
| 110 | 186 | 
| 111 void PictureLayerTiling::SetCanUseLCDText(bool can_use_lcd_text) { | 187 void PictureLayerTiling::SetCanUseLCDText(bool can_use_lcd_text) { | 
| 112 for (TileMap::iterator it = tiles_.begin(); it != tiles_.end(); ++it) | 188 // TODO(vmpstr): This can be done per bundle with results used | 
| 113 it->second->set_can_use_lcd_text(can_use_lcd_text); | 189 // in tile manager. | 
| 190 for (TileBundleMap::iterator it = tile_bundles_.begin(); | |
| 191 it != tile_bundles_.end(); | |
| 192 ++it) { | |
| 193 for (TileBundle::Iterator tile_it(it->second); tile_it; ++tile_it) | |
| 194 tile_it->set_can_use_lcd_text(can_use_lcd_text); | |
| 195 } | |
| 114 } | 196 } | 
| 115 | 197 | 
| 116 void PictureLayerTiling::CreateMissingTilesInLiveTilesRect() { | 198 void PictureLayerTiling::CreateMissingTilesInLiveTilesRect() { | 
| 199 DCHECK(client_->IsPending()); | |
| 200 | |
| 117 const PictureLayerTiling* twin_tiling = client_->GetTwinTiling(this); | 201 const PictureLayerTiling* twin_tiling = client_->GetTwinTiling(this); | 
| 118 for (TilingData::Iterator iter(&tiling_data_, live_tiles_rect_); iter; | 202 for (TilingData::Iterator iter(&tiling_data_, live_tiles_rect_); iter; | 
| 119 ++iter) { | 203 ++iter) { | 
| 120 TileMapKey key = iter.index(); | 204 int tile_x = iter.index_x(); | 
| 121 TileMap::iterator find = tiles_.find(key); | 205 int tile_y = iter.index_y(); | 
| 122 if (find != tiles_.end()) | 206 Tile* tile = TileAt(PENDING_TREE, tile_x, tile_y); | 
| 207 if (tile) | |
| 123 continue; | 208 continue; | 
| 124 CreateTile(key.first, key.second, twin_tiling); | 209 CreateTile(PENDING_TREE, tile_x, tile_y, twin_tiling); | 
| 125 } | 210 } | 
| 126 } | 211 } | 
| 127 | 212 | 
| 128 void PictureLayerTiling::SetLayerBounds(gfx::Size layer_bounds) { | 213 void PictureLayerTiling::SetLayerBounds(gfx::Size layer_bounds) { | 
| 129 if (layer_bounds_ == layer_bounds) | 214 if (layer_bounds_ == layer_bounds) | 
| 130 return; | 215 return; | 
| 131 | 216 | 
| 217 DCHECK(client_->IsPending()); | |
| 132 DCHECK(!layer_bounds.IsEmpty()); | 218 DCHECK(!layer_bounds.IsEmpty()); | 
| 133 | 219 | 
| 134 gfx::Size old_layer_bounds = layer_bounds_; | 220 gfx::Size old_layer_bounds = layer_bounds_; | 
| 135 layer_bounds_ = layer_bounds; | 221 layer_bounds_ = layer_bounds; | 
| 136 gfx::Size old_content_bounds = tiling_data_.total_size(); | 222 gfx::Size old_content_bounds = tiling_data_.total_size(); | 
| 137 gfx::Size content_bounds = | 223 gfx::Size content_bounds = | 
| 138 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds_, contents_scale_)); | 224 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds_, contents_scale_)); | 
| 139 | 225 | 
| 140 gfx::Size tile_size = client_->CalculateTileSize(content_bounds); | 226 gfx::Size tile_size = client_->CalculateTileSize(content_bounds); | 
| 141 if (tile_size != tiling_data_.max_texture_size()) { | 227 if (tile_size != tiling_data_.max_texture_size()) { | 
| 142 tiling_data_.SetTotalSize(content_bounds); | 228 tiling_data_.SetTotalSize(content_bounds); | 
| 143 tiling_data_.SetMaxTextureSize(tile_size); | 229 tiling_data_.SetMaxTextureSize(tile_size); | 
| 230 bundle_tiling_data_.SetTotalSize(content_bounds); | |
| 231 bundle_tiling_data_.SetMaxTextureSize( | |
| 232 gfx::Size(tile_size.width() * kTileBundleWidth, | |
| 233 tile_size.height() * kTileBundleHeight)); | |
| 144 Reset(); | 234 Reset(); | 
| 145 return; | 235 return; | 
| 146 } | 236 } | 
| 147 | 237 | 
| 148 // Any tiles outside our new bounds are invalid and should be dropped. | 238 // Any tiles outside our new bounds are invalid and should be dropped. | 
| 149 gfx::Rect bounded_live_tiles_rect(live_tiles_rect_); | 239 gfx::Rect bounded_live_tiles_rect(live_tiles_rect_); | 
| 150 bounded_live_tiles_rect.Intersect(gfx::Rect(content_bounds)); | 240 bounded_live_tiles_rect.Intersect(gfx::Rect(content_bounds)); | 
| 151 SetLiveTilesRect(bounded_live_tiles_rect); | 241 SetLiveTilesRect(PENDING_TREE, bounded_live_tiles_rect); | 
| 152 tiling_data_.SetTotalSize(content_bounds); | 242 tiling_data_.SetTotalSize(content_bounds); | 
| 243 bundle_tiling_data_.SetTotalSize(content_bounds); | |
| 153 | 244 | 
| 154 // Create tiles for newly exposed areas. | 245 // Create tiles for newly exposed areas. | 
| 155 Region layer_region((gfx::Rect(layer_bounds_))); | 246 Region layer_region((gfx::Rect(layer_bounds_))); | 
| 156 layer_region.Subtract(gfx::Rect(old_layer_bounds)); | 247 layer_region.Subtract(gfx::Rect(old_layer_bounds)); | 
| 157 Invalidate(layer_region); | 248 Invalidate(layer_region); | 
| 158 } | 249 } | 
| 159 | 250 | 
| 160 void PictureLayerTiling::Invalidate(const Region& layer_region) { | 251 void PictureLayerTiling::Invalidate(const Region& layer_region) { | 
| 161 std::vector<TileMapKey> new_tile_keys; | 252 DCHECK(client_->IsPending()); | 
| 253 | |
| 254 std::vector<std::pair<int, int> > new_tile_keys; | |
| 162 for (Region::Iterator iter(layer_region); iter.has_rect(); iter.next()) { | 255 for (Region::Iterator iter(layer_region); iter.has_rect(); iter.next()) { | 
| 163 gfx::Rect layer_rect = iter.rect(); | 256 gfx::Rect layer_rect = iter.rect(); | 
| 164 gfx::Rect content_rect = | 257 gfx::Rect content_rect = | 
| 165 gfx::ScaleToEnclosingRect(layer_rect, contents_scale_); | 258 gfx::ScaleToEnclosingRect(layer_rect, contents_scale_); | 
| 166 content_rect.Intersect(live_tiles_rect_); | 259 content_rect.Intersect(live_tiles_rect_); | 
| 167 if (content_rect.IsEmpty()) | 260 if (content_rect.IsEmpty()) | 
| 168 continue; | 261 continue; | 
| 169 for (TilingData::Iterator iter(&tiling_data_, content_rect); iter; ++iter) { | 262 for (TilingData::Iterator iter(&tiling_data_, content_rect); iter; ++iter) { | 
| 170 TileMapKey key(iter.index()); | 263 int tile_x = iter.index_x(); | 
| 171 TileMap::iterator find = tiles_.find(key); | 264 int tile_y = iter.index_y(); | 
| 172 if (find == tiles_.end()) | 265 | 
| 173 continue; | 266 // If there is no bundle for the given tile, we can skip. | 
| 174 tiles_.erase(find); | 267 bool deleted = RemoveTile(PENDING_TREE, tile_x, tile_y); | 
| 175 new_tile_keys.push_back(key); | 268 if (deleted) | 
| 269 new_tile_keys.push_back(std::make_pair(tile_x, tile_y)); | |
| 176 } | 270 } | 
| 177 } | 271 } | 
| 178 | 272 | 
| 179 const PictureLayerTiling* twin_tiling = client_->GetTwinTiling(this); | 273 const PictureLayerTiling* twin_tiling = client_->GetTwinTiling(this); | 
| 180 for (size_t i = 0; i < new_tile_keys.size(); ++i) | 274 for (size_t i = 0; i < new_tile_keys.size(); ++i) { | 
| 181 CreateTile(new_tile_keys[i].first, new_tile_keys[i].second, twin_tiling); | 275 CreateTile(PENDING_TREE, | 
| 276 new_tile_keys[i].first, | |
| 277 new_tile_keys[i].second, | |
| 278 twin_tiling); | |
| 279 } | |
| 182 } | 280 } | 
| 183 | 281 | 
| 184 PictureLayerTiling::CoverageIterator::CoverageIterator() | 282 PictureLayerTiling::CoverageIterator::CoverageIterator() | 
| 185 : tiling_(NULL), | 283 : tiling_(NULL), | 
| 186 current_tile_(NULL), | 284 current_tile_(NULL), | 
| 187 tile_i_(0), | 285 tile_i_(0), | 
| 188 tile_j_(0), | 286 tile_j_(0), | 
| 189 left_(0), | 287 left_(0), | 
| 190 top_(0), | 288 top_(0), | 
| 191 right_(-1), | 289 right_(-1), | 
| 192 bottom_(-1) { | 290 bottom_(-1) { | 
| 193 } | 291 } | 
| 194 | 292 | 
| 195 PictureLayerTiling::CoverageIterator::CoverageIterator( | 293 PictureLayerTiling::CoverageIterator::CoverageIterator( | 
| 196 const PictureLayerTiling* tiling, | 294 const PictureLayerTiling* tiling, | 
| 197 float dest_scale, | 295 float dest_scale, | 
| 198 gfx::Rect dest_rect) | 296 gfx::Rect dest_rect) | 
| 199 : tiling_(tiling), | 297 : tiling_(tiling), | 
| 200 dest_rect_(dest_rect), | 298 dest_rect_(dest_rect), | 
| 201 dest_to_content_scale_(0), | 299 dest_to_content_scale_(0), | 
| 202 current_tile_(NULL), | 300 current_tile_(NULL), | 
| 203 tile_i_(0), | 301 tile_i_(0), | 
| 204 tile_j_(0), | 302 tile_j_(0), | 
| 205 left_(0), | 303 left_(0), | 
| 206 top_(0), | 304 top_(0), | 
| 207 right_(-1), | 305 right_(-1), | 
| 208 bottom_(-1) { | 306 bottom_(-1), | 
| 307 tree_(tiling->client_->IsActive() ? ACTIVE_TREE : PENDING_TREE) { | |
| 209 DCHECK(tiling_); | 308 DCHECK(tiling_); | 
| 210 if (dest_rect_.IsEmpty()) | 309 if (dest_rect_.IsEmpty()) | 
| 211 return; | 310 return; | 
| 212 | 311 | 
| 213 dest_to_content_scale_ = tiling_->contents_scale_ / dest_scale; | 312 dest_to_content_scale_ = tiling_->contents_scale_ / dest_scale; | 
| 214 // This is the maximum size that the dest rect can be, given the content size. | 313 // This is the maximum size that the dest rect can be, given the content size. | 
| 215 gfx::Size dest_content_size = gfx::ToCeiledSize(gfx::ScaleSize( | 314 gfx::Size dest_content_size = gfx::ToCeiledSize(gfx::ScaleSize( | 
| 216 tiling_->ContentRect().size(), | 315 tiling_->ContentRect().size(), | 
| 217 1 / dest_to_content_scale_, | 316 1 / dest_to_content_scale_, | 
| 218 1 / dest_to_content_scale_)); | 317 1 / dest_to_content_scale_)); | 
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 253 if (tile_i_ > right_) { | 352 if (tile_i_ > right_) { | 
| 254 tile_i_ = left_; | 353 tile_i_ = left_; | 
| 255 tile_j_++; | 354 tile_j_++; | 
| 256 new_row = true; | 355 new_row = true; | 
| 257 if (tile_j_ > bottom_) { | 356 if (tile_j_ > bottom_) { | 
| 258 current_tile_ = NULL; | 357 current_tile_ = NULL; | 
| 259 return *this; | 358 return *this; | 
| 260 } | 359 } | 
| 261 } | 360 } | 
| 262 | 361 | 
| 263 current_tile_ = tiling_->TileAt(tile_i_, tile_j_); | 362 current_tile_ = tiling_->TileAt(tree_, tile_i_, tile_j_); | 
| 264 | 363 | 
| 265 // Calculate the current geometry rect. Due to floating point rounding | 364 // Calculate the current geometry rect. Due to floating point rounding | 
| 266 // and ToEnclosingRect, tiles might overlap in destination space on the | 365 // and ToEnclosingRect, tiles might overlap in destination space on the | 
| 267 // edges. | 366 // edges. | 
| 268 gfx::Rect last_geometry_rect = current_geometry_rect_; | 367 gfx::Rect last_geometry_rect = current_geometry_rect_; | 
| 269 | 368 | 
| 270 gfx::Rect content_rect = tiling_->tiling_data_.TileBounds(tile_i_, tile_j_); | 369 gfx::Rect content_rect = tiling_->tiling_data_.TileBounds(tile_i_, tile_j_); | 
| 271 | 370 | 
| 272 current_geometry_rect_ = | 371 current_geometry_rect_ = | 
| 273 gfx::ScaleToEnclosingRect(content_rect, | 372 gfx::ScaleToEnclosingRect(content_rect, | 
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 309 return current_geometry_rect_; | 408 return current_geometry_rect_; | 
| 310 } | 409 } | 
| 311 | 410 | 
| 312 gfx::Rect | 411 gfx::Rect | 
| 313 PictureLayerTiling::CoverageIterator::full_tile_geometry_rect() const { | 412 PictureLayerTiling::CoverageIterator::full_tile_geometry_rect() const { | 
| 314 gfx::Rect rect = tiling_->tiling_data_.TileBoundsWithBorder(tile_i_, tile_j_); | 413 gfx::Rect rect = tiling_->tiling_data_.TileBoundsWithBorder(tile_i_, tile_j_); | 
| 315 rect.set_size(tiling_->tiling_data_.max_texture_size()); | 414 rect.set_size(tiling_->tiling_data_.max_texture_size()); | 
| 316 return rect; | 415 return rect; | 
| 317 } | 416 } | 
| 318 | 417 | 
| 418 TilePriority PictureLayerTiling::CoverageIterator::priority() { | |
| 419 TileBundle* bundle = tiling_->TileBundleContainingTileAt(tile_i_, tile_j_); | |
| 420 if (bundle) | |
| 421 return bundle->GetPriority(tree_); | |
| 422 return TilePriority(); | |
| 423 } | |
| 424 | |
| 425 void PictureLayerTiling::CoverageIterator::SetPriorityForTesting( | |
| 426 const TilePriority& priority) { | |
| 427 TileBundle* bundle = tiling_->TileBundleContainingTileAt(tile_i_, tile_j_); | |
| 428 bundle->SetPriority(tree_, priority); | |
| 429 } | |
| 430 | |
| 319 gfx::RectF PictureLayerTiling::CoverageIterator::texture_rect() const { | 431 gfx::RectF PictureLayerTiling::CoverageIterator::texture_rect() const { | 
| 320 gfx::PointF tex_origin = | 432 gfx::PointF tex_origin = | 
| 321 tiling_->tiling_data_.TileBoundsWithBorder(tile_i_, tile_j_).origin(); | 433 tiling_->tiling_data_.TileBoundsWithBorder(tile_i_, tile_j_).origin(); | 
| 322 | 434 | 
| 323 // Convert from dest space => content space => texture space. | 435 // Convert from dest space => content space => texture space. | 
| 324 gfx::RectF texture_rect(current_geometry_rect_); | 436 gfx::RectF texture_rect(current_geometry_rect_); | 
| 325 texture_rect.Scale(dest_to_content_scale_, | 437 texture_rect.Scale(dest_to_content_scale_, | 
| 326 dest_to_content_scale_); | 438 dest_to_content_scale_); | 
| 327 texture_rect.Offset(-tex_origin.OffsetFromOrigin()); | 439 texture_rect.Offset(-tex_origin.OffsetFromOrigin()); | 
| 328 texture_rect.Intersect(tiling_->ContentRect()); | 440 texture_rect.Intersect(tiling_->ContentRect()); | 
| 329 | 441 | 
| 330 return texture_rect; | 442 return texture_rect; | 
| 331 } | 443 } | 
| 332 | 444 | 
| 333 gfx::Size PictureLayerTiling::CoverageIterator::texture_size() const { | 445 gfx::Size PictureLayerTiling::CoverageIterator::texture_size() const { | 
| 334 return tiling_->tiling_data_.max_texture_size(); | 446 return tiling_->tiling_data_.max_texture_size(); | 
| 335 } | 447 } | 
| 336 | 448 | 
| 337 void PictureLayerTiling::Reset() { | 449 void PictureLayerTiling::Reset() { | 
| 338 live_tiles_rect_ = gfx::Rect(); | 450 live_tiles_rect_ = gfx::Rect(); | 
| 339 tiles_.clear(); | 451 tile_bundles_.clear(); | 
| 340 } | 452 } | 
| 341 | 453 | 
| 342 void PictureLayerTiling::UpdateTilePriorities( | 454 void PictureLayerTiling::UpdateTilePriorities( | 
| 343 WhichTree tree, | 455 WhichTree tree, | 
| 344 gfx::Size device_viewport, | 456 gfx::Size device_viewport, | 
| 345 gfx::Rect viewport_in_layer_space, | 457 gfx::Rect viewport_in_layer_space, | 
| 346 gfx::Rect visible_layer_rect, | 458 gfx::Rect visible_layer_rect, | 
| 347 gfx::Size last_layer_bounds, | 459 gfx::Size last_layer_bounds, | 
| 348 gfx::Size current_layer_bounds, | 460 gfx::Size current_layer_bounds, | 
| 349 float last_layer_contents_scale, | 461 float last_layer_contents_scale, | 
| (...skipping 25 matching lines...) Expand all Loading... | |
| 375 ? viewport_in_content_space | 487 ? viewport_in_content_space | 
| 376 : visible_content_rect; | 488 : visible_content_rect; | 
| 377 gfx::Rect interest_rect = ExpandRectEquallyToAreaBoundedBy( | 489 gfx::Rect interest_rect = ExpandRectEquallyToAreaBoundedBy( | 
| 378 starting_rect, | 490 starting_rect, | 
| 379 interest_rect_area, | 491 interest_rect_area, | 
| 380 ContentRect(), | 492 ContentRect(), | 
| 381 &expansion_cache_); | 493 &expansion_cache_); | 
| 382 DCHECK(interest_rect.IsEmpty() || | 494 DCHECK(interest_rect.IsEmpty() || | 
| 383 ContentRect().Contains(interest_rect)); | 495 ContentRect().Contains(interest_rect)); | 
| 384 | 496 | 
| 385 SetLiveTilesRect(interest_rect); | 497 SetLiveTilesRect(tree, interest_rect); | 
| 386 | 498 | 
| 387 double time_delta = 0; | 499 double time_delta = 0; | 
| 388 if (last_impl_frame_time_in_seconds_ != 0.0 && | 500 if (last_impl_frame_time_in_seconds_ != 0.0 && | 
| 389 last_layer_bounds == current_layer_bounds) { | 501 last_layer_bounds == current_layer_bounds) { | 
| 390 time_delta = | 502 time_delta = | 
| 391 current_frame_time_in_seconds - last_impl_frame_time_in_seconds_; | 503 current_frame_time_in_seconds - last_impl_frame_time_in_seconds_; | 
| 392 } | 504 } | 
| 393 | 505 | 
| 394 gfx::Rect view_rect(device_viewport); | 506 gfx::Rect view_rect(device_viewport); | 
| 395 float current_scale = current_layer_contents_scale / contents_scale_; | 507 float current_scale = current_layer_contents_scale / contents_scale_; | 
| 396 float last_scale = last_layer_contents_scale / contents_scale_; | 508 float last_scale = last_layer_contents_scale / contents_scale_; | 
| 397 | 509 | 
| 398 // Fast path tile priority calculation when both transforms are translations. | 510 // Fast path tile priority calculation when both transforms are translations. | 
| 399 if (last_screen_transform.IsApproximatelyIdentityOrTranslation( | 511 if (last_screen_transform.IsApproximatelyIdentityOrTranslation( | 
| 400 std::numeric_limits<float>::epsilon()) && | 512 std::numeric_limits<float>::epsilon()) && | 
| 401 current_screen_transform.IsApproximatelyIdentityOrTranslation( | 513 current_screen_transform.IsApproximatelyIdentityOrTranslation( | 
| 402 std::numeric_limits<float>::epsilon())) { | 514 std::numeric_limits<float>::epsilon())) { | 
| 403 gfx::Vector2dF current_offset( | 515 gfx::Vector2dF current_offset( | 
| 404 current_screen_transform.matrix().get(0, 3), | 516 current_screen_transform.matrix().get(0, 3), | 
| 405 current_screen_transform.matrix().get(1, 3)); | 517 current_screen_transform.matrix().get(1, 3)); | 
| 406 gfx::Vector2dF last_offset( | 518 gfx::Vector2dF last_offset( | 
| 407 last_screen_transform.matrix().get(0, 3), | 519 last_screen_transform.matrix().get(0, 3), | 
| 408 last_screen_transform.matrix().get(1, 3)); | 520 last_screen_transform.matrix().get(1, 3)); | 
| 409 | 521 | 
| 410 for (TilingData::Iterator iter(&tiling_data_, interest_rect); | 522 for (TilingData::Iterator iter(&bundle_tiling_data_, interest_rect); | 
| 411 iter; ++iter) { | 523 iter; ++iter) { | 
| 412 TileMap::iterator find = tiles_.find(iter.index()); | 524 int bundle_x = iter.index_x(); | 
| 413 if (find == tiles_.end()) | 525 int bundle_y = iter.index_y(); | 
| 526 TileBundle* bundle = TileBundleAt(bundle_x, bundle_y); | |
| 527 if (!bundle) | |
| 414 continue; | 528 continue; | 
| 415 Tile* tile = find->second.get(); | |
| 416 | 529 | 
| 417 gfx::Rect tile_bounds = | 530 gfx::Rect bundle_bounds = | 
| 418 tiling_data_.TileBounds(iter.index_x(), iter.index_y()); | 531 bundle_tiling_data_.TileBounds(bundle_x, bundle_y); | 
| 419 gfx::RectF current_screen_rect = gfx::ScaleRect( | 532 gfx::RectF current_screen_rect = | 
| 420 tile_bounds, | 533 gfx::ScaleRect(bundle_bounds, current_scale, current_scale) + | 
| 421 current_scale, | 534 current_offset; | 
| 422 current_scale) + current_offset; | 535 gfx::RectF last_screen_rect = | 
| 423 gfx::RectF last_screen_rect = gfx::ScaleRect( | 536 gfx::ScaleRect(bundle_bounds, last_scale, last_scale) + | 
| 424 tile_bounds, | 537 last_offset; | 
| 425 last_scale, | |
| 426 last_scale) + last_offset; | |
| 427 | 538 | 
| 428 float distance_to_visible_in_pixels = | 539 float distance_to_visible_in_pixels = | 
| 429 TilePriority::manhattanDistance(current_screen_rect, view_rect); | 540 TilePriority::manhattanDistance(current_screen_rect, view_rect); | 
| 430 | 541 | 
| 431 float time_to_visible_in_seconds = | 542 float time_to_visible_in_seconds = | 
| 432 TilePriority::TimeForBoundsToIntersect( | 543 TilePriority::TimeForBoundsToIntersect( | 
| 433 last_screen_rect, current_screen_rect, time_delta, view_rect); | 544 last_screen_rect, current_screen_rect, time_delta, view_rect); | 
| 434 TilePriority priority( | 545 TilePriority priority( | 
| 435 resolution_, | 546 resolution_, | 
| 436 time_to_visible_in_seconds, | 547 time_to_visible_in_seconds, | 
| 437 distance_to_visible_in_pixels); | 548 distance_to_visible_in_pixels); | 
| 438 tile->SetPriority(tree, priority); | 549 | 
| 550 bundle->SetPriority(tree, priority); | |
| 439 } | 551 } | 
| 440 } else if (!last_screen_transform.HasPerspective() && | 552 } else if (!last_screen_transform.HasPerspective() && | 
| 441 !current_screen_transform.HasPerspective()) { | 553 !current_screen_transform.HasPerspective()) { | 
| 442 // Secondary fast path that can be applied for any affine transforms. | 554 // Secondary fast path that can be applied for any affine transforms. | 
| 443 | 555 | 
| 444 // Initialize the necessary geometry in screen space, so that we can | 556 // Initialize the necessary geometry in screen space, so that we can | 
| 445 // iterate over tiles in screen space without needing a costly transform | 557 // iterate over tiles in screen space without needing a costly transform | 
| 446 // mapping for each tile. | 558 // mapping for each tile. | 
| 447 | 559 | 
| 448 // Apply screen space transform to the local origin point (0, 0); only the | 560 // Apply screen space transform to the local origin point (0, 0); only the | 
| 449 // translation component is needed and can be initialized directly. | 561 // translation component is needed and can be initialized directly. | 
| 450 gfx::Point current_screen_space_origin( | 562 gfx::Point current_screen_space_origin( | 
| 451 current_screen_transform.matrix().get(0, 3), | 563 current_screen_transform.matrix().get(0, 3), | 
| 452 current_screen_transform.matrix().get(1, 3)); | 564 current_screen_transform.matrix().get(1, 3)); | 
| 453 | 565 | 
| 454 gfx::Point last_screen_space_origin( | 566 gfx::Point last_screen_space_origin( | 
| 455 last_screen_transform.matrix().get(0, 3), | 567 last_screen_transform.matrix().get(0, 3), | 
| 456 last_screen_transform.matrix().get(1, 3)); | 568 last_screen_transform.matrix().get(1, 3)); | 
| 457 | 569 | 
| 458 float current_tile_width = tiling_data_.TileSizeX(0) * current_scale; | 570 float current_bundle_width = | 
| 459 float last_tile_width = tiling_data_.TileSizeX(0) * last_scale; | 571 bundle_tiling_data_.TileSizeX(0) * current_scale; | 
| 460 float current_tile_height = tiling_data_.TileSizeY(0) * current_scale; | 572 float last_bundle_width = | 
| 461 float last_tile_height = tiling_data_.TileSizeY(0) * last_scale; | 573 bundle_tiling_data_.TileSizeX(0) * last_scale; | 
| 574 float current_bundle_height = | |
| 575 bundle_tiling_data_.TileSizeY(0) * current_scale; | |
| 576 float last_bundle_height = | |
| 577 bundle_tiling_data_.TileSizeY(0) * last_scale; | |
| 462 | 578 | 
| 463 // Apply screen space transform to local basis vectors (tile_width, 0) and | 579 // Apply screen space transform to local basis vectors (tile_width, 0) and | 
| 464 // (0, tile_height); the math simplifies and can be initialized directly. | 580 // (0, tile_height); the math simplifies and can be initialized directly. | 
| 465 gfx::Vector2dF current_horizontal( | 581 gfx::Vector2dF current_horizontal( | 
| 466 current_screen_transform.matrix().get(0, 0) * current_tile_width, | 582 current_screen_transform.matrix().get(0, 0) * current_bundle_width, | 
| 467 current_screen_transform.matrix().get(1, 0) * current_tile_width); | 583 current_screen_transform.matrix().get(1, 0) * current_bundle_width); | 
| 468 gfx::Vector2dF current_vertical( | 584 gfx::Vector2dF current_vertical( | 
| 469 current_screen_transform.matrix().get(0, 1) * current_tile_height, | 585 current_screen_transform.matrix().get(0, 1) * current_bundle_height, | 
| 470 current_screen_transform.matrix().get(1, 1) * current_tile_height); | 586 current_screen_transform.matrix().get(1, 1) * current_bundle_height); | 
| 471 | 587 | 
| 472 gfx::Vector2dF last_horizontal( | 588 gfx::Vector2dF last_horizontal( | 
| 473 last_screen_transform.matrix().get(0, 0) * last_tile_width, | 589 last_screen_transform.matrix().get(0, 0) * last_bundle_width, | 
| 474 last_screen_transform.matrix().get(1, 0) * last_tile_width); | 590 last_screen_transform.matrix().get(1, 0) * last_bundle_width); | 
| 475 gfx::Vector2dF last_vertical( | 591 gfx::Vector2dF last_vertical( | 
| 476 last_screen_transform.matrix().get(0, 1) * last_tile_height, | 592 last_screen_transform.matrix().get(0, 1) * last_bundle_height, | 
| 477 last_screen_transform.matrix().get(1, 1) * last_tile_height); | 593 last_screen_transform.matrix().get(1, 1) * last_bundle_height); | 
| 478 | 594 | 
| 479 for (TilingData::Iterator iter(&tiling_data_, interest_rect); | 595 for (TilingData::Iterator iter(&bundle_tiling_data_, interest_rect); | 
| 480 iter; ++iter) { | 596 iter; ++iter) { | 
| 481 TileMap::iterator find = tiles_.find(iter.index()); | 597 int bundle_x = iter.index_x(); | 
| 482 if (find == tiles_.end()) | 598 int bundle_y = iter.index_y(); | 
| 599 TileBundle* bundle = TileBundleAt(bundle_x, bundle_y); | |
| 600 if (!bundle) | |
| 483 continue; | 601 continue; | 
| 484 | 602 | 
| 485 Tile* tile = find->second.get(); | 603 gfx::PointF current_bundle_origin = current_screen_space_origin + | 
| 486 | 604 ScaleVector2d(current_horizontal, bundle_x) + | 
| 487 int i = iter.index_x(); | 605 ScaleVector2d(current_vertical, bundle_y); | 
| 488 int j = iter.index_y(); | 606 gfx::PointF last_bundle_origin = last_screen_space_origin + | 
| 489 gfx::PointF current_tile_origin = current_screen_space_origin + | 607 ScaleVector2d(last_horizontal, bundle_x) + | 
| 490 ScaleVector2d(current_horizontal, i) + | 608 ScaleVector2d(last_vertical, bundle_y); | 
| 491 ScaleVector2d(current_vertical, j); | |
| 492 gfx::PointF last_tile_origin = last_screen_space_origin + | |
| 493 ScaleVector2d(last_horizontal, i) + | |
| 494 ScaleVector2d(last_vertical, j); | |
| 495 | 609 | 
| 496 gfx::RectF current_screen_rect = gfx::QuadF( | 610 gfx::RectF current_screen_rect = gfx::QuadF( | 
| 497 current_tile_origin, | 611 current_bundle_origin, | 
| 498 current_tile_origin + current_horizontal, | 612 current_bundle_origin + current_horizontal, | 
| 499 current_tile_origin + current_horizontal + current_vertical, | 613 current_bundle_origin + current_horizontal + current_vertical, | 
| 500 current_tile_origin + current_vertical).BoundingBox(); | 614 current_bundle_origin + current_vertical).BoundingBox(); | 
| 501 | 615 | 
| 502 gfx::RectF last_screen_rect = gfx::QuadF( | 616 gfx::RectF last_screen_rect = gfx::QuadF( | 
| 503 last_tile_origin, | 617 last_bundle_origin, | 
| 504 last_tile_origin + last_horizontal, | 618 last_bundle_origin + last_horizontal, | 
| 505 last_tile_origin + last_horizontal + last_vertical, | 619 last_bundle_origin + last_horizontal + last_vertical, | 
| 506 last_tile_origin + last_vertical).BoundingBox(); | 620 last_bundle_origin + last_vertical).BoundingBox(); | 
| 507 | 621 | 
| 508 float distance_to_visible_in_pixels = | 622 float distance_to_visible_in_pixels = | 
| 509 TilePriority::manhattanDistance(current_screen_rect, view_rect); | 623 TilePriority::manhattanDistance(current_screen_rect, view_rect); | 
| 510 | 624 | 
| 511 float time_to_visible_in_seconds = | 625 float time_to_visible_in_seconds = | 
| 512 TilePriority::TimeForBoundsToIntersect( | 626 TilePriority::TimeForBoundsToIntersect( | 
| 513 last_screen_rect, current_screen_rect, time_delta, view_rect); | 627 last_screen_rect, current_screen_rect, time_delta, view_rect); | 
| 514 TilePriority priority( | 628 TilePriority priority( | 
| 515 resolution_, | 629 resolution_, | 
| 516 time_to_visible_in_seconds, | 630 time_to_visible_in_seconds, | 
| 517 distance_to_visible_in_pixels); | 631 distance_to_visible_in_pixels); | 
| 518 tile->SetPriority(tree, priority); | 632 | 
| 633 bundle->SetPriority(tree, priority); | |
| 519 } | 634 } | 
| 520 } else { | 635 } else { | 
| 521 for (TilingData::Iterator iter(&tiling_data_, interest_rect); | 636 for (TilingData::Iterator iter(&bundle_tiling_data_, interest_rect); | 
| 522 iter; ++iter) { | 637 iter; ++iter) { | 
| 523 TileMap::iterator find = tiles_.find(iter.index()); | 638 int bundle_x = iter.index_x(); | 
| 524 if (find == tiles_.end()) | 639 int bundle_y = iter.index_y(); | 
| 640 TileBundle* bundle = TileBundleAt(bundle_x, bundle_y); | |
| 641 if (!bundle) | |
| 525 continue; | 642 continue; | 
| 526 Tile* tile = find->second.get(); | |
| 527 | 643 | 
| 528 gfx::Rect tile_bounds = | 644 gfx::Rect bundle_bounds = | 
| 529 tiling_data_.TileBounds(iter.index_x(), iter.index_y()); | 645 bundle_tiling_data_.TileBounds(bundle_x, bundle_y); | 
| 530 gfx::RectF current_layer_content_rect = gfx::ScaleRect( | 646 gfx::RectF current_layer_content_rect = gfx::ScaleRect( | 
| 531 tile_bounds, | 647 bundle_bounds, | 
| 532 current_scale, | 648 current_scale, | 
| 533 current_scale); | 649 current_scale); | 
| 534 gfx::RectF current_screen_rect = MathUtil::MapClippedRect( | 650 gfx::RectF current_screen_rect = MathUtil::MapClippedRect( | 
| 535 current_screen_transform, current_layer_content_rect); | 651 current_screen_transform, current_layer_content_rect); | 
| 536 gfx::RectF last_layer_content_rect = gfx::ScaleRect( | 652 gfx::RectF last_layer_content_rect = gfx::ScaleRect( | 
| 537 tile_bounds, | 653 bundle_bounds, | 
| 538 last_scale, | 654 last_scale, | 
| 539 last_scale); | 655 last_scale); | 
| 540 gfx::RectF last_screen_rect = MathUtil::MapClippedRect( | 656 gfx::RectF last_screen_rect = MathUtil::MapClippedRect( | 
| 541 last_screen_transform, last_layer_content_rect); | 657 last_screen_transform, last_layer_content_rect); | 
| 542 | 658 | 
| 543 float distance_to_visible_in_pixels = | 659 float distance_to_visible_in_pixels = | 
| 544 TilePriority::manhattanDistance(current_screen_rect, view_rect); | 660 TilePriority::manhattanDistance(current_screen_rect, view_rect); | 
| 545 | 661 | 
| 546 float time_to_visible_in_seconds = | 662 float time_to_visible_in_seconds = | 
| 547 TilePriority::TimeForBoundsToIntersect( | 663 TilePriority::TimeForBoundsToIntersect( | 
| 548 last_screen_rect, current_screen_rect, time_delta, view_rect); | 664 last_screen_rect, current_screen_rect, time_delta, view_rect); | 
| 549 | 665 | 
| 550 TilePriority priority( | 666 TilePriority priority( | 
| 551 resolution_, | 667 resolution_, | 
| 552 time_to_visible_in_seconds, | 668 time_to_visible_in_seconds, | 
| 553 distance_to_visible_in_pixels); | 669 distance_to_visible_in_pixels); | 
| 554 tile->SetPriority(tree, priority); | 670 | 
| 671 bundle->SetPriority(tree, priority); | |
| 555 } | 672 } | 
| 556 } | 673 } | 
| 557 | 674 | 
| 558 last_impl_frame_time_in_seconds_ = current_frame_time_in_seconds; | 675 last_impl_frame_time_in_seconds_ = current_frame_time_in_seconds; | 
| 559 } | 676 } | 
| 560 | 677 | 
| 561 void PictureLayerTiling::SetLiveTilesRect( | 678 void PictureLayerTiling::SetLiveTilesRect( | 
| 562 gfx::Rect new_live_tiles_rect) { | 679 WhichTree tree, gfx::Rect new_live_tiles_rect) { | 
| 563 DCHECK(new_live_tiles_rect.IsEmpty() || | 680 DCHECK(new_live_tiles_rect.IsEmpty() || | 
| 564 ContentRect().Contains(new_live_tiles_rect)); | 681 ContentRect().Contains(new_live_tiles_rect)); | 
| 565 if (live_tiles_rect_ == new_live_tiles_rect) | 682 if (live_tiles_rect_ == new_live_tiles_rect) | 
| 566 return; | 683 return; | 
| 567 | 684 | 
| 568 // Iterate to delete all tiles outside of our new live_tiles rect. | 685 // Iterate to delete all tiles outside of our new live_tiles rect. | 
| 569 for (TilingData::DifferenceIterator iter(&tiling_data_, | 686 for (TilingData::DifferenceIterator iter(&tiling_data_, | 
| 570 live_tiles_rect_, | 687 live_tiles_rect_, | 
| 571 new_live_tiles_rect); | 688 new_live_tiles_rect); | 
| 572 iter; | 689 iter; | 
| 573 ++iter) { | 690 ++iter) { | 
| 574 TileMapKey key(iter.index()); | 691 int tile_x = iter.index_x(); | 
| 575 TileMap::iterator found = tiles_.find(key); | 692 int tile_y = iter.index_y(); | 
| 693 | |
| 576 // If the tile was outside of the recorded region, it won't exist even | 694 // If the tile was outside of the recorded region, it won't exist even | 
| 577 // though it was in the live rect. | 695 // though it was in the live rect. | 
| 578 if (found != tiles_.end()) | 696 RemoveTile(tree, tile_x, tile_y); | 
| 579 tiles_.erase(found); | 697 RemoveBundleIfEmptyContainingTileAt(tile_x, tile_y); | 
| 580 } | 698 } | 
| 581 | 699 | 
| 582 const PictureLayerTiling* twin_tiling = client_->GetTwinTiling(this); | 700 const PictureLayerTiling* twin_tiling = client_->GetTwinTiling(this); | 
| 583 | 701 | 
| 584 // Iterate to allocate new tiles for all regions with newly exposed area. | 702 // Iterate to allocate new tiles for all regions with newly exposed area. | 
| 585 for (TilingData::DifferenceIterator iter(&tiling_data_, | 703 for (TilingData::DifferenceIterator iter(&tiling_data_, | 
| 586 new_live_tiles_rect, | 704 new_live_tiles_rect, | 
| 587 live_tiles_rect_); | 705 live_tiles_rect_); | 
| 588 iter; | 706 iter; | 
| 589 ++iter) { | 707 ++iter) { | 
| 590 TileMapKey key(iter.index()); | 708 // TODO(vmpstr): Since the old active tree became the recycled tree, | 
| 
 
enne (OOO)
2013/11/25 22:17:11
For what it's worth, the old pending tree becomes
 
vmpstr
2013/11/27 00:03:15
I've changed this... This wasn't the correct fix f
 
enne (OOO)
2013/11/27 01:38:05
Re: DidBecomeRecycled/Active/Pending with swapping
 
vmpstr
2013/11/27 21:09:36
Of course. I plan to add more than one. :) I just
 
 | |
| 591 CreateTile(key.first, key.second, twin_tiling); | 709 // and since the recycle tiles are recorded in bundle's pending list, | 
| 710 // we might run into a situation where we already have a tile in that | |
| 711 // region. We should remove it first. We can't use RemoveTile here, | |
| 712 // since the bundle might not yet be on this tiling. That is, the | |
| 713 // act of adding a tile will grab a bundle from the twin tiling that | |
| 714 // has this bad property of already having a tile in that spot. | |
| 715 // The todo here is to come up with a better way of recycling. | |
| 716 // Maybe having a separate list for that. | |
| 717 TileBundleMapKey key = | |
| 718 ComputeTileBundleIndex(iter.index_x(), iter.index_y()); | |
| 719 TileBundleMap::iterator bundle_it = tile_bundles_.find(key); | |
| 720 TileBundle* bundle = NULL; | |
| 721 if (bundle_it != tile_bundles_.end()) { | |
| 722 bundle = bundle_it->second; | |
| 723 } else { | |
| 724 bundle = | |
| 725 CreateBundleForTileAt(iter.index_x(), iter.index_y(), twin_tiling); | |
| 726 } | |
| 727 | |
| 728 bundle->RemoveTileAt(tree, iter.index_x(), iter.index_y()); | |
| 729 CreateTile(tree, iter.index_x(), iter.index_y(), twin_tiling); | |
| 592 } | 730 } | 
| 593 | 731 | 
| 594 live_tiles_rect_ = new_live_tiles_rect; | 732 live_tiles_rect_ = new_live_tiles_rect; | 
| 595 } | 733 } | 
| 596 | 734 | 
| 597 void PictureLayerTiling::DidBecomeRecycled() { | 735 void PictureLayerTiling::DidBecomeRecycled() { | 
| 598 // DidBecomeActive below will set the active priority for tiles that are | 736 // DidBecomeActive below will set the active priority for tiles that are | 
| 599 // still in the tree. Calling this first on an active tiling that is becoming | 737 // still in the tree. Calling this first on an active tiling that is becoming | 
| 600 // recycled takes care of tiles that are no longer in the active tree (eg. | 738 // recycled takes care of tiles that are no longer in the active tree (eg. | 
| 601 // due to a pending invalidation). | 739 // due to a pending invalidation). | 
| 602 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) { | 740 for (TileBundleMap::const_iterator it = tile_bundles_.begin(); | 
| 603 it->second->SetPriority(ACTIVE_TREE, TilePriority()); | 741 it != tile_bundles_.end(); | 
| 742 ++it) { | |
| 743 it->second->DidBecomeRecycled(); | |
| 604 } | 744 } | 
| 605 } | 745 } | 
| 606 | 746 | 
| 607 void PictureLayerTiling::DidBecomeActive() { | 747 void PictureLayerTiling::DidBecomeActive() { | 
| 608 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) { | 748 for (TileBundleMap::const_iterator it = tile_bundles_.begin(); | 
| 609 it->second->SetPriority(ACTIVE_TREE, it->second->priority(PENDING_TREE)); | 749 it != tile_bundles_.end(); | 
| 610 it->second->SetPriority(PENDING_TREE, TilePriority()); | 750 ++it) { | 
| 611 | 751 it->second->DidBecomeActive(); | 
| 612 // Tile holds a ref onto a picture pile. If the tile never gets invalidated | 752 for (TileBundle::Iterator tile_it(it->second.get()); tile_it; ++tile_it) { | 
| 613 // and recreated, then that picture pile ref could exist indefinitely. To | 753 // Tile holds a ref onto a picture pile. If the tile never gets | 
| 614 // prevent this, ask the client to update the pile to its own ref. This | 754 // invalidated and recreated, then that picture pile ref could exist | 
| 615 // will cause PicturePileImpls and their clones to get deleted once the | 755 // indefinitely. To prevent this, ask the client to update the pile to | 
| 616 // corresponding PictureLayerImpl and any in flight raster jobs go out of | 756 // its own ref. This will cause PicturePileImpls and their clones to get | 
| 617 // scope. | 757 // deleted once the corresponding PictureLayerImpl and any in flight | 
| 618 client_->UpdatePile(it->second.get()); | 758 // raster jobs go out of scope. | 
| 759 if (tile_it.active_tree_only_tile() && | |
| 760 tile_it.active_priority() != TilePriority()) | |
| 761 client_->UpdatePile(*tile_it); | |
| 
 
enne (OOO)
2013/11/25 22:17:11
Previously DidBecomeActive and UpdateTileToCurrent
 
vmpstr
2013/11/27 00:03:15
I changed this to be only updated for shared tiles
 
enne (OOO)
2013/11/27 01:38:05
Hmm.  In the case that the pile can't raster onto
 
vmpstr
2013/11/27 21:09:36
Done.
 
 | |
| 762 } | |
| 619 } | 763 } | 
| 620 } | 764 } | 
| 621 | 765 | 
| 622 void PictureLayerTiling::UpdateTilesToCurrentPile() { | 766 void PictureLayerTiling::UpdateTilesToCurrentPile() { | 
| 623 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) { | 767 for (TileBundleMap::const_iterator it = tile_bundles_.begin(); | 
| 624 client_->UpdatePile(it->second.get()); | 768 it != tile_bundles_.end(); | 
| 769 ++it) { | |
| 770 for (TileBundle::Iterator tile_it(it->second.get()); tile_it; ++tile_it) { | |
| 771 if (tile_it.pending_tree_only_tile() && | |
| 772 tile_it.pending_priority() != TilePriority()) | |
| 773 client_->UpdatePile(*tile_it); | |
| 774 } | |
| 625 } | 775 } | 
| 626 } | 776 } | 
| 627 | 777 | 
| 628 scoped_ptr<base::Value> PictureLayerTiling::AsValue() const { | 778 scoped_ptr<base::Value> PictureLayerTiling::AsValue() const { | 
| 629 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); | 779 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); | 
| 630 state->SetInteger("num_tiles", tiles_.size()); | 780 state->SetInteger("num_tile_bundles", tile_bundles_.size()); | 
| 631 state->SetDouble("content_scale", contents_scale_); | 781 state->SetDouble("content_scale", contents_scale_); | 
| 632 state->Set("content_bounds", | 782 state->Set("content_bounds", | 
| 633 MathUtil::AsValue(ContentRect().size()).release()); | 783 MathUtil::AsValue(ContentRect().size()).release()); | 
| 634 return state.PassAs<base::Value>(); | 784 return state.PassAs<base::Value>(); | 
| 635 } | 785 } | 
| 636 | 786 | 
| 637 size_t PictureLayerTiling::GPUMemoryUsageInBytes() const { | 787 size_t PictureLayerTiling::GPUMemoryUsageInBytes() const { | 
| 638 size_t amount = 0; | 788 size_t amount = 0; | 
| 639 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) { | 789 for (TileBundleMap::const_iterator it = tile_bundles_.begin(); | 
| 640 const Tile* tile = it->second.get(); | 790 it != tile_bundles_.end(); | 
| 641 amount += tile->GPUMemoryUsageInBytes(); | 791 ++it) { | 
| 792 for (TileBundle::Iterator tile_it(it->second.get()); tile_it; ++tile_it) | |
| 793 amount += tile_it->GPUMemoryUsageInBytes(); | |
| 642 } | 794 } | 
| 643 return amount; | 795 return amount; | 
| 644 } | 796 } | 
| 645 | 797 | 
| 646 PictureLayerTiling::RectExpansionCache::RectExpansionCache() | 798 PictureLayerTiling::RectExpansionCache::RectExpansionCache() | 
| 647 : previous_target(0) { | 799 : previous_target(0) { | 
| 648 } | 800 } | 
| 649 | 801 | 
| 650 namespace { | 802 namespace { | 
| 651 | 803 | 
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 786 break; | 938 break; | 
| 787 } | 939 } | 
| 788 | 940 | 
| 789 gfx::Rect result(origin_x, origin_y, width, height); | 941 gfx::Rect result(origin_x, origin_y, width, height); | 
| 790 if (cache) | 942 if (cache) | 
| 791 cache->previous_result = result; | 943 cache->previous_result = result; | 
| 792 return result; | 944 return result; | 
| 793 } | 945 } | 
| 794 | 946 | 
| 795 } // namespace cc | 947 } // namespace cc | 
| OLD | NEW |