perf: use OffscreenCanvas in Chrome 82+ (#1779)

This commit is contained in:
Nolan Lawson 2020-05-18 20:00:02 -07:00 committed by GitHub
parent beade4aec3
commit ea1315858d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 2 deletions

View file

@ -0,0 +1,15 @@
// checking for Chrome 82 because that's when this bug was fixed
// https://bugs.chromium.org/p/chromium/issues/detail?id=1053477
import { thunk } from '../thunk'
import { isChrome } from './isChrome'
function getChromeVersion () {
try {
return parseInt(navigator.userAgent.match(/Chrome\/(\d+)/)[1], 10) || undefined
} catch (e) {
return undefined
}
}
export const isChromePre82 = thunk(() => process.browser && isChrome() && getChromeVersion() < 82)

View file

@ -2,11 +2,11 @@ import '../_thirdparty/regenerator-runtime/runtime.js'
import { decode as decodeBlurHash } from 'blurhash' import { decode as decodeBlurHash } from 'blurhash'
import registerPromiseWorker from 'promise-worker/register' import registerPromiseWorker from 'promise-worker/register'
import { BLURHASH_RESOLUTION as RESOLUTION } from '../_static/blurhash' import { BLURHASH_RESOLUTION as RESOLUTION } from '../_static/blurhash'
import { isChrome } from '../_utils/userAgent/isChrome' import { isChromePre82 } from '../_utils/userAgent/isChromePre82'
// Disabled in Chrome because convertToBlob() is slow // Disabled in Chrome because convertToBlob() is slow
// https://github.com/nolanlawson/pinafore/issues/1396 // https://github.com/nolanlawson/pinafore/issues/1396
const OFFSCREEN_CANVAS = !isChrome() && typeof OffscreenCanvas === 'function' const OFFSCREEN_CANVAS = !isChromePre82() && typeof OffscreenCanvas === 'function'
? new OffscreenCanvas(RESOLUTION, RESOLUTION) : null ? new OffscreenCanvas(RESOLUTION, RESOLUTION) : null
const OFFSCREEN_CANVAS_CONTEXT_2D = OFFSCREEN_CANVAS const OFFSCREEN_CANVAS_CONTEXT_2D = OFFSCREEN_CANVAS
? OFFSCREEN_CANVAS.getContext('2d') : null ? OFFSCREEN_CANVAS.getContext('2d') : null