Bug 1390386 - Make MakeCurrent const. - r=daoshengmu
MozReview-Commit-ID: 3m3T6iMgZOc
--- a/gfx/gl/GLContext.cpp
+++ b/gfx/gl/GLContext.cpp
@@ -59,17 +59,17 @@ namespace gl {
using namespace mozilla::gfx;
using namespace mozilla::layers;
#ifdef MOZ_GL_DEBUG
unsigned GLContext::sCurrentGLContextTLS = -1;
#endif
-MOZ_THREAD_LOCAL(GLContext*) GLContext::sCurrentContext;
+MOZ_THREAD_LOCAL(const GLContext*) GLContext::sCurrentContext;
// If adding defines, don't forget to undefine symbols. See #undef block below.
#define CORE_SYMBOL(x) { (PRFuncPtr*) &mSymbols.f##x, { #x, nullptr } }
#define CORE_EXT_SYMBOL2(x,y,z) { (PRFuncPtr*) &mSymbols.f##x, { #x, #x #y, #x #z, nullptr } }
#define EXT_SYMBOL2(x,y,z) { (PRFuncPtr*) &mSymbols.f##x, { #x #y, #x #z, nullptr } }
#define EXT_SYMBOL3(x,y,z,w) { (PRFuncPtr*) &mSymbols.f##x, { #x #y, #x #z, #x #w, nullptr } }
#define END_SYMBOLS { nullptr, { nullptr } }
@@ -3023,23 +3023,24 @@ GetBytesPerTexel(GLenum format, GLenum t
{
return 2;
}
gfxCriticalError() << "Unknown texture type " << type << " or format " << format;
return 0;
}
-bool GLContext::MakeCurrent(bool aForce)
+bool
+GLContext::MakeCurrent(bool aForce) const
{
- if (IsDestroyed())
+ if (MOZ_UNLIKELY( IsDestroyed() ))
return false;
#ifdef MOZ_GL_DEBUG
- PR_SetThreadPrivate(sCurrentGLContextTLS, this);
+ PR_SetThreadPrivate(sCurrentGLContextTLS, (void*)this);
// XXX this assertion is disabled because it's triggering on Mac;
// we need to figure out why and reenable it.
#if 0
// IsOwningThreadCurrent is a bit of a misnomer;
// the "owning thread" is the creation thread,
// and the only thread that can own this. We don't
// support contexts used on multiple threads.
--- a/gfx/gl/GLContext.h
+++ b/gfx/gl/GLContext.h
@@ -191,17 +191,17 @@ enum class GLRenderer {
class GLContext
: public GLLibraryLoader
, public GenericAtomicRefCounted
, public SupportsWeakPtr<GLContext>
{
public:
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(GLContext)
- static MOZ_THREAD_LOCAL(GLContext*) sCurrentContext;
+ static MOZ_THREAD_LOCAL(const GLContext*) sCurrentContext;
// -----------------------------------------------------------------------------
// basic getters
public:
/**
* Returns true if the context is using ANGLE. This should only be overridden
* for an ANGLE implementation.
@@ -291,28 +291,28 @@ public:
* If this context is double-buffered, returns TRUE.
*/
virtual bool IsDoubleBuffered() const {
return false;
}
virtual GLContextType GetContextType() const = 0;
- virtual bool IsCurrent() = 0;
+ virtual bool IsCurrent() const = 0;
/**
* Get the default framebuffer for this context.
*/
virtual GLuint GetDefaultFramebuffer() {
return 0;
}
protected:
bool mIsOffscreen;
- bool mContextLost;
+ mutable bool mContextLost;
const bool mUseTLSIsCurrent;
/**
* mVersion store the OpenGL's version, multiplied by 100. For example, if
* the context is an OpenGL 2.1 context, mVersion value will be 210.
*/
uint32_t mVersion;
ContextProfile mProfile;
@@ -535,33 +535,33 @@ public:
case LOCAL_GL_INVALID_FRAMEBUFFER_OPERATION:
return "GL_INVALID_FRAMEBUFFER_OPERATION";
default:
return "";
}
}
private:
- GLenum mTopError;
-
- GLenum RawGetError() {
+ mutable GLenum mTopError;
+
+ GLenum RawGetError() const {
return mSymbols.fGetError();
}
- GLenum RawGetErrorAndClear() {
+ GLenum RawGetErrorAndClear() const {
GLenum err = RawGetError();
if (err)
while (RawGetError()) {}
return err;
}
public:
- GLenum FlushErrors() {
+ GLenum FlushErrors() const {
GLenum err = RawGetErrorAndClear();
if (!mTopError)
mTopError = err;
return err;
}
// We smash all errors together, so you never have to loop on this. We
// guarantee that immediately after this call, there are no errors left.
@@ -3280,34 +3280,34 @@ public:
// the GL function pointers!
void MarkDestroyed();
// -----------------------------------------------------------------------------
// Everything that isn't standard GL APIs
protected:
typedef gfx::SurfaceFormat SurfaceFormat;
- virtual bool MakeCurrentImpl(bool aForce) = 0;
+ virtual bool MakeCurrentImpl(bool aForce) const = 0;
public:
#ifdef MOZ_GL_DEBUG
static void StaticInit() {
PR_NewThreadPrivateIndex(&sCurrentGLContextTLS, nullptr);
}
#endif
- bool MakeCurrent(bool aForce = false);
+ bool MakeCurrent(bool aForce = false) const;
virtual bool Init() = 0;
virtual bool SetupLookupFunction() = 0;
virtual void ReleaseSurface() {}
- bool IsDestroyed() {
+ bool IsDestroyed() const {
// MarkDestroyed will mark all these as null.
return mSymbols.fUseProgram == nullptr;
}
GLContext* GetSharedContext() { return mSharedContext; }
/**
* Returns true if the thread on which this context was created is the currently
--- a/gfx/gl/GLContextCGL.h
+++ b/gfx/gl/GLContextCGL.h
@@ -40,19 +40,19 @@ public:
return static_cast<GLContextCGL*>(gl);
}
bool Init() override;
NSOpenGLContext* GetNSOpenGLContext() const { return mContext; }
CGLContextObj GetCGLContext() const;
- virtual bool MakeCurrentImpl(bool aForce) override;
+ virtual bool MakeCurrentImpl(bool aForce) const override;
- virtual bool IsCurrent() override;
+ virtual bool IsCurrent() const override;
virtual GLenum GetPreferredARGB32Format() const override;
virtual bool SetupLookupFunction() override;
virtual bool IsDoubleBuffered() const override;
virtual bool SwapBuffers() override;
--- a/gfx/gl/GLContextEAGL.h
+++ b/gfx/gl/GLContextEAGL.h
@@ -38,19 +38,19 @@ public:
}
bool Init() override;
bool AttachToWindow(nsIWidget* aWidget);
EAGLContext* GetEAGLContext() const { return mContext; }
- virtual bool MakeCurrentImpl(bool aForce) override;
+ virtual bool MakeCurrentImpl(bool aForce) const override;
- virtual bool IsCurrent() override;
+ virtual bool IsCurrent() const override;
virtual bool SetupLookupFunction() override;
virtual bool IsDoubleBuffered() const override;
virtual bool SwapBuffers() override;
virtual void GetWSIInfo(nsCString* const out) const override;
--- a/gfx/gl/GLContextEGL.h
+++ b/gfx/gl/GLContextEGL.h
@@ -68,19 +68,19 @@ public:
virtual bool ReleaseTexImage() override;
void SetEGLSurfaceOverride(EGLSurface surf);
EGLSurface GetEGLSurfaceOverride() {
return mSurfaceOverride;
}
- virtual bool MakeCurrentImpl(bool aForce) override;
+ virtual bool MakeCurrentImpl(bool aForce) const override;
- virtual bool IsCurrent() override;
+ virtual bool IsCurrent() const override;
virtual bool RenewSurface(widget::CompositorWidget* aWidget) override;
virtual void ReleaseSurface() override;
virtual bool SetupLookupFunction() override;
virtual bool SwapBuffers() override;
--- a/gfx/gl/GLContextGLX.h
+++ b/gfx/gl/GLContextGLX.h
@@ -41,19 +41,19 @@ public:
static GLContextGLX* Cast(GLContext* gl) {
MOZ_ASSERT(gl->GetContextType() == GLContextType::GLX);
return static_cast<GLContextGLX*>(gl);
}
bool Init() override;
- virtual bool MakeCurrentImpl(bool aForce) override;
+ virtual bool MakeCurrentImpl(bool aForce) const override;
- virtual bool IsCurrent() override;
+ virtual bool IsCurrent() const override;
virtual bool SetupLookupFunction() override;
virtual bool IsDoubleBuffered() const override;
virtual bool SwapBuffers() override;
virtual void GetWSIInfo(nsCString* const out) const override;
--- a/gfx/gl/GLContextProviderCGL.mm
+++ b/gfx/gl/GLContextProviderCGL.mm
@@ -105,17 +105,17 @@ GLContextCGL::Init()
CGLContextObj
GLContextCGL::GetCGLContext() const
{
return static_cast<CGLContextObj>([mContext CGLContextObj]);
}
bool
-GLContextCGL::MakeCurrentImpl(bool aForce)
+GLContextCGL::MakeCurrentImpl(bool aForce) const
{
if (!aForce && [NSOpenGLContext currentContext] == mContext) {
return true;
}
if (mContext) {
[mContext makeCurrentContext];
MOZ_ASSERT(IsCurrent());
@@ -127,17 +127,18 @@ GLContextCGL::MakeCurrentImpl(bool aForc
// glSwapBuffers, which will happen when swapInt==0.
GLint swapInt = gfxPrefs::LayoutFrameRate() == 0 ? 0 : 1;
[mContext setValues:&swapInt forParameter:NSOpenGLCPSwapInterval];
}
return true;
}
bool
-GLContextCGL::IsCurrent() {
+GLContextCGL::IsCurrent() const
+{
return [NSOpenGLContext currentContext] == mContext;
}
GLenum
GLContextCGL::GetPreferredARGB32Format() const
{
return LOCAL_GL_BGRA;
}
--- a/gfx/gl/GLContextProviderEAGL.mm
+++ b/gfx/gl/GLContextProviderEAGL.mm
@@ -108,32 +108,33 @@ GLContextEAGL::RecreateRB()
fBindFramebuffer(LOCAL_GL_FRAMEBUFFER, mBackbufferFB);
fFramebufferRenderbuffer(LOCAL_GL_FRAMEBUFFER, LOCAL_GL_COLOR_ATTACHMENT0,
LOCAL_GL_RENDERBUFFER, mBackbufferRB);
return LOCAL_GL_FRAMEBUFFER_COMPLETE == fCheckFramebufferStatus(LOCAL_GL_FRAMEBUFFER);
}
bool
-GLContextEAGL::MakeCurrentImpl(bool aForce)
+GLContextEAGL::MakeCurrentImpl(bool aForce) const
{
if (!aForce && [EAGLContext currentContext] == mContext) {
return true;
}
if (mContext) {
if(![EAGLContext setCurrentContext:mContext]) {
return false;
}
}
return true;
}
bool
-GLContextEAGL::IsCurrent() {
+GLContextEAGL::IsCurrent() const
+{
return [EAGLContext currentContext] == mContext;
}
bool
GLContextEAGL::SetupLookupFunction()
{
return false;
}
--- a/gfx/gl/GLContextProviderEGL.cpp
+++ b/gfx/gl/GLContextProviderEGL.cpp
@@ -348,17 +348,18 @@ GLContextEGL::SetEGLSurfaceOverride(EGLS
}
mSurfaceOverride = surf;
DebugOnly<bool> ok = MakeCurrent(true);
MOZ_ASSERT(ok);
}
bool
-GLContextEGL::MakeCurrentImpl(bool aForce) {
+GLContextEGL::MakeCurrentImpl(bool aForce) const
+{
bool succeeded = true;
// Assume that EGL has the same problem as WGL does,
// where MakeCurrent with an already-current context is
// still expensive.
bool needsMakeCurrent = (aForce || sEGLLibrary.fGetCurrentContext() != mContext);
if (needsMakeCurrent) {
EGLSurface surface = mSurfaceOverride != EGL_NO_SURFACE
@@ -383,17 +384,18 @@ GLContextEGL::MakeCurrentImpl(bool aForc
}
}
}
return succeeded;
}
bool
-GLContextEGL::IsCurrent() {
+GLContextEGL::IsCurrent() const
+{
return sEGLLibrary.fGetCurrentContext() == mContext;
}
bool
GLContextEGL::RenewSurface(CompositorWidget* aWidget) {
if (!mOwnsContext) {
return false;
}
--- a/gfx/gl/GLContextProviderGLX.cpp
+++ b/gfx/gl/GLContextProviderGLX.cpp
@@ -601,17 +601,17 @@ GLContextGLX::Init()
// so we'll also check for ARB_framebuffer_object
if (!IsExtensionSupported(EXT_framebuffer_object) && !IsSupported(GLFeature::framebuffer_object))
return false;
return true;
}
bool
-GLContextGLX::MakeCurrentImpl(bool aForce)
+GLContextGLX::MakeCurrentImpl(bool aForce) const
{
bool succeeded = true;
// With the ATI FGLRX driver, glxMakeCurrent is very slow even when the context doesn't change.
// (This is not the case with other drivers such as NVIDIA).
// So avoid calling it more than necessary. Since GLX documentation says that:
// "glXGetCurrentContext returns client-side information.
// It does not make a round trip to the server."
@@ -634,17 +634,18 @@ GLContextGLX::MakeCurrentImpl(bool aForc
mGLX->fSwapInterval(mDisplay, mDrawable, isASAP ? 0 : 1);
}
}
return succeeded;
}
bool
-GLContextGLX::IsCurrent() {
+GLContextGLX::IsCurrent() const
+{
return mGLX->fGetCurrentContext() == mContext;
}
bool
GLContextGLX::SetupLookupFunction()
{
mLookupFunc = (PlatformLookupFunction)sGLXLibrary.GetGetProcAddress();
return true;
--- a/gfx/gl/GLContextProviderWGL.cpp
+++ b/gfx/gl/GLContextProviderWGL.cpp
@@ -318,34 +318,34 @@ GLContextWGL::Init()
SetupLookupFunction();
if (!InitWithPrefix("gl", true))
return false;
return true;
}
bool
-GLContextWGL::MakeCurrentImpl(bool aForce)
+GLContextWGL::MakeCurrentImpl(bool aForce) const
{
BOOL succeeded = true;
// wglGetCurrentContext seems to just pull the HGLRC out
// of its TLS slot, so no need to do our own tls slot.
// You would think that wglMakeCurrent would avoid doing
// work if mContext was already current, but not so much..
if (aForce || sWGLLib.mSymbols.fGetCurrentContext() != mContext) {
succeeded = sWGLLib.mSymbols.fMakeCurrent(mDC, mContext);
NS_ASSERTION(succeeded, "Failed to make GL context current!");
}
return succeeded;
}
bool
-GLContextWGL::IsCurrent()
+GLContextWGL::IsCurrent() const
{
return sWGLLib.mSymbols.fGetCurrentContext() == mContext;
}
void
GLContextWGL::SetIsDoubleBuffered(bool aIsDB)
{
mIsDoubleBuffered = aIsDB;
--- a/gfx/gl/GLContextWGL.h
+++ b/gfx/gl/GLContextWGL.h
@@ -40,19 +40,19 @@ public:
static GLContextWGL* Cast(GLContext* gl) {
MOZ_ASSERT(gl->GetContextType() == GLContextType::WGL);
return static_cast<GLContextWGL*>(gl);
}
bool Init() override;
- virtual bool MakeCurrentImpl(bool aForce) override;
+ virtual bool MakeCurrentImpl(bool aForce) const override;
- virtual bool IsCurrent() override;
+ virtual bool IsCurrent() const override;
void SetIsDoubleBuffered(bool aIsDB);
virtual bool IsDoubleBuffered() const override;
virtual bool SwapBuffers() override;
virtual bool SetupLookupFunction() override;