Line data Source code
1 : /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 : * This Source Code Form is subject to the terms of the Mozilla Public
3 : * License, v. 2.0. If a copy of the MPL was not distributed with this
4 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 : #ifndef mozilla_gfx_layers_TextureSourceProvider_h
6 : #define mozilla_gfx_layers_TextureSourceProvider_h
7 :
8 : #include "nsISupportsImpl.h"
9 : #include "mozilla/AlreadyAddRefed.h"
10 : #include "mozilla/TimeStamp.h"
11 : #include "mozilla/layers/CompositorTypes.h"
12 : #include "nsTArray.h"
13 :
14 : struct ID3D11Device;
15 :
16 : namespace mozilla {
17 : namespace gfx {
18 : class DataSourceSurface;
19 : } // namespace gfx
20 : namespace gl {
21 : class GLContext;
22 : } // namespace gl
23 : namespace layers {
24 :
25 : class TextureHost;
26 : class DataTextureSource;
27 : class Compositor;
28 :
29 : // Provided by a HostLayerManager or Compositor for allocating backend-specific
30 : // texture types.
31 1 : class TextureSourceProvider
32 : {
33 : public:
34 112 : NS_INLINE_DECL_REFCOUNTING(TextureSourceProvider)
35 :
36 : virtual already_AddRefed<DataTextureSource>
37 : CreateDataTextureSource(TextureFlags aFlags = TextureFlags::NO_FLAGS) = 0;
38 :
39 : virtual already_AddRefed<DataTextureSource>
40 0 : CreateDataTextureSourceAround(gfx::DataSourceSurface* aSurface) {
41 0 : return nullptr;
42 : }
43 :
44 : virtual already_AddRefed<DataTextureSource>
45 0 : CreateDataTextureSourceAroundYCbCr(TextureHost* aTexture) {
46 0 : return nullptr;
47 : }
48 :
49 : virtual TimeStamp GetLastCompositionEndTime() const = 0;
50 :
51 : // Return true if the effect type is supported.
52 : //
53 : // By default Compositor implementations should support all effects but in
54 : // some rare cases it is not possible to support an effect efficiently.
55 : // This is the case for BasicCompositor with EffectYCbCr.
56 0 : virtual bool SupportsEffect(EffectTypes aEffect) { return true; }
57 :
58 : /// Most compositor backends operate asynchronously under the hood. This
59 : /// means that when a layer stops using a texture it is often desirable to
60 : /// wait for the end of the next composition before releasing the texture's
61 : /// ReadLock.
62 : /// This function provides a convenient way to do this delayed unlocking, if
63 : /// the texture itself requires it.
64 : void UnlockAfterComposition(TextureHost* aTexture);
65 :
66 : /// Most compositor backends operate asynchronously under the hood. This
67 : /// means that when a layer stops using a texture it is often desirable to
68 : /// wait for the end of the next composition before NotifyNotUsed() call.
69 : /// This function provides a convenient way to do this delayed NotifyNotUsed()
70 : /// call, if the texture itself requires it.
71 : /// See bug 1260611 and bug 1252835
72 : ///
73 : /// Returns true if notified, false otherwise.
74 : virtual bool NotifyNotUsedAfterComposition(TextureHost* aTextureHost);
75 :
76 : // If overridden, make sure to call the base function.
77 : virtual void Destroy();
78 :
79 : void FlushPendingNotifyNotUsed();
80 :
81 : // If this provider is also a Compositor, return the compositor. Otherwise return
82 : // null.
83 0 : virtual Compositor* AsCompositor() {
84 0 : return nullptr;
85 : }
86 :
87 : #ifdef XP_WIN
88 : // On Windows, if this provides Direct3D textures, it must expose the device.
89 : virtual ID3D11Device* GetD3D11Device() const {
90 : return nullptr;
91 : }
92 : #endif
93 :
94 : // If this provides OpenGL textures, it must expose the GLContext.
95 0 : virtual gl::GLContext* GetGLContext() const {
96 0 : return nullptr;
97 : }
98 :
99 : virtual int32_t GetMaxTextureSize() const = 0;
100 :
101 : // Return whether or not this provider is still valid (i.e., is still being
102 : // used to composite).
103 : virtual bool IsValid() const = 0;
104 :
105 : public:
106 : class MOZ_STACK_CLASS AutoReadUnlockTextures
107 : {
108 : public:
109 0 : explicit AutoReadUnlockTextures(TextureSourceProvider* aProvider)
110 0 : : mProvider(aProvider)
111 0 : {}
112 0 : ~AutoReadUnlockTextures() {
113 0 : mProvider->ReadUnlockTextures();
114 0 : }
115 :
116 : private:
117 : RefPtr<TextureSourceProvider> mProvider;
118 : };
119 :
120 : protected:
121 : // Should be called at the end of each composition.
122 : void ReadUnlockTextures();
123 :
124 : virtual ~TextureSourceProvider();
125 :
126 : private:
127 : // An array of locks that will need to be unlocked after the next composition.
128 : nsTArray<RefPtr<TextureHost>> mUnlockAfterComposition;
129 :
130 : // An array of TextureHosts that will need to call NotifyNotUsed() after the next composition.
131 : nsTArray<RefPtr<TextureHost>> mNotifyNotUsedAfterComposition;
132 : };
133 :
134 : } // namespace layers
135 : } // namespace mozilla
136 :
137 : #endif // mozilla_gfx_layers_TextureSourceProvider_h
|