skia2/modules/canvaskit/tests/core.spec.js
Kevin Lubick cc13fd3d6c [CanvasKit] Add basic support for SkPicture
Can dump SkPicture to an skp, but only for debugging purposes
(no deserialization).

Bug: skia:
Change-Id: I37f3c4dcfdd70b665748773ee6b5135329c6240a
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/206262
Reviewed-by: Florin Malita <fmalita@chromium.org>
2019-04-05 17:14:55 +00:00

51 lines
1.7 KiB
JavaScript

describe('Core canvas behavior', function() {
let container = document.createElement('div');
document.body.appendChild(container);
const CANVAS_WIDTH = 600;
const CANVAS_HEIGHT = 600;
beforeEach(function() {
container.innerHTML = `
<canvas width=600 height=600 id=test></canvas>
<canvas width=600 height=600 id=report></canvas>`;
});
afterEach(function() {
container.innerHTML = '';
});
it('can draw an SkPicture', function(done) {
LoadCanvasKit.then(catchException(done, () => {
// This is taken from example.html
const surface = CanvasKit.MakeCanvasSurface('test');
expect(surface).toBeTruthy('Could not make surface')
if (!surface) {
done();
return;
}
const spr = new CanvasKit.SkPictureRecorder();
const rcanvas = spr.beginRecording(
CanvasKit.LTRBRect(0, 0, surface.width(), surface.height()));
const paint = new CanvasKit.SkPaint();
paint.setStrokeWidth(2.0);
paint.setAntiAlias(true);
paint.setColor(CanvasKit.Color(0, 0, 0, 1.0));
paint.setStyle(CanvasKit.PaintStyle.Stroke);
rcanvas.drawRoundRect(CanvasKit.LTRBRect(5, 35, 45, 80), 15, 10, paint);
const font = new CanvasKit.SkFont(null, 20);
rcanvas.drawText('this picture has a round rect', 5, 100, paint, font);
const pic = spr.finishRecordingAsPicture();
spr.delete();
const canvas = surface.getCanvas();
canvas.drawPicture(pic);
reportSurface(surface, 'picture_test', done);
}));
});
});