mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-10 02:05:37 +02:00
Split the existing WebGLUtils
in two classes, a private WebGLUtils
and a public WebGLContext
, and utilize the latter in the API to allow various code to access the methods of WebGLUtils
This patch is one (small) step on the way to reduce the general dependency on a global `PDFJS` object, for PDF.js version `2.0`.
This commit is contained in:
parent
503bc95a2b
commit
59b5e14301
4 changed files with 86 additions and 43 deletions
|
@ -14,9 +14,35 @@
|
|||
*/
|
||||
/* eslint-disable no-multi-str */
|
||||
|
||||
import { getDefaultSetting } from './dom_utils';
|
||||
import { shadow } from '../shared/util';
|
||||
|
||||
class WebGLContext {
|
||||
constructor({ enable = false, }) {
|
||||
this._enabled = enable === true;
|
||||
}
|
||||
|
||||
get isEnabled() {
|
||||
let enabled = this._enabled;
|
||||
if (enabled) {
|
||||
enabled = WebGLUtils.tryInitGL();
|
||||
}
|
||||
return shadow(this, 'isEnabled', enabled);
|
||||
}
|
||||
|
||||
composeSMask({ layer, mask, properties, }) {
|
||||
return WebGLUtils.composeSMask(layer, mask, properties);
|
||||
}
|
||||
|
||||
drawFigures({ width, height, backgroundColor, figures, context, }) {
|
||||
return WebGLUtils.drawFigures(width, height, backgroundColor, figures,
|
||||
context);
|
||||
}
|
||||
|
||||
clear() {
|
||||
WebGLUtils.cleanup();
|
||||
}
|
||||
}
|
||||
|
||||
var WebGLUtils = (function WebGLUtilsClosure() {
|
||||
function loadShader(gl, code, shaderType) {
|
||||
var shader = gl.createShader(shaderType);
|
||||
|
@ -405,37 +431,34 @@ var WebGLUtils = (function WebGLUtilsClosure() {
|
|||
return canvas;
|
||||
}
|
||||
|
||||
function cleanup() {
|
||||
if (smaskCache && smaskCache.canvas) {
|
||||
smaskCache.canvas.width = 0;
|
||||
smaskCache.canvas.height = 0;
|
||||
}
|
||||
if (figuresCache && figuresCache.canvas) {
|
||||
figuresCache.canvas.width = 0;
|
||||
figuresCache.canvas.height = 0;
|
||||
}
|
||||
smaskCache = null;
|
||||
figuresCache = null;
|
||||
}
|
||||
|
||||
return {
|
||||
get isEnabled() {
|
||||
if (getDefaultSetting('disableWebGL')) {
|
||||
return false;
|
||||
}
|
||||
var enabled = false;
|
||||
tryInitGL() {
|
||||
try {
|
||||
generateGL();
|
||||
enabled = !!currentGL;
|
||||
} catch (e) { }
|
||||
return shadow(this, 'isEnabled', enabled);
|
||||
return !!currentGL;
|
||||
} catch (ex) { }
|
||||
return false;
|
||||
},
|
||||
|
||||
composeSMask,
|
||||
|
||||
drawFigures,
|
||||
clear: cleanup,
|
||||
|
||||
cleanup() {
|
||||
if (smaskCache && smaskCache.canvas) {
|
||||
smaskCache.canvas.width = 0;
|
||||
smaskCache.canvas.height = 0;
|
||||
}
|
||||
if (figuresCache && figuresCache.canvas) {
|
||||
figuresCache.canvas.width = 0;
|
||||
figuresCache.canvas.height = 0;
|
||||
}
|
||||
smaskCache = null;
|
||||
figuresCache = null;
|
||||
},
|
||||
};
|
||||
})();
|
||||
|
||||
export {
|
||||
WebGLUtils,
|
||||
WebGLContext,
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue