OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 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 #include <string> | 7 #include <string> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 11 #include "base/time/time.h" |
11 #include "base/values.h" | 12 #include "base/values.h" |
12 #include "chrome/browser/android/vr_shell/animation.h" | 13 #include "chrome/browser/android/vr_shell/animation.h" |
13 #include "chrome/browser/android/vr_shell/easing.h" | 14 #include "chrome/browser/android/vr_shell/easing.h" |
14 #include "chrome/browser/android/vr_shell/ui_elements.h" | 15 #include "chrome/browser/android/vr_shell/ui_elements.h" |
15 | 16 |
16 namespace vr_shell { | 17 namespace vr_shell { |
17 | 18 |
18 namespace { | 19 namespace { |
19 | 20 |
20 // Parse an integer to an int or enum value. | 21 // Parse an integer to an int or enum value. |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 std::unique_ptr<Animation> animation) { | 223 std::unique_ptr<Animation> animation) { |
223 ContentRectangle* element = GetUiElementById(element_id); | 224 ContentRectangle* element = GetUiElementById(element_id); |
224 CHECK_NE(element, nullptr); | 225 CHECK_NE(element, nullptr); |
225 for (auto& existing_animation : element->animations) { | 226 for (auto& existing_animation : element->animations) { |
226 CHECK_NE(existing_animation->id, animation->id); | 227 CHECK_NE(existing_animation->id, animation->id); |
227 } | 228 } |
228 element->animations.emplace_back(std::move(animation)); | 229 element->animations.emplace_back(std::move(animation)); |
229 } | 230 } |
230 | 231 |
231 void UiScene::AddAnimationFromDict(const base::DictionaryValue& dict, | 232 void UiScene::AddAnimationFromDict(const base::DictionaryValue& dict, |
232 int64_t time_in_micro) { | 233 const base::TimeTicks& current_time) { |
233 int animation_id; | 234 int animation_id; |
234 int element_id; | 235 int element_id; |
235 Animation::Property property; | 236 Animation::Property property; |
236 double start_time_ms; | 237 double start_time_ms; |
237 double duration_ms; | 238 double duration_ms; |
238 | 239 |
239 const base::DictionaryValue* easing_dict = nullptr; | 240 const base::DictionaryValue* easing_dict = nullptr; |
240 const base::DictionaryValue* from_dict = nullptr; | 241 const base::DictionaryValue* from_dict = nullptr; |
241 const base::DictionaryValue* to_dict = nullptr; | 242 const base::DictionaryValue* to_dict = nullptr; |
242 std::vector<float> from; | 243 std::vector<float> from; |
(...skipping 11 matching lines...) Expand all Loading... |
254 CHECK(dict.GetDictionary("to", &to_dict)); | 255 CHECK(dict.GetDictionary("to", &to_dict)); |
255 ParseEndpointToFloats(property, *to_dict, &to); | 256 ParseEndpointToFloats(property, *to_dict, &to); |
256 | 257 |
257 // The start location is optional. If not specified, the animation will | 258 // The start location is optional. If not specified, the animation will |
258 // start from the element's current location. | 259 // start from the element's current location. |
259 dict.GetDictionary("from", &from_dict); | 260 dict.GetDictionary("from", &from_dict); |
260 if (from_dict != nullptr) { | 261 if (from_dict != nullptr) { |
261 ParseEndpointToFloats(property, *from_dict, &from); | 262 ParseEndpointToFloats(property, *from_dict, &from); |
262 } | 263 } |
263 | 264 |
264 int64_t start = time_in_micro + (start_time_ms * 1000.0); | 265 base::TimeDelta delay = base::TimeDelta::FromMilliseconds(start_time_ms); |
265 int64_t duration = duration_ms * 1000.0; | 266 base::TimeTicks start = current_time + delay; |
| 267 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(duration_ms); |
266 | 268 |
267 ContentRectangle* element = GetUiElementById(element_id); | 269 ContentRectangle* element = GetUiElementById(element_id); |
268 CHECK_NE(element, nullptr); | 270 CHECK_NE(element, nullptr); |
269 element->animations.emplace_back(base::MakeUnique<Animation>( | 271 element->animations.emplace_back(base::MakeUnique<Animation>( |
270 animation_id, static_cast<Animation::Property>(property), | 272 animation_id, static_cast<Animation::Property>(property), |
271 std::move(easing), from, to, start, duration)); | 273 std::move(easing), from, to, start, duration)); |
272 } | 274 } |
273 | 275 |
274 void UiScene::RemoveAnimation(int element_id, int animation_id) { | 276 void UiScene::RemoveAnimation(int element_id, int animation_id) { |
275 ContentRectangle* element = GetUiElementById(element_id); | 277 ContentRectangle* element = GetUiElementById(element_id); |
276 CHECK_NE(element, nullptr); | 278 CHECK_NE(element, nullptr); |
277 auto& animations = element->animations; | 279 auto& animations = element->animations; |
278 for (auto it = animations.begin(); it != animations.end(); ++it) { | 280 for (auto it = animations.begin(); it != animations.end(); ++it) { |
279 const Animation& existing_animation = **it; | 281 const Animation& existing_animation = **it; |
280 if (existing_animation.id == animation_id) { | 282 if (existing_animation.id == animation_id) { |
281 animations.erase(it); | 283 animations.erase(it); |
282 return; | 284 return; |
283 } | 285 } |
284 } | 286 } |
285 } | 287 } |
286 | 288 |
287 void UiScene::HandleCommands(std::unique_ptr<base::ListValue> commands, | 289 void UiScene::HandleCommands(std::unique_ptr<base::ListValue> commands, |
288 int64_t time_in_micro) { | 290 const base::TimeTicks& time) { |
289 for (auto& item : *commands) { | 291 for (auto& item : *commands) { |
290 base::DictionaryValue* dict; | 292 base::DictionaryValue* dict; |
291 CHECK(item->GetAsDictionary(&dict)); | 293 CHECK(item->GetAsDictionary(&dict)); |
292 | 294 |
293 Command type; | 295 Command type; |
294 base::DictionaryValue* data; | 296 base::DictionaryValue* data; |
295 CHECK(ParseInt(*dict, "type", &type)); | 297 CHECK(ParseInt(*dict, "type", &type)); |
296 CHECK(dict->GetDictionary("data", &data)); | 298 CHECK(dict->GetDictionary("data", &data)); |
297 | 299 |
298 switch (type) { | 300 switch (type) { |
299 case Command::ADD_ELEMENT: | 301 case Command::ADD_ELEMENT: |
300 AddUiElementFromDict(*data); | 302 AddUiElementFromDict(*data); |
301 break; | 303 break; |
302 case Command::UPDATE_ELEMENT: | 304 case Command::UPDATE_ELEMENT: |
303 UpdateUiElementFromDict(*data); | 305 UpdateUiElementFromDict(*data); |
304 break; | 306 break; |
305 case Command::REMOVE_ELEMENT: { | 307 case Command::REMOVE_ELEMENT: { |
306 int element_id; | 308 int element_id; |
307 CHECK(ParseInt(*data, "id", &element_id)); | 309 CHECK(ParseInt(*data, "id", &element_id)); |
308 RemoveUiElement(element_id); | 310 RemoveUiElement(element_id); |
309 break; | 311 break; |
310 } | 312 } |
311 case Command::ADD_ANIMATION: | 313 case Command::ADD_ANIMATION: |
312 AddAnimationFromDict(*data, time_in_micro); | 314 AddAnimationFromDict(*data, time); |
313 break; | 315 break; |
314 case Command::REMOVE_ANIMATION: { | 316 case Command::REMOVE_ANIMATION: { |
315 int element_id, animation_id; | 317 int element_id, animation_id; |
316 CHECK(ParseInt(*data, "id", &animation_id)); | 318 CHECK(ParseInt(*data, "id", &animation_id)); |
317 CHECK(ParseInt(*data, "meshId", &element_id)); | 319 CHECK(ParseInt(*data, "meshId", &element_id)); |
318 RemoveAnimation(element_id, animation_id); | 320 RemoveAnimation(element_id, animation_id); |
319 break; | 321 break; |
320 } | 322 } |
321 case Command::CONFIGURE_SCENE: | 323 case Command::CONFIGURE_SCENE: |
322 ParseColorf(*data, "backgroundColor", &background_color_); | 324 ParseColorf(*data, "backgroundColor", &background_color_); |
323 ParseFloat(*data, "backgroundDistance", &background_distance_); | 325 ParseFloat(*data, "backgroundDistance", &background_distance_); |
324 data->GetBoolean("drawWebVr", &webvr_rendering_enabled_); | 326 data->GetBoolean("drawWebVr", &webvr_rendering_enabled_); |
325 break; | 327 break; |
326 } | 328 } |
327 } | 329 } |
328 } | 330 } |
329 | 331 |
330 void UiScene::UpdateTransforms(int64_t time_in_micro) { | 332 void UiScene::UpdateTransforms(const base::TimeTicks& time) { |
331 for (auto& element : ui_elements_) { | 333 for (auto& element : ui_elements_) { |
332 // Process all animations before calculating object transforms. | 334 // Process all animations before calculating object transforms. |
333 element->Animate(time_in_micro); | 335 element->Animate(time); |
334 element->dirty = true; | 336 element->dirty = true; |
335 } | 337 } |
336 for (auto& element : ui_elements_) { | 338 for (auto& element : ui_elements_) { |
337 ApplyRecursiveTransforms(element.get()); | 339 ApplyRecursiveTransforms(element.get()); |
338 } | 340 } |
339 } | 341 } |
340 | 342 |
341 ContentRectangle* UiScene::GetUiElementById(int element_id) { | 343 ContentRectangle* UiScene::GetUiElementById(int element_id) { |
342 for (auto& element : ui_elements_) { | 344 for (auto& element : ui_elements_) { |
343 if (element->id == element_id) { | 345 if (element->id == element_id) { |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
501 content_element_ = element; | 503 content_element_ = element; |
502 break; | 504 break; |
503 default: | 505 default: |
504 element->fill = Fill::NONE; | 506 element->fill = Fill::NONE; |
505 break; | 507 break; |
506 } | 508 } |
507 } | 509 } |
508 } | 510 } |
509 | 511 |
510 } // namespace vr_shell | 512 } // namespace vr_shell |
OLD | NEW |