diff --git a/modules/canvaskit/CHANGELOG.md b/modules/canvaskit/CHANGELOG.md index da199ea5d3..dd446cc420 100644 --- a/modules/canvaskit/CHANGELOG.md +++ b/modules/canvaskit/CHANGELOG.md @@ -14,6 +14,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 to `RuntimeEffect.makeShader` as floats (like all other uniforms), and will be converted to integers internally, to match the expectations of the shader. +### Removed + - `Picture.saveAsFile()`, in favor of `Picture.serialize()` where clients can control how to + store/encode the bytes. + ## [0.25.1] - 2021-03-30 ### Added diff --git a/modules/canvaskit/externs.js b/modules/canvaskit/externs.js index da7d808005..3d9436edfb 100644 --- a/modules/canvaskit/externs.js +++ b/modules/canvaskit/externs.js @@ -1018,8 +1018,6 @@ var CanvasKit = { CanvasKit.Paragraph.prototype.getRectsForRange = function() {}; CanvasKit.Paragraph.prototype.getRectsForPlaceholders = function() {}; -CanvasKit.Picture.prototype.saveAsFile = function() {}; - CanvasKit.Surface.prototype.dispose = function() {}; CanvasKit.Surface.prototype.flush = function() {}; CanvasKit.Surface.prototype.requestAnimationFrame = function() {}; diff --git a/modules/canvaskit/htmlcanvas/util.js b/modules/canvaskit/htmlcanvas/util.js index 4ea121d4e7..42cbce1e34 100644 --- a/modules/canvaskit/htmlcanvas/util.js +++ b/modules/canvaskit/htmlcanvas/util.js @@ -12,7 +12,7 @@ function allAreFinite(args) { } function toBase64String(bytes) { - if (isNode) { + if (typeof Buffer !== 'undefined') { // Are we on node? return Buffer.from(bytes).toString('base64'); } else { // From https://stackoverflow.com/a/25644409 diff --git a/modules/canvaskit/skp.js b/modules/canvaskit/skp.js index bddccdb983..9248d76364 100644 --- a/modules/canvaskit/skp.js +++ b/modules/canvaskit/skp.js @@ -14,16 +14,4 @@ CanvasKit._extraInitializations.push(function() { } return pic; }; - - // The serialized format of an Picture (informally called an "skp"), is not something - // that clients should ever rely on. The format may change at anytime and no promises - // are made for backwards or forward compatibility. - CanvasKit.Picture.prototype.saveAsFile = function(skpName) { - var bytes = this.serialize(); - if (!bytes) { - Debug('Could not serialize to skpicture.'); - return; - } - saveBytesToFile(bytes, skpName); - } }); diff --git a/modules/canvaskit/tests/core.spec.js b/modules/canvaskit/tests/core.spec.js index b2b0baf27e..45eb6c1bad 100644 --- a/modules/canvaskit/tests/core.spec.js +++ b/modules/canvaskit/tests/core.spec.js @@ -34,10 +34,8 @@ describe('Core canvas behavior', () => { canvas.drawPicture(pic); - // test that file saving functionality throws no errors - // Unfortunately jasmine spy objects can't fake their type so we can't verify it downloads - // a nonzero sized file. - pic.saveAsFile('foo.skp'); + const bytes = pic.serialize(); + expect(bytes).toBeTruthy(); pic.delete(); }); diff --git a/modules/canvaskit/util.js b/modules/canvaskit/util.js index be8e4a20ba..69c3a60e9b 100644 --- a/modules/canvaskit/util.js +++ b/modules/canvaskit/util.js @@ -13,37 +13,6 @@ function degreesToRadians(deg) { return (deg / 180) * Math.PI; } -// See https://stackoverflow.com/a/31090240 -// This contraption keeps closure from minifying away the check -// if btoa is defined *and* prevents runtime 'btoa' or 'window' is not defined. -// Defined outside any scopes to make it available in all files. -var isNode = !(new Function('try {return this===window;}catch(e){ return false;}')()); - function almostEqual(floata, floatb) { return Math.abs(floata - floatb) < 0.00001; } - -function saveBytesToFile(bytes, fileName) { - if (!isNode) { - // https://stackoverflow.com/a/32094834 - var blob = new Blob([bytes], {type: 'application/octet-stream'}); - url = window.URL.createObjectURL(blob); - var a = document.createElement('a'); - document.body.appendChild(a); - a.href = url; - a.download = fileName; - a.click(); - // clean up after because FF might not download it synchronously - setTimeout(function() { - URL.revokeObjectURL(url); - a.remove(); - }, 50); - } else { - var fs = require('fs'); - // https://stackoverflow.com/a/42006750 - // https://stackoverflow.com/a/47018122 - fs.writeFile(fileName, new Buffer(bytes), function(err) { - if (err) throw err; - }); - } -} \ No newline at end of file