Skip to content

Commit

Permalink
[skottieWASM] make sure we are using CPU or GPU correctly
Browse files Browse the repository at this point in the history
Change-Id: Ib9013fa9bedbbbf8a7787ef2a75d707dd6360cf8
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/257635
Reviewed-by: Brian Osman <[email protected]>
Reviewed-by: Ravi Mistry <[email protected]>
  • Loading branch information
kjlubick committed Dec 3, 2019
1 parent a4f1391 commit 6bbeaa7
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 13 deletions.
33 changes: 22 additions & 11 deletions tools/skottie-wasm-perf/skottie-wasm-perf.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,33 @@

const animation = CK.MakeManagedAnimation(json, null);
if (!animation) {
console.error('Could not process JSON');
window._error = 'Could not process JSON';
return
}

const surface = CK.MakeCanvasSurface("anim");
if (!surface) {
console.error('Could not make surface');
return;
let surface = null;
if (window.location.hash.indexOf('gpu') !== -1) {
surface = CK.MakeWebGLCanvasSurface('anim');
if (!surface) {
window._error = 'Could not make GPU surface';
return;
}
let c = document.getElementById('anim');
// If CanvasKit was unable to instantiate a WebGL context, it will fallback
// to CPU and add a ck-replaced class to the canvas element.
if (c.classList.contains('ck-replaced')) {
window._error = 'fell back to CPU';
return;
}
} else {
surface = CK.MakeSWCanvasSurface('anim');
if (!surface) {
window._error = 'Could not make CPU surface';
return;
}
}
const canvas = surface.getCanvas();

let c = document.getElementById('anim');
// If CanvasKit was unable to instantiate a WebGL context, it will fallback
// to CPU and add a ck-replaced class to the canvas element.
window._gpu = CK.gpu && !c.classList.contains('ck-replaced');

const t_rate = 1.0 / (maxFrames-1);
let seek = 0;
let frame = 0;
Expand Down Expand Up @@ -93,7 +104,7 @@
});
surface.flush();
}
console.log("Used seek: " + seek);
console.log(`Used seek: ${seek}`);
seek += t_rate;
frame++;
window.requestAnimationFrame(drawFrame);
Expand Down
14 changes: 12 additions & 2 deletions tools/skottie-wasm-perf/skottie-wasm-perf.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,11 @@ async function wait(ms) {
return ms;
}

const targetURL = "http://localhost:" + options.port + "/";
let hash = "#cpu";
if (options.use_gpu) {
hash = "#gpu";
}
const targetURL = `http://localhost:${options.port}/${hash}`;
const viewPort = {width: 1000, height: 1000};

// Drive chrome to load the web page from the server we have running.
Expand Down Expand Up @@ -158,10 +162,16 @@ async function driveBrowser() {
});

console.log('Waiting 60s for run to be done');
await page.waitForFunction('window._skottieDone === true', {
await page.waitForFunction(`(window._skottieDone === true) || window._error`, {
timeout: 60000,
});

const err = await page.evaluate('window._error');
if (err) {
console.log(`ERROR: ${err}`)
process.exit(1);
}

// Stop Trace.
await page.tracing.stop();
} catch(e) {
Expand Down

0 comments on commit 6bbeaa7

Please sign in to comment.