Bug 743755 - Remove OSMesa support r=bjacob

This commit is contained in:
Andrew Quartey 2012-09-07 18:35:22 -04:00
parent 5cce115650
commit 0e25c1e408
7 changed files with 2 additions and 304 deletions

View File

@ -385,8 +385,6 @@ WebGLContext::SetDimensions(int32_t width, int32_t height)
// Get some prefs for some preferred/overriden things
NS_ENSURE_TRUE(Preferences::GetRootBranch(), NS_ERROR_FAILURE);
bool forceOSMesa =
Preferences::GetBool("webgl.force_osmesa", false);
#ifdef XP_WIN
bool preferEGL =
Preferences::GetBool("webgl.prefer-egl", false);
@ -507,16 +505,6 @@ WebGLContext::SetDimensions(int32_t width, int32_t height)
}
#endif
// if we're forcing osmesa, do it first
if (forceOSMesa) {
gl = gl::GLContextProviderOSMesa::CreateOffscreen(gfxIntSize(width, height), format);
if (!gl || !InitAndValidateGL()) {
GenerateWarning("OSMesa forced, but creating context failed -- aborting!");
return NS_ERROR_FAILURE;
}
GenerateWarning("Using software rendering via OSMesa (THIS WILL BE SLOW)");
}
#ifdef XP_WIN
// if we want EGL, try it now
if (!gl && (preferEGL || useANGLE) && !preferOpenGL) {
@ -542,19 +530,6 @@ WebGLContext::SetDimensions(int32_t width, int32_t height)
}
}
// finally, try OSMesa
if (!gl) {
gl = gl::GLContextProviderOSMesa::CreateOffscreen(gfxIntSize(width, height), format);
if (gl) {
if (!InitAndValidateGL()) {
GenerateWarning("Error during OSMesa initialization");
return NS_ERROR_FAILURE;
} else {
GenerateWarning("Using software rendering via OSMesa (THIS WILL BE SLOW)");
}
}
}
if (!gl) {
GenerateWarning("Can't get a usable WebGL context");
return NS_ERROR_FAILURE;

View File

@ -585,8 +585,7 @@ public:
ContextTypeWGL,
ContextTypeCGL,
ContextTypeGLX,
ContextTypeEGL,
ContextTypeOSMesa
ContextTypeEGL
};
virtual GLContextType GetContextType() { return ContextTypeUnknown; }

View File

@ -19,15 +19,11 @@ namespace gl {
#define IN_GL_CONTEXT_PROVIDER_H
// Null and OSMesa are always there
// Null is always there
#define GL_CONTEXT_PROVIDER_NAME GLContextProviderNull
#include "GLContextProviderImpl.h"
#undef GL_CONTEXT_PROVIDER_NAME
#define GL_CONTEXT_PROVIDER_NAME GLContextProviderOSMesa
#include "GLContextProviderImpl.h"
#undef GL_CONTEXT_PROVIDER_NAME
#ifdef XP_WIN
#define GL_CONTEXT_PROVIDER_NAME GLContextProviderWGL
#include "GLContextProviderImpl.h"

View File

@ -1,266 +0,0 @@
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* 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/. */
#include "GLContextProvider.h"
#include "GLContext.h"
#include "GLLibraryLoader.h"
#include "nsDebug.h"
#include "nsString.h"
#include "nsIWidget.h"
#include "nsDirectoryServiceUtils.h"
#include "nsAppDirectoryServiceDefs.h"
#include "nsIConsoleService.h"
#include "mozilla/Preferences.h"
#include "gfxASurface.h"
#include "gfxImageSurface.h"
#include "gfxCrashReporterUtils.h"
// from GL/osmesa.h. We don't include that file so as to avoid having a build-time dependency on OSMesa.
#define OSMESA_RGBA GL_RGBA
#define OSMESA_BGRA 0x1
#define OSMESA_ARGB 0x2
#define OSMESA_RGB GL_RGB
#define OSMESA_BGR 0x4
#define OSMESA_RGB_565 0x5
#define OSMESA_Y_UP 0x11
namespace mozilla {
namespace gl {
static void LogMessage(const char *msg)
{
nsCOMPtr<nsIConsoleService> console(do_GetService(NS_CONSOLESERVICE_CONTRACTID));
if (console) {
console->LogStringMessage(NS_ConvertUTF8toUTF16(nsDependentCString(msg)).get());
fprintf(stderr, "%s\n", msg);
}
}
typedef void* PrivateOSMesaContext;
class OSMesaLibrary
{
public:
OSMesaLibrary() : mInitialized(false), mOSMesaLibrary(nullptr) {}
typedef PrivateOSMesaContext (GLAPIENTRY * PFNOSMESACREATECONTEXTEXT) (GLenum, GLint, GLint, GLint, PrivateOSMesaContext);
typedef void (GLAPIENTRY * PFNOSMESADESTROYCONTEXT) (PrivateOSMesaContext);
typedef bool (GLAPIENTRY * PFNOSMESAMAKECURRENT) (PrivateOSMesaContext, void *, GLenum, GLsizei, GLsizei);
typedef PrivateOSMesaContext (GLAPIENTRY * PFNOSMESAGETCURRENTCONTEXT) (void);
typedef void (GLAPIENTRY * PFNOSMESAPIXELSTORE) (GLint, GLint);
typedef PRFuncPtr (GLAPIENTRY * PFNOSMESAGETPROCADDRESS) (const char*);
PFNOSMESACREATECONTEXTEXT fCreateContextExt;
PFNOSMESADESTROYCONTEXT fDestroyContext;
PFNOSMESAMAKECURRENT fMakeCurrent;
PFNOSMESAGETCURRENTCONTEXT fGetCurrentContext;
PFNOSMESAPIXELSTORE fPixelStore;
PFNOSMESAGETPROCADDRESS fGetProcAddress;
bool EnsureInitialized();
private:
bool mInitialized;
PRLibrary *mOSMesaLibrary;
};
OSMesaLibrary sOSMesaLibrary;
bool
OSMesaLibrary::EnsureInitialized()
{
if (mInitialized)
return true;
nsAdoptingCString osmesalib = Preferences::GetCString("webgl.osmesalib");
if (osmesalib.IsEmpty()) {
return false;
}
mOSMesaLibrary = PR_LoadLibrary(osmesalib.get());
if (!mOSMesaLibrary) {
LogMessage("Couldn't open OSMesa lib for software rendering -- webgl.osmesalib path is incorrect, or not a valid shared library");
return false;
}
GLLibraryLoader::SymLoadStruct symbols[] = {
{ (PRFuncPtr*) &fCreateContextExt, { "OSMesaCreateContextExt", NULL } },
{ (PRFuncPtr*) &fMakeCurrent, { "OSMesaMakeCurrent", NULL } },
{ (PRFuncPtr*) &fPixelStore, { "OSMesaPixelStore", NULL } },
{ (PRFuncPtr*) &fDestroyContext, { "OSMesaDestroyContext", NULL } },
{ (PRFuncPtr*) &fGetCurrentContext, { "OSMesaGetCurrentContext", NULL } },
{ (PRFuncPtr*) &fMakeCurrent, { "OSMesaMakeCurrent", NULL } },
{ (PRFuncPtr*) &fGetProcAddress, { "OSMesaGetProcAddress", NULL } },
{ NULL, { NULL } }
};
if (!GLLibraryLoader::LoadSymbols(mOSMesaLibrary, &symbols[0])) {
LogMessage("Couldn't find required entry points in OSMesa libary");
return false;
}
mInitialized = true;
return true;
}
class GLContextOSMesa : public GLContext
{
public:
GLContextOSMesa(const ContextFormat& aFormat)
: GLContext(aFormat, true, nullptr),
mThebesSurface(nullptr),
mContext(nullptr)
{
}
~GLContextOSMesa()
{
MarkDestroyed();
if (mContext)
sOSMesaLibrary.fDestroyContext(mContext);
}
GLContextType GetContextType() {
return ContextTypeOSMesa;
}
bool Init(const gfxIntSize &aSize)
{
int osmesa_format = -1;
int gfxasurface_imageformat = -1;
bool format_accepted = false;
if (mCreationFormat.red > 0 &&
mCreationFormat.green > 0 &&
mCreationFormat.blue > 0 &&
mCreationFormat.red <= 8 &&
mCreationFormat.green <= 8 &&
mCreationFormat.blue <= 8)
{
if (mCreationFormat.alpha == 0) {
// we can't use OSMESA_BGR because it is packed 24 bits per pixel.
// So we use OSMESA_BGRA and have to use ImageFormatRGB24
// to make sure that the dummy alpha channel is ignored.
osmesa_format = OSMESA_BGRA;
gfxasurface_imageformat = gfxASurface::ImageFormatRGB24;
format_accepted = true;
} else if (mCreationFormat.alpha <= 8) {
osmesa_format = OSMESA_BGRA;
gfxasurface_imageformat = gfxASurface::ImageFormatARGB32;
format_accepted = true;
}
}
if (!format_accepted) {
NS_WARNING("Pixel format not supported with OSMesa.");
return false;
}
mThebesSurface = new gfxImageSurface(aSize, gfxASurface::gfxImageFormat(gfxasurface_imageformat));
if (mThebesSurface->CairoStatus() != 0) {
NS_WARNING("image surface failed");
return false;
}
mContext = sOSMesaLibrary.fCreateContextExt(osmesa_format, mCreationFormat.depth, mCreationFormat.stencil, 0, NULL);
if (!mContext) {
NS_WARNING("OSMesaCreateContextExt failed!");
return false;
}
if (!MakeCurrent()) return false;
if (!SetupLookupFunction()) return false;
// OSMesa's different from the other GL providers, it renders to an image surface, not to a pbuffer
sOSMesaLibrary.fPixelStore(OSMESA_Y_UP, 0);
return InitWithPrefix("gl", true);
}
bool MakeCurrentImpl(bool aForce = false)
{
bool succeeded
= sOSMesaLibrary.fMakeCurrent(mContext, mThebesSurface->Data(),
LOCAL_GL_UNSIGNED_BYTE,
mThebesSurface->Width(),
mThebesSurface->Height());
NS_ASSERTION(succeeded, "Failed to make OSMesa context current!");
return succeeded;
}
virtual bool IsCurrent() {
return sOSMesaLibrary.fGetCurrentContext() == mContext;
}
bool SetupLookupFunction()
{
mLookupFunc = (PlatformLookupFunction)sOSMesaLibrary.fGetProcAddress;
return true;
}
void *GetNativeData(NativeDataType aType)
{
switch (aType) {
case NativeImageSurface:
return mThebesSurface.get();
default:
return nullptr;
}
}
bool SupportsRobustness()
{
return false;
}
private:
nsRefPtr<gfxImageSurface> mThebesSurface;
PrivateOSMesaContext mContext;
};
already_AddRefed<GLContext>
GLContextProviderOSMesa::CreateForWindow(nsIWidget *aWidget)
{
return nullptr;
}
already_AddRefed<GLContext>
GLContextProviderOSMesa::CreateOffscreen(const gfxIntSize& aSize,
const ContextFormat& aFormat,
const ContextFlags)
{
if (!sOSMesaLibrary.EnsureInitialized()) {
return nullptr;
}
ContextFormat actualFormat(aFormat);
actualFormat.samples = 0;
nsRefPtr<GLContextOSMesa> glContext = new GLContextOSMesa(actualFormat);
if (!glContext->Init(aSize))
{
return nullptr;
}
return glContext.forget();
}
GLContext *
GLContextProviderOSMesa::GetGlobalContext(const ContextFlags)
{
return nullptr;
}
void
GLContextProviderOSMesa::Shutdown()
{
}
} /* namespace gl */
} /* namespace mozilla */

View File

@ -47,7 +47,6 @@ CPPSRCS = \
GLContext.cpp \
GLContextUtils.cpp \
GLLibraryLoader.cpp \
GLContextProviderOSMesa.cpp \
$(NULL)
GL_PROVIDER = Null

View File

@ -390,9 +390,6 @@ gfxPlatform::Shutdown()
// Shut down the default GL context provider.
mozilla::gl::GLContextProvider::Shutdown();
// We always have OSMesa at least potentially available; shut it down too.
mozilla::gl::GLContextProviderOSMesa::Shutdown();
#if defined(XP_WIN)
// The above shutdown calls operate on the available context providers on
// most platforms. Windows is a "special snowflake", though, and has three

View File

@ -3542,8 +3542,6 @@ pref("image.mem.max_decoded_image_kb", 51200);
pref("webgl.force-enabled", false);
pref("webgl.disabled", false);
pref("webgl.shader_validator", true);
pref("webgl.force_osmesa", false);
pref("webgl.osmesalib", "");
pref("webgl.prefer-native-gl", false);
pref("webgl.min_capability_mode", false);
pref("webgl.disable-extensions", false);