/work/obj-fuzz/dist/include/mozilla/layers/TextureSourceProvider.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 | | #ifndef mozilla_gfx_layers_TextureSourceProvider_h |
7 | | #define mozilla_gfx_layers_TextureSourceProvider_h |
8 | | |
9 | | #include "nsISupportsImpl.h" |
10 | | #include "mozilla/AlreadyAddRefed.h" |
11 | | #include "mozilla/TimeStamp.h" |
12 | | #include "mozilla/layers/CompositorTypes.h" |
13 | | #include "nsTArray.h" |
14 | | |
15 | | struct ID3D11Device; |
16 | | |
17 | | namespace mozilla { |
18 | | namespace gfx { |
19 | | class DataSourceSurface; |
20 | | } // namespace gfx |
21 | | namespace gl { |
22 | | class GLContext; |
23 | | } // namespace gl |
24 | | namespace layers { |
25 | | |
26 | | class TextureHost; |
27 | | class DataTextureSource; |
28 | | class Compositor; |
29 | | |
30 | | // Provided by a HostLayerManager or Compositor for allocating backend-specific |
31 | | // texture types. |
32 | | class TextureSourceProvider |
33 | | { |
34 | | public: |
35 | | NS_INLINE_DECL_REFCOUNTING(TextureSourceProvider) |
36 | | |
37 | | virtual already_AddRefed<DataTextureSource> |
38 | | CreateDataTextureSource(TextureFlags aFlags = TextureFlags::NO_FLAGS) = 0; |
39 | | |
40 | | virtual already_AddRefed<DataTextureSource> |
41 | 0 | CreateDataTextureSourceAround(gfx::DataSourceSurface* aSurface) { |
42 | 0 | return nullptr; |
43 | 0 | } |
44 | | |
45 | | virtual already_AddRefed<DataTextureSource> |
46 | 0 | CreateDataTextureSourceAroundYCbCr(TextureHost* aTexture) { |
47 | 0 | return nullptr; |
48 | 0 | } |
49 | | |
50 | | virtual TimeStamp GetLastCompositionEndTime() const = 0; |
51 | | |
52 | | // Return true if the effect type is supported. |
53 | | // |
54 | | // By default Compositor implementations should support all effects but in |
55 | | // some rare cases it is not possible to support an effect efficiently. |
56 | | // This is the case for BasicCompositor with EffectYCbCr. |
57 | 0 | virtual bool SupportsEffect(EffectTypes aEffect) { return true; } |
58 | | |
59 | | /// Most compositor backends operate asynchronously under the hood. This |
60 | | /// means that when a layer stops using a texture it is often desirable to |
61 | | /// wait for the end of the next composition before releasing the texture's |
62 | | /// ReadLock. |
63 | | /// This function provides a convenient way to do this delayed unlocking, if |
64 | | /// the texture itself requires it. |
65 | | virtual void UnlockAfterComposition(TextureHost* aTexture); |
66 | | |
67 | | /// This is used for client storage support on OSX. On Nvidia hardware, it |
68 | | /// seems that if we glDeleteTextures on a texture too early, even if we've |
69 | | /// waited on the texture with glFinishObjectAPPLE, we'll see visual defects. |
70 | | /// This just holds a reference to the texture until ReadUnlockTextures, |
71 | | /// but we don't need to unlock it since we have already done so. |
72 | | void ReferenceUntilAfterComposition(DataTextureSource* aTextureSource); |
73 | | |
74 | | /// Most compositor backends operate asynchronously under the hood. This |
75 | | /// means that when a layer stops using a texture it is often desirable to |
76 | | /// wait for the end of the next composition before NotifyNotUsed() call. |
77 | | /// This function provides a convenient way to do this delayed NotifyNotUsed() |
78 | | /// call, if the texture itself requires it. |
79 | | /// See bug 1260611 and bug 1252835 |
80 | | /// |
81 | | /// Returns true if notified, false otherwise. |
82 | | virtual bool NotifyNotUsedAfterComposition(TextureHost* aTextureHost); |
83 | | |
84 | 0 | virtual void MaybeUnlockBeforeNextComposition(TextureHost* aTextureHost) {} |
85 | 0 | virtual void TryUnlockTextures() {} |
86 | | |
87 | | // If overridden, make sure to call the base function. |
88 | | virtual void Destroy(); |
89 | | |
90 | | void FlushPendingNotifyNotUsed(); |
91 | | |
92 | | // If this provider is also a Compositor, return the compositor. Otherwise return |
93 | | // null. |
94 | 0 | virtual Compositor* AsCompositor() { |
95 | 0 | return nullptr; |
96 | 0 | } |
97 | | |
98 | | #ifdef XP_WIN |
99 | | // On Windows, if this provides Direct3D textures, it must expose the device. |
100 | | virtual ID3D11Device* GetD3D11Device() const { |
101 | | return nullptr; |
102 | | } |
103 | | #endif |
104 | | |
105 | | // If this provides OpenGL textures, it must expose the GLContext. |
106 | 0 | virtual gl::GLContext* GetGLContext() const { |
107 | 0 | return nullptr; |
108 | 0 | } |
109 | | |
110 | | virtual int32_t GetMaxTextureSize() const = 0; |
111 | | |
112 | | // Return whether or not this provider is still valid (i.e., is still being |
113 | | // used to composite). |
114 | | virtual bool IsValid() const = 0; |
115 | | |
116 | | public: |
117 | | class MOZ_STACK_CLASS AutoReadUnlockTextures |
118 | | { |
119 | | public: |
120 | | explicit AutoReadUnlockTextures(TextureSourceProvider* aProvider) |
121 | | : mProvider(aProvider) |
122 | 0 | {} |
123 | 0 | ~AutoReadUnlockTextures() { |
124 | 0 | mProvider->ReadUnlockTextures(); |
125 | 0 | } |
126 | | |
127 | | private: |
128 | | RefPtr<TextureSourceProvider> mProvider; |
129 | | }; |
130 | | |
131 | | protected: |
132 | | // Should be called at the end of each composition. |
133 | | void ReadUnlockTextures(); |
134 | | |
135 | | virtual ~TextureSourceProvider(); |
136 | | |
137 | | private: |
138 | | // An array of locks that will need to be unlocked after the next composition. |
139 | | nsTArray<RefPtr<TextureHost>> mUnlockAfterComposition; |
140 | | |
141 | | // See ReferenceUntilAfterComposition. |
142 | | nsTArray<RefPtr<DataTextureSource>> mReferenceUntilAfterComposition; |
143 | | |
144 | | // An array of TextureHosts that will need to call NotifyNotUsed() after the next composition. |
145 | | nsTArray<RefPtr<TextureHost>> mNotifyNotUsedAfterComposition; |
146 | | }; |
147 | | |
148 | | } // namespace layers |
149 | | } // namespace mozilla |
150 | | |
151 | | #endif // mozilla_gfx_layers_TextureSourceProvider_h |