2018-11-30 22:52:05 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2018-11-30 18:39:55 +03:00
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2014-01-08 00:02:18 +04:00
|
|
|
/* 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 GLCONTEXTEGL_H_
|
|
|
|
#define GLCONTEXTEGL_H_
|
|
|
|
|
|
|
|
#include "GLContext.h"
|
|
|
|
#include "GLLibraryEGL.h"
|
2020-02-11 04:23:37 +03:00
|
|
|
#include "nsRegion.h"
|
2020-08-07 10:14:46 +03:00
|
|
|
#include <memory>
|
2014-01-08 00:02:18 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
2020-08-07 10:14:46 +03:00
|
|
|
namespace layers {
|
|
|
|
class SurfaceTextureImage;
|
|
|
|
} // namespace layers
|
2017-01-21 02:31:02 +03:00
|
|
|
namespace widget {
|
|
|
|
class CompositorWidget;
|
|
|
|
} // namespace widget
|
2014-01-08 00:02:18 +04:00
|
|
|
namespace gl {
|
|
|
|
|
2020-08-07 10:14:46 +03:00
|
|
|
RefPtr<GLLibraryEGL> DefaultEglLibrary(nsACString* const out_failureId);
|
|
|
|
|
|
|
|
inline std::shared_ptr<EglDisplay> DefaultEglDisplay(
|
|
|
|
nsACString* const out_failureId) {
|
|
|
|
const auto lib = DefaultEglLibrary(out_failureId);
|
|
|
|
if (!lib) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return lib->DefaultDisplay(out_failureId);
|
|
|
|
}
|
2020-08-07 00:19:32 +03:00
|
|
|
|
2020-08-07 10:14:46 +03:00
|
|
|
// -
|
|
|
|
|
|
|
|
class GLContextEGL final : public GLContext {
|
2014-01-08 00:02:18 +04:00
|
|
|
public:
|
2015-03-21 19:28:04 +03:00
|
|
|
MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(GLContextEGL, override)
|
2014-01-08 00:02:18 +04:00
|
|
|
|
2020-08-07 10:14:46 +03:00
|
|
|
static RefPtr<GLContextEGL> CreateGLContext(
|
|
|
|
std::shared_ptr<EglDisplay>, const GLContextDesc&, EGLConfig config,
|
|
|
|
EGLSurface surface, const bool useGles, nsACString* const out_failureId);
|
|
|
|
|
|
|
|
private:
|
|
|
|
GLContextEGL(std::shared_ptr<EglDisplay>, const GLContextDesc&,
|
|
|
|
EGLConfig config, EGLSurface surface, EGLContext context);
|
2014-01-08 00:02:18 +04:00
|
|
|
~GLContextEGL();
|
|
|
|
|
2020-08-07 10:14:46 +03:00
|
|
|
public:
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual GLContextType GetContextType() const override {
|
|
|
|
return GLContextType::EGL;
|
|
|
|
}
|
2014-01-08 00:02:18 +04:00
|
|
|
|
|
|
|
static GLContextEGL* Cast(GLContext* gl) {
|
2014-01-10 22:55:24 +04:00
|
|
|
MOZ_ASSERT(gl->GetContextType() == GLContextType::EGL);
|
2014-01-08 00:02:18 +04:00
|
|
|
return static_cast<GLContextEGL*>(gl);
|
2014-01-08 00:02:18 +04:00
|
|
|
}
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
bool Init() override;
|
2014-01-08 00:02:18 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual bool IsDoubleBuffered() const override { return mIsDoubleBuffered; }
|
2014-01-08 00:02:18 +04:00
|
|
|
|
|
|
|
void SetIsDoubleBuffered(bool aIsDB) { mIsDoubleBuffered = aIsDB; }
|
|
|
|
|
2020-08-07 10:14:46 +03:00
|
|
|
virtual bool IsANGLE() const override { return mEgl->mLib->IsANGLE(); }
|
|
|
|
virtual bool IsWARP() const override { return mEgl->mIsWARP; }
|
2015-07-23 20:11:04 +03:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual bool BindTexImage() override;
|
2014-01-08 00:02:18 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual bool ReleaseTexImage() override;
|
2014-01-08 00:02:18 +04:00
|
|
|
|
|
|
|
void SetEGLSurfaceOverride(EGLSurface surf);
|
2017-03-04 00:14:27 +03:00
|
|
|
EGLSurface GetEGLSurfaceOverride() { return mSurfaceOverride; }
|
2014-01-08 00:02:18 +04:00
|
|
|
|
2017-08-15 23:21:37 +03:00
|
|
|
virtual bool MakeCurrentImpl() const override;
|
2014-01-08 00:02:18 +04:00
|
|
|
|
2017-08-11 23:54:40 +03:00
|
|
|
virtual bool IsCurrentImpl() const override;
|
2014-01-08 00:02:18 +04:00
|
|
|
|
2017-01-21 02:31:02 +03:00
|
|
|
virtual bool RenewSurface(widget::CompositorWidget* aWidget) override;
|
2014-01-08 00:02:18 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void ReleaseSurface() override;
|
2014-01-08 00:02:18 +04:00
|
|
|
|
2019-02-23 00:17:28 +03:00
|
|
|
Maybe<SymbolLoader> GetSymbolLoader() const override;
|
2014-01-08 00:02:18 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual bool SwapBuffers() override;
|
2014-01-08 00:02:18 +04:00
|
|
|
|
2020-01-30 13:46:54 +03:00
|
|
|
virtual void SetDamage(const nsIntRegion& aDamageRegion) override;
|
|
|
|
|
2020-11-13 21:41:41 +03:00
|
|
|
GLint GetBufferAge() const override;
|
|
|
|
|
2017-01-31 05:58:52 +03:00
|
|
|
virtual void GetWSIInfo(nsCString* const out) const override;
|
|
|
|
|
2015-09-24 22:21:05 +03:00
|
|
|
EGLSurface GetEGLSurface() const { return mSurface; }
|
2015-04-17 19:28:41 +03:00
|
|
|
|
Bug 1575765 - Implement KHR_partial_update for webrender. r=sotaro,jgilbert
KHR_partial_update allows us to avoid rerendering the entire
backbuffer every frame, and instead only render what has changed on
the current frame, as well as the difference between the current
backbuffer and the current frontbuffer. It works similarily to
EXT_buffer_age, which we already support, with the additional
requirement that we must call eglSetDamageRegion each frame before
rendering to the backbuffer.
Modify GLContextEGL::GetBufferAge() so that it queries the age if
either EXT_buffer_age or KHR_partial_update are available. This will
now automatically be queried by webrender through the
PartialPresentCompositor trait. Add a new function to that trait,
set_buffer_damage_region(), whose RenderCompositorEGL implementation
calls eglSetDamageRegion(). Call this from composite_simple(), once
the damage rect has been calculated but before rendering to the
backbuffer.
Additionally, change both RenderCompositorEGL and
RenderCompositorOGL's implementations of
ShouldDrawPreviousPartialPresentRegions() to unconditionally return
true, rather than checking for the existence of EXT_buffer_age (or
adding a new check for KHR_partial_update). The lack of these
extensions does not mean that webrender is able to skip rendering
previous frames' damage. Rather the opposite, it means we cannot
render *only* the previous frames' damage, and must instead always
render the entire buffer.
Differential Revision: https://phabricator.services.mozilla.com/D91203
2020-10-02 13:23:56 +03:00
|
|
|
bool HasExtBufferAge() const;
|
|
|
|
bool HasKhrPartialUpdate() const;
|
2020-05-22 21:15:13 +03:00
|
|
|
|
2016-06-11 04:37:07 +03:00
|
|
|
bool BindTex2DOffscreen(GLContext* aOffscreen);
|
|
|
|
void UnbindTex2DOffscreen(GLContext* aOffscreen);
|
2014-01-08 00:02:18 +04:00
|
|
|
void BindOffscreenFramebuffer();
|
|
|
|
|
2018-06-04 05:09:52 +03:00
|
|
|
void Destroy();
|
|
|
|
|
2020-08-07 10:14:46 +03:00
|
|
|
static RefPtr<GLContextEGL> CreateEGLPBufferOffscreenContext(
|
|
|
|
std::shared_ptr<EglDisplay>, const GLContextCreateDesc&,
|
|
|
|
const gfx::IntSize& size, nsACString* const out_FailureId);
|
|
|
|
static RefPtr<GLContextEGL> CreateEGLPBufferOffscreenContextImpl(
|
|
|
|
std::shared_ptr<EglDisplay>, const GLContextCreateDesc&,
|
|
|
|
const gfx::IntSize& size, bool aUseGles, nsACString* const out_FailureId);
|
2014-01-08 00:02:18 +04:00
|
|
|
|
2019-02-12 10:32:51 +03:00
|
|
|
static EGLSurface CreateEGLSurfaceForCompositorWidget(
|
2019-03-06 22:00:38 +03:00
|
|
|
widget::CompositorWidget* aCompositorWidget, const EGLConfig aConfig);
|
2020-08-07 10:14:46 +03:00
|
|
|
|
2020-09-03 12:02:44 +03:00
|
|
|
#ifdef MOZ_X11
|
2021-10-06 14:30:37 +03:00
|
|
|
static bool FindVisual(int* const out_visualId);
|
2020-09-03 12:02:44 +03:00
|
|
|
#endif
|
|
|
|
|
2014-01-08 00:02:18 +04:00
|
|
|
protected:
|
|
|
|
friend class GLContextProviderEGL;
|
2017-01-21 03:20:59 +03:00
|
|
|
friend class GLContextEGLFactory;
|
2014-01-08 00:02:18 +04:00
|
|
|
|
2019-01-11 03:04:26 +03:00
|
|
|
virtual void OnMarkDestroyed() override;
|
|
|
|
|
2015-09-24 22:21:05 +03:00
|
|
|
public:
|
2020-08-07 10:14:46 +03:00
|
|
|
const std::shared_ptr<EglDisplay> mEgl;
|
2017-07-18 05:17:41 +03:00
|
|
|
const EGLConfig mConfig;
|
2019-06-15 08:21:12 +03:00
|
|
|
const EGLContext mContext;
|
2014-01-08 00:02:18 +04:00
|
|
|
|
2018-08-18 01:21:26 +03:00
|
|
|
protected:
|
|
|
|
EGLSurface mSurface;
|
|
|
|
const EGLSurface mFallbackSurface;
|
2014-01-08 00:02:18 +04:00
|
|
|
|
2018-08-18 01:21:26 +03:00
|
|
|
EGLSurface mSurfaceOverride = EGL_NO_SURFACE;
|
|
|
|
bool mBound = false;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-08-18 01:21:26 +03:00
|
|
|
bool mIsPBuffer = false;
|
|
|
|
bool mIsDoubleBuffered = false;
|
|
|
|
bool mCanBindToTexture = false;
|
|
|
|
bool mShareWithEGLImage = false;
|
|
|
|
bool mOwnsContext = true;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2020-01-30 13:46:54 +03:00
|
|
|
nsIntRegion mDamageRegion;
|
|
|
|
|
2014-01-08 00:02:18 +04:00
|
|
|
static EGLSurface CreatePBufferSurfaceTryingPowerOfTwo(
|
2020-08-07 10:14:46 +03:00
|
|
|
EglDisplay&, EGLConfig, EGLenum bindToTextureFormat,
|
2019-06-15 08:21:12 +03:00
|
|
|
gfx::IntSize& pbsize);
|
2020-08-07 10:14:46 +03:00
|
|
|
|
|
|
|
static EGLSurface CreateWaylandBufferSurface(EglDisplay&, EGLConfig,
|
2018-05-22 11:34:32 +03:00
|
|
|
gfx::IntSize& pbsize);
|
2020-08-07 10:14:46 +03:00
|
|
|
|
2017-06-07 03:26:49 +03:00
|
|
|
public:
|
2020-08-07 10:14:46 +03:00
|
|
|
EGLSurface CreateCompatibleSurface(void* aWindow) const;
|
2014-01-08 00:02:18 +04:00
|
|
|
};
|
|
|
|
|
2020-08-07 10:14:46 +03:00
|
|
|
// -
|
2020-09-03 12:02:44 +03:00
|
|
|
// aVisual is used in Linux only to exactly match window and framebuffer
|
|
|
|
// visuals on NVIDIA drivers (Bug 1478454).
|
2020-08-07 10:14:46 +03:00
|
|
|
bool CreateConfig(EglDisplay&, EGLConfig* aConfig, int32_t depth,
|
2020-09-03 12:02:44 +03:00
|
|
|
bool aEnableDepthBuffer, bool aUseGles, int aVisual = 0);
|
2018-02-01 15:39:31 +03:00
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace gl
|
|
|
|
} // namespace mozilla
|
2014-01-08 00:02:18 +04:00
|
|
|
|
|
|
|
#endif // GLCONTEXTEGL_H_
|