Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CC_BASE_SWAP_PROMISE_H_ | 5 #ifndef CC_BASE_SWAP_PROMISE_H_ |
| 6 #define CC_BASE_SWAP_PROMISE_H_ | 6 #define CC_BASE_SWAP_PROMISE_H_ |
| 7 | 7 |
| 8 #include "base/compiler_specific.h" | |
| 9 #include "ui/events/latency_info.h" | |
| 10 | |
| 8 namespace cc { | 11 namespace cc { |
| 9 | 12 |
| 10 const unsigned int kMaxQueuedSwapPromiseNumber = 100; | 13 const unsigned int kMaxQueuedSwapPromiseNumber = 100; |
| 11 | 14 |
| 12 // When a change to the compositor's state/invalidation/whatever happens, a | 15 // When a change to the compositor's state/invalidation/whatever happens, a |
| 13 // Swap Promise can be inserted into LayerTreeHost/LayerTreeImpl, to track | 16 // Swap Promise can be inserted into LayerTreeHost/LayerTreeImpl, to track |
| 14 // whether the compositor's reply to the new state/invaliadtion/whatever is | 17 // whether the compositor's reply to the new state/invaliadtion/whatever is |
| 15 // completed in the compositor, i.e. the compositor knows it has been sent | 18 // completed in the compositor, i.e. the compositor knows it has been sent |
| 16 // to its output or not. | 19 // to its output or not. |
| 17 // | 20 // |
| 18 // If the new compositor state is sent to the output, SwapPromise::DidSwap() | 21 // If the new compositor state is sent to the output, SwapPromise::DidSwap() |
| 19 // will be called, and if the compositor fails to send its new state to the | 22 // will be called, and if the compositor fails to send its new state to the |
| 20 // output, SwapPromise::DidNotSwap() will be called. | 23 // output, SwapPromise::DidNotSwap() will be called. |
| 21 // | 24 // |
| 22 // Client wishes to use SwapPromise should have a subclass that defines | 25 // Client wishes to use SwapPromise should have a subclass that defines |
| 23 // the behavior of DidSwap() and DidNotSwap(). Notice that the promise can | 26 // the behavior of DidSwap() and DidNotSwap(). Notice that the promise can |
| 24 // be broken at either main or impl thread, e.g. commit fails on main thread, | 27 // be broken at either main or impl thread, e.g. commit fails on main thread, |
| 25 // new frame data has no actual damage so LayerTreeHostImpl::SwapBuffers() | 28 // new frame data has no actual damage so LayerTreeHostImpl::SwapBuffers() |
| 26 // bails out early on impl thread, so don't assume that DidSwap() and | 29 // bails out early on impl thread, so don't assume that DidSwap() and |
| 27 // DidNotSwap() are called at a particular thread. It is better to let the | 30 // DidNotSwap() are called at a particular thread. It is better to let the |
| 28 // subclass carry thread-safe member data and operate on that member data in | 31 // subclass carry thread-safe member data and operate on that member data in |
| 29 // DidSwap() and DidNotSwap(). | 32 // DidSwap() and DidNotSwap(). |
| 30 class SwapPromise { | 33 class SwapPromise { |
| 31 public: | 34 public: |
| 32 SwapPromise() {} | 35 enum SwapPromiseType { |
| 33 virtual ~SwapPromise() {} | 36 SWAP_PROMISE_UNKNOWN, |
| 37 SWAP_PROMISE_LATENCY_INFO, | |
| 38 }; | |
| 34 | 39 |
| 35 enum DidNotSwapReason { | 40 enum DidNotSwapReason { |
| 36 DID_NOT_SWAP_UNKNOWN, | 41 DID_NOT_SWAP_UNKNOWN, |
| 37 SWAP_FAILS, | 42 SWAP_FAILS, |
| 38 COMMIT_FAILS, | 43 COMMIT_FAILS, |
| 39 SWAP_PROMISE_LIST_OVERFLOW, | 44 SWAP_PROMISE_LIST_OVERFLOW, |
| 40 }; | 45 }; |
| 41 | 46 |
| 47 explicit SwapPromise(SwapPromiseType type); | |
| 48 virtual ~SwapPromise(); | |
| 49 | |
| 50 SwapPromiseType type(); | |
| 51 | |
| 42 virtual void DidSwap() = 0; | 52 virtual void DidSwap() = 0; |
| 43 virtual void DidNotSwap(DidNotSwapReason reason) = 0; | 53 virtual void DidNotSwap(DidNotSwapReason reason) = 0; |
| 54 | |
| 55 protected: | |
| 56 SwapPromiseType type_; | |
| 57 }; | |
| 58 | |
| 59 class LatencyInfoSwapPromise : public SwapPromise { | |
|
danakj
2013/11/26 19:17:53
one class per file please
Yufeng Shen (Slow to review)
2013/11/27 20:05:33
Done.
| |
| 60 public: | |
| 61 explicit LatencyInfoSwapPromise(const ui::LatencyInfo& latency_info); | |
| 62 virtual ~LatencyInfoSwapPromise(); | |
| 63 | |
| 64 virtual void DidSwap() OVERRIDE; | |
| 65 virtual void DidNotSwap(DidNotSwapReason reason) OVERRIDE; | |
| 66 | |
| 67 const ui::LatencyInfo& GetLatencyInfo(); | |
| 68 | |
| 69 private: | |
| 70 ui::LatencyInfo latency_; | |
| 44 }; | 71 }; |
| 45 | 72 |
| 46 } // namespace cc | 73 } // namespace cc |
| 47 | 74 |
| 48 #endif // CC_BASE_SWAP_PROMISE_H_ | 75 #endif // CC_BASE_SWAP_PROMISE_H_ |
| OLD | NEW |