Source code

Revision control

Other Tools

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 BasicCompositor;
29
class Compositor;
30
class CompositorOGL;
31
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)
37
38
virtual already_AddRefed<DataTextureSource> CreateDataTextureSource(
39
TextureFlags aFlags = TextureFlags::NO_FLAGS) = 0;
40
41
virtual already_AddRefed<DataTextureSource> CreateDataTextureSourceAround(
42
gfx::DataSourceSurface* aSurface) {
43
return nullptr;
44
}
45
46
virtual already_AddRefed<DataTextureSource>
47
CreateDataTextureSourceAroundYCbCr(TextureHost* aTexture) {
48
return nullptr;
49
}
50
51
virtual TimeStamp GetLastCompositionEndTime() const = 0;
52
53
// Return true if the effect type is supported.
54
//
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; }
59
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);
67
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);
77
78
virtual void MaybeUnlockBeforeNextComposition(TextureHost* aTextureHost) {}
79
virtual void TryUnlockTextures() {}
80
81
// If overridden, make sure to call the base function.
82
virtual void Destroy();
83
84
void FlushPendingNotifyNotUsed();
85
86
// If this provider is also a Compositor, return the compositor. Otherwise
87
// return null.
88
virtual Compositor* AsCompositor() { return nullptr; }
89
90
// If this provider is also a BasicCompositor, return the compositor.
91
// Otherwise return nullptr.
92
virtual BasicCompositor* AsBasicCompositor() { return nullptr; }
93
94
// If this provider is also a CompositorOGL, return the compositor. Otherwise
95
// return nullptr.
96
virtual CompositorOGL* AsCompositorOGL() { return nullptr; }
97
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
102
103
// If this provides OpenGL textures, it must expose the GLContext.
104
virtual gl::GLContext* GetGLContext() const { return nullptr; }
105
106
virtual int32_t GetMaxTextureSize() const = 0;
107
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;
111
112
public:
113
class MOZ_STACK_CLASS AutoReadUnlockTextures final {
114
public:
115
explicit AutoReadUnlockTextures(TextureSourceProvider* aProvider)
116
: mProvider(aProvider) {}
117
~AutoReadUnlockTextures() { mProvider->ReadUnlockTextures(); }
118
119
private:
120
RefPtr<TextureSourceProvider> mProvider;
121
};
122
123
protected:
124
// Should be called at the end of each composition.
125
void ReadUnlockTextures();
126
127
virtual ~TextureSourceProvider();
128
129
private:
130
// An array of locks that will need to be unlocked after the next composition.
131
nsTArray<RefPtr<TextureHost>> mUnlockAfterComposition;
132
133
// An array of TextureHosts that will need to call NotifyNotUsed() after the
134
// next composition.
135
nsTArray<RefPtr<TextureHost>> mNotifyNotUsedAfterComposition;
136
};
137
138
} // namespace layers
139
} // namespace mozilla
140
141
#endif // mozilla_gfx_layers_TextureSourceProvider_h