Use multiline attribute to check for IA2_STATE_MULTILINE.
[chromium-blink-merge.git] / cc / test / fake_picture_layer_impl.cc
blob75f7fdafa4f1a927ae87d7437a1e82be297f235c
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/resources/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 SetContentBounds(raster_source->GetSize());
29 SetRasterSourceOnPending(raster_source, Region());
32 FakePictureLayerImpl::FakePictureLayerImpl(
33 LayerTreeImpl* tree_impl,
34 int id,
35 scoped_refptr<RasterSource> raster_source,
36 bool is_mask,
37 const gfx::Size& layer_bounds)
38 : PictureLayerImpl(tree_impl,
39 id,
40 is_mask,
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,
53 int id,
54 bool is_mask)
55 : FakePictureLayerImpl(tree_impl,
56 id,
57 is_mask,
58 new LayerImpl::SyncedScrollOffset) {
61 FakePictureLayerImpl::FakePictureLayerImpl(
62 LayerTreeImpl* tree_impl,
63 int id,
64 bool is_mask,
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.
109 CHECK(!result);
110 result = tiling;
113 return result;
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.
122 CHECK(!result);
123 result = tiling;
126 return result;
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 WhichTree tree =
152 layer_tree_impl()->IsActiveTree() ? ACTIVE_TREE : PENDING_TREE;
154 for (size_t tiling_idx = 0; tiling_idx < tilings_->num_tilings();
155 ++tiling_idx) {
156 PictureLayerTiling* tiling = tilings_->tiling_at(tiling_idx);
157 std::vector<Tile*> tiles = tiling->AllTilesForTesting();
158 for (size_t tile_idx = 0; tile_idx < tiles.size(); ++tile_idx) {
159 Tile* tile = tiles[tile_idx];
160 TilePriority priority;
161 priority.resolution = HIGH_RESOLUTION;
162 priority.priority_bin = TilePriority::NOW;
163 priority.distance_to_visible = 0.f;
164 tile->SetPriority(tree, priority);
169 void FakePictureLayerImpl::ResetAllTilesPriorities() {
170 for (size_t tiling_idx = 0; tiling_idx < tilings_->num_tilings();
171 ++tiling_idx) {
172 PictureLayerTiling* tiling = tilings_->tiling_at(tiling_idx);
173 std::vector<Tile*> tiles = tiling->AllTilesForTesting();
174 for (size_t tile_idx = 0; tile_idx < tiles.size(); ++tile_idx) {
175 Tile* tile = tiles[tile_idx];
176 tile->SetPriority(ACTIVE_TREE, TilePriority());
177 tile->SetPriority(PENDING_TREE, TilePriority());
182 void FakePictureLayerImpl::SetAllTilesReady() {
183 for (size_t tiling_idx = 0; tiling_idx < tilings_->num_tilings();
184 ++tiling_idx) {
185 PictureLayerTiling* tiling = tilings_->tiling_at(tiling_idx);
186 SetAllTilesReadyInTiling(tiling);
190 void FakePictureLayerImpl::SetAllTilesReadyInTiling(
191 PictureLayerTiling* tiling) {
192 std::vector<Tile*> tiles = tiling->AllTilesForTesting();
193 for (size_t tile_idx = 0; tile_idx < tiles.size(); ++tile_idx) {
194 Tile* tile = tiles[tile_idx];
195 SetTileReady(tile);
199 void FakePictureLayerImpl::SetTileReady(Tile* tile) {
200 TileDrawInfo& draw_info = tile->draw_info();
201 draw_info.SetSolidColorForTesting(true);
202 DCHECK(tile->IsReadyToDraw());
205 void FakePictureLayerImpl::DidBecomeActive() {
206 PictureLayerImpl::DidBecomeActive();
207 ++did_become_active_call_count_;
210 bool FakePictureLayerImpl::HasValidTilePriorities() const {
211 return use_set_valid_tile_priorities_flag_
212 ? has_valid_tile_priorities_
213 : PictureLayerImpl::HasValidTilePriorities();
216 size_t FakePictureLayerImpl::CountTilesRequired(
217 TileRequirementCheck is_tile_required_callback) const {
218 if (!HasValidTilePriorities())
219 return 0;
221 if (!tilings_)
222 return 0;
224 if (visible_rect_for_tile_priority_.IsEmpty())
225 return 0;
227 gfx::Rect rect = viewport_rect_for_tile_priority_in_content_space_;
228 rect.Intersect(visible_rect_for_tile_priority_);
230 size_t count = 0;
232 for (size_t i = 0; i < tilings_->num_tilings(); ++i) {
233 PictureLayerTiling* tiling = tilings_->tiling_at(i);
234 if (tiling->resolution() != HIGH_RESOLUTION &&
235 tiling->resolution() != LOW_RESOLUTION)
236 continue;
238 for (PictureLayerTiling::CoverageIterator iter(tiling, 1.f, rect); iter;
239 ++iter) {
240 const Tile* tile = *iter;
241 // A null tile (i.e. missing recording) can just be skipped.
242 // TODO(vmpstr): Verify this is true if we create tiles in raster
243 // iterators.
244 if (!tile)
245 continue;
247 // We can't check tile->required_for_activation, because that value might
248 // be out of date. It is updated in the raster/eviction iterators.
249 // TODO(vmpstr): Remove the comment once you can't access this information
250 // from the tile.
251 if ((tiling->*is_tile_required_callback)(tile))
252 ++count;
256 return count;
259 size_t FakePictureLayerImpl::CountTilesRequiredForActivation() const {
260 if (!layer_tree_impl()->IsPendingTree())
261 return 0;
263 return CountTilesRequired(
264 &PictureLayerTiling::IsTileRequiredForActivationIfVisible);
267 size_t FakePictureLayerImpl::CountTilesRequiredForDraw() const {
268 if (!layer_tree_impl()->IsActiveTree())
269 return 0;
271 return CountTilesRequired(
272 &PictureLayerTiling::IsTileRequiredForDrawIfVisible);
275 void FakePictureLayerImpl::ReleaseResources() {
276 PictureLayerImpl::ReleaseResources();
277 ++release_resources_count_;
280 } // namespace cc