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/tiles/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::SetAllTilesReady() {
151 for (size_t tiling_idx
= 0; tiling_idx
< tilings_
->num_tilings();
153 PictureLayerTiling
* tiling
= tilings_
->tiling_at(tiling_idx
);
154 SetAllTilesReadyInTiling(tiling
);
158 void FakePictureLayerImpl::SetAllTilesReadyInTiling(
159 PictureLayerTiling
* tiling
) {
160 std::vector
<Tile
*> tiles
= tiling
->AllTilesForTesting();
161 for (size_t tile_idx
= 0; tile_idx
< tiles
.size(); ++tile_idx
) {
162 Tile
* tile
= tiles
[tile_idx
];
167 void FakePictureLayerImpl::SetTileReady(Tile
* tile
) {
168 TileDrawInfo
& draw_info
= tile
->draw_info();
169 draw_info
.SetSolidColorForTesting(true);
170 DCHECK(draw_info
.IsReadyToDraw());
173 void FakePictureLayerImpl::DidBecomeActive() {
174 PictureLayerImpl::DidBecomeActive();
175 ++did_become_active_call_count_
;
178 bool FakePictureLayerImpl::HasValidTilePriorities() const {
179 return use_set_valid_tile_priorities_flag_
180 ? has_valid_tile_priorities_
181 : PictureLayerImpl::HasValidTilePriorities();
184 size_t FakePictureLayerImpl::CountTilesRequired(
185 TileRequirementCheck is_tile_required_callback
) const {
186 if (!HasValidTilePriorities())
192 if (visible_rect_for_tile_priority_
.IsEmpty())
195 gfx::Rect rect
= viewport_rect_for_tile_priority_in_content_space_
;
196 rect
.Intersect(visible_rect_for_tile_priority_
);
200 for (size_t i
= 0; i
< tilings_
->num_tilings(); ++i
) {
201 PictureLayerTiling
* tiling
= tilings_
->tiling_at(i
);
202 if (tiling
->resolution() != HIGH_RESOLUTION
&&
203 tiling
->resolution() != LOW_RESOLUTION
)
206 for (PictureLayerTiling::CoverageIterator
iter(tiling
, 1.f
, rect
); iter
;
208 const Tile
* tile
= *iter
;
209 // A null tile (i.e. missing recording) can just be skipped.
210 // TODO(vmpstr): Verify this is true if we create tiles in raster
215 // We can't check tile->required_for_activation, because that value might
216 // be out of date. It is updated in the raster/eviction iterators.
217 // TODO(vmpstr): Remove the comment once you can't access this information
219 if ((tiling
->*is_tile_required_callback
)(tile
))
227 size_t FakePictureLayerImpl::CountTilesRequiredForActivation() const {
228 if (!layer_tree_impl()->IsPendingTree())
231 return CountTilesRequired(&PictureLayerTiling::IsTileRequiredForActivation
);
234 size_t FakePictureLayerImpl::CountTilesRequiredForDraw() const {
235 if (!layer_tree_impl()->IsActiveTree())
238 return CountTilesRequired(&PictureLayerTiling::IsTileRequiredForDraw
);
241 void FakePictureLayerImpl::ReleaseResources() {
242 PictureLayerImpl::ReleaseResources();
243 ++release_resources_count_
;