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/. */
7 #ifndef mozilla_dom_AnimationFrameProvider_h
8 #define mozilla_dom_AnimationFrameProvider_h
10 #include "mozilla/dom/AnimationFrameProviderBinding.h"
11 #include "mozilla/HashTable.h"
12 #include "mozilla/RefPtr.h"
15 namespace mozilla::dom
{
18 FrameRequest(FrameRequestCallback
& aCallback
, int32_t aHandle
);
21 // Comparator operators to allow RemoveElementSorted with an
22 // integer argument on arrays of FrameRequest
23 bool operator==(int32_t aHandle
) const { return mHandle
== aHandle
; }
24 bool operator<(int32_t aHandle
) const { return mHandle
< aHandle
; }
26 RefPtr
<FrameRequestCallback
> mCallback
;
30 class FrameRequestManager
{
32 FrameRequestManager() = default;
33 ~FrameRequestManager() = default;
35 nsresult
Schedule(FrameRequestCallback
& aCallback
, int32_t* aHandle
);
36 bool Cancel(int32_t aHandle
);
38 bool IsEmpty() const { return mCallbacks
.IsEmpty(); }
40 bool IsCanceled(int32_t aHandle
) const {
41 return !mCanceledCallbacks
.empty() && mCanceledCallbacks
.has(aHandle
);
44 void Take(nsTArray
<FrameRequest
>& aCallbacks
) {
45 aCallbacks
= std::move(mCallbacks
);
46 mCanceledCallbacks
.clear();
51 void Traverse(nsCycleCollectionTraversalCallback
& aCB
);
54 nsTArray
<FrameRequest
> mCallbacks
;
56 // The set of frame request callbacks that were canceled but which we failed
57 // to find in mFrameRequestCallbacks.
58 HashSet
<int32_t> mCanceledCallbacks
;
61 * The current frame request callback handle
63 int32_t mCallbackCounter
= 0;
66 inline void ImplCycleCollectionUnlink(FrameRequestManager
& aField
) {
70 inline void ImplCycleCollectionTraverse(
71 nsCycleCollectionTraversalCallback
& aCallback
, FrameRequestManager
& aField
,
72 const char* aName
, uint32_t aFlags
) {
73 aField
.Traverse(aCallback
);
76 } // namespace mozilla::dom