Skip to content

Commit

Permalink
isTargetTransparent() now samples the cache directly.
Browse files Browse the repository at this point in the history
Previously, isTargetTransparent would do a paint from the cache
to the contextCache which has more overhead and is slower.
With this commit, fabricjs will test the cache canvas directly
using x/y coordinates calculated with respect to the target object
center. This is more performant since it avoids an extra render
on every call to isTargetTransparent.
  • Loading branch information
AndrewJDR committed May 8, 2018
1 parent 3d1d595 commit f89a9b6
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/canvas.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,17 @@
* @return {Boolean}
*/
isTargetTransparent: function (target, x, y) {
if (target.shouldCache() && target._cacheCanvas && !target.isCacheDirty()) {
var normalizedPointer = this._normalizePointer(target, {x:x, y:y}),
targetRelativeX = target.cacheTranslationX + (normalizedPointer.x * target.zoomX),
targetRelativeY = target.cacheTranslationY + (normalizedPointer.y * target.zoomY);

var isTransparent = fabric.util.isTransparent(
target._cacheContext, targetRelativeX, targetRelativeY, this.targetFindTolerance);

return isTransparent;
}

var ctx = this.contextCache,
originalColor = target.selectionBackgroundColor, v = this.viewportTransform;

Expand Down

0 comments on commit f89a9b6

Please sign in to comment.