Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / cc / test / fake_picture_layer_impl.cc
blob93cfbc232700d0ffd6d4de90521292184565f96c
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/tiles/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<RasterSource> raster_source,
17 bool is_mask)
18 : PictureLayerImpl(tree_impl,
19 id,
20 is_mask,
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 SetRasterSourceOnPending(raster_source, Region());
31 FakePictureLayerImpl::FakePictureLayerImpl(
32 LayerTreeImpl* tree_impl,
33 int id,
34 scoped_refptr<RasterSource> raster_source,
35 bool is_mask,
36 const gfx::Size& layer_bounds)
37 : PictureLayerImpl(tree_impl,
38 id,
39 is_mask,
40 new LayerImpl::SyncedScrollOffset),
41 append_quads_count_(0),
42 did_become_active_call_count_(0),
43 has_valid_tile_priorities_(false),
44 use_set_valid_tile_priorities_flag_(false),
45 release_resources_count_(0) {
46 SetBounds(layer_bounds);
47 SetRasterSourceOnPending(raster_source, Region());
50 FakePictureLayerImpl::FakePictureLayerImpl(LayerTreeImpl* tree_impl,
51 int id,
52 bool is_mask)
53 : FakePictureLayerImpl(tree_impl,
54 id,
55 is_mask,
56 new LayerImpl::SyncedScrollOffset) {
59 FakePictureLayerImpl::FakePictureLayerImpl(
60 LayerTreeImpl* tree_impl,
61 int id,
62 bool is_mask,
63 scoped_refptr<LayerImpl::SyncedScrollOffset> synced_scroll_offset)
64 : PictureLayerImpl(tree_impl, id, is_mask, synced_scroll_offset),
65 append_quads_count_(0),
66 did_become_active_call_count_(0),
67 has_valid_tile_priorities_(false),
68 use_set_valid_tile_priorities_flag_(false),
69 release_resources_count_(0) {
72 scoped_ptr<LayerImpl> FakePictureLayerImpl::CreateLayerImpl(
73 LayerTreeImpl* tree_impl) {
74 return make_scoped_ptr(new FakePictureLayerImpl(tree_impl, id(), is_mask_,
75 synced_scroll_offset()));
78 void FakePictureLayerImpl::PushPropertiesTo(LayerImpl* layer_impl) {
79 FakePictureLayerImpl* picture_layer_impl =
80 static_cast<FakePictureLayerImpl*>(layer_impl);
81 picture_layer_impl->fixed_tile_size_ = fixed_tile_size_;
82 PictureLayerImpl::PushPropertiesTo(layer_impl);
85 void FakePictureLayerImpl::AppendQuads(
86 RenderPass* render_pass,
87 AppendQuadsData* append_quads_data) {
88 PictureLayerImpl::AppendQuads(render_pass, append_quads_data);
89 ++append_quads_count_;
92 gfx::Size FakePictureLayerImpl::CalculateTileSize(
93 const gfx::Size& content_bounds) const {
94 if (fixed_tile_size_.IsEmpty()) {
95 return PictureLayerImpl::CalculateTileSize(content_bounds);
98 return fixed_tile_size_;
101 PictureLayerTiling* FakePictureLayerImpl::HighResTiling() const {
102 PictureLayerTiling* result = NULL;
103 for (size_t i = 0; i < tilings_->num_tilings(); ++i) {
104 PictureLayerTiling* tiling = tilings_->tiling_at(i);
105 if (tiling->resolution() == HIGH_RESOLUTION) {
106 // There should be only one high res tiling.
107 CHECK(!result);
108 result = tiling;
111 return result;
114 PictureLayerTiling* FakePictureLayerImpl::LowResTiling() const {
115 PictureLayerTiling* result = NULL;
116 for (size_t i = 0; i < tilings_->num_tilings(); ++i) {
117 PictureLayerTiling* tiling = tilings_->tiling_at(i);
118 if (tiling->resolution() == LOW_RESOLUTION) {
119 // There should be only one low res tiling.
120 CHECK(!result);
121 result = tiling;
124 return result;
127 void FakePictureLayerImpl::SetRasterSourceOnPending(
128 scoped_refptr<RasterSource> raster_source,
129 const Region& invalidation) {
130 DCHECK(layer_tree_impl()->IsPendingTree());
131 Region invalidation_temp = invalidation;
132 const PictureLayerTilingSet* pending_set = nullptr;
133 set_gpu_raster_max_texture_size(layer_tree_impl()->device_viewport_size());
134 UpdateRasterSource(raster_source, &invalidation_temp, pending_set);
137 void FakePictureLayerImpl::SetIsDrawnRenderSurfaceLayerListMember(bool is) {
138 draw_properties().last_drawn_render_surface_layer_list_id =
139 is ? layer_tree_impl()->current_render_surface_list_id()
140 : layer_tree_impl()->current_render_surface_list_id() - 1;
143 void FakePictureLayerImpl::CreateAllTiles() {
144 for (size_t i = 0; i < num_tilings(); ++i)
145 tilings_->tiling_at(i)->CreateAllTilesForTesting();
148 void FakePictureLayerImpl::SetAllTilesReady() {
149 for (size_t tiling_idx = 0; tiling_idx < tilings_->num_tilings();
150 ++tiling_idx) {
151 PictureLayerTiling* tiling = tilings_->tiling_at(tiling_idx);
152 SetAllTilesReadyInTiling(tiling);
156 void FakePictureLayerImpl::SetAllTilesReadyInTiling(
157 PictureLayerTiling* tiling) {
158 std::vector<Tile*> tiles = tiling->AllTilesForTesting();
159 for (size_t tile_idx = 0; tile_idx < tiles.size(); ++tile_idx) {
160 Tile* tile = tiles[tile_idx];
161 SetTileReady(tile);
165 void FakePictureLayerImpl::SetTileReady(Tile* tile) {
166 TileDrawInfo& draw_info = tile->draw_info();
167 draw_info.SetSolidColorForTesting(true);
168 DCHECK(draw_info.IsReadyToDraw());
171 void FakePictureLayerImpl::DidBecomeActive() {
172 PictureLayerImpl::DidBecomeActive();
173 ++did_become_active_call_count_;
176 bool FakePictureLayerImpl::HasValidTilePriorities() const {
177 return use_set_valid_tile_priorities_flag_
178 ? has_valid_tile_priorities_
179 : PictureLayerImpl::HasValidTilePriorities();
182 size_t FakePictureLayerImpl::CountTilesRequired(
183 TileRequirementCheck is_tile_required_callback) const {
184 if (!HasValidTilePriorities())
185 return 0;
187 if (!tilings_)
188 return 0;
190 if (visible_rect_for_tile_priority_.IsEmpty())
191 return 0;
193 gfx::Rect rect = viewport_rect_for_tile_priority_in_content_space_;
194 rect.Intersect(visible_rect_for_tile_priority_);
196 size_t count = 0;
198 for (size_t i = 0; i < tilings_->num_tilings(); ++i) {
199 PictureLayerTiling* tiling = tilings_->tiling_at(i);
200 if (tiling->resolution() != HIGH_RESOLUTION &&
201 tiling->resolution() != LOW_RESOLUTION)
202 continue;
204 for (PictureLayerTiling::CoverageIterator iter(tiling, 1.f, rect); iter;
205 ++iter) {
206 const Tile* tile = *iter;
207 // A null tile (i.e. missing recording) can just be skipped.
208 // TODO(vmpstr): Verify this is true if we create tiles in raster
209 // iterators.
210 if (!tile)
211 continue;
213 // We can't check tile->required_for_activation, because that value might
214 // be out of date. It is updated in the raster/eviction iterators.
215 // TODO(vmpstr): Remove the comment once you can't access this information
216 // from the tile.
217 if ((tiling->*is_tile_required_callback)(tile))
218 ++count;
222 return count;
225 size_t FakePictureLayerImpl::CountTilesRequiredForActivation() const {
226 if (!layer_tree_impl()->IsPendingTree())
227 return 0;
229 return CountTilesRequired(&PictureLayerTiling::IsTileRequiredForActivation);
232 size_t FakePictureLayerImpl::CountTilesRequiredForDraw() const {
233 if (!layer_tree_impl()->IsActiveTree())
234 return 0;
236 return CountTilesRequired(&PictureLayerTiling::IsTileRequiredForDraw);
239 void FakePictureLayerImpl::ReleaseResources() {
240 PictureLayerImpl::ReleaseResources();
241 ++release_resources_count_;
244 } // namespace cc