Commit 0875b32a authored by enne's avatar enne Committed by Commit bot

Use vsync manager regardless of begin frame settings

There was some hope that the ui::CompositorVSyncManager could be removed
once --enable-begin-frame-scheduling was turned on.  Unfortunately, the
vsync manager is used by two additional systems that can't be easily
removed: DelegatedFrameHost::AttemptFrameSubscriberCapture as well as
components/exo/wayland/server.cc.  The latter may go away eventually.
If so, then the frame capture could then be changed to more simple
polling as needed instead of vsync manager and observer system that
needs to be plumbed everywhere.

In the medium term, the vsync manager needs to live on in all paths.
This means that BrowserCompositorOutputSurface and ui::Compositor always
need to update the vsync manager with changes.  Conditionals for
whether or not to send vsync information to renderers just get moved
down the pipeline from the output surface to DelegatedFrameHost.

Review-Url: https://codereview.chromium.org/2277883002
Cr-Commit-Position: refs/heads/master@{#414186}
parent 5f32fe5b
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
#include "base/location.h" #include "base/location.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "cc/base/switches.h"
#include "cc/output/output_surface_client.h" #include "cc/output/output_surface_client.h"
#include "cc/scheduler/begin_frame_source.h" #include "cc/scheduler/begin_frame_source.h"
#include "components/display_compositor/compositor_overlay_candidate_validator.h" #include "components/display_compositor/compositor_overlay_candidate_validator.h"
...@@ -29,10 +28,7 @@ BrowserCompositorOutputSurface::BrowserCompositorOutputSurface( ...@@ -29,10 +28,7 @@ BrowserCompositorOutputSurface::BrowserCompositorOutputSurface(
: OutputSurface(std::move(context_provider), nullptr, nullptr), : OutputSurface(std::move(context_provider), nullptr, nullptr),
vsync_manager_(std::move(vsync_manager)), vsync_manager_(std::move(vsync_manager)),
synthetic_begin_frame_source_(begin_frame_source), synthetic_begin_frame_source_(begin_frame_source),
reflector_(nullptr), reflector_(nullptr) {
use_begin_frame_scheduling_(
!base::CommandLine::ForCurrentProcess()->HasSwitch(
cc::switches::kDisableBeginFrameScheduling)) {
overlay_candidate_validator_ = std::move(overlay_candidate_validator); overlay_candidate_validator_ = std::move(overlay_candidate_validator);
Initialize(); Initialize();
} }
...@@ -44,10 +40,7 @@ BrowserCompositorOutputSurface::BrowserCompositorOutputSurface( ...@@ -44,10 +40,7 @@ BrowserCompositorOutputSurface::BrowserCompositorOutputSurface(
: OutputSurface(nullptr, nullptr, std::move(software_device)), : OutputSurface(nullptr, nullptr, std::move(software_device)),
vsync_manager_(vsync_manager), vsync_manager_(vsync_manager),
synthetic_begin_frame_source_(begin_frame_source), synthetic_begin_frame_source_(begin_frame_source),
reflector_(nullptr), reflector_(nullptr) {
use_begin_frame_scheduling_(
!base::CommandLine::ForCurrentProcess()->HasSwitch(
cc::switches::kDisableBeginFrameScheduling)) {
Initialize(); Initialize();
} }
...@@ -66,57 +59,21 @@ BrowserCompositorOutputSurface::~BrowserCompositorOutputSurface() { ...@@ -66,57 +59,21 @@ BrowserCompositorOutputSurface::~BrowserCompositorOutputSurface() {
if (reflector_) if (reflector_)
reflector_->DetachFromOutputSurface(); reflector_->DetachFromOutputSurface();
DCHECK(!reflector_); DCHECK(!reflector_);
if (!HasClient())
return;
// When BeginFrame scheduling is enabled, vsync info is not routed to renderer
// by using |vsync_manager_|. Instead, BeginFrame message is used.
if (!use_begin_frame_scheduling_)
vsync_manager_->RemoveObserver(this);
} }
void BrowserCompositorOutputSurface::Initialize() { void BrowserCompositorOutputSurface::Initialize() {
capabilities_.adjust_deadline_for_parent = false; capabilities_.adjust_deadline_for_parent = false;
} }
bool BrowserCompositorOutputSurface::BindToClient( void BrowserCompositorOutputSurface::OnUpdateVSyncParametersFromGpu(
cc::OutputSurfaceClient* client) {
if (!OutputSurface::BindToClient(client))
return false;
// Don't want vsync notifications until there is a client.
if (!use_begin_frame_scheduling_)
vsync_manager_->AddObserver(this);
return true;
}
void BrowserCompositorOutputSurface::UpdateVSyncParametersInternal(
base::TimeTicks timebase, base::TimeTicks timebase,
base::TimeDelta interval) { base::TimeDelta interval) {
DCHECK(HasClient());
if (interval.is_zero()) { if (interval.is_zero()) {
// TODO(brianderson): We should not be receiving 0 intervals. // TODO(brianderson): We should not be receiving 0 intervals.
interval = cc::BeginFrameArgs::DefaultInterval(); interval = cc::BeginFrameArgs::DefaultInterval();
} }
synthetic_begin_frame_source_->OnUpdateVSyncParameters(timebase, interval); synthetic_begin_frame_source_->OnUpdateVSyncParameters(timebase, interval);
}
void BrowserCompositorOutputSurface::OnUpdateVSyncParameters(
base::TimeTicks timebase,
base::TimeDelta interval) {
DCHECK(HasClient());
DCHECK(!use_begin_frame_scheduling_);
UpdateVSyncParametersInternal(timebase, interval);
}
void BrowserCompositorOutputSurface::OnUpdateVSyncParametersFromGpu(
base::TimeTicks timebase,
base::TimeDelta interval) {
DCHECK(HasClient());
if (use_begin_frame_scheduling_) {
UpdateVSyncParametersInternal(timebase, interval);
return;
}
vsync_manager_->UpdateVSyncParameters(timebase, interval); vsync_manager_->UpdateVSyncParameters(timebase, interval);
} }
......
...@@ -35,19 +35,13 @@ class ReflectorImpl; ...@@ -35,19 +35,13 @@ class ReflectorImpl;
class WebGraphicsContext3DCommandBufferImpl; class WebGraphicsContext3DCommandBufferImpl;
class CONTENT_EXPORT BrowserCompositorOutputSurface class CONTENT_EXPORT BrowserCompositorOutputSurface
: public cc::OutputSurface, : public cc::OutputSurface {
public ui::CompositorVSyncManager::Observer {
public: public:
~BrowserCompositorOutputSurface() override; ~BrowserCompositorOutputSurface() override;
// cc::OutputSurface implementation. // cc::OutputSurface implementation.
bool BindToClient(cc::OutputSurfaceClient* client) override;
cc::OverlayCandidateValidator* GetOverlayCandidateValidator() const override; cc::OverlayCandidateValidator* GetOverlayCandidateValidator() const override;
// ui::CompositorVSyncManager::Observer implementation.
void OnUpdateVSyncParameters(base::TimeTicks timebase,
base::TimeDelta interval) override;
void OnUpdateVSyncParametersFromGpu(base::TimeTicks timebase, void OnUpdateVSyncParametersFromGpu(base::TimeTicks timebase,
base::TimeDelta interval); base::TimeDelta interval);
...@@ -95,15 +89,9 @@ class CONTENT_EXPORT BrowserCompositorOutputSurface ...@@ -95,15 +89,9 @@ class CONTENT_EXPORT BrowserCompositorOutputSurface
cc::SyntheticBeginFrameSource* synthetic_begin_frame_source_; cc::SyntheticBeginFrameSource* synthetic_begin_frame_source_;
ReflectorImpl* reflector_; ReflectorImpl* reflector_;
// True when BeginFrame scheduling is enabled.
bool use_begin_frame_scheduling_;
private: private:
void Initialize(); void Initialize();
void UpdateVSyncParametersInternal(base::TimeTicks timebase,
base::TimeDelta interval);
std::unique_ptr<display_compositor::CompositorOverlayCandidateValidator> std::unique_ptr<display_compositor::CompositorOverlayCandidateValidator>
overlay_candidate_validator_; overlay_candidate_validator_;
......
...@@ -300,13 +300,8 @@ void BrowserCompositorMac::UpdateVSyncParameters( ...@@ -300,13 +300,8 @@ void BrowserCompositorMac::UpdateVSyncParameters(
const base::TimeTicks& timebase, const base::TimeTicks& timebase,
const base::TimeDelta& interval) { const base::TimeDelta& interval) {
if (recyclable_compositor_) { if (recyclable_compositor_) {
recyclable_compositor_->compositor() recyclable_compositor_->compositor()->SetDisplayVSyncParameters(
->vsync_manager() timebase, interval);
->UpdateVSyncParameters(timebase, interval);
recyclable_compositor_->compositor()
->context_factory()
->SetDisplayVSyncParameters(recyclable_compositor_->compositor(),
timebase, interval);
} }
} }
...@@ -474,7 +469,6 @@ bool BrowserCompositorMac::IsAutoResizeEnabled() const { ...@@ -474,7 +469,6 @@ bool BrowserCompositorMac::IsAutoResizeEnabled() const {
// cc::BeginFrameSourceBase, public: // cc::BeginFrameSourceBase, public:
void BrowserCompositorMac::OnBeginFrame(const cc::BeginFrameArgs& args) { void BrowserCompositorMac::OnBeginFrame(const cc::BeginFrameArgs& args) {
delegated_frame_host_->SetVSyncParameters(args.frame_time, args.interval);
client_->BrowserCompositorMacSendBeginFrame(args); client_->BrowserCompositorMacSendBeginFrame(args);
last_begin_frame_args_ = args; last_begin_frame_args_ = args;
} }
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "base/command_line.h" #include "base/command_line.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "base/time/default_tick_clock.h" #include "base/time/default_tick_clock.h"
#include "cc/base/switches.h"
#include "cc/output/compositor_frame.h" #include "cc/output/compositor_frame.h"
#include "cc/output/copy_output_request.h" #include "cc/output/copy_output_request.h"
#include "cc/resources/single_release_callback.h" #include "cc/resources/single_release_callback.h"
...@@ -65,6 +66,9 @@ void RequireCallback(cc::SurfaceManager* manager, ...@@ -65,6 +66,9 @@ void RequireCallback(cc::SurfaceManager* manager,
DelegatedFrameHost::DelegatedFrameHost(DelegatedFrameHostClient* client) DelegatedFrameHost::DelegatedFrameHost(DelegatedFrameHostClient* client)
: client_(client), : client_(client),
compositor_(nullptr), compositor_(nullptr),
using_begin_frame_scheduling_(
!base::CommandLine::ForCurrentProcess()->HasSwitch(
cc::switches::kDisableBeginFrameScheduling)),
tick_clock_(new base::DefaultTickClock()), tick_clock_(new base::DefaultTickClock()),
last_output_surface_id_(0), last_output_surface_id_(0),
pending_delegated_ack_count_(0), pending_delegated_ack_count_(0),
...@@ -797,8 +801,9 @@ void DelegatedFrameHost::OnCompositingShuttingDown(ui::Compositor* compositor) { ...@@ -797,8 +801,9 @@ void DelegatedFrameHost::OnCompositingShuttingDown(ui::Compositor* compositor) {
void DelegatedFrameHost::OnUpdateVSyncParameters(base::TimeTicks timebase, void DelegatedFrameHost::OnUpdateVSyncParameters(base::TimeTicks timebase,
base::TimeDelta interval) { base::TimeDelta interval) {
SetVSyncParameters(timebase, interval); vsync_timebase_ = timebase;
if (client_->DelegatedFrameHostIsVisible()) vsync_interval_ = interval;
if (!using_begin_frame_scheduling_ && client_->DelegatedFrameHostIsVisible())
client_->DelegatedFrameHostUpdateVSyncParameters(timebase, interval); client_->DelegatedFrameHostUpdateVSyncParameters(timebase, interval);
} }
...@@ -854,21 +859,15 @@ void DelegatedFrameHost::ResetCompositor() { ...@@ -854,21 +859,15 @@ void DelegatedFrameHost::ResetCompositor() {
} }
if (compositor_->HasObserver(this)) if (compositor_->HasObserver(this))
compositor_->RemoveObserver(this); compositor_->RemoveObserver(this);
if (vsync_manager_.get()) { if (vsync_manager_) {
vsync_manager_->RemoveObserver(this); vsync_manager_->RemoveObserver(this);
vsync_manager_ = NULL; vsync_manager_ = nullptr;
} }
compositor_->RemoveSurfaceClient(id_allocator_->client_id()); compositor_->RemoveSurfaceClient(id_allocator_->client_id());
compositor_ = nullptr; compositor_ = nullptr;
} }
void DelegatedFrameHost::SetVSyncParameters(const base::TimeTicks& timebase,
const base::TimeDelta& interval) {
vsync_timebase_ = timebase;
vsync_interval_ = interval;
}
void DelegatedFrameHost::LockResources() { void DelegatedFrameHost::LockResources() {
DCHECK(!surface_id_.is_null()); DCHECK(!surface_id_.is_null());
delegated_frame_evictor_->LockFrame(); delegated_frame_evictor_->LockFrame();
......
...@@ -139,8 +139,6 @@ class CONTENT_EXPORT DelegatedFrameHost ...@@ -139,8 +139,6 @@ class CONTENT_EXPORT DelegatedFrameHost
gfx::Size GetRequestedRendererSize() const; gfx::Size GetRequestedRendererSize() const;
void SetCompositor(ui::Compositor* compositor); void SetCompositor(ui::Compositor* compositor);
void ResetCompositor(); void ResetCompositor();
void SetVSyncParameters(const base::TimeTicks& timebase,
const base::TimeDelta& interval);
// Note: |src_subset| is specified in DIP dimensions while |output_size| // Note: |src_subset| is specified in DIP dimensions while |output_size|
// expects pixels. // expects pixels.
void CopyFromCompositingSurface(const gfx::Rect& src_subrect, void CopyFromCompositingSurface(const gfx::Rect& src_subrect,
...@@ -257,6 +255,7 @@ class CONTENT_EXPORT DelegatedFrameHost ...@@ -257,6 +255,7 @@ class CONTENT_EXPORT DelegatedFrameHost
// The vsync manager we are observing for changes, if any. // The vsync manager we are observing for changes, if any.
scoped_refptr<ui::CompositorVSyncManager> vsync_manager_; scoped_refptr<ui::CompositorVSyncManager> vsync_manager_;
bool using_begin_frame_scheduling_;
// The current VSync timebase and interval. These are zero until the first // The current VSync timebase and interval. These are zero until the first
// call to SetVSyncParameters(). // call to SetVSyncParameters().
......
...@@ -723,7 +723,6 @@ void RenderWidgetHostViewAura::SetNeedsBeginFrames(bool needs_begin_frames) { ...@@ -723,7 +723,6 @@ void RenderWidgetHostViewAura::SetNeedsBeginFrames(bool needs_begin_frames) {
void RenderWidgetHostViewAura::OnBeginFrame( void RenderWidgetHostViewAura::OnBeginFrame(
const cc::BeginFrameArgs& args) { const cc::BeginFrameArgs& args) {
delegated_frame_host_->SetVSyncParameters(args.frame_time, args.interval);
host_->Send(new ViewMsg_BeginFrame(host_->GetRoutingID(), args)); host_->Send(new ViewMsg_BeginFrame(host_->GetRoutingID(), args));
last_begin_frame_args_ = args; last_begin_frame_args_ = args;
} }
......
...@@ -398,10 +398,13 @@ bool Compositor::GetScrollOffsetForLayer(int layer_id, ...@@ -398,10 +398,13 @@ bool Compositor::GetScrollOffsetForLayer(int layer_id,
void Compositor::SetAuthoritativeVSyncInterval( void Compositor::SetAuthoritativeVSyncInterval(
const base::TimeDelta& interval) { const base::TimeDelta& interval) {
context_factory_->SetAuthoritativeVSyncInterval(this, interval); context_factory_->SetAuthoritativeVSyncInterval(this, interval);
if (base::CommandLine::ForCurrentProcess()->HasSwitch( vsync_manager_->SetAuthoritativeVSyncInterval(interval);
cc::switches::kDisableBeginFrameScheduling)) { }
vsync_manager_->SetAuthoritativeVSyncInterval(interval);
} void Compositor::SetDisplayVSyncParameters(base::TimeTicks timebase,
base::TimeDelta interval) {
context_factory_->SetDisplayVSyncParameters(this, timebase, interval);
vsync_manager_->UpdateVSyncParameters(timebase, interval);
} }
void Compositor::SetAcceleratedWidget(gfx::AcceleratedWidget widget) { void Compositor::SetAcceleratedWidget(gfx::AcceleratedWidget widget) {
......
...@@ -287,6 +287,12 @@ class COMPOSITOR_EXPORT Compositor ...@@ -287,6 +287,12 @@ class COMPOSITOR_EXPORT Compositor
// context. // context.
void SetAuthoritativeVSyncInterval(const base::TimeDelta& interval); void SetAuthoritativeVSyncInterval(const base::TimeDelta& interval);
// Most platforms set their vsync info via BrowerCompositorOutputSurface's
// OnUpdateVSyncParametersFromGpu, but Mac routes vsync info via the
// browser compositor instead through this path.
void SetDisplayVSyncParameters(base::TimeTicks timebase,
base::TimeDelta interval);
// Sets the widget for the compositor to render into. // Sets the widget for the compositor to render into.
void SetAcceleratedWidget(gfx::AcceleratedWidget widget); void SetAcceleratedWidget(gfx::AcceleratedWidget widget);
// Releases the widget previously set through SetAcceleratedWidget(). // Releases the widget previously set through SetAcceleratedWidget().
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment