RenderCompositorD3D11SWGL.h (3956B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef MOZILLA_GFX_RENDERCOMPOSITOR_D3D11_H 8 #define MOZILLA_GFX_RENDERCOMPOSITOR_D3D11_H 9 10 #include "mozilla/gfx/2D.h" 11 #include "mozilla/layers/ScreenshotGrabber.h" 12 #include "mozilla/layers/TextureD3D11.h" 13 #include "mozilla/layers/CompositorD3D11.h" 14 #include "mozilla/webrender/RenderCompositorLayersSWGL.h" 15 16 namespace mozilla { 17 18 namespace wr { 19 20 class SurfaceD3D11SWGL; 21 22 class RenderCompositorD3D11SWGL : public RenderCompositorLayersSWGL { 23 public: 24 static UniquePtr<RenderCompositor> Create( 25 const RefPtr<widget::CompositorWidget>& aWidget, nsACString& aError); 26 27 RenderCompositorD3D11SWGL(layers::CompositorD3D11* aCompositor, 28 const RefPtr<widget::CompositorWidget>& aWidget, 29 void* aContext); 30 virtual ~RenderCompositorD3D11SWGL(); 31 32 void Pause() override; 33 bool Resume() override; 34 35 gfx::DeviceResetReason IsContextLost(bool aForce) override; 36 37 layers::WebRenderCompositor CompositorType() const override { 38 return layers::WebRenderCompositor::D3D11; 39 } 40 RenderCompositorD3D11SWGL* AsRenderCompositorD3D11SWGL() override { 41 return this; 42 } 43 44 bool BeginFrame() override; 45 46 bool MaybeReadback(const gfx::IntSize& aReadbackSize, 47 const wr::ImageFormat& aReadbackFormat, 48 const Range<uint8_t>& aReadbackBuffer, 49 bool* aNeedsYFlip) override; 50 51 layers::CompositorD3D11* GetCompositorD3D11() { 52 return mCompositor->AsCompositorD3D11(); 53 } 54 55 ID3D11Device* GetDevice() { return GetCompositorD3D11()->GetDevice(); } 56 57 private: 58 already_AddRefed<ID3D11Texture2D> CreateStagingTexture( 59 const gfx::IntSize aSize); 60 already_AddRefed<gfx::DataSourceSurface> CreateStagingSurface( 61 const gfx::IntSize aSize); 62 63 void HandleExternalImage(RenderTextureHost* aExternalImage, 64 FrameSurface& aFrameSurface) override; 65 UniquePtr<RenderCompositorLayersSWGL::Surface> DoCreateSurface( 66 wr::DeviceIntSize aTileSize, bool aIsOpaque) override; 67 UniquePtr<RenderCompositorLayersSWGL::Tile> DoCreateTile( 68 Surface* aSurface) override; 69 70 class TileD3D11 : public RenderCompositorLayersSWGL::Tile { 71 public: 72 TileD3D11(layers::DataTextureSourceD3D11* aTexture, 73 ID3D11Texture2D* aStagingTexture, 74 gfx::DataSourceSurface* aDataSourceSurface, Surface* aOwner, 75 RenderCompositorD3D11SWGL* aRenderCompositor); 76 virtual ~TileD3D11() {} 77 78 bool Map(wr::DeviceIntRect aDirtyRect, wr::DeviceIntRect aValidRect, 79 void** aData, int32_t* aStride) override; 80 void Unmap(const gfx::IntRect& aDirtyRect) override; 81 layers::DataTextureSource* GetTextureSource() override { return mTexture; } 82 bool IsValid() override; 83 84 private: 85 RefPtr<layers::DataTextureSourceD3D11> mTexture; 86 RefPtr<ID3D11Texture2D> mStagingTexture; 87 RefPtr<gfx::DataSourceSurface> mSurface; 88 SurfaceD3D11SWGL* mOwner; 89 RenderCompositorD3D11SWGL* mRenderCompositor; 90 }; 91 92 enum UploadMode { 93 Upload_Immediate, 94 Upload_Staging, 95 Upload_StagingNoBlock, 96 Upload_StagingPooled 97 }; 98 UploadMode GetUploadMode(); 99 UploadMode mUploadMode = Upload_Staging; 100 101 RefPtr<ID3D11Texture2D> mCurrentStagingTexture; 102 bool mCurrentStagingTextureIsTemp = false; 103 }; 104 105 class SurfaceD3D11SWGL : public RenderCompositorLayersSWGL::Surface { 106 public: 107 SurfaceD3D11SWGL(wr::DeviceIntSize aTileSize, bool aIsOpaque); 108 virtual ~SurfaceD3D11SWGL() {} 109 110 SurfaceD3D11SWGL* AsSurfaceD3D11SWGL() override { return this; } 111 112 nsTArray<RefPtr<ID3D11Texture2D>> mStagingPool; 113 }; 114 115 } // namespace wr 116 } // namespace mozilla 117 118 #endif