/src/mozilla-central/gfx/layers/ipc/CompositorManagerChild.h
Line | Count | Source (jump to first uncovered line) |
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_COMPOSITORMANAGERCHILD_H |
8 | | #define MOZILLA_GFX_COMPOSITORMANAGERCHILD_H |
9 | | |
10 | | #include <stddef.h> // for size_t |
11 | | #include <stdint.h> // for uint32_t, uint64_t |
12 | | #include "mozilla/Attributes.h" // for override |
13 | | #include "mozilla/RefPtr.h" // for already_AddRefed |
14 | | #include "mozilla/StaticPtr.h" // for StaticRefPtr |
15 | | #include "mozilla/layers/PCompositorManagerChild.h" |
16 | | |
17 | | namespace mozilla { |
18 | | namespace layers { |
19 | | |
20 | | class CompositorManagerParent; |
21 | | class LayerManager; |
22 | | |
23 | | class CompositorManagerChild : public PCompositorManagerChild |
24 | | { |
25 | | NS_INLINE_DECL_THREADSAFE_REFCOUNTING(CompositorManagerChild) |
26 | | |
27 | | public: |
28 | | static bool IsInitialized(uint64_t aProcessToken); |
29 | | static void InitSameProcess(uint32_t aNamespace, uint64_t aProcessToken); |
30 | | static bool Init(Endpoint<PCompositorManagerChild>&& aEndpoint, |
31 | | uint32_t aNamespace, |
32 | | uint64_t aProcessToken = 0); |
33 | | static void Shutdown(); |
34 | | static void OnGPUProcessLost(uint64_t aProcessToken); |
35 | | |
36 | | static bool |
37 | | CreateContentCompositorBridge(uint32_t aNamespace); |
38 | | |
39 | | static already_AddRefed<CompositorBridgeChild> |
40 | | CreateWidgetCompositorBridge(uint64_t aProcessToken, |
41 | | LayerManager* aLayerManager, |
42 | | uint32_t aNamespace, |
43 | | CSSToLayoutDeviceScale aScale, |
44 | | const CompositorOptions& aOptions, |
45 | | bool aUseExternalSurfaceSize, |
46 | | const gfx::IntSize& aSurfaceSize); |
47 | | |
48 | | static already_AddRefed<CompositorBridgeChild> |
49 | | CreateSameProcessWidgetCompositorBridge(LayerManager* aLayerManager, |
50 | | uint32_t aNamespace); |
51 | | |
52 | | static CompositorManagerChild* GetInstance() |
53 | 0 | { |
54 | 0 | MOZ_ASSERT(NS_IsMainThread()); |
55 | 0 | return sInstance; |
56 | 0 | } |
57 | | |
58 | | bool CanSend() const |
59 | | { |
60 | | MOZ_ASSERT(NS_IsMainThread()); |
61 | | return mCanSend; |
62 | | } |
63 | | |
64 | | uint32_t GetNextResourceId() |
65 | 0 | { |
66 | 0 | MOZ_ASSERT(NS_IsMainThread()); |
67 | 0 | return ++mResourceId; |
68 | 0 | } |
69 | | |
70 | | uint32_t GetNamespace() const |
71 | | { |
72 | | return mNamespace; |
73 | | } |
74 | | |
75 | | bool OwnsExternalImageId(const wr::ExternalImageId& aId) const |
76 | 0 | { |
77 | 0 | return mNamespace == static_cast<uint32_t>(wr::AsUint64(aId) >> 32); |
78 | 0 | } |
79 | | |
80 | | wr::ExternalImageId GetNextExternalImageId() |
81 | 0 | { |
82 | 0 | uint64_t id = GetNextResourceId(); |
83 | 0 | MOZ_RELEASE_ASSERT(id != 0); |
84 | 0 | id |= (static_cast<uint64_t>(mNamespace) << 32); |
85 | 0 | return wr::ToExternalImageId(id); |
86 | 0 | } |
87 | | |
88 | | void ActorDestroy(ActorDestroyReason aReason) override; |
89 | | |
90 | | void HandleFatalError(const char* aMsg) const override; |
91 | | |
92 | | void ProcessingError(Result aCode, const char* aReason) override; |
93 | | |
94 | | PCompositorBridgeChild* AllocPCompositorBridgeChild(const CompositorBridgeOptions& aOptions) override; |
95 | | |
96 | | bool DeallocPCompositorBridgeChild(PCompositorBridgeChild* aActor) override; |
97 | | |
98 | | bool ShouldContinueFromReplyTimeout() override; |
99 | | |
100 | | private: |
101 | | static StaticRefPtr<CompositorManagerChild> sInstance; |
102 | | |
103 | | CompositorManagerChild(CompositorManagerParent* aParent, |
104 | | uint64_t aProcessToken, |
105 | | uint32_t aNamespace); |
106 | | |
107 | | CompositorManagerChild(Endpoint<PCompositorManagerChild>&& aEndpoint, |
108 | | uint64_t aProcessToken, |
109 | | uint32_t aNamespace); |
110 | | |
111 | | ~CompositorManagerChild() override |
112 | | { |
113 | | } |
114 | | |
115 | | void DeallocPCompositorManagerChild() override; |
116 | | |
117 | | already_AddRefed<nsIEventTarget> |
118 | | GetSpecificMessageEventTarget(const Message& aMsg) override; |
119 | | |
120 | | void SetReplyTimeout(); |
121 | | |
122 | | uint64_t mProcessToken; |
123 | | uint32_t mNamespace; |
124 | | uint32_t mResourceId; |
125 | | bool mCanSend; |
126 | | }; |
127 | | |
128 | | } // namespace layers |
129 | | } // namespace mozilla |
130 | | |
131 | | #endif |