Bug 980642 - Implement ClearRect for CompositorD3D11. r=Bas, a=lsblakk.
authorMatt Woodrow <mwoodrow@mozilla.com>
Fri, 28 Mar 2014 16:38:32 +1300
changeset 192686 3bba214a0a6079a7653f4145dc7718aa1004bb47
parent 192685 db2f8f867500d708e0babe5c3777a6acc7c442e3
child 192687 5dc2f1b960edb74891eea6a90e789dff26c9825e
push id474
push userasasaki@mozilla.com
push dateMon, 02 Jun 2014 21:01:02 +0000
treeherdermozilla-release@967f4cf1b31c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersBas, lsblakk
bugs980642
milestone30.0a2
Bug 980642 - Implement ClearRect for CompositorD3D11. r=Bas, a=lsblakk.
gfx/layers/d3d11/CompositorD3D11.cpp
gfx/layers/d3d11/CompositorD3D11.h
--- a/gfx/layers/d3d11/CompositorD3D11.cpp
+++ b/gfx/layers/d3d11/CompositorD3D11.cpp
@@ -53,16 +53,17 @@ struct DeviceAttachmentsD3D11
   RefPtr<ID3D11Buffer> mPSConstantBuffer;
   RefPtr<ID3D11Buffer> mVSConstantBuffer;
   RefPtr<ID3D11RasterizerState> mRasterizerState;
   RefPtr<ID3D11SamplerState> mLinearSamplerState;
   RefPtr<ID3D11SamplerState> mPointSamplerState;
   RefPtr<ID3D11BlendState> mPremulBlendState;
   RefPtr<ID3D11BlendState> mNonPremulBlendState;
   RefPtr<ID3D11BlendState> mComponentBlendState;
+  RefPtr<ID3D11BlendState> mDisabledBlendState;
 };
 
 CompositorD3D11::CompositorD3D11(nsIWidget* aWidget)
   : mAttachments(nullptr)
   , mWidget(aWidget)
   , mHwnd(nullptr)
   , mDisableSequenceForNextFrame(false)
 {
@@ -238,16 +239,28 @@ CompositorD3D11::Initialize()
         D3D11_COLOR_WRITE_ENABLE_ALL
       };
       blendDesc.RenderTarget[0] = rtBlendComponent;
       hr = mDevice->CreateBlendState(&blendDesc, byRef(mAttachments->mComponentBlendState));
       if (FAILED(hr)) {
         return false;
       }
     }
+
+    D3D11_RENDER_TARGET_BLEND_DESC rtBlendDisabled = {
+      FALSE,
+      D3D11_BLEND_SRC_ALPHA, D3D11_BLEND_INV_SRC_ALPHA, D3D11_BLEND_OP_ADD,
+      D3D11_BLEND_ONE, D3D11_BLEND_INV_SRC_ALPHA, D3D11_BLEND_OP_ADD,
+      D3D11_COLOR_WRITE_ENABLE_ALL
+    };
+    blendDesc.RenderTarget[0] = rtBlendDisabled;
+    hr = mDevice->CreateBlendState(&blendDesc, byRef(mAttachments->mDisabledBlendState));
+    if (FAILED(hr)) {
+      return false;
+    }
   }
 
   nsRefPtr<IDXGIDevice> dxgiDevice;
   nsRefPtr<IDXGIAdapter> dxgiAdapter;
 
   mDevice->QueryInterface(dxgiDevice.StartAssignment());
   dxgiDevice->GetAdapter(getter_AddRefs(dxgiAdapter));
 
@@ -484,16 +497,51 @@ CompositorD3D11::SetPSForEffect(Effect* 
     return;
   default:
     NS_WARNING("No shader to load");
     return;
   }
 }
 
 void
+CompositorD3D11::ClearRect(const gfx::Rect& aRect)
+{
+  mContext->OMSetBlendState(mAttachments->mDisabledBlendState, sBlendFactor, 0xFFFFFFFF);
+
+  Matrix4x4 identity;
+  memcpy(&mVSConstants.layerTransform, &identity._11, 64);
+
+  mVSConstants.layerQuad = aRect;
+  mVSConstants.renderTargetOffset[0] = 0;
+  mVSConstants.renderTargetOffset[1] = 0;
+  mPSConstants.layerOpacity[0] = 1.0f;
+
+  D3D11_RECT scissor;
+  scissor.left = aRect.x;
+  scissor.right = aRect.XMost();
+  scissor.top = aRect.y;
+  scissor.bottom = aRect.YMost();
+  mContext->RSSetScissorRects(1, &scissor);
+  mContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
+  mContext->VSSetShader(mAttachments->mVSQuadShader[MaskNone], nullptr, 0);
+
+  mContext->PSSetShader(mAttachments->mSolidColorShader[MaskNone], nullptr, 0);
+  mPSConstants.layerColor[0] = 0;
+  mPSConstants.layerColor[1] = 0;
+  mPSConstants.layerColor[2] = 0;
+  mPSConstants.layerColor[3] = 0;
+
+  UpdateConstantBuffers();
+
+  mContext->Draw(4, 0);
+
+  mContext->OMSetBlendState(mAttachments->mPremulBlendState, sBlendFactor, 0xFFFFFFFF);
+}
+
+void
 CompositorD3D11::DrawQuad(const gfx::Rect& aRect,
                           const gfx::Rect& aClipRect,
                           const EffectChain& aEffectChain,
                           gfx::Float aOpacity,
                           const gfx::Matrix4x4& aTransform)
 {
   MOZ_ASSERT(mCurrentRT, "No render target");
   memcpy(&mVSConstants.layerTransform, &aTransform._11, 64);
--- a/gfx/layers/d3d11/CompositorD3D11.h
+++ b/gfx/layers/d3d11/CompositorD3D11.h
@@ -85,16 +85,18 @@ public:
   virtual void SetScreenRenderOffset(const ScreenPoint& aOffset) MOZ_OVERRIDE
   {
     if (aOffset.x || aOffset.y) {
       NS_RUNTIMEABORT("SetScreenRenderOffset not supported by CompositorD3D11.");
     }
     // If the offset is 0, 0 that's okay.
   }
 
+  virtual void ClearRect(const gfx::Rect& aRect) MOZ_OVERRIDE;
+
   virtual void DrawQuad(const gfx::Rect &aRect,
                         const gfx::Rect &aClipRect,
                         const EffectChain &aEffectChain,
                         gfx::Float aOpacity,
                         const gfx::Matrix4x4 &aTransform) MOZ_OVERRIDE;
 
   /**
    * Start a new frame. If aClipRectIn is null, sets *aClipRectOut to the