• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef CC_TEST_LAYER_TREE_HOST_COMMON_TEST_H_
6 #define CC_TEST_LAYER_TREE_HOST_COMMON_TEST_H_
7 
8 #include <vector>
9 
10 #include "base/memory/scoped_ptr.h"
11 #include "cc/layers/layer_lists.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13 
14 namespace gfx {
15 class PointF;
16 class Point3F;
17 class Size;
18 class Transform;
19 }
20 
21 namespace cc {
22 
23 class Layer;
24 class LayerImpl;
25 class RenderSurfaceLayerList;
26 
27 class LayerTreeHostCommonTestBase {
28  protected:
29   LayerTreeHostCommonTestBase();
30   virtual ~LayerTreeHostCommonTestBase();
31 
32   template <typename LayerType>
SetLayerPropertiesForTestingInternal(LayerType * 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)33   void SetLayerPropertiesForTestingInternal(
34       LayerType* layer,
35       const gfx::Transform& transform,
36       const gfx::Point3F& transform_origin,
37       const gfx::PointF& position,
38       const gfx::Size& bounds,
39       bool flatten_transform,
40       bool is_3d_sorted) {
41     layer->SetTransform(transform);
42     layer->SetTransformOrigin(transform_origin);
43     layer->SetPosition(position);
44     layer->SetBounds(bounds);
45     layer->SetShouldFlattenTransform(flatten_transform);
46     layer->Set3dSortingContextId(is_3d_sorted ? 1 : 0);
47   }
48 
49   void SetLayerPropertiesForTesting(Layer* layer,
50                                     const gfx::Transform& transform,
51                                     const gfx::Point3F& transform_origin,
52                                     const gfx::PointF& position,
53                                     const gfx::Size& bounds,
54                                     bool flatten_transform,
55                                     bool is_3d_sorted);
56 
57   void SetLayerPropertiesForTesting(LayerImpl* layer,
58                                     const gfx::Transform& transform,
59                                     const gfx::Point3F& transform_origin,
60                                     const gfx::PointF& position,
61                                     const gfx::Size& bounds,
62                                     bool flatten_transform,
63                                     bool is_3d_sorted);
64 
65   void ExecuteCalculateDrawProperties(Layer* root_layer,
66                                       float device_scale_factor,
67                                       float page_scale_factor,
68                                       Layer* page_scale_application_layer,
69                                       bool can_use_lcd_text);
70 
71   void ExecuteCalculateDrawProperties(LayerImpl* root_layer,
72                                       float device_scale_factor,
73                                       float page_scale_factor,
74                                       LayerImpl* page_scale_application_layer,
75                                       bool can_use_lcd_text);
76 
77   template <class LayerType>
ExecuteCalculateDrawProperties(LayerType * root_layer)78   void ExecuteCalculateDrawProperties(LayerType* root_layer) {
79     LayerType* page_scale_application_layer = NULL;
80     ExecuteCalculateDrawProperties(
81         root_layer, 1.f, 1.f, page_scale_application_layer, false);
82   }
83 
84   template <class LayerType>
ExecuteCalculateDrawProperties(LayerType * root_layer,float device_scale_factor)85   void ExecuteCalculateDrawProperties(LayerType* root_layer,
86                                       float device_scale_factor) {
87     LayerType* page_scale_application_layer = NULL;
88     ExecuteCalculateDrawProperties(root_layer,
89                                    device_scale_factor,
90                                    1.f,
91                                    page_scale_application_layer,
92                                    false);
93   }
94 
95   template <class LayerType>
ExecuteCalculateDrawProperties(LayerType * root_layer,float device_scale_factor,float page_scale_factor,LayerType * page_scale_application_layer)96   void ExecuteCalculateDrawProperties(LayerType* root_layer,
97                                       float device_scale_factor,
98                                       float page_scale_factor,
99                                       LayerType* page_scale_application_layer) {
100     ExecuteCalculateDrawProperties(root_layer,
101                                    device_scale_factor,
102                                    page_scale_factor,
103                                    page_scale_application_layer,
104                                    false);
105   }
106 
render_surface_layer_list()107   RenderSurfaceLayerList* render_surface_layer_list() const {
108     return render_surface_layer_list_.get();
109   }
110 
render_surface_layer_list_impl()111   LayerImplList* render_surface_layer_list_impl() const {
112     return render_surface_layer_list_impl_.get();
113   }
114 
render_surface_layer_list_count()115   int render_surface_layer_list_count() const {
116     return render_surface_layer_list_count_;
117   }
118 
119  private:
120   scoped_ptr<RenderSurfaceLayerList> render_surface_layer_list_;
121   scoped_ptr<std::vector<LayerImpl*> > render_surface_layer_list_impl_;
122 
123   int render_surface_layer_list_count_;
124 };
125 
126 class LayerTreeHostCommonTest : public LayerTreeHostCommonTestBase,
127                                 public testing::Test {};
128 
129 }  // namespace cc
130 
131 #endif  // CC_TEST_LAYER_TREE_HOST_COMMON_TEST_H_
132