OLD | NEW |
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/android/vr_shell/ui_scene.h" | 5 #include "chrome/browser/android/vr_shell/ui_scene.h" |
6 | 6 |
7 #define _USE_MATH_DEFINES // For M_PI in MSVC. | 7 #define _USE_MATH_DEFINES // For M_PI in MSVC. |
8 #include <cmath> | 8 #include <cmath> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 element->scale = {2, 2, 1}; | 118 element->scale = {2, 2, 1}; |
119 element->rotation = {0, 0, 1, M_PI / 2}; | 119 element->rotation = {0, 0, 1, M_PI / 2}; |
120 element->translation = {3, 0, 0}; | 120 element->translation = {3, 0, 0}; |
121 scene.AddUiElement(element); | 121 scene.AddUiElement(element); |
122 const ContentRectangle* child = scene.GetUiElementById(1); | 122 const ContentRectangle* child = scene.GetUiElementById(1); |
123 | 123 |
124 const gvr::Vec3f origin({0, 0, 0}); | 124 const gvr::Vec3f origin({0, 0, 0}); |
125 const gvr::Vec3f point({1, 0, 0}); | 125 const gvr::Vec3f point({1, 0, 0}); |
126 | 126 |
127 // Check resulting transform with no screen tilt. | 127 // Check resulting transform with no screen tilt. |
128 scene.UpdateTransforms(0, 0); | 128 scene.UpdateTransforms(0); |
129 auto new_origin = MatrixVectorMul(child->transform.to_world, origin); | 129 auto new_origin = MatrixVectorMul(child->TransformMatrix(), origin); |
130 auto new_point = MatrixVectorMul(child->transform.to_world, point); | 130 auto new_point = MatrixVectorMul(child->TransformMatrix(), point); |
131 EXPECT_VEC3F_NEAR(gvr::Vec3f({6, 10, 0}), new_origin); | 131 EXPECT_VEC3F_NEAR(gvr::Vec3f({6, 10, 0}), new_origin); |
132 EXPECT_VEC3F_NEAR(gvr::Vec3f({0, 10, 0}), new_point); | 132 EXPECT_VEC3F_NEAR(gvr::Vec3f({0, 10, 0}), new_point); |
133 | |
134 // Check with screen tilt (use 90 degrees for simplicity). | |
135 scene.UpdateTransforms(M_PI / 2, 0); | |
136 new_origin = MatrixVectorMul(child->transform.to_world, origin); | |
137 new_point = MatrixVectorMul(child->transform.to_world, point); | |
138 EXPECT_VEC3F_NEAR(gvr::Vec3f({6, 0, 10}), new_origin); | |
139 EXPECT_VEC3F_NEAR(gvr::Vec3f({0, 0, 10}), new_point); | |
140 } | 133 } |
141 | 134 |
142 TEST(UiScene, Opacity) { | 135 TEST(UiScene, Opacity) { |
143 UiScene scene; | 136 UiScene scene; |
144 std::unique_ptr<ContentRectangle> element; | 137 std::unique_ptr<ContentRectangle> element; |
145 | 138 |
146 element.reset(new ContentRectangle); | 139 element.reset(new ContentRectangle); |
147 element->id = 0; | 140 element->id = 0; |
148 element->opacity = 0.5; | 141 element->opacity = 0.5; |
149 scene.AddUiElement(element); | 142 scene.AddUiElement(element); |
150 | 143 |
151 element.reset(new ContentRectangle); | 144 element.reset(new ContentRectangle); |
152 element->id = 1; | 145 element->id = 1; |
153 element->parent_id = 0; | 146 element->parent_id = 0; |
154 element->opacity = 0.5; | 147 element->opacity = 0.5; |
155 scene.AddUiElement(element); | 148 scene.AddUiElement(element); |
156 | 149 |
157 scene.UpdateTransforms(0, 0); | 150 scene.UpdateTransforms(0); |
158 EXPECT_EQ(scene.GetUiElementById(0)->computed_opacity, 0.5f); | 151 EXPECT_EQ(scene.GetUiElementById(0)->computed_opacity, 0.5f); |
159 EXPECT_EQ(scene.GetUiElementById(1)->computed_opacity, 0.25f); | 152 EXPECT_EQ(scene.GetUiElementById(1)->computed_opacity, 0.25f); |
160 } | 153 } |
161 | 154 |
162 typedef struct { | 155 typedef struct { |
163 XAnchoring x_anchoring; | 156 XAnchoring x_anchoring; |
164 YAnchoring y_anchoring; | 157 YAnchoring y_anchoring; |
165 float expected_x; | 158 float expected_x; |
166 float expected_y; | 159 float expected_y; |
167 } AnchoringTestCase; | 160 } AnchoringTestCase; |
(...skipping 11 matching lines...) Expand all Loading... |
179 scene.AddUiElement(element); | 172 scene.AddUiElement(element); |
180 | 173 |
181 // Add a child to the parent, with anchoring. | 174 // Add a child to the parent, with anchoring. |
182 element.reset(new ContentRectangle); | 175 element.reset(new ContentRectangle); |
183 element->id = 1; | 176 element->id = 1; |
184 element->parent_id = 0; | 177 element->parent_id = 0; |
185 element->x_anchoring = GetParam().x_anchoring; | 178 element->x_anchoring = GetParam().x_anchoring; |
186 element->y_anchoring = GetParam().y_anchoring; | 179 element->y_anchoring = GetParam().y_anchoring; |
187 scene.AddUiElement(element); | 180 scene.AddUiElement(element); |
188 | 181 |
189 scene.UpdateTransforms(0, 0); | 182 scene.UpdateTransforms(0); |
190 const ContentRectangle* child = scene.GetUiElementById(1); | 183 const ContentRectangle* child = scene.GetUiElementById(1); |
191 EXPECT_NEAR(child->GetCenter().x, GetParam().expected_x, TOLERANCE); | 184 EXPECT_NEAR(child->GetCenter().x, GetParam().expected_x, TOLERANCE); |
192 EXPECT_NEAR(child->GetCenter().y, GetParam().expected_y, TOLERANCE); | 185 EXPECT_NEAR(child->GetCenter().y, GetParam().expected_y, TOLERANCE); |
193 scene.RemoveUiElement(1); | 186 scene.RemoveUiElement(1); |
194 } | 187 } |
195 | 188 |
196 const std::vector<AnchoringTestCase> anchoring_test_cases = { | 189 const std::vector<AnchoringTestCase> anchoring_test_cases = { |
197 {XAnchoring::XNONE, YAnchoring::YNONE, 0, 0}, | 190 {XAnchoring::XNONE, YAnchoring::YNONE, 0, 0}, |
198 {XAnchoring::XLEFT, YAnchoring::YNONE, -2, 0}, | 191 {XAnchoring::XLEFT, YAnchoring::YNONE, -2, 0}, |
199 {XAnchoring::XRIGHT, YAnchoring::YNONE, 2, 0}, | 192 {XAnchoring::XRIGHT, YAnchoring::YNONE, 2, 0}, |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 EXPECT_FLOAT_EQ(animation->from[0], 300); | 405 EXPECT_FLOAT_EQ(animation->from[0], 300); |
413 EXPECT_FLOAT_EQ(animation->from[1], 301); | 406 EXPECT_FLOAT_EQ(animation->from[1], 301); |
414 EXPECT_FLOAT_EQ(animation->from[2], 302); | 407 EXPECT_FLOAT_EQ(animation->from[2], 302); |
415 EXPECT_FLOAT_EQ(animation->from[3], 303); | 408 EXPECT_FLOAT_EQ(animation->from[3], 303); |
416 | 409 |
417 EXPECT_EQ(animation->start, 22345000); | 410 EXPECT_EQ(animation->start, 22345000); |
418 EXPECT_EQ(animation->duration, 54321000); | 411 EXPECT_EQ(animation->duration, 54321000); |
419 } | 412 } |
420 | 413 |
421 } // namespace vr_shell | 414 } // namespace vr_shell |
OLD | NEW |