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 "cc/layer_tree_host_common.h" | |
6 #include "cc/picture_image_layer.h" | |
7 #include "testing/gtest/include/gtest/gtest.h" | |
8 #include "third_party/WebKit/Source/Platform/chromium/public/WebFloatPoint.h" | |
9 #include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h" | |
10 #include "third_party/WebKit/Source/Platform/chromium/public/WebTransformationMa trix.h" | |
11 #include "third_party/skia/include/utils/SkMatrix44.h" | |
12 #include "ui/gfx/point3_f.h" | |
13 #include "webkit/compositor_bindings/web_layer_impl_fixed_bounds.h" | |
14 | |
15 using namespace WebKit; | |
16 | |
17 TEST(WebLayerImplFixedBoundsTest, IdentityBounds) | |
18 { | |
19 scoped_ptr<WebLayerImplFixedBounds> layer(new WebLayerImplFixedBounds()); | |
20 layer->setAnchorPoint(WebFloatPoint(0, 0)); | |
21 layer->setFixedBounds(gfx::Size(100, 100)); | |
22 layer->setBounds(WebSize(100, 100)); | |
23 EXPECT_EQ(WebSize(100, 100), layer->bounds()); | |
24 EXPECT_EQ(gfx::Size(100, 100), layer->layer()->bounds()); | |
25 EXPECT_EQ(gfx::Transform(), layer->layer()->transform()); | |
26 } | |
27 | |
28 #define EXPECT_POINT3F_EQ(p1, p2) \ | |
enne (OOO)
2013/02/22 23:53:32
Can you put these in geometry_test_utils.h?
Xianzhu
2013/02/23 00:56:19
Done.
| |
29 EXPECT_FLOAT_EQ((p1).x(), (p2).x()); \ | |
30 EXPECT_FLOAT_EQ((p1).y(), (p2).y()); \ | |
31 EXPECT_FLOAT_EQ((p1).z(), (p2).z()); | |
32 | |
33 #define EXPECT_RECTF_EQ(r1, r2) \ | |
34 EXPECT_FLOAT_EQ((r1).x(), (r2).x()); \ | |
35 EXPECT_FLOAT_EQ((r1).y(), (r2).y()); \ | |
36 EXPECT_FLOAT_EQ((r1).width(), (r2).width()); \ | |
37 EXPECT_FLOAT_EQ((r1).height(), (r2).height()); | |
38 | |
39 gfx::Point3F transformPoint(const gfx::Transform& transform, const gfx::Point3F& point) | |
enne (OOO)
2013/02/22 23:53:32
style nits:
80 columns everywhere in this file, p
Xianzhu
2013/02/23 00:05:20
I thought all files under the directory should fol
Xianzhu
2013/02/23 00:56:19
Converted this file into Chromium style.
Still ke
enne (OOO)
2013/02/23 01:10:55
As jamesr says, new code should be Chromium style,
| |
40 { | |
41 gfx::Point3F result = point; | |
42 transform.TransformPoint(result); | |
43 return result; | |
44 } | |
45 | |
46 void checkBoundsScaleSimple(WebLayerImplFixedBounds* layer, | |
47 const WebSize& bounds, | |
48 const gfx::Size& fixedBounds) | |
49 { | |
50 layer->setBounds(bounds); | |
51 layer->setFixedBounds(fixedBounds); | |
52 | |
53 EXPECT_EQ(bounds, layer->bounds()); | |
54 EXPECT_EQ(fixedBounds, layer->layer()->bounds()); | |
55 EXPECT_TRUE(layer->transform().isIdentity()); | |
56 EXPECT_TRUE(layer->sublayerTransform().isIdentity()); | |
57 | |
58 // An arbitrary point to check the scale and transforms. | |
59 gfx::Point3F originalPoint(10, 20, 1); | |
60 gfx::Point3F scaledPoint(originalPoint.x() * bounds.width / fixedBounds.widt h(), | |
61 originalPoint.y() * bounds.height / fixedBounds.hei ght(), | |
62 originalPoint.z()); | |
63 // Test if the bounds scale is correctly applied in transform and sublayerTr ansform. | |
64 EXPECT_POINT3F_EQ(scaledPoint, transformPoint(layer->layer()->transform(), o riginalPoint)); | |
65 EXPECT_POINT3F_EQ(originalPoint, transformPoint(layer->layer()->sublayerTran sform(), scaledPoint)); | |
66 } | |
67 | |
68 TEST(WebLayerImplFixedBoundsTest, BoundsScaleSimple) | |
69 { | |
70 scoped_ptr<WebLayerImplFixedBounds> layer(new WebLayerImplFixedBounds()); | |
71 layer->setAnchorPoint(WebFloatPoint(0, 0)); | |
72 // All numbers below are arbitrary values that should not affect the results . | |
73 checkBoundsScaleSimple(layer.get(), WebSize(100, 200), gfx::Size(150, 250)); | |
74 // Change fixedBounds. | |
75 checkBoundsScaleSimple(layer.get(), WebSize(100, 200), gfx::Size(75, 100)); | |
76 // Change bounds. | |
77 checkBoundsScaleSimple(layer.get(), WebSize(300, 100), gfx::Size(75, 100)); | |
78 } | |
79 | |
80 void compareToWebLayerImpl(const WebFloatPoint& anchorPoint, | |
enne (OOO)
2013/02/22 23:53:32
This function is great. That's exactly what I was
| |
81 const gfx::Transform& transform, | |
82 const gfx::Transform& sublayerTransform) | |
83 { | |
84 const gfx::Size deviceViewportSize(800, 600); | |
85 const float deviceScaleFactor = 1.f; // 2.f; | |
86 const float pageScaleFactor = 1.f; // 1.5f; | |
87 const int maxTextureSize = 512; | |
88 | |
89 WebSize bounds(100, 100); // (150, 200); | |
90 WebFloatPoint position(20, 30); | |
91 WebSize sublayerBounds(88, 99); | |
92 WebFloatPoint sublayerPosition(50, 60); | |
93 gfx::Size fixedBounds(200, 200); // (160, 70); | |
enne (OOO)
2013/02/22 23:53:32
Are these debug comments that should be removed?
Xianzhu
2013/02/23 00:56:19
Done.
| |
94 | |
95 scoped_ptr<WebLayerImplFixedBounds> rootLayer(new WebLayerImplFixedBounds()) ; | |
96 | |
97 WebLayerImplFixedBounds* fixedBoundsLayer = new WebLayerImplFixedBounds(cc:: PictureImageLayer::create()); | |
98 WebLayerImpl* sublayerUnderFixedBoundsLayer = new WebLayerImpl(); | |
99 sublayerUnderFixedBoundsLayer->setBounds(sublayerBounds); | |
100 sublayerUnderFixedBoundsLayer->setPosition(sublayerPosition); | |
101 sublayerUnderFixedBoundsLayer->setDebugName("sublayerUnderFixedBoundsLayer") ; | |
102 fixedBoundsLayer->setDebugName("fixedBoundsLayer"); | |
103 fixedBoundsLayer->addChild(sublayerUnderFixedBoundsLayer); | |
104 fixedBoundsLayer->setBounds(bounds); | |
105 fixedBoundsLayer->setFixedBounds(fixedBounds); | |
106 fixedBoundsLayer->setAnchorPoint(anchorPoint); | |
107 fixedBoundsLayer->setTransform(transform.matrix()); | |
108 fixedBoundsLayer->setSublayerTransform(sublayerTransform.matrix()); | |
109 fixedBoundsLayer->setPosition(position); | |
110 rootLayer->addChild(fixedBoundsLayer); | |
111 | |
112 WebLayerImpl* normalLayer(new WebLayerImpl(cc::PictureImageLayer::create())) ; | |
113 WebLayerImpl* sublayerUnderNormalLayer = new WebLayerImpl(); | |
114 sublayerUnderNormalLayer->setBounds(sublayerBounds); | |
115 sublayerUnderNormalLayer->setPosition(sublayerPosition); | |
116 sublayerUnderNormalLayer->setDebugName("sublayerUnderNormalLayer"); | |
117 normalLayer->setDebugName("normalLayer"); | |
118 normalLayer->addChild(sublayerUnderNormalLayer); | |
119 normalLayer->setBounds(bounds); | |
120 normalLayer->setAnchorPoint(anchorPoint); | |
121 normalLayer->setTransform(transform.matrix()); | |
122 normalLayer->setSublayerTransform(sublayerTransform.matrix()); | |
123 normalLayer->setPosition(position); | |
124 rootLayer->addChild(normalLayer); | |
125 | |
126 std::vector<scoped_refptr<cc::Layer> > renderSurfaceLayerList; | |
127 cc::LayerTreeHostCommon::calculateDrawProperties(rootLayer->layer(), deviceV iewportSize, deviceScaleFactor, pageScaleFactor, maxTextureSize, false, renderSu rfaceLayerList); | |
128 | |
129 gfx::RectF fixedBoundsLayerContentRect(fixedBoundsLayer->layer()->contentBou nds()); | |
enne (OOO)
2013/02/22 23:53:32
Content rects are not guaranteed to be the same.
| |
130 fixedBoundsLayer->layer()->drawTransform().TransformRect(&fixedBoundsLayerCo ntentRect); | |
131 gfx::RectF normalLayerContentRect(normalLayer->layer()->contentBounds()); | |
132 normalLayer->layer()->drawTransform().TransformRect(&normalLayerContentRect) ; | |
enne (OOO)
2013/02/22 23:55:44
Oh, scratch my previous comment. Can you not name
Xianzhu
2013/02/23 00:56:19
Done.
| |
133 EXPECT_RECTF_EQ(fixedBoundsLayerContentRect, normalLayerContentRect); | |
134 | |
135 gfx::RectF subLayerUnderFixedBoundsLayerContentRect(sublayerUnderFixedBounds Layer->layer()->contentBounds()); | |
136 sublayerUnderFixedBoundsLayer->layer()->drawTransform().TransformRect(&subLa yerUnderFixedBoundsLayerContentRect); | |
137 gfx::RectF subLayerUnderNormalLayerContentRect(sublayerUnderNormalLayer->lay er()->contentBounds()); | |
138 sublayerUnderNormalLayer->layer()->drawTransform().TransformRect(&subLayerUn derNormalLayerContentRect); | |
139 EXPECT_RECTF_EQ(subLayerUnderFixedBoundsLayerContentRect, subLayerUnderNorma lLayerContentRect); | |
140 } | |
141 | |
142 // A black box test that ensures WebLayerImplFixedBounds won't change final laye r geometries. | |
143 // Simple case: identity transforms and zero anchor point. | |
144 TEST(WebLayerImplFixedBoundsTest, CompareToWebLayerImplSimple) | |
145 { | |
146 compareToWebLayerImpl(WebFloatPoint(0, 0), gfx::Transform(), gfx::Transform( )); | |
147 } | |
148 | |
149 // A black box test that ensures WebLayerImplFixedBounds won't change final laye r geometries. | |
150 // Complex case: complex transforms and non-zero anchor point. | |
151 TEST(WebLayerImplFixedBoundsTest, CompareToWebLayerImplComplex) | |
152 { | |
153 gfx::Transform transform; | |
154 // These are arbitrary values that should not affect the results. | |
155 transform.Translate3d(50, 60, 70); | |
156 transform.Scale3d(1, 1, 1); | |
157 transform.RotateAbout(gfx::Vector3dF(33, 44, 55), 99); | |
158 | |
159 gfx::Transform sublayerTransform; | |
160 // These are arbitrary values that should not affect the results. | |
161 sublayerTransform.Scale3d(1, 2, 1);// (1.1, 2.2, 3.3); | |
162 sublayerTransform.Translate3d(11, 22, 33); | |
163 sublayerTransform.RotateAbout(gfx::Vector3dF(10, 30, 20), 88); | |
164 | |
165 compareToWebLayerImpl(WebFloatPoint(0, 0), transform, sublayerTransform); | |
166 | |
167 // With non-zero anchor point, WebLayerImplFixedBounds will fall back to Web LayerImpl. | |
168 compareToWebLayerImpl(WebFloatPoint(0.4, 0.6), transform, sublayerTransform) ; | |
169 } | |
OLD | NEW |