mirror of
https://github.com/Hopiu/fabric.js.git
synced 2026-03-16 22:10:32 +00:00
Remove caching of some path parsing steps (#5140)
* disable caching * missing jsdocs * missing jsdocs * added jsdocs
This commit is contained in:
parent
ed50b032de
commit
146769e0a5
2 changed files with 36 additions and 18 deletions
22
HEADER.js
22
HEADER.js
|
|
@ -140,6 +140,28 @@ fabric.devicePixelRatio = fabric.window.devicePixelRatio ||
|
|||
*/
|
||||
fabric.browserShadowBlurConstant = 1;
|
||||
|
||||
/**
|
||||
* This object contains the result of arc to beizer conversion for faster retrieving if the same arc needs to be converted again.
|
||||
* It was an internal variable, is accessible since version 2.3.4
|
||||
*/
|
||||
fabric.arcToSegmentsCache = { };
|
||||
|
||||
/**
|
||||
* This object keeps the results of the boundsOfCurve calculation mapped by the joined arguments necessary to calculate it.
|
||||
* It does speed up calculation, if you parse and add always the same paths, but in case of heavy usage of freedrawing
|
||||
* you do not get any speed benefit and you get a big object in memory.
|
||||
* The object was a private variable before, while now is appended to the lib so that you have access to it and you
|
||||
* can eventually clear it.
|
||||
* It was an internal variable, is accessible since version 2.3.4
|
||||
*/
|
||||
fabric.boundsOfCurveCache = { };
|
||||
|
||||
/**
|
||||
* If disabled boundsOfCurveCache is not used. For apps that make heavy usage of pencil drawing probably disabling it is better
|
||||
* @default true
|
||||
*/
|
||||
fabric.cachesBoundsOfCurve = true;
|
||||
|
||||
fabric.initFilterBackend = function() {
|
||||
if (fabric.enableGLFiltering && fabric.isWebglSupported && fabric.isWebglSupported(fabric.textureSize)) {
|
||||
console.log('max texture size: ' + fabric.maxTextureSize);
|
||||
|
|
|
|||
|
|
@ -1,9 +1,6 @@
|
|||
(function() {
|
||||
|
||||
var arcToSegmentsCache = { },
|
||||
segmentToBezierCache = { },
|
||||
boundsOfCurveCache = { },
|
||||
_join = Array.prototype.join;
|
||||
var _join = Array.prototype.join;
|
||||
|
||||
/* Adapted from http://dxr.mozilla.org/mozilla-central/source/content/svg/content/src/nsSVGPathDataParser.cpp
|
||||
* by Andrea Bogazzi code is under MPL. if you don't have a copy of the license you can take it here
|
||||
|
|
@ -11,8 +8,8 @@
|
|||
*/
|
||||
function arcToSegments(toX, toY, rx, ry, large, sweep, rotateX) {
|
||||
var argsString = _join.call(arguments);
|
||||
if (arcToSegmentsCache[argsString]) {
|
||||
return arcToSegmentsCache[argsString];
|
||||
if (fabric.arcToSegmentsCache[argsString]) {
|
||||
return fabric.arcToSegmentsCache[argsString];
|
||||
}
|
||||
|
||||
var PI = Math.PI, th = rotateX * PI / 180,
|
||||
|
|
@ -66,16 +63,11 @@
|
|||
mTheta = th3;
|
||||
th3 += mDelta;
|
||||
}
|
||||
arcToSegmentsCache[argsString] = result;
|
||||
fabric.arcToSegmentsCache[argsString] = result;
|
||||
return result;
|
||||
}
|
||||
|
||||
function segmentToBezier(th2, th3, cosTh, sinTh, rx, ry, cx1, cy1, mT, fromX, fromY) {
|
||||
var argsString2 = _join.call(arguments);
|
||||
if (segmentToBezierCache[argsString2]) {
|
||||
return segmentToBezierCache[argsString2];
|
||||
}
|
||||
|
||||
var costh2 = fabric.util.cos(th2),
|
||||
sinth2 = fabric.util.sin(th2),
|
||||
costh3 = fabric.util.cos(th3),
|
||||
|
|
@ -87,12 +79,11 @@
|
|||
cp2X = toX + mT * ( cosTh * rx * sinth3 + sinTh * ry * costh3),
|
||||
cp2Y = toY + mT * ( sinTh * rx * sinth3 - cosTh * ry * costh3);
|
||||
|
||||
segmentToBezierCache[argsString2] = [
|
||||
return [
|
||||
cp1X, cp1Y,
|
||||
cp2X, cp2Y,
|
||||
toX, toY
|
||||
];
|
||||
return segmentToBezierCache[argsString2];
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -178,9 +169,12 @@
|
|||
*/
|
||||
// taken from http://jsbin.com/ivomiq/56/edit no credits available for that.
|
||||
function getBoundsOfCurve(x0, y0, x1, y1, x2, y2, x3, y3) {
|
||||
var argsString = _join.call(arguments);
|
||||
if (boundsOfCurveCache[argsString]) {
|
||||
return boundsOfCurveCache[argsString];
|
||||
var argsString;
|
||||
if (fabric.cachesBoundsOfCurve) {
|
||||
argsString = _join.call(arguments);
|
||||
if (fabric.boundsOfCurveCache[argsString]) {
|
||||
return fabric.boundsOfCurveCache[argsString];
|
||||
}
|
||||
}
|
||||
|
||||
var sqrt = Math.sqrt,
|
||||
|
|
@ -250,7 +244,9 @@
|
|||
y: max.apply(null, bounds[1])
|
||||
}
|
||||
];
|
||||
boundsOfCurveCache[argsString] = result;
|
||||
if (fabric.cachesBoundsOfCurve) {
|
||||
fabric.boundsOfCurveCache[argsString] = result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue