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

Side by Side Diff: content/browser/renderer_host/begin_frame_observer_proxy.cc

Issue 1408213002: Add hooks for flushing input from BeginFrame dispatch on Aura (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix build for real Created 5 years, 1 month 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "content/browser/renderer_host/begin_frame_observer_proxy.h" 5 #include "content/browser/renderer_host/begin_frame_observer_proxy.h"
6 6
7 namespace content { 7 namespace content {
8 8
9 BeginFrameObserverProxy::BeginFrameObserverProxy( 9 BeginFrameObserverProxy::BeginFrameObserverProxy(
10 BeginFrameObserverProxyClient* client) 10 BeginFrameObserverProxyClient* client)
11 : needs_begin_frames_(false), 11 : needs_begin_frames_(false),
12 needs_one_begin_frame_(false),
13 observing_begin_frames_(false),
12 client_(client), 14 client_(client),
13 compositor_(nullptr) { 15 compositor_(nullptr) {}
14 }
15 16
16 BeginFrameObserverProxy::~BeginFrameObserverProxy() { 17 BeginFrameObserverProxy::~BeginFrameObserverProxy() {
17 DCHECK(!compositor_); 18 DCHECK(!compositor_);
18 } 19 }
19 20
20 void BeginFrameObserverProxy::SetNeedsBeginFrames(bool needs_begin_frames) { 21 void BeginFrameObserverProxy::SetNeedsBeginFrames(bool needs_begin_frames) {
21 if (needs_begin_frames_ == needs_begin_frames) 22 if (needs_begin_frames_ == needs_begin_frames)
22 return; 23 return;
23 24
24 needs_begin_frames_ = needs_begin_frames; 25 needs_begin_frames_ = needs_begin_frames;
26 UpdateBeginFrameObservation();
27 }
25 28
26 // In some cases, BeginFrame message is requested before |client_|'s window is 29 void BeginFrameObserverProxy::SetNeedsOneBeginFrame() {
27 // added in the root window hierarchy. 30 if (needs_one_begin_frame_)
28 if (!compositor_)
29 return; 31 return;
30 32
31 if (needs_begin_frames) 33 needs_one_begin_frame_ = true;
32 StartObservingBeginFrames(); 34 UpdateBeginFrameObservation();
33 else
34 StopObservingBeginFrames();
35 } 35 }
36 36
37 void BeginFrameObserverProxy::SetCompositor(ui::Compositor* compositor) { 37 void BeginFrameObserverProxy::SetCompositor(ui::Compositor* compositor) {
38 DCHECK(!compositor_); 38 DCHECK(!compositor_);
39 DCHECK(compositor); 39 DCHECK(compositor);
40 40
41 compositor_ = compositor; 41 compositor_ = compositor;
42 compositor_->AddObserver(this); 42 compositor_->AddObserver(this);
43 if (needs_begin_frames_) 43 UpdateBeginFrameObservation();
44 StartObservingBeginFrames();
45 } 44 }
46 45
47 void BeginFrameObserverProxy::ResetCompositor() { 46 void BeginFrameObserverProxy::ResetCompositor() {
48 if (!compositor_) 47 if (!compositor_)
49 return; 48 return;
50 compositor_->RemoveObserver(this); 49 compositor_->RemoveObserver(this);
51 50 StopObservingBeginFrames();
52 if (needs_begin_frames_)
53 StopObservingBeginFrames();
54 compositor_ = nullptr; 51 compositor_ = nullptr;
55 } 52 }
56 53
57 void BeginFrameObserverProxy::OnSendBeginFrame(const cc::BeginFrameArgs& args) { 54 void BeginFrameObserverProxy::OnSendBeginFrame(const cc::BeginFrameArgs& args) {
58 if (last_sent_begin_frame_args_.frame_time != args.frame_time) 55 DCHECK(needs_one_begin_frame_ || needs_begin_frames_);
56 if (last_sent_begin_frame_args_.frame_time != args.frame_time) {
57 // Don't immediately unsubscribe in case BeginFrame dispatch triggers
58 // another request.
59 needs_one_begin_frame_ = false;
59 client_->SendBeginFrame(args); 60 client_->SendBeginFrame(args);
61 UpdateBeginFrameObservation();
62 }
60 last_sent_begin_frame_args_ = args; 63 last_sent_begin_frame_args_ = args;
61 } 64 }
62 65
63 void BeginFrameObserverProxy::OnCompositingShuttingDown( 66 void BeginFrameObserverProxy::OnCompositingShuttingDown(
64 ui::Compositor* compositor) { 67 ui::Compositor* compositor) {
65 ResetCompositor(); 68 ResetCompositor();
66 } 69 }
67 70
71 void BeginFrameObserverProxy::UpdateBeginFrameObservation() {
72 // In some cases, BeginFrame message is requested before |client_|'s window is
73 // added in the root window hierarchy.
74 if (!compositor_) {
75 DCHECK(!observing_begin_frames_);
76 return;
77 }
78
79 if (needs_begin_frames_ || needs_one_begin_frame_)
80 StartObservingBeginFrames();
81 else
82 StopObservingBeginFrames();
83 }
84
68 void BeginFrameObserverProxy::StartObservingBeginFrames() { 85 void BeginFrameObserverProxy::StartObservingBeginFrames() {
69 DCHECK(compositor_); 86 DCHECK(compositor_);
70 compositor_->AddBeginFrameObserver(this); 87 if (!observing_begin_frames_) {
88 observing_begin_frames_ = true;
89 compositor_->AddBeginFrameObserver(this);
90 }
71 } 91 }
72 92
73 void BeginFrameObserverProxy::StopObservingBeginFrames() { 93 void BeginFrameObserverProxy::StopObservingBeginFrames() {
74 DCHECK(compositor_); 94 DCHECK(compositor_);
75 compositor_->RemoveBeginFrameObserver(this); 95 if (observing_begin_frames_) {
96 observing_begin_frames_ = false;
97 compositor_->RemoveBeginFrameObserver(this);
98 }
76 } 99 }
77 100
78 } // namespace content 101 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698