|
1 | 1 | define([
|
2 | 2 | './defaultValue',
|
3 | 3 | './defined',
|
4 |
| - './Fullscreen' |
| 4 | + './Fullscreen', |
| 5 | + './RuntimeError', |
| 6 | + '../ThirdParty/when' |
5 | 7 | ], function(
|
6 | 8 | defaultValue,
|
7 | 9 | defined,
|
8 |
| - Fullscreen) { |
| 10 | + Fullscreen, |
| 11 | + RuntimeError, |
| 12 | + when) { |
9 | 13 | 'use strict';
|
10 | 14 | /*global CanvasPixelArray*/
|
11 | 15 |
|
@@ -199,6 +203,35 @@ define([
|
199 | 203 | return supportsImageRenderingPixelated() ? imageRenderingValueResult : undefined;
|
200 | 204 | }
|
201 | 205 |
|
| 206 | + var supportsWebpPromise; |
| 207 | + function supportsWebp() { |
| 208 | + // From https://developers.google.com/speed/webp/faq#how_can_i_detect_browser_support_for_webp |
| 209 | + if (defined(supportsWebpPromise)) { |
| 210 | + return supportsWebpPromise.promise; |
| 211 | + } |
| 212 | + |
| 213 | + supportsWebpPromise = when.defer(); |
| 214 | + if (isEdge()) { |
| 215 | + // Edge's WebP support with WebGL is incomplete. |
| 216 | + // See bug report: https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/19221241/ |
| 217 | + supportsWebpPromise.resolve(false); |
| 218 | + } |
| 219 | + |
| 220 | + var image = new Image(); |
| 221 | + image.onload = function () { |
| 222 | + var success = (image.width > 0) && (image.height > 0); |
| 223 | + supportsWebpPromise.resolve(success); |
| 224 | + }; |
| 225 | + |
| 226 | + image.onerror = function () { |
| 227 | + supportsWebpPromise.resolve(false); |
| 228 | + }; |
| 229 | + |
| 230 | + image.src = 'data:image/webp;base64,UklGRiIAAABXRUJQVlA4IBYAAAAwAQCdASoBAAEADsD+JaQAA3AAAAAA'; |
| 231 | + |
| 232 | + return supportsWebpPromise.promise; |
| 233 | + } |
| 234 | + |
202 | 235 | var typedArrayTypes = [];
|
203 | 236 | if (typeof ArrayBuffer !== 'undefined') {
|
204 | 237 | typedArrayTypes.push(Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, Uint32Array, Float32Array, Float64Array);
|
@@ -235,6 +268,7 @@ define([
|
235 | 268 | hardwareConcurrency : defaultValue(theNavigator.hardwareConcurrency, 3),
|
236 | 269 | supportsPointerEvents : supportsPointerEvents,
|
237 | 270 | supportsImageRenderingPixelated: supportsImageRenderingPixelated,
|
| 271 | + supportsWebp: supportsWebp, |
238 | 272 | imageRenderingValue: imageRenderingValue,
|
239 | 273 | typedArrayTypes: typedArrayTypes
|
240 | 274 | };
|
|
0 commit comments