Bug 1919083 - [ci] Enable os-integration variant for more suites, r=jmaher
[gecko.git] / gfx / layers / IPDLActor.h
blobb5eb04d0dcea0cf3b1440fb481c11cfaf022bfb3
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_LAYERS_IPDLACTOR_H
8 #define MOZILLA_LAYERS_IPDLACTOR_H
10 #include "mozilla/ipc/ProtocolUtils.h"
11 #include "mozilla/layers/CompositableForwarder.h"
12 #include "mozilla/Unused.h"
13 #include "gfxPlatform.h"
15 namespace mozilla {
16 namespace layers {
18 /// A base class to facilitate the deallocation of IPDL actors.
19 ///
20 /// Implements the parent side of the simple deallocation handshake.
21 /// Override the Destroy method rather than the ActorDestroy method.
22 template <typename Protocol>
23 class ParentActor : public Protocol {
24 public:
25 ParentActor() : mDestroyed(false) {}
27 ~ParentActor() { MOZ_ASSERT(mDestroyed); }
29 bool CanSend() const { return !mDestroyed; }
31 // Override this rather than ActorDestroy
32 virtual void Destroy() {}
34 mozilla::ipc::IPCResult RecvDestroy() final {
35 DestroyIfNeeded();
36 Unused << Protocol::Send__delete__(this);
37 return IPC_OK();
40 typedef ipc::IProtocol::ActorDestroyReason Why;
42 void ActorDestroy(Why) override { DestroyIfNeeded(); }
44 protected:
45 void DestroyIfNeeded() {
46 if (!mDestroyed) {
47 Destroy();
48 mDestroyed = true;
52 private:
53 bool mDestroyed;
56 } // namespace layers
57 } // namespace mozilla
59 #endif