Skip to content

Commit

Permalink
isTargetTransparent() now samples the cache directly. (#4955)
Browse files Browse the repository at this point in the history
* isTargetTransparent() now samples the cache directly.

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.

* remove cacheDirty that should not be needed.
  • Loading branch information
AndrewJDR authored and asturur committed May 19, 2018
1 parent ac804af commit c3b6e65
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 @@ -503,6 +503,17 @@
* @return {Boolean}
*/
isTargetTransparent: function (target, x, y) {
if (target.shouldCache() && target._cacheCanvas) {
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 c3b6e65

Please sign in to comment.