Bug 1690340 - Part 2: Use the new naming for the developer tools menu items. r=jdescottes
[gecko.git] / gfx / layers / ipc / KnowsCompositor.h
blob68fd77eda1944bf7dd6b2efe6ef0d93f7baae36c
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_LAYERS_KNOWSCOMPOSITOR
8 #define MOZILLA_LAYERS_KNOWSCOMPOSITOR
10 #include "mozilla/layers/LayersTypes.h" // for LayersBackend
11 #include "mozilla/layers/CompositorTypes.h"
12 #include "nsExpirationTracker.h"
13 #include "mozilla/DataMutex.h"
14 #include "mozilla/layers/SyncObject.h"
16 namespace mozilla {
17 namespace layers {
19 class TextureForwarder;
20 class LayersIPCActor;
21 class ImageBridgeChild;
23 /**
24 * See ActiveResourceTracker below.
26 class ActiveResource {
27 public:
28 virtual void NotifyInactive() = 0;
29 nsExpirationState* GetExpirationState() { return &mExpirationState; }
30 bool IsActivityTracked() { return mExpirationState.IsTracked(); }
32 private:
33 nsExpirationState mExpirationState;
36 /**
37 * A convenience class on top of nsExpirationTracker
39 class ActiveResourceTracker : public nsExpirationTracker<ActiveResource, 3> {
40 public:
41 ActiveResourceTracker(uint32_t aExpirationCycle, const char* aName,
42 nsIEventTarget* aEventTarget)
43 : nsExpirationTracker(aExpirationCycle, aName, aEventTarget) {}
45 void NotifyExpired(ActiveResource* aResource) override {
46 RemoveObject(aResource);
47 aResource->NotifyInactive();
51 /**
52 * An abstract interface for classes that are tied to a specific Compositor
53 * across IPDL and uses TextureFactoryIdentifier to describe this Compositor.
55 class KnowsCompositor {
56 public:
57 NS_INLINE_DECL_PURE_VIRTUAL_REFCOUNTING
59 KnowsCompositor();
60 virtual ~KnowsCompositor();
62 void IdentifyTextureHost(const TextureFactoryIdentifier& aIdentifier);
64 // The sync object for the global content device.
65 RefPtr<SyncObjectClient> GetSyncObject() {
66 auto lock = mData.Lock();
67 if (lock.ref().mSyncObject) {
68 lock.ref().mSyncObject->EnsureInitialized();
70 return lock.ref().mSyncObject;
73 /// And by "thread-safe" here we merely mean "okay to hold strong references
74 /// to from multiple threads". Not all methods actually are thread-safe.
75 virtual bool IsThreadSafe() const { return true; }
77 virtual RefPtr<KnowsCompositor> GetForMedia() {
78 return RefPtr<KnowsCompositor>(this);
81 int32_t GetMaxTextureSize() const {
82 auto lock = mData.Lock();
83 return lock.ref().mTextureFactoryIdentifier.mMaxTextureSize;
86 /**
87 * Returns the type of backend that is used off the main thread.
88 * We only don't allow changing the backend type at runtime so this value can
89 * be queried once and will not change until Gecko is restarted.
91 LayersBackend GetCompositorBackendType() const {
92 auto lock = mData.Lock();
93 return lock.ref().mTextureFactoryIdentifier.mParentBackend;
96 bool SupportsTextureBlitting() const {
97 auto lock = mData.Lock();
98 return lock.ref().mTextureFactoryIdentifier.mSupportsTextureBlitting;
101 bool SupportsPartialUploads() const {
102 auto lock = mData.Lock();
103 return lock.ref().mTextureFactoryIdentifier.mSupportsPartialUploads;
106 bool SupportsComponentAlpha() const {
107 auto lock = mData.Lock();
108 return lock.ref().mTextureFactoryIdentifier.mSupportsComponentAlpha;
111 bool SupportsTextureDirectMapping() const {
112 auto lock = mData.Lock();
113 return lock.ref().mTextureFactoryIdentifier.mSupportsTextureDirectMapping;
116 bool SupportsD3D11() const {
117 auto lock = mData.Lock();
118 return lock.ref().mTextureFactoryIdentifier.mParentBackend ==
119 layers::LayersBackend::LAYERS_D3D11 ||
120 (lock.ref().mTextureFactoryIdentifier.mParentBackend ==
121 layers::LayersBackend::LAYERS_WR &&
122 (lock.ref().mTextureFactoryIdentifier.mCompositorUseANGLE ||
123 lock.ref().mTextureFactoryIdentifier.mWebRenderCompositor ==
124 layers::WebRenderCompositor::D3D11));
127 bool GetCompositorUseANGLE() const {
128 auto lock = mData.Lock();
129 return lock.ref().mTextureFactoryIdentifier.mCompositorUseANGLE;
132 bool GetCompositorUseDComp() const {
133 auto lock = mData.Lock();
134 return lock.ref().mTextureFactoryIdentifier.mCompositorUseDComp;
137 bool GetUseCompositorWnd() const {
138 auto lock = mData.Lock();
139 return lock.ref().mTextureFactoryIdentifier.mUseCompositorWnd;
142 bool UsingSoftwareWebRender() const {
143 auto lock = mData.Lock();
144 return lock.ref().mTextureFactoryIdentifier.mParentBackend ==
145 layers::LayersBackend::LAYERS_WR &&
146 lock.ref().mTextureFactoryIdentifier.mWebRenderBackend ==
147 WebRenderBackend::SOFTWARE;
150 bool UsingSoftwareWebRenderD3D11() const {
151 auto lock = mData.Lock();
152 return lock.ref().mTextureFactoryIdentifier.mParentBackend ==
153 layers::LayersBackend::LAYERS_WR &&
154 lock.ref().mTextureFactoryIdentifier.mWebRenderBackend ==
155 WebRenderBackend::SOFTWARE &&
156 lock.ref().mTextureFactoryIdentifier.mWebRenderCompositor ==
157 layers::WebRenderCompositor::D3D11;
160 TextureFactoryIdentifier GetTextureFactoryIdentifier() const {
161 auto lock = mData.Lock();
162 return lock.ref().mTextureFactoryIdentifier;
165 bool DeviceCanReset() const {
166 return GetCompositorBackendType() != LayersBackend::LAYERS_BASIC;
169 int32_t GetSerial() const { return mSerial; }
172 * Sends a synchronous ping to the compsoitor.
174 * This is bad for performance and should only be called as a last resort if
175 * the compositor may be blocked for a long period of time, to avoid that the
176 * content process accumulates resource allocations that the compositor is not
177 * consuming and releasing.
179 virtual void SyncWithCompositor() { MOZ_ASSERT_UNREACHABLE("Unimplemented"); }
182 * Helpers for finding other related interface. These are infallible.
184 virtual TextureForwarder* GetTextureForwarder() = 0;
185 virtual LayersIPCActor* GetLayersIPCActor() = 0;
186 virtual ActiveResourceTracker* GetActiveResourceTracker() {
187 MOZ_ASSERT_UNREACHABLE("Unimplemented");
188 return nullptr;
191 protected:
192 struct SharedData {
193 TextureFactoryIdentifier mTextureFactoryIdentifier;
194 RefPtr<SyncObjectClient> mSyncObject;
196 mutable DataMutex<SharedData> mData;
198 const int32_t mSerial;
199 static mozilla::Atomic<int32_t> sSerialCounter;
202 /// Some implementations of KnowsCompositor can be used off their IPDL thread
203 /// like the ImageBridgeChild, and others just can't. Instead of passing them
204 /// we create a proxy KnowsCompositor that has information about compositor
205 /// backend but proxies allocations to the ImageBridge.
206 /// This is kind of specific to the needs of media which wants to allocate
207 /// textures, usually through the Image Bridge accessed by KnowsCompositor but
208 /// also wants access to the compositor backend information that ImageBridge
209 /// doesn't know about.
211 /// This is really a band aid to what turned into a class hierarchy horror show.
212 /// Hopefully we can come back and simplify this some way.
213 class KnowsCompositorMediaProxy : public KnowsCompositor {
214 public:
215 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(KnowsCompositorMediaProxy, override);
217 explicit KnowsCompositorMediaProxy(
218 const TextureFactoryIdentifier& aIdentifier);
220 TextureForwarder* GetTextureForwarder() override;
222 LayersIPCActor* GetLayersIPCActor() override;
224 ActiveResourceTracker* GetActiveResourceTracker() override;
226 void SyncWithCompositor() override;
228 protected:
229 virtual ~KnowsCompositorMediaProxy();
231 RefPtr<ImageBridgeChild> mThreadSafeAllocator;
234 } // namespace layers
235 } // namespace mozilla
237 #endif