no bug - Import translations from android-l10n r=release a=l10n CLOSED TREE
[gecko.git] / gfx / layers / ipc / CompositorManagerChild.h
blob072b0d028ee23eae264d1ec82a729a722ffef14a
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/. */
7 #ifndef MOZILLA_GFX_COMPOSITORMANAGERCHILD_H
8 #define MOZILLA_GFX_COMPOSITORMANAGERCHILD_H
10 #include <stddef.h> // for size_t
11 #include <stdint.h> // for uint32_t, uint64_t
12 #include "mozilla/Atomics.h"
13 #include "mozilla/Attributes.h" // for override
14 #include "mozilla/RefPtr.h" // for already_AddRefed
15 #include "mozilla/StaticPtr.h" // for StaticRefPtr
16 #include "mozilla/layers/CompositableForwarder.h" // for FwdTransactionCounter
17 #include "mozilla/layers/PCompositorManagerChild.h"
19 namespace mozilla {
20 namespace layers {
22 class CompositorBridgeChild;
23 class CompositorManagerParent;
24 class WebRenderLayerManager;
26 class CompositorManagerChild : public PCompositorManagerChild {
27 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(CompositorManagerChild, override)
29 public:
30 static bool IsInitialized(uint64_t aProcessToken);
31 static void InitSameProcess(uint32_t aNamespace, uint64_t aProcessToken);
32 static bool Init(Endpoint<PCompositorManagerChild>&& aEndpoint,
33 uint32_t aNamespace, uint64_t aProcessToken = 0);
34 static void Shutdown();
35 static void OnGPUProcessLost(uint64_t aProcessToken);
37 static bool CreateContentCompositorBridge(uint32_t aNamespace);
39 static already_AddRefed<CompositorBridgeChild> CreateWidgetCompositorBridge(
40 uint64_t aProcessToken, WebRenderLayerManager* aLayerManager,
41 uint32_t aNamespace, CSSToLayoutDeviceScale aScale,
42 const CompositorOptions& aOptions, bool aUseExternalSurfaceSize,
43 const gfx::IntSize& aSurfaceSize, uint64_t aInnerWindowId);
45 static already_AddRefed<CompositorBridgeChild>
46 CreateSameProcessWidgetCompositorBridge(WebRenderLayerManager* aLayerManager,
47 uint32_t aNamespace);
49 static CompositorManagerChild* GetInstance() {
50 MOZ_ASSERT(NS_IsMainThread());
51 return sInstance;
54 // Threadsafe way to get the compositor process ID.
55 static base::ProcessId GetOtherPid() { return sOtherPid; }
57 bool CanSend() const {
58 MOZ_ASSERT(NS_IsMainThread());
59 return mCanSend;
62 bool SameProcess() const {
63 MOZ_ASSERT(NS_IsMainThread());
64 return mSameProcess;
67 uint32_t GetNextResourceId() {
68 MOZ_ASSERT(NS_IsMainThread());
69 return ++mResourceId;
72 uint32_t GetNamespace() const { return mNamespace; }
74 bool OwnsExternalImageId(const wr::ExternalImageId& aId) const {
75 return mNamespace == static_cast<uint32_t>(wr::AsUint64(aId) >> 32);
78 wr::ExternalImageId GetNextExternalImageId() {
79 uint64_t id = GetNextResourceId();
80 MOZ_RELEASE_ASSERT(id != 0);
81 id |= (static_cast<uint64_t>(mNamespace) << 32);
82 return wr::ToExternalImageId(id);
85 void ActorDestroy(ActorDestroyReason aReason) override;
87 void HandleFatalError(const char* aMsg) override;
89 void ProcessingError(Result aCode, const char* aReason) override;
91 bool ShouldContinueFromReplyTimeout() override;
93 mozilla::ipc::IPCResult RecvNotifyWebRenderError(
94 const WebRenderError&& aError);
96 FwdTransactionCounter& GetFwdTransactionCounter() {
97 return mFwdTransactionCounter;
100 private:
101 static StaticRefPtr<CompositorManagerChild> sInstance;
102 static Atomic<base::ProcessId> sOtherPid;
104 CompositorManagerChild(CompositorManagerParent* aParent,
105 uint64_t aProcessToken, uint32_t aNamespace);
107 CompositorManagerChild(Endpoint<PCompositorManagerChild>&& aEndpoint,
108 uint64_t aProcessToken, uint32_t aNamespace);
110 virtual ~CompositorManagerChild() = default;
112 void SetReplyTimeout();
114 uint64_t mProcessToken;
115 uint32_t mNamespace;
116 uint32_t mResourceId;
117 bool mCanSend;
118 bool mSameProcess;
119 FwdTransactionCounter mFwdTransactionCounter;
122 } // namespace layers
123 } // namespace mozilla
125 #endif