TransactionIdAllocator.h (3230B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef GFX_TRANSACTION_ID_ALLOCATOR_H 8 #define GFX_TRANSACTION_ID_ALLOCATOR_H 9 10 #include "nsISupportsImpl.h" 11 #include "mozilla/layers/LayersTypes.h" 12 #include "mozilla/TimeStamp.h" 13 #include "mozilla/VsyncDispatcher.h" 14 15 namespace mozilla { 16 namespace layers { 17 18 class TransactionIdAllocator { 19 protected: 20 virtual ~TransactionIdAllocator() = default; 21 22 public: 23 NS_INLINE_DECL_REFCOUNTING(TransactionIdAllocator) 24 25 /** 26 * Allocate a unique id number for the current refresh tick, can 27 * only be called while IsInRefresh(). 28 * 29 * If too many id's are allocated without being returned then 30 * the refresh driver will suspend until they catch up. This 31 * "throttling" behaviour can be skipped by passing aThrottle=false. 32 * Otherwise call sites should generally be passing aThrottle=true. 33 */ 34 virtual TransactionId GetTransactionId(bool aThrottle) = 0; 35 36 /** 37 * Return the transaction id that for the last non-revoked transaction. 38 * This allows the caller to tell whether a composite was triggered by 39 * a paint that occurred after a call to TransactionId(). 40 */ 41 virtual TransactionId LastTransactionId() const = 0; 42 43 /** 44 * Notify that all work (including asynchronous composites) 45 * for a given transaction id has been completed. 46 * 47 * If the refresh driver has been suspended because 48 * of having too many outstanding id's, then this may 49 * resume it. 50 */ 51 virtual void NotifyTransactionCompleted(TransactionId aTransactionId) = 0; 52 53 /** 54 * Revoke a transaction id that isn't needed to track 55 * completion of asynchronous work. This is similar 56 * to NotifyTransactionCompleted except avoids 57 * return ordering issues. 58 */ 59 virtual void RevokeTransactionId(TransactionId aTransactionId) = 0; 60 61 /** 62 * Stop waiting for pending transactions, if any. 63 * 64 * This is used when ClientLayerManager is assigning to another refresh 65 * driver, and the current refresh driver may never receive transaction 66 * completed notifications. 67 */ 68 virtual void ClearPendingTransactions() = 0; 69 70 /** 71 * Transaction id is usually initialized as 0, however when ClientLayerManager 72 * switches to another refresh driver, completed transactions of the previous 73 * refresh driver could be delivered and confuse the newly adopted refresh 74 * driver. To prevent this situation, use this function to reset transaction 75 * id to the last transaction id from previous refresh driver, so that all 76 * completed transactions of previous refresh driver will be ignored. 77 */ 78 virtual void ResetInitialTransactionId(TransactionId aTransactionId) = 0; 79 80 /** 81 * Get the start time of the current refresh tick. 82 */ 83 virtual mozilla::TimeStamp GetTransactionStart() = 0; 84 85 virtual VsyncId GetVsyncId() = 0; 86 87 virtual mozilla::TimeStamp GetVsyncStart() = 0; 88 }; 89 90 } // namespace layers 91 } // namespace mozilla 92 93 #endif /* GFX_TRANSACTION_ID_ALLOCATOR_H */