2018-11-30 19:52:05 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2018-11-30 15:39:55 +00:00
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2014-01-07 20:02:18 +00: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"
|
|
|
|
|
|
|
|
namespace mozilla {
|
2017-01-20 23:31:02 +00:00
|
|
|
namespace widget {
|
|
|
|
class CompositorWidget;
|
|
|
|
} // namespace widget
|
2014-01-07 20:02:18 +00:00
|
|
|
namespace gl {
|
|
|
|
|
|
|
|
class GLContextEGL : public GLContext {
|
|
|
|
friend class TextureImageEGL;
|
|
|
|
|
|
|
|
static already_AddRefed<GLContextEGL> CreateGLContext(
|
2015-11-27 19:02:52 +00:00
|
|
|
CreateContextFlags flags, const SurfaceCaps& caps, bool isOffscreen,
|
2016-06-11 02:01:00 +00:00
|
|
|
EGLConfig config, EGLSurface surface, nsACString* const out_failureId);
|
2014-01-07 20:02:18 +00:00
|
|
|
|
|
|
|
public:
|
2015-03-21 16:28:04 +00:00
|
|
|
MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(GLContextEGL, override)
|
2016-06-06 23:27:43 +00:00
|
|
|
GLContextEGL(CreateContextFlags flags, const SurfaceCaps& caps,
|
2014-01-07 20:02:18 +00:00
|
|
|
bool isOffscreen, EGLConfig config, EGLSurface surface,
|
|
|
|
EGLContext context);
|
|
|
|
|
|
|
|
~GLContextEGL();
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual GLContextType GetContextType() const override {
|
|
|
|
return GLContextType::EGL;
|
|
|
|
}
|
2014-01-07 20:02:18 +00:00
|
|
|
|
|
|
|
static GLContextEGL* Cast(GLContext* gl) {
|
2014-01-10 18:55:24 +00:00
|
|
|
MOZ_ASSERT(gl->GetContextType() == GLContextType::EGL);
|
2014-01-07 20:02:18 +00:00
|
|
|
return static_cast<GLContextEGL*>(gl);
|
2014-01-07 20:02:18 +00:00
|
|
|
}
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
bool Init() override;
|
2014-01-07 20:02:18 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual bool IsDoubleBuffered() const override { return mIsDoubleBuffered; }
|
2014-01-07 20:02:18 +00:00
|
|
|
|
|
|
|
void SetIsDoubleBuffered(bool aIsDB) { mIsDoubleBuffered = aIsDB; }
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual bool IsANGLE() const override {
|
2018-06-04 02:09:29 +00:00
|
|
|
return GLLibraryEGL::Get()->IsANGLE();
|
2014-01-07 20:02:18 +00:00
|
|
|
}
|
|
|
|
|
2015-07-23 17:11:04 +00:00
|
|
|
virtual bool IsWARP() const override { return GLLibraryEGL::Get()->IsWARP(); }
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual bool BindTexImage() override;
|
2014-01-07 20:02:18 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual bool ReleaseTexImage() override;
|
2014-01-07 20:02:18 +00:00
|
|
|
|
|
|
|
void SetEGLSurfaceOverride(EGLSurface surf);
|
2017-03-03 21:14:27 +00:00
|
|
|
EGLSurface GetEGLSurfaceOverride() { return mSurfaceOverride; }
|
2014-01-07 20:02:18 +00:00
|
|
|
|
2017-08-15 20:21:37 +00:00
|
|
|
virtual bool MakeCurrentImpl() const override;
|
2014-01-07 20:02:18 +00:00
|
|
|
|
2017-08-11 20:54:40 +00:00
|
|
|
virtual bool IsCurrentImpl() const override;
|
2014-01-07 20:02:18 +00:00
|
|
|
|
2017-01-20 23:31:02 +00:00
|
|
|
virtual bool RenewSurface(widget::CompositorWidget* aWidget) override;
|
2014-01-07 20:02:18 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual void ReleaseSurface() override;
|
2014-01-07 20:02:18 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual bool SetupLookupFunction() override;
|
2014-01-07 20:02:18 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual bool SwapBuffers() override;
|
2014-01-07 20:02:18 +00:00
|
|
|
|
2017-01-31 02:58:52 +00:00
|
|
|
virtual void GetWSIInfo(nsCString* const out) const override;
|
|
|
|
|
2014-01-07 20:02:18 +00:00
|
|
|
// hold a reference to the given surface
|
|
|
|
// for the lifetime of this context.
|
2016-06-11 01:37:07 +00:00
|
|
|
void HoldSurface(gfxASurface* aSurf);
|
2014-01-07 20:02:18 +00:00
|
|
|
|
2015-09-24 19:21:05 +00:00
|
|
|
EGLSurface GetEGLSurface() const { return mSurface; }
|
2015-04-17 16:28:41 +00:00
|
|
|
|
2018-06-04 02:09:29 +00:00
|
|
|
EGLDisplay GetEGLDisplay() const { return GLLibraryEGL::Get()->Display(); }
|
2015-04-17 16:28:41 +00:00
|
|
|
|
2016-06-11 01:37:07 +00:00
|
|
|
bool BindTex2DOffscreen(GLContext* aOffscreen);
|
|
|
|
void UnbindTex2DOffscreen(GLContext* aOffscreen);
|
2014-01-07 20:02:18 +00:00
|
|
|
void BindOffscreenFramebuffer();
|
|
|
|
|
2018-06-04 02:09:52 +00:00
|
|
|
void Destroy();
|
|
|
|
|
2015-11-27 19:02:52 +00:00
|
|
|
static already_AddRefed<GLContextEGL> CreateEGLPBufferOffscreenContext(
|
|
|
|
CreateContextFlags flags, const gfx::IntSize& size,
|
2016-06-11 02:01:00 +00:00
|
|
|
const SurfaceCaps& minCaps, nsACString* const out_FailureId);
|
2014-01-07 20:02:18 +00:00
|
|
|
|
2019-02-12 07:32:51 +00:00
|
|
|
#if defined(MOZ_WAYLAND)
|
|
|
|
static EGLSurface CreateEGLSurfaceForCompositorWidget(
|
|
|
|
widget::CompositorWidget* aCompositorWidget, bool aForceAccelerated);
|
|
|
|
#endif
|
2014-01-07 20:02:18 +00:00
|
|
|
protected:
|
|
|
|
friend class GLContextProviderEGL;
|
2017-01-21 00:20:59 +00:00
|
|
|
friend class GLContextEGLFactory;
|
2014-01-07 20:02:18 +00:00
|
|
|
|
2019-01-11 00:04:26 +00:00
|
|
|
virtual void OnMarkDestroyed() override;
|
|
|
|
|
2015-09-24 19:21:05 +00:00
|
|
|
public:
|
2017-07-18 02:17:41 +00:00
|
|
|
const EGLConfig mConfig;
|
2014-01-07 20:02:18 +00:00
|
|
|
|
2018-08-17 22:21:26 +00:00
|
|
|
protected:
|
|
|
|
const RefPtr<GLLibraryEGL> mEgl;
|
|
|
|
EGLSurface mSurface;
|
|
|
|
const EGLSurface mFallbackSurface;
|
2014-01-07 20:02:18 +00:00
|
|
|
|
2018-11-30 10:46:48 +00:00
|
|
|
public:
|
2014-01-07 20:02:18 +00:00
|
|
|
const EGLContext mContext;
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2015-09-24 19:21:05 +00:00
|
|
|
protected:
|
2018-08-17 22:21:26 +00:00
|
|
|
EGLSurface mSurfaceOverride = EGL_NO_SURFACE;
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<gfxASurface> mThebesSurface;
|
2018-08-17 22:21:26 +00:00
|
|
|
bool mBound = false;
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2018-08-17 22:21:26 +00:00
|
|
|
bool mIsPBuffer = false;
|
|
|
|
bool mIsDoubleBuffered = false;
|
|
|
|
bool mCanBindToTexture = false;
|
|
|
|
bool mShareWithEGLImage = false;
|
|
|
|
bool mOwnsContext = true;
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2014-01-07 20:02:18 +00:00
|
|
|
static EGLSurface CreatePBufferSurfaceTryingPowerOfTwo(
|
|
|
|
EGLConfig config, EGLenum bindToTextureFormat, gfx::IntSize& pbsize);
|
2018-05-22 08:34:32 +00:00
|
|
|
#if defined(MOZ_WAYLAND)
|
|
|
|
static EGLSurface CreateWaylandBufferSurface(EGLConfig config,
|
|
|
|
gfx::IntSize& pbsize);
|
|
|
|
#endif
|
2017-06-07 00:26:49 +00:00
|
|
|
#if defined(MOZ_WIDGET_ANDROID)
|
|
|
|
public:
|
|
|
|
EGLSurface CreateCompatibleSurface(void* aWindow);
|
|
|
|
#endif // defined(MOZ_WIDGET_ANDROID)
|
2014-01-07 20:02:18 +00:00
|
|
|
};
|
|
|
|
|
2018-02-01 12:39:31 +00:00
|
|
|
bool CreateConfig(EGLConfig* config, int32_t depth, bool enableDepthBuffer);
|
|
|
|
|
2015-07-13 15:25:42 +00:00
|
|
|
} // namespace gl
|
|
|
|
} // namespace mozilla
|
2014-01-07 20:02:18 +00:00
|
|
|
|
|
|
|
#endif // GLCONTEXTEGL_H_
|