Bug 1632310 [wpt PR 23186] - Add test for computed versus resolved style., a=testonly
[gecko.git] / gfx / layers / TextureSourceProvider.h
blobaeaace8514c7d722baffadb9e1fc296bffd40482
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 #ifndef mozilla_gfx_layers_TextureSourceProvider_h
7 #define mozilla_gfx_layers_TextureSourceProvider_h
9 #include "nsISupportsImpl.h"
10 #include "mozilla/AlreadyAddRefed.h"
11 #include "mozilla/TimeStamp.h"
12 #include "mozilla/layers/CompositorTypes.h"
13 #include "nsTArray.h"
15 struct ID3D11Device;
17 namespace mozilla {
18 namespace gfx {
19 class DataSourceSurface;
20 } // namespace gfx
21 namespace gl {
22 class GLContext;
23 } // namespace gl
24 namespace layers {
26 class TextureHost;
27 class DataTextureSource;
28 class BasicCompositor;
29 class Compositor;
30 class CompositorOGL;
32 // Provided by a HostLayerManager or Compositor for allocating backend-specific
33 // texture types.
34 class TextureSourceProvider {
35 public:
36 NS_INLINE_DECL_REFCOUNTING(TextureSourceProvider)
38 virtual already_AddRefed<DataTextureSource> CreateDataTextureSource(
39 TextureFlags aFlags = TextureFlags::NO_FLAGS) = 0;
41 virtual already_AddRefed<DataTextureSource> CreateDataTextureSourceAround(
42 gfx::DataSourceSurface* aSurface) {
43 return nullptr;
46 virtual already_AddRefed<DataTextureSource>
47 CreateDataTextureSourceAroundYCbCr(TextureHost* aTexture) {
48 return nullptr;
51 virtual TimeStamp GetLastCompositionEndTime() const = 0;
53 // Return true if the effect type is supported.
55 // By default Compositor implementations should support all effects but in
56 // some rare cases it is not possible to support an effect efficiently.
57 // This is the case for BasicCompositor with EffectYCbCr.
58 virtual bool SupportsEffect(EffectTypes aEffect) { return true; }
60 /// Most compositor backends operate asynchronously under the hood. This
61 /// means that when a layer stops using a texture it is often desirable to
62 /// wait for the end of the next composition before releasing the texture's
63 /// ReadLock.
64 /// This function provides a convenient way to do this delayed unlocking, if
65 /// the texture itself requires it.
66 virtual void UnlockAfterComposition(TextureHost* aTexture);
68 /// Most compositor backends operate asynchronously under the hood. This
69 /// means that when a layer stops using a texture it is often desirable to
70 /// wait for the end of the next composition before NotifyNotUsed() call.
71 /// This function provides a convenient way to do this delayed NotifyNotUsed()
72 /// call, if the texture itself requires it.
73 /// See bug 1260611 and bug 1252835
74 ///
75 /// Returns true if notified, false otherwise.
76 virtual bool NotifyNotUsedAfterComposition(TextureHost* aTextureHost);
78 virtual void MaybeUnlockBeforeNextComposition(TextureHost* aTextureHost) {}
79 virtual void TryUnlockTextures() {}
81 // If overridden, make sure to call the base function.
82 virtual void Destroy();
84 void FlushPendingNotifyNotUsed();
86 // If this provider is also a Compositor, return the compositor. Otherwise
87 // return null.
88 virtual Compositor* AsCompositor() { return nullptr; }
90 // If this provider is also a BasicCompositor, return the compositor.
91 // Otherwise return nullptr.
92 virtual BasicCompositor* AsBasicCompositor() { return nullptr; }
94 // If this provider is also a CompositorOGL, return the compositor. Otherwise
95 // return nullptr.
96 virtual CompositorOGL* AsCompositorOGL() { return nullptr; }
98 #ifdef XP_WIN
99 // On Windows, if this provides Direct3D textures, it must expose the device.
100 virtual ID3D11Device* GetD3D11Device() const { return nullptr; }
101 #endif
103 // If this provides OpenGL textures, it must expose the GLContext.
104 virtual gl::GLContext* GetGLContext() const { return nullptr; }
106 virtual int32_t GetMaxTextureSize() const = 0;
108 // Return whether or not this provider is still valid (i.e., is still being
109 // used to composite).
110 virtual bool IsValid() const = 0;
112 public:
113 class MOZ_STACK_CLASS AutoReadUnlockTextures final {
114 public:
115 explicit AutoReadUnlockTextures(TextureSourceProvider* aProvider)
116 : mProvider(aProvider) {}
117 ~AutoReadUnlockTextures() { mProvider->ReadUnlockTextures(); }
119 private:
120 RefPtr<TextureSourceProvider> mProvider;
123 protected:
124 // Should be called at the end of each composition.
125 void ReadUnlockTextures();
127 virtual ~TextureSourceProvider();
129 private:
130 // An array of locks that will need to be unlocked after the next composition.
131 nsTArray<RefPtr<TextureHost>> mUnlockAfterComposition;
133 // An array of TextureHosts that will need to call NotifyNotUsed() after the
134 // next composition.
135 nsTArray<RefPtr<TextureHost>> mNotifyNotUsedAfterComposition;
138 } // namespace layers
139 } // namespace mozilla
141 #endif // mozilla_gfx_layers_TextureSourceProvider_h