tor-browser

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

VideoBridgeParent.h (3236B)


      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_VideoBridgeParent_h_
      8 #define gfx_layers_ipc_VideoBridgeParent_h_
      9 
     10 #include "mozilla/Monitor.h"
     11 #include "mozilla/layers/ISurfaceAllocator.h"
     12 #include "mozilla/layers/PVideoBridgeParent.h"
     13 
     14 namespace mozilla::layers {
     15 
     16 enum class VideoBridgeSource : uint8_t;
     17 class CompositorThreadHolder;
     18 
     19 class VideoBridgeParent final : public PVideoBridgeParent,
     20                                public HostIPCAllocator,
     21                                public mozilla::ipc::IShmemAllocator {
     22 public:
     23  NS_IMETHODIMP_(MozExternalRefCountType) AddRef(void) override;
     24  NS_IMETHODIMP_(MozExternalRefCountType) Release(void) override;
     25 
     26  static RefPtr<VideoBridgeParent> GetSingleton(
     27      const Maybe<VideoBridgeSource>& aSource);
     28 
     29  static void Open(Endpoint<PVideoBridgeParent>&& aEndpoint,
     30                   VideoBridgeSource aSource);
     31  static void Shutdown();
     32  static void UnregisterExternalImages();
     33 
     34  already_AddRefed<TextureHost> LookupTextureAsync(
     35      const dom::ContentParentId& aContentId, uint64_t aSerial);
     36  already_AddRefed<TextureHost> LookupTexture(
     37      const dom::ContentParentId& aContentId, uint64_t aSerial);
     38 
     39  // PVideoBridgeParent
     40  void ActorDestroy(ActorDestroyReason aWhy) override;
     41  PTextureParent* AllocPTextureParent(const SurfaceDescriptor& aSharedData,
     42                                      ReadLockDescriptor& aReadLock,
     43                                      const LayersBackend& aLayersBackend,
     44                                      const TextureFlags& aFlags,
     45                                      const dom::ContentParentId& aContentId,
     46                                      const uint64_t& aSerial);
     47  bool DeallocPTextureParent(PTextureParent* actor);
     48 
     49  // HostIPCAllocator
     50  base::ProcessId GetChildProcessId() override { return OtherPid(); }
     51  void NotifyNotUsed(PTextureParent* aTexture,
     52                     uint64_t aTransactionId) override;
     53  void SendAsyncMessage(
     54      const nsTArray<AsyncParentMessageData>& aMessage) override;
     55 
     56  // ISurfaceAllocator
     57  IShmemAllocator* AsShmemAllocator() override { return this; }
     58  bool IsSameProcess() const override;
     59  bool IPCOpen() const override { return !mClosed; }
     60 
     61  // IShmemAllocator
     62  bool AllocShmem(size_t aSize, mozilla::ipc::Shmem* aShmem) override;
     63 
     64  bool AllocUnsafeShmem(size_t aSize, mozilla::ipc::Shmem* aShmem) override;
     65 
     66  bool DeallocShmem(mozilla::ipc::Shmem& aShmem) override;
     67 
     68 private:
     69  ~VideoBridgeParent();
     70 
     71  explicit VideoBridgeParent(VideoBridgeSource aSource);
     72  void Bind(Endpoint<PVideoBridgeParent>&& aEndpoint);
     73  static void ShutdownInternal();
     74 
     75  void DoUnregisterExternalImages();
     76 
     77  Monitor mMonitor;
     78  RefPtr<CompositorThreadHolder> mCompositorThreadHolder
     79      MOZ_GUARDED_BY(mMonitor);
     80  std::map<uint64_t, PTextureParent*> mTextureMap MOZ_GUARDED_BY(mMonitor);
     81  bool mClosed;
     82 };
     83 
     84 }  // namespace mozilla::layers
     85 
     86 #endif  // gfx_layers_ipc_VideoBridgeParent_h_