Backed out 3 changesets (bug 1591523) for bustages complaining about RenderCompositorOGL.cpp CLOSED TREE

Backed out changeset 407f051e14db (bug 1591523)
Backed out changeset b4c8080dae86 (bug 1591523)
Backed out changeset abb627bc4f75 (bug 1591523)
This commit is contained in:
Bogdan Tara 2019-10-29 22:00:05 +02:00
Родитель 9585925ff5
Коммит f866fef3ad
12 изменённых файлов: 43 добавлений и 188 удалений

Просмотреть файл

@ -36,7 +36,6 @@ class NativeLayerRoot {
virtual already_AddRefed<NativeLayer> CreateLayer() = 0;
virtual void AppendLayer(NativeLayer* aLayer) = 0;
virtual void RemoveLayer(NativeLayer* aLayer) = 0;
virtual void SetLayers(const nsTArray<RefPtr<NativeLayer>>& aLayers) = 0;
protected:
virtual ~NativeLayerRoot() {}

Просмотреть файл

@ -66,7 +66,6 @@ class NativeLayerRootCA : public NativeLayerRoot {
already_AddRefed<NativeLayer> CreateLayer() override;
void AppendLayer(NativeLayer* aLayer) override;
void RemoveLayer(NativeLayer* aLayer) override;
void SetLayers(const nsTArray<RefPtr<NativeLayer>>& aLayers) override;
protected:
explicit NativeLayerRootCA(CALayer* aLayer);

Просмотреть файл

@ -80,29 +80,6 @@ void NativeLayerRootCA::RemoveLayer(NativeLayer* aLayer) {
mMutated = true;
}
void NativeLayerRootCA::SetLayers(const nsTArray<RefPtr<NativeLayer>>& aLayers) {
MutexAutoLock lock(mMutex);
// Ideally, we'd just be able to do mSublayers = std::move(aLayers).
// However, aLayers has a different type: it carries NativeLayer objects, whereas mSublayers
// carries NativeLayerCA objects, so we have to downcast all the elements first. There's one other
// reason to look at all the elements in aLayers first: We need to make sure any new layers know
// about our current backing scale.
nsTArray<RefPtr<NativeLayerCA>> layersCA(aLayers.Length());
for (auto& layer : aLayers) {
RefPtr<NativeLayerCA> layerCA = layer->AsNativeLayerCA();
MOZ_RELEASE_ASSERT(layerCA);
layerCA->SetBackingScale(mBackingScale);
layersCA.AppendElement(std::move(layerCA));
}
if (layersCA != mSublayers) {
mSublayers = std::move(layersCA);
mMutated = true;
}
}
// Must be called within a current CATransaction on the transaction's thread.
void NativeLayerRootCA::ApplyChanges() {
MutexAutoLock lock(mMutex);

Просмотреть файл

@ -19,6 +19,7 @@ class GLContext;
}
namespace layers {
class NativeLayer;
class SyncObjectHost;
} // namespace layers
@ -36,7 +37,7 @@ class RenderCompositor {
RenderCompositor(RefPtr<widget::CompositorWidget>&& aWidget);
virtual ~RenderCompositor();
virtual bool BeginFrame() = 0;
virtual bool BeginFrame(layers::NativeLayer* aNativeLayer) = 0;
virtual void EndFrame() = 0;
// Returns false when waiting gpu tasks is failed.
// It might happen when rendering context is lost.

Просмотреть файл

@ -349,7 +349,8 @@ RefPtr<IDXGISwapChain1> RenderCompositorANGLE::CreateSwapChainForDComp(
return nullptr;
}
bool RenderCompositorANGLE::BeginFrame() {
bool RenderCompositorANGLE::BeginFrame(layers::NativeLayer* aNativeLayer) {
MOZ_RELEASE_ASSERT(!aNativeLayer, "Unexpected native layer on this platform");
mWidget->AsWindows()->UpdateCompositorWndSizeIfNecessary();
if (mDCLayerTree) {

Просмотреть файл

@ -39,7 +39,7 @@ class RenderCompositorANGLE : public RenderCompositor {
virtual ~RenderCompositorANGLE();
bool Initialize();
bool BeginFrame() override;
bool BeginFrame(layers::NativeLayer* aNativeLayer) override;
void EndFrame() override;
bool WaitForGPU() override;
void Pause() override;

Просмотреть файл

@ -63,7 +63,8 @@ RenderCompositorEGL::~RenderCompositorEGL() {
DestroyEGLSurface();
}
bool RenderCompositorEGL::BeginFrame() {
bool RenderCompositorEGL::BeginFrame(layers::NativeLayer* aNativeLayer) {
MOZ_RELEASE_ASSERT(!aNativeLayer, "Unexpected native layer on this platform");
#ifdef MOZ_WAYLAND
bool newSurface =
mWidget->AsX11() && mWidget->AsX11()->WaylandRequestsUpdatingEGLSurface();

Просмотреть файл

@ -22,7 +22,7 @@ class RenderCompositorEGL : public RenderCompositor {
explicit RenderCompositorEGL(RefPtr<widget::CompositorWidget> aWidget);
virtual ~RenderCompositorEGL();
bool BeginFrame() override;
bool BeginFrame(layers::NativeLayer* aNativeLayer) override;
void EndFrame() override;
void Pause() override;
bool Resume() override;

Просмотреть файл

@ -32,26 +32,12 @@ RenderCompositorOGL::RenderCompositorOGL(
RefPtr<gl::GLContext>&& aGL, RefPtr<widget::CompositorWidget>&& aWidget)
: RenderCompositor(std::move(aWidget)),
mGL(aGL),
mNativeLayerRoot(GetWidget()->GetNativeLayerRoot()),
mPreviousFrameDoneSync(nullptr),
mThisFrameDoneSync(nullptr) {
MOZ_ASSERT(mGL);
if (mNativeLayerRoot && !ShouldUseNativeCompositor()) {
mNativeLayerForEntireWindow = mNativeLayerRoot->CreateLayer();
mNativeLayerForEntireWindow->SetSurfaceIsFlipped(true);
mNativeLayerForEntireWindow->SetGLContext(mGL);
mNativeLayerRoot->AppendLayer(mNativeLayerForEntireWindow);
}
}
RenderCompositorOGL::~RenderCompositorOGL() {
if (mNativeLayerRoot) {
mNativeLayerRoot->SetLayers({});
mNativeLayerForEntireWindow = nullptr;
mNativeLayerRoot = nullptr;
}
if (!mGL->MakeCurrent()) {
gfxCriticalNote
<< "Failed to make render context current during destroying.";
@ -69,21 +55,21 @@ RenderCompositorOGL::~RenderCompositorOGL() {
}
}
bool RenderCompositorOGL::BeginFrame() {
bool RenderCompositorOGL::BeginFrame(layers::NativeLayer* aNativeLayer) {
if (!mGL->MakeCurrent()) {
gfxCriticalNote << "Failed to make render context current, can't draw.";
return false;
}
if (mNativeLayerForEntireWindow) {
gfx::IntRect bounds({}, GetBufferSize().ToUnknownSize());
mNativeLayerForEntireWindow->SetRect(bounds);
Maybe<GLuint> fbo =
mNativeLayerForEntireWindow->NextSurfaceAsFramebuffer(true);
if (aNativeLayer) {
aNativeLayer->SetSurfaceIsFlipped(true);
aNativeLayer->SetGLContext(mGL);
Maybe<GLuint> fbo = aNativeLayer->NextSurfaceAsFramebuffer(true);
if (!fbo) {
return false;
}
mGL->fBindFramebuffer(LOCAL_GL_FRAMEBUFFER, *fbo);
mCurrentNativeLayer = aNativeLayer;
} else {
mGL->fBindFramebuffer(LOCAL_GL_FRAMEBUFFER, mGL->GetDefaultFramebuffer());
}
@ -95,8 +81,9 @@ void RenderCompositorOGL::EndFrame() {
InsertFrameDoneSync();
mGL->SwapBuffers();
if (mNativeLayerForEntireWindow) {
mNativeLayerForEntireWindow->NotifySurfaceReady();
if (mCurrentNativeLayer) {
mCurrentNativeLayer->NotifySurfaceReady();
mCurrentNativeLayer = nullptr;
}
}
@ -136,109 +123,5 @@ LayoutDeviceIntSize RenderCompositorOGL::GetBufferSize() {
return mWidget->GetClientSize();
}
bool RenderCompositorOGL::ShouldUseNativeCompositor() {
return mNativeLayerRoot && StaticPrefs::gfx_webrender_compositor_AtStartup();
}
void RenderCompositorOGL::CompositorBeginFrame() {
mAddedLayers.Clear();
mAddedPixelCount = 0;
mAddedClippedPixelCount = 0;
}
void RenderCompositorOGL::CompositorEndFrame() {
auto bufferSize = GetBufferSize();
uint64_t windowPixelCount = uint64_t(bufferSize.width) * bufferSize.height;
printf(
"CompositorEndFrame with %d layers (%d used / %d unused), in-use memory: "
"%d%%, overdraw: %d%%, painting: %d%%\n",
int(mNativeLayers.size()), int(mAddedLayers.Length()),
int(mNativeLayers.size() - mAddedLayers.Length()),
int(mAddedPixelCount * 100 / windowPixelCount),
int(mAddedClippedPixelCount * 100 / windowPixelCount),
int(mDrawnPixelCount * 100 / windowPixelCount));
mDrawnPixelCount = 0;
mNativeLayerRoot->SetLayers(mAddedLayers);
}
void RenderCompositorOGL::Bind(wr::NativeSurfaceId aId,
wr::DeviceIntPoint* aOffset, uint32_t* aFboId,
wr::DeviceIntRect aDirtyRect) {
MOZ_RELEASE_ASSERT(!mCurrentlyBoundNativeLayer);
auto layerCursor = mNativeLayers.find(wr::AsUint64(aId));
MOZ_RELEASE_ASSERT(layerCursor != mNativeLayers.end());
RefPtr<layers::NativeLayer> layer = layerCursor->second;
gfx::IntRect layerRect = layer->GetRect();
gfx::IntRect dirtyRect(aDirtyRect.origin.x, aDirtyRect.origin.y,
aDirtyRect.size.width, aDirtyRect.size.height);
MOZ_RELEASE_ASSERT(
dirtyRect.IsEqualInterior(layerRect - layerRect.TopLeft()),
"We currently do not support partial updates (max_update_rects is set to "
"0), so we expect the dirty rect to always cover the entire layer.");
Maybe<GLuint> fbo = layer->NextSurfaceAsFramebuffer(true);
MOZ_RELEASE_ASSERT(fbo); // TODO: make fallible
mCurrentlyBoundNativeLayer = layer;
*aFboId = *fbo;
*aOffset = wr::DeviceIntPoint{0, 0};
mDrawnPixelCount += layerRect.Area();
}
void RenderCompositorOGL::Unbind() {
MOZ_RELEASE_ASSERT(mCurrentlyBoundNativeLayer);
mGL->fBindFramebuffer(LOCAL_GL_FRAMEBUFFER, 0);
mCurrentlyBoundNativeLayer->NotifySurfaceReady();
mCurrentlyBoundNativeLayer = nullptr;
}
void RenderCompositorOGL::CreateSurface(wr::NativeSurfaceId aId,
wr::DeviceIntSize aSize) {
RefPtr<layers::NativeLayer> layer = mNativeLayerRoot->CreateLayer();
layer->SetRect(gfx::IntRect(0, 0, aSize.width, aSize.height));
layer->SetGLContext(mGL);
mNativeLayers.insert({wr::AsUint64(aId), layer});
}
void RenderCompositorOGL::DestroySurface(NativeSurfaceId aId) {
auto layerCursor = mNativeLayers.find(wr::AsUint64(aId));
if (layerCursor == mNativeLayers.end()) {
printf("deleting non-existent layer %llu\n", wr::AsUint64(aId));
return;
}
MOZ_RELEASE_ASSERT(layerCursor != mNativeLayers.end());
RefPtr<layers::NativeLayer> layer = layerCursor->second;
mNativeLayers.erase(layerCursor);
// If the layer is currently present in mNativeLayerRoot, it will be destroyed
// once CompositorEndFrame() replaces mNativeLayerRoot's layers and drops that
// reference.
}
void RenderCompositorOGL::AddSurface(wr::NativeSurfaceId aId,
wr::DeviceIntPoint aPosition,
wr::DeviceIntRect aClipRect) {
MOZ_RELEASE_ASSERT(!mCurrentlyBoundNativeLayer);
auto layerCursor = mNativeLayers.find(wr::AsUint64(aId));
MOZ_RELEASE_ASSERT(layerCursor != mNativeLayers.end());
RefPtr<layers::NativeLayer> layer = layerCursor->second;
gfx::IntSize layerSize = layer->GetRect().Size();
gfx::IntRect layerRect(aPosition.x, aPosition.y, layerSize.width,
layerSize.height);
gfx::IntRect clipRect(aClipRect.origin.x, aClipRect.origin.y,
aClipRect.size.width, aClipRect.size.height);
layer->SetRect(layerRect);
layer->SetClipRect(Some(clipRect));
mAddedLayers.AppendElement(layer);
mAddedPixelCount += layerRect.Area();
mAddedClippedPixelCount += clipRect.Intersect(layerRect).Area();
}
} // namespace wr
} // namespace mozilla

Просмотреть файл

@ -11,11 +11,6 @@
namespace mozilla {
namespace layers {
class NativeLayerRoot;
class NativeLayer;
} // namespace layers
namespace wr {
class RenderCompositorOGL : public RenderCompositor {
@ -27,7 +22,7 @@ class RenderCompositorOGL : public RenderCompositor {
RefPtr<widget::CompositorWidget>&& aWidget);
virtual ~RenderCompositorOGL();
bool BeginFrame() override;
bool BeginFrame(layers::NativeLayer* aNativeLayer) override;
void EndFrame() override;
bool WaitForGPU() override;
void Pause() override;
@ -39,36 +34,15 @@ class RenderCompositorOGL : public RenderCompositor {
LayoutDeviceIntSize GetBufferSize() override;
bool ShouldUseNativeCompositor() override;
// Interface for wr::Compositor
void CompositorBeginFrame() override;
void CompositorEndFrame() override;
void Bind(wr::NativeSurfaceId aId, wr::DeviceIntPoint* aOffset,
uint32_t* aFboId, wr::DeviceIntRect aDirtyRect) override;
void Unbind() override;
void CreateSurface(wr::NativeSurfaceId aId, wr::DeviceIntSize aSize) override;
void DestroySurface(NativeSurfaceId aId) override;
void AddSurface(wr::NativeSurfaceId aId, wr::DeviceIntPoint aPosition,
wr::DeviceIntRect aClipRect) override;
protected:
void InsertFrameDoneSync();
RefPtr<gl::GLContext> mGL;
// Can be null.
RefPtr<layers::NativeLayerRoot> mNativeLayerRoot;
RefPtr<layers::NativeLayer> mNativeLayerForEntireWindow;
// Used in native compositor mode:
RefPtr<layers::NativeLayer> mCurrentlyBoundNativeLayer;
nsTArray<RefPtr<layers::NativeLayer>> mAddedLayers;
uint64_t mAddedPixelCount = 0;
uint64_t mAddedClippedPixelCount = 0;
uint64_t mDrawnPixelCount = 0;
gfx::IntRect mVisibleBounds;
std::unordered_map<uint64_t, RefPtr<layers::NativeLayer>> mNativeLayers;
// The native layer that we're currently rendering to, if any.
// Non-null only between BeginFrame and EndFrame if BeginFrame has been called
// with a non-null aNativeLayer.
RefPtr<layers::NativeLayer> mCurrentNativeLayer;
// Used to apply back-pressure in WaitForGPU().
GLsync mPreviousFrameDoneSync;

Просмотреть файл

@ -58,6 +58,12 @@ RendererOGL::RendererOGL(RefPtr<RenderThread>&& aThread,
MOZ_ASSERT(mRenderer);
MOZ_ASSERT(mBridge);
MOZ_COUNT_CTOR(RendererOGL);
mNativeLayerRoot = mCompositor->GetWidget()->GetNativeLayerRoot();
if (mNativeLayerRoot) {
mNativeLayerForEntireWindow = mNativeLayerRoot->CreateLayer();
mNativeLayerRoot->AppendLayer(mNativeLayerForEntireWindow);
}
}
RendererOGL::~RendererOGL() {
@ -68,6 +74,11 @@ RendererOGL::~RendererOGL() {
// Leak resources!
return;
}
if (mNativeLayerRoot) {
mNativeLayerRoot->RemoveLayer(mNativeLayerForEntireWindow);
mNativeLayerForEntireWindow = nullptr;
mNativeLayerRoot = nullptr;
}
wr_renderer_delete(mRenderer);
}
@ -109,7 +120,12 @@ bool RendererOGL::UpdateAndRender(const Maybe<gfx::IntSize>& aReadbackSize,
}
// XXX set clear color if MOZ_WIDGET_ANDROID is defined.
if (!mCompositor->BeginFrame()) {
if (mNativeLayerForEntireWindow) {
gfx::IntRect bounds({}, mCompositor->GetBufferSize().ToUnknownSize());
mNativeLayerForEntireWindow->SetRect(bounds);
}
if (!mCompositor->BeginFrame(mNativeLayerForEntireWindow)) {
if (mCompositor->IsContextLost()) {
RenderThread::Get()->HandleDeviceReset("BeginFrame", /* aNotify */ true);
}

Просмотреть файл

@ -26,6 +26,8 @@ class GLContext;
namespace layers {
class CompositorBridgeParent;
class NativeLayerRoot;
class NativeLayer;
class SyncObjectHost;
} // namespace layers
@ -106,6 +108,8 @@ class RendererOGL {
protected:
RefPtr<RenderThread> mThread;
UniquePtr<RenderCompositor> mCompositor;
RefPtr<layers::NativeLayerRoot> mNativeLayerRoot;
RefPtr<layers::NativeLayer> mNativeLayerForEntireWindow;
wr::Renderer* mRenderer;
layers::CompositorBridgeParent* mBridge;
wr::WindowId mWindowId;