Skip to content

Commit

Permalink
Backed out changeset e74b9560a9d4 (bug 1528396) for causing mochitest…
Browse files Browse the repository at this point in the history
… webgl failures on test_pixel_pack_buffer. CLOSED TREE
  • Loading branch information
CosminSabou committed Feb 21, 2019
1 parent 4f6a2ea commit a36e530
Show file tree
Hide file tree
Showing 19 changed files with 665 additions and 649 deletions.
648 changes: 326 additions & 322 deletions gfx/gl/GLContext.cpp

Large diffs are not rendered by default.

25 changes: 15 additions & 10 deletions gfx/gl/GLContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,8 @@ enum class GLRenderer {
Other
};

class GLContext : public GenericAtomicRefCounted,
class GLContext : public GLLibraryLoader,
public GenericAtomicRefCounted,
public SupportsWeakPtr<GLContext> {
public:
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(GLContext)
Expand Down Expand Up @@ -3310,8 +3311,8 @@ class GLContext : public GenericAtomicRefCounted,
// -----------------------------------------------------------------------------
// Constructor
protected:
explicit GLContext(CreateContextFlags flags,
const SurfaceCaps& caps, GLContext* sharedContext = nullptr,
explicit GLContext(CreateContextFlags flags, const SurfaceCaps& caps,
GLContext* sharedContext = nullptr,
bool isOffscreen = false, bool canUseTLSIsCurrent = false);

// -----------------------------------------------------------------------------
Expand All @@ -3332,6 +3333,10 @@ class GLContext : public GenericAtomicRefCounted,
typedef gfx::SurfaceFormat SurfaceFormat;

public:
virtual bool Init() = 0;

virtual bool SetupLookupFunction() = 0;

virtual void ReleaseSurface() {}

bool IsDestroyed() const {
Expand Down Expand Up @@ -3366,8 +3371,6 @@ class GLContext : public GenericAtomicRefCounted,
*/
virtual bool ReleaseTexImage() { return false; }

virtual Maybe<SymbolLoader> GetSymbolLoader() const = 0;

// Before reads from offscreen texture
void GuaranteeResolve();

Expand Down Expand Up @@ -3561,14 +3564,16 @@ class GLContext : public GenericAtomicRefCounted,

bool IsOffscreenSizeAllowed(const gfx::IntSize& aSize) const;

virtual bool Init();
protected:
bool InitWithPrefix(const char* prefix, bool trygl);

private:
bool InitImpl();
void LoadMoreSymbols(const SymbolLoader& loader);
bool LoadExtSymbols(const SymbolLoader& loader, const SymLoadStruct* list,
bool InitWithPrefixImpl(const char* prefix, bool trygl);
void LoadMoreSymbols(const char* prefix, bool trygl);
bool LoadExtSymbols(const char* prefix, bool trygl, const SymLoadStruct* list,
GLExtensions ext);
bool LoadFeatureSymbols(const SymbolLoader& loader, const SymLoadStruct* list, GLFeature feature);
bool LoadFeatureSymbols(const char* prefix, bool trygl,
const SymLoadStruct* list, GLFeature feature);

protected:
void InitExtensions();
Expand Down
6 changes: 4 additions & 2 deletions gfx/gl/GLContextCGL.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ class GLContextCGL : public GLContext {
return static_cast<GLContextCGL*>(gl);
}

bool Init() override;

NSOpenGLContext* GetNSOpenGLContext() const { return mContext; }
CGLContextObj GetCGLContext() const;

Expand All @@ -50,13 +52,13 @@ class GLContextCGL : public GLContext {

virtual GLenum GetPreferredARGB32Format() const override;

virtual bool SetupLookupFunction() override;

virtual bool IsDoubleBuffered() const override;

virtual bool SwapBuffers() override;

virtual void GetWSIInfo(nsCString* const out) const override;

Maybe<SymbolLoader> GetSymbolLoader() const override;
};

} // namespace gl
Expand Down
4 changes: 3 additions & 1 deletion gfx/gl/GLContextEAGL.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class GLContextEAGL : public GLContext {
return static_cast<GLContextEAGL*>(gl);
}

bool Init() override;

bool AttachToWindow(nsIWidget* aWidget);

EAGLContext* GetEAGLContext() const { return mContext; }
Expand All @@ -45,7 +47,7 @@ class GLContextEAGL : public GLContext {

virtual bool IsCurrentImpl() const override;

Maybe<SymbolLoader> GetSymbolLoader() const override;
virtual bool SetupLookupFunction() override;

virtual bool IsDoubleBuffered() const override;

Expand Down
2 changes: 1 addition & 1 deletion gfx/gl/GLContextEGL.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class GLContextEGL : public GLContext {

virtual void ReleaseSurface() override;

Maybe<SymbolLoader> GetSymbolLoader() const override;
virtual bool SetupLookupFunction() override;

virtual bool SwapBuffers() override;

Expand Down
2 changes: 1 addition & 1 deletion gfx/gl/GLContextGLX.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class GLContextGLX : public GLContext {

virtual bool IsCurrentImpl() const override;

Maybe<SymbolLoader> GetSymbolLoader() const override;
virtual bool SetupLookupFunction() override;

virtual bool IsDoubleBuffered() const override;

Expand Down
16 changes: 8 additions & 8 deletions gfx/gl/GLContextProviderCGL.mm
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ bool UseDoubleBufferedWindows() const {
return mUseDoubleBufferedWindows;
}

const auto& Library() const { return mOGLLibrary; }

private:
bool mInitialized = false;
bool mUseDoubleBufferedWindows = true;
Expand All @@ -84,6 +82,12 @@ bool UseDoubleBufferedWindows() const {
}
}

bool GLContextCGL::Init() {
if (!InitWithPrefix("gl", true)) return false;

return true;
}

CGLContextObj GLContextCGL::GetCGLContext() const {
return static_cast<CGLContextObj>([mContext CGLContextObj]);
}
Expand All @@ -108,6 +112,8 @@ bool UseDoubleBufferedWindows() const {

GLenum GLContextCGL::GetPreferredARGB32Format() const { return LOCAL_GL_BGRA; }

bool GLContextCGL::SetupLookupFunction() { return false; }

bool GLContextCGL::IsDoubleBuffered() const { return sCGLLibrary.UseDoubleBufferedWindows(); }

bool GLContextCGL::SwapBuffers() {
Expand All @@ -119,12 +125,6 @@ bool UseDoubleBufferedWindows() const {

void GLContextCGL::GetWSIInfo(nsCString* const out) const { out->AppendLiteral("CGL"); }

Maybe<SymbolLoader> GLContextCGL::GetSymbolLoader() const
{
const auto& lib = sCGLLibrary.Library();
return Some(SymbolLoader(*lib));
}

already_AddRefed<GLContext> GLContextProviderCGL::CreateWrappingExisting(void*, void*) {
return nullptr;
}
Expand Down
19 changes: 7 additions & 12 deletions gfx/gl/GLContextProviderEAGL.mm
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@
}
}

bool GLContextEAGL::Init() {
if (!InitWithPrefix("gl", true)) return false;

return true;
}

bool GLContextEAGL::AttachToWindow(nsIWidget* aWidget) {
// This should only be called once
MOZ_ASSERT(!mBackbufferFB && !mBackbufferRB);
Expand Down Expand Up @@ -100,18 +106,7 @@

bool GLContextEAGL::IsCurrentImpl() const { return [EAGLContext currentContext] == mContext; }

static PRFuncPtr GLAPIENTRY GetLoadedProcAddress(const char* const name) {
PRLibrary* lib = nullptr;
const auto& ret = PR_FindFunctionSymbolAndLibrary(name, &leakedLibRef);
if (lib) {
PR_UnloadLibrary(lib);
}
return ret;
}

Maybe<SymbolLoader> GLContextEAGL::GetSymbolLoader() const {
return Some(SymbolLoader(&GetLoadedProcAddress));
}
bool GLContextEAGL::SetupLookupFunction() { return false; }

bool GLContextEAGL::IsDoubleBuffered() const { return true; }

Expand Down
22 changes: 19 additions & 3 deletions gfx/gl/GLContextProviderEGL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,22 @@ GLContextEGL::~GLContextEGL() {
}

bool GLContextEGL::Init() {
if (!GLContext::Init()) return false;
#if defined(ANDROID)
// We can't use LoadApitraceLibrary here because the GLContext
// expects its own handle to the GL library
if (!OpenLibrary(APITRACE_LIB))
#endif
if (!OpenLibrary(GLES2_LIB)) {
#if defined(XP_UNIX)
if (!OpenLibrary(GLES2_LIB2)) {
NS_WARNING("Couldn't load GLES2 LIB.");
return false;
}
#endif
}

SetupLookupFunction();
if (!InitWithPrefix("gl", true)) return false;

bool current = MakeCurrent();
if (!current) {
Expand Down Expand Up @@ -486,8 +501,9 @@ void GLContextEGL::ReleaseSurface() {
mSurface = EGL_NO_SURFACE;
}

Maybe<SymbolLoader> GLContextEGL::GetSymbolLoader() const {
return mEgl->GetSymbolLoader();
bool GLContextEGL::SetupLookupFunction() {
mLookupFunc = mEgl->GetLookupFunction();
return true;
}

bool GLContextEGL::SwapBuffers() {
Expand Down
70 changes: 36 additions & 34 deletions gfx/gl/GLContextProviderGLX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,20 @@ bool GLXLibrary::EnsureInitialized() {
PR_SetEnv("force_s3tc_enable=true");

if (!mOGLLibrary) {
const char* libGLfilename = nullptr;
bool forceFeatureReport = false;

// see e.g. bug 608526: it is intrinsically interesting to know whether we
// have dynamically linked to libGL.so.1 because at least the NVIDIA
// implementation requires an executable stack, which causes mprotect calls,
// which trigger glibc bug
// http://sourceware.org/bugzilla/show_bug.cgi?id=12225
const char* libGLfilename = "libGL.so.1";
#ifdef __OpenBSD__
libGLfilename = "libGL.so";
#else
libGLfilename = "libGL.so.1";
#endif

const bool forceFeatureReport = false;
ScopedGfxFeatureReporter reporter(libGLfilename, forceFeatureReport);
mOGLLibrary = PR_LoadLibrary(libGLfilename);
if (!mOGLLibrary) {
Expand All @@ -98,18 +101,16 @@ bool GLXLibrary::EnsureInitialized() {
mDebug = true;
}

#define SYMBOL(X) \
{ \
(PRFuncPtr*)&mSymbols.f##X, { \
{ "glX" #X } \
} \
#define SYMBOL(X) \
{ \
(PRFuncPtr*)&mSymbols.f##X, { "glX" #X, nullptr } \
}
#define END_OF_SYMBOLS \
{ \
nullptr, {} \
#define END_OF_SYMBOLS \
{ \
nullptr, { nullptr } \
}

const SymLoadStruct symbols[] = {
const GLLibraryLoader::SymLoadStruct symbols[] = {
/* functions that were in GLX 1.0 */
SYMBOL(DestroyContext),
SYMBOL(MakeCurrent),
Expand All @@ -136,17 +137,12 @@ bool GLXLibrary::EnsureInitialized() {

// Core in GLX 1.4, ARB extension before.
{(PRFuncPtr*)&mSymbols.fGetProcAddress,
{{"glXGetProcAddress", "glXGetProcAddressARB"}}},
{"glXGetProcAddress", "glXGetProcAddressARB", nullptr}},
END_OF_SYMBOLS};

{
const SymbolLoader libLoader(*mOGLLibrary);
if (!libLoader.LoadSymbols(symbols)) {
NS_WARNING("Couldn't load required GLX symbols.");
return false;
}
if (!GLLibraryLoader::LoadSymbols(mOGLLibrary, symbols)) {
NS_WARNING("Couldn't load required GLX symbols.");
return false;
}
const SymbolLoader pfnLoader(mSymbols.fGetProcAddress);

Display* display = DefaultXDisplay();
int screen = DefaultScreen(display);
Expand All @@ -159,24 +155,29 @@ bool GLXLibrary::EnsureInitialized() {
}
}

const SymLoadStruct symbols_texturefrompixmap[] = {
const GLLibraryLoader::SymLoadStruct symbols_texturefrompixmap[] = {
SYMBOL(BindTexImageEXT), SYMBOL(ReleaseTexImageEXT), END_OF_SYMBOLS};

const SymLoadStruct symbols_createcontext[] = {
const GLLibraryLoader::SymLoadStruct symbols_createcontext[] = {
SYMBOL(CreateContextAttribsARB), END_OF_SYMBOLS};

const SymLoadStruct symbols_videosync[] = {
const GLLibraryLoader::SymLoadStruct symbols_videosync[] = {
SYMBOL(GetVideoSyncSGI), SYMBOL(WaitVideoSyncSGI), END_OF_SYMBOLS};

const SymLoadStruct symbols_swapcontrol[] = {SYMBOL(SwapIntervalEXT),
END_OF_SYMBOLS};
const GLLibraryLoader::SymLoadStruct symbols_swapcontrol[] = {
SYMBOL(SwapIntervalEXT), END_OF_SYMBOLS};

const auto fnLoadSymbols = [&](const SymLoadStruct* symbols) {
if (pfnLoader.LoadSymbols(symbols)) return true;
const auto lookupFunction =
(GLLibraryLoader::PlatformLookupFunction)mSymbols.fGetProcAddress;

ClearSymbols(symbols);
return false;
};
const auto fnLoadSymbols =
[&](const GLLibraryLoader::SymLoadStruct* symbols) {
if (GLLibraryLoader::LoadSymbols(mOGLLibrary, symbols, lookupFunction))
return true;

GLLibraryLoader::ClearSymbols(symbols);
return false;
};

const char* clientVendor = fGetClientString(display, LOCAL_GLX_VENDOR);
const char* serverVendor =
Expand Down Expand Up @@ -570,7 +571,8 @@ GLContextGLX::~GLContextGLX() {
}

bool GLContextGLX::Init() {
if (!GLContext::Init()) {
SetupLookupFunction();
if (!InitWithPrefix("gl", true)) {
return false;
}

Expand Down Expand Up @@ -607,9 +609,9 @@ bool GLContextGLX::IsCurrentImpl() const {
return mGLX->fGetCurrentContext() == mContext;
}

Maybe<SymbolLoader> GLContextGLX::GetSymbolLoader() const {
const auto pfn = sGLXLibrary.GetGetProcAddress();
return Some(SymbolLoader(pfn));
bool GLContextGLX::SetupLookupFunction() {
mLookupFunc = (PlatformLookupFunction)sGLXLibrary.GetGetProcAddress();
return true;
}

bool GLContextGLX::IsDoubleBuffered() const { return mDoubleBuffered; }
Expand Down
Loading

0 comments on commit a36e530

Please sign in to comment.