|
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 |
|
6 #ifndef MOZILLA_GFX_COMPOSITORD3D11_H |
|
7 #define MOZILLA_GFX_COMPOSITORD3D11_H |
|
8 |
|
9 #include "mozilla/gfx/2D.h" |
|
10 #include "gfx2DGlue.h" |
|
11 #include "mozilla/layers/Compositor.h" |
|
12 #include "TextureD3D11.h" |
|
13 #include <d3d11.h> |
|
14 |
|
15 class nsWidget; |
|
16 |
|
17 namespace mozilla { |
|
18 namespace layers { |
|
19 |
|
20 #define LOGD3D11(param) |
|
21 |
|
22 struct VertexShaderConstants |
|
23 { |
|
24 float layerTransform[4][4]; |
|
25 float projection[4][4]; |
|
26 float renderTargetOffset[4]; |
|
27 gfx::Rect textureCoords; |
|
28 gfx::Rect layerQuad; |
|
29 gfx::Rect maskQuad; |
|
30 }; |
|
31 |
|
32 struct PixelShaderConstants |
|
33 { |
|
34 float layerColor[4]; |
|
35 float layerOpacity[4]; |
|
36 }; |
|
37 |
|
38 struct DeviceAttachmentsD3D11; |
|
39 |
|
40 class CompositorD3D11 : public Compositor |
|
41 { |
|
42 public: |
|
43 CompositorD3D11(nsIWidget* aWidget); |
|
44 ~CompositorD3D11(); |
|
45 |
|
46 virtual bool Initialize() MOZ_OVERRIDE; |
|
47 virtual void Destroy() MOZ_OVERRIDE {} |
|
48 |
|
49 virtual TextureFactoryIdentifier |
|
50 GetTextureFactoryIdentifier() MOZ_OVERRIDE; |
|
51 |
|
52 virtual TemporaryRef<DataTextureSource> |
|
53 CreateDataTextureSource(TextureFlags aFlags = 0) MOZ_OVERRIDE; |
|
54 |
|
55 virtual bool CanUseCanvasLayerForSize(const gfx::IntSize& aSize) MOZ_OVERRIDE; |
|
56 virtual int32_t GetMaxTextureSize() const MOZ_FINAL; |
|
57 |
|
58 virtual void SetTargetContext(gfx::DrawTarget* aTarget) MOZ_OVERRIDE |
|
59 { |
|
60 mTarget = aTarget; |
|
61 } |
|
62 |
|
63 virtual void MakeCurrent(MakeCurrentFlags aFlags = 0) MOZ_OVERRIDE {} |
|
64 |
|
65 virtual TemporaryRef<CompositingRenderTarget> |
|
66 CreateRenderTarget(const gfx::IntRect &aRect, |
|
67 SurfaceInitMode aInit) MOZ_OVERRIDE; |
|
68 |
|
69 virtual TemporaryRef<CompositingRenderTarget> |
|
70 CreateRenderTargetFromSource(const gfx::IntRect& aRect, |
|
71 const CompositingRenderTarget* aSource, |
|
72 const gfx::IntPoint& aSourcePoint) MOZ_OVERRIDE; |
|
73 |
|
74 virtual void SetRenderTarget(CompositingRenderTarget* aSurface) MOZ_OVERRIDE; |
|
75 virtual CompositingRenderTarget* GetCurrentRenderTarget() const MOZ_OVERRIDE |
|
76 { |
|
77 return mCurrentRT; |
|
78 } |
|
79 |
|
80 virtual void SetDestinationSurfaceSize(const gfx::IntSize& aSize) MOZ_OVERRIDE {} |
|
81 |
|
82 /** |
|
83 * Declare an offset to use when rendering layers. This will be ignored when |
|
84 * rendering to a target instead of the screen. |
|
85 */ |
|
86 virtual void SetScreenRenderOffset(const ScreenPoint& aOffset) MOZ_OVERRIDE |
|
87 { |
|
88 if (aOffset.x || aOffset.y) { |
|
89 NS_RUNTIMEABORT("SetScreenRenderOffset not supported by CompositorD3D11."); |
|
90 } |
|
91 // If the offset is 0, 0 that's okay. |
|
92 } |
|
93 |
|
94 virtual void ClearRect(const gfx::Rect& aRect) MOZ_OVERRIDE; |
|
95 |
|
96 virtual void DrawQuad(const gfx::Rect &aRect, |
|
97 const gfx::Rect &aClipRect, |
|
98 const EffectChain &aEffectChain, |
|
99 gfx::Float aOpacity, |
|
100 const gfx::Matrix4x4 &aTransform) MOZ_OVERRIDE; |
|
101 |
|
102 /** |
|
103 * Start a new frame. If aClipRectIn is null, sets *aClipRectOut to the |
|
104 * screen dimensions. |
|
105 */ |
|
106 virtual void BeginFrame(const nsIntRegion& aInvalidRegion, |
|
107 const gfx::Rect *aClipRectIn, |
|
108 const gfx::Matrix& aTransform, |
|
109 const gfx::Rect& aRenderBounds, |
|
110 gfx::Rect *aClipRectOut = nullptr, |
|
111 gfx::Rect *aRenderBoundsOut = nullptr) MOZ_OVERRIDE; |
|
112 |
|
113 /** |
|
114 * Flush the current frame to the screen. |
|
115 */ |
|
116 virtual void EndFrame() MOZ_OVERRIDE; |
|
117 |
|
118 /** |
|
119 * Post rendering stuff if the rendering is outside of this Compositor |
|
120 * e.g., by Composer2D |
|
121 */ |
|
122 virtual void EndFrameForExternalComposition(const gfx::Matrix& aTransform) MOZ_OVERRIDE {} |
|
123 |
|
124 /** |
|
125 * Tidy up if BeginFrame has been called, but EndFrame won't be |
|
126 */ |
|
127 virtual void AbortFrame() MOZ_OVERRIDE {} |
|
128 |
|
129 /** |
|
130 * Setup the viewport and projection matrix for rendering |
|
131 * to a window of the given dimensions. |
|
132 */ |
|
133 virtual void PrepareViewport(const gfx::IntSize& aSize, |
|
134 const gfx::Matrix& aWorldTransform) MOZ_OVERRIDE; |
|
135 |
|
136 virtual bool SupportsPartialTextureUpdate() MOZ_OVERRIDE { return true; } |
|
137 |
|
138 #ifdef MOZ_DUMP_PAINTING |
|
139 virtual const char* Name() const MOZ_OVERRIDE { return "Direct3D 11"; } |
|
140 #endif |
|
141 |
|
142 virtual LayersBackend GetBackendType() const MOZ_OVERRIDE { |
|
143 return LayersBackend::LAYERS_D3D11; |
|
144 } |
|
145 |
|
146 virtual nsIWidget* GetWidget() const MOZ_OVERRIDE { return mWidget; } |
|
147 |
|
148 ID3D11Device* GetDevice() { return mDevice; } |
|
149 |
|
150 private: |
|
151 // ensure mSize is up to date with respect to mWidget |
|
152 void EnsureSize(); |
|
153 void VerifyBufferSize(); |
|
154 void UpdateRenderTarget(); |
|
155 bool CreateShaders(); |
|
156 void UpdateConstantBuffers(); |
|
157 void SetSamplerForFilter(gfx::Filter aFilter); |
|
158 void SetPSForEffect(Effect *aEffect, MaskType aMaskType, gfx::SurfaceFormat aFormat); |
|
159 void PaintToTarget(); |
|
160 |
|
161 virtual gfx::IntSize GetWidgetSize() const MOZ_OVERRIDE { return gfx::ToIntSize(mSize); } |
|
162 |
|
163 RefPtr<ID3D11DeviceContext> mContext; |
|
164 RefPtr<ID3D11Device> mDevice; |
|
165 RefPtr<IDXGISwapChain> mSwapChain; |
|
166 RefPtr<CompositingRenderTargetD3D11> mDefaultRT; |
|
167 RefPtr<CompositingRenderTargetD3D11> mCurrentRT; |
|
168 |
|
169 DeviceAttachmentsD3D11* mAttachments; |
|
170 |
|
171 RefPtr<gfx::DrawTarget> mTarget; |
|
172 |
|
173 nsIWidget* mWidget; |
|
174 |
|
175 nsIntSize mSize; |
|
176 |
|
177 HWND mHwnd; |
|
178 |
|
179 D3D_FEATURE_LEVEL mFeatureLevel; |
|
180 |
|
181 VertexShaderConstants mVSConstants; |
|
182 PixelShaderConstants mPSConstants; |
|
183 bool mDisableSequenceForNextFrame; |
|
184 }; |
|
185 |
|
186 } |
|
187 } |
|
188 |
|
189 #endif |