michael@0: /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef MOZILLA_GFX_COMPOSITORD3D11_H michael@0: #define MOZILLA_GFX_COMPOSITORD3D11_H michael@0: michael@0: #include "mozilla/gfx/2D.h" michael@0: #include "gfx2DGlue.h" michael@0: #include "mozilla/layers/Compositor.h" michael@0: #include "TextureD3D11.h" michael@0: #include michael@0: michael@0: class nsWidget; michael@0: michael@0: namespace mozilla { michael@0: namespace layers { michael@0: michael@0: #define LOGD3D11(param) michael@0: michael@0: struct VertexShaderConstants michael@0: { michael@0: float layerTransform[4][4]; michael@0: float projection[4][4]; michael@0: float renderTargetOffset[4]; michael@0: gfx::Rect textureCoords; michael@0: gfx::Rect layerQuad; michael@0: gfx::Rect maskQuad; michael@0: }; michael@0: michael@0: struct PixelShaderConstants michael@0: { michael@0: float layerColor[4]; michael@0: float layerOpacity[4]; michael@0: }; michael@0: michael@0: struct DeviceAttachmentsD3D11; michael@0: michael@0: class CompositorD3D11 : public Compositor michael@0: { michael@0: public: michael@0: CompositorD3D11(nsIWidget* aWidget); michael@0: ~CompositorD3D11(); michael@0: michael@0: virtual bool Initialize() MOZ_OVERRIDE; michael@0: virtual void Destroy() MOZ_OVERRIDE {} michael@0: michael@0: virtual TextureFactoryIdentifier michael@0: GetTextureFactoryIdentifier() MOZ_OVERRIDE; michael@0: michael@0: virtual TemporaryRef michael@0: CreateDataTextureSource(TextureFlags aFlags = 0) MOZ_OVERRIDE; michael@0: michael@0: virtual bool CanUseCanvasLayerForSize(const gfx::IntSize& aSize) MOZ_OVERRIDE; michael@0: virtual int32_t GetMaxTextureSize() const MOZ_FINAL; michael@0: michael@0: virtual void SetTargetContext(gfx::DrawTarget* aTarget) MOZ_OVERRIDE michael@0: { michael@0: mTarget = aTarget; michael@0: } michael@0: michael@0: virtual void MakeCurrent(MakeCurrentFlags aFlags = 0) MOZ_OVERRIDE {} michael@0: michael@0: virtual TemporaryRef michael@0: CreateRenderTarget(const gfx::IntRect &aRect, michael@0: SurfaceInitMode aInit) MOZ_OVERRIDE; michael@0: michael@0: virtual TemporaryRef michael@0: CreateRenderTargetFromSource(const gfx::IntRect& aRect, michael@0: const CompositingRenderTarget* aSource, michael@0: const gfx::IntPoint& aSourcePoint) MOZ_OVERRIDE; michael@0: michael@0: virtual void SetRenderTarget(CompositingRenderTarget* aSurface) MOZ_OVERRIDE; michael@0: virtual CompositingRenderTarget* GetCurrentRenderTarget() const MOZ_OVERRIDE michael@0: { michael@0: return mCurrentRT; michael@0: } michael@0: michael@0: virtual void SetDestinationSurfaceSize(const gfx::IntSize& aSize) MOZ_OVERRIDE {} michael@0: michael@0: /** michael@0: * Declare an offset to use when rendering layers. This will be ignored when michael@0: * rendering to a target instead of the screen. michael@0: */ michael@0: virtual void SetScreenRenderOffset(const ScreenPoint& aOffset) MOZ_OVERRIDE michael@0: { michael@0: if (aOffset.x || aOffset.y) { michael@0: NS_RUNTIMEABORT("SetScreenRenderOffset not supported by CompositorD3D11."); michael@0: } michael@0: // If the offset is 0, 0 that's okay. michael@0: } michael@0: michael@0: virtual void ClearRect(const gfx::Rect& aRect) MOZ_OVERRIDE; michael@0: michael@0: virtual void DrawQuad(const gfx::Rect &aRect, michael@0: const gfx::Rect &aClipRect, michael@0: const EffectChain &aEffectChain, michael@0: gfx::Float aOpacity, michael@0: const gfx::Matrix4x4 &aTransform) MOZ_OVERRIDE; michael@0: michael@0: /** michael@0: * Start a new frame. If aClipRectIn is null, sets *aClipRectOut to the michael@0: * screen dimensions. michael@0: */ michael@0: virtual void BeginFrame(const nsIntRegion& aInvalidRegion, michael@0: const gfx::Rect *aClipRectIn, michael@0: const gfx::Matrix& aTransform, michael@0: const gfx::Rect& aRenderBounds, michael@0: gfx::Rect *aClipRectOut = nullptr, michael@0: gfx::Rect *aRenderBoundsOut = nullptr) MOZ_OVERRIDE; michael@0: michael@0: /** michael@0: * Flush the current frame to the screen. michael@0: */ michael@0: virtual void EndFrame() MOZ_OVERRIDE; michael@0: michael@0: /** michael@0: * Post rendering stuff if the rendering is outside of this Compositor michael@0: * e.g., by Composer2D michael@0: */ michael@0: virtual void EndFrameForExternalComposition(const gfx::Matrix& aTransform) MOZ_OVERRIDE {} michael@0: michael@0: /** michael@0: * Tidy up if BeginFrame has been called, but EndFrame won't be michael@0: */ michael@0: virtual void AbortFrame() MOZ_OVERRIDE {} michael@0: michael@0: /** michael@0: * Setup the viewport and projection matrix for rendering michael@0: * to a window of the given dimensions. michael@0: */ michael@0: virtual void PrepareViewport(const gfx::IntSize& aSize, michael@0: const gfx::Matrix& aWorldTransform) MOZ_OVERRIDE; michael@0: michael@0: virtual bool SupportsPartialTextureUpdate() MOZ_OVERRIDE { return true; } michael@0: michael@0: #ifdef MOZ_DUMP_PAINTING michael@0: virtual const char* Name() const MOZ_OVERRIDE { return "Direct3D 11"; } michael@0: #endif michael@0: michael@0: virtual LayersBackend GetBackendType() const MOZ_OVERRIDE { michael@0: return LayersBackend::LAYERS_D3D11; michael@0: } michael@0: michael@0: virtual nsIWidget* GetWidget() const MOZ_OVERRIDE { return mWidget; } michael@0: michael@0: ID3D11Device* GetDevice() { return mDevice; } michael@0: michael@0: private: michael@0: // ensure mSize is up to date with respect to mWidget michael@0: void EnsureSize(); michael@0: void VerifyBufferSize(); michael@0: void UpdateRenderTarget(); michael@0: bool CreateShaders(); michael@0: void UpdateConstantBuffers(); michael@0: void SetSamplerForFilter(gfx::Filter aFilter); michael@0: void SetPSForEffect(Effect *aEffect, MaskType aMaskType, gfx::SurfaceFormat aFormat); michael@0: void PaintToTarget(); michael@0: michael@0: virtual gfx::IntSize GetWidgetSize() const MOZ_OVERRIDE { return gfx::ToIntSize(mSize); } michael@0: michael@0: RefPtr mContext; michael@0: RefPtr mDevice; michael@0: RefPtr mSwapChain; michael@0: RefPtr mDefaultRT; michael@0: RefPtr mCurrentRT; michael@0: michael@0: DeviceAttachmentsD3D11* mAttachments; michael@0: michael@0: RefPtr mTarget; michael@0: michael@0: nsIWidget* mWidget; michael@0: michael@0: nsIntSize mSize; michael@0: michael@0: HWND mHwnd; michael@0: michael@0: D3D_FEATURE_LEVEL mFeatureLevel; michael@0: michael@0: VertexShaderConstants mVSConstants; michael@0: PixelShaderConstants mPSConstants; michael@0: bool mDisableSequenceForNextFrame; michael@0: }; michael@0: michael@0: } michael@0: } michael@0: michael@0: #endif