gfx/layers/d3d11/TextureD3D11.h

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:c48df96de137
1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
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
6 #ifndef MOZILLA_GFX_TEXTURED3D11_H
7 #define MOZILLA_GFX_TEXTURED3D11_H
8
9 #include "mozilla/layers/Compositor.h"
10 #include "mozilla/layers/TextureClient.h"
11 #include "mozilla/layers/TextureHost.h"
12 #include "gfxWindowsPlatform.h"
13 #include "mozilla/GfxMessageUtils.h"
14 #include <d3d11.h>
15 #include <vector>
16
17 class gfxD2DSurface;
18
19 namespace mozilla {
20 namespace layers {
21
22 class CompositorD3D11;
23
24 /**
25 * A TextureClient to share a D3D10 texture with the compositor thread.
26 * The corresponding TextureHost is DXGITextureHostD3D11
27 */
28 class TextureClientD3D11 : public TextureClient
29 {
30 public:
31 TextureClientD3D11(gfx::SurfaceFormat aFormat, TextureFlags aFlags);
32
33 virtual ~TextureClientD3D11();
34
35 // TextureClient
36
37 virtual bool IsAllocated() const MOZ_OVERRIDE { return !!mTexture; }
38
39 virtual bool Lock(OpenMode aOpenMode) MOZ_OVERRIDE;
40
41 virtual void Unlock() MOZ_OVERRIDE;
42
43 virtual bool IsLocked() const MOZ_OVERRIDE { return mIsLocked; }
44
45 virtual bool ImplementsLocking() const MOZ_OVERRIDE { return true; }
46
47 virtual bool HasInternalBuffer() const MOZ_OVERRIDE { return false; }
48
49 virtual bool ToSurfaceDescriptor(SurfaceDescriptor& aOutDescriptor) MOZ_OVERRIDE;
50
51 virtual gfx::IntSize GetSize() const MOZ_OVERRIDE { return mSize; }
52
53 virtual TextureClientData* DropTextureData() MOZ_OVERRIDE { return nullptr; }
54
55 virtual gfx::SurfaceFormat GetFormat() const MOZ_OVERRIDE { return mFormat; }
56
57 virtual bool CanExposeDrawTarget() const MOZ_OVERRIDE { return true; }
58
59 virtual TemporaryRef<gfx::DrawTarget> GetAsDrawTarget() MOZ_OVERRIDE;
60
61 virtual bool AllocateForSurface(gfx::IntSize aSize,
62 TextureAllocationFlags aFlags = ALLOC_DEFAULT) MOZ_OVERRIDE;
63
64 protected:
65 gfx::IntSize mSize;
66 RefPtr<ID3D10Texture2D> mTexture;
67 RefPtr<gfx::DrawTarget> mDrawTarget;
68 gfx::SurfaceFormat mFormat;
69 bool mIsLocked;
70 bool mNeedsClear;
71 };
72
73 /**
74 * TextureSource that provides with the necessary APIs to be composited by a
75 * CompositorD3D11.
76 */
77 class TextureSourceD3D11
78 {
79 public:
80 TextureSourceD3D11() {}
81 virtual ~TextureSourceD3D11() {}
82
83 virtual ID3D11Texture2D* GetD3D11Texture() const { return mTexture; }
84
85 protected:
86 virtual gfx::IntSize GetSize() const { return mSize; }
87
88 gfx::IntSize mSize;
89 RefPtr<ID3D11Texture2D> mTexture;
90 };
91
92 /**
93 * A TextureSource that implements the DataTextureSource interface.
94 * it can be used without a TextureHost and is able to upload texture data
95 * from a gfx::DataSourceSurface.
96 */
97 class DataTextureSourceD3D11 : public DataTextureSource
98 , public TextureSourceD3D11
99 , public TileIterator
100 {
101 public:
102 DataTextureSourceD3D11(gfx::SurfaceFormat aFormat, CompositorD3D11* aCompositor,
103 TextureFlags aFlags);
104
105 DataTextureSourceD3D11(gfx::SurfaceFormat aFormat, CompositorD3D11* aCompositor,
106 ID3D11Texture2D* aTexture);
107
108 virtual ~DataTextureSourceD3D11();
109
110
111 // DataTextureSource
112
113 virtual bool Update(gfx::DataSourceSurface* aSurface,
114 nsIntRegion* aDestRegion = nullptr,
115 gfx::IntPoint* aSrcOffset = nullptr) MOZ_OVERRIDE;
116
117 // TextureSource
118
119 virtual TextureSourceD3D11* AsSourceD3D11() MOZ_OVERRIDE { return this; }
120
121 virtual ID3D11Texture2D* GetD3D11Texture() const MOZ_OVERRIDE;
122
123 virtual DataTextureSource* AsDataTextureSource() MOZ_OVERRIDE { return this; }
124
125 virtual void DeallocateDeviceData() MOZ_OVERRIDE { mTexture = nullptr; }
126
127 virtual gfx::IntSize GetSize() const MOZ_OVERRIDE { return mSize; }
128
129 virtual gfx::SurfaceFormat GetFormat() const MOZ_OVERRIDE { return mFormat; }
130
131 virtual void SetCompositor(Compositor* aCompositor) MOZ_OVERRIDE;
132
133 // TileIterator
134
135 virtual TileIterator* AsTileIterator() MOZ_OVERRIDE { return mIsTiled ? this : nullptr; }
136
137 virtual size_t GetTileCount() MOZ_OVERRIDE { return mTileTextures.size(); }
138
139 virtual bool NextTile() MOZ_OVERRIDE { return (++mCurrentTile < mTileTextures.size()); }
140
141 virtual nsIntRect GetTileRect() MOZ_OVERRIDE;
142
143 virtual void EndTileIteration() MOZ_OVERRIDE { mIterating = false; }
144
145 virtual void BeginTileIteration() MOZ_OVERRIDE
146 {
147 mIterating = true;
148 mCurrentTile = 0;
149 }
150
151 protected:
152 gfx::IntRect GetTileRect(uint32_t aIndex) const;
153
154 void Reset();
155
156 std::vector< RefPtr<ID3D11Texture2D> > mTileTextures;
157 RefPtr<CompositorD3D11> mCompositor;
158 gfx::SurfaceFormat mFormat;
159 TextureFlags mFlags;
160 uint32_t mCurrentTile;
161 bool mIsTiled;
162 bool mIterating;
163
164 };
165
166 /**
167 * A TextureHost for shared D3D11 textures.
168 */
169 class DXGITextureHostD3D11 : public TextureHost
170 {
171 public:
172 DXGITextureHostD3D11(TextureFlags aFlags,
173 const SurfaceDescriptorD3D10& aDescriptor);
174
175 virtual NewTextureSource* GetTextureSources() MOZ_OVERRIDE;
176
177 virtual void DeallocateDeviceData() MOZ_OVERRIDE {}
178
179 virtual void SetCompositor(Compositor* aCompositor) MOZ_OVERRIDE;
180
181 virtual gfx::SurfaceFormat GetFormat() const MOZ_OVERRIDE { return mFormat; }
182
183 virtual bool Lock() MOZ_OVERRIDE;
184
185 virtual void Unlock() MOZ_OVERRIDE;
186
187 virtual gfx::IntSize GetSize() const MOZ_OVERRIDE { return mSize; }
188
189 virtual TemporaryRef<gfx::DataSourceSurface> GetAsSurface() MOZ_OVERRIDE
190 {
191 return nullptr;
192 }
193
194 protected:
195 ID3D11Device* GetDevice();
196
197 RefPtr<DataTextureSourceD3D11> mTextureSource;
198 RefPtr<CompositorD3D11> mCompositor;
199 gfx::IntSize mSize;
200 WindowsHandle mHandle;
201 gfx::SurfaceFormat mFormat;
202 bool mIsLocked;
203 };
204
205 class CompositingRenderTargetD3D11 : public CompositingRenderTarget,
206 public TextureSourceD3D11
207 {
208 public:
209 CompositingRenderTargetD3D11(ID3D11Texture2D* aTexture,
210 const gfx::IntPoint& aOrigin);
211
212 virtual TextureSourceD3D11* AsSourceD3D11() MOZ_OVERRIDE { return this; }
213
214 virtual gfx::IntSize GetSize() const MOZ_OVERRIDE;
215
216 void SetSize(const gfx::IntSize& aSize) { mSize = aSize; }
217
218 private:
219 friend class CompositorD3D11;
220
221 RefPtr<ID3D11RenderTargetView> mRTView;
222 };
223
224 inline uint32_t GetMaxTextureSizeForFeatureLevel(D3D_FEATURE_LEVEL aFeatureLevel)
225 {
226 int32_t maxTextureSize;
227 switch (aFeatureLevel) {
228 case D3D_FEATURE_LEVEL_11_1:
229 case D3D_FEATURE_LEVEL_11_0:
230 maxTextureSize = D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION;
231 break;
232 case D3D_FEATURE_LEVEL_10_1:
233 case D3D_FEATURE_LEVEL_10_0:
234 maxTextureSize = D3D10_REQ_TEXTURE2D_U_OR_V_DIMENSION;
235 break;
236 case D3D_FEATURE_LEVEL_9_3:
237 maxTextureSize = D3D_FL9_3_REQ_TEXTURE2D_U_OR_V_DIMENSION;
238 break;
239 default:
240 maxTextureSize = D3D_FL9_1_REQ_TEXTURE2D_U_OR_V_DIMENSION;
241 }
242 return maxTextureSize;
243 }
244
245 }
246 }
247
248 #endif /* MOZILLA_GFX_TEXTURED3D11_H */

mercurial