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"
21 UniquePtr
<RenderCompositor
> RenderCompositorOGL::Create(
22 RefPtr
<widget::CompositorWidget
>&& aWidget
, nsACString
& aError
) {
23 RefPtr
<gl::GLContext
> gl
= RenderThread::Get()->SingletonGL();
25 gl
= gl::GLContextProvider::CreateForCompositorWidget(
26 aWidget
, /* aWebRender */ true, /* aForceAccelerated */ true);
27 RenderThread::MaybeEnableGLDebugMessage(gl
);
29 if (!gl
|| !gl
->MakeCurrent()) {
30 gfxCriticalNote
<< "Failed GL context creation for WebRender: "
31 << gfx::hexa(gl
.get());
34 return MakeUnique
<RenderCompositorOGL
>(std::move(gl
), std::move(aWidget
));
37 RenderCompositorOGL::RenderCompositorOGL(
38 RefPtr
<gl::GLContext
>&& aGL
, RefPtr
<widget::CompositorWidget
>&& aWidget
)
39 : RenderCompositor(std::move(aWidget
)), mGL(aGL
) {
42 mIsEGL
= aGL
->GetContextType() == mozilla::gl::GLContextType::EGL
;
45 RenderCompositorOGL::~RenderCompositorOGL() {
46 if (!mGL
->MakeCurrent()) {
48 << "Failed to make render context current during destroying.";
54 bool RenderCompositorOGL::BeginFrame() {
55 if (!mGL
->MakeCurrent()) {
56 gfxCriticalNote
<< "Failed to make render context current, can't draw.";
60 mGL
->fBindFramebuffer(LOCAL_GL_FRAMEBUFFER
, mGL
->GetDefaultFramebuffer());
65 RenderedFrameId
RenderCompositorOGL::EndFrame(
66 const nsTArray
<DeviceIntRect
>& aDirtyRects
) {
67 RenderedFrameId frameId
= GetNextRenderFrameId();
68 if (UsePartialPresent() && aDirtyRects
.Length() > 0) {
69 gfx::IntRegion bufferInvalid
;
70 const auto bufferSize
= GetBufferSize();
71 for (const DeviceIntRect
& rect
: aDirtyRects
) {
72 const auto left
= std::max(0, std::min(bufferSize
.width
, rect
.origin
.x
));
73 const auto top
= std::max(0, std::min(bufferSize
.height
, rect
.origin
.y
));
75 const auto right
= std::min(bufferSize
.width
,
76 std::max(0, rect
.origin
.x
+ rect
.size
.width
));
77 const auto bottom
= std::min(
78 bufferSize
.height
, std::max(0, rect
.origin
.y
+ rect
.size
.height
));
80 const auto width
= right
- left
;
81 const auto height
= bottom
- top
;
84 gfx::IntRect(left
, (GetBufferSize().height
- bottom
), width
, height
));
86 gl()->SetDamage(bufferInvalid
);
92 void RenderCompositorOGL::Pause() {}
94 bool RenderCompositorOGL::Resume() { return true; }
96 LayoutDeviceIntSize
RenderCompositorOGL::GetBufferSize() {
97 return mWidget
->GetClientSize();
100 uint32_t RenderCompositorOGL::GetMaxPartialPresentRects() {
101 return gfx::gfxVars::WebRenderMaxPartialPresentRects();
104 bool RenderCompositorOGL::RequestFullRender() { return false; }
106 bool RenderCompositorOGL::UsePartialPresent() {
107 return gfx::gfxVars::WebRenderMaxPartialPresentRects() > 0;
110 bool RenderCompositorOGL::ShouldDrawPreviousPartialPresentRegions() {
114 size_t RenderCompositorOGL::GetBufferAge() const {
116 gfx_webrender_allow_partial_present_buffer_age_AtStartup()) {
119 return gl()->GetBufferAge();
123 } // namespace mozilla