Backed out 2 changesets (bug 1096633)
authorPhil Ringnalda <philringnalda@gmail.com>
Thu, 13 Nov 2014 21:02:31 -0800
changeset 231922 0cf9d23846cd83ca51f563fce7444dee996998f5
parent 231921 cc036cbdc52c232aade21787fa812c1b3767447f
child 231923 63d19478437854b2c9807e963498259dce373bc2
push id7326
push userbhearsum@mozilla.com
push dateFri, 28 Nov 2014 15:58:42 +0000
treeherdermozilla-aurora@d3a3b2a0f2f8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1096633
milestone36.0a1
backs out17e1001f62c99ade03f5f315abb138ce6f0233c4
0b0b306c021dbcbbba9a812e781858cb14c29593
Backed out 2 changesets (bug 1096633) Backed out changeset 17e1001f62c9 (bug 1096633) Backed out changeset 0b0b306c021d (bug 1096633)
dom/canvas/test/webgl-mochitest/test_webgl_request_mismatch.html
dom/html/HTMLCanvasElement.cpp
--- a/dom/canvas/test/webgl-mochitest/test_webgl_request_mismatch.html
+++ b/dom/canvas/test/webgl-mochitest/test_webgl_request_mismatch.html
@@ -1,90 +1,35 @@
 <!DOCTYPE HTML>
-<html>
-<head>
+<title>WebGL test: Mismatched 'webgl' and 'experimental-webgl' context requests</title>
 <script src="/tests/SimpleTest/SimpleTest.js"></script>
 <link rel="stylesheet" href="/tests/SimpleTest/test.css">
-</head>
 <body>
+<canvas id="c1"></canvas>
+<canvas id="c2"></canvas>
+<canvas id="c3"></canvas>
+<canvas id="c4"></canvas>
 <script>
 
-WEBGL_TYPES = {};
-WEBGL_TYPES['experimental-webgl'] = true;
-WEBGL_TYPES['webgl'] = true;
+function testContextRetrieval(canvasId, creationId, requestId) {
+  var canvas = document.getElementById(canvasId);
+  ok(canvas, 'Invalid `canvasId`: ' + canvasId);
 
-function AreBothIn(a, b, set) {
-    return (a in set) && (b in set);
-}
+  var createdGL = canvas.getContext(creationId);
+  if (!createdGL)
+    return; // No WebGL on this machine?
 
-function IsAlias(typeA, typeB) {
-    if (typeA == typeB)
-        return true;
-
-    if (AreBothIn(typeA, typeB, WEBGL_TYPES))
-        return true;
-
-    return false;
+  var requestedGL = canvas.getContext(requestId);
+  if (creationId == requestId) {
+    ok(requestedGL, 'Request for \'' + requestId + '\' on from \'' + creationId + '\' should succeed.');
+    ok(requestedGL == createdGL, 'Request for \'' + requestId + '\' on from \'' + creationId + '\' should match.');
+  } else {
+    ok(!requestedGL, 'Request for \'' + requestId + '\' on from \'' + creationId + '\' should fail.');
+  }
 }
 
-function TestContextRetrieval(creationType, requestType, functionalTypeSet) {
-    var canvas = document.createElement('canvas');
-    var createdGL = canvas.getContext(creationType);
-
-    var didCreationSucceed = (createdGL != null);
-    if (creationType in functionalTypeSet) {
-        ok(createdGL, 'Context creation should succeed for type \'' +
-                      creationType + '\'');
-    } else {
-        ok(!createdGL, 'Context creation should fail for type \'' +
-                       creationType + '\'');
-        return;
-    }
-
-    var requestedGL = canvas.getContext(requestType);
-
-    if (requestType in functionalTypeSet &&
-        IsAlias(creationType, requestType))
-    {
-        ok(requestedGL, 'Request for \'' + requestType + '\' from \'' +
-                        creationType + '\' should succeed.');
-        ok(requestedGL == createdGL, 'Request for \'' + requestType +
-                                     '\' from \'' + creationType +
-                                     '\' should match.');
-    } else {
-        ok(!requestedGL, 'Request for \'' + requestType + '\' from \'' +
-                         creationType + '\' should fail.');
-    }
-}
-
-function IsWebGLFunctional() {
-    var canvas = document.createElement('canvas');
-    return canvas.getContext('experimental-webgl') != null;
-}
-
-function IsWebGLConformant() {
-    var canvas = document.createElement('canvas');
-    return canvas.getContext('webgl') != null;
-}
-
-var typeList = ['2d', 'experimental-webgl', 'webgl'];
-var functionalTypeSet = {};
-functionalTypeSet['2d'] = true;
-
-if (IsWebGLFunctional())
-    functionalTypeSet['experimental-webgl'] = true;
-
-if (IsWebGLConformant())
-    functionalTypeSet['webgl'] = true;
-
-for (var i in typeList) {
-    var creationType = typeList[i];
-
-    for (var j in typeList) {
-        var requestType = typeList[j];
-
-        TestContextRetrieval(creationType, requestType, functionalTypeSet);
-    }
-}
+testContextRetrieval('c1', 'experimental-webgl', 'webgl');
+testContextRetrieval('c2', 'webgl', 'experimental-webgl');
+testContextRetrieval('c3', 'experimental-webgl', 'experimental-webgl');
+testContextRetrieval('c4', 'webgl', 'webgl');
 
 </script>
-</body>
-</html>
+
--- a/dom/html/HTMLCanvasElement.cpp
+++ b/dom/html/HTMLCanvasElement.cpp
@@ -721,17 +721,17 @@ HTMLCanvasElement::GetContext(const nsAS
 {
   ErrorResult rv;
   *aContext =
     GetContext(nullptr, aContextId, JS::NullHandleValue, rv).take();
   return rv.ErrorCode();
 }
 
 static bool
-IsContextIdWebGL1(const nsAString& str)
+IsContextIdWebGL(const nsAString& str)
 {
   return str.EqualsLiteral("webgl") ||
          str.EqualsLiteral("experimental-webgl");
 }
 
 already_AddRefed<nsISupports>
 HTMLCanvasElement::GetContext(JSContext* aCx,
                               const nsAString& aContextId,
@@ -757,27 +757,31 @@ HTMLCanvasElement::GetContext(JSContext*
     rv = UpdateContext(aCx, aContextOptions);
     if (rv.Failed()) {
       rv = NS_OK; // See bug 645792
       return nullptr;
     }
     mCurrentContextId.Assign(aContextId);
   }
 
-  if (mCurrentContextId.Equals(aContextId)) {
-      // Valid.
-  } else if (IsContextIdWebGL1(aContextId) &&
-             IsContextIdWebGL1(mCurrentContextId))
-  {
-      /* Valid.
-       * WebGL 1.0, $2.1 "Context Creation":
-       *   If the user agent supports both the webgl and experimental-webgl
-       *   canvas context types, they shall be treated as aliases.
-       */
-  } else {
+  if (!mCurrentContextId.Equals(aContextId)) {
+    if (IsContextIdWebGL(aContextId) &&
+        IsContextIdWebGL(mCurrentContextId))
+    {
+      // Warn when we get a request for a webgl context with an id that differs
+      // from the id it was created with.
+      nsCString creationId = NS_LossyConvertUTF16toASCII(mCurrentContextId);
+      nsCString requestId = NS_LossyConvertUTF16toASCII(aContextId);
+      JS_ReportWarning(aCx, "WebGL: Retrieving a WebGL context from a canvas "
+                            "via a request id ('%s') different from the id used "
+                            "to create the context ('%s') is not allowed.",
+                            requestId.get(),
+                            creationId.get());
+    }
+    
     //XXX eventually allow for more than one active context on a given canvas
     return nullptr;
   }
 
   nsCOMPtr<nsICanvasRenderingContextInternal> context = mCurrentContext;
   return context.forget();
 }