From 77efed6626af11bd77ee7ef535c6e84ed060bca1 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Tue, 13 Feb 2018 14:16:10 +0100 Subject: [PATCH] Replace the `PDFJS.disableWebGL` option with a `enableWebGL` option passed, via `BaseViewer`/`PDFPageView`, to `PDFPageProxy.render` Please note that the, pre-existing, viewer preference is already named `enableWebGL`; fixes 4919. --- src/display/api.js | 6 +++--- src/display/dom_utils.js | 2 -- src/display/global.js | 7 ------- web/app.js | 8 +++++--- web/base_viewer.js | 4 ++++ web/pdf_page_view.js | 4 ++++ 6 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/display/api.js b/src/display/api.js index cfa95f00d..e5befbb5f 100644 --- a/src/display/api.js +++ b/src/display/api.js @@ -707,6 +707,8 @@ var PDFDocumentProxy = (function PDFDocumentProxyClosure() { * calling of PDFPage.getViewport method. * @property {string} intent - Rendering intent, can be 'display' or 'print' * (default value is 'display'). + * @property {boolean} enableWebGL - (optional) Enables WebGL accelerated + * rendering for some operations. The default value is `false`. * @property {boolean} renderInteractiveForms - (optional) Whether or not * interactive form elements are rendered in the display * layer. If so, we do not render them on canvas as well. @@ -828,9 +830,7 @@ var PDFPageProxy = (function PDFPageProxyClosure() { var renderingIntent = (params.intent === 'print' ? 'print' : 'display'); var canvasFactory = params.canvasFactory || new DOMCanvasFactory(); let webGLContext = new WebGLContext({ - // TODO: When moving this parameter from `PDFJS` to {RenderParameters}, - // change its name to `enableWebGL` instead. - enable: !getDefaultSetting('disableWebGL'), + enable: params.enableWebGL, }); if (!this.intentStates[renderingIntent]) { diff --git a/src/display/dom_utils.js b/src/display/dom_utils.js index 52bcf4895..e82a5b83f 100644 --- a/src/display/dom_utils.js +++ b/src/display/dom_utils.js @@ -345,8 +345,6 @@ function getDefaultSetting(id) { return globalSettings ? globalSettings.disableFontFace : false; case 'disableCreateObjectURL': return globalSettings ? globalSettings.disableCreateObjectURL : false; - case 'disableWebGL': - return globalSettings ? globalSettings.disableWebGL : true; case 'cMapUrl': return globalSettings ? globalSettings.cMapUrl : null; case 'cMapPacked': diff --git a/src/display/global.js b/src/display/global.js index e764752a8..a7a99f5fb 100644 --- a/src/display/global.js +++ b/src/display/global.js @@ -180,13 +180,6 @@ PDFJS.postMessageTransfers = (PDFJS.postMessageTransfers === undefined ? PDFJS.disableCreateObjectURL = (PDFJS.disableCreateObjectURL === undefined ? false : PDFJS.disableCreateObjectURL); -/** - * Disables WebGL usage. - * @var {boolean} - */ -PDFJS.disableWebGL = (PDFJS.disableWebGL === undefined ? - true : PDFJS.disableWebGL); - /** * Specifies the |target| attribute for external links. * The constants from {LinkTarget} should be used: diff --git a/web/app.js b/web/app.js index cd4cc1495..da44cd7d1 100644 --- a/web/app.js +++ b/web/app.js @@ -139,6 +139,7 @@ let PDFViewerApplication = { isInitialViewSet: false, downloadComplete: false, viewerPrefs: { + enableWebGL: false, sidebarViewOnLoad: SidebarView.NONE, pdfBugEnabled: false, showPreviousViewOnLoad: true, @@ -203,7 +204,7 @@ let PDFViewerApplication = { return Promise.all([ preferences.get('enableWebGL').then(function resolved(value) { - PDFJS.disableWebGL = !value; + viewerPrefs['enableWebGL'] = value; }), preferences.get('sidebarViewOnLoad').then(function resolved(value) { viewerPrefs['sidebarViewOnLoad'] = value; @@ -304,7 +305,7 @@ let PDFViewerApplication = { PDFJS.disableHistory = (hashParams['disablehistory'] === 'true'); } if ('webgl' in hashParams) { - PDFJS.disableWebGL = (hashParams['webgl'] !== 'true'); + viewerPrefs['enableWebGL'] = (hashParams['webgl'] === 'true'); } if ('useonlycsszoom' in hashParams) { PDFJS.useOnlyCssZoom = (hashParams['useonlycsszoom'] === 'true'); @@ -394,6 +395,7 @@ let PDFViewerApplication = { linkService: pdfLinkService, downloadManager, renderer: viewerPrefs['renderer'], + enableWebGL: viewerPrefs['enableWebGL'], l10n: this.l10n, textLayerMode: viewerPrefs['textLayerMode'], imageResourcesPath: PDFJS.imageResourcesPath, @@ -1172,7 +1174,7 @@ let PDFViewerApplication = { info.PDFFormatVersion + ' ' + (info.Producer || '-').trim() + ' / ' + (info.Creator || '-').trim() + ']' + ' (PDF.js: ' + (version || '-') + - (!PDFJS.disableWebGL ? ' [WebGL]' : '') + ')'); + (this.viewerPrefs['enableWebGL'] ? ' [WebGL]' : '') + ')'); let pdfTitle; if (metadata && metadata.has('dc:title')) { diff --git a/web/base_viewer.js b/web/base_viewer.js index b9e2e2591..2b966379a 100644 --- a/web/base_viewer.js +++ b/web/base_viewer.js @@ -52,6 +52,8 @@ const DEFAULT_CACHE_SIZE = 10; * rotation of pages whose orientation differ from the first page upon * printing. The default is `false`. * @property {string} renderer - 'canvas' or 'svg'. The default is 'canvas'. + * @property {boolean} enableWebGL - (optional) Enables WebGL accelerated + * rendering for some operations. The default value is `false`. * @property {boolean} useOnlyCssZoom - (optional) Enables CSS only zooming. * The default value is `false`. * @property {number} maxCanvasPixels - (optional) The maximum supported canvas @@ -123,6 +125,7 @@ class BaseViewer { this.renderInteractiveForms = options.renderInteractiveForms || false; this.enablePrintAutoRotate = options.enablePrintAutoRotate || false; this.renderer = options.renderer || RendererType.CANVAS; + this.enableWebGL = options.enableWebGL || false; this.useOnlyCssZoom = options.useOnlyCssZoom || false; this.maxCanvasPixels = options.maxCanvasPixels; this.l10n = options.l10n || NullL10n; @@ -392,6 +395,7 @@ class BaseViewer { imageResourcesPath: this.imageResourcesPath, renderInteractiveForms: this.renderInteractiveForms, renderer: this.renderer, + enableWebGL: this.enableWebGL, useOnlyCssZoom: this.useOnlyCssZoom, maxCanvasPixels: this.maxCanvasPixels, l10n: this.l10n, diff --git a/web/pdf_page_view.js b/web/pdf_page_view.js index 65e1b46af..3b4f91425 100644 --- a/web/pdf_page_view.js +++ b/web/pdf_page_view.js @@ -43,6 +43,8 @@ import { viewerCompatibilityParams } from './viewer_compatibility'; * @property {boolean} renderInteractiveForms - Turns on rendering of * interactive form elements. The default is `false`. * @property {string} renderer - 'canvas' or 'svg'. The default is 'canvas'. + * @property {boolean} enableWebGL - (optional) Enables WebGL accelerated + * rendering for some operations. The default value is `false`. * @property {boolean} useOnlyCssZoom - (optional) Enables CSS only zooming. * The default value is `false`. * @property {number} maxCanvasPixels - (optional) The maximum supported canvas @@ -86,6 +88,7 @@ class PDFPageView { this.textLayerFactory = options.textLayerFactory; this.annotationLayerFactory = options.annotationLayerFactory; this.renderer = options.renderer || RendererType.CANVAS; + this.enableWebGL = options.enableWebGL || false; this.l10n = options.l10n || NullL10n; this.paintTask = null; @@ -571,6 +574,7 @@ class PDFPageView { canvasContext: ctx, transform, viewport: this.viewport, + enableWebGL: this.enableWebGL, renderInteractiveForms: this.renderInteractiveForms, }; let renderTask = this.pdfPage.render(renderContext);