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

     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/. */
     6 #ifndef MOZILLA_GFX_COMPOSITORD3D11_H
     7 #define MOZILLA_GFX_COMPOSITORD3D11_H
     9 #include "mozilla/gfx/2D.h"
    10 #include "gfx2DGlue.h"
    11 #include "mozilla/layers/Compositor.h"
    12 #include "TextureD3D11.h"
    13 #include <d3d11.h>
    15 class nsWidget;
    17 namespace mozilla {
    18 namespace layers {
    20 #define LOGD3D11(param)
    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 };
    32 struct PixelShaderConstants
    33 {
    34   float layerColor[4];
    35   float layerOpacity[4];
    36 };
    38 struct DeviceAttachmentsD3D11;
    40 class CompositorD3D11 : public Compositor
    41 {
    42 public:
    43   CompositorD3D11(nsIWidget* aWidget);
    44   ~CompositorD3D11();
    46   virtual bool Initialize() MOZ_OVERRIDE;
    47   virtual void Destroy() MOZ_OVERRIDE {}
    49   virtual TextureFactoryIdentifier
    50     GetTextureFactoryIdentifier() MOZ_OVERRIDE;
    52   virtual TemporaryRef<DataTextureSource>
    53     CreateDataTextureSource(TextureFlags aFlags = 0) MOZ_OVERRIDE;
    55   virtual bool CanUseCanvasLayerForSize(const gfx::IntSize& aSize) MOZ_OVERRIDE;
    56   virtual int32_t GetMaxTextureSize() const MOZ_FINAL;
    58   virtual void SetTargetContext(gfx::DrawTarget* aTarget)  MOZ_OVERRIDE
    59   {
    60     mTarget = aTarget;
    61   }
    63   virtual void MakeCurrent(MakeCurrentFlags aFlags = 0)  MOZ_OVERRIDE {}
    65   virtual TemporaryRef<CompositingRenderTarget>
    66     CreateRenderTarget(const gfx::IntRect &aRect,
    67                        SurfaceInitMode aInit) MOZ_OVERRIDE;
    69   virtual TemporaryRef<CompositingRenderTarget>
    70     CreateRenderTargetFromSource(const gfx::IntRect& aRect,
    71                                  const CompositingRenderTarget* aSource,
    72                                  const gfx::IntPoint& aSourcePoint) MOZ_OVERRIDE;
    74   virtual void SetRenderTarget(CompositingRenderTarget* aSurface) MOZ_OVERRIDE;
    75   virtual CompositingRenderTarget* GetCurrentRenderTarget() const MOZ_OVERRIDE
    76   {
    77     return mCurrentRT;
    78   }
    80   virtual void SetDestinationSurfaceSize(const gfx::IntSize& aSize) MOZ_OVERRIDE {}
    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   }
    94   virtual void ClearRect(const gfx::Rect& aRect) MOZ_OVERRIDE;
    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;
   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;
   113   /**
   114    * Flush the current frame to the screen.
   115    */
   116   virtual void EndFrame() MOZ_OVERRIDE;
   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 {}
   124   /**
   125    * Tidy up if BeginFrame has been called, but EndFrame won't be
   126    */
   127   virtual void AbortFrame() MOZ_OVERRIDE {}
   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;
   136   virtual bool SupportsPartialTextureUpdate() MOZ_OVERRIDE { return true; }
   138 #ifdef MOZ_DUMP_PAINTING
   139   virtual const char* Name() const MOZ_OVERRIDE { return "Direct3D 11"; }
   140 #endif
   142   virtual LayersBackend GetBackendType() const MOZ_OVERRIDE {
   143     return LayersBackend::LAYERS_D3D11;
   144   }
   146   virtual nsIWidget* GetWidget() const MOZ_OVERRIDE { return mWidget; }
   148   ID3D11Device* GetDevice() { return mDevice; }
   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();
   161   virtual gfx::IntSize GetWidgetSize() const MOZ_OVERRIDE { return gfx::ToIntSize(mSize); }
   163   RefPtr<ID3D11DeviceContext> mContext;
   164   RefPtr<ID3D11Device> mDevice;
   165   RefPtr<IDXGISwapChain> mSwapChain;
   166   RefPtr<CompositingRenderTargetD3D11> mDefaultRT;
   167   RefPtr<CompositingRenderTargetD3D11> mCurrentRT;
   169   DeviceAttachmentsD3D11* mAttachments;
   171   RefPtr<gfx::DrawTarget> mTarget;
   173   nsIWidget* mWidget;
   175   nsIntSize mSize;
   177   HWND mHwnd;
   179   D3D_FEATURE_LEVEL mFeatureLevel;
   181   VertexShaderConstants mVSConstants;
   182   PixelShaderConstants mPSConstants;
   183   bool mDisableSequenceForNextFrame;
   184 };
   186 }
   187 }
   189 #endif

mercurial