Bug 1219890. Use ES3 when appropriate. r=jgilbert

This enables the use of WebGL2 on top of ANGLE.
This commit is contained in:
Jeff Muizelaar 2015-11-27 14:02:52 -05:00
parent cf8265bebe
commit 18f1188eac
4 changed files with 29 additions and 15 deletions

View File

@ -654,6 +654,7 @@ WebGLContext::CreateAndInitGL(bool forceEnabled)
gl::CreateContextFlags flags = gl::CreateContextFlags::NONE;
if (forceEnabled) flags |= gl::CreateContextFlags::FORCE_ENABLE_HARDWARE;
if (!IsWebGL2()) flags |= gl::CreateContextFlags::REQUIRE_COMPAT_PROFILE;
if (IsWebGL2()) flags |= gl::CreateContextFlags::PREFER_ES3;
const gl::SurfaceCaps baseCaps = BaseCaps(mOptions, this);

View File

@ -20,7 +20,8 @@ class GLContextEGL : public GLContext
friend class TextureImageEGL;
static already_AddRefed<GLContextEGL>
CreateGLContext(const SurfaceCaps& caps,
CreateGLContext(CreateContextFlags flags,
const SurfaceCaps& caps,
GLContextEGL *shareContext,
bool isOffscreen,
EGLConfig config,
@ -108,7 +109,8 @@ public:
CreateEGLPixmapOffscreenContext(const gfx::IntSize& size);
static already_AddRefed<GLContextEGL>
CreateEGLPBufferOffscreenContext(const gfx::IntSize& size,
CreateEGLPBufferOffscreenContext(CreateContextFlags flags,
const gfx::IntSize& size,
const SurfaceCaps& minCaps);
protected:

View File

@ -485,7 +485,8 @@ GLContextEGL::DestroySurface(EGLSurface aSurface)
}
already_AddRefed<GLContextEGL>
GLContextEGL::CreateGLContext(const SurfaceCaps& caps,
GLContextEGL::CreateGLContext(CreateContextFlags flags,
const SurfaceCaps& caps,
GLContextEGL *shareContext,
bool isOffscreen,
EGLConfig config,
@ -502,7 +503,10 @@ GLContextEGL::CreateGLContext(const SurfaceCaps& caps,
nsTArray<EGLint> contextAttribs;
contextAttribs.AppendElement(LOCAL_EGL_CONTEXT_CLIENT_VERSION);
contextAttribs.AppendElement(2);
if (flags & CreateContextFlags::PREFER_ES3)
contextAttribs.AppendElement(3);
else
contextAttribs.AppendElement(2);
if (sEGLLibrary.HasRobustness()) {
// contextAttribs.AppendElement(LOCAL_EGL_CONTEXT_ROBUST_ACCESS_EXT);
@ -782,7 +786,7 @@ GLContextProviderEGL::CreateForWindow(nsIWidget *aWidget)
SurfaceCaps caps = SurfaceCaps::Any();
RefPtr<GLContextEGL> glContext =
GLContextEGL::CreateGLContext(caps,
GLContextEGL::CreateGLContext(CreateContextFlags::NONE, caps,
nullptr, false,
config, surface);
@ -835,13 +839,17 @@ GLContextProviderEGL::DestroyEGLSurface(EGLSurface surface)
static void
FillContextAttribs(bool alpha, bool depth, bool stencil, bool bpp16,
nsTArray<EGLint>* out)
bool es3, nsTArray<EGLint>* out)
{
out->AppendElement(LOCAL_EGL_SURFACE_TYPE);
out->AppendElement(LOCAL_EGL_PBUFFER_BIT);
out->AppendElement(LOCAL_EGL_RENDERABLE_TYPE);
out->AppendElement(LOCAL_EGL_OPENGL_ES2_BIT);
if (es3) {
out->AppendElement(LOCAL_EGL_OPENGL_ES3_BIT_KHR);
} else {
out->AppendElement(LOCAL_EGL_OPENGL_ES2_BIT);
}
out->AppendElement(LOCAL_EGL_RED_SIZE);
if (bpp16) {
@ -896,12 +904,12 @@ GetAttrib(GLLibraryEGL* egl, EGLConfig config, EGLint attrib)
}
static EGLConfig
ChooseConfig(GLLibraryEGL* egl, const SurfaceCaps& minCaps,
ChooseConfig(GLLibraryEGL* egl, CreateContextFlags flags, const SurfaceCaps& minCaps,
SurfaceCaps* const out_configCaps)
{
nsTArray<EGLint> configAttribList;
FillContextAttribs(minCaps.alpha, minCaps.depth, minCaps.stencil, minCaps.bpp16,
&configAttribList);
bool(flags & CreateContextFlags::PREFER_ES3), &configAttribList);
const EGLint* configAttribs = configAttribList.Elements();
@ -930,11 +938,12 @@ ChooseConfig(GLLibraryEGL* egl, const SurfaceCaps& minCaps,
}
/*static*/ already_AddRefed<GLContextEGL>
GLContextEGL::CreateEGLPBufferOffscreenContext(const mozilla::gfx::IntSize& size,
GLContextEGL::CreateEGLPBufferOffscreenContext(CreateContextFlags flags,
const mozilla::gfx::IntSize& size,
const SurfaceCaps& minCaps)
{
SurfaceCaps configCaps;
EGLConfig config = ChooseConfig(&sEGLLibrary, minCaps, &configCaps);
EGLConfig config = ChooseConfig(&sEGLLibrary, flags, minCaps, &configCaps);
if (config == EGL_NO_CONFIG) {
NS_WARNING("Failed to find a compatible config.");
return nullptr;
@ -953,7 +962,7 @@ GLContextEGL::CreateEGLPBufferOffscreenContext(const mozilla::gfx::IntSize& size
}
RefPtr<GLContextEGL> gl = GLContextEGL::CreateGLContext(configCaps, nullptr, true,
RefPtr<GLContextEGL> gl = GLContextEGL::CreateGLContext(flags, configCaps, nullptr, true,
config, surface);
if (!gl) {
NS_WARNING("Failed to create GLContext from PBuffer");
@ -990,7 +999,7 @@ GLContextEGL::CreateEGLPixmapOffscreenContext(const mozilla::gfx::IntSize& size)
SurfaceCaps dummyCaps = SurfaceCaps::Any();
RefPtr<GLContextEGL> glContext =
GLContextEGL::CreateGLContext(dummyCaps,
GLContextEGL::CreateGLContext(CreateContextFlags::NONE, dummyCaps,
nullptr, true,
config, surface);
if (!glContext) {
@ -1019,7 +1028,7 @@ GLContextProviderEGL::CreateHeadless(CreateContextFlags flags)
mozilla::gfx::IntSize dummySize = mozilla::gfx::IntSize(16, 16);
SurfaceCaps dummyCaps = SurfaceCaps::Any();
return GLContextEGL::CreateEGLPBufferOffscreenContext(dummySize, dummyCaps);
return GLContextEGL::CreateEGLPBufferOffscreenContext(flags, dummySize, dummyCaps);
}
// Under EGL, on Android, pbuffers are supported fine, though
@ -1054,7 +1063,7 @@ GLContextProviderEGL::CreateOffscreen(const mozilla::gfx::IntSize& size,
minBackbufferCaps.stencil = false;
}
gl = GLContextEGL::CreateEGLPBufferOffscreenContext(size, minBackbufferCaps);
gl = GLContextEGL::CreateEGLPBufferOffscreenContext(flags, size, minBackbufferCaps);
if (!gl)
return nullptr;

View File

@ -52,6 +52,8 @@ enum class CreateContextFlags : int8_t {
FORCE_ENABLE_HARDWARE = 1 << 1,
/* Don't force discrete GPU to be used (if applicable) */
ALLOW_OFFLINE_RENDERER = 1 << 2,
// Ask for ES3 if possible
PREFER_ES3 = 1 << 3,
};
MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(CreateContextFlags)