gfx/layers/d3d11/TextureD3D11.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/layers/d3d11/TextureD3D11.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,248 @@
     1.4 +/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
     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_TEXTURED3D11_H
    1.10 +#define MOZILLA_GFX_TEXTURED3D11_H
    1.11 +
    1.12 +#include "mozilla/layers/Compositor.h"
    1.13 +#include "mozilla/layers/TextureClient.h"
    1.14 +#include "mozilla/layers/TextureHost.h"
    1.15 +#include "gfxWindowsPlatform.h"
    1.16 +#include "mozilla/GfxMessageUtils.h"
    1.17 +#include <d3d11.h>
    1.18 +#include <vector>
    1.19 +
    1.20 +class gfxD2DSurface;
    1.21 +
    1.22 +namespace mozilla {
    1.23 +namespace layers {
    1.24 +
    1.25 +class CompositorD3D11;
    1.26 +
    1.27 +/**
    1.28 + * A TextureClient to share a D3D10 texture with the compositor thread.
    1.29 + * The corresponding TextureHost is DXGITextureHostD3D11
    1.30 + */
    1.31 +class TextureClientD3D11 : public TextureClient
    1.32 +{
    1.33 +public:
    1.34 +  TextureClientD3D11(gfx::SurfaceFormat aFormat, TextureFlags aFlags);
    1.35 +
    1.36 +  virtual ~TextureClientD3D11();
    1.37 +
    1.38 +  // TextureClient
    1.39 +
    1.40 +  virtual bool IsAllocated() const MOZ_OVERRIDE { return !!mTexture; }
    1.41 +
    1.42 +  virtual bool Lock(OpenMode aOpenMode) MOZ_OVERRIDE;
    1.43 +
    1.44 +  virtual void Unlock() MOZ_OVERRIDE;
    1.45 +
    1.46 +  virtual bool IsLocked() const MOZ_OVERRIDE { return mIsLocked; }
    1.47 +
    1.48 +  virtual bool ImplementsLocking() const MOZ_OVERRIDE { return true; }
    1.49 +
    1.50 +  virtual bool HasInternalBuffer() const MOZ_OVERRIDE { return false; }
    1.51 +
    1.52 +  virtual bool ToSurfaceDescriptor(SurfaceDescriptor& aOutDescriptor) MOZ_OVERRIDE;
    1.53 +
    1.54 +  virtual gfx::IntSize GetSize() const MOZ_OVERRIDE { return mSize; }
    1.55 +
    1.56 +  virtual TextureClientData* DropTextureData() MOZ_OVERRIDE { return nullptr; }
    1.57 +
    1.58 +  virtual gfx::SurfaceFormat GetFormat() const MOZ_OVERRIDE { return mFormat; }
    1.59 +
    1.60 +  virtual bool CanExposeDrawTarget() const MOZ_OVERRIDE { return true; }
    1.61 +
    1.62 +  virtual TemporaryRef<gfx::DrawTarget> GetAsDrawTarget() MOZ_OVERRIDE;
    1.63 +
    1.64 +  virtual bool AllocateForSurface(gfx::IntSize aSize,
    1.65 +                                  TextureAllocationFlags aFlags = ALLOC_DEFAULT) MOZ_OVERRIDE;
    1.66 +
    1.67 +protected:
    1.68 +  gfx::IntSize mSize;
    1.69 +  RefPtr<ID3D10Texture2D> mTexture;
    1.70 +  RefPtr<gfx::DrawTarget> mDrawTarget;
    1.71 +  gfx::SurfaceFormat mFormat;
    1.72 +  bool mIsLocked;
    1.73 +  bool mNeedsClear;
    1.74 +};
    1.75 +
    1.76 +/**
    1.77 + * TextureSource that provides with the necessary APIs to be composited by a
    1.78 + * CompositorD3D11.
    1.79 + */
    1.80 +class TextureSourceD3D11
    1.81 +{
    1.82 +public:
    1.83 +  TextureSourceD3D11() {}
    1.84 +  virtual ~TextureSourceD3D11() {}
    1.85 +
    1.86 +  virtual ID3D11Texture2D* GetD3D11Texture() const { return mTexture; }
    1.87 +
    1.88 +protected:
    1.89 +  virtual gfx::IntSize GetSize() const { return mSize; }
    1.90 +
    1.91 +  gfx::IntSize mSize;
    1.92 +  RefPtr<ID3D11Texture2D> mTexture;
    1.93 +};
    1.94 +
    1.95 +/**
    1.96 + * A TextureSource that implements the DataTextureSource interface.
    1.97 + * it can be used without a TextureHost and is able to upload texture data
    1.98 + * from a gfx::DataSourceSurface.
    1.99 + */
   1.100 +class DataTextureSourceD3D11 : public DataTextureSource
   1.101 +                             , public TextureSourceD3D11
   1.102 +                             , public TileIterator
   1.103 +{
   1.104 +public:
   1.105 +  DataTextureSourceD3D11(gfx::SurfaceFormat aFormat, CompositorD3D11* aCompositor,
   1.106 +                         TextureFlags aFlags);
   1.107 +
   1.108 +  DataTextureSourceD3D11(gfx::SurfaceFormat aFormat, CompositorD3D11* aCompositor,
   1.109 +                         ID3D11Texture2D* aTexture);
   1.110 +
   1.111 +  virtual ~DataTextureSourceD3D11();
   1.112 +
   1.113 +
   1.114 +  // DataTextureSource
   1.115 +
   1.116 +  virtual bool Update(gfx::DataSourceSurface* aSurface,
   1.117 +                      nsIntRegion* aDestRegion = nullptr,
   1.118 +                      gfx::IntPoint* aSrcOffset = nullptr) MOZ_OVERRIDE;
   1.119 +
   1.120 +  // TextureSource
   1.121 +
   1.122 +  virtual TextureSourceD3D11* AsSourceD3D11() MOZ_OVERRIDE { return this; }
   1.123 +
   1.124 +  virtual ID3D11Texture2D* GetD3D11Texture() const MOZ_OVERRIDE;
   1.125 +
   1.126 +  virtual DataTextureSource* AsDataTextureSource() MOZ_OVERRIDE { return this; }
   1.127 +
   1.128 +  virtual void DeallocateDeviceData() MOZ_OVERRIDE { mTexture = nullptr; }
   1.129 +
   1.130 +  virtual gfx::IntSize GetSize() const  MOZ_OVERRIDE { return mSize; }
   1.131 +
   1.132 +  virtual gfx::SurfaceFormat GetFormat() const MOZ_OVERRIDE { return mFormat; }
   1.133 +
   1.134 +  virtual void SetCompositor(Compositor* aCompositor) MOZ_OVERRIDE;
   1.135 +
   1.136 +  // TileIterator
   1.137 +
   1.138 +  virtual TileIterator* AsTileIterator() MOZ_OVERRIDE { return mIsTiled ? this : nullptr; }
   1.139 +
   1.140 +  virtual size_t GetTileCount() MOZ_OVERRIDE { return mTileTextures.size(); }
   1.141 +
   1.142 +  virtual bool NextTile() MOZ_OVERRIDE { return (++mCurrentTile < mTileTextures.size()); }
   1.143 +
   1.144 +  virtual nsIntRect GetTileRect() MOZ_OVERRIDE;
   1.145 +
   1.146 +  virtual void EndTileIteration() MOZ_OVERRIDE { mIterating = false; }
   1.147 +
   1.148 +  virtual void BeginTileIteration() MOZ_OVERRIDE
   1.149 +  {
   1.150 +    mIterating = true;
   1.151 +    mCurrentTile = 0;
   1.152 +  }
   1.153 +
   1.154 +protected:
   1.155 +  gfx::IntRect GetTileRect(uint32_t aIndex) const;
   1.156 +
   1.157 +  void Reset();
   1.158 +
   1.159 +  std::vector< RefPtr<ID3D11Texture2D> > mTileTextures;
   1.160 +  RefPtr<CompositorD3D11> mCompositor;
   1.161 +  gfx::SurfaceFormat mFormat;
   1.162 +  TextureFlags mFlags;
   1.163 +  uint32_t mCurrentTile;
   1.164 +  bool mIsTiled;
   1.165 +  bool mIterating;
   1.166 +
   1.167 +};
   1.168 +
   1.169 +/**
   1.170 + * A TextureHost for shared D3D11 textures.
   1.171 + */
   1.172 +class DXGITextureHostD3D11 : public TextureHost
   1.173 +{
   1.174 +public:
   1.175 +  DXGITextureHostD3D11(TextureFlags aFlags,
   1.176 +                       const SurfaceDescriptorD3D10& aDescriptor);
   1.177 +
   1.178 +  virtual NewTextureSource* GetTextureSources() MOZ_OVERRIDE;
   1.179 +
   1.180 +  virtual void DeallocateDeviceData() MOZ_OVERRIDE {}
   1.181 +
   1.182 +  virtual void SetCompositor(Compositor* aCompositor) MOZ_OVERRIDE;
   1.183 +
   1.184 +  virtual gfx::SurfaceFormat GetFormat() const MOZ_OVERRIDE { return mFormat; }
   1.185 +
   1.186 +  virtual bool Lock() MOZ_OVERRIDE;
   1.187 +
   1.188 +  virtual void Unlock() MOZ_OVERRIDE;
   1.189 +
   1.190 +  virtual gfx::IntSize GetSize() const MOZ_OVERRIDE { return mSize; }
   1.191 +
   1.192 +  virtual TemporaryRef<gfx::DataSourceSurface> GetAsSurface() MOZ_OVERRIDE
   1.193 +  {
   1.194 +    return nullptr;
   1.195 +  }
   1.196 +
   1.197 +protected:
   1.198 +  ID3D11Device* GetDevice();
   1.199 +
   1.200 +  RefPtr<DataTextureSourceD3D11> mTextureSource;
   1.201 +  RefPtr<CompositorD3D11> mCompositor;
   1.202 +  gfx::IntSize mSize;
   1.203 +  WindowsHandle mHandle;
   1.204 +  gfx::SurfaceFormat mFormat;
   1.205 +  bool mIsLocked;
   1.206 +};
   1.207 +
   1.208 +class CompositingRenderTargetD3D11 : public CompositingRenderTarget,
   1.209 +                                     public TextureSourceD3D11
   1.210 +{
   1.211 +public:
   1.212 +  CompositingRenderTargetD3D11(ID3D11Texture2D* aTexture,
   1.213 +                               const gfx::IntPoint& aOrigin);
   1.214 +
   1.215 +  virtual TextureSourceD3D11* AsSourceD3D11() MOZ_OVERRIDE { return this; }
   1.216 +
   1.217 +  virtual gfx::IntSize GetSize() const MOZ_OVERRIDE;
   1.218 +
   1.219 +  void SetSize(const gfx::IntSize& aSize) { mSize = aSize; }
   1.220 +
   1.221 +private:
   1.222 +  friend class CompositorD3D11;
   1.223 +
   1.224 +  RefPtr<ID3D11RenderTargetView> mRTView;
   1.225 +};
   1.226 +
   1.227 +inline uint32_t GetMaxTextureSizeForFeatureLevel(D3D_FEATURE_LEVEL aFeatureLevel)
   1.228 +{
   1.229 +  int32_t maxTextureSize;
   1.230 +  switch (aFeatureLevel) {
   1.231 +  case D3D_FEATURE_LEVEL_11_1:
   1.232 +  case D3D_FEATURE_LEVEL_11_0:
   1.233 +    maxTextureSize = D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION;
   1.234 +    break;
   1.235 +  case D3D_FEATURE_LEVEL_10_1:
   1.236 +  case D3D_FEATURE_LEVEL_10_0:
   1.237 +    maxTextureSize = D3D10_REQ_TEXTURE2D_U_OR_V_DIMENSION;
   1.238 +    break;
   1.239 +  case D3D_FEATURE_LEVEL_9_3:
   1.240 +    maxTextureSize = D3D_FL9_3_REQ_TEXTURE2D_U_OR_V_DIMENSION;
   1.241 +    break;
   1.242 +  default:
   1.243 +    maxTextureSize = D3D_FL9_1_REQ_TEXTURE2D_U_OR_V_DIMENSION;
   1.244 +  }
   1.245 +  return maxTextureSize;
   1.246 +}
   1.247 +
   1.248 +}
   1.249 +}
   1.250 +
   1.251 +#endif /* MOZILLA_GFX_TEXTURED3D11_H */

mercurial