Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. // Copyright 2013 The Flutter 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 "flutter/shell/common/vsync_waiter_fallback.h"
  6.  
  7. #include "flutter/fml/logging.h"
  8.  
  9. namespace shell {
  10. namespace {
  11.  
  12. static fml::TimePoint SnapToNextTick(fml::TimePoint value,
  13. fml::TimePoint tick_phase,
  14. fml::TimeDelta tick_interval) {
  15. fml::TimeDelta offset = (tick_phase - value) % tick_interval;
  16. if (offset != fml::TimeDelta::Zero())
  17. offset = offset + tick_interval;
  18. return value + offset;
  19. }
  20.  
  21. } // namespace
  22.  
  23. VsyncWaiterFallback::VsyncWaiterFallback(blink::TaskRunners task_runners)
  24. : VsyncWaiter(std::move(task_runners)), phase_(fml::TimePoint::Now()) {}
  25.  
  26. VsyncWaiterFallback::~VsyncWaiterFallback() = default;
  27.  
  28. // |shell::VsyncWaiter|
  29. void VsyncWaiterFallback::AwaitVSync() {
  30. constexpr fml::TimeDelta kSingleFrameInterval =
  31. fml::TimeDelta::FromSecondsF(1.0 / 60.0);
  32.  
  33. auto next =
  34. SnapToNextTick(fml::TimePoint::Now(), phase_, kSingleFrameInterval);
  35.  
  36. FireCallback(next, next + kSingleFrameInterval);
  37. }
  38.  
  39. } // namespace shell
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement