tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

ImageBridgeParent.h (4892B)


      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/dom/ipc/IdType.h"
     14 #include "mozilla/ipc/ProtocolUtils.h"
     15 #include "mozilla/layers/CompositorThread.h"
     16 #include "mozilla/layers/PImageBridgeParent.h"
     17 #include "nsISupportsImpl.h"
     18 #include "nsTArrayForwardDeclare.h"  // for nsTArray
     19 
     20 namespace mozilla {
     21 namespace ipc {
     22 class Shmem;
     23 }  // namespace ipc
     24 
     25 namespace layers {
     26 
     27 struct ImageCompositeNotificationInfo;
     28 class RemoteTextureTxnScheduler;
     29 
     30 /**
     31 * ImageBridgeParent is the manager Protocol of async Compositables.
     32 */
     33 class ImageBridgeParent final : public PImageBridgeParent,
     34                                public CompositableParentManager,
     35                                public mozilla::ipc::IShmemAllocator {
     36 public:
     37  typedef nsTArray<CompositableOperation> EditArray;
     38  typedef nsTArray<OpDestroy> OpDestroyArray;
     39 
     40 protected:
     41  ImageBridgeParent(nsISerialEventTarget* aThread,
     42                    ipc::EndpointProcInfo aChildProcessInfo,
     43                    dom::ContentParentId aContentId);
     44 
     45 public:
     46  NS_IMETHOD_(MozExternalRefCountType) AddRef() override {
     47    return ISurfaceAllocator::AddRef();
     48  }
     49  NS_IMETHOD_(MozExternalRefCountType) Release() override {
     50    return ISurfaceAllocator::Release();
     51  }
     52 
     53  /**
     54   * Creates the globals of ImageBridgeParent.
     55   */
     56  static void Setup();
     57 
     58  static ImageBridgeParent* CreateSameProcess();
     59  static bool CreateForGPUProcess(Endpoint<PImageBridgeParent>&& aEndpoint);
     60  static bool CreateForContent(Endpoint<PImageBridgeParent>&& aEndpoint,
     61                               dom::ContentParentId aContentId);
     62  static void Shutdown();
     63 
     64  IShmemAllocator* AsShmemAllocator() override { return this; }
     65 
     66  void ActorDestroy(ActorDestroyReason aWhy) override;
     67 
     68  // CompositableParentManager
     69  void SendAsyncMessage(
     70      const nsTArray<AsyncParentMessageData>& aMessage) override;
     71 
     72  void NotifyNotUsed(PTextureParent* aTexture,
     73                     uint64_t aTransactionId) override;
     74 
     75  base::ProcessId GetChildProcessId() override { return OtherPid(); }
     76  dom::ContentParentId GetContentId() override { return mContentId; }
     77 
     78  // PImageBridge
     79  mozilla::ipc::IPCResult RecvUpdate(EditArray&& aEdits,
     80                                     OpDestroyArray&& aToDestroy,
     81                                     const uint64_t& aFwdTransactionId);
     82 
     83  PTextureParent* AllocPTextureParent(
     84      const SurfaceDescriptor& aSharedData, ReadLockDescriptor& aReadLock,
     85      const LayersBackend& aLayersBackend, const TextureFlags& aFlags,
     86      const uint64_t& aSerial,
     87      const wr::MaybeExternalImageId& aExternalImageId);
     88  bool DeallocPTextureParent(PTextureParent* actor);
     89 
     90  mozilla::ipc::IPCResult RecvNewCompositable(const CompositableHandle& aHandle,
     91                                              const TextureInfo& aInfo);
     92  mozilla::ipc::IPCResult RecvReleaseCompositable(
     93      const CompositableHandle& aHandle);
     94 
     95  PMediaSystemResourceManagerParent* AllocPMediaSystemResourceManagerParent();
     96  bool DeallocPMediaSystemResourceManagerParent(
     97      PMediaSystemResourceManagerParent* aActor);
     98 
     99  // Shutdown step 1
    100  mozilla::ipc::IPCResult RecvWillClose();
    101 
    102  nsISerialEventTarget* GetThread() const { return mThread; }
    103 
    104  // IShmemAllocator
    105 
    106  bool AllocShmem(size_t aSize, ipc::Shmem* aShmem) override;
    107 
    108  bool AllocUnsafeShmem(size_t aSize, ipc::Shmem* aShmem) override;
    109 
    110  bool DeallocShmem(ipc::Shmem& aShmem) override;
    111 
    112  bool IsSameProcess() const override;
    113 
    114  static already_AddRefed<ImageBridgeParent> GetInstance(ProcessId aId);
    115 
    116  static bool NotifyImageComposites(
    117      nsTArray<ImageCompositeNotificationInfo>& aNotifications);
    118 
    119  bool UsesImageBridge() const override { return true; }
    120 
    121  bool IPCOpen() const override { return !mClosed; }
    122 
    123 protected:
    124  void Bind(Endpoint<PImageBridgeParent>&& aEndpoint);
    125 
    126 private:
    127  virtual ~ImageBridgeParent();
    128 
    129  static void ShutdownInternal();
    130 
    131  void DeferredDestroy();
    132  nsCOMPtr<nsISerialEventTarget> mThread;
    133 
    134  dom::ContentParentId mContentId;
    135 
    136  bool mClosed;
    137 
    138  /**
    139   * Map of all living ImageBridgeParent instances
    140   */
    141  typedef std::map<base::ProcessId, ImageBridgeParent*> ImageBridgeMap;
    142  static ImageBridgeMap sImageBridges;
    143 
    144  RefPtr<CompositorThreadHolder> mCompositorThreadHolder;
    145 
    146  RefPtr<RemoteTextureTxnScheduler> mRemoteTextureTxnScheduler;
    147 };
    148 
    149 }  // namespace layers
    150 }  // namespace mozilla
    151 
    152 #endif  // gfx_layers_ipc_ImageBridgeParent_h_