Bug 1228687: ScopedResolveTexturesForDraw needs the context to be current, so make those calls earlier. r?jrmuizel draft
authorMilan Sreckovic <milan@mozilla.com>
Mon, 07 Mar 2016 16:35:32 +0800
changeset 337316 e3aa6ae0e86ff01ccf5506aa8f64e23ce04d714c
parent 337277 b6acf4d4fc20431a8ae14bf32cdc6e43a9c0f9ad
child 515629 def5bf08708c8e30396ff1e3f5f88add0f578435
push id12321
push usermsreckovic@mozilla.com
push dateMon, 07 Mar 2016 08:35:58 +0000
reviewersjrmuizel
bugs1228687
milestone47.0a1
Bug 1228687: ScopedResolveTexturesForDraw needs the context to be current, so make those calls earlier. r?jrmuizel MozReview-Commit-ID: KIBOduX3e1y
dom/canvas/WebGLContextDraw.cpp
--- a/dom/canvas/WebGLContextDraw.cpp
+++ b/dom/canvas/WebGLContextDraw.cpp
@@ -42,16 +42,18 @@ public:
     ~ScopedResolveTexturesForDraw();
 };
 
 ScopedResolveTexturesForDraw::ScopedResolveTexturesForDraw(WebGLContext* webgl,
                                                            const char* funcName,
                                                            bool* const out_error)
     : mWebGL(webgl)
 {
+    MOZ_ASSERT(webgl->gl->IsCurrent());
+
     typedef decltype(WebGLContext::mBound2DTextures) TexturesT;
 
     const auto fnResolveAll = [this, funcName](const TexturesT& textures)
     {
         const auto len = textures.Length();
         for (uint32_t texUnit = 0; texUnit < len; ++texUnit) {
             WebGLTexture* tex = textures[texUnit];
             if (!tex)
@@ -215,17 +217,17 @@ WebGLContext::DrawArrays_check(GLint fir
         return false;
     }
 
     if (uint32_t(primcount) > mMaxFetchedInstances) {
         ErrorInvalidOperation("%s: bound instance attribute buffers do not have sufficient size for given primcount", info);
         return false;
     }
 
-    MakeContextCurrent();
+    MOZ_ASSERT(gl->IsCurrent());
 
     if (mBoundDrawFramebuffer) {
         if (!mBoundDrawFramebuffer->ValidateAndInitAttachments(info))
             return false;
     } else {
         ClearBackbufferIfNeeded();
     }
 
@@ -241,16 +243,18 @@ WebGLContext::DrawArrays(GLenum mode, GL
 {
     const char funcName[] = "drawArrays";
     if (IsContextLost())
         return;
 
     if (!ValidateDrawModeEnum(mode, funcName))
         return;
 
+    MakeContextCurrent();
+
     bool error;
     ScopedResolveTexturesForDraw scopedResolve(this, funcName, &error);
     if (error)
         return;
 
     if (!DrawArrays_check(first, count, 1, funcName))
         return;
 
@@ -269,16 +273,18 @@ WebGLContext::DrawArraysInstanced(GLenum
 {
     const char funcName[] = "drawArraysInstanced";
     if (IsContextLost())
         return;
 
     if (!ValidateDrawModeEnum(mode, funcName))
         return;
 
+    MakeContextCurrent();
+
     bool error;
     ScopedResolveTexturesForDraw scopedResolve(this, funcName, &error);
     if (error)
         return;
 
     if (!DrawArrays_check(first, count, primcount, funcName))
         return;
 
@@ -404,17 +410,17 @@ WebGLContext::DrawElements_check(GLsizei
     // Bug 1008310 - Check if buffer has been used with a different previous type
     if (elemArrayBuffer.IsElementArrayUsedWithMultipleTypes()) {
         GenerateWarning("%s: bound element array buffer previously used with a type other than "
                         "%s, this will affect performance.",
                         info,
                         WebGLContext::EnumName(type));
     }
 
-    MakeContextCurrent();
+    MOZ_ASSERT(gl->IsCurrent());
 
     if (mBoundDrawFramebuffer) {
         if (!mBoundDrawFramebuffer->ValidateAndInitAttachments(info))
             return false;
     } else {
         ClearBackbufferIfNeeded();
     }
 
@@ -431,16 +437,18 @@ WebGLContext::DrawElements(GLenum mode, 
 {
     const char funcName[] = "drawElements";
     if (IsContextLost())
         return;
 
     if (!ValidateDrawModeEnum(mode, funcName))
         return;
 
+    MakeContextCurrent();
+
     bool error;
     ScopedResolveTexturesForDraw scopedResolve(this, funcName, &error);
     if (error)
         return;
 
     GLuint upperBound = 0;
     if (!DrawElements_check(count, type, byteOffset, 1, funcName, &upperBound))
         return;
@@ -468,16 +476,18 @@ WebGLContext::DrawElementsInstanced(GLen
 {
     const char funcName[] = "drawElementsInstanced";
     if (IsContextLost())
         return;
 
     if (!ValidateDrawModeEnum(mode, funcName))
         return;
 
+    MakeContextCurrent();
+
     bool error;
     ScopedResolveTexturesForDraw scopedResolve(this, funcName, &error);
     if (error)
         return;
 
     GLuint upperBound = 0;
     if (!DrawElements_check(count, type, byteOffset, primcount, funcName, &upperBound))
         return;