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"
8 #include "cc/resources/tile.h"
9 #include "cc/trees/layer_tree_impl.h"
13 FakePictureLayerImpl::FakePictureLayerImpl(LayerTreeImpl
* tree_impl
,
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) {
22 SetBounds(pile_
->tiling_size());
23 SetContentBounds(pile_
->tiling_size());
26 FakePictureLayerImpl::FakePictureLayerImpl(LayerTreeImpl
* tree_impl
,
28 scoped_refptr
<PicturePileImpl
> pile
,
29 const gfx::Size
& layer_bounds
)
30 : PictureLayerImpl(tree_impl
, id
),
31 append_quads_count_(0),
32 did_become_active_call_count_(0),
33 has_valid_tile_priorities_(false),
34 use_set_valid_tile_priorities_flag_(false) {
36 SetBounds(layer_bounds
);
37 SetContentBounds(layer_bounds
);
40 FakePictureLayerImpl::FakePictureLayerImpl(LayerTreeImpl
* tree_impl
, int id
)
41 : PictureLayerImpl(tree_impl
, id
),
42 append_quads_count_(0),
43 did_become_active_call_count_(0),
44 has_valid_tile_priorities_(false),
45 use_set_valid_tile_priorities_flag_(false) {
48 scoped_ptr
<LayerImpl
> FakePictureLayerImpl::CreateLayerImpl(
49 LayerTreeImpl
* tree_impl
) {
50 return make_scoped_ptr(
51 new FakePictureLayerImpl(tree_impl
, id())).PassAs
<LayerImpl
>();
54 void FakePictureLayerImpl::AppendQuads(
55 RenderPass
* render_pass
,
56 const OcclusionTracker
<LayerImpl
>& occlusion_tracker
,
57 AppendQuadsData
* append_quads_data
) {
58 PictureLayerImpl::AppendQuads(
59 render_pass
, occlusion_tracker
, append_quads_data
);
60 ++append_quads_count_
;
63 gfx::Size
FakePictureLayerImpl::CalculateTileSize(
64 const gfx::Size
& content_bounds
) const {
65 if (fixed_tile_size_
.IsEmpty()) {
66 return PictureLayerImpl::CalculateTileSize(content_bounds
);
69 return fixed_tile_size_
;
72 PictureLayerTiling
* FakePictureLayerImpl::HighResTiling() const {
73 PictureLayerTiling
* result
= NULL
;
74 for (size_t i
= 0; i
< tilings_
->num_tilings(); ++i
) {
75 PictureLayerTiling
* tiling
= tilings_
->tiling_at(i
);
76 if (tiling
->resolution() == HIGH_RESOLUTION
) {
77 // There should be only one high res tiling.
85 PictureLayerTiling
* FakePictureLayerImpl::LowResTiling() const {
86 PictureLayerTiling
* result
= NULL
;
87 for (size_t i
= 0; i
< tilings_
->num_tilings(); ++i
) {
88 PictureLayerTiling
* tiling
= tilings_
->tiling_at(i
);
89 if (tiling
->resolution() == LOW_RESOLUTION
) {
90 // There should be only one low res tiling.
98 void FakePictureLayerImpl::SetAllTilesVisible() {
100 layer_tree_impl()->IsActiveTree() ? ACTIVE_TREE
: PENDING_TREE
;
102 for (size_t tiling_idx
= 0; tiling_idx
< tilings_
->num_tilings();
104 PictureLayerTiling
* tiling
= tilings_
->tiling_at(tiling_idx
);
105 std::vector
<Tile
*> tiles
= tiling
->AllTilesForTesting();
106 for (size_t tile_idx
= 0; tile_idx
< tiles
.size(); ++tile_idx
) {
107 Tile
* tile
= tiles
[tile_idx
];
108 TilePriority priority
;
109 priority
.resolution
= HIGH_RESOLUTION
;
110 priority
.priority_bin
= TilePriority::NOW
;
111 priority
.distance_to_visible
= 0.f
;
112 tile
->SetPriority(tree
, priority
);
117 void FakePictureLayerImpl::ResetAllTilesPriorities() {
118 for (size_t tiling_idx
= 0; tiling_idx
< tilings_
->num_tilings();
120 PictureLayerTiling
* tiling
= tilings_
->tiling_at(tiling_idx
);
121 std::vector
<Tile
*> tiles
= tiling
->AllTilesForTesting();
122 for (size_t tile_idx
= 0; tile_idx
< tiles
.size(); ++tile_idx
) {
123 Tile
* tile
= tiles
[tile_idx
];
124 tile
->SetPriority(ACTIVE_TREE
, TilePriority());
125 tile
->SetPriority(PENDING_TREE
, TilePriority());
130 void FakePictureLayerImpl::SetAllTilesReady() {
131 for (size_t tiling_idx
= 0; tiling_idx
< tilings_
->num_tilings();
133 PictureLayerTiling
* tiling
= tilings_
->tiling_at(tiling_idx
);
134 SetAllTilesReadyInTiling(tiling
);
138 void FakePictureLayerImpl::SetAllTilesReadyInTiling(
139 PictureLayerTiling
* tiling
) {
140 std::vector
<Tile
*> tiles
= tiling
->AllTilesForTesting();
141 for (size_t tile_idx
= 0; tile_idx
< tiles
.size(); ++tile_idx
) {
142 Tile
* tile
= tiles
[tile_idx
];
143 ManagedTileState
& state
= tile
->managed_state();
144 for (size_t mode_idx
= 0; mode_idx
< NUM_RASTER_MODES
; ++mode_idx
)
145 state
.tile_versions
[mode_idx
].SetSolidColorForTesting(true);
146 DCHECK(tile
->IsReadyToDraw());
150 void FakePictureLayerImpl::CreateDefaultTilingsAndTiles() {
151 layer_tree_impl()->UpdateDrawProperties();
153 if (CanHaveTilings()) {
154 DCHECK_EQ(tilings()->num_tilings(),
155 layer_tree_impl()->settings().create_low_res_tiling
? 2u : 1u);
156 DCHECK_EQ(tilings()->tiling_at(0)->resolution(), HIGH_RESOLUTION
);
157 HighResTiling()->CreateAllTilesForTesting();
158 if (layer_tree_impl()->settings().create_low_res_tiling
) {
159 DCHECK_EQ(tilings()->tiling_at(1)->resolution(), LOW_RESOLUTION
);
160 LowResTiling()->CreateAllTilesForTesting();
163 DCHECK_EQ(tilings()->num_tilings(), 0u);
167 void FakePictureLayerImpl::DidBecomeActive() {
168 PictureLayerImpl::DidBecomeActive();
169 ++did_become_active_call_count_
;
172 bool FakePictureLayerImpl::HasValidTilePriorities() const {
173 return use_set_valid_tile_priorities_flag_
174 ? has_valid_tile_priorities_
175 : PictureLayerImpl::HasValidTilePriorities();