| OLD | NEW |
| (Empty) |
| 1 // Copyright 2013 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 <vector> | |
| 6 #include "cc/layers/picture_image_layer.h" | |
| 7 #include "cc/test/geometry_test_utils.h" | |
| 8 #include "cc/trees/layer_tree_host_common.h" | |
| 9 #include "testing/gtest/include/gtest/gtest.h" | |
| 10 #include "third_party/WebKit/Source/Platform/chromium/public/WebFloatPoint.h" | |
| 11 #include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h" | |
| 12 #include "third_party/skia/include/utils/SkMatrix44.h" | |
| 13 #include "ui/gfx/point3_f.h" | |
| 14 #include "webkit/compositor_bindings/web_layer_impl_fixed_bounds.h" | |
| 15 | |
| 16 using WebKit::WebFloatPoint; | |
| 17 using WebKit::WebSize; | |
| 18 | |
| 19 namespace webkit { | |
| 20 namespace { | |
| 21 | |
| 22 TEST(WebLayerImplFixedBoundsTest, IdentityBounds) { | |
| 23 scoped_ptr<WebLayerImplFixedBounds> layer(new WebLayerImplFixedBounds()); | |
| 24 layer->setAnchorPoint(WebFloatPoint(0, 0)); | |
| 25 layer->SetFixedBounds(gfx::Size(100, 100)); | |
| 26 layer->setBounds(WebSize(100, 100)); | |
| 27 EXPECT_EQ(WebSize(100, 100), layer->bounds()); | |
| 28 EXPECT_EQ(gfx::Size(100, 100), layer->layer()->bounds()); | |
| 29 EXPECT_EQ(gfx::Transform(), layer->layer()->transform()); | |
| 30 } | |
| 31 | |
| 32 gfx::Point3F TransformPoint(const gfx::Transform& transform, | |
| 33 const gfx::Point3F& point) { | |
| 34 gfx::Point3F result = point; | |
| 35 transform.TransformPoint(result); | |
| 36 return result; | |
| 37 } | |
| 38 | |
| 39 void CheckBoundsScaleSimple(WebLayerImplFixedBounds* layer, | |
| 40 const WebSize& bounds, | |
| 41 const gfx::Size& fixed_bounds) { | |
| 42 layer->setBounds(bounds); | |
| 43 layer->SetFixedBounds(fixed_bounds); | |
| 44 | |
| 45 EXPECT_EQ(bounds, layer->bounds()); | |
| 46 EXPECT_EQ(fixed_bounds, layer->layer()->bounds()); | |
| 47 EXPECT_TRUE(layer->transform().isIdentity()); | |
| 48 EXPECT_TRUE(layer->sublayerTransform().isIdentity()); | |
| 49 | |
| 50 // An arbitrary point to check the scale and transforms. | |
| 51 gfx::Point3F original_point(10, 20, 1); | |
| 52 gfx::Point3F scaled_point( | |
| 53 original_point.x() * bounds.width / fixed_bounds.width(), | |
| 54 original_point.y() * bounds.height / fixed_bounds.height(), | |
| 55 original_point.z()); | |
| 56 // Test if the bounds scale is correctly applied in transform and | |
| 57 // sublayerTransform. | |
| 58 EXPECT_POINT3F_EQ(scaled_point, | |
| 59 TransformPoint(layer->layer()->transform(), | |
| 60 original_point)); | |
| 61 EXPECT_POINT3F_EQ(original_point, | |
| 62 TransformPoint(layer->layer()->sublayer_transform(), | |
| 63 scaled_point)); | |
| 64 } | |
| 65 | |
| 66 TEST(WebLayerImplFixedBoundsTest, BoundsScaleSimple) { | |
| 67 scoped_ptr<WebLayerImplFixedBounds> layer(new WebLayerImplFixedBounds()); | |
| 68 layer->setAnchorPoint(WebFloatPoint(0, 0)); | |
| 69 CheckBoundsScaleSimple(layer.get(), WebSize(100, 200), gfx::Size(150, 250)); | |
| 70 // Change fixed_bounds. | |
| 71 CheckBoundsScaleSimple(layer.get(), WebSize(100, 200), gfx::Size(75, 100)); | |
| 72 // Change bounds. | |
| 73 CheckBoundsScaleSimple(layer.get(), WebSize(300, 100), gfx::Size(75, 100)); | |
| 74 } | |
| 75 | |
| 76 void ExpectEqualLayerRectsInTarget(cc::Layer* layer1, cc::Layer* layer2) { | |
| 77 gfx::RectF layer1_rect_in_target(layer1->content_bounds()); | |
| 78 layer1->draw_transform().TransformRect(&layer1_rect_in_target); | |
| 79 | |
| 80 gfx::RectF layer2_rect_in_target(layer2->content_bounds()); | |
| 81 layer2->draw_transform().TransformRect(&layer2_rect_in_target); | |
| 82 | |
| 83 EXPECT_FLOAT_RECT_EQ(layer1_rect_in_target, layer2_rect_in_target); | |
| 84 } | |
| 85 | |
| 86 void CompareFixedBoundsLayerAndNormalLayer( | |
| 87 const WebFloatPoint& anchor_point, | |
| 88 const gfx::Transform& transform, | |
| 89 const gfx::Transform& sublayer_transform) { | |
| 90 const gfx::Size kDeviceViewportSize(800, 600); | |
| 91 const float kDeviceScaleFactor = 2.f; | |
| 92 const float kPageScaleFactor = 1.5f; | |
| 93 const int kMaxTextureSize = 512; | |
| 94 | |
| 95 WebSize bounds(150, 200); | |
| 96 WebFloatPoint position(20, 30); | |
| 97 WebSize sublayer_bounds(88, 99); | |
| 98 WebFloatPoint sublayer_position(50, 60); | |
| 99 gfx::Size fixed_bounds(160, 70); | |
| 100 | |
| 101 scoped_ptr<WebLayerImplFixedBounds> root_layer(new WebLayerImplFixedBounds()); | |
| 102 | |
| 103 WebLayerImplFixedBounds* fixed_bounds_layer = | |
| 104 new WebLayerImplFixedBounds(cc::PictureImageLayer::Create()); | |
| 105 WebLayerImpl* sublayer_under_fixed_bounds_layer = new WebLayerImpl(); | |
| 106 sublayer_under_fixed_bounds_layer->setBounds(sublayer_bounds); | |
| 107 sublayer_under_fixed_bounds_layer->setPosition(sublayer_position); | |
| 108 fixed_bounds_layer->addChild(sublayer_under_fixed_bounds_layer); | |
| 109 fixed_bounds_layer->setBounds(bounds); | |
| 110 fixed_bounds_layer->SetFixedBounds(fixed_bounds); | |
| 111 fixed_bounds_layer->setAnchorPoint(anchor_point); | |
| 112 fixed_bounds_layer->setTransform(transform.matrix()); | |
| 113 fixed_bounds_layer->setSublayerTransform(sublayer_transform.matrix()); | |
| 114 fixed_bounds_layer->setPosition(position); | |
| 115 root_layer->addChild(fixed_bounds_layer); | |
| 116 | |
| 117 WebLayerImpl* normal_layer(new WebLayerImpl(cc::PictureImageLayer::Create())); | |
| 118 WebLayerImpl* sublayer_under_normal_layer = new WebLayerImpl(); | |
| 119 sublayer_under_normal_layer->setBounds(sublayer_bounds); | |
| 120 sublayer_under_normal_layer->setPosition(sublayer_position); | |
| 121 | |
| 122 normal_layer->addChild(sublayer_under_normal_layer); | |
| 123 normal_layer->setBounds(bounds); | |
| 124 normal_layer->setAnchorPoint(anchor_point); | |
| 125 normal_layer->setTransform(transform.matrix()); | |
| 126 normal_layer->setSublayerTransform(sublayer_transform.matrix()); | |
| 127 normal_layer->setPosition(position); | |
| 128 root_layer->addChild(normal_layer); | |
| 129 | |
| 130 std::vector<scoped_refptr<cc::Layer> > render_surface_layer_list; | |
| 131 cc::LayerTreeHostCommon::CalculateDrawProperties( | |
| 132 root_layer->layer(), | |
| 133 kDeviceViewportSize, | |
| 134 kDeviceScaleFactor, | |
| 135 kPageScaleFactor, | |
| 136 root_layer->layer(), | |
| 137 kMaxTextureSize, | |
| 138 false, // can_use_lcd_text | |
| 139 false, // can_adjust_raster_scales | |
| 140 &render_surface_layer_list); | |
| 141 ExpectEqualLayerRectsInTarget(normal_layer->layer(), | |
| 142 fixed_bounds_layer->layer()); | |
| 143 ExpectEqualLayerRectsInTarget(sublayer_under_normal_layer->layer(), | |
| 144 sublayer_under_fixed_bounds_layer->layer()); | |
| 145 | |
| 146 // Change of fixed bounds should not affect the target geometries. | |
| 147 fixed_bounds_layer->SetFixedBounds(gfx::Size(fixed_bounds.width() / 2, | |
| 148 fixed_bounds.height() * 2)); | |
| 149 cc::LayerTreeHostCommon::CalculateDrawProperties( | |
| 150 root_layer->layer(), | |
| 151 kDeviceViewportSize, | |
| 152 kDeviceScaleFactor, | |
| 153 kPageScaleFactor, | |
| 154 root_layer->layer(), | |
| 155 kMaxTextureSize, | |
| 156 false, // can_use_lcd_text | |
| 157 false, // can_adjust_raster_scales | |
| 158 &render_surface_layer_list); | |
| 159 ExpectEqualLayerRectsInTarget(normal_layer->layer(), | |
| 160 fixed_bounds_layer->layer()); | |
| 161 ExpectEqualLayerRectsInTarget(sublayer_under_normal_layer->layer(), | |
| 162 sublayer_under_fixed_bounds_layer->layer()); | |
| 163 } | |
| 164 | |
| 165 // A black box test that ensures WebLayerImplFixedBounds won't change target | |
| 166 // geometries. Simple case: identity transforms and zero anchor point. | |
| 167 TEST(WebLayerImplFixedBoundsTest, CompareToWebLayerImplSimple) { | |
| 168 CompareFixedBoundsLayerAndNormalLayer(WebFloatPoint(0, 0), | |
| 169 gfx::Transform(), | |
| 170 gfx::Transform()); | |
| 171 } | |
| 172 | |
| 173 // A black box test that ensures WebLayerImplFixedBounds won't change target | |
| 174 // geometries. Complex case: complex transforms and non-zero anchor point. | |
| 175 TEST(WebLayerImplFixedBoundsTest, CompareToWebLayerImplComplex) { | |
| 176 gfx::Transform transform; | |
| 177 // These are arbitrary values that should not affect the results. | |
| 178 transform.Translate3d(50, 60, 70); | |
| 179 transform.Scale3d(2, 3, 4); | |
| 180 transform.RotateAbout(gfx::Vector3dF(33, 44, 55), 99); | |
| 181 | |
| 182 gfx::Transform sublayer_transform; | |
| 183 // These are arbitrary values that should not affect the results. | |
| 184 sublayer_transform.Scale3d(1.1, 2.2, 3.3); | |
| 185 sublayer_transform.Translate3d(11, 22, 33); | |
| 186 sublayer_transform.RotateAbout(gfx::Vector3dF(10, 30, 20), 88); | |
| 187 | |
| 188 CompareFixedBoundsLayerAndNormalLayer(WebFloatPoint(0, 0), | |
| 189 transform, | |
| 190 sublayer_transform); | |
| 191 | |
| 192 // With non-zero anchor point, WebLayerImplFixedBounds will fall back to | |
| 193 // WebLayerImpl. | |
| 194 CompareFixedBoundsLayerAndNormalLayer(WebFloatPoint(0.4f, 0.6f), | |
| 195 transform, | |
| 196 sublayer_transform); | |
| 197 } | |
| 198 | |
| 199 } // namespace | |
| 200 } // namespace webkit | |
| OLD | NEW |