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
<RasterSource
> raster_source
,
18 : PictureLayerImpl(tree_impl
,
21 new LayerImpl::SyncedScrollOffset
),
22 append_quads_count_(0),
23 did_become_active_call_count_(0),
24 has_valid_tile_priorities_(false),
25 use_set_valid_tile_priorities_flag_(false),
26 release_resources_count_(0) {
27 SetBounds(raster_source
->GetSize());
28 SetContentBounds(raster_source
->GetSize());
29 SetRasterSourceOnPending(raster_source
, Region());
32 FakePictureLayerImpl::FakePictureLayerImpl(
33 LayerTreeImpl
* tree_impl
,
35 scoped_refptr
<RasterSource
> raster_source
,
37 const gfx::Size
& layer_bounds
)
38 : PictureLayerImpl(tree_impl
,
41 new LayerImpl::SyncedScrollOffset
),
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),
46 release_resources_count_(0) {
47 SetBounds(layer_bounds
);
48 SetContentBounds(layer_bounds
);
49 SetRasterSourceOnPending(raster_source
, Region());
52 FakePictureLayerImpl::FakePictureLayerImpl(LayerTreeImpl
* tree_impl
,
55 : FakePictureLayerImpl(tree_impl
,
58 new LayerImpl::SyncedScrollOffset
) {
61 FakePictureLayerImpl::FakePictureLayerImpl(
62 LayerTreeImpl
* tree_impl
,
65 scoped_refptr
<LayerImpl::SyncedScrollOffset
> synced_scroll_offset
)
66 : PictureLayerImpl(tree_impl
, id
, is_mask
, synced_scroll_offset
),
67 append_quads_count_(0),
68 did_become_active_call_count_(0),
69 has_valid_tile_priorities_(false),
70 use_set_valid_tile_priorities_flag_(false),
71 release_resources_count_(0) {
74 scoped_ptr
<LayerImpl
> FakePictureLayerImpl::CreateLayerImpl(
75 LayerTreeImpl
* tree_impl
) {
76 return make_scoped_ptr(new FakePictureLayerImpl(tree_impl
, id(), is_mask_
,
77 synced_scroll_offset()));
80 void FakePictureLayerImpl::PushPropertiesTo(LayerImpl
* layer_impl
) {
81 FakePictureLayerImpl
* picture_layer_impl
=
82 static_cast<FakePictureLayerImpl
*>(layer_impl
);
83 picture_layer_impl
->fixed_tile_size_
= fixed_tile_size_
;
84 PictureLayerImpl::PushPropertiesTo(layer_impl
);
87 void FakePictureLayerImpl::AppendQuads(
88 RenderPass
* render_pass
,
89 AppendQuadsData
* append_quads_data
) {
90 PictureLayerImpl::AppendQuads(render_pass
, append_quads_data
);
91 ++append_quads_count_
;
94 gfx::Size
FakePictureLayerImpl::CalculateTileSize(
95 const gfx::Size
& content_bounds
) const {
96 if (fixed_tile_size_
.IsEmpty()) {
97 return PictureLayerImpl::CalculateTileSize(content_bounds
);
100 return fixed_tile_size_
;
103 PictureLayerTiling
* FakePictureLayerImpl::HighResTiling() const {
104 PictureLayerTiling
* result
= NULL
;
105 for (size_t i
= 0; i
< tilings_
->num_tilings(); ++i
) {
106 PictureLayerTiling
* tiling
= tilings_
->tiling_at(i
);
107 if (tiling
->resolution() == HIGH_RESOLUTION
) {
108 // There should be only one high res tiling.
116 PictureLayerTiling
* FakePictureLayerImpl::LowResTiling() const {
117 PictureLayerTiling
* result
= NULL
;
118 for (size_t i
= 0; i
< tilings_
->num_tilings(); ++i
) {
119 PictureLayerTiling
* tiling
= tilings_
->tiling_at(i
);
120 if (tiling
->resolution() == LOW_RESOLUTION
) {
121 // There should be only one low res tiling.
129 void FakePictureLayerImpl::SetRasterSourceOnPending(
130 scoped_refptr
<RasterSource
> raster_source
,
131 const Region
& invalidation
) {
132 DCHECK(layer_tree_impl()->IsPendingTree());
133 Region invalidation_temp
= invalidation
;
134 const PictureLayerTilingSet
* pending_set
= nullptr;
135 set_gpu_raster_max_texture_size(layer_tree_impl()->device_viewport_size());
136 UpdateRasterSource(raster_source
, &invalidation_temp
, pending_set
);
139 void FakePictureLayerImpl::SetIsDrawnRenderSurfaceLayerListMember(bool is
) {
140 draw_properties().last_drawn_render_surface_layer_list_id
=
141 is
? layer_tree_impl()->current_render_surface_list_id()
142 : layer_tree_impl()->current_render_surface_list_id() - 1;
145 void FakePictureLayerImpl::CreateAllTiles() {
146 for (size_t i
= 0; i
< num_tilings(); ++i
)
147 tilings_
->tiling_at(i
)->CreateAllTilesForTesting();
150 void FakePictureLayerImpl::SetAllTilesVisible() {
151 for (size_t tiling_idx
= 0; tiling_idx
< tilings_
->num_tilings();
153 PictureLayerTiling
* tiling
= tilings_
->tiling_at(tiling_idx
);
154 std::vector
<Tile
*> tiles
= tiling
->AllTilesForTesting();
155 for (size_t tile_idx
= 0; tile_idx
< tiles
.size(); ++tile_idx
) {
156 Tile
* tile
= tiles
[tile_idx
];
157 TilePriority priority
;
158 priority
.resolution
= HIGH_RESOLUTION
;
159 priority
.priority_bin
= TilePriority::NOW
;
160 priority
.distance_to_visible
= 0.f
;
161 tile
->set_priority(priority
);
166 void FakePictureLayerImpl::ResetAllTilesPriorities() {
167 for (size_t tiling_idx
= 0; tiling_idx
< tilings_
->num_tilings();
169 PictureLayerTiling
* tiling
= tilings_
->tiling_at(tiling_idx
);
170 std::vector
<Tile
*> tiles
= tiling
->AllTilesForTesting();
171 for (size_t tile_idx
= 0; tile_idx
< tiles
.size(); ++tile_idx
) {
172 Tile
* tile
= tiles
[tile_idx
];
173 tile
->set_priority(TilePriority());
178 void FakePictureLayerImpl::SetAllTilesReady() {
179 for (size_t tiling_idx
= 0; tiling_idx
< tilings_
->num_tilings();
181 PictureLayerTiling
* tiling
= tilings_
->tiling_at(tiling_idx
);
182 SetAllTilesReadyInTiling(tiling
);
186 void FakePictureLayerImpl::SetAllTilesReadyInTiling(
187 PictureLayerTiling
* tiling
) {
188 std::vector
<Tile
*> tiles
= tiling
->AllTilesForTesting();
189 for (size_t tile_idx
= 0; tile_idx
< tiles
.size(); ++tile_idx
) {
190 Tile
* tile
= tiles
[tile_idx
];
195 void FakePictureLayerImpl::SetTileReady(Tile
* tile
) {
196 TileDrawInfo
& draw_info
= tile
->draw_info();
197 draw_info
.SetSolidColorForTesting(true);
198 DCHECK(tile
->IsReadyToDraw());
201 void FakePictureLayerImpl::DidBecomeActive() {
202 PictureLayerImpl::DidBecomeActive();
203 ++did_become_active_call_count_
;
206 bool FakePictureLayerImpl::HasValidTilePriorities() const {
207 return use_set_valid_tile_priorities_flag_
208 ? has_valid_tile_priorities_
209 : PictureLayerImpl::HasValidTilePriorities();
212 size_t FakePictureLayerImpl::CountTilesRequired(
213 TileRequirementCheck is_tile_required_callback
) const {
214 if (!HasValidTilePriorities())
220 if (visible_rect_for_tile_priority_
.IsEmpty())
223 gfx::Rect rect
= viewport_rect_for_tile_priority_in_content_space_
;
224 rect
.Intersect(visible_rect_for_tile_priority_
);
228 for (size_t i
= 0; i
< tilings_
->num_tilings(); ++i
) {
229 PictureLayerTiling
* tiling
= tilings_
->tiling_at(i
);
230 if (tiling
->resolution() != HIGH_RESOLUTION
&&
231 tiling
->resolution() != LOW_RESOLUTION
)
234 for (PictureLayerTiling::CoverageIterator
iter(tiling
, 1.f
, rect
); iter
;
236 const Tile
* tile
= *iter
;
237 // A null tile (i.e. missing recording) can just be skipped.
238 // TODO(vmpstr): Verify this is true if we create tiles in raster
243 // We can't check tile->required_for_activation, because that value might
244 // be out of date. It is updated in the raster/eviction iterators.
245 // TODO(vmpstr): Remove the comment once you can't access this information
247 if ((tiling
->*is_tile_required_callback
)(tile
))
255 size_t FakePictureLayerImpl::CountTilesRequiredForActivation() const {
256 if (!layer_tree_impl()->IsPendingTree())
259 return CountTilesRequired(&PictureLayerTiling::IsTileRequiredForActivation
);
262 size_t FakePictureLayerImpl::CountTilesRequiredForDraw() const {
263 if (!layer_tree_impl()->IsActiveTree())
266 return CountTilesRequired(&PictureLayerTiling::IsTileRequiredForDraw
);
269 void FakePictureLayerImpl::ReleaseResources() {
270 PictureLayerImpl::ReleaseResources();
271 ++release_resources_count_
;