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

Unified Diff: cc/trees/single_thread_proxy.cc

Issue 19106007: cc: Allow the main thread to cancel commits (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 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: cc/trees/single_thread_proxy.cc
diff --git a/cc/trees/single_thread_proxy.cc b/cc/trees/single_thread_proxy.cc
index 484acb6486f6591c6b48225440b8d5f8cc15703b..ef266d1faa195eb64ea1c748493ae71fc6917b98 100644
--- a/cc/trees/single_thread_proxy.cc
+++ b/cc/trees/single_thread_proxy.cc
@@ -26,7 +26,8 @@ SingleThreadProxy::SingleThreadProxy(LayerTreeHost* layer_tree_host)
layer_tree_host_(layer_tree_host),
created_offscreen_context_provider_(false),
next_frame_is_newly_committed_frame_(false),
- inside_draw_(false) {
+ inside_draw_(false),
+ can_cancel_commit_(false) {
TRACE_EVENT0("cc", "SingleThreadProxy::SingleThreadProxy");
DCHECK(Proxy::IsMainThread());
DCHECK(layer_tree_host);
@@ -171,6 +172,11 @@ void SingleThreadProxy::SetNeedsAnimate() {
NOTREACHED();
}
+void SingleThreadProxy::SetNeedsUpdateLayers() {
+ DCHECK(Proxy::IsMainThread());
+ layer_tree_host_->ScheduleComposite();
+}
+
void SingleThreadProxy::DoCommit(scoped_ptr<ResourceUpdateQueue> queue) {
DCHECK(Proxy::IsMainThread());
// Commit immediately.
@@ -219,6 +225,7 @@ void SingleThreadProxy::DoCommit(scoped_ptr<ResourceUpdateQueue> queue) {
void SingleThreadProxy::SetNeedsCommit() {
DCHECK(Proxy::IsMainThread());
+ can_cancel_commit_ = false;
layer_tree_host_->ScheduleComposite();
}
@@ -262,6 +269,9 @@ void SingleThreadProxy::OnCanDrawStateChanged(bool can_draw) {
}
void SingleThreadProxy::SetNeedsRedrawOnImplThread() {
+ // Since commit+draw happens in a single pass for this proxy,
+ // this also prevents cancelling a commit.
+ can_cancel_commit_ = false;
layer_tree_host_->ScheduleComposite();
}
@@ -400,11 +410,21 @@ bool SingleThreadProxy::CommitAndComposite(
->UnlinkAndClearEvictedBackings();
}
+ // Reset this flag for the next commit. It's possible that UpdateLayers
+ // will force another commit, so record this flag.
+ bool can_cancel_this_commit = can_cancel_commit_ && !for_readback;
+ can_cancel_commit_ = true;
+
scoped_ptr<ResourceUpdateQueue> queue =
make_scoped_ptr(new ResourceUpdateQueue);
- layer_tree_host_->UpdateLayers(
+ bool updated = layer_tree_host_->UpdateLayers(
queue.get(), layer_tree_host_impl_->memory_allocation_limit_bytes());
+ if (!updated && can_cancel_this_commit) {
+ TRACE_EVENT0("cc", "EarlyOut_NoUpdates");
+ return false;
+ }
+
layer_tree_host_->WillCommit();
DoCommit(queue.Pass());
bool result = DoComposite(offscreen_context_provider,
@@ -413,6 +433,7 @@ bool SingleThreadProxy::CommitAndComposite(
for_readback,
frame);
layer_tree_host_->DidBeginFrame();
+
return result;
}

Powered by Google App Engine
This is Rietveld 408576698