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/test/fake_picture_layer_impl.h" 6 7 #include <vector> 8 #include "cc/resources/tile.h" 9 #include "cc/trees/layer_tree_impl.h" 10 11 namespace cc { 12 13 FakePictureLayerImpl::FakePictureLayerImpl(LayerTreeImpl* tree_impl, 14 int id, 15 scoped_refptr<PicturePileImpl> pile) 16 : PictureLayerImpl(tree_impl, id), 17 append_quads_count_(0), 18 did_become_active_call_count_(0), 19 has_valid_tile_priorities_(false), 20 use_set_valid_tile_priorities_flag_(false), 21 release_resources_count_(0) { 22 pile_ = pile; 23 SetBounds(pile_->tiling_size()); 24 SetContentBounds(pile_->tiling_size()); 25 } 26 27 FakePictureLayerImpl::FakePictureLayerImpl(LayerTreeImpl* tree_impl, 28 int id, 29 scoped_refptr<PicturePileImpl> pile, 30 const gfx::Size& layer_bounds) 31 : PictureLayerImpl(tree_impl, id), 32 append_quads_count_(0), 33 did_become_active_call_count_(0), 34 has_valid_tile_priorities_(false), 35 use_set_valid_tile_priorities_flag_(false), 36 release_resources_count_(0) { 37 pile_ = pile; 38 SetBounds(layer_bounds); 39 SetContentBounds(layer_bounds); 40 } 41 42 FakePictureLayerImpl::FakePictureLayerImpl(LayerTreeImpl* tree_impl, int id) 43 : PictureLayerImpl(tree_impl, id), 44 append_quads_count_(0), 45 did_become_active_call_count_(0), 46 has_valid_tile_priorities_(false), 47 use_set_valid_tile_priorities_flag_(false), 48 release_resources_count_(0) { 49 } 50 51 scoped_ptr<LayerImpl> FakePictureLayerImpl::CreateLayerImpl( 52 LayerTreeImpl* tree_impl) { 53 return make_scoped_ptr( 54 new FakePictureLayerImpl(tree_impl, id())).PassAs<LayerImpl>(); 55 } 56 57 void FakePictureLayerImpl::AppendQuads( 58 RenderPass* render_pass, 59 const OcclusionTracker<LayerImpl>& occlusion_tracker, 60 AppendQuadsData* append_quads_data) { 61 PictureLayerImpl::AppendQuads( 62 render_pass, occlusion_tracker, append_quads_data); 63 ++append_quads_count_; 64 } 65 66 gfx::Size FakePictureLayerImpl::CalculateTileSize( 67 const gfx::Size& content_bounds) const { 68 if (fixed_tile_size_.IsEmpty()) { 69 return PictureLayerImpl::CalculateTileSize(content_bounds); 70 } 71 72 return fixed_tile_size_; 73 } 74 75 PictureLayerTiling* FakePictureLayerImpl::HighResTiling() const { 76 PictureLayerTiling* result = NULL; 77 for (size_t i = 0; i < tilings_->num_tilings(); ++i) { 78 PictureLayerTiling* tiling = tilings_->tiling_at(i); 79 if (tiling->resolution() == HIGH_RESOLUTION) { 80 // There should be only one high res tiling. 81 CHECK(!result); 82 result = tiling; 83 } 84 } 85 return result; 86 } 87 88 PictureLayerTiling* FakePictureLayerImpl::LowResTiling() const { 89 PictureLayerTiling* result = NULL; 90 for (size_t i = 0; i < tilings_->num_tilings(); ++i) { 91 PictureLayerTiling* tiling = tilings_->tiling_at(i); 92 if (tiling->resolution() == LOW_RESOLUTION) { 93 // There should be only one low res tiling. 94 CHECK(!result); 95 result = tiling; 96 } 97 } 98 return result; 99 } 100 101 void FakePictureLayerImpl::SetAllTilesVisible() { 102 WhichTree tree = 103 layer_tree_impl()->IsActiveTree() ? ACTIVE_TREE : PENDING_TREE; 104 105 for (size_t tiling_idx = 0; tiling_idx < tilings_->num_tilings(); 106 ++tiling_idx) { 107 PictureLayerTiling* tiling = tilings_->tiling_at(tiling_idx); 108 std::vector<Tile*> tiles = tiling->AllTilesForTesting(); 109 for (size_t tile_idx = 0; tile_idx < tiles.size(); ++tile_idx) { 110 Tile* tile = tiles[tile_idx]; 111 TilePriority priority; 112 priority.resolution = HIGH_RESOLUTION; 113 priority.priority_bin = TilePriority::NOW; 114 priority.distance_to_visible = 0.f; 115 tile->SetPriority(tree, priority); 116 } 117 } 118 } 119 120 void FakePictureLayerImpl::ResetAllTilesPriorities() { 121 for (size_t tiling_idx = 0; tiling_idx < tilings_->num_tilings(); 122 ++tiling_idx) { 123 PictureLayerTiling* tiling = tilings_->tiling_at(tiling_idx); 124 std::vector<Tile*> tiles = tiling->AllTilesForTesting(); 125 for (size_t tile_idx = 0; tile_idx < tiles.size(); ++tile_idx) { 126 Tile* tile = tiles[tile_idx]; 127 tile->SetPriority(ACTIVE_TREE, TilePriority()); 128 tile->SetPriority(PENDING_TREE, TilePriority()); 129 } 130 } 131 } 132 133 void FakePictureLayerImpl::SetAllTilesReady() { 134 for (size_t tiling_idx = 0; tiling_idx < tilings_->num_tilings(); 135 ++tiling_idx) { 136 PictureLayerTiling* tiling = tilings_->tiling_at(tiling_idx); 137 SetAllTilesReadyInTiling(tiling); 138 } 139 } 140 141 void FakePictureLayerImpl::SetAllTilesReadyInTiling( 142 PictureLayerTiling* tiling) { 143 std::vector<Tile*> tiles = tiling->AllTilesForTesting(); 144 for (size_t tile_idx = 0; tile_idx < tiles.size(); ++tile_idx) { 145 Tile* tile = tiles[tile_idx]; 146 SetTileReady(tile); 147 } 148 } 149 150 void FakePictureLayerImpl::SetTileReady(Tile* tile) { 151 ManagedTileState& state = tile->managed_state(); 152 for (size_t mode_idx = 0; mode_idx < NUM_RASTER_MODES; ++mode_idx) 153 state.tile_versions[mode_idx].SetSolidColorForTesting(true); 154 DCHECK(tile->IsReadyToDraw()); 155 } 156 157 void FakePictureLayerImpl::CreateDefaultTilingsAndTiles() { 158 layer_tree_impl()->UpdateDrawProperties(); 159 160 if (CanHaveTilings()) { 161 DCHECK_EQ(tilings()->num_tilings(), 162 layer_tree_impl()->settings().create_low_res_tiling ? 2u : 1u); 163 DCHECK_EQ(tilings()->tiling_at(0)->resolution(), HIGH_RESOLUTION); 164 HighResTiling()->CreateAllTilesForTesting(); 165 if (layer_tree_impl()->settings().create_low_res_tiling) { 166 DCHECK_EQ(tilings()->tiling_at(1)->resolution(), LOW_RESOLUTION); 167 LowResTiling()->CreateAllTilesForTesting(); 168 } 169 } else { 170 DCHECK_EQ(tilings()->num_tilings(), 0u); 171 } 172 } 173 174 void FakePictureLayerImpl::DidBecomeActive() { 175 PictureLayerImpl::DidBecomeActive(); 176 ++did_become_active_call_count_; 177 } 178 179 bool FakePictureLayerImpl::HasValidTilePriorities() const { 180 return use_set_valid_tile_priorities_flag_ 181 ? has_valid_tile_priorities_ 182 : PictureLayerImpl::HasValidTilePriorities(); 183 } 184 185 void FakePictureLayerImpl::ReleaseResources() { 186 PictureLayerImpl::ReleaseResources(); 187 ++release_resources_count_; 188 } 189 190 } // namespace cc 191