Bug 1842773 - Part 5: Add ArrayBuffer.prototype.{maxByteLength,resizable} getters...
[gecko.git] / dom / base / AnimationFrameProvider.cpp
blobba2ee8849b0b18bee17c24c73a5ff4995ff7c814
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 #include "mozilla/dom/AnimationFrameProvider.h"
8 #include "nsThreadUtils.h"
10 namespace mozilla::dom {
12 FrameRequest::FrameRequest(FrameRequestCallback& aCallback, int32_t aHandle)
13 : mCallback(&aCallback), mHandle(aHandle) {
14 LogFrameRequestCallback::LogDispatch(mCallback);
17 FrameRequest::~FrameRequest() = default;
19 nsresult FrameRequestManager::Schedule(FrameRequestCallback& aCallback,
20 int32_t* aHandle) {
21 if (mCallbackCounter == INT32_MAX) {
22 // Can't increment without overflowing; bail out
23 return NS_ERROR_NOT_AVAILABLE;
25 int32_t newHandle = ++mCallbackCounter;
27 mCallbacks.AppendElement(FrameRequest(aCallback, newHandle));
29 *aHandle = newHandle;
30 return NS_OK;
33 bool FrameRequestManager::Cancel(int32_t aHandle) {
34 // mCallbacks is stored sorted by handle
35 if (mCallbacks.RemoveElementSorted(aHandle)) {
36 return true;
39 Unused << mCanceledCallbacks.put(aHandle);
40 return false;
43 void FrameRequestManager::Unlink() { mCallbacks.Clear(); }
45 void FrameRequestManager::Traverse(nsCycleCollectionTraversalCallback& aCB) {
46 for (auto& i : mCallbacks) {
47 NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(aCB,
48 "FrameRequestManager::mCallbacks[i]");
49 aCB.NoteXPCOMChild(i.mCallback);
53 } // namespace mozilla::dom