Skip to content

Commit

Permalink
fix #7671 by avoiding incomplete webp support in Edge 18
Browse files Browse the repository at this point in the history
  • Loading branch information
ansis committed Dec 11, 2018
1 parent 7ddbfa2 commit e88ecae
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/util/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,31 @@ const exported = {
export default exported;

if (window.document) {
testWebp();
}

function testWebp() {
const webpImgTest = window.document.createElement('img');
webpImgTest.onload = function() {
exported.supportsWebp = true;

// Edge 18 supports WebP but not uploading a WebP image to a gl texture
// Test support for this before allowing WebP images.
// https://github.com/mapbox/mapbox-gl-js/issues/7671
const canvas = window.document.createElement('canvas');
const gl = canvas.getContext('webgl') || canvas.getContext('experimental-webgl');
const texture = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, texture);

try {
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, webpImgTest);
exported.supportsWebp = true;
} catch (e) {
// Catch "Unspecified Error." in Edge 18.
}

gl.deleteTexture(texture);
const extension = gl.getExtension('WEBGL_lose_context');
if (extension) extension.loseContext();
};
webpImgTest.src = 'data:image/webp;base64,UklGRh4AAABXRUJQVlA4TBEAAAAvAQAAAAfQ//73v/+BiOh/AAA=';
}

0 comments on commit e88ecae

Please sign in to comment.