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"
19 class DataSourceSurface
;
27 class DataTextureSource
;
28 class BasicCompositor
;
32 // Provided by a HostLayerManager or Compositor for allocating backend-specific
34 class TextureSourceProvider
{
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
) {
46 virtual already_AddRefed
<DataTextureSource
>
47 CreateDataTextureSourceAroundYCbCr(TextureHost
* aTexture
) {
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
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
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
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
96 virtual CompositorOGL
* AsCompositorOGL() { return nullptr; }
99 // On Windows, if this provides Direct3D textures, it must expose the device.
100 virtual ID3D11Device
* GetD3D11Device() const { return nullptr; }
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;
113 class MOZ_STACK_CLASS AutoReadUnlockTextures final
{
115 explicit AutoReadUnlockTextures(TextureSourceProvider
* aProvider
)
116 : mProvider(aProvider
) {}
117 ~AutoReadUnlockTextures() { mProvider
->ReadUnlockTextures(); }
120 RefPtr
<TextureSourceProvider
> mProvider
;
124 // Should be called at the end of each composition.
125 void ReadUnlockTextures();
127 virtual ~TextureSourceProvider();
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
135 nsTArray
<RefPtr
<TextureHost
>> mNotifyNotUsedAfterComposition
;
138 } // namespace layers
139 } // namespace mozilla
141 #endif // mozilla_gfx_layers_TextureSourceProvider_h