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 <stdint.h>               // for uint32_t
11 #include "mozilla/Attributes.h"   // for override
12 #include "mozilla/StaticPtr.h"    // for StaticRefPtr
13 #include "mozilla/StaticMutex.h"  // for StaticMutex
14 #include "mozilla/RefPtr.h"       // for already_AddRefed
15 #include "mozilla/layers/PCompositorManagerParent.h"
16 #include "nsTArray.h"  // for AutoTArray
17 
18 namespace mozilla {
19 namespace layers {
20 
21 class CompositorBridgeParent;
22 class CompositorThreadHolder;
23 
24 #ifndef DEBUG
25 #  define COMPOSITOR_MANAGER_PARENT_EXPLICIT_SHUTDOWN
26 #endif
27 
28 class CompositorManagerParent final : public PCompositorManagerParent {
29   NS_INLINE_DECL_THREADSAFE_REFCOUNTING(CompositorManagerParent)
30 
31  public:
32   static already_AddRefed<CompositorManagerParent> CreateSameProcess();
33   static bool Create(Endpoint<PCompositorManagerParent>&& aEndpoint,
34                      bool aIsRoot);
35   static void Shutdown();
36 
37   static already_AddRefed<CompositorBridgeParent>
38   CreateSameProcessWidgetCompositorBridge(CSSToLayoutDeviceScale aScale,
39                                           const CompositorOptions& aOptions,
40                                           bool aUseExternalSurfaceSize,
41                                           const gfx::IntSize& aSurfaceSize);
42 
43   mozilla::ipc::IPCResult RecvAddSharedSurface(const wr::ExternalImageId& aId,
44                                                SurfaceDescriptorShared&& aDesc);
45   mozilla::ipc::IPCResult RecvRemoveSharedSurface(
46       const wr::ExternalImageId& aId);
47   mozilla::ipc::IPCResult RecvReportSharedSurfacesMemory(
48       ReportSharedSurfacesMemoryResolver&&);
49 
50   mozilla::ipc::IPCResult RecvNotifyMemoryPressure();
51 
52   mozilla::ipc::IPCResult RecvReportMemory(ReportMemoryResolver&&);
53 
54   mozilla::ipc::IPCResult RecvInitCanvasManager(
55       Endpoint<PCanvasManagerParent>&&);
56 
57   void BindComplete(bool aIsRoot);
58   void ActorDestroy(ActorDestroyReason aReason) override;
59 
60   already_AddRefed<PCompositorBridgeParent> AllocPCompositorBridgeParent(
61       const CompositorBridgeOptions& aOpt);
62 
63   static void NotifyWebRenderError(wr::WebRenderError aError);
64 
65  private:
66   static StaticRefPtr<CompositorManagerParent> sInstance;
67   static StaticMutex sMutex;
68 
69 #ifdef COMPOSITOR_MANAGER_PARENT_EXPLICIT_SHUTDOWN
70   static StaticAutoPtr<nsTArray<CompositorManagerParent*>> sActiveActors;
71   static void ShutdownInternal();
72 #endif
73 
74   CompositorManagerParent();
75   virtual ~CompositorManagerParent();
76 
77   void Bind(Endpoint<PCompositorManagerParent>&& aEndpoint, bool aIsRoot);
78 
79   void ActorDealloc() override;
80 
81   void DeferredDestroy();
82 
83   RefPtr<CompositorThreadHolder> mCompositorThreadHolder;
84 
85   AutoTArray<RefPtr<CompositorBridgeParent>, 1> mPendingCompositorBridges;
86 };
87 
88 }  // namespace layers
89 }  // namespace mozilla
90 
91 #endif
92