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.
4
5 #include "cc/test/layer_tree_host_common_test.h"
6
7 #include "cc/layers/layer.h"
8 #include "cc/layers/layer_impl.h"
9 #include "cc/trees/layer_tree_host_common.h"
10
11 namespace cc {
12
LayerTreeHostCommonTestBase()13 LayerTreeHostCommonTestBase::LayerTreeHostCommonTestBase()
14 : render_surface_layer_list_count_(0) {
15 }
16
~LayerTreeHostCommonTestBase()17 LayerTreeHostCommonTestBase::~LayerTreeHostCommonTestBase() {
18 }
19
SetLayerPropertiesForTesting(Layer * layer,const gfx::Transform & transform,const gfx::Point3F & transform_origin,const gfx::PointF & position,const gfx::Size & bounds,bool flatten_transform,bool is_3d_sorted)20 void LayerTreeHostCommonTestBase::SetLayerPropertiesForTesting(
21 Layer* layer,
22 const gfx::Transform& transform,
23 const gfx::Point3F& transform_origin,
24 const gfx::PointF& position,
25 const gfx::Size& bounds,
26 bool flatten_transform,
27 bool is_3d_sorted) {
28 SetLayerPropertiesForTestingInternal<Layer>(layer,
29 transform,
30 transform_origin,
31 position,
32 bounds,
33 flatten_transform,
34 is_3d_sorted);
35 }
36
SetLayerPropertiesForTesting(LayerImpl * layer,const gfx::Transform & transform,const gfx::Point3F & transform_origin,const gfx::PointF & position,const gfx::Size & bounds,bool flatten_transform,bool 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 SetLayerPropertiesForTestingInternal<LayerImpl>(layer,
46 transform,
47 transform_origin,
48 position,
49 bounds,
50 flatten_transform,
51 is_3d_sorted);
52 layer->SetContentBounds(bounds);
53 }
54
ExecuteCalculateDrawProperties(Layer * root_layer,float device_scale_factor,float page_scale_factor,Layer * page_scale_application_layer,bool can_use_lcd_text)55 void LayerTreeHostCommonTestBase::ExecuteCalculateDrawProperties(
56 Layer* root_layer,
57 float device_scale_factor,
58 float page_scale_factor,
59 Layer* page_scale_application_layer,
60 bool can_use_lcd_text) {
61 EXPECT_TRUE(page_scale_application_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);
66
67 render_surface_layer_list_.reset(new RenderSurfaceLayerList);
68
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_application_layer = page_scale_application_layer;
77 inputs.can_use_lcd_text = can_use_lcd_text;
78 inputs.can_adjust_raster_scales = true;
79 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
80 }
81
ExecuteCalculateDrawProperties(LayerImpl * root_layer,float device_scale_factor,float page_scale_factor,LayerImpl * page_scale_application_layer,bool can_use_lcd_text)82 void LayerTreeHostCommonTestBase::ExecuteCalculateDrawProperties(
83 LayerImpl* root_layer,
84 float device_scale_factor,
85 float page_scale_factor,
86 LayerImpl* page_scale_application_layer,
87 bool can_use_lcd_text) {
88 gfx::Transform identity_matrix;
89 gfx::Size device_viewport_size =
90 gfx::Size(root_layer->bounds().width() * device_scale_factor,
91 root_layer->bounds().height() * device_scale_factor);
92
93 render_surface_layer_list_impl_.reset(new LayerImplList);
94
95 // We are probably not testing what is intended if the root_layer bounds are
96 // empty.
97 DCHECK(!root_layer->bounds().IsEmpty());
98 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
99 root_layer, device_viewport_size, render_surface_layer_list_impl_.get());
100 inputs.device_scale_factor = device_scale_factor;
101 inputs.page_scale_factor = page_scale_factor;
102 inputs.page_scale_application_layer = page_scale_application_layer;
103 inputs.can_use_lcd_text = can_use_lcd_text;
104 inputs.can_adjust_raster_scales = true;
105
106 ++render_surface_layer_list_count_;
107 inputs.current_render_surface_layer_list_id =
108 render_surface_layer_list_count_;
109
110 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
111 }
112
113 } // namespace cc
114