Remove ctx.currentPath caching optimization.

Unfortunately all browser have moved away from this again, in favour of Path2D.
This commit is contained in:
Jürg Lehni 2016-01-10 11:51:56 +01:00
parent 4eafe808fa
commit c5eaaff073
4 changed files with 13 additions and 45 deletions

View file

@ -174,15 +174,9 @@ var Group = Item.extend(/** @lends Group# */{
param = param.extend({ clipItem: clipItem, clip: false });
if (clip) {
// If told to clip with a group, we start our own path and draw each
// child just like in a compound-path. We also cache the resulting
// path in _currentPath.
if (this._currentPath) {
ctx.currentPath = this._currentPath;
draw = false;
} else {
ctx.beginPath();
param.dontStart = param.dontFinish = true;
}
// child just like in a compound-path.
ctx.beginPath();
param.dontStart = param.dontFinish = true;
} else if (clipItem) {
clipItem.draw(ctx, param.extend({ clip: true }));
}
@ -194,8 +188,5 @@ var Group = Item.extend(/** @lends Group# */{
item.draw(ctx, param);
}
}
if (clip) {
this._currentPath = ctx.currentPath;
}
}
});

View file

@ -195,10 +195,9 @@ var Item = Base.extend(Emitter, /** @lends Item# */{
project = this._project;
if (flags & /*#=*/ChangeFlag.GEOMETRY) {
// Clear cached bounds, position and decomposed matrix whenever
// geometry changes. Also clear _currentPath since it can be used
// both on compound-paths and clipping groups.
// geometry changes.
this._bounds = this._position = this._decomposed =
this._globalMatrix = this._currentPath = undefined;
this._globalMatrix = undefined;
}
if (cacheParent
&& (flags & /*#=*/(ChangeFlag.GEOMETRY | ChangeFlag.STROKE))) {
@ -3908,8 +3907,7 @@ var Item = Base.extend(Emitter, /** @lends Item# */{
viewMatrix = param.viewMatrix,
matrix = this._matrix,
globalMatrix = matrices[matrices.length - 1].chain(matrix);
// If this item is not invertible, do not draw it, since it would cause
// empty ctx.currentPath and mess up caching. It appears to also be a
// If this item is not invertible, do not draw it. It appears to be a
// good idea generally to not draw in such circumstances, e.g. SVG
// handles it the same way.
if (!globalMatrix.isInvertible())
@ -4040,10 +4038,8 @@ var Item = Base.extend(Emitter, /** @lends Item# */{
*/
_isUpdated: function(updateVersion) {
var parent = this._parent;
// For compound-paths, we need to use the _updateVersion of the parent,
// because when using the ctx.currentPath optimization, the children
// don't have to get drawn on each frame and thus won't change their
// _updateVersion.
// For compound-paths, use the _updateVersion of the parent, because the
// shape gets drawn at once at might get cached (e.g. Path2D soon).
if (parent instanceof CompoundPath)
return parent._isUpdated(updateVersion);
// In case a parent is visible but isn't drawn (e.g. opacity == 0), the

View file

@ -288,15 +288,10 @@ var CompoundPath = PathItem.extend(/** @lends CompoundPath# */{
if (children.length === 0)
return;
if (this._currentPath) {
ctx.currentPath = this._currentPath;
} else {
param = param.extend({ dontStart: true, dontFinish: true });
ctx.beginPath();
for (var i = 0, l = children.length; i < l; i++)
children[i].draw(ctx, param, strokeMatrix);
this._currentPath = ctx.currentPath;
}
param = param.extend({ dontStart: true, dontFinish: true });
ctx.beginPath();
for (var i = 0, l = children.length; i < l; i++)
children[i].draw(ctx, param, strokeMatrix);
if (!param.clip) {
this._setStyles(ctx);

View file

@ -142,12 +142,6 @@ var Path = PathItem.extend(/** @lends Path# */{
_changed: function _changed(flags) {
_changed.base.call(this, flags);
if (flags & /*#=*/ChangeFlag.GEOMETRY) {
// The _currentPath is already cleared in Item, but clear it on the
// parent too, for children of CompoundPaths, and Groups (ab)used as
// clipping paths.
var parent = this._parent;
if (parent)
parent._currentPath = undefined;
// Clockwise state becomes undefined as soon as geometry changes.
// Also clear cached mono curves used for winding calculations.
this._length = this._area = this._clockwise = this._monoCurves =
@ -2192,17 +2186,12 @@ new function() { // Scope for drawing
if (!dontStart)
ctx.beginPath();
if (!dontStart && this._currentPath) {
ctx.currentPath = this._currentPath;
} else if (hasFill || hasStroke && !dashLength || dontPaint) {
if (hasFill || hasStroke && !dashLength || dontPaint) {
// Prepare the canvas path if we have any situation that
// requires it to be defined.
drawSegments(ctx, this, strokeMatrix);
if (this._closed)
ctx.closePath();
// CompoundPath collects its own _currentPath
if (!dontStart)
this._currentPath = ctx.currentPath;
}
function getOffset(i) {
@ -2226,9 +2215,6 @@ new function() { // Scope for drawing
if (dashLength) {
// We cannot use the path created by drawSegments above
// Use PathIterator to draw dashed paths:
// NOTE: We don't cache this path in another currentPath
// since browsers that support currentPath also support
// native dashes.
if (!dontStart)
ctx.beginPath();
var iterator = new PathIterator(this, 32, 0.25,