no bug - Bumping Firefox l10n changesets r=release a=l10n-bump DONTBUILD CLOSED TREE
[gecko.git] / dom / ipc / VsyncWorkerChild.cpp
blob470ff73a27a1e2901bf703cd66bc44a2c17b5b2b
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 "VsyncWorkerChild.h"
8 #include "mozilla/dom/WorkerPrivate.h"
9 #include "mozilla/dom/WorkerRef.h"
10 #include "mozilla/dom/WorkerScope.h"
12 namespace mozilla::dom {
14 VsyncWorkerChild::VsyncWorkerChild() = default;
16 VsyncWorkerChild::~VsyncWorkerChild() = default;
18 bool VsyncWorkerChild::Initialize(WorkerPrivate* aWorkerPrivate) {
19 MOZ_ASSERT(aWorkerPrivate);
20 MOZ_ASSERT(!mWorkerRef);
22 mWorkerRef =
23 IPCWorkerRef::Create(aWorkerPrivate, "VsyncWorkerChild",
24 [self = RefPtr{this}]() { self->Destroy(); });
25 return !!mWorkerRef;
28 void VsyncWorkerChild::Destroy() {
29 MOZ_ASSERT_IF(!CanSend(), !mWorkerRef);
30 MOZ_ASSERT_IF(!CanSend(), !mObserving);
31 Send__delete__(this);
32 MOZ_ASSERT(!mWorkerRef);
33 MOZ_ASSERT(!mObserving);
36 void VsyncWorkerChild::TryObserve() {
37 if (CanSend() && !mObserving) {
38 mObserving = SendObserve();
42 void VsyncWorkerChild::TryUnobserve() {
43 if (CanSend() && mObserving) {
44 mObserving = !SendUnobserve();
48 mozilla::ipc::IPCResult VsyncWorkerChild::RecvNotify(const VsyncEvent& aVsync,
49 const float& aVsyncRate) {
50 // For MOZ_CAN_RUN_SCRIPT_BOUNDARY purposes: We know IPDL is explicitly
51 // keeping our actor alive until it is done processing the messages. We know
52 // that the WorkerGlobalScope callee is responsible keeping itself alive
53 // during the OnVsync callback.
54 WorkerPrivate* workerPrivate = mWorkerRef->Private();
55 WorkerGlobalScope* scope = workerPrivate->GlobalScope();
56 if (scope) {
57 scope->OnVsync(aVsync);
59 return IPC_OK();
62 void VsyncWorkerChild::ActorDestroy(ActorDestroyReason aActorDestroyReason) {
63 mWorkerRef = nullptr;
64 mObserving = false;
67 } // namespace mozilla::dom