зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1150944 - Add a flags parameter to GLContextProvider functions instead of a bool. r=jgilbert
This commit is contained in:
Родитель
a4cac5b663
Коммит
501c8bec02
|
@ -539,10 +539,10 @@ HasAcceleratedLayers(const nsCOMPtr<nsIGfxInfo>& gfxInfo)
|
|||
}
|
||||
|
||||
static already_AddRefed<GLContext>
|
||||
CreateHeadlessNativeGL(bool forceEnabled, const nsCOMPtr<nsIGfxInfo>& gfxInfo,
|
||||
bool requireCompatProfile, WebGLContext* webgl)
|
||||
CreateHeadlessNativeGL(CreateContextFlags flags, const nsCOMPtr<nsIGfxInfo>& gfxInfo,
|
||||
WebGLContext* webgl)
|
||||
{
|
||||
if (!forceEnabled &&
|
||||
if (!(flags & CreateContextFlags::FORCE_ENABLE_HARDWARE) &&
|
||||
IsFeatureInBlacklist(gfxInfo, nsIGfxInfo::FEATURE_WEBGL_OPENGL))
|
||||
{
|
||||
webgl->GenerateWarning("Refused to create native OpenGL context"
|
||||
|
@ -550,7 +550,7 @@ CreateHeadlessNativeGL(bool forceEnabled, const nsCOMPtr<nsIGfxInfo>& gfxInfo,
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
nsRefPtr<GLContext> gl = gl::GLContextProvider::CreateHeadless(requireCompatProfile);
|
||||
nsRefPtr<GLContext> gl = gl::GLContextProvider::CreateHeadless(flags);
|
||||
if (!gl) {
|
||||
webgl->GenerateWarning("Error during native OpenGL init.");
|
||||
return nullptr;
|
||||
|
@ -564,8 +564,8 @@ CreateHeadlessNativeGL(bool forceEnabled, const nsCOMPtr<nsIGfxInfo>& gfxInfo,
|
|||
// right now, we get ANGLE implicitly by using EGL on Windows.
|
||||
// Eventually, we want to be able to pick ANGLE-EGL or native EGL.
|
||||
static already_AddRefed<GLContext>
|
||||
CreateHeadlessANGLE(bool forceEnabled, const nsCOMPtr<nsIGfxInfo>& gfxInfo,
|
||||
bool requireCompatProfile, WebGLContext* webgl)
|
||||
CreateHeadlessANGLE(CreateContextFlags flags, const nsCOMPtr<nsIGfxInfo>& gfxInfo,
|
||||
WebGLContext* webgl)
|
||||
{
|
||||
nsRefPtr<GLContext> gl;
|
||||
|
||||
|
@ -583,13 +583,12 @@ CreateHeadlessANGLE(bool forceEnabled, const nsCOMPtr<nsIGfxInfo>& gfxInfo,
|
|||
}
|
||||
|
||||
static already_AddRefed<GLContext>
|
||||
CreateHeadlessEGL(bool forceEnabled, bool requireCompatProfile,
|
||||
WebGLContext* webgl)
|
||||
CreateHeadlessEGL(CreateContextFlags flags, WebGLContext* webgl)
|
||||
{
|
||||
nsRefPtr<GLContext> gl;
|
||||
|
||||
#ifdef ANDROID
|
||||
gl = gl::GLContextProviderEGL::CreateHeadless(requireCompatProfile);
|
||||
gl = gl::GLContextProviderEGL::CreateHeadless(flags);
|
||||
if (!gl) {
|
||||
webgl->GenerateWarning("Error during EGL OpenGL init.");
|
||||
return nullptr;
|
||||
|
@ -601,7 +600,7 @@ CreateHeadlessEGL(bool forceEnabled, bool requireCompatProfile,
|
|||
}
|
||||
|
||||
static already_AddRefed<GLContext>
|
||||
CreateHeadlessGL(bool forceEnabled, const nsCOMPtr<nsIGfxInfo>& gfxInfo,
|
||||
CreateHeadlessGL(CreateContextFlags flags, const nsCOMPtr<nsIGfxInfo>& gfxInfo,
|
||||
WebGLContext* webgl)
|
||||
{
|
||||
bool preferEGL = PR_GetEnv("MOZ_WEBGL_PREFER_EGL");
|
||||
|
@ -610,21 +609,21 @@ CreateHeadlessGL(bool forceEnabled, const nsCOMPtr<nsIGfxInfo>& gfxInfo,
|
|||
if (PR_GetEnv("MOZ_WEBGL_FORCE_OPENGL"))
|
||||
disableANGLE = true;
|
||||
|
||||
bool requireCompatProfile = webgl->IsWebGL2() ? false : true;
|
||||
if (!webgl->IsWebGL2()) {
|
||||
flags |= CreateContextFlags::REQUIRE_COMPAT_PROFILE;
|
||||
}
|
||||
|
||||
nsRefPtr<GLContext> gl;
|
||||
|
||||
if (preferEGL)
|
||||
gl = CreateHeadlessEGL(forceEnabled, requireCompatProfile, webgl);
|
||||
gl = CreateHeadlessEGL(flags, webgl);
|
||||
|
||||
if (!gl && !disableANGLE) {
|
||||
gl = CreateHeadlessANGLE(forceEnabled, gfxInfo, requireCompatProfile,
|
||||
webgl);
|
||||
gl = CreateHeadlessANGLE(flags, gfxInfo, webgl);
|
||||
}
|
||||
|
||||
if (!gl) {
|
||||
gl = CreateHeadlessNativeGL(forceEnabled, gfxInfo,
|
||||
requireCompatProfile, webgl);
|
||||
gl = CreateHeadlessNativeGL(flags, gfxInfo, webgl);
|
||||
}
|
||||
|
||||
return gl.forget();
|
||||
|
@ -749,7 +748,10 @@ WebGLContext::CreateOffscreenGL(bool forceEnabled)
|
|||
}
|
||||
#endif
|
||||
|
||||
gl = CreateHeadlessGL(forceEnabled, gfxInfo, this);
|
||||
CreateContextFlags flags = forceEnabled ? CreateContextFlags::FORCE_ENABLE_HARDWARE :
|
||||
CreateContextFlags::NONE;
|
||||
|
||||
gl = CreateHeadlessGL(flags, gfxInfo, this);
|
||||
|
||||
do {
|
||||
if (!gl)
|
||||
|
|
|
@ -186,7 +186,7 @@ protected:
|
|||
return true;
|
||||
}
|
||||
|
||||
mGLContext = GLContextProvider::CreateHeadless(false);
|
||||
mGLContext = GLContextProvider::CreateHeadless(CreateContextFlags::NONE);
|
||||
return mGLContext;
|
||||
}
|
||||
|
||||
|
|
|
@ -92,8 +92,7 @@ static nsRefPtr<GLContext> sPluginContext = nullptr;
|
|||
static bool EnsureGLContext()
|
||||
{
|
||||
if (!sPluginContext) {
|
||||
bool requireCompatProfile = true;
|
||||
sPluginContext = GLContextProvider::CreateHeadless(requireCompatProfile);
|
||||
sPluginContext = GLContextProvider::CreateHeadless(CreateContextFlags::REQUIRE_COMPAT_PROFILE);
|
||||
}
|
||||
|
||||
return sPluginContext != nullptr;
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include "GLContextTypes.h"
|
||||
#include "nsAutoPtr.h"
|
||||
#include "SurfaceTypes.h"
|
||||
#include "mozilla/TypedEnumBits.h"
|
||||
|
||||
#include "nsSize.h" // for gfx::IntSize (needed by GLContextProviderImpl.h below)
|
||||
|
||||
|
@ -17,6 +18,14 @@ class nsIWidget;
|
|||
namespace mozilla {
|
||||
namespace gl {
|
||||
|
||||
enum class CreateContextFlags : int8_t {
|
||||
NONE = 0,
|
||||
REQUIRE_COMPAT_PROFILE = 1 << 0,
|
||||
// Force the use of hardware backed GL, don't allow software implementations.
|
||||
FORCE_ENABLE_HARDWARE = 1 << 1,
|
||||
};
|
||||
MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(CreateContextFlags)
|
||||
|
||||
#define IN_GL_CONTEXT_PROVIDER_H
|
||||
|
||||
// Null is always there
|
||||
|
|
|
@ -253,7 +253,7 @@ GLContextProviderCGL::CreateForWindow(nsIWidget *aWidget)
|
|||
}
|
||||
|
||||
static already_AddRefed<GLContextCGL>
|
||||
CreateOffscreenFBOContext(bool requireCompatProfile)
|
||||
CreateOffscreenFBOContext(CreateContextFlags flags)
|
||||
{
|
||||
if (!sCGLLibrary.EnsureInitialized()) {
|
||||
return nullptr;
|
||||
|
@ -262,7 +262,7 @@ CreateOffscreenFBOContext(bool requireCompatProfile)
|
|||
ContextProfile profile;
|
||||
NSOpenGLContext* context = nullptr;
|
||||
|
||||
if (!requireCompatProfile) {
|
||||
if (!(flags & CreateContextFlags::REQUIRE_COMPAT_PROFILE)) {
|
||||
profile = ContextProfile::OpenGLCore;
|
||||
context = CreateWithFormat(kAttribs_offscreen_coreProfile);
|
||||
}
|
||||
|
@ -287,10 +287,10 @@ CreateOffscreenFBOContext(bool requireCompatProfile)
|
|||
}
|
||||
|
||||
already_AddRefed<GLContext>
|
||||
GLContextProviderCGL::CreateHeadless(bool requireCompatProfile, bool forceEnabled)
|
||||
GLContextProviderCGL::CreateHeadless(CreateContextFlags flags)
|
||||
{
|
||||
nsRefPtr<GLContextCGL> gl;
|
||||
gl = CreateOffscreenFBOContext(requireCompatProfile);
|
||||
gl = CreateOffscreenFBOContext(flags);
|
||||
if (!gl)
|
||||
return nullptr;
|
||||
|
||||
|
@ -305,9 +305,9 @@ GLContextProviderCGL::CreateHeadless(bool requireCompatProfile, bool forceEnable
|
|||
already_AddRefed<GLContext>
|
||||
GLContextProviderCGL::CreateOffscreen(const IntSize& size,
|
||||
const SurfaceCaps& caps,
|
||||
bool requireCompatProfile)
|
||||
CreateContextFlags flags)
|
||||
{
|
||||
nsRefPtr<GLContext> glContext = CreateHeadless(requireCompatProfile);
|
||||
nsRefPtr<GLContext> glContext = CreateHeadless(flags);
|
||||
if (!glContext->InitOffscreen(size, caps)) {
|
||||
NS_WARNING("Failed during InitOffscreen.");
|
||||
return nullptr;
|
||||
|
@ -330,7 +330,7 @@ GLContextProviderCGL::GetGlobalContext()
|
|||
// than 16x16 in size; also 16x16 is POT so that we can do
|
||||
// a FBO with it on older video cards. A FBO context for
|
||||
// sharing is preferred since it has no associated target.
|
||||
gGlobalContext = CreateOffscreenFBOContext(false);
|
||||
gGlobalContext = CreateOffscreenFBOContext(CreateContextFlags::NONE);
|
||||
if (!gGlobalContext || !static_cast<GLContextCGL*>(gGlobalContext.get())->Init()) {
|
||||
NS_WARNING("Couldn't init gGlobalContext.");
|
||||
gGlobalContext = nullptr;
|
||||
|
|
|
@ -933,9 +933,9 @@ GLContextEGL::CreateEGLPixmapOffscreenContext(const mozilla::gfx::IntSize& size)
|
|||
}
|
||||
|
||||
already_AddRefed<GLContext>
|
||||
GLContextProviderEGL::CreateHeadless(bool requireCompatProfile, bool forceEnabled)
|
||||
GLContextProviderEGL::CreateHeadless(CreateContextFlags flags)
|
||||
{
|
||||
if (!sEGLLibrary.EnsureInitialized(forceEnabled)) {
|
||||
if (!sEGLLibrary.EnsureInitialized(flags & CreateContextFlags::FORCE_ENABLE_HARDWARE)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -953,9 +953,9 @@ GLContextProviderEGL::CreateHeadless(bool requireCompatProfile, bool forceEnable
|
|||
already_AddRefed<GLContext>
|
||||
GLContextProviderEGL::CreateOffscreen(const mozilla::gfx::IntSize& size,
|
||||
const SurfaceCaps& caps,
|
||||
bool requireCompatProfile)
|
||||
CreateContextFlags flags)
|
||||
{
|
||||
nsRefPtr<GLContext> glContext = CreateHeadless(requireCompatProfile);
|
||||
nsRefPtr<GLContext> glContext = CreateHeadless(flags);
|
||||
if (!glContext)
|
||||
return nullptr;
|
||||
|
||||
|
|
|
@ -1215,7 +1215,7 @@ DONE_CREATING_PIXMAP:
|
|||
}
|
||||
|
||||
already_AddRefed<GLContext>
|
||||
GLContextProviderGLX::CreateHeadless(bool requireCompatProfile, bool forceEnabled)
|
||||
GLContextProviderGLX::CreateHeadless(CreateContextFlags)
|
||||
{
|
||||
IntSize dummySize = IntSize(16, 16);
|
||||
nsRefPtr<GLContext> glContext = CreateOffscreenPixmapContext(dummySize);
|
||||
|
@ -1228,9 +1228,9 @@ GLContextProviderGLX::CreateHeadless(bool requireCompatProfile, bool forceEnable
|
|||
already_AddRefed<GLContext>
|
||||
GLContextProviderGLX::CreateOffscreen(const IntSize& size,
|
||||
const SurfaceCaps& caps,
|
||||
bool requireCompatProfile)
|
||||
CreateContextFlags flags)
|
||||
{
|
||||
nsRefPtr<GLContext> glContext = CreateHeadless(requireCompatProfile);
|
||||
nsRefPtr<GLContext> glContext = CreateHeadless(flags);
|
||||
if (!glContext)
|
||||
return nullptr;
|
||||
|
||||
|
|
|
@ -54,19 +54,21 @@ public:
|
|||
* resource sharing can be avoided on the target platform, it will
|
||||
* be, in order to isolate the offscreen context.
|
||||
*
|
||||
* @param aSize The initial size of this offscreen context.
|
||||
* @param aFormat The ContextFormat for this offscreen context.
|
||||
* @param size The initial size of this offscreen context.
|
||||
* @param caps The SurfaceCaps for this offscreen context.
|
||||
* @param flags The set of CreateContextFlags to be used for this
|
||||
* offscreen context.
|
||||
*
|
||||
* @return Context to use for offscreen rendering
|
||||
*/
|
||||
static already_AddRefed<GLContext>
|
||||
CreateOffscreen(const mozilla::gfx::IntSize& size,
|
||||
const SurfaceCaps& caps,
|
||||
bool requireCompatProfile);
|
||||
CreateContextFlags flags);
|
||||
|
||||
// Just create a context. We'll add offscreen stuff ourselves.
|
||||
static already_AddRefed<GLContext>
|
||||
CreateHeadless(bool requireCompatProfile, bool forceEnabled = false);
|
||||
CreateHeadless(CreateContextFlags flags);
|
||||
|
||||
/**
|
||||
* Create wrapping Gecko GLContext for external gl context.
|
||||
|
|
|
@ -23,13 +23,13 @@ GLContextProviderNull::CreateWrappingExisting(void*, void*)
|
|||
already_AddRefed<GLContext>
|
||||
GLContextProviderNull::CreateOffscreen(const gfx::IntSize&,
|
||||
const SurfaceCaps&,
|
||||
bool)
|
||||
CreateContextFlags)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
already_AddRefed<GLContext>
|
||||
GLContextProviderNull::CreateHeadless(bool)
|
||||
GLContextProviderNull::CreateHeadless(CreateContextFlags)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
|
|
@ -607,7 +607,7 @@ CreateWindowOffscreenContext()
|
|||
}
|
||||
|
||||
already_AddRefed<GLContext>
|
||||
GLContextProviderWGL::CreateHeadless(bool requireCompatProfile, bool forceEnabled)
|
||||
GLContextProviderWGL::CreateHeadless(CreateContextFlags)
|
||||
{
|
||||
if (!sWGLLib.EnsureInitialized()) {
|
||||
return nullptr;
|
||||
|
@ -642,9 +642,9 @@ GLContextProviderWGL::CreateHeadless(bool requireCompatProfile, bool forceEnable
|
|||
already_AddRefed<GLContext>
|
||||
GLContextProviderWGL::CreateOffscreen(const IntSize& size,
|
||||
const SurfaceCaps& caps,
|
||||
bool requireCompatProfile)
|
||||
CreateContextFlags flags)
|
||||
{
|
||||
nsRefPtr<GLContext> glContext = CreateHeadless(requireCompatProfile);
|
||||
nsRefPtr<GLContext> glContext = CreateHeadless(flags);
|
||||
if (!glContext)
|
||||
return nullptr;
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ GLImage::GetAsSourceSurface()
|
|||
MOZ_ASSERT(NS_IsMainThread(), "Should be on the main thread");
|
||||
|
||||
if (!sSnapshotContext) {
|
||||
sSnapshotContext = GLContextProvider::CreateHeadless(false);
|
||||
sSnapshotContext = GLContextProvider::CreateHeadless(CreateContextFlags::NONE);
|
||||
if (!sSnapshotContext) {
|
||||
NS_WARNING("Failed to create snapshot GLContext");
|
||||
return nullptr;
|
||||
|
|
|
@ -126,9 +126,8 @@ CompositorOGL::CreateContext()
|
|||
caps.preserve = false;
|
||||
caps.bpp16 = gfxPlatform::GetPlatform()->GetOffscreenFormat() == gfxImageFormat::RGB16_565;
|
||||
|
||||
bool requireCompatProfile = true;
|
||||
context = GLContextProvider::CreateOffscreen(mSurfaceSize,
|
||||
caps, requireCompatProfile);
|
||||
caps, CreateContextFlags::REQUIRE_COMPAT_PROFILE);
|
||||
}
|
||||
|
||||
if (!context) {
|
||||
|
|
|
@ -45,7 +45,8 @@ public:
|
|||
caps.preserve = false;
|
||||
caps.bpp16 = false;
|
||||
nsRefPtr<GLContext> context = GLContextProvider::CreateOffscreen(
|
||||
IntSize(gCompWidth, gCompHeight), caps, true);
|
||||
IntSize(gCompWidth, gCompHeight), caps,
|
||||
CreateContextFlags::REQUIRE_COMPAT_PROFILE);
|
||||
return context.forget().take();
|
||||
}
|
||||
return nullptr;
|
||||
|
|
|
@ -122,6 +122,7 @@ void ShutdownTileCache();
|
|||
|
||||
using namespace mozilla;
|
||||
using namespace mozilla::layers;
|
||||
using namespace mozilla::gl;
|
||||
|
||||
gfxPlatform *gPlatform = nullptr;
|
||||
static bool gEverInitialized = false;
|
||||
|
@ -494,7 +495,7 @@ gfxPlatform::Init()
|
|||
#endif
|
||||
|
||||
#ifdef MOZ_GL_DEBUG
|
||||
mozilla::gl::GLContext::StaticInit();
|
||||
GLContext::StaticInit();
|
||||
#endif
|
||||
|
||||
InitLayersAccelerationPrefs();
|
||||
|
@ -542,11 +543,11 @@ gfxPlatform::Init()
|
|||
gPlatform->mFontPrefsObserver = new FontPrefsObserver();
|
||||
Preferences::AddStrongObservers(gPlatform->mFontPrefsObserver, kObservedPrefs);
|
||||
|
||||
mozilla::gl::GLContext::PlatformStartup();
|
||||
GLContext::PlatformStartup();
|
||||
|
||||
#ifdef MOZ_WIDGET_ANDROID
|
||||
// Texture pool init
|
||||
mozilla::gl::TexturePoolOGL::Init();
|
||||
TexturePoolOGL::Init();
|
||||
#endif
|
||||
|
||||
#ifdef MOZ_WIDGET_GONK
|
||||
|
@ -626,11 +627,11 @@ gfxPlatform::Shutdown()
|
|||
|
||||
#ifdef MOZ_WIDGET_ANDROID
|
||||
// Shut down the texture pool
|
||||
mozilla::gl::TexturePoolOGL::Shutdown();
|
||||
TexturePoolOGL::Shutdown();
|
||||
#endif
|
||||
|
||||
// Shut down the default GL context provider.
|
||||
mozilla::gl::GLContextProvider::Shutdown();
|
||||
GLContextProvider::Shutdown();
|
||||
|
||||
#if defined(XP_WIN)
|
||||
// The above shutdown calls operate on the available context providers on
|
||||
|
@ -639,7 +640,7 @@ gfxPlatform::Shutdown()
|
|||
// We should only support the default GL provider on Windows; then, this
|
||||
// could go away. Unfortunately, we currently support WGL (the default) for
|
||||
// WebGL on Optimus.
|
||||
mozilla::gl::GLContextProviderEGL::Shutdown();
|
||||
GLContextProviderEGL::Shutdown();
|
||||
#endif
|
||||
|
||||
// This is a bit iffy - we're assuming that we were the ones that set the
|
||||
|
@ -1078,7 +1079,7 @@ gfxPlatform::InitializeSkiaCacheLimits()
|
|||
}
|
||||
}
|
||||
|
||||
mozilla::gl::SkiaGLGlue*
|
||||
SkiaGLGlue*
|
||||
gfxPlatform::GetSkiaGLGlue()
|
||||
{
|
||||
#ifdef USE_SKIA_GPU
|
||||
|
@ -1088,14 +1089,13 @@ gfxPlatform::GetSkiaGLGlue()
|
|||
* FIXME: This should be stored in TLS or something, since there needs to be one for each thread using it. As it
|
||||
* stands, this only works on the main thread.
|
||||
*/
|
||||
bool requireCompatProfile = true;
|
||||
nsRefPtr<mozilla::gl::GLContext> glContext;
|
||||
glContext = mozilla::gl::GLContextProvider::CreateHeadless(requireCompatProfile);
|
||||
nsRefPtr<GLContext> glContext;
|
||||
glContext = GLContextProvider::CreateHeadless(CreateContextFlags::REQUIRE_COMPAT_PROFILE);
|
||||
if (!glContext) {
|
||||
printf_stderr("Failed to create GLContext for SkiaGL!\n");
|
||||
return nullptr;
|
||||
}
|
||||
mSkiaGlue = new mozilla::gl::SkiaGLGlue(glContext);
|
||||
mSkiaGlue = new SkiaGLGlue(glContext);
|
||||
MOZ_ASSERT(mSkiaGlue->GetGrContext(), "No GrContext");
|
||||
InitializeSkiaCacheLimits();
|
||||
}
|
||||
|
|
|
@ -75,8 +75,7 @@ public:
|
|||
}
|
||||
|
||||
nsRefPtr<gl::GLContext> gl;
|
||||
bool requireCompatProfile = true;
|
||||
gl = gl::GLContextProvider::CreateHeadless(requireCompatProfile);
|
||||
gl = gl::GLContextProvider::CreateHeadless(gl::CreateContextFlags::REQUIRE_COMPAT_PROFILE);
|
||||
|
||||
if (!gl) {
|
||||
// Setting mReady to true here means that we won't retry. Everything will
|
||||
|
|
Загрузка…
Ссылка в новой задаче