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

Unified Diff: content/browser/renderer_host/render_widget_host_view_aura.cc

Issue 10690168: Aura: Resize locks with --ui-enable-threaded-compositing (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: New approach. Created 8 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: content/browser/renderer_host/render_widget_host_view_aura.cc
diff --git a/content/browser/renderer_host/render_widget_host_view_aura.cc b/content/browser/renderer_host/render_widget_host_view_aura.cc
index c46a867c087cdfed52fb012068d949277c9d797c..abfdd62357f5fa7e1d59d3124bd2afd0eac5fd4c 100644
--- a/content/browser/renderer_host/render_widget_host_view_aura.cc
+++ b/content/browser/renderer_host/render_widget_host_view_aura.cc
@@ -167,7 +167,7 @@ class RenderWidgetHostViewAura::ResizeLock
ResizeLock(aura::RootWindow* root_window, const gfx::Size new_size)
: root_window_(root_window),
new_size_(new_size),
- compositor_lock_(root_window_->GetCompositorLock()) {
+ compositor_lock_(root_window_->compositor()->GetCompositorLock()) {
root_window_->HoldMouseMoves();
BrowserThread::PostDelayedTask(
@@ -181,6 +181,10 @@ class RenderWidgetHostViewAura::ResizeLock
CancelLock();
}
+ bool IsLocked() {
+ return root_window_ != NULL;
+ }
+
void UnlockCompositor() {
compositor_lock_ = NULL;
}
@@ -200,7 +204,7 @@ class RenderWidgetHostViewAura::ResizeLock
private:
aura::RootWindow* root_window_;
gfx::Size new_size_;
- scoped_refptr<aura::CompositorLock> compositor_lock_;
+ scoped_refptr<ui::CompositorLock> compositor_lock_;
DISALLOW_COPY_AND_ASSIGN(ResizeLock);
};
@@ -281,7 +285,7 @@ void RenderWidgetHostViewAura::WasShown() {
if (!current_surface_ && host_->is_accelerated_compositing_active() &&
!released_front_lock_.get()) {
- released_front_lock_ = window_->GetRootWindow()->GetCompositorLock();
+ released_front_lock_ = GetCompositor()->GetCompositorLock();
}
AdjustSurfaceProtection();
@@ -558,35 +562,7 @@ void RenderWidgetHostViewAura::UpdateExternalTexture() {
if (!container) {
resize_locks_.clear();
} else {
- typedef std::vector<linked_ptr<ResizeLock> > ResizeLockList;
- ResizeLockList::iterator it = resize_locks_.begin();
- while (it != resize_locks_.end()) {
- gfx::Size container_size = ConvertSizeToDIP(this,
- container->size());
- if ((*it)->expected_size() == container_size)
- break;
- ++it;
- }
- if (it != resize_locks_.end()) {
- ++it;
- ui::Compositor* compositor = GetCompositor();
- if (compositor) {
- // Delay the release of the lock until we've kicked a frame with the
- // new texture, to avoid resizing the UI before we have a chance to
- // draw a "good" frame.
- locks_pending_draw_.insert(
- locks_pending_draw_.begin(), resize_locks_.begin(), it);
- // However since we got the size we were looking for, unlock the
- // compositor.
- for (ResizeLockList::iterator it2 = resize_locks_.begin();
- it2 !=it; ++it2) {
- it2->get()->UnlockCompositor();
- }
- if (!compositor->HasObserver(this))
- compositor->AddObserver(this);
- }
- resize_locks_.erase(resize_locks_.begin(), it);
- }
+ UpdateResizeLocks(ConvertSizeToDIP(this, container->size()));
}
} else {
window_->SetExternalTexture(NULL);
@@ -597,7 +573,7 @@ void RenderWidgetHostViewAura::UpdateExternalTexture() {
// then we really know its no longer in use.
ui::Compositor* compositor = GetCompositor();
if (compositor) {
- on_compositing_will_start_callbacks_.push_back(
+ AddCompositingStartedCallback(
base::Bind(&RenderWidgetHostViewAura::
SetSurfaceNotInUseByCompositor,
AsWeakPtr()));
@@ -609,6 +585,62 @@ void RenderWidgetHostViewAura::UpdateExternalTexture() {
}
}
+void RenderWidgetHostViewAura::UpdateResizeLocks(
+ const gfx::Size& surface_size_in_dip) {
+ typedef std::vector<linked_ptr<ResizeLock> > ResizeLockList;
+
+ // Remove locks that timed out.
+ ResizeLockList::iterator it = resize_locks_.begin();
+ while (it != resize_locks_.end()) {
+ if ((*it)->IsLocked())
+ break;
+ ++it;
+ }
+ resize_locks_.erase(resize_locks_.begin(), it);
+
+ // Remove locks if we've got got the right size.
piman 2012/07/31 23:42:17 typo: got got
jonathan.backer 2012/08/01 17:22:43 Done.
+ it = resize_locks_.begin();
+ while (it != resize_locks_.end()) {
+ if ((*it)->expected_size() == surface_size_in_dip)
+ break;
+ ++it;
+ }
+
+ if (it != resize_locks_.end()) {
+ ++it;
+ ui::Compositor* compositor = GetCompositor();
+ if (compositor) {
+ // Delay the release of the lock until we've kicked a frame with the
+ // new texture, to avoid resizing the UI before we have a chance to
+ // draw a "good" frame.
+ locks_pending_draw_.insert(
+ locks_pending_draw_.begin(), resize_locks_.begin(), it);
+ // However since we got the size we were looking for, unlock the
+ // compositor.
+ for (ResizeLockList::iterator it2 = resize_locks_.begin();
+ it2 != it; ++it2) {
+ it2->get()->UnlockCompositor();
+ }
+ if (!compositor->HasObserver(this))
+ compositor->AddObserver(this);
+ }
+ resize_locks_.erase(resize_locks_.begin(), it);
+ }
+}
+
+bool RenderWidgetHostViewAura::CanFastTrackACK(
+ const gfx::Size& surface_size_in_dip) {
+ std::vector<linked_ptr<ResizeLock> >::iterator it = resize_locks_.begin();
+ if (it == resize_locks_.end())
+ return false;
+
+ if (!(*it)->IsLocked())
+ return false;
+
+ UpdateResizeLocks(surface_size_in_dip);
+ return !resize_locks_.empty();
+}
+
void RenderWidgetHostViewAura::AcceleratedSurfaceBuffersSwapped(
const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params_in_pixel,
int gpu_host_id) {
@@ -623,7 +655,6 @@ void RenderWidgetHostViewAura::AcceleratedSurfaceBuffersSwapped(
InsertSyncPointAndACK(params_in_pixel.route_id, gpu_host_id, NULL);
return;
}
- current_surface_ = params_in_pixel.surface_handle;
// If we don't require an ACK that means the content is not a fresh updated
// new frame, rather we are just resetting our handle to some old content that
// we still hadn't discarded. Although we could display immediately, by not
@@ -632,8 +663,6 @@ void RenderWidgetHostViewAura::AcceleratedSurfaceBuffersSwapped(
if (!params_in_pixel.skip_ack)
released_front_lock_ = NULL;
- UpdateExternalTexture();
-
ui::Compositor* compositor = GetCompositor();
if (!compositor) {
// We have no compositor, so we have no way to display the surface.
@@ -645,36 +674,24 @@ void RenderWidgetHostViewAura::AcceleratedSurfaceBuffersSwapped(
image_transport_clients_.end());
gfx::Size surface_size_in_pixel =
image_transport_clients_[params_in_pixel.surface_handle]->size();
- gfx::Size surface_size = ConvertSizeToDIP(this,
- surface_size_in_pixel);
+ gfx::Size surface_size = ConvertSizeToDIP(this, surface_size_in_pixel);
window_->SchedulePaintInRect(gfx::Rect(surface_size));
- if (!params_in_pixel.skip_ack) {
- if (!resize_locks_.empty()) {
- // If we are waiting for the resize, fast-track the ACK.
- if (compositor->IsThreaded()) {
- // We need the compositor thread to pick up the active buffer before
- // ACKing.
- on_compositing_did_commit_callbacks_.push_back(
- base::Bind(&RenderWidgetHostViewAura::InsertSyncPointAndACK,
- params_in_pixel.route_id,
- gpu_host_id));
- if (!compositor->HasObserver(this))
- compositor->AddObserver(this);
- } else {
- // The compositor will pickup the active buffer during a draw, so we
- // can ACK immediately.
- InsertSyncPointAndACK(params_in_pixel.route_id, gpu_host_id,
- compositor);
- }
+ if (params_in_pixel.skip_ack) {
+ current_surface_ = params_in_pixel.surface_handle;
+ UpdateExternalTexture();
+ } else {
+ if (CanFastTrackACK(surface_size)) {
+ // Skip the flip.
+ InsertSyncPointAndACK(params_in_pixel.route_id, gpu_host_id, NULL);
} else {
- // Add sending an ACK to the list of things to do OnCompositingWillStart
- on_compositing_will_start_callbacks_.push_back(
+ current_surface_ = params_in_pixel.surface_handle;
+ UpdateExternalTexture();
+
+ AddCompositingStartedCallback(
base::Bind(&RenderWidgetHostViewAura::InsertSyncPointAndACK,
params_in_pixel.route_id,
gpu_host_id));
- if (!compositor->HasObserver(this))
- compositor->AddObserver(this);
}
}
}
@@ -693,10 +710,6 @@ void RenderWidgetHostViewAura::AcceleratedSurfacePostSubBuffer(
InsertSyncPointAndACK(params_in_pixel.route_id, gpu_host_id, NULL);
return;
}
- current_surface_ = params_in_pixel.surface_handle;
- released_front_lock_ = NULL;
- DCHECK(current_surface_);
- UpdateExternalTexture();
ui::Compositor* compositor = GetCompositor();
if (!compositor) {
@@ -725,31 +738,19 @@ void RenderWidgetHostViewAura::AcceleratedSurfacePostSubBuffer(
window_->SchedulePaintInRect(rect_to_paint);
- if (!resize_locks_.empty()) {
- // If we are waiting for the resize, fast-track the ACK.
- if (compositor->IsThreaded()) {
- // We need the compositor thread to pick up the active buffer before
- // ACKing.
- on_compositing_did_commit_callbacks_.push_back(
- base::Bind(&RenderWidgetHostViewAura::InsertSyncPointAndACK,
- params_in_pixel.route_id,
- gpu_host_id));
- if (!compositor->HasObserver(this))
- compositor->AddObserver(this);
- } else {
- // The compositor will pickup the active buffer during a draw, so we
- // can ACK immediately.
- InsertSyncPointAndACK(params_in_pixel.route_id, gpu_host_id,
- compositor);
- }
+ if (CanFastTrackACK(ConvertSizeToDIP(this, surface_size_in_pixel))) {
+ // Skip the flip.
+ InsertSyncPointAndACK(params_in_pixel.route_id, gpu_host_id, NULL);
} else {
- // Add sending an ACK to the list of things to do OnCompositingWillStart
- on_compositing_will_start_callbacks_.push_back(
+ current_surface_ = params_in_pixel.surface_handle;
+ released_front_lock_ = NULL;
+ DCHECK(current_surface_);
+ UpdateExternalTexture();
+
+ AddCompositingStartedCallback(
piman 2012/07/31 23:42:17 So, in the single-thread case, we're moving the sy
jonathan.backer 2012/08/01 17:22:43 Done.
base::Bind(&RenderWidgetHostViewAura::InsertSyncPointAndACK,
params_in_pixel.route_id,
gpu_host_id));
- if (!compositor->HasObserver(this))
- compositor->AddObserver(this);
}
}
}
@@ -1422,18 +1423,9 @@ void RenderWidgetHostViewAura::OnLostActive() {
////////////////////////////////////////////////////////////////////////////////
// RenderWidgetHostViewAura, ui::CompositorObserver implementation:
-void RenderWidgetHostViewAura::OnCompositingDidCommit(
- ui::Compositor* compositor) {
- RunCompositingDidCommitCallbacks(compositor);
-}
-
-void RenderWidgetHostViewAura::OnCompositingWillStart(
- ui::Compositor* compositor) {
- RunCompositingWillStartCallbacks(compositor);
-}
-
void RenderWidgetHostViewAura::OnCompositingStarted(
ui::Compositor* compositor) {
+ RunCompositingStartedCallbacks(compositor);
locks_pending_draw_.clear();
}
@@ -1584,24 +1576,29 @@ bool RenderWidgetHostViewAura::ShouldMoveToCenter() {
global_mouse_position_.y() > rect.bottom() - border_y;
}
-void RenderWidgetHostViewAura::RunCompositingDidCommitCallbacks(
+void RenderWidgetHostViewAura::RunCompositingStartedCallbacks(
ui::Compositor* compositor) {
- for (std::vector< base::Callback<void(ui::Compositor*)> >::const_iterator
- it = on_compositing_did_commit_callbacks_.begin();
- it != on_compositing_did_commit_callbacks_.end(); ++it) {
- it->Run(compositor);
+ std::vector<CommitIdAndCallback> uncalled;
+ for (std::vector<CommitIdAndCallback>::const_iterator
+ it = on_compositing_started_callbacks_.begin();
+ it != on_compositing_started_callbacks_.end(); ++it) {
+ if (it->first <= compositor->last_commit_id()) {
+ it->second.Run(compositor);
+ } else {
+ uncalled.push_back(*it);
+ }
}
- on_compositing_did_commit_callbacks_.clear();
+ on_compositing_started_callbacks_.swap(uncalled);
}
-void RenderWidgetHostViewAura::RunCompositingWillStartCallbacks(
- ui::Compositor* compositor) {
- for (std::vector< base::Callback<void(ui::Compositor*)> >::const_iterator
- it = on_compositing_will_start_callbacks_.begin();
- it != on_compositing_will_start_callbacks_.end(); ++it) {
- it->Run(compositor);
- }
- on_compositing_will_start_callbacks_.clear();
+void RenderWidgetHostViewAura::AddCompositingStartedCallback(
+ base::Callback<void(ui::Compositor*)> callback) {
+ ui::Compositor* compositor = GetCompositor();
+ DCHECK(compositor);
+ on_compositing_started_callbacks_.push_back(
+ CommitIdAndCallback(compositor->last_commit_id() + 1, callback));
+ if (!compositor->HasObserver(this))
+ compositor->AddObserver(this);
}
// static
@@ -1627,8 +1624,7 @@ void RenderWidgetHostViewAura::RemovingFromRootWindow() {
// frame though, because we will reissue a new frame right away without that
// composited data.
ui::Compositor* compositor = GetCompositor();
- RunCompositingDidCommitCallbacks(compositor);
- RunCompositingWillStartCallbacks(compositor);
+ RunCompositingStartedCallbacks(compositor);
locks_pending_draw_.clear();
if (compositor && compositor->HasObserver(this))
compositor->RemoveObserver(this);

Powered by Google App Engine
This is Rietveld 408576698