Index: sky/shell/ui/animator.cc |
diff --git a/sky/shell/ui/animator.cc b/sky/shell/ui/animator.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..1af21042cbffa119e79260badf7d72f4bcb8909b |
--- /dev/null |
+++ b/sky/shell/ui/animator.cc |
@@ -0,0 +1,59 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "sky/shell/ui/animator.h" |
+ |
+#include "base/bind.h" |
+#include "base/message_loop/message_loop.h" |
+ |
+namespace sky { |
+namespace shell { |
+ |
+Animator::Animator(const Engine::Config& config, Engine* engine) |
+ : config_(config), |
+ engine_(engine), |
+ frame_requested_(false), |
+ frame_pending_(false), |
+ weak_factory_(this) { |
+} |
+ |
+Animator::~Animator() { |
+} |
+ |
+void Animator::RequestFrame() { |
+ if (frame_requested_) |
+ return; |
+ frame_requested_ = true; |
+ |
+ if (!frame_pending_) { |
+ frame_pending_ = true; |
+ base::MessageLoop::current()->PostTask( |
+ FROM_HERE, |
+ base::Bind(&Animator::BeginFrame, weak_factory_.GetWeakPtr())); |
+ } |
+} |
+ |
+void Animator::BeginFrame() { |
+ DCHECK(frame_pending_); |
+ DCHECK(frame_requested_); |
+ frame_requested_ = false; |
+ |
+ engine_->BeginFrame(base::TimeTicks::Now()); |
+ config_.gpu_task_runner->PostTaskAndReply( |
+ FROM_HERE, |
+ base::Bind(&GPUDelegate::Draw, config_.gpu_delegate, engine_->Paint()), |
+ base::Bind(&Animator::OnFrameComplete, weak_factory_.GetWeakPtr())); |
+} |
+ |
+void Animator::OnFrameComplete() { |
+ DCHECK(frame_pending_); |
+ frame_pending_ = false; |
+ if (frame_requested_) { |
+ frame_pending_ = true; |
+ BeginFrame(); |
+ } |
+} |
+ |
+} // namespace shell |
+} // namespace sky |