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 #include "RenderCompositorOGL.h"
10 #include "GLContextEGL.h"
11 #include "GLContextProvider.h"
12 #include "mozilla/gfx/gfxVars.h"
13 #include "mozilla/gfx/Logging.h"
14 #include "mozilla/webrender/RenderThread.h"
15 #include "mozilla/widget/CompositorWidget.h"
17 namespace mozilla::wr
{
19 extern LazyLogModule gRenderThreadLog
;
20 #define LOG(...) MOZ_LOG(gRenderThreadLog, LogLevel::Debug, (__VA_ARGS__))
23 UniquePtr
<RenderCompositor
> RenderCompositorOGL::Create(
24 const RefPtr
<widget::CompositorWidget
>& aWidget
, nsACString
& aError
) {
25 RefPtr
<gl::GLContext
> gl
= RenderThread::Get()->SingletonGL();
27 gl
= gl::GLContextProvider::CreateForCompositorWidget(
28 aWidget
, /* aHardwareWebRender */ true, /* aForceAccelerated */ true);
29 RenderThread::MaybeEnableGLDebugMessage(gl
);
31 if (!gl
|| !gl
->MakeCurrent()) {
32 gfxCriticalNote
<< "Failed GL context creation for WebRender: "
33 << gfx::hexa(gl
.get());
36 return MakeUnique
<RenderCompositorOGL
>(std::move(gl
), aWidget
);
39 RenderCompositorOGL::RenderCompositorOGL(
40 RefPtr
<gl::GLContext
>&& aGL
,
41 const RefPtr
<widget::CompositorWidget
>& aWidget
)
42 : RenderCompositor(aWidget
), mGL(aGL
) {
44 LOG("RenderCompositorOGL::RenderCompositorOGL()");
46 mIsEGL
= aGL
->GetContextType() == mozilla::gl::GLContextType::EGL
;
49 RenderCompositorOGL::~RenderCompositorOGL() {
50 LOG("RenderCompositorOGL::~RenderCompositorOGL()");
52 if (!mGL
->MakeCurrent()) {
54 << "Failed to make render context current during destroying.";
60 bool RenderCompositorOGL::BeginFrame() {
61 if (!mGL
->MakeCurrent()) {
62 gfxCriticalNote
<< "Failed to make render context current, can't draw.";
66 mGL
->fBindFramebuffer(LOCAL_GL_FRAMEBUFFER
, mGL
->GetDefaultFramebuffer());
71 RenderedFrameId
RenderCompositorOGL::EndFrame(
72 const nsTArray
<DeviceIntRect
>& aDirtyRects
) {
73 RenderedFrameId frameId
= GetNextRenderFrameId();
74 if (UsePartialPresent() && aDirtyRects
.Length() > 0) {
75 gfx::IntRegion bufferInvalid
;
76 const auto bufferSize
= GetBufferSize();
77 for (const DeviceIntRect
& rect
: aDirtyRects
) {
78 const auto left
= std::max(0, std::min(bufferSize
.width
, rect
.min
.x
));
79 const auto top
= std::max(0, std::min(bufferSize
.height
, rect
.min
.y
));
81 const auto right
= std::min(bufferSize
.width
, std::max(0, rect
.max
.x
));
82 const auto bottom
= std::min(bufferSize
.height
, std::max(0, rect
.max
.y
));
84 const auto width
= right
- left
;
85 const auto height
= bottom
- top
;
88 gfx::IntRect(left
, (GetBufferSize().height
- bottom
), width
, height
));
90 gl()->SetDamage(bufferInvalid
);
96 void RenderCompositorOGL::Pause() {}
98 bool RenderCompositorOGL::Resume() { return true; }
100 LayoutDeviceIntSize
RenderCompositorOGL::GetBufferSize() {
101 return mWidget
->GetClientSize();
104 uint32_t RenderCompositorOGL::GetMaxPartialPresentRects() {
105 return gfx::gfxVars::WebRenderMaxPartialPresentRects();
108 bool RenderCompositorOGL::RequestFullRender() { return false; }
110 bool RenderCompositorOGL::UsePartialPresent() {
111 return gfx::gfxVars::WebRenderMaxPartialPresentRects() > 0;
114 bool RenderCompositorOGL::ShouldDrawPreviousPartialPresentRegions() {
118 size_t RenderCompositorOGL::GetBufferAge() const {
120 gfx_webrender_allow_partial_present_buffer_age_AtStartup()) {
123 return gl()->GetBufferAge();
126 } // namespace mozilla::wr