Bug 1874684 - Part 28: Return DateDuration from DifferenceISODateTime. r=mgaudet
[gecko.git] / gfx / webrender_bindings / RenderCompositorD3D11SWGL.h
blob2365230f66201552486e322d72e445e74afec3b0
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/. */
7 #ifndef MOZILLA_GFX_RENDERCOMPOSITOR_D3D11_H
8 #define MOZILLA_GFX_RENDERCOMPOSITOR_D3D11_H
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"
16 namespace mozilla {
18 namespace wr {
20 class SurfaceD3D11SWGL;
22 class RenderCompositorD3D11SWGL : public RenderCompositorLayersSWGL {
23 public:
24 static UniquePtr<RenderCompositor> Create(
25 const RefPtr<widget::CompositorWidget>& aWidget, nsACString& aError);
27 RenderCompositorD3D11SWGL(layers::CompositorD3D11* aCompositor,
28 const RefPtr<widget::CompositorWidget>& aWidget,
29 void* aContext);
30 virtual ~RenderCompositorD3D11SWGL();
32 void Pause() override;
33 bool Resume() override;
35 GLenum IsContextLost(bool aForce) override;
37 layers::WebRenderCompositor CompositorType() const override {
38 return layers::WebRenderCompositor::D3D11;
40 RenderCompositorD3D11SWGL* AsRenderCompositorD3D11SWGL() override {
41 return this;
44 bool BeginFrame() override;
46 bool MaybeReadback(const gfx::IntSize& aReadbackSize,
47 const wr::ImageFormat& aReadbackFormat,
48 const Range<uint8_t>& aReadbackBuffer,
49 bool* aNeedsYFlip) override;
51 layers::CompositorD3D11* GetCompositorD3D11() {
52 return mCompositor->AsCompositorD3D11();
55 ID3D11Device* GetDevice() { return GetCompositorD3D11()->GetDevice(); }
57 private:
58 already_AddRefed<ID3D11Texture2D> CreateStagingTexture(
59 const gfx::IntSize aSize);
60 already_AddRefed<gfx::DataSourceSurface> CreateStagingSurface(
61 const gfx::IntSize aSize);
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;
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() {}
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;
84 private:
85 RefPtr<layers::DataTextureSourceD3D11> mTexture;
86 RefPtr<ID3D11Texture2D> mStagingTexture;
87 RefPtr<gfx::DataSourceSurface> mSurface;
88 SurfaceD3D11SWGL* mOwner;
89 RenderCompositorD3D11SWGL* mRenderCompositor;
92 enum UploadMode {
93 Upload_Immediate,
94 Upload_Staging,
95 Upload_StagingNoBlock,
96 Upload_StagingPooled
98 UploadMode GetUploadMode();
99 UploadMode mUploadMode = Upload_Staging;
101 RefPtr<ID3D11Texture2D> mCurrentStagingTexture;
102 bool mCurrentStagingTextureIsTemp = false;
105 class SurfaceD3D11SWGL : public RenderCompositorLayersSWGL::Surface {
106 public:
107 SurfaceD3D11SWGL(wr::DeviceIntSize aTileSize, bool aIsOpaque);
108 virtual ~SurfaceD3D11SWGL() {}
110 SurfaceD3D11SWGL* AsSurfaceD3D11SWGL() override { return this; }
112 nsTArray<RefPtr<ID3D11Texture2D>> mStagingPool;
115 } // namespace wr
116 } // namespace mozilla
118 #endif