in seriously.js [542:607]
function checkSource(source) {
var element, canvas, ctx, texture;
//todo: don't need to create a new array every time we do this
element = getElement(source, ['img', 'canvas', 'video']);
if (!element) {
return false;
}
canvas = document.createElement('canvas');
if (!canvas) {
Seriously.logger.warn('Browser does not support canvas or Seriously.js');
return false;
}
if (element.naturalWidth === 0 && element.tagName === 'IMG') {
Seriously.logger.warn('Image not loaded');
return false;
}
if (element.readyState === 0 && element.videoWidth === 0 && element.tagName === 'VIDEO') {
Seriously.logger.warn('Video not loaded');
return false;
}
ctx = getTestContext();
if (ctx) {
texture = ctx.createTexture();
if (!texture) {
Seriously.logger.error('Test WebGL context has been lost');
}
ctx.bindTexture(ctx.TEXTURE_2D, texture);
try {
ctx.texImage2D(ctx.TEXTURE_2D, 0, ctx.RGBA, ctx.RGBA, ctx.UNSIGNED_BYTE, element);
} catch (textureError) {
if (textureError.code === window.DOMException.SECURITY_ERR) {
Seriously.logger.log('Unable to access cross-domain image');
} else {
Seriously.logger.error('Error storing image to texture: ' + textureError.message);
}
ctx.deleteTexture(texture);
return false;
}
ctx.deleteTexture(texture);
} else {
ctx = canvas.getContext('2d');
try {
ctx.drawImage(element, 0, 0);
ctx.getImageData(0, 0, 1, 1);
} catch (drawImageError) {
if (drawImageError.code === window.DOMException.SECURITY_ERR) {
Seriously.logger.log('Unable to access cross-domain image');
} else {
Seriously.logger.error('Error drawing image to canvas: ' + drawImageError.message);
}
return false;
}
}
// This method will return a false positive for resources that aren't
// actually images or haven't loaded yet
return true;
}