gfx/layers/d3d11/CompositorD3D11.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/layers/d3d11/CompositorD3D11.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,189 @@
     1.4 +/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
     1.5 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#ifndef MOZILLA_GFX_COMPOSITORD3D11_H
    1.10 +#define MOZILLA_GFX_COMPOSITORD3D11_H
    1.11 +
    1.12 +#include "mozilla/gfx/2D.h"
    1.13 +#include "gfx2DGlue.h"
    1.14 +#include "mozilla/layers/Compositor.h"
    1.15 +#include "TextureD3D11.h"
    1.16 +#include <d3d11.h>
    1.17 +
    1.18 +class nsWidget;
    1.19 +
    1.20 +namespace mozilla {
    1.21 +namespace layers {
    1.22 +
    1.23 +#define LOGD3D11(param)
    1.24 +
    1.25 +struct VertexShaderConstants
    1.26 +{
    1.27 +  float layerTransform[4][4];
    1.28 +  float projection[4][4];
    1.29 +  float renderTargetOffset[4];
    1.30 +  gfx::Rect textureCoords;
    1.31 +  gfx::Rect layerQuad;
    1.32 +  gfx::Rect maskQuad;
    1.33 +};
    1.34 +
    1.35 +struct PixelShaderConstants
    1.36 +{
    1.37 +  float layerColor[4];
    1.38 +  float layerOpacity[4];
    1.39 +};
    1.40 +
    1.41 +struct DeviceAttachmentsD3D11;
    1.42 +
    1.43 +class CompositorD3D11 : public Compositor
    1.44 +{
    1.45 +public:
    1.46 +  CompositorD3D11(nsIWidget* aWidget);
    1.47 +  ~CompositorD3D11();
    1.48 +
    1.49 +  virtual bool Initialize() MOZ_OVERRIDE;
    1.50 +  virtual void Destroy() MOZ_OVERRIDE {}
    1.51 +
    1.52 +  virtual TextureFactoryIdentifier
    1.53 +    GetTextureFactoryIdentifier() MOZ_OVERRIDE;
    1.54 +
    1.55 +  virtual TemporaryRef<DataTextureSource>
    1.56 +    CreateDataTextureSource(TextureFlags aFlags = 0) MOZ_OVERRIDE;
    1.57 +
    1.58 +  virtual bool CanUseCanvasLayerForSize(const gfx::IntSize& aSize) MOZ_OVERRIDE;
    1.59 +  virtual int32_t GetMaxTextureSize() const MOZ_FINAL;
    1.60 +
    1.61 +  virtual void SetTargetContext(gfx::DrawTarget* aTarget)  MOZ_OVERRIDE
    1.62 +  {
    1.63 +    mTarget = aTarget;
    1.64 +  }
    1.65 +
    1.66 +  virtual void MakeCurrent(MakeCurrentFlags aFlags = 0)  MOZ_OVERRIDE {}
    1.67 +
    1.68 +  virtual TemporaryRef<CompositingRenderTarget>
    1.69 +    CreateRenderTarget(const gfx::IntRect &aRect,
    1.70 +                       SurfaceInitMode aInit) MOZ_OVERRIDE;
    1.71 +
    1.72 +  virtual TemporaryRef<CompositingRenderTarget>
    1.73 +    CreateRenderTargetFromSource(const gfx::IntRect& aRect,
    1.74 +                                 const CompositingRenderTarget* aSource,
    1.75 +                                 const gfx::IntPoint& aSourcePoint) MOZ_OVERRIDE;
    1.76 +
    1.77 +  virtual void SetRenderTarget(CompositingRenderTarget* aSurface) MOZ_OVERRIDE;
    1.78 +  virtual CompositingRenderTarget* GetCurrentRenderTarget() const MOZ_OVERRIDE
    1.79 +  {
    1.80 +    return mCurrentRT;
    1.81 +  }
    1.82 +
    1.83 +  virtual void SetDestinationSurfaceSize(const gfx::IntSize& aSize) MOZ_OVERRIDE {}
    1.84 +
    1.85 +  /**
    1.86 +   * Declare an offset to use when rendering layers. This will be ignored when
    1.87 +   * rendering to a target instead of the screen.
    1.88 +   */
    1.89 +  virtual void SetScreenRenderOffset(const ScreenPoint& aOffset) MOZ_OVERRIDE
    1.90 +  {
    1.91 +    if (aOffset.x || aOffset.y) {
    1.92 +      NS_RUNTIMEABORT("SetScreenRenderOffset not supported by CompositorD3D11.");
    1.93 +    }
    1.94 +    // If the offset is 0, 0 that's okay.
    1.95 +  }
    1.96 +
    1.97 +  virtual void ClearRect(const gfx::Rect& aRect) MOZ_OVERRIDE;
    1.98 +
    1.99 +  virtual void DrawQuad(const gfx::Rect &aRect,
   1.100 +                        const gfx::Rect &aClipRect,
   1.101 +                        const EffectChain &aEffectChain,
   1.102 +                        gfx::Float aOpacity,
   1.103 +                        const gfx::Matrix4x4 &aTransform) MOZ_OVERRIDE;
   1.104 +
   1.105 +  /**
   1.106 +   * Start a new frame. If aClipRectIn is null, sets *aClipRectOut to the
   1.107 +   * screen dimensions. 
   1.108 +   */
   1.109 +  virtual void BeginFrame(const nsIntRegion& aInvalidRegion,
   1.110 +                          const gfx::Rect *aClipRectIn,
   1.111 +                          const gfx::Matrix& aTransform,
   1.112 +                          const gfx::Rect& aRenderBounds,
   1.113 +                          gfx::Rect *aClipRectOut = nullptr,
   1.114 +                          gfx::Rect *aRenderBoundsOut = nullptr) MOZ_OVERRIDE;
   1.115 +
   1.116 +  /**
   1.117 +   * Flush the current frame to the screen.
   1.118 +   */
   1.119 +  virtual void EndFrame() MOZ_OVERRIDE;
   1.120 +
   1.121 +  /**
   1.122 +   * Post rendering stuff if the rendering is outside of this Compositor
   1.123 +   * e.g., by Composer2D
   1.124 +   */
   1.125 +  virtual void EndFrameForExternalComposition(const gfx::Matrix& aTransform) MOZ_OVERRIDE {}
   1.126 +
   1.127 +  /**
   1.128 +   * Tidy up if BeginFrame has been called, but EndFrame won't be
   1.129 +   */
   1.130 +  virtual void AbortFrame() MOZ_OVERRIDE {}
   1.131 +
   1.132 +  /**
   1.133 +   * Setup the viewport and projection matrix for rendering
   1.134 +   * to a window of the given dimensions.
   1.135 +   */
   1.136 +  virtual void PrepareViewport(const gfx::IntSize& aSize,
   1.137 +                               const gfx::Matrix& aWorldTransform) MOZ_OVERRIDE;
   1.138 +
   1.139 +  virtual bool SupportsPartialTextureUpdate() MOZ_OVERRIDE { return true; }
   1.140 +
   1.141 +#ifdef MOZ_DUMP_PAINTING
   1.142 +  virtual const char* Name() const MOZ_OVERRIDE { return "Direct3D 11"; }
   1.143 +#endif
   1.144 +
   1.145 +  virtual LayersBackend GetBackendType() const MOZ_OVERRIDE {
   1.146 +    return LayersBackend::LAYERS_D3D11;
   1.147 +  }
   1.148 +
   1.149 +  virtual nsIWidget* GetWidget() const MOZ_OVERRIDE { return mWidget; }
   1.150 +
   1.151 +  ID3D11Device* GetDevice() { return mDevice; }
   1.152 +
   1.153 +private:
   1.154 +  // ensure mSize is up to date with respect to mWidget
   1.155 +  void EnsureSize();
   1.156 +  void VerifyBufferSize();
   1.157 +  void UpdateRenderTarget();
   1.158 +  bool CreateShaders();
   1.159 +  void UpdateConstantBuffers();
   1.160 +  void SetSamplerForFilter(gfx::Filter aFilter);
   1.161 +  void SetPSForEffect(Effect *aEffect, MaskType aMaskType, gfx::SurfaceFormat aFormat);
   1.162 +  void PaintToTarget();
   1.163 +
   1.164 +  virtual gfx::IntSize GetWidgetSize() const MOZ_OVERRIDE { return gfx::ToIntSize(mSize); }
   1.165 +
   1.166 +  RefPtr<ID3D11DeviceContext> mContext;
   1.167 +  RefPtr<ID3D11Device> mDevice;
   1.168 +  RefPtr<IDXGISwapChain> mSwapChain;
   1.169 +  RefPtr<CompositingRenderTargetD3D11> mDefaultRT;
   1.170 +  RefPtr<CompositingRenderTargetD3D11> mCurrentRT;
   1.171 +
   1.172 +  DeviceAttachmentsD3D11* mAttachments;
   1.173 +
   1.174 +  RefPtr<gfx::DrawTarget> mTarget;
   1.175 +
   1.176 +  nsIWidget* mWidget;
   1.177 +
   1.178 +  nsIntSize mSize;
   1.179 +
   1.180 +  HWND mHwnd;
   1.181 +
   1.182 +  D3D_FEATURE_LEVEL mFeatureLevel;
   1.183 +
   1.184 +  VertexShaderConstants mVSConstants;
   1.185 +  PixelShaderConstants mPSConstants;
   1.186 +  bool mDisableSequenceForNextFrame;
   1.187 +};
   1.188 +
   1.189 +}
   1.190 +}
   1.191 +
   1.192 +#endif

mercurial