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 MOZILLA_LAYERS_LAYERTRANSACTIONCHILD_H
8 #define MOZILLA_LAYERS_LAYERTRANSACTIONCHILD_H
9 
10 #include <stdint.h>              // for uint32_t
11 #include "mozilla/Attributes.h"  // for override
12 #include "mozilla/ipc/ProtocolUtils.h"
13 #include "mozilla/layers/PLayerTransactionChild.h"
14 #include "mozilla/RefPtr.h"
15 
16 namespace mozilla {
17 
18 namespace layers {
19 
20 class ShadowLayerForwarder;
21 
22 class LayerTransactionChild : public PLayerTransactionChild {
23  public:
24   NS_INLINE_DECL_THREADSAFE_REFCOUNTING(LayerTransactionChild)
25   /**
26    * Clean this up, finishing with SendShutDown() which will cause __delete__
27    * to be sent from the parent side.
28    *
29    * It is expected (checked with an assert) that all shadow layers
30    * created by this have already been destroyed and
31    * Send__delete__()d by the time this method is called.
32    */
33   void Destroy();
34 
IPCOpen()35   bool IPCOpen() const { return mIPCOpen && !mDestroyed; }
IsDestroyed()36   bool IsDestroyed() const { return mDestroyed; }
37 
SetForwarder(ShadowLayerForwarder * aForwarder)38   void SetForwarder(ShadowLayerForwarder* aForwarder) {
39     mForwarder = aForwarder;
40   }
41 
GetId()42   LayersId GetId() const { return mId; }
43 
MarkDestroyed()44   void MarkDestroyed() { mDestroyed = true; }
45 
46  protected:
LayerTransactionChild(const LayersId & aId)47   explicit LayerTransactionChild(const LayersId& aId)
48       : mForwarder(nullptr), mIPCOpen(false), mDestroyed(false), mId(aId) {}
49   virtual ~LayerTransactionChild() = default;
50 
51   void ActorDestroy(ActorDestroyReason why) override;
52 
AddIPDLReference()53   void AddIPDLReference() {
54     MOZ_ASSERT(mIPCOpen == false);
55     mIPCOpen = true;
56     AddRef();
57   }
ReleaseIPDLReference()58   void ReleaseIPDLReference() {
59     MOZ_ASSERT(mIPCOpen == true);
60     mIPCOpen = false;
61     Release();
62   }
63   friend class CompositorBridgeChild;
64 
65   ShadowLayerForwarder* mForwarder;
66   bool mIPCOpen;
67   bool mDestroyed;
68   LayersId mId;
69 };
70 
71 }  // namespace layers
72 }  // namespace mozilla
73 
74 #endif  // MOZILLA_LAYERS_LAYERTRANSACTIONCHILD_H
75