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