[canvaskit] POC working on Node.js
Basically no hoops to jump through - the same binary
that works in the browser works in Node.
Tested locally with Node 8.9.3.
This aligns the GPU and CPU APIs (that is, makeSurface)
and breaks out the GPU/CPU js interface parts into
their own files. We only need one of them and we know
which at compile time.
Bug: skia:
Change-Id: I6d141387403a792d2374cf904872c6dbc999abfb
Reviewed-on: https://skia-review.googlesource.com/c/162746
Commit-Queue: Kevin Lubick <kjlubick@google.com>
Reviewed-by: Mike Reed <reed@google.com>
Reviewed-by: Joe Gregorio <jcgregorio@google.com>
diff --git a/experimental/canvaskit/interface.js b/experimental/canvaskit/interface.js
index 938ef3e..885d7e2 100644
--- a/experimental/canvaskit/interface.js
+++ b/experimental/canvaskit/interface.js
@@ -107,53 +107,11 @@
return this;
};
- if (CanvasKit.gpu) {
- CanvasKit.getWebGLSurface = function(htmlID) {
- var canvas = document.getElementById(htmlID);
- if (!canvas) {
- throw 'Canvas with id ' + htmlID + ' was not found';
- }
- // Maybe better to use clientWidth/height. See:
- // https://webglfundamentals.org/webgl/lessons/webgl-anti-patterns.html
- return this._getWebGLSurface(htmlID, canvas.width, canvas.height);
- };
-
- CanvasKit.SkSurface.prototype.flush = function() {
- this._flush();
- }
- } else {
- CanvasKit.getRasterN32PremulSurface = function(htmlID) {
- var canvas = document.getElementById(htmlID);
- if (!canvas) {
- throw 'Canvas with id ' + htmlID + ' was not found';
- }
- // Maybe better to use clientWidth/height. See:
- // https://webglfundamentals.org/webgl/lessons/webgl-anti-patterns.html
- var surface = this._getRasterN32PremulSurface(canvas.width, canvas.height);
- if (surface) {
- surface.canvas = canvas;
- surface._width = canvas.width;
- surface._height = canvas.height;
- surface._pixelLen = surface._width * surface._height * 4; // it's 8888
- // Allocate the buffer of pixels to be used to draw back and forth.
- surface._pixelPtr = CanvasKit._malloc(surface._pixelLen);
- }
- return surface;
- };
-
- CanvasKit.SkSurface.prototype.flush = function() {
- this._flush();
- var success = this._readPixels(this._width, this._height, this._pixelPtr);
- if (!success) {
- console.err('could not read pixels');
- return;
- }
-
- var pixels = new Uint8ClampedArray(CanvasKit.buffer, this._pixelPtr, this._pixelLen);
- var imageData = new ImageData(pixels, this._width, this._height);
-
- this.canvas.getContext('2d').putImageData(imageData, 0, 0);
- };
+ // Run through the JS files that are added at compile time.
+ if (CanvasKit._extraInitializations) {
+ CanvasKit._extraInitializations.forEach(function(init) {
+ init();
+ });
}
} // end CanvasKit.onRuntimeInitialized, that is, anything changing prototypes or dynamic.