gfx/layers/d3d11/CompositorD3D11.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial