Bug 1390386 - Make MakeCurrent const. - r=daoshengmu
☠☠ backed out by fdbcfc9b7987 ☠ ☠
authorJeff Gilbert <jgilbert@mozilla.com>
Thu, 10 Aug 2017 18:00:02 -0700
changeset 375407 d1286d0d2c792751472c807f75996c9fc34220d1
parent 375406 3da239c081bc81b623c765c45e9d4868b6e8bff6
child 375408 9d16670edeb5a831913ae92469c5754a768b9b07
push id93901
push userjgilbert@mozilla.com
push dateThu, 17 Aug 2017 23:18:03 +0000
treeherdermozilla-inbound@22b11f9aedd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdaoshengmu
bugs1390386
milestone57.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1390386 - Make MakeCurrent const. - r=daoshengmu MozReview-Commit-ID: 3m3T6iMgZOc
gfx/gl/GLContext.cpp
gfx/gl/GLContext.h
gfx/gl/GLContextCGL.h
gfx/gl/GLContextEAGL.h
gfx/gl/GLContextEGL.h
gfx/gl/GLContextGLX.h
gfx/gl/GLContextProviderCGL.mm
gfx/gl/GLContextProviderEAGL.mm
gfx/gl/GLContextProviderEGL.cpp
gfx/gl/GLContextProviderGLX.cpp
gfx/gl/GLContextProviderWGL.cpp
gfx/gl/GLContextWGL.h
--- 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 } }
 
@@ -3024,23 +3024,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
@@ -192,17 +192,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.
@@ -292,28 +292,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;
@@ -536,33 +536,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.
@@ -3265,34 +3265,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
@@ -334,17 +334,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
@@ -369,17 +370,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;