Backed out 2 changesets (bug 1096633)

Backed out changeset 17e1001f62c9 (bug 1096633)
Backed out changeset 0b0b306c021d (bug 1096633)
This commit is contained in:
Phil Ringnalda 2014-11-13 21:02:31 -08:00
parent 9c3b7ca95a
commit e30e4344b5
2 changed files with 40 additions and 91 deletions

View File

@ -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?
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 IsAlias(typeA, typeB) {
if (typeA == typeB)
return true;
if (AreBothIn(typeA, typeB, WEBGL_TYPES))
return true;
return false;
}
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>

View File

@ -726,7 +726,7 @@ HTMLCanvasElement::GetContext(const nsAString& aContextId,
}
static bool
IsContextIdWebGL1(const nsAString& str)
IsContextIdWebGL(const nsAString& str)
{
return str.EqualsLiteral("webgl") ||
str.EqualsLiteral("experimental-webgl");
@ -762,17 +762,21 @@ HTMLCanvasElement::GetContext(JSContext* aCx,
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;
}