Add Correctness tests for CanvasKit
Also make a CPU only and GPU only build (although
the latter still has a lot of CPU logic).
Bug: skia:
Change-Id: I857c2300021c2adb5344865c28e4ad3e8d332954
Reviewed-on: https://skia-review.googlesource.com/c/162022
Reviewed-by: Kevin Lubick <kjlubick@google.com>
diff --git a/experimental/canvaskit/interface.js b/experimental/canvaskit/interface.js
index 98be5ef..938ef3e 100644
--- a/experimental/canvaskit/interface.js
+++ b/experimental/canvaskit/interface.js
@@ -107,49 +107,55 @@
return this;
};
- CanvasKit.SkSurface.prototype.flush = function() {
- var success = this._readPixels(this._width, this._height, this._pixelPtr);
- if (!success) {
- console.err('could not read pixels');
- return;
+ 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;
+ };
- var pixels = new Uint8ClampedArray(CanvasKit.buffer, this._pixelPtr, this._pixelLen);
- var imageData = new ImageData(pixels, this._width, this._height);
+ 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;
+ }
- this.canvas.getContext('2d').putImageData(imageData, 0, 0);
+ var pixels = new Uint8ClampedArray(CanvasKit.buffer, this._pixelPtr, this._pixelLen);
+ var imageData = new ImageData(pixels, this._width, this._height);
- };
- }
-
- CanvasKit.getWebGLSurface = function(htmlID) {
- var canvas = document.getElementById(htmlID);
- if (!canvas) {
- throw 'Canvas with id ' + htmlID + ' was not found';
+ this.canvas.getContext('2d').putImageData(imageData, 0, 0);
+ };
}
- // 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.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;
- }
+ } // end CanvasKit.onRuntimeInitialized, that is, anything changing prototypes or dynamic.
// Likely only used for tests.
CanvasKit.LTRBRect = function(l, t, r, b) {