Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(24)

Side by Side Diff: webkit/compositor_bindings/web_layer_impl_fixed_bounds_unittest.cc

Issue 12326022: Efficiently handle image layer scaling (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix win warnings Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webkit/compositor_bindings/web_layer_impl_fixed_bounds.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 "cc/test/geometry_test_utils.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "third_party/WebKit/Source/Platform/chromium/public/WebFloatPoint.h"
10 #include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h"
11 #include "third_party/WebKit/Source/Platform/chromium/public/WebTransformationMa trix.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 namespace WebKit;
17
18 TEST(WebLayerImplFixedBoundsTest, IdentityBounds) {
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 gfx::Point3F TransformPoint(const gfx::Transform& transform,
29 const gfx::Point3F& point) {
30 gfx::Point3F result = point;
31 transform.TransformPoint(result);
32 return result;
33 }
34
35 void CheckBoundsScaleSimple(WebLayerImplFixedBounds* layer,
36 const WebSize& bounds,
37 const gfx::Size& fixed_bounds) {
38 layer->setBounds(bounds);
39 layer->SetFixedBounds(fixed_bounds);
40
41 EXPECT_EQ(bounds, layer->bounds());
42 EXPECT_EQ(fixed_bounds, layer->layer()->bounds());
43 EXPECT_TRUE(layer->transform().isIdentity());
44 EXPECT_TRUE(layer->sublayerTransform().isIdentity());
45
46 // An arbitrary point to check the scale and transforms.
47 gfx::Point3F original_point(10, 20, 1);
48 gfx::Point3F scaled_point(
49 original_point.x() * bounds.width / fixed_bounds.width(),
50 original_point.y() * bounds.height / fixed_bounds.height(),
51 original_point.z());
52 // Test if the bounds scale is correctly applied in transform and
53 // sublayerTransform.
54 EXPECT_POINT3F_EQ(scaled_point,
55 TransformPoint(layer->layer()->transform(),
56 original_point));
57 EXPECT_POINT3F_EQ(original_point,
58 TransformPoint(layer->layer()->sublayerTransform(),
59 scaled_point));
60 }
61
62 TEST(WebLayerImplFixedBoundsTest, BoundsScaleSimple) {
63 scoped_ptr<WebLayerImplFixedBounds> layer(new WebLayerImplFixedBounds());
64 layer->setAnchorPoint(WebFloatPoint(0, 0));
65 CheckBoundsScaleSimple(layer.get(), WebSize(100, 200), gfx::Size(150, 250));
66 // Change fixedBounds.
67 CheckBoundsScaleSimple(layer.get(), WebSize(100, 200), gfx::Size(75, 100));
68 // Change bounds.
69 CheckBoundsScaleSimple(layer.get(), WebSize(300, 100), gfx::Size(75, 100));
70 }
71
72 void ExpectEqualLayerRectsInTarget(cc::Layer* layer1, cc::Layer* layer2) {
73 gfx::RectF layer1_rect_in_target(layer1->contentBounds());
74 layer1->drawTransform().TransformRect(&layer1_rect_in_target);
75
76 gfx::RectF layer2_rect_in_target(layer2->contentBounds());
77 layer2->drawTransform().TransformRect(&layer2_rect_in_target);
78
79 EXPECT_FLOAT_RECT_EQ(layer1_rect_in_target, layer2_rect_in_target);
80 }
81
82 void CompareFixedBoundsLayerAndNormalLayer(
83 const WebFloatPoint& anchor_point,
84 const gfx::Transform& transform,
85 const gfx::Transform& sublayer_transform) {
86 const gfx::Size kDeviceViewportSize(800, 600);
87 const float kDeviceScaleFactor = 2.f;
88 const float kPageScaleFactor = 1.5f;
89 const int kMaxTextureSize = 512;
90
91 WebSize bounds(150, 200);
92 WebFloatPoint position(20, 30);
93 WebSize sublayer_bounds(88, 99);
94 WebFloatPoint sublayer_position(50, 60);
95 gfx::Size fixed_bounds(160, 70);
96
97 scoped_ptr<WebLayerImplFixedBounds> root_layer(new WebLayerImplFixedBounds());
98
99 WebLayerImplFixedBounds* fixed_bounds_layer =
100 new WebLayerImplFixedBounds(cc::PictureImageLayer::create());
101 WebLayerImpl* sublayer_under_fixed_bounds_layer = new WebLayerImpl();
102 sublayer_under_fixed_bounds_layer->setBounds(sublayer_bounds);
103 sublayer_under_fixed_bounds_layer->setPosition(sublayer_position);
104 fixed_bounds_layer->addChild(sublayer_under_fixed_bounds_layer);
105 fixed_bounds_layer->setBounds(bounds);
106 fixed_bounds_layer->SetFixedBounds(fixed_bounds);
107 fixed_bounds_layer->setAnchorPoint(anchor_point);
108 fixed_bounds_layer->setTransform(transform.matrix());
109 fixed_bounds_layer->setSublayerTransform(sublayer_transform.matrix());
110 fixed_bounds_layer->setPosition(position);
111 root_layer->addChild(fixed_bounds_layer);
112
113 WebLayerImpl* normal_layer(new WebLayerImpl(cc::PictureImageLayer::create()));
114 WebLayerImpl* sublayer_under_normal_layer = new WebLayerImpl();
115 sublayer_under_normal_layer->setBounds(sublayer_bounds);
116 sublayer_under_normal_layer->setPosition(sublayer_position);
117
118 normal_layer->addChild(sublayer_under_normal_layer);
119 normal_layer->setBounds(bounds);
120 normal_layer->setAnchorPoint(anchor_point);
121 normal_layer->setTransform(transform.matrix());
122 normal_layer->setSublayerTransform(sublayer_transform.matrix());
123 normal_layer->setPosition(position);
124 root_layer->addChild(normal_layer);
125
126 std::vector<scoped_refptr<cc::Layer> > renderSurfaceLayerList;
127 cc::LayerTreeHostCommon::calculateDrawProperties(
128 root_layer->layer(),
129 kDeviceViewportSize,
130 kDeviceScaleFactor,
131 kPageScaleFactor,
132 kMaxTextureSize,
133 false,
134 renderSurfaceLayerList);
135 ExpectEqualLayerRectsInTarget(normal_layer->layer(),
136 fixed_bounds_layer->layer());
137 ExpectEqualLayerRectsInTarget(sublayer_under_normal_layer->layer(),
138 sublayer_under_fixed_bounds_layer->layer());
139
140 // Change of fixed bounds should not affect the target geometries.
141 fixed_bounds_layer->SetFixedBounds(gfx::Size(fixed_bounds.width() / 2,
142 fixed_bounds.height() * 2));
143 cc::LayerTreeHostCommon::calculateDrawProperties(
144 root_layer->layer(),
145 kDeviceViewportSize,
146 kDeviceScaleFactor,
147 kPageScaleFactor,
148 kMaxTextureSize,
149 false,
150 renderSurfaceLayerList);
151 ExpectEqualLayerRectsInTarget(normal_layer->layer(),
152 fixed_bounds_layer->layer());
153 ExpectEqualLayerRectsInTarget(sublayer_under_normal_layer->layer(),
154 sublayer_under_fixed_bounds_layer->layer());
155
156 }
157
158 // A black box test that ensures WebLayerImplFixedBounds won't change target
159 // geometries. Simple case: identity transforms and zero anchor point.
160 TEST(WebLayerImplFixedBoundsTest, CompareToWebLayerImplSimple) {
161 CompareFixedBoundsLayerAndNormalLayer(WebFloatPoint(0, 0),
162 gfx::Transform(),
163 gfx::Transform());
164 }
165
166 // A black box test that ensures WebLayerImplFixedBounds won't change target
167 // geometries. Complex case: complex transforms and non-zero anchor point.
168 TEST(WebLayerImplFixedBoundsTest, CompareToWebLayerImplComplex) {
169 gfx::Transform transform;
170 // These are arbitrary values that should not affect the results.
171 transform.Translate3d(50, 60, 70);
172 transform.Scale3d(2, 3, 4);
173 transform.RotateAbout(gfx::Vector3dF(33, 44, 55), 99);
174
175 gfx::Transform sublayer_transform;
176 // These are arbitrary values that should not affect the results.
177 sublayer_transform.Scale3d(1.1, 2.2, 3.3);
178 sublayer_transform.Translate3d(11, 22, 33);
179 sublayer_transform.RotateAbout(gfx::Vector3dF(10, 30, 20), 88);
180
181 CompareFixedBoundsLayerAndNormalLayer(WebFloatPoint(0, 0),
182 transform,
183 sublayer_transform);
184
185 // With non-zero anchor point, WebLayerImplFixedBounds will fall back to
186 // WebLayerImpl.
187 CompareFixedBoundsLayerAndNormalLayer(WebFloatPoint(0.4f, 0.6f),
188 transform,
189 sublayer_transform);
190 }
OLDNEW
« no previous file with comments | « webkit/compositor_bindings/web_layer_impl_fixed_bounds.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698