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(
14 LayerTreeImpl
* tree_impl
,
16 scoped_refptr
<PicturePileImpl
> pile
)
17 : PictureLayerImpl(tree_impl
, id
),
18 append_quads_count_(0) {
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
,
27 scoped_refptr
<PicturePileImpl
> pile
,
28 const gfx::Size
& layer_bounds
)
29 : PictureLayerImpl(tree_impl
, id
), append_quads_count_(0) {
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.
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.
88 void FakePictureLayerImpl::SetAllTilesVisible() {
90 layer_tree_impl()->IsActiveTree() ? ACTIVE_TREE
: PENDING_TREE
;
92 for (size_t tiling_idx
= 0; tiling_idx
< tilings_
->num_tilings();
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();
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();
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();
153 DCHECK_EQ(tilings()->num_tilings(), 0u);