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

Unified Diff: content/browser/renderer_host/begin_frame_observer_proxy.cc

Issue 1000503002: Add BeginFrameObserverProxy (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rename to BeginFrameObserverProxy Created 5 years, 9 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: content/browser/renderer_host/begin_frame_observer_proxy.cc
diff --git a/content/browser/renderer_host/begin_frame_observer_proxy.cc b/content/browser/renderer_host/begin_frame_observer_proxy.cc
new file mode 100644
index 0000000000000000000000000000000000000000..7a6651f53c3a9faf6d55e981e1838d333563dd5a
--- /dev/null
+++ b/content/browser/renderer_host/begin_frame_observer_proxy.cc
@@ -0,0 +1,70 @@
+// 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 "content/browser/renderer_host/begin_frame_observer_proxy.h"
+
+namespace content {
+
+BeginFrameObserverProxy::BeginFrameObserverProxy(
+ BeginFrameObserverProxyClient* client)
+ : needs_begin_frames_(false),
+ client_(client),
+ compositor_(nullptr) {
+}
+
+BeginFrameObserverProxy::~BeginFrameObserverProxy() {
+}
+
+void BeginFrameObserverProxy::SetNeedsBeginFrames(bool needs_begin_frames) {
+ if (needs_begin_frames_ == needs_begin_frames)
+ return;
+
+ needs_begin_frames_ = needs_begin_frames;
+
+ // In some cases, BeginFrame message is requested before |client_|'s window is
+ // added in the root window hierarchy.
+ if (!compositor_)
+ return;
+
+ if (needs_begin_frames)
+ StartObservingBeginFrames();
+ else
+ StopObservingBeginFrames();
+}
+
+void BeginFrameObserverProxy::SetCompositor(ui::Compositor* compositor) {
+ DCHECK(!compositor_);
+ DCHECK(compositor);
+
+ compositor_ = compositor;
+ if (needs_begin_frames_)
+ StartObservingBeginFrames();
+}
+
+void BeginFrameObserverProxy::ResetCompositor() {
+ if (!compositor_)
+ return;
+
+ if (needs_begin_frames_)
+ StopObservingBeginFrames();
+ compositor_ = nullptr;
+}
+
+void BeginFrameObserverProxy::OnSendBeginFrame(const cc::BeginFrameArgs& args) {
+ if (last_sent_begin_frame_args_.frame_time != args.frame_time)
+ client_->SendBeginFrame(args);
+ last_sent_begin_frame_args_ = args;
+}
+
+void BeginFrameObserverProxy::StartObservingBeginFrames() {
+ DCHECK(compositor_);
+ compositor_->AddBeginFrameObserver(this);
+}
+
+void BeginFrameObserverProxy::StopObservingBeginFrames() {
+ DCHECK(compositor_);
+ compositor_->RemoveBeginFrameObserver(this);
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698