Skip to content

Commit

Permalink
Fix runtime type errors when running with canvaskit (flutter#16312)
Browse files Browse the repository at this point in the history
* fix runtime type errors when running with canvaskit
  • Loading branch information
vsmenon committed Feb 4, 2020
1 parent 16cd6f0 commit 8c6cc65
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
8 changes: 6 additions & 2 deletions lib/web_ui/lib/src/engine/compositor/fonts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class SkiaFontCollection {
final String asset = fontAsset['asset'];
_loadingFontBuffers.add(html.window
.fetch(assetManager.getAssetUrl(asset))
.then((dynamic fetchResult) => fetchResult.arrayBuffer()));
.then(_getArrayBuffer));
}
}

Expand All @@ -69,9 +69,13 @@ class SkiaFontCollection {
// Download Roboto and add it to the font buffers.
_loadingFontBuffers.add(html.window
.fetch(_robotoUrl)
.then((dynamic fetchResult) => fetchResult.arrayBuffer()));
.then(_getArrayBuffer));
}
}

Future<ByteBuffer> _getArrayBuffer(dynamic fetchResult) {
return fetchResult.arrayBuffer().then<ByteBuffer>((x) => x as ByteBuffer);
}

js.JsObject skFontMgr;
}
10 changes: 5 additions & 5 deletions lib/web_ui/lib/src/engine/compositor/surface.dart
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,10 @@ class Surface {
..position = 'absolute'
..width = '${logicalSize.width.ceil()}px'
..height = '${logicalSize.height.ceil()}px';
final js.JsObject glContext = canvasKit
final int glContext = canvasKit
.callMethod('GetWebGLContext', <html.CanvasElement>[htmlCanvas]);
final js.JsObject grContext =
canvasKit.callMethod('MakeGrContext', <js.JsObject>[glContext]);
canvasKit.callMethod('MakeGrContext', [glContext]);
final js.JsObject skSurface =
canvasKit.callMethod('MakeOnScreenGLSurface', <dynamic>[
grContext,
Expand All @@ -135,7 +135,7 @@ class Surface {
return false;
}

canvasKit.callMethod('setCurrentContext', <js.JsObject>[_surface.context]);
canvasKit.callMethod('setCurrentContext', [_surface.context]);
_surface.getCanvas().flush();
return true;
}
Expand All @@ -144,7 +144,7 @@ class Surface {
/// A Dart wrapper around Skia's SkSurface.
class SkSurface {
final js.JsObject _surface;
final js.JsObject _glContext;
final int _glContext;

SkSurface(this._surface, this._glContext);

Expand All @@ -153,7 +153,7 @@ class SkSurface {
return SkCanvas(skCanvas);
}

js.JsObject get context => _glContext;
int get context => _glContext;

int width() => _surface.callMethod('width');
int height() => _surface.callMethod('height');
Expand Down

0 comments on commit 8c6cc65

Please sign in to comment.