-
Notifications
You must be signed in to change notification settings - Fork 54
/
RenderCompositorOGL.h
137 lines (109 loc) · 4.38 KB
/
RenderCompositorOGL.h
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/* -*- 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_OGL_H
#define MOZILLA_GFX_RENDERCOMPOSITOR_OGL_H
#include "GLTypes.h"
#include "mozilla/webrender/RenderCompositor.h"
#include "mozilla/TimeStamp.h"
namespace mozilla {
namespace layers {
class NativeLayerRootSnapshotter;
class NativeLayerRoot;
class NativeLayer;
class SurfacePoolHandle;
} // namespace layers
namespace wr {
class RenderCompositorOGL : public RenderCompositor {
public:
static UniquePtr<RenderCompositor> Create(
RefPtr<widget::CompositorWidget>&& aWidget);
RenderCompositorOGL(RefPtr<gl::GLContext>&& aGL,
RefPtr<widget::CompositorWidget>&& aWidget);
virtual ~RenderCompositorOGL();
bool BeginFrame() override;
RenderedFrameId EndFrame(const nsTArray<DeviceIntRect>& aDirtyRects) final;
bool WaitForGPU() override;
void Pause() override;
bool Resume() override;
gl::GLContext* gl() const override { return mGL; }
bool UseANGLE() const override { return false; }
LayoutDeviceIntSize GetBufferSize() override;
bool ShouldUseNativeCompositor() override;
uint32_t GetMaxUpdateRects() override;
// Does the readback for the ShouldUseNativeCompositor() case.
bool MaybeReadback(const gfx::IntSize& aReadbackSize,
const wr::ImageFormat& aReadbackFormat,
const Range<uint8_t>& aReadbackBuffer) override;
// Interface for wr::Compositor
void CompositorBeginFrame() override;
void CompositorEndFrame() override;
void Bind(wr::NativeTileId aId, wr::DeviceIntPoint* aOffset, uint32_t* aFboId,
wr::DeviceIntRect aDirtyRect,
wr::DeviceIntRect aValidRect) override;
void Unbind() override;
void CreateSurface(wr::NativeSurfaceId aId, wr::DeviceIntPoint aVirtualOffset,
wr::DeviceIntSize aTileSize, bool aIsOpaque) override;
void DestroySurface(NativeSurfaceId aId) override;
void CreateTile(wr::NativeSurfaceId aId, int32_t aX, int32_t aY) override;
void DestroyTile(wr::NativeSurfaceId aId, int32_t aX, int32_t aY) override;
void AddSurface(wr::NativeSurfaceId aId, wr::DeviceIntPoint aPosition,
wr::DeviceIntRect aClipRect) override;
CompositorCapabilities GetCompositorCapabilities() override;
struct TileKey {
TileKey(int32_t aX, int32_t aY) : mX(aX), mY(aY) {}
int32_t mX;
int32_t mY;
};
protected:
void InsertFrameDoneSync();
RefPtr<gl::GLContext> mGL;
// Can be null.
RefPtr<layers::NativeLayerRoot> mNativeLayerRoot;
UniquePtr<layers::NativeLayerRootSnapshotter> mNativeLayerRootSnapshotter;
RefPtr<layers::NativeLayer> mNativeLayerForEntireWindow;
RefPtr<layers::SurfacePoolHandle> mSurfacePoolHandle;
struct TileKeyHashFn {
std::size_t operator()(const TileKey& aId) const {
return HashGeneric(aId.mX, aId.mY);
}
};
struct Surface {
explicit Surface(wr::DeviceIntSize aTileSize, bool aIsOpaque)
: mTileSize(aTileSize), mIsOpaque(aIsOpaque) {}
gfx::IntSize TileSize() {
return gfx::IntSize(mTileSize.width, mTileSize.height);
}
wr::DeviceIntSize mTileSize;
bool mIsOpaque;
std::unordered_map<TileKey, RefPtr<layers::NativeLayer>, TileKeyHashFn>
mNativeLayers;
};
struct SurfaceIdHashFn {
std::size_t operator()(const wr::NativeSurfaceId& aId) const {
return HashGeneric(wr::AsUint64(aId));
}
};
// Used in native compositor mode:
RefPtr<layers::NativeLayer> mCurrentlyBoundNativeLayer;
nsTArray<RefPtr<layers::NativeLayer>> mAddedLayers;
uint64_t mTotalPixelCount = 0;
uint64_t mAddedPixelCount = 0;
uint64_t mAddedClippedPixelCount = 0;
uint64_t mDrawnPixelCount = 0;
gfx::IntRect mVisibleBounds;
std::unordered_map<wr::NativeSurfaceId, Surface, SurfaceIdHashFn> mSurfaces;
TimeStamp mBeginFrameTimeStamp;
// Used to apply back-pressure in WaitForGPU().
GLsync mPreviousFrameDoneSync;
GLsync mThisFrameDoneSync;
};
static inline bool operator==(const RenderCompositorOGL::TileKey& a0,
const RenderCompositorOGL::TileKey& a1) {
return a0.mX == a1.mX && a0.mY == a1.mY;
}
} // namespace wr
} // namespace mozilla
#endif