Update V8 to version 4.6.62.
[chromium-blink-merge.git] / cc / test / layer_tree_host_common_test.cc
blob1cde940b4ee228e783199aa505c58db0c88ecb65
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 EXPECT_TRUE(page_scale_layer || (page_scale_factor == 1.f));
62 gfx::Transform identity_matrix;
63 gfx::Size device_viewport_size =
64 gfx::Size(root_layer->bounds().width() * device_scale_factor,
65 root_layer->bounds().height() * device_scale_factor);
67 render_surface_layer_list_.reset(new RenderSurfaceLayerList);
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::CalcDrawPropsMainInputsForTesting inputs(
73 root_layer, device_viewport_size, render_surface_layer_list_.get());
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 inputs.can_use_lcd_text = can_use_lcd_text;
78 inputs.layers_always_allowed_lcd_text = layers_always_allowed_lcd_text;
79 inputs.can_adjust_raster_scales = true;
80 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
83 void LayerTreeHostCommonTestBase::
84 ExecuteCalculateDrawPropertiesWithPropertyTrees(Layer* root_layer) {
85 DCHECK(root_layer->layer_tree_host());
86 LayerTreeHostCommon::PreCalculateMetaInformation(root_layer);
88 gfx::Transform identity_transform;
89 bool preserves_2d_axis_alignment = false;
90 bool can_render_to_separate_surface = true;
91 LayerTreeHostCommon::UpdateRenderSurfaces(
92 root_layer, can_render_to_separate_surface, identity_transform,
93 preserves_2d_axis_alignment);
95 Layer* page_scale_layer = nullptr;
96 Layer* inner_viewport_scroll_layer =
97 root_layer->layer_tree_host()->inner_viewport_scroll_layer();
98 Layer* outer_viewport_scroll_layer =
99 root_layer->layer_tree_host()->outer_viewport_scroll_layer();
100 float page_scale_factor = 1.f;
101 float device_scale_factor = 1.f;
102 gfx::Size device_viewport_size =
103 gfx::Size(root_layer->bounds().width() * device_scale_factor,
104 root_layer->bounds().height() * device_scale_factor);
105 BuildPropertyTreesAndComputeVisibleRects(
106 root_layer, page_scale_layer, inner_viewport_scroll_layer,
107 outer_viewport_scroll_layer, page_scale_factor, device_scale_factor,
108 gfx::Rect(device_viewport_size), identity_transform,
109 root_layer->layer_tree_host()->property_trees(), &update_layer_list_);
112 void LayerTreeHostCommonTestBase::
113 ExecuteCalculateDrawPropertiesWithPropertyTrees(LayerImpl* root_layer) {
114 DCHECK(root_layer->layer_tree_impl());
115 LayerTreeHostCommon::PreCalculateMetaInformationForTesting(root_layer);
117 gfx::Transform identity_transform;
118 LayerImpl* page_scale_layer = nullptr;
119 LayerImpl* inner_viewport_scroll_layer =
120 root_layer->layer_tree_impl()->InnerViewportScrollLayer();
121 LayerImpl* outer_viewport_scroll_layer =
122 root_layer->layer_tree_impl()->OuterViewportScrollLayer();
123 float page_scale_factor = 1.f;
124 float device_scale_factor = 1.f;
125 gfx::Size device_viewport_size =
126 gfx::Size(root_layer->bounds().width() * device_scale_factor,
127 root_layer->bounds().height() * device_scale_factor);
128 std::vector<LayerImpl*> update_layer_list;
129 BuildPropertyTreesAndComputeVisibleRects(
130 root_layer, page_scale_layer, inner_viewport_scroll_layer,
131 outer_viewport_scroll_layer, page_scale_factor, device_scale_factor,
132 gfx::Rect(device_viewport_size), identity_transform,
133 root_layer->layer_tree_impl()->property_trees(), &update_layer_list);
136 void LayerTreeHostCommonTestBase::ExecuteCalculateDrawProperties(
137 LayerImpl* root_layer,
138 float device_scale_factor,
139 float page_scale_factor,
140 LayerImpl* page_scale_layer,
141 bool can_use_lcd_text,
142 bool layers_always_allowed_lcd_text) {
143 host_impl()->SetDeviceScaleFactor(device_scale_factor);
144 host_impl()->SetPageScaleOnActiveTree(page_scale_factor);
146 gfx::Transform identity_matrix;
147 gfx::Size device_viewport_size =
148 gfx::Size(root_layer->bounds().width() * device_scale_factor,
149 root_layer->bounds().height() * device_scale_factor);
151 render_surface_layer_list_impl_.reset(new LayerImplList);
153 // We are probably not testing what is intended if the root_layer bounds are
154 // empty.
155 DCHECK(!root_layer->bounds().IsEmpty());
156 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
157 root_layer, device_viewport_size, render_surface_layer_list_impl_.get());
158 inputs.device_scale_factor = device_scale_factor;
159 inputs.page_scale_factor = page_scale_factor;
160 inputs.page_scale_layer = page_scale_layer;
161 inputs.can_use_lcd_text = can_use_lcd_text;
162 inputs.layers_always_allowed_lcd_text = layers_always_allowed_lcd_text;
163 inputs.can_adjust_raster_scales = true;
165 ++render_surface_layer_list_count_;
166 inputs.current_render_surface_layer_list_id =
167 render_surface_layer_list_count_;
169 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
172 bool LayerTreeHostCommonTestBase::UpdateLayerListContains(int id) const {
173 for (size_t i = 0; i < update_layer_list_.size(); ++i) {
174 if (update_layer_list_[i]->id() == id)
175 return true;
177 return false;
180 LayerTreeHostCommonTest::LayerTreeHostCommonTest()
181 : LayerTreeHostCommonTestBase(LayerTreeSettings()) {
184 LayerTreeHostCommonTest::LayerTreeHostCommonTest(
185 const LayerTreeSettings& settings)
186 : LayerTreeHostCommonTestBase(settings) {
189 } // namespace cc