Index: ui/compositor/compositor.cc |
diff --git a/ui/compositor/compositor.cc b/ui/compositor/compositor.cc |
index 4f4037490a2a0135b0170f599f799b76e82be0cb..d5d38897dafbc26de7dc5444f000bf95323d6da3 100644 |
--- a/ui/compositor/compositor.cc |
+++ b/ui/compositor/compositor.cc |
@@ -24,7 +24,6 @@ |
#include "third_party/skia/include/core/SkBitmap.h" |
#include "ui/compositor/compositor_observer.h" |
#include "ui/compositor/compositor_switches.h" |
-#include "ui/compositor/compositor_vsync_manager.h" |
#include "ui/compositor/dip_util.h" |
#include "ui/compositor/layer.h" |
#include "ui/compositor/layer_animator_collection.h" |
@@ -64,8 +63,6 @@ void CompositorLock::CancelLock() { |
} // namespace ui |
-namespace {} // namespace |
- |
namespace ui { |
Compositor::Compositor(gfx::AcceleratedWidget widget, |
@@ -76,7 +73,6 @@ Compositor::Compositor(gfx::AcceleratedWidget widget, |
widget_(widget), |
compositor_thread_loop_(context_factory->GetCompositorMessageLoop()), |
task_runner_(task_runner), |
- vsync_manager_(new CompositorVSyncManager()), |
device_scale_factor_(0.0f), |
last_started_frame_(0), |
last_ended_frame_(0), |
@@ -87,7 +83,8 @@ Compositor::Compositor(gfx::AcceleratedWidget widget, |
draw_on_compositing_end_(false), |
swap_state_(SWAP_NONE), |
layer_animator_collection_(this), |
- schedule_draw_factory_(this) { |
+ schedule_draw_factory_(this), |
+ output_surface_lost_(true) { |
root_web_layer_ = cc::Layer::Create(); |
CommandLine* command_line = CommandLine::ForCurrentProcess(); |
@@ -104,6 +101,8 @@ Compositor::Compositor(gfx::AcceleratedWidget widget, |
#if !defined(OS_MACOSX) |
settings.partial_swap_enabled = |
!command_line->HasSwitch(cc::switches::kUIDisablePartialSwap); |
+ settings.begin_frame_publisher = |
+ command_line->HasSwitch(cc::switches::kEnableBeginFrameScheduling); |
#endif |
#if defined(OS_CHROMEOS) |
settings.per_tile_painting_enabled = true; |
@@ -140,6 +139,8 @@ Compositor::Compositor(gfx::AcceleratedWidget widget, |
base::TimeTicks before_create = base::TimeTicks::Now(); |
if (compositor_thread_loop_.get()) { |
+ // Unified BeginFrame scheduling is not used with threaded compositing. |
+ DCHECK(!settings.begin_frame_publisher); |
host_ = cc::LayerTreeHost::CreateThreaded( |
this, |
context_factory_->GetSharedBitmapManager(), |
@@ -166,6 +167,8 @@ Compositor::~Compositor() { |
CancelCompositorLock(); |
DCHECK(!compositor_lock_); |
+ DCHECK(!begin_frame_observer_list_.might_have_observers()); |
+ |
if (root_layer_) |
root_layer_->SetCompositor(NULL); |
@@ -279,8 +282,17 @@ void Compositor::SetVisible(bool visible) { |
host_->SetVisible(visible); |
} |
-scoped_refptr<CompositorVSyncManager> Compositor::vsync_manager() const { |
- return vsync_manager_; |
+void Compositor::SetAuthoritativeVSyncInterval(base::TimeDelta interval) const { |
+ host_->SetAuthoritativeVSyncInterval(interval); |
+} |
+ |
+void Compositor::StartBeginFrame(const cc::BeginFrameArgs& args) const { |
+ if (output_surface_lost_) |
+ return; |
+ task_runner_->PostTask( |
+ FROM_HERE, |
+ base::Bind( |
+ &cc::OutputSurface::BeginFrame, output_surface_weak_ptr_, args)); |
} |
void Compositor::AddObserver(CompositorObserver* observer) { |
@@ -324,6 +336,45 @@ bool Compositor::HasAnimationObserver(CompositorAnimationObserver* observer) { |
return animation_observer_list_.HasObserver(observer); |
} |
+void Compositor::AddBeginFrameObserver( |
+ CompositorBeginFrameObserver* observer, |
+ const cc::BeginFrameArgs& last_begin_frame_args_sent_to_observer) { |
+ bool need_begin_frame = false; |
+ if (!begin_frame_observer_list_.might_have_observers()) { |
+ need_begin_frame = true; |
+ } |
+ |
+ begin_frame_observer_list_.AddObserver(observer); |
+ |
+ if (need_begin_frame) { |
+ task_runner_->PostTask(FROM_HERE, |
+ base::Bind(&Compositor::SetChildrenNeedBeginFrames, |
+ base::Unretained(this), |
+ true)); |
+ } |
+ |
+ // If |last_begin_frame_args_| is still effective, send it to the new |
+ // |observer| immediately. |
+ if (!last_begin_frame_args_sent_to_observer.deadline.is_null() && |
+ last_begin_frame_args_sent_to_observer != last_begin_frame_args_ && |
+ last_begin_frame_args_.deadline > base::TimeTicks::Now()) |
+ observer->OnSendBeginFrame(last_begin_frame_args_); |
+} |
+ |
+void Compositor::RemoveBeginFrameObserver( |
+ CompositorBeginFrameObserver* observer) { |
+ DCHECK(begin_frame_observer_list_.might_have_observers()); |
+ |
+ begin_frame_observer_list_.RemoveObserver(observer); |
+ |
+ if (!begin_frame_observer_list_.might_have_observers()) { |
+ task_runner_->PostTask(FROM_HERE, |
+ base::Bind(&Compositor::SetChildrenNeedBeginFrames, |
+ base::Unretained(this), |
+ false)); |
+ } |
+} |
+ |
void Compositor::BeginMainFrame(const cc::BeginFrameArgs& args) { |
FOR_EACH_OBSERVER(CompositorAnimationObserver, |
animation_observer_list_, |
@@ -342,7 +393,22 @@ void Compositor::Layout() { |
} |
scoped_ptr<cc::OutputSurface> Compositor::CreateOutputSurface(bool fallback) { |
- return context_factory_->CreateOutputSurface(this, fallback); |
+ scoped_ptr<cc::OutputSurface> output_surface = |
+ context_factory_->CreateOutputSurface(this, fallback); |
+ // Keep this here, but can be used when DidInitializeOutputSurface() is false. |
+ DCHECK(!output_surface_weak_ptr_); |
+ output_surface_weak_ptr_ = output_surface->GetWeakPtr(); |
+ return output_surface.Pass(); |
+} |
+ |
+void Compositor::DidInitializeOutputSurface() { |
+ DCHECK(output_surface_weak_ptr_); |
+ output_surface_lost_ = false; |
+} |
+ |
+void Compositor::DidLoseOutputSurface() { |
+ output_surface_lost_ = true; |
+ output_surface_weak_ptr_.reset(); |
} |
void Compositor::DidCommit() { |
@@ -378,6 +444,13 @@ void Compositor::ScheduleAnimation() { |
ScheduleComposite(); |
} |
+void Compositor::SendBeginFrameToChildren(const cc::BeginFrameArgs& args) { |
+ FOR_EACH_OBSERVER(CompositorBeginFrameObserver, |
+ begin_frame_observer_list_, |
+ OnSendBeginFrame(args)); |
+ last_begin_frame_args_ = args; |
+} |
+ |
void Compositor::DidPostSwapBuffers() { |
DCHECK(!compositor_thread_loop_.get()); |
DCHECK_EQ(swap_state_, SWAP_NONE); |
@@ -449,4 +522,8 @@ void Compositor::NotifyEnd() { |
CompositorObserver, observer_list_, OnCompositingEnded(this)); |
} |
+void Compositor::SetChildrenNeedBeginFrames(bool need_begin_frame) { |
+ host_->SetChildrenNeedBeginFrames(need_begin_frame); |
+} |
+ |
} // namespace ui |