@@ -6831,7 +6831,7 @@ this.createjs = this.createjs||{};
6831
6831
* @return {String} The image data url for the cache.
6832
6832
**/
6833
6833
p.getCacheDataURL = function() {
6834
- return this.bitmapCache?this.bitmapCache.getDataURL ():null;
6834
+ return this.bitmapCache?this.bitmapCache.getCacheDataURL ():null;
6835
6835
};
6836
6836
6837
6837
/**
@@ -9461,6 +9461,46 @@ this.createjs = this.createjs||{};
9461
9461
typeof WebGLRenderingContext !== 'undefined';
9462
9462
};
9463
9463
9464
+ /**
9465
+ * Utility used to convert the colour values the Context2D API accepts into WebGL color values.
9466
+ * @param {String | Number} color
9467
+ * @static
9468
+ * @return {Object} Object with r, g, b, a in 0-1 values of the color.
9469
+ */
9470
+ StageGL.colorToObj = function (color) {
9471
+ var r, g, b, a;
9472
+
9473
+ if (typeof color === "string") {
9474
+ if (color.indexOf("#") === 0) {
9475
+ if (color.length === 4) {
9476
+ color = "#" + color.charAt(1)+color.charAt(1) + color.charAt(2)+color.charAt(2) + color.charAt(3)+color.charAt(3)
9477
+ }
9478
+ r = Number("0x"+color.slice(1, 3))/255;
9479
+ g = Number("0x"+color.slice(3, 5))/255;
9480
+ b = Number("0x"+color.slice(5, 7))/255;
9481
+ a = color.length > 7 ? Number("0x"+color.slice(7, 9))/255 : 1;
9482
+ } else if (color.indexOf("rgba(") === 0) {
9483
+ var output = color.slice(5, -1).split(",");
9484
+ r = Number(output[0])/255;
9485
+ g = Number(output[1])/255;
9486
+ b = Number(output[2])/255;
9487
+ a = Number(output[3]);
9488
+ }
9489
+ } else { // >>> is an unsigned shift which is what we want as 0x80000000 and up are negative values
9490
+ r = ((color & 0xFF000000) >>> 24)/255;
9491
+ g = ((color & 0x00FF0000) >>> 16)/255;
9492
+ b = ((color & 0x0000FF00) >>> 8)/255;
9493
+ a = (color & 0x000000FF)/255;
9494
+ }
9495
+
9496
+ return {
9497
+ r: Math.min(Math.max(0, r), 1),
9498
+ g: Math.min(Math.max(0, g), 1),
9499
+ b: Math.min(Math.max(0, b), 1),
9500
+ a: Math.min(Math.max(0, a), 1)
9501
+ }
9502
+ };
9503
+
9464
9504
// static properties:
9465
9505
/**
9466
9506
* The number of properties defined per vertex (x, y, textureU, textureV, textureIndex, alpha)
@@ -10005,7 +10045,7 @@ this.createjs = this.createjs||{};
10005
10045
10006
10046
"hue": {
10007
10047
shader: (StageGL.BLEND_FRAGMENT_HSL_UTIL + StageGL.BLEND_FRAGMENT_COMPLEX +
10008
- "setLum(setSat(srcClr, getSat(dstClr)), getLum(dstClr))"
10048
+ "setLum(setSat(srcClr, getSat(dstClr)), getLum(dstClr))"
10009
10049
+ StageGL.BLEND_FRAGMENT_COMPLEX_CAP)
10010
10050
},
10011
10051
"saturation": {
@@ -10243,6 +10283,12 @@ this.createjs = this.createjs||{};
10243
10283
return false;
10244
10284
}
10245
10285
10286
+ for (var i = 0; i < this._gpuTextureCount; i++) {
10287
+ if(this._batchTextures[i]._frameBuffer) {
10288
+ this._batchTextures[i] = this._baseTextures[i];
10289
+ }
10290
+ }
10291
+
10246
10292
var storeBatchOutput = this._batchTextureOutput;
10247
10293
var storeBatchConcat = this._batchTextureConcat;
10248
10294
var storeBatchTemp = this._batchTextureTemp;
@@ -10587,35 +10633,64 @@ this.createjs = this.createjs||{};
10587
10633
* @param {String|int} [color=0x00000000] The new color to use as the background
10588
10634
*/
10589
10635
p.setClearColor = function (color) {
10590
- var r, g, b, a, output;
10636
+ this._clearColor = StageGL.colorToObj(color);
10637
+ };
10591
10638
10592
- if (typeof color === "string") {
10593
- if (color.indexOf("#") === 0) {
10594
- if (color.length === 4) {
10595
- color = "#" + color.charAt(1)+color.charAt(1) + color.charAt(2)+color.charAt(2) + color.charAt(3)+color.charAt(3)
10596
- }
10597
- r = Number("0x"+color.slice(1, 3))/255;
10598
- g = Number("0x"+color.slice(3, 5))/255;
10599
- b = Number("0x"+color.slice(5, 7))/255;
10600
- a = Number("0x"+color.slice(7, 9))/255;
10601
- } else if (color.indexOf("rgba(") === 0) {
10602
- output = color.slice(5, -1).split(",");
10603
- r = Number(output[0])/255;
10604
- g = Number(output[1])/255;
10605
- b = Number(output[2])/255;
10606
- a = Number(output[3]);
10639
+ /**
10640
+ * Returns a data url that contains a Base64-encoded image of the contents of the stage. The returned data url can
10641
+ * be specified as the src value of an image element. StageGL renders differently than Context2D and the information
10642
+ * of the last render is harder to get. For best results turn directDraw to false, or preserveBuffer to true and no
10643
+ * backgorund color.
10644
+ * @method toDataURL
10645
+ * @param {String} [backgroundColor=undefined] The background color to be used for the generated image. See setClearColor
10646
+ * for valid values. A value of undefined will make no adjustments to the existing background which may be significantly faster.
10647
+ * @param {String} [mimeType="image/png"] The MIME type of the image format to be create. The default is "image/png". If an unknown MIME type
10648
+ * is passed in, or if the browser does not support the specified MIME type, the default value will be used.
10649
+ * @return {String} a Base64 encoded image.
10650
+ **/
10651
+ p.toDataURL = function(backgroundColor, mimeType) {
10652
+ var dataURL, gl = this._webGLContext;
10653
+ this.batchReason = "dataURL";
10654
+ var clearBackup = this._clearColor;
10655
+
10656
+ if (!this.canvas) { return; }
10657
+ if (!StageGL.isWebGLActive(gl)) {
10658
+ return this.Stage_toDataURL(backgroundColor, mimeType);
10659
+ }
10660
+
10661
+ // if the buffer is preserved and we don't want a background we can just output what we have, otherwise we'll have to render it
10662
+ if(!this._preserveBuffer || backgroundColor !== undefined) {
10663
+ // render it onto the right background
10664
+ if(backgroundColor !== undefined) {
10665
+ this._clearColor = StageGL.colorToObj(backgroundColor);
10666
+ }
10667
+ this.clear();
10668
+ // if we're not using directDraw then we can just trust the last buffer content
10669
+ if(!this._directDraw) {
10670
+ this._drawCover(null, this._bufferTextureOutput);
10671
+ } else {
10672
+ console.log("No stored/useable gl render info, result may be incorrect if content was changed since render");
10673
+ this.draw(gl);
10607
10674
}
10608
- } else { // >>> is an unsigned shift which is what we want as 0x80000000 and up are negative values
10609
- r = ((color & 0xFF000000) >>> 24)/255;
10610
- g = ((color & 0x00FF0000) >>> 16)/255;
10611
- b = ((color & 0x0000FF00) >>> 8)/255;
10612
- a = (color & 0x000000FF)/255;
10613
10675
}
10614
10676
10615
- this._clearColor.r = r || 0;
10616
- this._clearColor.g = g || 0;
10617
- this._clearColor.b = b || 0;
10618
- this._clearColor.a = a || 0;
10677
+ // create the dataurl
10678
+ dataURL = this.canvas.toDataURL(mimeType||"image/png");
10679
+
10680
+ // reset the picture in the canvas
10681
+ if(!this._preserveBuffer || backgroundColor !== undefined) {
10682
+ if(backgroundColor !== undefined) {
10683
+ this._clearColor = clearBackup;
10684
+ }
10685
+ this.clear();
10686
+ if(!this._directDraw) {
10687
+ this._drawCover(null, this._bufferTextureOutput);
10688
+ } else {
10689
+ this.draw(gl);
10690
+ }
10691
+ }
10692
+
10693
+ return dataURL;
10619
10694
};
10620
10695
10621
10696
// Docced in subclass
@@ -11415,7 +11490,8 @@ this.createjs = this.createjs||{};
11415
11490
continue;
11416
11491
}
11417
11492
11418
- if (item.compositeOperation !== null) {
11493
+ var containerRenderMode = this._renderMode;
11494
+ if (item.compositeOperation) {
11419
11495
this._updateRenderMode(item.compositeOperation);
11420
11496
}
11421
11497
@@ -11560,6 +11636,10 @@ this.createjs = this.createjs||{};
11560
11636
if (this._immediateRender) {
11561
11637
this._immediateBatchRender();
11562
11638
}
11639
+
11640
+ if (this._renderMode !== containerRenderMode) {
11641
+ this._updateRenderMode(containerRenderMode);
11642
+ }
11563
11643
}
11564
11644
11565
11645
if (this._renderMode !== previousRenderMode) {
@@ -15557,8 +15637,8 @@ this.createjs = this.createjs||{};
15557
15637
p.getBounds = function() {
15558
15638
var scale = this.scale;
15559
15639
return this._boundRect.setValues(
15560
- this._filterOffX/scale , this._filterOffY/scale ,
15561
- this.width/scale, this.height/scale
15640
+ this.x , this.y ,
15641
+ this.width/scale, this.height/scale
15562
15642
);
15563
15643
};
15564
15644
@@ -17541,6 +17621,6 @@ this.createjs = this.createjs || {};
17541
17621
* @type String
17542
17622
* @static
17543
17623
**/
17544
- s.buildDate = /*=date*/"Wed, 23 May 2018 21:52 :20 GMT"; // injected by build process
17624
+ s.buildDate = /*=date*/"Thu, 14 Jun 2018 21:18 :20 GMT"; // injected by build process
17545
17625
17546
17626
})();
0 commit comments