Index: ui/compositor/compositor.h |
diff --git a/ui/compositor/compositor.h b/ui/compositor/compositor.h |
index ea5772480c321aaa0cc6146331827bcf56d675cf..afb67c4380e430f5e63b12c5f705463fa3167ceb 100644 |
--- a/ui/compositor/compositor.h |
+++ b/ui/compositor/compositor.h |
@@ -126,6 +126,32 @@ class COMPOSITOR_EXPORT CompositorDelegate { |
virtual ~CompositorDelegate() {} |
}; |
+// This class represents a lock on the compositor, that can be used to prevent |
+// commits to the compositor tree while we're waiting for an asynchronous |
+// event. The typical use case is when waiting for a renderer to produce a frame |
+// at the right size. The caller keeps a reference on this object, and drops the |
+// reference once it desires to release the lock. |
+// Note however that the lock is canceled after a short timeout to ensure |
+// responsiveness of the UI, so the compositor tree should be kept in a |
+// "reasonable" state while the lock is held. |
+// Don't instantiate this class directly, use Compositor::GetCompositorLock. |
+class COMPOSITOR_EXPORT CompositorLock |
+ : public base::RefCounted<CompositorLock>, |
+ public base::SupportsWeakPtr<CompositorLock> { |
+ private: |
+ friend class base::RefCounted<CompositorLock>; |
+ friend class Compositor; |
+ |
+ explicit CompositorLock(Compositor* compositor); |
+ ~CompositorLock(); |
+ |
+ void CancelLock(); |
+ |
+ Compositor* compositor_; |
+ DISALLOW_COPY_AND_ASSIGN(CompositorLock); |
+}; |
+ |
+ |
// Compositor object to take care of GPU painting. |
// A Browser compositor object is responsible for generating the final |
// displayable form of pixels comprising a single widget's contents. It draws an |
@@ -195,6 +221,9 @@ class COMPOSITOR_EXPORT Compositor |
// (i.e. |Compositor::Initialize(true)| was called). |
bool IsThreaded() const; |
+ // Creates a compositor lock. |
+ scoped_refptr<CompositorLock> GetCompositorLock(); |
+ |
// Internal functions, called back by command-buffer contexts on swap buffer |
// events. |
@@ -224,6 +253,10 @@ class COMPOSITOR_EXPORT Compositor |
private: |
friend class base::RefCounted<Compositor>; |
+ friend class CompositorLock; |
+ |
+ // Called by CompositorLock. |
+ void Unlock(); |
// When reading back pixel data we often get RGBA rather than BGRA pixels and |
// and the image often needs to be flipped vertically. |
@@ -258,6 +291,21 @@ class COMPOSITOR_EXPORT Compositor |
bool disable_schedule_composite_; |
+ enum CommitsAllowedState { |
+ // We've told |root_layer_| to enable commits, but no commit has cleared. |
+ ENABLED_NEEDS_COMMIT, |
+ // We've committed since being enabled. |
+ ENABLED_DID_COMMIT, |
+ // We will tell |root_layer_| to defer commits once an commit clears. |
+ DISABLED_PENDING_COMMIT, |
+ // We told |root_layer_| to disable commits. |
+ DISABLED, |
+ }; |
+ |
+ CommitsAllowedState commits_allowed_; |
+ |
+ CompositorLock* compositor_lock_; |
+ |
DISALLOW_COPY_AND_ASSIGN(Compositor); |
}; |