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

Unified Diff: content/browser/compositor/delegated_frame_host.cc

Issue 775143003: cc: Implement unified BeginFrame on aura (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add unittest 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/compositor/delegated_frame_host.cc
diff --git a/content/browser/compositor/delegated_frame_host.cc b/content/browser/compositor/delegated_frame_host.cc
index e6cb16150673df0c4db6cc80b28610e4154792a2..23c958eebc15faac0e6f4bce71375b2962986c6d 100644
--- a/content/browser/compositor/delegated_frame_host.cc
+++ b/content/browser/compositor/delegated_frame_host.cc
@@ -6,6 +6,7 @@
#include "base/callback_helpers.h"
#include "base/command_line.h"
+#include "cc/output/begin_frame_args.h"
#include "cc/output/compositor_frame.h"
#include "cc/output/compositor_frame_ack.h"
#include "cc/output/copy_output_request.h"
@@ -17,6 +18,7 @@
#include "content/browser/compositor/resize_lock.h"
#include "content/browser/gpu/compositor_util.h"
#include "content/common/gpu/client/gl_helper.h"
+#include "content/common/view_messages.h"
#include "content/public/browser/render_widget_host_view_frame_subscriber.h"
#include "content/public/common/content_switches.h"
#include "media/base/video_frame.h"
@@ -55,7 +57,8 @@ void RequireCallback(cc::SurfaceManager* manager,
////////////////////////////////////////////////////////////////////////////////
// DelegatedFrameHost
-DelegatedFrameHost::DelegatedFrameHost(DelegatedFrameHostClient* client)
+DelegatedFrameHost::DelegatedFrameHost(DelegatedFrameHostClient* client,
+ bool begin_frame_scheduling_enabled)
: client_(client),
compositor_(nullptr),
use_surfaces_(UseSurfacesEnabled()),
@@ -64,7 +67,9 @@ DelegatedFrameHost::DelegatedFrameHost(DelegatedFrameHostClient* client)
skipped_frames_(false),
current_scale_factor_(1.f),
can_lock_compositor_(YES_CAN_LOCK),
- delegated_frame_evictor_(new DelegatedFrameEvictor(this)) {
+ delegated_frame_evictor_(new DelegatedFrameEvictor(this)),
+ begin_frame_scheduling_enabled_(begin_frame_scheduling_enabled),
+ needs_begin_frames_(false) {
ImageTransportFactory::GetInstance()->AddObserver(this);
}
@@ -829,6 +834,25 @@ void DelegatedFrameHost::CopyFromCompositingSurfaceHasResultForVideo(
finished_callback);
}
+void DelegatedFrameHost::OnSetNeedsBeginFrames(bool needs_begin_frames) {
+ DCHECK(begin_frame_scheduling_enabled_);
+
+ if (needs_begin_frames_ == needs_begin_frames)
+ return;
+
+ needs_begin_frames_ = needs_begin_frames;
+
+ // In some cases, BeginFrame is needed before |client_|'s window is added
+ // in the root window hierarchy.
+ if (!compositor_)
+ return;
+
+ if (needs_begin_frames)
+ StartObservingBeginFrames();
+ else
+ StopObservingBeginFrames();
+}
+
////////////////////////////////////////////////////////////////////////////////
// DelegatedFrameHost, ui::CompositorObserver implementation:
@@ -878,13 +902,15 @@ void DelegatedFrameHost::OnCompositingShuttingDown(ui::Compositor* compositor) {
DCHECK(!compositor_);
}
-void DelegatedFrameHost::OnUpdateVSyncParameters(
- base::TimeTicks timebase,
- base::TimeDelta interval) {
- vsync_timebase_ = timebase;
- vsync_interval_ = interval;
- if (client_->DelegatedFrameHostIsVisible())
- client_->DelegatedFrameHostUpdateVSyncParameters(timebase, interval);
+///////////////////////////////////////////////////////////////////////////////
+// ui::CompositorBeginFrameObserver implementation.
+void DelegatedFrameHost::OnSendBeginFrame(const cc::BeginFrameArgs& args) {
+ DCHECK(begin_frame_scheduling_enabled_);
+
+ client_->DelegatedFrameHostSendBeginFrame(args);
+ last_sent_begin_frame_args_ = args;
+ vsync_timebase_ = args.frame_time;
+ vsync_interval_ = args.interval;
}
////////////////////////////////////////////////////////////////////////////////
@@ -910,8 +936,6 @@ DelegatedFrameHost::~DelegatedFrameHost() {
surface_factory_->Destroy(surface_id_);
if (resource_collection_.get())
resource_collection_->SetClient(NULL);
-
- DCHECK(!vsync_manager_.get());
}
void DelegatedFrameHost::RunOnCommitCallbacks() {
@@ -938,9 +962,9 @@ void DelegatedFrameHost::SetCompositor(ui::Compositor* compositor) {
return;
compositor_ = compositor;
compositor_->AddObserver(this);
- DCHECK(!vsync_manager_.get());
- vsync_manager_ = compositor_->vsync_manager();
- vsync_manager_->AddObserver(this);
+
+ if (begin_frame_scheduling_enabled_ && needs_begin_frames_)
+ StartObservingBeginFrames();
}
void DelegatedFrameHost::ResetCompositor() {
@@ -953,10 +977,10 @@ void DelegatedFrameHost::ResetCompositor() {
}
if (compositor_->HasObserver(this))
compositor_->RemoveObserver(this);
- if (vsync_manager_.get()) {
- vsync_manager_->RemoveObserver(this);
- vsync_manager_ = NULL;
- }
+
+ if (begin_frame_scheduling_enabled_ && needs_begin_frames_)
+ StopObservingBeginFrames();
+
compositor_ = nullptr;
}
@@ -978,6 +1002,20 @@ void DelegatedFrameHost::UnlockResources() {
delegated_frame_evictor_->UnlockFrame();
}
+void DelegatedFrameHost::StartObservingBeginFrames() {
+ DCHECK(begin_frame_scheduling_enabled_);
+ DCHECK(compositor_);
+
+ compositor_->AddBeginFrameObserver(this, last_sent_begin_frame_args_);
+}
+
+void DelegatedFrameHost::StopObservingBeginFrames() {
+ DCHECK(begin_frame_scheduling_enabled_);
+ DCHECK(compositor_);
+
+ compositor_->RemoveBeginFrameObserver(this);
+}
+
////////////////////////////////////////////////////////////////////////////////
// DelegatedFrameHost, ui::LayerOwnerDelegate implementation:

Powered by Google App Engine
This is Rietveld 408576698