Skip to content

Commit 0b6c985

Browse files
authored
Merge pull request #920 from DavidHGillen/master
Fixes issue with bitmap cache and bounds calculations
2 parents b056f33 + 54e8c3e commit 0b6c985

4 files changed

Lines changed: 36 additions & 13 deletions

File tree

extras/SVGExporter/SVGExporter.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,8 @@
291291
var img = this._getImage(o.cacheCanvas, "cache");
292292
if (!img) { return; }
293293
// don't forget cache offset & scale
294-
return this.exportCommon(img, o, "cache", o._cacheOffsetX, o._cacheOffsetY, o._cacheScale);
294+
var cache = o.bitmapCache;
295+
return this.exportCommon(img, o, "cache", cache._filterOffX, cache._filterOffY, cache.scale);
295296
};
296297

297298
p.exportContainer = function(o) {

src/easeljs/display/DisplayObject.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,7 @@ this.createjs = this.createjs||{};
719719
},
720720
scale: {
721721
get: function() { return this.scaleX; },
722-
set: function(scale) { this.scaleX = this.scaleY = scale; },
722+
set: function(scale) { this.scaleX = this.scaleY = scale; }
723723
}
724724
});
725725
} catch (e) {}
@@ -1144,10 +1144,9 @@ this.createjs = this.createjs||{};
11441144
**/
11451145
p.getBounds = function() {
11461146
if (this._bounds) { return this._rectangle.copy(this._bounds); }
1147-
var cacheCanvas = this.cacheCanvas;
1148-
if (cacheCanvas) {
1149-
var scale = this._cacheScale;
1150-
return this._rectangle.setValues(this._cacheOffsetX, this._cacheOffsetY, cacheCanvas.width/scale, cacheCanvas.height/scale);
1147+
var cache = this.bitmapCache;
1148+
if (cache) {
1149+
return cache.getBounds();
11511150
}
11521151
return null;
11531152
};

src/easeljs/display/StageGL.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,7 +1479,7 @@ this.createjs = this.createjs||{};
14791479
var texture = this.getBaseTexture(w, h);
14801480

14811481
if(!texture) {
1482-
msg = "Problem creating texture, possible cause: using too much VRAM, please try releasing texture memory";
1482+
var msg = "Problem creating texture, possible cause: using too much VRAM, please try releasing texture memory";
14831483
(console.error && console.error(msg)) || console.log(msg);
14841484

14851485
texture = this._baseTextures[0];
@@ -1644,16 +1644,16 @@ this.createjs = this.createjs||{};
16441644
*/
16451645
p._createShader = function (gl, type, str) {
16461646
// inject the static number
1647-
str = str.replace(/{{count}}/g, this._batchTextureCount);
1647+
str = str.replace(/\{\{count}}/g, this._batchTextureCount);
16481648

16491649
// resolve issue with no dynamic samplers by creating correct samplers in if else chain
16501650
// TODO: WebGL 2.0 does not need this support
16511651
var insert = "";
16521652
for (var i = 1; i<this._batchTextureCount; i++) {
16531653
insert += "} else if (indexPicker <= "+ i +".5) { color = texture2D(uSampler["+ i +"], vTextureCoord);";
16541654
}
1655-
str = str.replace(/{{alternates}}/g, insert);
1656-
str = str.replace(/{{fragColor}}/g, this._premultiply ? StageGL.REGULAR_FRAG_COLOR_PREMULTIPLY : StageGL.REGULAR_FRAG_COLOR_NORMAL);
1655+
str = str.replace(/\{\{alternates}}/g, insert);
1656+
str = str.replace(/\{\{fragColor}}/g, this._premultiply ? StageGL.REGULAR_FRAG_COLOR_PREMULTIPLY : StageGL.REGULAR_FRAG_COLOR_NORMAL);
16571657

16581658
// actually compile the shader
16591659
var shader = gl.createShader(type);

src/easeljs/filters/BitmapCache.js

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,15 @@ this.createjs = this.createjs||{};
193193
* @default 0
194194
**/
195195
this._drawHeight = 0;
196+
197+
/**
198+
* Internal tracking of the last requested bounds, may happen repeadtedly so stored to avoid object creation
199+
* @property _boundRect
200+
* @protected
201+
* @type {Rectangle}
202+
* @default 0
203+
**/
204+
this._boundRect = new createjs.Rectangle();
196205
}
197206
var p = BitmapCache.prototype;
198207

@@ -401,6 +410,19 @@ this.createjs = this.createjs||{};
401410
return true;
402411
};
403412

413+
/**
414+
* Determine the bounds of the shape in local space.
415+
* @method getBounds
416+
* @returns {Rectangle}
417+
*/
418+
p.getBounds = function() {
419+
var scale = this.scale;
420+
return this._boundRect.setValue(
421+
this._filterOffX/scale, this._filterOffY/scale,
422+
this.width/scale, this.height/scale
423+
);
424+
};
425+
404426
// private methods:
405427
/**
406428
* Create or resize the invisible canvas/surface that is needed for the display object(s) to draw to,
@@ -410,8 +432,10 @@ this.createjs = this.createjs||{};
410432
* @protected
411433
**/
412434
p._updateSurface = function() {
435+
var surface;
436+
413437
if (!this._options || !this._options.useGL) {
414-
var surface = this.target.cacheCanvas;
438+
surface = this.target.cacheCanvas;
415439

416440
// create it if it's missing
417441
if(!surface) {
@@ -451,7 +475,7 @@ this.createjs = this.createjs||{};
451475
}
452476

453477
// now size render surfaces
454-
var surface = this.target.cacheCanvas;
478+
surface = this.target.cacheCanvas;
455479
var stageGL = this._webGLCache;
456480

457481
// if we have a dedicated stage we've gotta size it
@@ -483,7 +507,6 @@ this.createjs = this.createjs||{};
483507
var webGL = this._webGLCache;
484508

485509
if (webGL){
486-
//TODO: auto split blur into an x/y pass
487510
webGL.cacheDraw(target, target.filters, this);
488511

489512
// we may of swapped around which element the surface is, so we re-fetch it

0 commit comments

Comments
 (0)