Move support check from display to browser

This commit is contained in:
Juanjo Diaz 2019-02-27 10:13:50 +02:00
parent 0505214cd9
commit 44f4c5545f
2 changed files with 11 additions and 9 deletions

View File

@ -8,14 +8,7 @@
import * as Log from './util/logging.js';
import Base64 from "./base64.js";
let SUPPORTS_IMAGEDATA_CONSTRUCTOR = false;
try {
new ImageData(new Uint8ClampedArray(4), 1, 1);
SUPPORTS_IMAGEDATA_CONSTRUCTOR = true;
} catch (ex) {
// ignore failure
}
import { supportsImageMetadata } from './util/browser.js';
export default class Display {
constructor(target) {
@ -573,7 +566,7 @@ export default class Display {
_rgbxImageData(x, y, width, height, arr, offset) {
// NB(directxman12): arr must be an Type Array view
let img;
if (SUPPORTS_IMAGEDATA_CONSTRUCTOR) {
if (supportsImageMetadata) {
img = new ImageData(new Uint8ClampedArray(arr.buffer, arr.byteOffset, width * height * 4), width, height);
} else {
img = this._drawCtx.createImageData(width, height);

View File

@ -49,6 +49,15 @@ export function supportsCursorURIs() {
return _cursor_uris_supported;
}
let _supportsImageMetadata = false;
try {
new ImageData(new Uint8ClampedArray(4), 1, 1);
_supportsImageMetadata = true;
} catch (ex) {
// ignore failure
}
export const supportsImageMetadata = _supportsImageMetadata;
export function isMac() {
return navigator && !!(/mac/i).exec(navigator.platform);
}