Revert "Reland c91b178b07b0d - Delete dead signin code (SigninGlobalError)"
[chromium-blink-merge.git] / cc / layers / picture_image_layer_impl_unittest.cc
blob2a9dda710db53b5cb2a8712e6e44bc76e947d10e
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/layers/picture_image_layer_impl.h"
7 #include "base/thread_task_runner_handle.h"
8 #include "cc/layers/append_quads_data.h"
9 #include "cc/quads/draw_quad.h"
10 #include "cc/test/fake_impl_proxy.h"
11 #include "cc/test/fake_layer_tree_host_impl.h"
12 #include "cc/test/fake_output_surface.h"
13 #include "cc/test/fake_picture_pile_impl.h"
14 #include "cc/test/test_shared_bitmap_manager.h"
15 #include "cc/test/test_task_graph_runner.h"
16 #include "cc/tiles/tile_priority.h"
17 #include "cc/trees/layer_tree_impl.h"
18 #include "testing/gtest/include/gtest/gtest.h"
20 namespace cc {
21 namespace {
23 class TestablePictureImageLayerImpl : public PictureImageLayerImpl {
24 public:
25 TestablePictureImageLayerImpl(LayerTreeImpl* tree_impl, int id)
26 : PictureImageLayerImpl(tree_impl, id, false) {}
27 using PictureLayerImpl::UpdateIdealScales;
28 using PictureLayerImpl::MaximumTilingContentsScale;
30 PictureLayerTilingSet* tilings() { return tilings_.get(); }
32 friend class PictureImageLayerImplTest;
35 class PictureLayerImplImageTestSettings : public LayerTreeSettings {
36 public:
37 PictureLayerImplImageTestSettings() {
38 layer_transforms_should_scale_layer_contents = true;
42 class PictureImageLayerImplTest : public testing::Test {
43 public:
44 PictureImageLayerImplTest()
45 : proxy_(base::ThreadTaskRunnerHandle::Get()),
46 host_impl_(PictureLayerImplImageTestSettings(),
47 &proxy_,
48 &shared_bitmap_manager_,
49 &task_graph_runner_) {
50 host_impl_.CreatePendingTree();
51 host_impl_.InitializeRenderer(FakeOutputSurface::Create3d());
54 scoped_ptr<TestablePictureImageLayerImpl> CreateLayer(int id,
55 WhichTree which_tree) {
56 LayerTreeImpl* tree = nullptr;
57 switch (which_tree) {
58 case ACTIVE_TREE:
59 tree = host_impl_.active_tree();
60 break;
61 case PENDING_TREE:
62 tree = host_impl_.pending_tree();
63 break;
65 TestablePictureImageLayerImpl* layer =
66 new TestablePictureImageLayerImpl(tree, id);
67 layer->raster_source_ = FakePicturePileImpl::CreateInfiniteFilledPile();
68 layer->SetBounds(layer->raster_source_->GetSize());
69 return make_scoped_ptr(layer);
72 void SetupDrawPropertiesAndUpdateTiles(TestablePictureImageLayerImpl* layer,
73 float ideal_contents_scale,
74 float device_scale_factor,
75 float page_scale_factor,
76 float maximum_animation_contents_scale,
77 bool animating_transform_to_screen,
78 gfx::Rect viewport_rect) {
79 gfx::Transform scale_transform;
80 scale_transform.Scale(ideal_contents_scale, ideal_contents_scale);
81 layer->draw_properties().target_space_transform = scale_transform;
82 DCHECK_EQ(layer->GetIdealContentsScale(), ideal_contents_scale);
83 layer->draw_properties().maximum_animation_contents_scale =
84 maximum_animation_contents_scale;
85 layer->draw_properties().screen_space_transform_is_animating =
86 animating_transform_to_screen;
87 layer->draw_properties().visible_layer_rect = viewport_rect;
88 bool resourceless_software_draw = false;
89 layer->UpdateTiles(resourceless_software_draw);
92 protected:
93 FakeImplProxy proxy_;
94 TestSharedBitmapManager shared_bitmap_manager_;
95 TestTaskGraphRunner task_graph_runner_;
96 FakeLayerTreeHostImpl host_impl_;
99 TEST_F(PictureImageLayerImplTest, CalculateContentsScale) {
100 scoped_ptr<TestablePictureImageLayerImpl> layer(CreateLayer(1, PENDING_TREE));
101 layer->SetDrawsContent(true);
103 gfx::Rect viewport(100, 200);
104 SetupDrawPropertiesAndUpdateTiles(
105 layer.get(), 2.f, 3.f, 4.f, 1.f, false, viewport);
106 EXPECT_FLOAT_EQ(1.f, layer->MaximumTilingContentsScale());
109 TEST_F(PictureImageLayerImplTest, IgnoreIdealContentScale) {
110 scoped_ptr<TestablePictureImageLayerImpl> pending_layer(
111 CreateLayer(1, PENDING_TREE));
112 pending_layer->SetDrawsContent(true);
114 gfx::Rect viewport(100, 200);
116 // Set PictureLayerImpl::ideal_contents_scale_ to 2.f which is not equal
117 // to the content scale used by PictureImageLayerImpl.
118 const float suggested_ideal_contents_scale = 2.f;
119 const float device_scale_factor = 3.f;
120 const float page_scale_factor = 4.f;
121 const float maximum_animation_contents_scale = 1.f;
122 const bool animating_transform_to_screen = false;
123 SetupDrawPropertiesAndUpdateTiles(pending_layer.get(),
124 suggested_ideal_contents_scale,
125 device_scale_factor,
126 page_scale_factor,
127 maximum_animation_contents_scale,
128 animating_transform_to_screen,
129 viewport);
130 EXPECT_EQ(1.f, pending_layer->tilings()->tiling_at(0)->contents_scale());
132 // Push to active layer.
133 host_impl_.pending_tree()->SetRootLayer(pending_layer.Pass());
134 host_impl_.ActivateSyncTree();
136 TestablePictureImageLayerImpl* active_layer =
137 static_cast<TestablePictureImageLayerImpl*>(
138 host_impl_.active_tree()->root_layer());
139 SetupDrawPropertiesAndUpdateTiles(active_layer,
140 suggested_ideal_contents_scale,
141 device_scale_factor,
142 page_scale_factor,
143 maximum_animation_contents_scale,
144 animating_transform_to_screen,
145 viewport);
146 EXPECT_EQ(1.f, active_layer->tilings()->tiling_at(0)->contents_scale());
148 // Create resources for the tiles.
149 host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(
150 active_layer->tilings()->tiling_at(0)->AllTilesForTesting());
152 // Draw.
153 scoped_ptr<RenderPass> render_pass = RenderPass::Create();
154 AppendQuadsData data;
155 active_layer->WillDraw(DRAW_MODE_SOFTWARE, nullptr);
156 active_layer->AppendQuads(render_pass.get(), &data);
157 active_layer->DidDraw(nullptr);
159 EXPECT_EQ(DrawQuad::TILED_CONTENT, render_pass->quad_list.front()->material);
161 // Tiles are ready at correct scale, so should not set had_incomplete_tile.
162 EXPECT_EQ(0, data.num_incomplete_tiles);
165 } // namespace
166 } // namespace cc