mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-26 01:58:06 +02:00
Improve caching of shading patterns. (bug 1721949)
The PDF in bug 1721949 uses many unique pattern objects that references the same shading many times. This caused a new canvas pattern to be created and cached many times driving up memory use. To fix, I've changed the cache in the worker to key off the shading object and instead send the shading and matrix separately. While that worked well to fix the above bug, there could be PDFs that use many shading that could cause memory issues, so I've also added a LRU cache on the main thread for canvas patterns. This should prevent memory use from getting too high.
This commit is contained in:
parent
777d890268
commit
c836e1f0fb
4 changed files with 85 additions and 60 deletions
|
@ -44,7 +44,6 @@ class Pattern {
|
|||
|
||||
static parseShading(
|
||||
shading,
|
||||
matrix,
|
||||
xref,
|
||||
res,
|
||||
handler,
|
||||
|
@ -60,7 +59,6 @@ class Pattern {
|
|||
case ShadingType.RADIAL:
|
||||
return new RadialAxialShading(
|
||||
dict,
|
||||
matrix,
|
||||
xref,
|
||||
res,
|
||||
pdfFunctionFactory,
|
||||
|
@ -72,7 +70,6 @@ class Pattern {
|
|||
case ShadingType.TENSOR_PATCH_MESH:
|
||||
return new MeshShading(
|
||||
shading,
|
||||
matrix,
|
||||
xref,
|
||||
res,
|
||||
pdfFunctionFactory,
|
||||
|
@ -115,16 +112,8 @@ class BaseShading {
|
|||
// Radial and axial shading have very similar implementations
|
||||
// If needed, the implementations can be broken into two classes.
|
||||
class RadialAxialShading extends BaseShading {
|
||||
constructor(
|
||||
dict,
|
||||
matrix,
|
||||
xref,
|
||||
resources,
|
||||
pdfFunctionFactory,
|
||||
localColorSpaceCache
|
||||
) {
|
||||
constructor(dict, xref, resources, pdfFunctionFactory, localColorSpaceCache) {
|
||||
super();
|
||||
this.matrix = matrix;
|
||||
this.coordsArr = dict.getArray("Coords");
|
||||
this.shadingType = dict.get("ShadingType");
|
||||
const cs = ColorSpace.parse({
|
||||
|
@ -244,17 +233,7 @@ class RadialAxialShading extends BaseShading {
|
|||
unreachable(`getPattern type unknown: ${shadingType}`);
|
||||
}
|
||||
|
||||
return [
|
||||
"RadialAxial",
|
||||
type,
|
||||
this.bbox,
|
||||
this.colorStops,
|
||||
p0,
|
||||
p1,
|
||||
r0,
|
||||
r1,
|
||||
this.matrix,
|
||||
];
|
||||
return ["RadialAxial", type, this.bbox, this.colorStops, p0, p1, r0, r1];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -418,7 +397,6 @@ class MeshShading extends BaseShading {
|
|||
|
||||
constructor(
|
||||
stream,
|
||||
matrix,
|
||||
xref,
|
||||
resources,
|
||||
pdfFunctionFactory,
|
||||
|
@ -429,7 +407,6 @@ class MeshShading extends BaseShading {
|
|||
throw new FormatError("Mesh data is not a stream");
|
||||
}
|
||||
const dict = stream.dict;
|
||||
this.matrix = matrix;
|
||||
this.shadingType = dict.get("ShadingType");
|
||||
const bbox = dict.getArray("BBox");
|
||||
if (Array.isArray(bbox) && bbox.length === 4) {
|
||||
|
@ -942,7 +919,6 @@ class MeshShading extends BaseShading {
|
|||
this.colors,
|
||||
this.figures,
|
||||
this.bounds,
|
||||
this.matrix,
|
||||
this.bbox,
|
||||
this.background,
|
||||
];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue