2017-10-27 23:10:06 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
2013-05-03 17:34:29 +00:00
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef MOZILLA_GFX_COMPOSITORD3D11_H
|
|
|
|
#define MOZILLA_GFX_COMPOSITORD3D11_H
|
|
|
|
|
2013-09-27 00:37:19 +00:00
|
|
|
#include "mozilla/gfx/2D.h"
|
2014-04-25 12:00:52 +00:00
|
|
|
#include "gfx2DGlue.h"
|
2013-05-03 17:34:29 +00:00
|
|
|
#include "mozilla/layers/Compositor.h"
|
|
|
|
#include "TextureD3D11.h"
|
|
|
|
#include <d3d11.h>
|
2017-03-30 18:47:13 +00:00
|
|
|
#include <dxgi1_2.h>
|
2017-04-30 18:38:58 +00:00
|
|
|
#include "ShaderDefinitionsD3D11.h"
|
2013-05-03 17:34:29 +00:00
|
|
|
|
|
|
|
class nsWidget;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace layers {
|
|
|
|
|
|
|
|
#define LOGD3D11(param)
|
|
|
|
|
2017-04-30 18:38:59 +00:00
|
|
|
class DeviceAttachmentsD3D11;
|
2017-04-11 02:44:46 +00:00
|
|
|
class DiagnosticsD3D11;
|
2013-05-03 17:34:29 +00:00
|
|
|
|
|
|
|
class CompositorD3D11 : public Compositor {
|
|
|
|
public:
|
2016-07-01 08:15:16 +00:00
|
|
|
CompositorD3D11(CompositorBridgeParent* aParent,
|
|
|
|
widget::CompositorWidget* aWidget);
|
2019-04-11 12:36:51 +00:00
|
|
|
virtual ~CompositorD3D11();
|
2013-05-03 17:34:29 +00:00
|
|
|
|
2019-04-11 12:36:51 +00:00
|
|
|
CompositorD3D11* AsCompositorD3D11() override { return this; }
|
2016-04-14 10:38:38 +00:00
|
|
|
|
2019-04-11 12:36:51 +00:00
|
|
|
bool Initialize(nsCString* const out_failureReason) override;
|
2013-05-03 17:34:29 +00:00
|
|
|
|
2019-04-11 12:36:51 +00:00
|
|
|
TextureFactoryIdentifier GetTextureFactoryIdentifier() override;
|
2013-05-03 17:34:29 +00:00
|
|
|
|
2019-04-11 12:36:51 +00:00
|
|
|
already_AddRefed<DataTextureSource> CreateDataTextureSource(
|
2015-03-21 16:28:04 +00:00
|
|
|
TextureFlags aFlags = TextureFlags::NO_FLAGS) override;
|
2013-07-30 09:59:51 +00:00
|
|
|
|
2019-04-11 12:36:51 +00:00
|
|
|
bool CanUseCanvasLayerForSize(const gfx::IntSize& aSize) override;
|
2018-02-09 05:22:43 +00:00
|
|
|
int32_t GetMaxTextureSize() const final;
|
2013-05-03 17:34:29 +00:00
|
|
|
|
2019-04-11 12:36:51 +00:00
|
|
|
void MakeCurrent(MakeCurrentFlags aFlags = 0) override {}
|
2013-05-03 17:34:29 +00:00
|
|
|
|
2019-04-11 12:36:51 +00:00
|
|
|
already_AddRefed<CompositingRenderTarget> CreateRenderTarget(
|
2015-03-21 16:28:04 +00:00
|
|
|
const gfx::IntRect& aRect, SurfaceInitMode aInit) override;
|
2013-05-03 17:34:29 +00:00
|
|
|
|
2019-04-11 12:36:51 +00:00
|
|
|
already_AddRefed<CompositingRenderTarget> CreateRenderTargetFromSource(
|
|
|
|
const gfx::IntRect& aRect, const CompositingRenderTarget* aSource,
|
|
|
|
const gfx::IntPoint& aSourcePoint) override;
|
2013-05-03 17:34:29 +00:00
|
|
|
|
2019-04-11 12:36:51 +00:00
|
|
|
void SetRenderTarget(CompositingRenderTarget* aSurface) override;
|
|
|
|
already_AddRefed<CompositingRenderTarget> GetCurrentRenderTarget()
|
2019-02-12 18:53:10 +00:00
|
|
|
const override {
|
|
|
|
return do_AddRef(mCurrentRT);
|
2013-05-03 17:34:29 +00:00
|
|
|
}
|
2019-04-11 12:36:51 +00:00
|
|
|
already_AddRefed<CompositingRenderTarget> GetWindowRenderTarget()
|
2019-02-19 14:54:12 +00:00
|
|
|
const override;
|
2013-05-03 17:34:29 +00:00
|
|
|
|
2019-04-11 12:36:51 +00:00
|
|
|
bool ReadbackRenderTarget(CompositingRenderTarget* aSource,
|
|
|
|
AsyncReadbackBuffer* aDest) override;
|
|
|
|
already_AddRefed<AsyncReadbackBuffer> CreateAsyncReadbackBuffer(
|
2019-02-19 14:54:12 +00:00
|
|
|
const gfx::IntSize& aSize) override;
|
|
|
|
|
2019-04-11 12:36:51 +00:00
|
|
|
bool BlitRenderTarget(CompositingRenderTarget* aSource,
|
|
|
|
const gfx::IntSize& aSourceSize,
|
|
|
|
const gfx::IntSize& aDestSize) override;
|
2019-02-19 14:54:12 +00:00
|
|
|
|
2019-04-11 12:36:51 +00:00
|
|
|
void SetDestinationSurfaceSize(const gfx::IntSize& aSize) override {}
|
2013-05-03 17:34:29 +00:00
|
|
|
|
2019-04-11 12:36:51 +00:00
|
|
|
void ClearRect(const gfx::Rect& aRect) override;
|
2014-03-28 03:38:32 +00:00
|
|
|
|
2019-04-11 12:36:51 +00:00
|
|
|
void DrawQuad(const gfx::Rect& aRect, const gfx::IntRect& aClipRect,
|
|
|
|
const EffectChain& aEffectChain, gfx::Float aOpacity,
|
|
|
|
const gfx::Matrix4x4& aTransform,
|
|
|
|
const gfx::Rect& aVisibleRect) override;
|
2013-05-03 17:34:29 +00:00
|
|
|
|
|
|
|
/**
|
2019-08-26 00:58:43 +00:00
|
|
|
* Start a new frame.
|
2013-05-03 17:34:29 +00:00
|
|
|
*/
|
2019-08-30 21:37:55 +00:00
|
|
|
Maybe<gfx::IntRect> BeginFrameForWindow(
|
|
|
|
const nsIntRegion& aInvalidRegion, const Maybe<gfx::IntRect>& aClipRect,
|
|
|
|
const gfx::IntRect& aRenderBounds,
|
|
|
|
const nsIntRegion& aOpaqueRegion) override;
|
2013-05-03 17:34:29 +00:00
|
|
|
|
2019-08-30 19:51:59 +00:00
|
|
|
Maybe<gfx::IntRect> BeginFrameForTarget(
|
|
|
|
const nsIntRegion& aInvalidRegion, const Maybe<gfx::IntRect>& aClipRect,
|
|
|
|
const gfx::IntRect& aRenderBounds, const nsIntRegion& aOpaqueRegion,
|
|
|
|
gfx::DrawTarget* aTarget, const gfx::IntRect& aTargetBounds) override;
|
|
|
|
|
2019-08-30 21:37:55 +00:00
|
|
|
void BeginFrameForNativeLayers() override;
|
|
|
|
|
|
|
|
Maybe<gfx::IntRect> BeginRenderingToNativeLayer(
|
|
|
|
const nsIntRegion& aInvalidRegion, const Maybe<gfx::IntRect>& aClipRect,
|
|
|
|
const nsIntRegion& aOpaqueRegion, NativeLayer* aNativeLayer) override;
|
|
|
|
|
|
|
|
void EndRenderingToNativeLayer() override;
|
|
|
|
|
2017-04-11 02:44:46 +00:00
|
|
|
void NormalDrawingDone() override;
|
|
|
|
|
2013-05-03 17:34:29 +00:00
|
|
|
/**
|
|
|
|
* Flush the current frame to the screen.
|
|
|
|
*/
|
2019-04-11 12:36:51 +00:00
|
|
|
void EndFrame() override;
|
2013-05-03 17:34:29 +00:00
|
|
|
|
2019-04-11 12:36:51 +00:00
|
|
|
void CancelFrame(bool aNeedFlush = true) override;
|
2016-10-11 12:10:22 +00:00
|
|
|
|
2013-05-03 17:34:29 +00:00
|
|
|
/**
|
|
|
|
* Setup the viewport and projection matrix for rendering
|
|
|
|
* to a window of the given dimensions.
|
|
|
|
*/
|
2015-05-19 17:51:26 +00:00
|
|
|
virtual void PrepareViewport(const gfx::IntSize& aSize);
|
|
|
|
virtual void PrepareViewport(const gfx::IntSize& aSize,
|
|
|
|
const gfx::Matrix4x4& aProjection, float aZNear,
|
|
|
|
float aZFar);
|
2013-05-03 17:34:29 +00:00
|
|
|
|
2019-04-11 12:36:51 +00:00
|
|
|
bool SupportsPartialTextureUpdate() override { return true; }
|
2013-05-03 17:34:29 +00:00
|
|
|
|
2019-04-11 12:36:51 +00:00
|
|
|
bool SupportsLayerGeometry() const override;
|
2017-02-20 11:19:28 +00:00
|
|
|
|
2013-05-03 17:34:29 +00:00
|
|
|
#ifdef MOZ_DUMP_PAINTING
|
2019-04-11 12:36:51 +00:00
|
|
|
const char* Name() const override { return "Direct3D 11"; }
|
2013-05-03 17:34:29 +00:00
|
|
|
#endif
|
|
|
|
|
2019-04-11 12:36:51 +00:00
|
|
|
LayersBackend GetBackendType() const override {
|
2014-02-18 00:30:05 +00:00
|
|
|
return LayersBackend::LAYERS_D3D11;
|
|
|
|
}
|
|
|
|
|
2016-03-10 03:12:55 +00:00
|
|
|
virtual void ForcePresent();
|
2016-02-24 03:50:09 +00:00
|
|
|
|
2017-03-22 03:32:53 +00:00
|
|
|
// For TextureSourceProvider.
|
|
|
|
ID3D11Device* GetD3D11Device() const override { return mDevice; }
|
|
|
|
|
2013-07-22 23:05:04 +00:00
|
|
|
ID3D11Device* GetDevice() { return mDevice; }
|
2013-05-03 17:34:29 +00:00
|
|
|
|
2014-07-09 14:21:11 +00:00
|
|
|
ID3D11DeviceContext* GetDC() { return mContext; }
|
|
|
|
|
2019-05-02 17:33:38 +00:00
|
|
|
virtual void RequestAllowFrameRecording(bool aWillRecord) override {
|
|
|
|
mAllowFrameRecording = aWillRecord;
|
|
|
|
}
|
|
|
|
|
2013-05-03 17:34:29 +00:00
|
|
|
private:
|
2014-10-23 14:22:41 +00:00
|
|
|
enum Severity {
|
|
|
|
Recoverable,
|
|
|
|
DebugAssert,
|
|
|
|
Critical,
|
|
|
|
};
|
|
|
|
|
2014-10-27 12:52:17 +00:00
|
|
|
void HandleError(HRESULT hr, Severity aSeverity = DebugAssert);
|
2014-10-23 14:22:41 +00:00
|
|
|
|
2015-10-06 06:38:40 +00:00
|
|
|
// Same as Failed(), except the severity is critical (with no abort) and
|
|
|
|
// a string prefix must be provided.
|
|
|
|
bool Failed(HRESULT hr, const char* aContext);
|
|
|
|
|
2013-08-04 07:46:17 +00:00
|
|
|
// ensure mSize is up to date with respect to mWidget
|
|
|
|
void EnsureSize();
|
2015-01-08 00:10:49 +00:00
|
|
|
bool VerifyBufferSize();
|
2015-10-27 13:11:00 +00:00
|
|
|
bool UpdateRenderTarget();
|
2014-10-06 12:53:42 +00:00
|
|
|
bool UpdateConstantBuffers();
|
2016-05-25 16:01:18 +00:00
|
|
|
void SetSamplerForSamplingFilter(gfx::SamplingFilter aSamplingFilter);
|
2017-02-20 11:19:28 +00:00
|
|
|
|
|
|
|
ID3D11PixelShader* GetPSForEffect(Effect* aEffect, const bool aUseBlendShader,
|
|
|
|
const MaskType aMaskType);
|
2019-08-30 19:51:55 +00:00
|
|
|
Maybe<gfx::IntRect> BeginFrame(const nsIntRegion& aInvalidRegion,
|
|
|
|
const Maybe<gfx::IntRect>& aClipRect,
|
|
|
|
const gfx::IntRect& aRenderBounds,
|
|
|
|
const nsIntRegion& aOpaqueRegion);
|
2013-05-03 17:34:29 +00:00
|
|
|
void PaintToTarget();
|
2016-02-03 00:33:13 +00:00
|
|
|
RefPtr<ID3D11Texture2D> CreateTexture(const gfx::IntRect& aRect,
|
|
|
|
const CompositingRenderTarget* aSource,
|
|
|
|
const gfx::IntPoint& aSourcePoint);
|
|
|
|
bool CopyBackdrop(const gfx::IntRect& aRect,
|
|
|
|
RefPtr<ID3D11Texture2D>* aOutTexture,
|
|
|
|
RefPtr<ID3D11ShaderResourceView>* aOutView);
|
2013-05-03 17:34:29 +00:00
|
|
|
|
2019-04-11 12:36:51 +00:00
|
|
|
void DrawTriangles(const nsTArray<gfx::TexturedTriangle>& aTriangles,
|
|
|
|
const gfx::Rect& aRect, const gfx::IntRect& aClipRect,
|
|
|
|
const EffectChain& aEffectChain, gfx::Float aOpacity,
|
|
|
|
const gfx::Matrix4x4& aTransform,
|
|
|
|
const gfx::Rect& aVisibleRect) override;
|
2017-02-20 11:19:28 +00:00
|
|
|
|
|
|
|
template <typename Geometry>
|
|
|
|
void DrawGeometry(const Geometry& aGeometry, const gfx::Rect& aRect,
|
|
|
|
const gfx::IntRect& aClipRect,
|
|
|
|
const EffectChain& aEffectChain, gfx::Float aOpacity,
|
|
|
|
const gfx::Matrix4x4& aTransform,
|
|
|
|
const gfx::Rect& aVisibleRect);
|
|
|
|
|
|
|
|
bool UpdateDynamicVertexBuffer(
|
|
|
|
const nsTArray<gfx::TexturedTriangle>& aTriangles);
|
|
|
|
|
|
|
|
void PrepareDynamicVertexBuffer();
|
|
|
|
void PrepareStaticVertexBuffer();
|
|
|
|
|
|
|
|
// Overloads for rendering both rects and triangles with same rendering path
|
|
|
|
void Draw(const nsTArray<gfx::TexturedTriangle>& aGeometry,
|
|
|
|
const gfx::Rect* aTexCoords);
|
|
|
|
|
|
|
|
void Draw(const gfx::Rect& aGeometry, const gfx::Rect* aTexCoords);
|
|
|
|
|
2017-04-11 02:44:46 +00:00
|
|
|
void GetFrameStats(GPUStats* aStats) override;
|
|
|
|
|
2017-04-11 02:44:46 +00:00
|
|
|
void Present();
|
|
|
|
|
2017-02-20 11:19:28 +00:00
|
|
|
ID3D11VertexShader* GetVSForGeometry(
|
|
|
|
const nsTArray<gfx::TexturedTriangle>& aTriangles,
|
|
|
|
const bool aUseBlendShader, const MaskType aMaskType);
|
|
|
|
|
|
|
|
ID3D11VertexShader* GetVSForGeometry(const gfx::Rect& aRect,
|
|
|
|
const bool aUseBlendShader,
|
|
|
|
const MaskType aMaskType);
|
|
|
|
|
|
|
|
template <typename VertexType>
|
|
|
|
void SetVertexBuffer(ID3D11Buffer* aBuffer);
|
|
|
|
|
2019-05-02 17:33:38 +00:00
|
|
|
/**
|
|
|
|
* Whether or not the recorder should be recording frames.
|
|
|
|
*
|
|
|
|
* When this returns true, the CompositorD3D11 will allocate and return window
|
|
|
|
* render targets from |GetWindowRenderTarget|, which otherwise returns
|
|
|
|
* nullptr.
|
|
|
|
*
|
|
|
|
* This will be true when either we are recording a profile with screenshots
|
|
|
|
* enabled or the |LayerManagerComposite| has requested us to record frames
|
|
|
|
* for the |CompositionRecorder|.
|
|
|
|
*/
|
|
|
|
bool ShouldAllowFrameRecording() const;
|
|
|
|
|
2019-08-30 19:51:59 +00:00
|
|
|
// The DrawTarget from BeginFrameForTarget, which EndFrame needs to copy the
|
|
|
|
// window contents into.
|
|
|
|
// Only non-null between BeginFrameForTarget and EndFrame.
|
|
|
|
RefPtr<gfx::DrawTarget> mTarget;
|
|
|
|
gfx::IntRect mTargetBounds;
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ID3D11DeviceContext> mContext;
|
|
|
|
RefPtr<ID3D11Device> mDevice;
|
|
|
|
RefPtr<IDXGISwapChain> mSwapChain;
|
|
|
|
RefPtr<CompositingRenderTargetD3D11> mDefaultRT;
|
|
|
|
RefPtr<CompositingRenderTargetD3D11> mCurrentRT;
|
2019-02-19 14:54:12 +00:00
|
|
|
mutable RefPtr<CompositingRenderTargetD3D11> mWindowRTCopy;
|
2013-05-03 17:34:29 +00:00
|
|
|
|
2016-05-10 22:53:46 +00:00
|
|
|
RefPtr<ID3D11Query> mQuery;
|
|
|
|
|
2017-04-30 18:38:59 +00:00
|
|
|
RefPtr<DeviceAttachmentsD3D11> mAttachments;
|
2017-04-11 02:44:46 +00:00
|
|
|
UniquePtr<DiagnosticsD3D11> mDiagnostics;
|
2013-05-03 17:34:29 +00:00
|
|
|
|
2015-12-03 06:29:54 +00:00
|
|
|
LayoutDeviceIntSize mSize;
|
2013-05-03 17:34:29 +00:00
|
|
|
|
|
|
|
HWND mHwnd;
|
|
|
|
|
|
|
|
D3D_FEATURE_LEVEL mFeatureLevel;
|
|
|
|
|
|
|
|
VertexShaderConstants mVSConstants;
|
|
|
|
PixelShaderConstants mPSConstants;
|
2013-09-15 22:30:11 +00:00
|
|
|
bool mDisableSequenceForNextFrame;
|
2016-08-13 19:12:51 +00:00
|
|
|
bool mAllowPartialPresents;
|
2017-03-30 18:47:13 +00:00
|
|
|
bool mIsDoubleBuffered;
|
2014-12-06 00:02:18 +00:00
|
|
|
|
2017-03-30 18:47:13 +00:00
|
|
|
gfx::IntRegion mFrontBufferInvalid;
|
|
|
|
gfx::IntRegion mBackBufferInvalid;
|
2014-12-06 00:02:18 +00:00
|
|
|
// This is the clip rect applied to the default DrawTarget (i.e. the window)
|
|
|
|
gfx::IntRect mCurrentClip;
|
2015-11-13 12:04:44 +00:00
|
|
|
|
|
|
|
bool mVerifyBuffersFailed;
|
2017-07-27 20:02:01 +00:00
|
|
|
bool mUseMutexOnPresent;
|
2019-05-02 17:33:38 +00:00
|
|
|
bool mAllowFrameRecording;
|
2013-05-03 17:34:29 +00:00
|
|
|
};
|
|
|
|
|
2018-09-15 23:00:02 +00:00
|
|
|
namespace TexSlot {
|
|
|
|
static const int RGB = 0;
|
|
|
|
static const int Y = 1;
|
|
|
|
static const int Cb = 2;
|
|
|
|
static const int Cr = 3;
|
|
|
|
static const int RGBWhite = 4;
|
|
|
|
static const int Mask = 5;
|
|
|
|
static const int Backdrop = 6;
|
|
|
|
} // namespace TexSlot
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2013-05-03 17:34:29 +00:00
|
|
|
} // namespace layers
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif
|