gfx/layers/d3d11/TextureD3D11.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
     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_TEXTURED3D11_H
     7 #define MOZILLA_GFX_TEXTURED3D11_H
     9 #include "mozilla/layers/Compositor.h"
    10 #include "mozilla/layers/TextureClient.h"
    11 #include "mozilla/layers/TextureHost.h"
    12 #include "gfxWindowsPlatform.h"
    13 #include "mozilla/GfxMessageUtils.h"
    14 #include <d3d11.h>
    15 #include <vector>
    17 class gfxD2DSurface;
    19 namespace mozilla {
    20 namespace layers {
    22 class CompositorD3D11;
    24 /**
    25  * A TextureClient to share a D3D10 texture with the compositor thread.
    26  * The corresponding TextureHost is DXGITextureHostD3D11
    27  */
    28 class TextureClientD3D11 : public TextureClient
    29 {
    30 public:
    31   TextureClientD3D11(gfx::SurfaceFormat aFormat, TextureFlags aFlags);
    33   virtual ~TextureClientD3D11();
    35   // TextureClient
    37   virtual bool IsAllocated() const MOZ_OVERRIDE { return !!mTexture; }
    39   virtual bool Lock(OpenMode aOpenMode) MOZ_OVERRIDE;
    41   virtual void Unlock() MOZ_OVERRIDE;
    43   virtual bool IsLocked() const MOZ_OVERRIDE { return mIsLocked; }
    45   virtual bool ImplementsLocking() const MOZ_OVERRIDE { return true; }
    47   virtual bool HasInternalBuffer() const MOZ_OVERRIDE { return false; }
    49   virtual bool ToSurfaceDescriptor(SurfaceDescriptor& aOutDescriptor) MOZ_OVERRIDE;
    51   virtual gfx::IntSize GetSize() const MOZ_OVERRIDE { return mSize; }
    53   virtual TextureClientData* DropTextureData() MOZ_OVERRIDE { return nullptr; }
    55   virtual gfx::SurfaceFormat GetFormat() const MOZ_OVERRIDE { return mFormat; }
    57   virtual bool CanExposeDrawTarget() const MOZ_OVERRIDE { return true; }
    59   virtual TemporaryRef<gfx::DrawTarget> GetAsDrawTarget() MOZ_OVERRIDE;
    61   virtual bool AllocateForSurface(gfx::IntSize aSize,
    62                                   TextureAllocationFlags aFlags = ALLOC_DEFAULT) MOZ_OVERRIDE;
    64 protected:
    65   gfx::IntSize mSize;
    66   RefPtr<ID3D10Texture2D> mTexture;
    67   RefPtr<gfx::DrawTarget> mDrawTarget;
    68   gfx::SurfaceFormat mFormat;
    69   bool mIsLocked;
    70   bool mNeedsClear;
    71 };
    73 /**
    74  * TextureSource that provides with the necessary APIs to be composited by a
    75  * CompositorD3D11.
    76  */
    77 class TextureSourceD3D11
    78 {
    79 public:
    80   TextureSourceD3D11() {}
    81   virtual ~TextureSourceD3D11() {}
    83   virtual ID3D11Texture2D* GetD3D11Texture() const { return mTexture; }
    85 protected:
    86   virtual gfx::IntSize GetSize() const { return mSize; }
    88   gfx::IntSize mSize;
    89   RefPtr<ID3D11Texture2D> mTexture;
    90 };
    92 /**
    93  * A TextureSource that implements the DataTextureSource interface.
    94  * it can be used without a TextureHost and is able to upload texture data
    95  * from a gfx::DataSourceSurface.
    96  */
    97 class DataTextureSourceD3D11 : public DataTextureSource
    98                              , public TextureSourceD3D11
    99                              , public TileIterator
   100 {
   101 public:
   102   DataTextureSourceD3D11(gfx::SurfaceFormat aFormat, CompositorD3D11* aCompositor,
   103                          TextureFlags aFlags);
   105   DataTextureSourceD3D11(gfx::SurfaceFormat aFormat, CompositorD3D11* aCompositor,
   106                          ID3D11Texture2D* aTexture);
   108   virtual ~DataTextureSourceD3D11();
   111   // DataTextureSource
   113   virtual bool Update(gfx::DataSourceSurface* aSurface,
   114                       nsIntRegion* aDestRegion = nullptr,
   115                       gfx::IntPoint* aSrcOffset = nullptr) MOZ_OVERRIDE;
   117   // TextureSource
   119   virtual TextureSourceD3D11* AsSourceD3D11() MOZ_OVERRIDE { return this; }
   121   virtual ID3D11Texture2D* GetD3D11Texture() const MOZ_OVERRIDE;
   123   virtual DataTextureSource* AsDataTextureSource() MOZ_OVERRIDE { return this; }
   125   virtual void DeallocateDeviceData() MOZ_OVERRIDE { mTexture = nullptr; }
   127   virtual gfx::IntSize GetSize() const  MOZ_OVERRIDE { return mSize; }
   129   virtual gfx::SurfaceFormat GetFormat() const MOZ_OVERRIDE { return mFormat; }
   131   virtual void SetCompositor(Compositor* aCompositor) MOZ_OVERRIDE;
   133   // TileIterator
   135   virtual TileIterator* AsTileIterator() MOZ_OVERRIDE { return mIsTiled ? this : nullptr; }
   137   virtual size_t GetTileCount() MOZ_OVERRIDE { return mTileTextures.size(); }
   139   virtual bool NextTile() MOZ_OVERRIDE { return (++mCurrentTile < mTileTextures.size()); }
   141   virtual nsIntRect GetTileRect() MOZ_OVERRIDE;
   143   virtual void EndTileIteration() MOZ_OVERRIDE { mIterating = false; }
   145   virtual void BeginTileIteration() MOZ_OVERRIDE
   146   {
   147     mIterating = true;
   148     mCurrentTile = 0;
   149   }
   151 protected:
   152   gfx::IntRect GetTileRect(uint32_t aIndex) const;
   154   void Reset();
   156   std::vector< RefPtr<ID3D11Texture2D> > mTileTextures;
   157   RefPtr<CompositorD3D11> mCompositor;
   158   gfx::SurfaceFormat mFormat;
   159   TextureFlags mFlags;
   160   uint32_t mCurrentTile;
   161   bool mIsTiled;
   162   bool mIterating;
   164 };
   166 /**
   167  * A TextureHost for shared D3D11 textures.
   168  */
   169 class DXGITextureHostD3D11 : public TextureHost
   170 {
   171 public:
   172   DXGITextureHostD3D11(TextureFlags aFlags,
   173                        const SurfaceDescriptorD3D10& aDescriptor);
   175   virtual NewTextureSource* GetTextureSources() MOZ_OVERRIDE;
   177   virtual void DeallocateDeviceData() MOZ_OVERRIDE {}
   179   virtual void SetCompositor(Compositor* aCompositor) MOZ_OVERRIDE;
   181   virtual gfx::SurfaceFormat GetFormat() const MOZ_OVERRIDE { return mFormat; }
   183   virtual bool Lock() MOZ_OVERRIDE;
   185   virtual void Unlock() MOZ_OVERRIDE;
   187   virtual gfx::IntSize GetSize() const MOZ_OVERRIDE { return mSize; }
   189   virtual TemporaryRef<gfx::DataSourceSurface> GetAsSurface() MOZ_OVERRIDE
   190   {
   191     return nullptr;
   192   }
   194 protected:
   195   ID3D11Device* GetDevice();
   197   RefPtr<DataTextureSourceD3D11> mTextureSource;
   198   RefPtr<CompositorD3D11> mCompositor;
   199   gfx::IntSize mSize;
   200   WindowsHandle mHandle;
   201   gfx::SurfaceFormat mFormat;
   202   bool mIsLocked;
   203 };
   205 class CompositingRenderTargetD3D11 : public CompositingRenderTarget,
   206                                      public TextureSourceD3D11
   207 {
   208 public:
   209   CompositingRenderTargetD3D11(ID3D11Texture2D* aTexture,
   210                                const gfx::IntPoint& aOrigin);
   212   virtual TextureSourceD3D11* AsSourceD3D11() MOZ_OVERRIDE { return this; }
   214   virtual gfx::IntSize GetSize() const MOZ_OVERRIDE;
   216   void SetSize(const gfx::IntSize& aSize) { mSize = aSize; }
   218 private:
   219   friend class CompositorD3D11;
   221   RefPtr<ID3D11RenderTargetView> mRTView;
   222 };
   224 inline uint32_t GetMaxTextureSizeForFeatureLevel(D3D_FEATURE_LEVEL aFeatureLevel)
   225 {
   226   int32_t maxTextureSize;
   227   switch (aFeatureLevel) {
   228   case D3D_FEATURE_LEVEL_11_1:
   229   case D3D_FEATURE_LEVEL_11_0:
   230     maxTextureSize = D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION;
   231     break;
   232   case D3D_FEATURE_LEVEL_10_1:
   233   case D3D_FEATURE_LEVEL_10_0:
   234     maxTextureSize = D3D10_REQ_TEXTURE2D_U_OR_V_DIMENSION;
   235     break;
   236   case D3D_FEATURE_LEVEL_9_3:
   237     maxTextureSize = D3D_FL9_3_REQ_TEXTURE2D_U_OR_V_DIMENSION;
   238     break;
   239   default:
   240     maxTextureSize = D3D_FL9_1_REQ_TEXTURE2D_U_OR_V_DIMENSION;
   241   }
   242   return maxTextureSize;
   243 }
   245 }
   246 }
   248 #endif /* MOZILLA_GFX_TEXTURED3D11_H */

mercurial