Skip to content

Commit f424356

Browse files
authored
Merge pull request #945 from DavidHGillen/master
Blending modes, cache and filter improvements
2 parents 0a93e7b + 0a2d2ed commit f424356

16 files changed

+2119
-944
lines changed

src/easeljs/display/Bitmap.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,10 @@ this.createjs = this.createjs||{};
212212
**/
213213
p.clone = function(node) {
214214
var image = this.image;
215-
if(image && node){ image = image.cloneNode(); }
215+
if(image && node){
216+
image = image.cloneNode();
217+
image.src = image.src; // IE cloneNode bug fix
218+
}
216219
var o = new Bitmap(image);
217220
if (this.sourceRect) { o.sourceRect = this.sourceRect.clone(); }
218221
this._cloneProps(o);

src/easeljs/display/Container.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -705,4 +705,4 @@ this.createjs = this.createjs||{};
705705

706706

707707
createjs.Container = createjs.promote(Container, "DisplayObject");
708-
}());
708+
}());

src/easeljs/display/DisplayObject.js

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ this.createjs = this.createjs||{};
153153
* If a cache is active, this returns the canvas that holds the image of this display object. See {{#crossLink "DisplayObject/cache:method"}}{{/crossLink}}
154154
* for more information. Use this to display the result of a cache. This will be a HTMLCanvasElement unless special cache rules have been deliberately enabled for this cache.
155155
* @property cacheCanvas
156-
* @type {HTMLCanvasElement | Object}
156+
* @type {HTMLCanvasElement | WebGLTexture | Object}
157157
* @default null
158158
* @readonly
159159
**/
@@ -457,6 +457,15 @@ this.createjs = this.createjs||{};
457457
* @default 0
458458
*/
459459
this._webGLRenderStyle = DisplayObject._StageGL_NONE;
460+
461+
/**
462+
* Storage for the calculated position of an object in StageGL. If not using StageGL, you can null it to save memory.
463+
* @property _glMtx
464+
* @protected
465+
* @type {Matrix2D}
466+
* @default null
467+
*/
468+
this._glMtx = new createjs.Matrix2D();
460469
}
461470
var p = createjs.extend(DisplayObject, createjs.EventDispatcher);
462471

@@ -751,7 +760,7 @@ this.createjs = this.createjs||{};
751760
**/
752761
p.draw = function(ctx, ignoreCache) {
753762
var cache = this.bitmapCache;
754-
if(cache && !ignoreCache) {
763+
if (cache && !ignoreCache) {
755764
return cache.draw(ctx);
756765
}
757766
return false;
@@ -826,8 +835,10 @@ this.createjs = this.createjs||{};
826835
* @param {Object} [options=undefined] Specify additional parameters for the cache logic
827836
**/
828837
p.cache = function(x, y, width, height, scale, options) {
829-
if(!this.bitmapCache){
838+
if (!this.bitmapCache){
830839
this.bitmapCache = new createjs.BitmapCache();
840+
} else {
841+
this.bitmapCache._autoGenerated = false;
831842
}
832843
this.bitmapCache.define(this, x, y, width, height, scale, options);
833844
};
@@ -855,7 +866,7 @@ this.createjs = this.createjs||{};
855866
* whatwg spec on compositing</a>.
856867
**/
857868
p.updateCache = function(compositeOperation) {
858-
if(!this.bitmapCache) {
869+
if (!this.bitmapCache) {
859870
throw "cache() must be called before updateCache()";
860871
}
861872
this.bitmapCache.update(compositeOperation);
@@ -866,7 +877,7 @@ this.createjs = this.createjs||{};
866877
* @method uncache
867878
**/
868879
p.uncache = function() {
869-
if(this.bitmapCache) {
880+
if (this.bitmapCache) {
870881
this.bitmapCache.release();
871882
this.bitmapCache = undefined;
872883
}
@@ -996,8 +1007,9 @@ this.createjs = this.createjs||{};
9961007
* @return {Matrix2D} A matrix representing this display object's transform.
9971008
**/
9981009
p.getMatrix = function(matrix) {
999-
var o = this, mtx = matrix&&matrix.identity() || new createjs.Matrix2D();
1000-
return o.transformMatrix ? mtx.copy(o.transformMatrix) : mtx.appendTransform(o.x, o.y, o.scaleX, o.scaleY, o.rotation, o.skewX, o.skewY, o.regX, o.regY);
1010+
var o = this, mtx = matrix || new createjs.Matrix2D();
1011+
return o.transformMatrix ? mtx.copy(o.transformMatrix) :
1012+
(mtx.identity() && mtx.appendTransform(o.x, o.y, o.scaleX, o.scaleY, o.rotation, o.skewX, o.skewY, o.regX, o.regY));
10011013
};
10021014

10031015
/**
@@ -1254,6 +1266,7 @@ this.createjs = this.createjs||{};
12541266
o.hitArea = this.hitArea;
12551267
o.cursor = this.cursor;
12561268
o._bounds = this._bounds;
1269+
o._webGLRenderStyle = this._webGLRenderStyle;
12571270
return o;
12581271
};
12591272

src/easeljs/display/Stage.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,24 @@ this.createjs = this.createjs||{};
376376
ctx.restore();
377377
this.dispatchEvent("drawend");
378378
};
379-
379+
380+
/**
381+
* Draws the stage into the specified context ignoring its visible, alpha, shadow, and transform.
382+
* Returns true if the draw was handled (useful for overriding functionality).
383+
*
384+
* NOTE: This method is mainly for internal use, though it may be useful for advanced uses.
385+
* @method draw
386+
* @param {CanvasRenderingContext2D} ctx The canvas 2D context object to draw into.
387+
* @param {Boolean} [ignoreCache=false] Indicates whether the draw operation should ignore any current cache.
388+
* For example, used for drawing the cache (to prevent it from simply drawing an existing cache back
389+
* into itself).
390+
**/
391+
p.draw = function(ctx, ignoreCache) {
392+
var result = this.Container_draw(ctx, ignoreCache);
393+
this.canvas._invalid = true;
394+
return result;
395+
};
396+
380397
/**
381398
* Propagates a tick event through the display list. This is automatically called by {{#crossLink "Stage/update"}}{{/crossLink}}
382399
* unless {{#crossLink "Stage/tickOnUpdate:property"}}{{/crossLink}} is set to false.

0 commit comments

Comments
 (0)