Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/gfx/layers/ipc/ImageBridgeParent.h
Line
Count
Source (jump to first uncovered line)
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 gfx_layers_ipc_ImageBridgeParent_h_
8
#define gfx_layers_ipc_ImageBridgeParent_h_
9
10
#include <stddef.h>                     // for size_t
11
#include <stdint.h>                     // for uint32_t, uint64_t
12
#include "CompositableTransactionParent.h"
13
#include "mozilla/Assertions.h"         // for MOZ_ASSERT_HELPER2
14
#include "mozilla/Attributes.h"         // for override
15
#include "mozilla/ipc/ProtocolUtils.h"
16
#include "mozilla/ipc/SharedMemory.h"   // for SharedMemory, etc
17
#include "mozilla/layers/CompositorThread.h"
18
#include "mozilla/layers/PImageBridgeParent.h"
19
#include "nsISupportsImpl.h"
20
#include "nsTArrayForwardDeclare.h"     // for InfallibleTArray
21
22
class MessageLoop;
23
24
namespace base {
25
class Thread;
26
} // namespace base
27
28
namespace mozilla {
29
namespace ipc {
30
class Shmem;
31
} // namespace ipc
32
33
namespace layers {
34
35
struct ImageCompositeNotificationInfo;
36
37
/**
38
 * ImageBridgeParent is the manager Protocol of async Compositables.
39
 */
40
class ImageBridgeParent final : public PImageBridgeParent,
41
                                public CompositableParentManager,
42
                                public ShmemAllocator
43
{
44
public:
45
  typedef InfallibleTArray<CompositableOperation> EditArray;
46
  typedef InfallibleTArray<OpDestroy> OpDestroyArray;
47
48
protected:
49
  ImageBridgeParent(MessageLoop* aLoop, ProcessId aChildProcessId);
50
51
public:
52
  ~ImageBridgeParent();
53
54
  /**
55
   * Creates the globals of ImageBridgeParent.
56
   */
57
  static void Setup();
58
59
  static ImageBridgeParent* CreateSameProcess();
60
  static bool CreateForGPUProcess(Endpoint<PImageBridgeParent>&& aEndpoint);
61
  static bool CreateForContent(Endpoint<PImageBridgeParent>&& aEndpoint);
62
  static void Shutdown();
63
64
0
  virtual ShmemAllocator* AsShmemAllocator() override { return this; }
65
66
  virtual void ActorDestroy(ActorDestroyReason aWhy) override;
67
68
  // CompositableParentManager
69
  virtual void SendAsyncMessage(const InfallibleTArray<AsyncParentMessageData>& aMessage) override;
70
71
  virtual void NotifyNotUsed(PTextureParent* aTexture, uint64_t aTransactionId) override;
72
73
  virtual base::ProcessId GetChildProcessId() override
74
0
  {
75
0
    return OtherPid();
76
0
  }
77
78
  // PImageBridge
79
  virtual mozilla::ipc::IPCResult RecvUpdate(EditArray&& aEdits, OpDestroyArray&& aToDestroy,
80
                                          const uint64_t& aFwdTransactionId) override;
81
82
  virtual PTextureParent* AllocPTextureParent(const SurfaceDescriptor& aSharedData,
83
                                              const ReadLockDescriptor& aReadLock,
84
                                              const LayersBackend& aLayersBackend,
85
                                              const TextureFlags& aFlags,
86
                                              const uint64_t& aSerial,
87
                                              const wr::MaybeExternalImageId& aExternalImageId) override;
88
  virtual bool DeallocPTextureParent(PTextureParent* actor) override;
89
90
  virtual mozilla::ipc::IPCResult RecvNewCompositable(const CompositableHandle& aHandle,
91
                                                      const TextureInfo& aInfo,
92
                                                      const LayersBackend& aLayersBackend) override;
93
  virtual mozilla::ipc::IPCResult RecvReleaseCompositable(const CompositableHandle& aHandle) override;
94
95
  PMediaSystemResourceManagerParent* AllocPMediaSystemResourceManagerParent() override;
96
  bool DeallocPMediaSystemResourceManagerParent(PMediaSystemResourceManagerParent* aActor) override;
97
98
  // Shutdown step 1
99
  virtual mozilla::ipc::IPCResult RecvWillClose() override;
100
101
0
  MessageLoop* GetMessageLoop() const { return mMessageLoop; }
102
103
  // ShmemAllocator
104
105
  virtual bool AllocShmem(size_t aSize,
106
                          ipc::SharedMemory::SharedMemoryType aType,
107
                          ipc::Shmem* aShmem) override;
108
109
  virtual bool AllocUnsafeShmem(size_t aSize,
110
                                ipc::SharedMemory::SharedMemoryType aType,
111
                                ipc::Shmem* aShmem) override;
112
113
  virtual void DeallocShmem(ipc::Shmem& aShmem) override;
114
115
  virtual bool IsSameProcess() const override;
116
117
  static already_AddRefed<ImageBridgeParent> GetInstance(ProcessId aId);
118
119
  static bool NotifyImageComposites(nsTArray<ImageCompositeNotificationInfo>& aNotifications);
120
121
0
  virtual bool UsesImageBridge() const override { return true; }
122
123
0
  virtual bool IPCOpen() const override { return !mClosed; }
124
125
protected:
126
  void Bind(Endpoint<PImageBridgeParent>&& aEndpoint);
127
128
private:
129
  static void ShutdownInternal();
130
131
  void DeferredDestroy();
132
  MessageLoop* mMessageLoop;
133
  // This keeps us alive until ActorDestroy(), at which point we do a
134
  // deferred destruction of ourselves.
135
  RefPtr<ImageBridgeParent> mSelfRef;
136
137
  bool mClosed;
138
139
  /**
140
   * Map of all living ImageBridgeParent instances
141
   */
142
  typedef std::map<base::ProcessId, ImageBridgeParent*> ImageBridgeMap;
143
  static ImageBridgeMap sImageBridges;
144
145
  RefPtr<CompositorThreadHolder> mCompositorThreadHolder;
146
};
147
148
} // namespace layers
149
} // namespace mozilla
150
151
#endif // gfx_layers_ipc_ImageBridgeParent_h_