683bbe01ff
In this CL: - Modify modules/canvaskit/gpu.js to support the use of OffscreenCanvas. - Add a CanvasKit demos.skia.org demo for CanvasKit in a Web Worker. Change-Id: I8c26bd94f2aa5b3c09cf149b056b910b0e4cd602 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/304320 Reviewed-by: Elliot Evans <elliotevans@google.com> Reviewed-by: Kevin Lubick <kjlubick@google.com> Reviewed-by: Nathaniel Nifong <nifong@google.com> Commit-Queue: Elliot Evans <elliotevans@google.com>
28 lines
849 B
JavaScript
28 lines
849 B
JavaScript
importScripts('https://particles.skia.org/static/canvaskit.js');
|
|
importScripts('shared.js');
|
|
|
|
const transferCanvasToOffscreenPromise =
|
|
new Promise((resolve) => addEventListener('message', resolve));
|
|
const canvasKitInitPromise =
|
|
CanvasKitInit({locateFile: (file) => 'https://particles.skia.org/static/'+file});
|
|
const skottieJsonPromise =
|
|
fetch('https://storage.googleapis.com/skia-cdn/misc/lego_loader.json')
|
|
.then((response) => response.text());
|
|
|
|
Promise.all([
|
|
transferCanvasToOffscreenPromise,
|
|
canvasKitInitPromise,
|
|
skottieJsonPromise
|
|
]).then(([
|
|
{ data: { offscreenCanvas } },
|
|
CanvasKit,
|
|
jsonStr
|
|
]) => {
|
|
const surface = CanvasKit.MakeWebGLCanvasSurface(offscreenCanvas, null);
|
|
if (!surface) {
|
|
throw 'Could not make canvas surface';
|
|
}
|
|
|
|
SkottieExample(CanvasKit, surface, jsonStr);
|
|
});
|