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/layer_tree_host_common.h"
14 LayerTreeHostCommonTestBase::LayerTreeHostCommonTestBase()
15 : client_(FakeLayerTreeHostClient::DIRECT_3D
),
16 render_surface_layer_list_count_(0) {
19 LayerTreeHostCommonTestBase::~LayerTreeHostCommonTestBase() {
22 void LayerTreeHostCommonTestBase::SetLayerPropertiesForTesting(
24 const gfx::Transform
& transform
,
25 const gfx::Point3F
& transform_origin
,
26 const gfx::PointF
& position
,
27 const gfx::Size
& bounds
,
28 bool flatten_transform
,
30 SetLayerPropertiesForTestingInternal(layer
, transform
, transform_origin
,
31 position
, bounds
, flatten_transform
,
35 void LayerTreeHostCommonTestBase::SetLayerPropertiesForTesting(
37 const gfx::Transform
& transform
,
38 const gfx::Point3F
& transform_origin
,
39 const gfx::PointF
& position
,
40 const gfx::Size
& bounds
,
41 bool flatten_transform
,
43 bool create_render_surface
) {
44 SetLayerPropertiesForTestingInternal(layer
, transform
, transform_origin
,
45 position
, bounds
, flatten_transform
,
47 if (create_render_surface
) {
48 layer
->SetHasRenderSurface(true);
51 layer
->SetContentBounds(bounds
);
54 void LayerTreeHostCommonTestBase::ExecuteCalculateDrawProperties(
56 float device_scale_factor
,
57 float page_scale_factor
,
58 Layer
* page_scale_application_layer
,
59 bool can_use_lcd_text
,
60 bool layers_always_allowed_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
);
67 render_surface_layer_list_
.reset(new RenderSurfaceLayerList
);
69 // We are probably not testing what is intended if the root_layer bounds are
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
.layers_always_allowed_lcd_text
= layers_always_allowed_lcd_text
;
79 inputs
.can_adjust_raster_scales
= true;
80 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
83 void LayerTreeHostCommonTestBase::ExecuteCalculateDrawProperties(
84 LayerImpl
* root_layer
,
85 float device_scale_factor
,
86 float page_scale_factor
,
87 LayerImpl
* page_scale_application_layer
,
88 bool can_use_lcd_text
,
89 bool layers_always_allowed_lcd_text
) {
90 gfx::Transform identity_matrix
;
91 gfx::Size device_viewport_size
=
92 gfx::Size(root_layer
->bounds().width() * device_scale_factor
,
93 root_layer
->bounds().height() * device_scale_factor
);
95 render_surface_layer_list_impl_
.reset(new LayerImplList
);
97 // We are probably not testing what is intended if the root_layer bounds are
99 DCHECK(!root_layer
->bounds().IsEmpty());
100 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting
inputs(
101 root_layer
, device_viewport_size
, render_surface_layer_list_impl_
.get());
102 inputs
.device_scale_factor
= device_scale_factor
;
103 inputs
.page_scale_factor
= page_scale_factor
;
104 inputs
.page_scale_application_layer
= page_scale_application_layer
;
105 inputs
.can_use_lcd_text
= can_use_lcd_text
;
106 inputs
.layers_always_allowed_lcd_text
= layers_always_allowed_lcd_text
;
107 inputs
.can_adjust_raster_scales
= true;
109 ++render_surface_layer_list_count_
;
110 inputs
.current_render_surface_layer_list_id
=
111 render_surface_layer_list_count_
;
113 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
116 scoped_ptr
<FakeLayerTreeHost
>
117 LayerTreeHostCommonTestBase::CreateFakeLayerTreeHost() {
118 return FakeLayerTreeHost::Create(&client_
);