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

Unified Diff: sky/shell/ui/animator.cc

Issue 936883002: Connect Sky and Ganesh in SkyShell (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: sort includes Created 5 years, 10 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 side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698