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/macros.h" |
| 9 #include "base/memory/weak_ptr.h" |
| 10 #include "ui/compositor/compositor_export.h" |
| 11 |
| 12 namespace ui { |
| 13 |
| 14 class Compositor; |
| 15 class CompositorLock; |
| 16 |
| 17 class CompositorLockClient { |
| 18 public: |
| 19 virtual ~CompositorLockClient() {} |
| 20 |
| 21 // Called if the CompositorLock ends before being destroyed due to timeout. |
| 22 virtual void CompositorLockTimedOut() = 0; |
| 23 }; |
| 24 |
| 25 class CompositorLockDelegate { |
| 26 public: |
| 27 virtual ~CompositorLockDelegate() {} |
| 28 |
| 29 // Called to perform the unlock operation. |
| 30 virtual void RemoveCompositorLock(CompositorLock*) = 0; |
| 31 }; |
| 32 |
| 33 // This class represents a lock on the compositor, that can be used to prevent |
| 34 // commits to the compositor tree while we're waiting for an asynchronous |
| 35 // event. The typical use case is when waiting for a renderer to produce a frame |
| 36 // at the right size. The caller keeps a reference on this object, and drops the |
| 37 // reference once it desires to release the lock. |
| 38 // By default, the lock will be cancelled after a short timeout to ensure |
| 39 // responsiveness of the UI, so the compositor tree should be kept in a |
| 40 // "reasonable" state while the lock is held. The timeout length, or no timeout, |
| 41 // can be requested at the time the lock is created. |
| 42 // Don't instantiate this class directly, use Compositor::GetCompositorLock. |
| 43 class COMPOSITOR_EXPORT CompositorLock { |
| 44 public: |
| 45 // The |client| is informed about events from the CompositorLock. The |
| 46 // |delegate| is used to perform actual unlocking. If |timeout| is zero then |
| 47 // no timeout is scheduled, else a timeout is scheduled on the |task_runner|. |
| 48 explicit CompositorLock(CompositorLockClient* client, |
| 49 base::WeakPtr<CompositorLockDelegate> delegate); |
| 50 ~CompositorLock(); |
| 51 |
| 52 private: |
| 53 friend class Compositor; |
| 54 friend class FakeCompositorLock; |
| 55 |
| 56 // Causes the CompositorLock to end due to a timeout. |
| 57 void TimeoutLock(); |
| 58 |
| 59 CompositorLockClient* const client_; |
| 60 base::WeakPtr<CompositorLockDelegate> delegate_; |
| 61 |
| 62 DISALLOW_COPY_AND_ASSIGN(CompositorLock); |
| 63 }; |
| 64 |
| 65 } // namespace ui |
| 66 |
| 67 #endif // UI_COMPOSITOR_COMPOSITOR_LOCK_H_ |
OLD | NEW |