Bug 1699062 - Flatten toolkit/themes/*/global/alerts/. r=desktop-theme-reviewers,dao
[gecko.git] / gfx / webrender_bindings / RenderCompositorD3D11SWGL.h
blob1fc0a8db34d4bcc9b59aa930b6e40dfb545309ae
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/layers/ScreenshotGrabber.h"
11 #include "mozilla/layers/TextureD3D11.h"
12 #include "mozilla/layers/CompositorD3D11.h"
13 #include "mozilla/webrender/RenderCompositorLayersSWGL.h"
15 namespace mozilla {
17 namespace wr {
19 class SurfaceD3D11SWGL;
21 class RenderCompositorD3D11SWGL : public RenderCompositorLayersSWGL {
22 public:
23 static UniquePtr<RenderCompositor> Create(
24 RefPtr<widget::CompositorWidget>&& aWidget, nsACString& aError);
26 RenderCompositorD3D11SWGL(layers::CompositorD3D11* aCompositor,
27 RefPtr<widget::CompositorWidget>&& aWidget,
28 void* aContext);
29 virtual ~RenderCompositorD3D11SWGL();
31 void Pause() override;
32 bool Resume() override;
34 GLenum IsContextLost(bool aForce) override;
36 layers::WebRenderCompositor CompositorType() const override {
37 return layers::WebRenderCompositor::D3D11;
39 RenderCompositorD3D11SWGL* AsRenderCompositorD3D11SWGL() override {
40 return this;
43 bool BeginFrame() override;
45 bool MaybeReadback(const gfx::IntSize& aReadbackSize,
46 const wr::ImageFormat& aReadbackFormat,
47 const Range<uint8_t>& aReadbackBuffer,
48 bool* aNeedsYFlip) override;
50 layers::CompositorD3D11* GetCompositorD3D11() {
51 return mCompositor->AsCompositorD3D11();
54 ID3D11Device* GetDevice() { return GetCompositorD3D11()->GetDevice(); }
56 private:
57 already_AddRefed<ID3D11Texture2D> CreateStagingTexture(
58 const gfx::IntSize aSize);
59 already_AddRefed<DataSourceSurface> CreateStagingSurface(
60 const gfx::IntSize aSize);
62 void HandleExternalImage(RenderTextureHost* aExternalImage,
63 FrameSurface& aFrameSurface) override;
64 UniquePtr<RenderCompositorLayersSWGL::Surface> DoCreateSurface(
65 wr::DeviceIntSize aTileSize, bool aIsOpaque) override;
66 UniquePtr<RenderCompositorLayersSWGL::Tile> DoCreateTile(
67 Surface* aSurface) override;
69 class TileD3D11 : public RenderCompositorLayersSWGL::Tile {
70 public:
71 TileD3D11(layers::DataTextureSourceD3D11* aTexture,
72 ID3D11Texture2D* aStagingTexture,
73 DataSourceSurface* aDataSourceSurface, Surface* aOwner,
74 RenderCompositorD3D11SWGL* aRenderCompositor);
75 virtual ~TileD3D11() {}
77 bool Map(wr::DeviceIntRect aDirtyRect, wr::DeviceIntRect aValidRect,
78 void** aData, int32_t* aStride) override;
79 void Unmap(const gfx::IntRect& aDirtyRect) override;
80 layers::DataTextureSource* GetTextureSource() override { return mTexture; }
81 bool IsValid() override;
83 private:
84 RefPtr<layers::DataTextureSourceD3D11> mTexture;
85 RefPtr<ID3D11Texture2D> mStagingTexture;
86 RefPtr<DataSourceSurface> mSurface;
87 SurfaceD3D11SWGL* mOwner;
88 RenderCompositorD3D11SWGL* mRenderCompositor;
91 enum UploadMode {
92 Upload_Immediate,
93 Upload_Staging,
94 Upload_StagingNoBlock,
95 Upload_StagingPooled
97 UploadMode GetUploadMode();
98 UploadMode mUploadMode = Upload_Staging;
100 RefPtr<ID3D11Texture2D> mCurrentStagingTexture;
101 bool mCurrentStagingTextureIsTemp = false;
104 class SurfaceD3D11SWGL : public RenderCompositorLayersSWGL::Surface {
105 public:
106 SurfaceD3D11SWGL(wr::DeviceIntSize aTileSize, bool aIsOpaque);
107 virtual ~SurfaceD3D11SWGL() {}
109 SurfaceD3D11SWGL* AsSurfaceD3D11SWGL() override { return this; }
111 nsTArray<RefPtr<ID3D11Texture2D>> mStagingPool;
114 } // namespace wr
115 } // namespace mozilla
117 #endif