Check OffscreenCanvas support once on the worker-thread

Currently we repeat the `FeatureTest.isOffscreenCanvasSupported` checks all over the worker-thread code, and with upcoming changes this will become even "worse".

Hence this patch, which changes the *worker-thread* default value for the `isOffscreenCanvasSupported`-parameter to `false` and moves the feature-testing into the `BasePdfManager`-constructor.

*Please note:* This patch is written using the GitHub UI, since I'm currently without a dev machine, so hopefully it works correctly.
This commit is contained in:
Jonas Jenwald 2023-02-27 12:27:28 +01:00 committed by GitHub
parent 2da2ac492e
commit 45c332110e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 16 deletions

View File

@ -23,7 +23,6 @@ import {
AnnotationType, AnnotationType,
assert, assert,
BASELINE_FACTOR, BASELINE_FACTOR,
FeatureTest,
getModificationDate, getModificationDate,
IDENTITY_MATRIX, IDENTITY_MATRIX,
LINE_DESCENT_FACTOR, LINE_DESCENT_FACTOR,
@ -147,7 +146,6 @@ class AnnotationFactory {
!collectFields && acroFormDict.get("NeedAppearances") === true, !collectFields && acroFormDict.get("NeedAppearances") === true,
pageIndex, pageIndex,
isOffscreenCanvasSupported: isOffscreenCanvasSupported:
FeatureTest.isOffscreenCanvasSupported &&
pdfManager.evaluatorOptions.isOffscreenCanvasSupported, pdfManager.evaluatorOptions.isOffscreenCanvasSupported,
}; };
@ -306,10 +304,8 @@ class AnnotationFactory {
} }
const xref = evaluator.xref; const xref = evaluator.xref;
const { isOffscreenCanvasSupported } = evaluator.options;
const promises = []; const promises = [];
const isOffscreenCanvasSupported =
FeatureTest.isOffscreenCanvasSupported &&
evaluator.options.isOffscreenCanvasSupported;
for (const annotation of annotations) { for (const annotation of annotations) {
switch (annotation.annotationType) { switch (annotation.annotationType) {
case AnnotationEditorType.FREETEXT: case AnnotationEditorType.FREETEXT:

View File

@ -80,7 +80,7 @@ const DefaultPartialEvaluatorOptions = Object.freeze({
disableFontFace: false, disableFontFace: false,
ignoreErrors: false, ignoreErrors: false,
isEvalSupported: true, isEvalSupported: true,
isOffscreenCanvasSupported: true, isOffscreenCanvasSupported: false,
fontExtraProperties: false, fontExtraProperties: false,
useSystemFonts: true, useSystemFonts: true,
cMapUrl: null, cMapUrl: null,

View File

@ -13,14 +13,7 @@
* limitations under the License. * limitations under the License.
*/ */
import { import { assert, FormatError, ImageKind, info, warn } from "../shared/util.js";
assert,
FeatureTest,
FormatError,
ImageKind,
info,
warn,
} from "../shared/util.js";
import { applyMaskImageData } from "../shared/image_utils.js"; import { applyMaskImageData } from "../shared/image_utils.js";
import { BaseStream } from "./base_stream.js"; import { BaseStream } from "./base_stream.js";
import { ColorSpace } from "./colorspace.js"; import { ColorSpace } from "./colorspace.js";
@ -356,7 +349,7 @@ class PDFImage {
imageIsFromDecodeStream, imageIsFromDecodeStream,
inverseDecode, inverseDecode,
interpolate, interpolate,
isOffscreenCanvasSupported = true, isOffscreenCanvasSupported = false,
}) { }) {
const isSingleOpaquePixel = const isSingleOpaquePixel =
width === 1 && width === 1 &&
@ -367,7 +360,7 @@ class PDFImage {
return { isSingleOpaquePixel }; return { isSingleOpaquePixel };
} }
if (isOffscreenCanvasSupported && FeatureTest.isOffscreenCanvasSupported) { if (isOffscreenCanvasSupported) {
const canvas = new OffscreenCanvas(width, height); const canvas = new OffscreenCanvas(width, height);
const ctx = canvas.getContext("2d"); const ctx = canvas.getContext("2d");
const imgData = ctx.createImageData(width, height); const imgData = ctx.createImageData(width, height);

View File

@ -15,6 +15,7 @@
import { import {
createValidAbsoluteUrl, createValidAbsoluteUrl,
FeatureTest,
shadow, shadow,
unreachable, unreachable,
warn, warn,
@ -44,6 +45,12 @@ class BasePdfManager {
this._docId = args.docId; this._docId = args.docId;
this._password = args.password; this._password = args.password;
this.enableXfa = args.enableXfa; this.enableXfa = args.enableXfa;
// Check `OffscreenCanvas` support once, rather than repeatedly throughout
// the worker-thread code.
args.evaluatorOptions.isOffscreenCanvasSupported =
args.evaluatorOptions.isOffscreenCanvasSupported &&
FeatureTest.isOffscreenCanvasSupported;
this.evaluatorOptions = args.evaluatorOptions; this.evaluatorOptions = args.evaluatorOptions;
} }