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 3 // found in the LICENSE file. 4 5 #ifndef CC_BASE_SWAP_PROMISE_H_ 6 #define CC_BASE_SWAP_PROMISE_H_ 7 8 #include "cc/output/compositor_frame_metadata.h" 9 10 namespace cc { 11 12 const unsigned int kMaxQueuedSwapPromiseNumber = 100; 13 14 // When a change to the compositor's state/invalidation/whatever happens, a 15 // Swap Promise can be inserted into LayerTreeHost/LayerTreeImpl, to track 16 // whether the compositor's reply to the new state/invaliadtion/whatever is 17 // completed in the compositor, i.e. the compositor knows it has been sent 18 // to its output or not. 19 // 20 // If the new compositor state is sent to the output, SwapPromise::DidSwap() 21 // will be called, and if the compositor fails to send its new state to the 22 // output, SwapPromise::DidNotSwap() will be called. 23 // 24 // Client wishes to use SwapPromise should have a subclass that defines 25 // the behavior of DidSwap() and DidNotSwap(). Notice that the promise can 26 // be broken at either main or impl thread, e.g. commit fails on main thread, 27 // new frame data has no actual damage so LayerTreeHostImpl::SwapBuffers() 28 // bails out early on impl thread, so don't assume that DidSwap() and 29 // DidNotSwap() are called at a particular thread. It is better to let the 30 // subclass carry thread-safe member data and operate on that member data in 31 // DidSwap() and DidNotSwap(). 32 class CC_EXPORT SwapPromise { 33 public: 34 enum DidNotSwapReason { 35 DID_NOT_SWAP_UNKNOWN, 36 SWAP_FAILS, 37 COMMIT_FAILS, 38 SWAP_PROMISE_LIST_OVERFLOW, 39 }; 40 SwapPromise()41 SwapPromise() {} ~SwapPromise()42 virtual ~SwapPromise() {} 43 44 virtual void DidSwap(CompositorFrameMetadata* metadata) = 0; 45 virtual void DidNotSwap(DidNotSwapReason reason) = 0; 46 }; 47 48 } // namespace cc 49 50 #endif // CC_BASE_SWAP_PROMISE_H_ 51