diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /gfx/webrender_bindings/RenderCompositorOGL.cpp | |
parent | Initial commit. (diff) | |
download | firefox-upstream.tar.xz firefox-upstream.zip |
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'gfx/webrender_bindings/RenderCompositorOGL.cpp')
-rw-r--r-- | gfx/webrender_bindings/RenderCompositorOGL.cpp | 131 |
1 files changed, 131 insertions, 0 deletions
diff --git a/gfx/webrender_bindings/RenderCompositorOGL.cpp b/gfx/webrender_bindings/RenderCompositorOGL.cpp new file mode 100644 index 0000000000..bcd5849ea1 --- /dev/null +++ b/gfx/webrender_bindings/RenderCompositorOGL.cpp @@ -0,0 +1,131 @@ +/* -*- 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/. */ + +#include "RenderCompositorOGL.h" + +#include "GLContext.h" +#include "GLContextEGL.h" +#include "GLContextProvider.h" +#include "mozilla/gfx/gfxVars.h" +#include "mozilla/gfx/Logging.h" +#include "mozilla/webrender/RenderThread.h" +#include "mozilla/widget/CompositorWidget.h" + +namespace mozilla { +namespace wr { + +/* static */ +UniquePtr<RenderCompositor> RenderCompositorOGL::Create( + RefPtr<widget::CompositorWidget>&& aWidget, nsACString& aError) { + RefPtr<gl::GLContext> gl = RenderThread::Get()->SharedGL(); + if (!gl) { + gl = gl::GLContextProvider::CreateForCompositorWidget( + aWidget, /* aWebRender */ true, /* aForceAccelerated */ true); + RenderThread::MaybeEnableGLDebugMessage(gl); + } + if (!gl || !gl->MakeCurrent()) { + gfxCriticalNote << "Failed GL context creation for WebRender: " + << gfx::hexa(gl.get()); + return nullptr; + } + return MakeUnique<RenderCompositorOGL>(std::move(gl), std::move(aWidget)); +} + +RenderCompositorOGL::RenderCompositorOGL( + RefPtr<gl::GLContext>&& aGL, RefPtr<widget::CompositorWidget>&& aWidget) + : RenderCompositor(std::move(aWidget)), mGL(aGL) { + MOZ_ASSERT(mGL); + + mIsEGL = aGL->GetContextType() == mozilla::gl::GLContextType::EGL; +} + +RenderCompositorOGL::~RenderCompositorOGL() { + if (!mGL->MakeCurrent()) { + gfxCriticalNote + << "Failed to make render context current during destroying."; + // Leak resources! + return; + } +} + +bool RenderCompositorOGL::BeginFrame() { + if (!mGL->MakeCurrent()) { + gfxCriticalNote << "Failed to make render context current, can't draw."; + return false; + } + + mGL->fBindFramebuffer(LOCAL_GL_FRAMEBUFFER, mGL->GetDefaultFramebuffer()); + + return true; +} + +RenderedFrameId RenderCompositorOGL::EndFrame( + const nsTArray<DeviceIntRect>& aDirtyRects) { + RenderedFrameId frameId = GetNextRenderFrameId(); + if (UsePartialPresent() && aDirtyRects.Length() > 0) { + gfx::IntRegion bufferInvalid; + const auto bufferSize = GetBufferSize(); + for (const DeviceIntRect& rect : aDirtyRects) { + const auto left = std::max(0, std::min(bufferSize.width, rect.origin.x)); + const auto top = std::max(0, std::min(bufferSize.height, rect.origin.y)); + + const auto right = std::min(bufferSize.width, + std::max(0, rect.origin.x + rect.size.width)); + const auto bottom = std::min( + bufferSize.height, std::max(0, rect.origin.y + rect.size.height)); + + const auto width = right - left; + const auto height = bottom - top; + + bufferInvalid.OrWith( + gfx::IntRect(left, (GetBufferSize().height - bottom), width, height)); + } + gl()->SetDamage(bufferInvalid); + } + mGL->SwapBuffers(); + return frameId; +} + +void RenderCompositorOGL::Pause() {} + +bool RenderCompositorOGL::Resume() { return true; } + +LayoutDeviceIntSize RenderCompositorOGL::GetBufferSize() { + return mWidget->GetClientSize(); +} + +CompositorCapabilities RenderCompositorOGL::GetCompositorCapabilities() { + CompositorCapabilities caps; + + caps.virtual_surface_size = 0; + + return caps; +} + +uint32_t RenderCompositorOGL::GetMaxPartialPresentRects() { + return gfx::gfxVars::WebRenderMaxPartialPresentRects(); +} + +bool RenderCompositorOGL::RequestFullRender() { return false; } + +bool RenderCompositorOGL::UsePartialPresent() { + return gfx::gfxVars::WebRenderMaxPartialPresentRects() > 0; +} + +bool RenderCompositorOGL::ShouldDrawPreviousPartialPresentRegions() { + return true; +} + +size_t RenderCompositorOGL::GetBufferAge() const { + if (!StaticPrefs:: + gfx_webrender_allow_partial_present_buffer_age_AtStartup()) { + return 0; + } + return gl()->GetBufferAge(); +} + +} // namespace wr +} // namespace mozilla |