CompositorManagerParent.h (4143B)
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_GFX_COMPOSITORMANAGERPARENT_H 8 #define MOZILLA_GFX_COMPOSITORMANAGERPARENT_H 9 10 #include <map> 11 #include <stdint.h> // for uint32_t 12 #include "mozilla/StaticPtr.h" // for StaticRefPtr 13 #include "mozilla/StaticMonitor.h" // for StaticMonitor 14 #include "mozilla/RefPtr.h" // for already_AddRefed 15 #include "mozilla/dom/ipc/IdType.h" 16 #include "mozilla/layers/PCompositorManagerParent.h" 17 #include "nsTArray.h" // for AutoTArray 18 19 namespace mozilla { 20 21 namespace gfx { 22 class SourceSurfaceSharedData; 23 } 24 25 namespace layers { 26 27 class CompositorBridgeParent; 28 class CompositorThreadHolder; 29 class RemoteTextureTxnScheduler; 30 class SharedSurfacesHolder; 31 32 class CompositorManagerParent final : public PCompositorManagerParent { 33 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(CompositorManagerParent, final) 34 35 public: 36 static already_AddRefed<CompositorManagerParent> CreateSameProcess( 37 uint32_t aNamespace); 38 static bool Create(Endpoint<PCompositorManagerParent>&& aEndpoint, 39 dom::ContentParentId aContentId, uint32_t aNamespace, 40 bool aIsRoot); 41 static void Shutdown(); 42 43 static already_AddRefed<CompositorBridgeParent> 44 CreateSameProcessWidgetCompositorBridge(CSSToLayoutDeviceScale aScale, 45 const CompositorOptions& aOptions, 46 bool aUseExternalSurfaceSize, 47 const gfx::IntSize& aSurfaceSize, 48 uint64_t aInnerWindowId); 49 50 static void WaitForSharedSurface(const wr::ExternalImageId& aId); 51 52 static void AddSharedSurface(const wr::ExternalImageId& aId, 53 gfx::SourceSurfaceSharedData* aSurface); 54 55 mozilla::ipc::IPCResult RecvAddSharedSurface(const wr::ExternalImageId& aId, 56 SurfaceDescriptorShared&& aDesc); 57 mozilla::ipc::IPCResult RecvRemoveSharedSurface( 58 const wr::ExternalImageId& aId); 59 mozilla::ipc::IPCResult RecvReportSharedSurfacesMemory( 60 ReportSharedSurfacesMemoryResolver&&); 61 62 mozilla::ipc::IPCResult RecvNotifyMemoryPressure(); 63 64 mozilla::ipc::IPCResult RecvReportMemory(ReportMemoryResolver&&); 65 66 mozilla::ipc::IPCResult RecvInitCanvasManager( 67 Endpoint<PCanvasManagerParent>&&); 68 69 void BindComplete(bool aIsRoot); 70 void ActorDestroy(ActorDestroyReason aReason) override; 71 72 already_AddRefed<PCompositorBridgeParent> AllocPCompositorBridgeParent( 73 const CompositorBridgeOptions& aOpt); 74 75 static void NotifyWebRenderError(wr::WebRenderError aError); 76 77 const dom::ContentParentId& GetContentId() const { return mContentId; } 78 79 bool OwnsExternalImageId(const wr::ExternalImageId& aId) const { 80 return mNamespace == static_cast<uint32_t>(wr::AsUint64(aId) >> 32); 81 } 82 83 private: 84 static StaticMonitor sMonitor; 85 static StaticRefPtr<CompositorManagerParent> sInstance 86 MOZ_GUARDED_BY(sMonitor); 87 88 // Indexed by namespace. 89 using ManagerMap = std::map<uint32_t, CompositorManagerParent*>; 90 static ManagerMap sManagers MOZ_GUARDED_BY(sMonitor); 91 92 static void ShutdownInternal(); 93 94 CompositorManagerParent(dom::ContentParentId aContentId, uint32_t aNamespace); 95 virtual ~CompositorManagerParent(); 96 97 void Bind(Endpoint<PCompositorManagerParent>&& aEndpoint, bool aIsRoot); 98 99 void DeferredDestroy(); 100 101 RefPtr<CompositorThreadHolder> mCompositorThreadHolder; 102 RefPtr<SharedSurfacesHolder> mSharedSurfacesHolder; 103 AutoTArray<RefPtr<CompositorBridgeParent>, 1> mPendingCompositorBridges; 104 const dom::ContentParentId mContentId; 105 const uint32_t mNamespace; 106 uint32_t mLastSharedSurfaceResourceId MOZ_GUARDED_BY(sMonitor) = 0; 107 RefPtr<RemoteTextureTxnScheduler> mRemoteTextureTxnScheduler; 108 }; 109 110 } // namespace layers 111 } // namespace mozilla 112 113 #endif