Bug 1428898 - Add TlsScope to reduce fIsCurrent calls. - r=daoshengmu
MozReview-Commit-ID: Kyi8dcO7nAu
--- a/dom/canvas/WebGLContextDraw.cpp
+++ b/dom/canvas/WebGLContextDraw.cpp
@@ -507,16 +507,18 @@ WebGLContext::DrawArrays_check(const cha
void
WebGLContext::DrawArraysInstanced(GLenum mode, GLint first, GLsizei vertCount,
GLsizei instanceCount, const char* const funcName)
{
AUTO_PROFILER_LABEL("WebGLContext::DrawArraysInstanced", GRAPHICS);
if (IsContextLost())
return;
+ const gl::GLContext::TlsScope inTls(gl);
+
Maybe<uint32_t> lastVert;
if (!DrawArrays_check(funcName, first, vertCount, instanceCount, &lastVert))
return;
bool error = false;
const ScopedDrawHelper scopedHelper(this, funcName, mode, lastVert, instanceCount,
&error);
if (error)
@@ -663,16 +665,18 @@ void
WebGLContext::DrawElementsInstanced(GLenum mode, GLsizei indexCount, GLenum type,
WebGLintptr byteOffset, GLsizei instanceCount,
const char* const funcName)
{
AUTO_PROFILER_LABEL("WebGLContext::DrawElementsInstanced", GRAPHICS);
if (IsContextLost())
return;
+ const gl::GLContext::TlsScope inTls(gl);
+
Maybe<uint32_t> lastVert;
if (!DrawElements_check(funcName, indexCount, type, byteOffset, instanceCount,
&lastVert))
{
return;
}
bool error = false;
--- a/gfx/gl/GLContext.cpp
+++ b/gfx/gl/GLContext.cpp
@@ -259,19 +259,19 @@ ChooseDebugFlags(CreateContextFlags crea
#endif
return debugFlags;
}
GLContext::GLContext(CreateContextFlags flags, const SurfaceCaps& caps,
GLContext* sharedContext, bool isOffscreen, bool useTLSIsCurrent)
: mImplicitMakeCurrent(false),
+ mUseTLSIsCurrent(ShouldUseTLSIsCurrent(useTLSIsCurrent)),
mIsOffscreen(isOffscreen),
mContextLost(false),
- mUseTLSIsCurrent(ShouldUseTLSIsCurrent(useTLSIsCurrent)),
mVersion(0),
mProfile(ContextProfile::Unknown),
mShadingLanguageVersion(0),
mVendor(GLVendor::Other),
mRenderer(GLRenderer::Other),
mTopError(LOCAL_GL_NO_ERROR),
mDebugFlags(ChooseDebugFlags(flags)),
mSharedContext(sharedContext),
@@ -3066,19 +3066,17 @@ GLContext::MakeCurrent(bool aForce) cons
MOZ_ASSERT(IsCurrentImpl());
return true;
}
}
if (!MakeCurrentImpl())
return false;
- if (mUseTLSIsCurrent) {
- sCurrentContext.set(reinterpret_cast<uintptr_t>(this));
- }
+ sCurrentContext.set(reinterpret_cast<uintptr_t>(this));
return true;
}
void
GLContext::ResetSyncCallCount(const char* resetReason) const
{
if (ShouldSpew()) {
printf_stderr("On %s, mSyncGLCallCount = %" PRIu64 "\n",
--- a/gfx/gl/GLContext.h
+++ b/gfx/gl/GLContext.h
@@ -194,16 +194,33 @@ class GLContext
, public GenericAtomicRefCounted
, public SupportsWeakPtr<GLContext>
{
public:
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(GLContext)
static MOZ_THREAD_LOCAL(uintptr_t) sCurrentContext;
bool mImplicitMakeCurrent;
+ bool mUseTLSIsCurrent;
+
+ class TlsScope final {
+ GLContext* const mGL;
+ const bool mWasTlsOk;
+ public:
+ explicit TlsScope(GLContext* const gl)
+ : mGL(gl)
+ , mWasTlsOk(gl->mUseTLSIsCurrent)
+ {
+ mGL->mUseTLSIsCurrent = true;
+ }
+
+ ~TlsScope() {
+ mGL->mUseTLSIsCurrent = mWasTlsOk;
+ }
+ };
// -----------------------------------------------------------------------------
// basic getters
public:
/**
* Returns true if the context is using ANGLE. This should only be overridden
* for an ANGLE implementation.
@@ -315,17 +332,16 @@ public:
*/
virtual GLuint GetDefaultFramebuffer() {
return 0;
}
protected:
bool mIsOffscreen;
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;