Lots of random cleanups, mostly for native_theme_win.cc:
[chromium-blink-merge.git] / cc / test / fake_picture_layer_impl.cc
blob3e92bd5af21e98b48a306923a6fcf08747f5c989
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.
5 #include "cc/test/fake_picture_layer_impl.h"
7 #include <vector>
8 #include "cc/resources/tile.h"
9 #include "cc/trees/layer_tree_impl.h"
11 namespace cc {
13 FakePictureLayerImpl::FakePictureLayerImpl(
14 LayerTreeImpl* tree_impl,
15 int id,
16 scoped_refptr<PicturePileImpl> pile)
17 : PictureLayerImpl(tree_impl, id),
18 append_quads_count_(0) {
19 pile_ = pile;
20 CHECK(pile->tiling_rect().origin() == gfx::Point());
21 SetBounds(pile_->tiling_rect().size());
22 SetContentBounds(pile_->tiling_rect().size());
25 FakePictureLayerImpl::FakePictureLayerImpl(LayerTreeImpl* tree_impl,
26 int id,
27 scoped_refptr<PicturePileImpl> pile,
28 const gfx::Size& layer_bounds)
29 : PictureLayerImpl(tree_impl, id), append_quads_count_(0) {
30 pile_ = pile;
31 SetBounds(layer_bounds);
32 SetContentBounds(layer_bounds);
35 FakePictureLayerImpl::FakePictureLayerImpl(LayerTreeImpl* tree_impl, int id)
36 : PictureLayerImpl(tree_impl, id), append_quads_count_(0) {}
38 scoped_ptr<LayerImpl> FakePictureLayerImpl::CreateLayerImpl(
39 LayerTreeImpl* tree_impl) {
40 return make_scoped_ptr(
41 new FakePictureLayerImpl(tree_impl, id())).PassAs<LayerImpl>();
44 void FakePictureLayerImpl::AppendQuads(
45 RenderPass* render_pass,
46 const OcclusionTracker<LayerImpl>& occlusion_tracker,
47 AppendQuadsData* append_quads_data) {
48 PictureLayerImpl::AppendQuads(
49 render_pass, occlusion_tracker, append_quads_data);
50 ++append_quads_count_;
53 gfx::Size FakePictureLayerImpl::CalculateTileSize(
54 const gfx::Size& content_bounds) const {
55 if (fixed_tile_size_.IsEmpty()) {
56 return PictureLayerImpl::CalculateTileSize(content_bounds);
59 return fixed_tile_size_;
62 PictureLayerTiling* FakePictureLayerImpl::HighResTiling() const {
63 PictureLayerTiling* result = NULL;
64 for (size_t i = 0; i < tilings_->num_tilings(); ++i) {
65 PictureLayerTiling* tiling = tilings_->tiling_at(i);
66 if (tiling->resolution() == HIGH_RESOLUTION) {
67 // There should be only one high res tiling.
68 CHECK(!result);
69 result = tiling;
72 return result;
75 PictureLayerTiling* FakePictureLayerImpl::LowResTiling() 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() == LOW_RESOLUTION) {
80 // There should be only one low res tiling.
81 CHECK(!result);
82 result = tiling;
85 return result;
88 void FakePictureLayerImpl::SetAllTilesVisible() {
89 WhichTree tree =
90 layer_tree_impl()->IsActiveTree() ? ACTIVE_TREE : PENDING_TREE;
92 for (size_t tiling_idx = 0; tiling_idx < tilings_->num_tilings();
93 ++tiling_idx) {
94 PictureLayerTiling* tiling = tilings_->tiling_at(tiling_idx);
95 std::vector<Tile*> tiles = tiling->AllTilesForTesting();
96 for (size_t tile_idx = 0; tile_idx < tiles.size(); ++tile_idx) {
97 Tile* tile = tiles[tile_idx];
98 TilePriority priority;
99 priority.resolution = HIGH_RESOLUTION;
100 priority.priority_bin = TilePriority::NOW;
101 priority.distance_to_visible = 0.f;
102 tile->SetPriority(tree, priority);
107 void FakePictureLayerImpl::ResetAllTilesPriorities() {
108 for (size_t tiling_idx = 0; tiling_idx < tilings_->num_tilings();
109 ++tiling_idx) {
110 PictureLayerTiling* tiling = tilings_->tiling_at(tiling_idx);
111 std::vector<Tile*> tiles = tiling->AllTilesForTesting();
112 for (size_t tile_idx = 0; tile_idx < tiles.size(); ++tile_idx) {
113 Tile* tile = tiles[tile_idx];
114 tile->SetPriority(ACTIVE_TREE, TilePriority());
115 tile->SetPriority(PENDING_TREE, TilePriority());
120 void FakePictureLayerImpl::SetAllTilesReady() {
121 for (size_t tiling_idx = 0; tiling_idx < tilings_->num_tilings();
122 ++tiling_idx) {
123 PictureLayerTiling* tiling = tilings_->tiling_at(tiling_idx);
124 SetAllTilesReadyInTiling(tiling);
128 void FakePictureLayerImpl::SetAllTilesReadyInTiling(
129 PictureLayerTiling* tiling) {
130 std::vector<Tile*> tiles = tiling->AllTilesForTesting();
131 for (size_t tile_idx = 0; tile_idx < tiles.size(); ++tile_idx) {
132 Tile* tile = tiles[tile_idx];
133 ManagedTileState& state = tile->managed_state();
134 for (size_t mode_idx = 0; mode_idx < NUM_RASTER_MODES; ++mode_idx)
135 state.tile_versions[mode_idx].SetSolidColorForTesting(true);
136 DCHECK(tile->IsReadyToDraw());
140 void FakePictureLayerImpl::CreateDefaultTilingsAndTiles() {
141 layer_tree_impl()->UpdateDrawProperties();
143 if (CanHaveTilings()) {
144 DCHECK_EQ(tilings()->num_tilings(),
145 layer_tree_impl()->settings().create_low_res_tiling ? 2u : 1u);
146 DCHECK_EQ(tilings()->tiling_at(0)->resolution(), HIGH_RESOLUTION);
147 HighResTiling()->CreateAllTilesForTesting();
148 if (layer_tree_impl()->settings().create_low_res_tiling) {
149 DCHECK_EQ(tilings()->tiling_at(1)->resolution(), LOW_RESOLUTION);
150 LowResTiling()->CreateAllTilesForTesting();
152 } else {
153 DCHECK_EQ(tilings()->num_tilings(), 0u);
157 } // namespace cc