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

Unified Diff: ui/compositor/compositor.cc

Issue 784653002: Revert of Make ui::Compositor use ui::Scheduler (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years 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
« no previous file with comments | « ui/compositor/compositor.h ('k') | ui/compositor/layer_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/compositor/compositor.cc
diff --git a/ui/compositor/compositor.cc b/ui/compositor/compositor.cc
index 0fae1937acb265839fc48a516aa597dfa96184b0..f67632290a3eeaee1a97549d84b572e99bfe4605 100644
--- a/ui/compositor/compositor.cc
+++ b/ui/compositor/compositor.cc
@@ -75,8 +75,14 @@
task_runner_(task_runner),
vsync_manager_(new CompositorVSyncManager()),
device_scale_factor_(0.0f),
+ last_started_frame_(0),
+ last_ended_frame_(0),
disable_schedule_composite_(false),
compositor_lock_(NULL),
+ defer_draw_scheduling_(false),
+ waiting_on_compositing_end_(false),
+ draw_on_compositing_end_(false),
+ swap_state_(SWAP_NONE),
layer_animator_collection_(this),
weak_ptr_factory_(this) {
root_web_layer_ = cc::Layer::Create();
@@ -102,8 +108,7 @@
settings.per_tile_painting_enabled = true;
#endif
#if defined(OS_WIN)
- settings.disable_hi_res_timer_tasks_on_battery =
- !context_factory_->DoesCreateTestContexts();
+ settings.disable_hi_res_timer_tasks_on_battery = true;
settings.renderer_settings.finish_rendering_on_resize = true;
#endif
@@ -134,6 +139,7 @@
settings.impl_side_painting = IsUIImplSidePaintingEnabled();
settings.use_zero_copy = IsUIZeroCopyEnabled();
+ settings.single_thread_proxy_scheduler = false;
base::TimeTicks before_create = base::TimeTicks::Now();
if (compositor_thread_loop_.get()) {
@@ -184,7 +190,14 @@
}
void Compositor::ScheduleDraw() {
- host_->SetNeedsCommit();
+ if (compositor_thread_loop_.get()) {
+ host_->SetNeedsCommit();
+ } else if (!defer_draw_scheduling_) {
+ defer_draw_scheduling_ = true;
+ task_runner_->PostTask(
+ FROM_HERE,
+ base::Bind(&Compositor::Draw, weak_ptr_factory_.GetWeakPtr()));
+ }
}
void Compositor::SetRootLayer(Layer* root_layer) {
@@ -205,19 +218,43 @@
host_->set_has_transparent_background(host_has_transparent_background);
}
+void Compositor::Draw() {
+ DCHECK(!compositor_thread_loop_.get());
+
+ defer_draw_scheduling_ = false;
+ if (waiting_on_compositing_end_) {
+ draw_on_compositing_end_ = true;
+ return;
+ }
+ if (!root_layer_)
+ return;
+
+ TRACE_EVENT_ASYNC_BEGIN0("ui", "Compositor::Draw", last_started_frame_ + 1);
+
+ DCHECK_NE(swap_state_, SWAP_POSTED);
+ swap_state_ = SWAP_NONE;
+
+ waiting_on_compositing_end_ = true;
+ last_started_frame_++;
+ if (!IsLocked()) {
+ // TODO(nduca): Temporary while compositor calls
+ // compositeImmediately() directly.
+ cc::BeginFrameArgs args = cc::BeginFrameArgs::Create(
+ BEGINFRAME_FROM_HERE, gfx::FrameTime::Now(), base::TimeTicks(),
+ cc::BeginFrameArgs::DefaultInterval(), cc::BeginFrameArgs::SYNCHRONOUS);
+ BeginMainFrame(args);
+ host_->Composite(args.frame_time);
+ }
+ if (swap_state_ == SWAP_NONE)
+ NotifyEnd();
+}
+
void Compositor::ScheduleFullRedraw() {
- // TODO(enne): Some callers (mac) call this function expecting that it
- // will also commit. This should probably just redraw the screen
- // from damage and not commit. ScheduleDraw/ScheduleRedraw need
- // better names.
host_->SetNeedsRedraw();
- host_->SetNeedsCommit();
}
void Compositor::ScheduleRedrawRect(const gfx::Rect& damage_rect) {
- // TODO(enne): Make this not commit. See ScheduleFullRedraw.
host_->SetNeedsRedrawRect(damage_rect);
- host_->SetNeedsCommit();
}
void Compositor::DisableSwapUntilResize() {
@@ -332,28 +369,45 @@
}
void Compositor::DidCommitAndDrawFrame() {
+ base::TimeTicks start_time = gfx::FrameTime::Now();
+ FOR_EACH_OBSERVER(CompositorObserver,
+ observer_list_,
+ OnCompositingStarted(this, start_time));
}
void Compositor::DidCompleteSwapBuffers() {
- // DidPostSwapBuffers is a SingleThreadProxy-only feature. Synthetically
- // generate OnCompositingStarted messages for the threaded case so that
- // OnCompositingStarted/OnCompositingEnded messages match.
if (compositor_thread_loop_.get()) {
- base::TimeTicks start_time = gfx::FrameTime::Now();
- FOR_EACH_OBSERVER(CompositorObserver, observer_list_,
- OnCompositingStarted(this, start_time));
- }
- FOR_EACH_OBSERVER(CompositorObserver, observer_list_,
- OnCompositingEnded(this));
+ NotifyEnd();
+ } else {
+ DCHECK_EQ(swap_state_, SWAP_POSTED);
+ NotifyEnd();
+ swap_state_ = SWAP_COMPLETED;
+ }
+}
+
+void Compositor::ScheduleComposite() {
+ if (!disable_schedule_composite_)
+ ScheduleDraw();
+}
+
+void Compositor::ScheduleAnimation() {
+ ScheduleComposite();
}
void Compositor::DidPostSwapBuffers() {
- base::TimeTicks start_time = gfx::FrameTime::Now();
- FOR_EACH_OBSERVER(CompositorObserver, observer_list_,
- OnCompositingStarted(this, start_time));
+ DCHECK(!compositor_thread_loop_.get());
+ DCHECK_EQ(swap_state_, SWAP_NONE);
+ swap_state_ = SWAP_POSTED;
}
void Compositor::DidAbortSwapBuffers() {
+ if (!compositor_thread_loop_.get()) {
+ if (swap_state_ == SWAP_POSTED) {
+ NotifyEnd();
+ swap_state_ = SWAP_COMPLETED;
+ }
+ }
+
FOR_EACH_OBSERVER(CompositorObserver,
observer_list_,
OnCompositingAborted(this));
@@ -375,7 +429,8 @@
scoped_refptr<CompositorLock> Compositor::GetCompositorLock() {
if (!compositor_lock_) {
compositor_lock_ = new CompositorLock(this);
- host_->SetDeferCommits(true);
+ if (compositor_thread_loop_.get())
+ host_->SetDeferCommits(true);
FOR_EACH_OBSERVER(CompositorObserver,
observer_list_,
OnCompositingLockStateChanged(this));
@@ -386,7 +441,8 @@
void Compositor::UnlockCompositor() {
DCHECK(compositor_lock_);
compositor_lock_ = NULL;
- host_->SetDeferCommits(false);
+ if (compositor_thread_loop_.get())
+ host_->SetDeferCommits(false);
FOR_EACH_OBSERVER(CompositorObserver,
observer_list_,
OnCompositingLockStateChanged(this));
@@ -397,4 +453,20 @@
compositor_lock_->CancelLock();
}
+void Compositor::NotifyEnd() {
+ last_ended_frame_++;
+ TRACE_EVENT_ASYNC_END0("ui", "Compositor::Draw", last_ended_frame_);
+ waiting_on_compositing_end_ = false;
+ if (draw_on_compositing_end_) {
+ draw_on_compositing_end_ = false;
+
+ // Call ScheduleDraw() instead of Draw() in order to allow other
+ // CompositorObservers to be notified before starting another
+ // draw cycle.
+ ScheduleDraw();
+ }
+ FOR_EACH_OBSERVER(
+ CompositorObserver, observer_list_, OnCompositingEnded(this));
+}
+
} // namespace ui
« no previous file with comments | « ui/compositor/compositor.h ('k') | ui/compositor/layer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698