| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "cc/resources/tile_bundle.h" |
| 6 |
| 7 #include "cc/resources/picture_layer_tiling.h" |
| 8 #include "cc/resources/tile.h" |
| 9 #include "cc/resources/tile_manager.h" |
| 10 |
| 11 namespace cc { |
| 12 |
| 13 TileBundle::Id TileBundle::s_next_id_ = 0; |
| 14 |
| 15 TileBundle::TileBundle(TileManager* tile_manager, |
| 16 int width, |
| 17 int height, |
| 18 int offset_x, |
| 19 int offset_y) |
| 20 : RefCountedManaged<TileBundle>(tile_manager), |
| 21 tiling_(NULL), |
| 22 width_(width), |
| 23 height_(height), |
| 24 offset_x_(offset_x), |
| 25 offset_y_(offset_y), |
| 26 id_(s_next_id_++) {} |
| 27 |
| 28 TileBundle::~TileBundle() {} |
| 29 |
| 30 Tile* TileBundle::TileAt(int index_x, int index_y) { |
| 31 TileMapKey key = ComputeLocalIndex(index_x, index_y); |
| 32 TileMap::iterator it = tiles_.find(key); |
| 33 if (it == tiles_.end()) |
| 34 return NULL; |
| 35 return it->second.get(); |
| 36 } |
| 37 |
| 38 TileBundle* TileBundle::GetTwinBundle() { |
| 39 DCHECK(client_); |
| 40 const PictureLayerTiling* twin_tiling = client_->GetTwinTiling(tiling_); |
| 41 if (!twin_tiling) |
| 42 return NULL; |
| 43 return twin_tiling->TileBundleContainingTileAt(offset_x_, offset_y_); |
| 44 } |
| 45 |
| 46 bool TileBundle::IsRecycled() const { |
| 47 return client_->IsRecycled(); |
| 48 } |
| 49 |
| 50 bool TileBundle::IsActive() const { |
| 51 return client_->IsActive(); |
| 52 } |
| 53 |
| 54 bool TileBundle::IsPending() const { |
| 55 return client_->IsPending(); |
| 56 } |
| 57 |
| 58 bool TileBundle::RemoveTileAt(int index_x, int index_y) { |
| 59 TileMapKey key = ComputeLocalIndex(index_x, index_y); |
| 60 TileMap::iterator it = tiles_.find(key); |
| 61 if (it == tiles_.end()) |
| 62 return false; |
| 63 |
| 64 tiles_.erase(it); |
| 65 return true; |
| 66 } |
| 67 |
| 68 void TileBundle::AddTileAt(int index_x, |
| 69 int index_y, |
| 70 scoped_refptr<Tile> tile) { |
| 71 TileMapKey key = ComputeLocalIndex(index_x, index_y); |
| 72 DCHECK(tiles_.find(key) == tiles_.end()); |
| 73 tiles_[key] = tile; |
| 74 } |
| 75 |
| 76 void TileBundle::DidBecomeRecycled() { |
| 77 priority_ = TilePriority(); |
| 78 } |
| 79 |
| 80 void TileBundle::DidBecomeActive() { |
| 81 } |
| 82 |
| 83 size_t TileBundle::TileCount() const { |
| 84 return tiles_.size(); |
| 85 } |
| 86 |
| 87 TileBundle::TileMapKey TileBundle::ComputeLocalIndex(int index_x, int index_y) { |
| 88 index_x -= offset_x_; |
| 89 index_y -= offset_y_; |
| 90 |
| 91 DCHECK_GE(index_x, 0); |
| 92 DCHECK_GE(index_y, 0); |
| 93 DCHECK_LT(index_x, width_); |
| 94 DCHECK_LT(index_x, height_); |
| 95 |
| 96 return TileMapKey(index_x, index_y); |
| 97 } |
| 98 |
| 99 TileBundle::Iterator::Iterator(TileBundle* bundle) |
| 100 : bundle_(bundle), iterator_(bundle_->tiles_.begin()) {} |
| 101 |
| 102 TileBundle::Iterator::~Iterator() {} |
| 103 |
| 104 } // namespace cc |
| OLD | NEW |