OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef UI_COMPOSITOR_COMPOSITOR_LOCK_H_ |
| 6 #define UI_COMPOSITOR_COMPOSITOR_LOCK_H_ |
| 7 |
| 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/memory/weak_ptr.h" |
| 10 #include "base/time/time.h" |
| 11 #include "ui/compositor/compositor_export.h" |
| 12 |
| 13 namespace base { |
| 14 class SequencedTaskRunner; |
| 15 } |
| 16 |
| 17 namespace ui { |
| 18 |
| 19 class Compositor; |
| 20 |
| 21 class CompositorLockClient { |
| 22 public: |
| 23 virtual ~CompositorLockClient() {} |
| 24 |
| 25 // Called if the CompositorLock ends before being destroyed due to timeout. |
| 26 virtual void CompositorLockTimedOut() = 0; |
| 27 }; |
| 28 |
| 29 class CompositorLockDelegate { |
| 30 public: |
| 31 virtual ~CompositorLockDelegate() {} |
| 32 |
| 33 // Called to perform the unlock operation. |
| 34 virtual void DoUnlockCompositor() = 0; |
| 35 }; |
| 36 |
| 37 // This class represents a lock on the compositor, that can be used to prevent |
| 38 // commits to the compositor tree while we're waiting for an asynchronous |
| 39 // event. The typical use case is when waiting for a renderer to produce a frame |
| 40 // at the right size. The caller keeps a reference on this object, and drops the |
| 41 // reference once it desires to release the lock. |
| 42 // By default, the lock will be cancelled after a short timeout to ensure |
| 43 // responsiveness of the UI, so the compositor tree should be kept in a |
| 44 // "reasonable" state while the lock is held. If the compositor sets |
| 45 // locks to not time out, then the lock will remain in effect until destroyed. |
| 46 // Don't instantiate this class directly, use Compositor::GetCompositorLock. |
| 47 class COMPOSITOR_EXPORT CompositorLock |
| 48 : public base::RefCounted<CompositorLock> { |
| 49 public: |
| 50 // The |client| is informed about events from the CompositorLock. The |
| 51 // |delegate| is used to perform actual unlocking. If |timeout| is zero then |
| 52 // no timeout is scheduled, else a timeout is scheduled on the |task_runner|. |
| 53 explicit CompositorLock(CompositorLockClient* client, |
| 54 CompositorLockDelegate* delegate, |
| 55 base::SequencedTaskRunner* task_runner, |
| 56 base::TimeDelta timeout); |
| 57 |
| 58 private: |
| 59 friend class base::RefCounted<CompositorLock>; |
| 60 friend class FakeCompositorLock; // For tests. |
| 61 |
| 62 ~CompositorLock(); |
| 63 |
| 64 void TimeoutLock(); |
| 65 |
| 66 CompositorLockClient* const client_; |
| 67 CompositorLockDelegate* delegate_; |
| 68 base::WeakPtrFactory<CompositorLock> weak_ptr_factory_; |
| 69 |
| 70 DISALLOW_COPY_AND_ASSIGN(CompositorLock); |
| 71 }; |
| 72 |
| 73 } // namespace ui |
| 74 |
| 75 #endif // UI_COMPOSITOR_COMPOSITOR_LOCK_H_ |
OLD | NEW |