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