1// Copyright 2013 The Flutter Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5part of engine; 6 7/// EXPERIMENTAL: Enable the Skia-based rendering backend. 8const bool experimentalUseSkia = false; 9 10/// The URL to use when downloading the CanvasKit script and associated wasm. 11const String canvasKitBaseUrl = 'https://unpkg.com/canvaskit-wasm@0.6.0/bin/'; 12 13/// Initialize the Skia backend. 14/// 15/// This calls `CanvasKitInit` and assigns the global [canvasKit] object. 16Future<void> initializeSkia() { 17 final Completer<void> canvasKitCompleter = Completer<void>(); 18 StreamSubscription<html.Event> loadSubscription; 19 loadSubscription = domRenderer.canvasKitScript.onLoad.listen((_) { 20 loadSubscription.cancel(); 21 final js.JsObject canvasKitInitArgs = js.JsObject.jsify(<dynamic, dynamic>{ 22 'locateFile': js.allowInterop((String file) => canvasKitBaseUrl + file) 23 }); 24 final js.JsObject canvasKitInit = 25 js.JsObject(js.context['CanvasKitInit'], <dynamic>[canvasKitInitArgs]); 26 final js.JsObject canvasKitInitPromise = canvasKitInit.callMethod('ready'); 27 canvasKitInitPromise.callMethod('then', <dynamic>[ 28 js.allowInterop((js.JsObject ck) { 29 canvasKit = ck; 30 canvasKitCompleter.complete(); 31 }) 32 ]); 33 }); 34 return canvasKitCompleter.future; 35} 36 37/// The entrypoint into all CanvasKit functions and classes. 38/// 39/// This is created by [initializeSkia]. 40js.JsObject canvasKit; 41