Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / cc / test / fake_picture_layer_impl.cc
blob11d13204682f819cc8324d2dacfc8772ebe9ed19
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 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::SetAllTilesReady() {
151 for (size_t tiling_idx = 0; tiling_idx < tilings_->num_tilings();
152 ++tiling_idx) {
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];
163 SetTileReady(tile);
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())
187 return 0;
189 if (!tilings_)
190 return 0;
192 if (visible_rect_for_tile_priority_.IsEmpty())
193 return 0;
195 gfx::Rect rect = viewport_rect_for_tile_priority_in_content_space_;
196 rect.Intersect(visible_rect_for_tile_priority_);
198 size_t count = 0;
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)
204 continue;
206 for (PictureLayerTiling::CoverageIterator iter(tiling, 1.f, rect); iter;
207 ++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
211 // iterators.
212 if (!tile)
213 continue;
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
218 // from the tile.
219 if ((tiling->*is_tile_required_callback)(tile))
220 ++count;
224 return count;
227 size_t FakePictureLayerImpl::CountTilesRequiredForActivation() const {
228 if (!layer_tree_impl()->IsPendingTree())
229 return 0;
231 return CountTilesRequired(&PictureLayerTiling::IsTileRequiredForActivation);
234 size_t FakePictureLayerImpl::CountTilesRequiredForDraw() const {
235 if (!layer_tree_impl()->IsActiveTree())
236 return 0;
238 return CountTilesRequired(&PictureLayerTiling::IsTileRequiredForDraw);
241 void FakePictureLayerImpl::ReleaseResources() {
242 PictureLayerImpl::ReleaseResources();
243 ++release_resources_count_;
246 } // namespace cc