[canvaskit] Remove isNode and saveAsPicture

This should fix https://github.com/flutter/flutter/issues/80221

Change-Id: I25e0ad58bcaad95b43cc94476af0e241e17ac244
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/397289
Reviewed-by: Kevin Lubick <kjlubick@google.com>
This commit is contained in:
Kevin Lubick 2021-04-16 14:30:18 -04:00
parent a0f7654fbe
commit 6e927095e1
6 changed files with 7 additions and 50 deletions

View File

@ -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

View File

@ -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() {};

View File

@ -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

View File

@ -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);
}
});

View File

@ -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();
});

View File

@ -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;
});
}
}