Skip to content

Commit

Permalink
Merge pull request #13358 from Snuffleupagus/rm-WebGL
Browse files Browse the repository at this point in the history
[api-minor] Remove the WebGL implementation
  • Loading branch information
timvandermeij committed May 9, 2021
2 parents 99eac86 + 2ba4b65 commit f07d50f
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 609 deletions.
6 changes: 0 additions & 6 deletions extensions/chromium/preferences_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,6 @@
],
"default": 0
},
"enableWebGL": {
"title": "Enable WebGL",
"description": "Whether to enable WebGL.",
"type": "boolean",
"default": false
},
"pdfBugEnabled": {
"title": "Enable debugging tools",
"description": "Whether to enable debugging tools.",
Expand Down
11 changes: 0 additions & 11 deletions src/display/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ import { MessageHandler } from "../shared/message_handler.js";
import { Metadata } from "./metadata.js";
import { OptionalContentConfig } from "./optional_content_config.js";
import { PDFDataTransportStream } from "./transport_stream.js";
import { WebGLContext } from "./webgl.js";

const DEFAULT_RANGE_CHUNK_SIZE = 65536; // 2^16 = 65536
const RENDERING_CANCELLED_TIMEOUT = 100; // ms
Expand Down Expand Up @@ -1092,8 +1091,6 @@ class PDFDocumentProxy {
* the `PDFPageProxy.getViewport` method.
* @property {string} [intent] - Rendering intent, can be 'display' or 'print'.
* The default value is 'display'.
* @property {boolean} [enableWebGL] - Enables WebGL accelerated rendering for
* some operations. The default value is `false`.
* @property {boolean} [renderInteractiveForms] - Whether or not interactive
* form elements are rendered in the display layer. If so, we do not render
* them on the canvas as well. The default value is `false`.
Expand Down Expand Up @@ -1272,7 +1269,6 @@ class PDFPageProxy {
canvasContext,
viewport,
intent = "display",
enableWebGL = false,
renderInteractiveForms = false,
transform = null,
imageLayer = null,
Expand Down Expand Up @@ -1319,9 +1315,6 @@ class PDFPageProxy {
const canvasFactoryInstance =
canvasFactory ||
new DefaultCanvasFactory({ ownerDocument: this._ownerDocument });
const webGLContext = new WebGLContext({
enable: enableWebGL,
});
const annotationStorage = includeAnnotationStorage
? this._transport.annotationStorage.serializable
: null;
Expand Down Expand Up @@ -1388,7 +1381,6 @@ class PDFPageProxy {
operatorList: intentState.operatorList,
pageIndex: this._pageIndex,
canvasFactory: canvasFactoryInstance,
webGLContext,
useRequestAnimationFrame: renderingIntent !== "print",
pdfBug: this._pdfBug,
});
Expand Down Expand Up @@ -3022,7 +3014,6 @@ const InternalRenderTask = (function InternalRenderTaskClosure() {
operatorList,
pageIndex,
canvasFactory,
webGLContext,
useRequestAnimationFrame = false,
pdfBug = false,
}) {
Expand All @@ -3034,7 +3025,6 @@ const InternalRenderTask = (function InternalRenderTaskClosure() {
this.operatorList = operatorList;
this._pageIndex = pageIndex;
this.canvasFactory = canvasFactory;
this.webGLContext = webGLContext;
this._pdfBug = pdfBug;

this.running = false;
Expand Down Expand Up @@ -3093,7 +3083,6 @@ const InternalRenderTask = (function InternalRenderTaskClosure() {
this.commonObjs,
this.objs,
this.canvasFactory,
this.webGLContext,
imageLayer,
optionalContentConfig
);
Expand Down
38 changes: 5 additions & 33 deletions src/display/canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,7 @@ const CanvasGraphics = (function CanvasGraphicsClosure() {
}
}

function composeSMask(ctx, smask, layerCtx, webGLContext) {
function composeSMask(ctx, smask, layerCtx) {
const mask = smask.canvas;
const maskCtx = smask.context;

Expand All @@ -821,27 +821,13 @@ const CanvasGraphics = (function CanvasGraphicsClosure() {
smask.offsetY
);

const backdrop = smask.backdrop || null;
if (!smask.transferMap && webGLContext.isEnabled) {
const composed = webGLContext.composeSMask({
layer: layerCtx.canvas,
mask,
properties: {
subtype: smask.subtype,
backdrop,
},
});
ctx.setTransform(1, 0, 0, 1, 0, 0);
ctx.drawImage(composed, smask.offsetX, smask.offsetY);
return;
}
genericComposeSMask(
maskCtx,
layerCtx,
mask.width,
mask.height,
smask.subtype,
backdrop,
smask.backdrop,
smask.transferMap
);
ctx.drawImage(mask, 0, 0);
Expand All @@ -859,7 +845,6 @@ const CanvasGraphics = (function CanvasGraphicsClosure() {
commonObjs,
objs,
canvasFactory,
webGLContext,
imageLayer,
optionalContentConfig
) {
Expand All @@ -873,7 +858,6 @@ const CanvasGraphics = (function CanvasGraphicsClosure() {
this.commonObjs = commonObjs;
this.objs = objs;
this.canvasFactory = canvasFactory;
this.webGLContext = webGLContext;
this.imageLayer = imageLayer;
this.groupStack = [];
this.processingType3 = null;
Expand Down Expand Up @@ -1042,7 +1026,6 @@ const CanvasGraphics = (function CanvasGraphicsClosure() {
}

this.cachedCanvases.clear();
this.webGLContext.clear();

if (this.imageLayer) {
this.imageLayer.endLayout();
Expand Down Expand Up @@ -1192,12 +1175,7 @@ const CanvasGraphics = (function CanvasGraphicsClosure() {
this.groupLevel--;
this.ctx = this.groupStack.pop();

composeSMask(
this.ctx,
this.current.activeSMask,
groupCtx,
this.webGLContext
);
composeSMask(this.ctx, this.current.activeSMask, groupCtx);
this.ctx.restore();
this.ctx.save(); // save is needed since SMask will be resumed.
copyCtxState(groupCtx, this.ctx);
Expand Down Expand Up @@ -1235,12 +1213,7 @@ const CanvasGraphics = (function CanvasGraphicsClosure() {
this.groupLevel--;
this.ctx = this.groupStack.pop();

composeSMask(
this.ctx,
this.current.activeSMask,
groupCtx,
this.webGLContext
);
composeSMask(this.ctx, this.current.activeSMask, groupCtx);
this.ctx.restore();
copyCtxState(groupCtx, this.ctx);
// Transform was changed in the SMask canvas, reflecting this change on
Expand Down Expand Up @@ -2004,8 +1977,7 @@ const CanvasGraphics = (function CanvasGraphicsClosure() {
ctx,
this.commonObjs,
this.objs,
this.canvasFactory,
this.webGLContext
this.canvasFactory
);
},
};
Expand Down
68 changes: 23 additions & 45 deletions src/display/pattern_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,7 @@ const createMeshCanvas = (function createMeshCanvasClosure() {
colors,
figures,
backgroundColor,
cachedCanvases,
webGLContext
cachedCanvases
) {
// we will increase scale on some weird factor to let antialiasing take
// care of "rough" edges
Expand Down Expand Up @@ -273,49 +272,29 @@ const createMeshCanvas = (function createMeshCanvasClosure() {
const paddedWidth = width + BORDER_SIZE * 2;
const paddedHeight = height + BORDER_SIZE * 2;

let canvas, tmpCanvas, i, ii;
if (webGLContext.isEnabled) {
canvas = webGLContext.drawFigures({
width,
height,
backgroundColor,
figures,
context,
});
// https://bugzilla.mozilla.org/show_bug.cgi?id=972126
tmpCanvas = cachedCanvases.getCanvas(
"mesh",
paddedWidth,
paddedHeight,
false
);
tmpCanvas.context.drawImage(canvas, BORDER_SIZE, BORDER_SIZE);
canvas = tmpCanvas.canvas;
} else {
tmpCanvas = cachedCanvases.getCanvas(
"mesh",
paddedWidth,
paddedHeight,
false
);
const tmpCtx = tmpCanvas.context;

const data = tmpCtx.createImageData(width, height);
if (backgroundColor) {
const bytes = data.data;
for (i = 0, ii = bytes.length; i < ii; i += 4) {
bytes[i] = backgroundColor[0];
bytes[i + 1] = backgroundColor[1];
bytes[i + 2] = backgroundColor[2];
bytes[i + 3] = 255;
}
}
for (i = 0; i < figures.length; i++) {
drawFigure(data, figures[i], context);
const tmpCanvas = cachedCanvases.getCanvas(
"mesh",
paddedWidth,
paddedHeight,
false
);
const tmpCtx = tmpCanvas.context;

const data = tmpCtx.createImageData(width, height);
if (backgroundColor) {
const bytes = data.data;
for (let i = 0, ii = bytes.length; i < ii; i += 4) {
bytes[i] = backgroundColor[0];
bytes[i + 1] = backgroundColor[1];
bytes[i + 2] = backgroundColor[2];
bytes[i + 3] = 255;
}
tmpCtx.putImageData(data, BORDER_SIZE, BORDER_SIZE);
canvas = tmpCanvas.canvas;
}
for (let i = 0, ii = figures.length; i < ii; i++) {
drawFigure(data, figures[i], context);
}
tmpCtx.putImageData(data, BORDER_SIZE, BORDER_SIZE);
const canvas = tmpCanvas.canvas;

return {
canvas,
Expand Down Expand Up @@ -362,8 +341,7 @@ ShadingIRs.Mesh = {
colors,
figures,
shadingFill ? null : background,
owner.cachedCanvases,
owner.webGLContext
owner.cachedCanvases
);

if (!shadingFill) {
Expand Down

0 comments on commit f07d50f

Please sign in to comment.