Revert "Reland c91b178b07b0d - Delete dead signin code (SigninGlobalError)"
[chromium-blink-merge.git] / cc / test / layer_tree_host_common_test.cc
blobd0dc494973296ec77128638143863610e4a525fa
1 // Copyright 2014 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/layer_tree_host_common_test.h"
7 #include "cc/layers/layer.h"
8 #include "cc/layers/layer_impl.h"
9 #include "cc/test/fake_layer_tree_host.h"
10 #include "cc/trees/draw_property_utils.h"
11 #include "cc/trees/layer_tree_host_common.h"
13 namespace cc {
15 LayerTreeHostCommonTestBase::LayerTreeHostCommonTestBase(
16 const LayerTreeSettings& settings)
17 : LayerTestCommon::LayerImplTest(settings),
18 render_surface_layer_list_count_(0) {
21 LayerTreeHostCommonTestBase::~LayerTreeHostCommonTestBase() {
24 void LayerTreeHostCommonTestBase::SetLayerPropertiesForTesting(
25 Layer* layer,
26 const gfx::Transform& transform,
27 const gfx::Point3F& transform_origin,
28 const gfx::PointF& position,
29 const gfx::Size& bounds,
30 bool flatten_transform,
31 bool is_3d_sorted) {
32 SetLayerPropertiesForTestingInternal(layer, transform, transform_origin,
33 position, bounds, flatten_transform,
34 is_3d_sorted);
37 void LayerTreeHostCommonTestBase::SetLayerPropertiesForTesting(
38 LayerImpl* layer,
39 const gfx::Transform& transform,
40 const gfx::Point3F& transform_origin,
41 const gfx::PointF& position,
42 const gfx::Size& bounds,
43 bool flatten_transform,
44 bool is_3d_sorted,
45 bool create_render_surface) {
46 SetLayerPropertiesForTestingInternal(layer, transform, transform_origin,
47 position, bounds, flatten_transform,
48 is_3d_sorted);
49 if (create_render_surface) {
50 layer->SetHasRenderSurface(true);
54 void LayerTreeHostCommonTestBase::ExecuteCalculateDrawProperties(
55 Layer* root_layer,
56 float device_scale_factor,
57 float page_scale_factor,
58 Layer* page_scale_layer,
59 bool can_use_lcd_text,
60 bool layers_always_allowed_lcd_text) {
61 LayerTreeHostCommon::PreCalculateMetaInformation(root_layer);
63 EXPECT_TRUE(page_scale_layer || (page_scale_factor == 1.f));
64 gfx::Transform identity_matrix;
65 gfx::Size device_viewport_size =
66 gfx::Size(root_layer->bounds().width() * device_scale_factor,
67 root_layer->bounds().height() * device_scale_factor);
69 // We are probably not testing what is intended if the root_layer bounds are
70 // empty.
71 DCHECK(!root_layer->bounds().IsEmpty());
72 LayerTreeHostCommon::CalcDrawPropsMainInputs inputs(root_layer,
73 device_viewport_size);
74 inputs.device_scale_factor = device_scale_factor;
75 inputs.page_scale_factor = page_scale_factor;
76 inputs.page_scale_layer = page_scale_layer;
77 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
80 void LayerTreeHostCommonTestBase::
81 ExecuteCalculateDrawPropertiesWithPropertyTrees(Layer* root_layer) {
82 DCHECK(root_layer->layer_tree_host());
83 LayerTreeHostCommon::PreCalculateMetaInformation(root_layer);
85 gfx::Transform identity_transform;
86 bool preserves_2d_axis_alignment = false;
87 bool can_render_to_separate_surface = true;
88 LayerTreeHostCommon::UpdateRenderSurfaces(
89 root_layer, can_render_to_separate_surface, identity_transform,
90 preserves_2d_axis_alignment);
92 Layer* page_scale_layer = nullptr;
93 Layer* inner_viewport_scroll_layer =
94 root_layer->layer_tree_host()->inner_viewport_scroll_layer();
95 Layer* outer_viewport_scroll_layer =
96 root_layer->layer_tree_host()->outer_viewport_scroll_layer();
97 float page_scale_factor = 1.f;
98 float device_scale_factor = 1.f;
99 gfx::Size device_viewport_size =
100 gfx::Size(root_layer->bounds().width() * device_scale_factor,
101 root_layer->bounds().height() * device_scale_factor);
102 BuildPropertyTreesAndComputeVisibleRects(
103 root_layer, page_scale_layer, inner_viewport_scroll_layer,
104 outer_viewport_scroll_layer, page_scale_factor, device_scale_factor,
105 gfx::Rect(device_viewport_size), identity_transform,
106 root_layer->layer_tree_host()->property_trees(), &update_layer_list_);
109 void LayerTreeHostCommonTestBase::
110 ExecuteCalculateDrawPropertiesWithPropertyTrees(LayerImpl* root_layer) {
111 DCHECK(root_layer->layer_tree_impl());
112 LayerTreeHostCommon::PreCalculateMetaInformationForTesting(root_layer);
114 gfx::Transform identity_transform;
115 LayerImpl* page_scale_layer = nullptr;
116 LayerImpl* inner_viewport_scroll_layer =
117 root_layer->layer_tree_impl()->InnerViewportScrollLayer();
118 LayerImpl* outer_viewport_scroll_layer =
119 root_layer->layer_tree_impl()->OuterViewportScrollLayer();
120 float page_scale_factor = 1.f;
121 float device_scale_factor = 1.f;
122 gfx::Size device_viewport_size =
123 gfx::Size(root_layer->bounds().width() * device_scale_factor,
124 root_layer->bounds().height() * device_scale_factor);
125 std::vector<LayerImpl*> update_layer_list;
126 BuildPropertyTreesAndComputeVisibleRects(
127 root_layer, page_scale_layer, inner_viewport_scroll_layer,
128 outer_viewport_scroll_layer, page_scale_factor, device_scale_factor,
129 gfx::Rect(device_viewport_size), identity_transform,
130 root_layer->layer_tree_impl()->property_trees(), &update_layer_list);
133 void LayerTreeHostCommonTestBase::ExecuteCalculateDrawProperties(
134 LayerImpl* root_layer,
135 float device_scale_factor,
136 float page_scale_factor,
137 LayerImpl* page_scale_layer,
138 bool can_use_lcd_text,
139 bool layers_always_allowed_lcd_text) {
140 host_impl()->SetDeviceScaleFactor(device_scale_factor);
141 host_impl()->SetPageScaleOnActiveTree(page_scale_factor);
143 gfx::Transform identity_matrix;
144 gfx::Size device_viewport_size =
145 gfx::Size(root_layer->bounds().width() * device_scale_factor,
146 root_layer->bounds().height() * device_scale_factor);
148 render_surface_layer_list_impl_.reset(new LayerImplList);
150 // We are probably not testing what is intended if the root_layer bounds are
151 // empty.
152 DCHECK(!root_layer->bounds().IsEmpty());
153 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
154 root_layer, device_viewport_size, render_surface_layer_list_impl_.get());
155 inputs.device_scale_factor = device_scale_factor;
156 inputs.page_scale_factor = page_scale_factor;
157 inputs.page_scale_layer = page_scale_layer;
158 inputs.can_use_lcd_text = can_use_lcd_text;
159 inputs.layers_always_allowed_lcd_text = layers_always_allowed_lcd_text;
160 inputs.can_adjust_raster_scales = true;
162 ++render_surface_layer_list_count_;
163 inputs.current_render_surface_layer_list_id =
164 render_surface_layer_list_count_;
166 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
169 bool LayerTreeHostCommonTestBase::UpdateLayerListContains(int id) const {
170 for (size_t i = 0; i < update_layer_list_.size(); ++i) {
171 if (update_layer_list_[i]->id() == id)
172 return true;
174 return false;
177 LayerTreeHostCommonTest::LayerTreeHostCommonTest()
178 : LayerTreeHostCommonTestBase(LayerTreeSettings()) {
181 LayerTreeHostCommonTest::LayerTreeHostCommonTest(
182 const LayerTreeSettings& settings)
183 : LayerTreeHostCommonTestBase(settings) {
186 } // namespace cc