diff --git a/src/shapes/path_group.class.js b/src/shapes/path_group.class.js index ef5b355e520..141e24a7d5e 100644 --- a/src/shapes/path_group.class.js +++ b/src/shapes/path_group.class.js @@ -103,6 +103,52 @@ ctx.restore(); }, + /** + * Decide if the object should cache or not. + * objectCaching is a global flag, wins over everything + * needsItsOwnCache should be used when the object drawing method requires + * a cache step. None of the fabric classes requires it. + * Generally you do not cache objects in groups because the group outside is cached. + * @return {Boolean} + */ + shouldCache: function() { + var parentCache = this.objectCaching && (!this.group || this.needsItsOwnCache || !this.group.isCaching()); + this.caching = parentCache; + if (parentCache) { + for (var i = 0, len = this.paths.length; i < len; i++) { + if (this.paths[i].willDrawShadow()) { + this.caching = false; + return false; + } + } + } + return parentCache; + }, + + /** + * Check if this object or a child object will cast a shadow + * @return {Boolean} + */ + willDrawShadow: function() { + if (this.shadow) { + return true; + } + for (var i = 0, len = this.paths.length; i < len; i++) { + if (this.paths[i].willDrawShadow()) { + return true; + } + } + return false; + }, + + /** + * Check if this group or its parent group are caching, recursively up + * @return {Boolean} + */ + isCaching: function() { + return this.caching || this.group && this.group.isCaching(); + }, + /** * Check if cache is dirty */