Add CanvasKit platform support for Skia.setResourceCacheMaxBytes. (flutter/engine#19254)

* Add CanvasKit platform support for Skia.setResourceCacheMaxBytes.
This commit is contained in:
Luigi Rosso
2020-07-09 10:12:24 -07:00
committed by GitHub
parent 3f2befee63
commit 4185636e42
3 changed files with 39 additions and 4 deletions

View File

@@ -13,6 +13,9 @@ class Rasterizer {
Rasterizer(this.surface);
void setSkiaResourceCacheMaxBytes(int bytes) =>
surface.setSkiaResourceCacheMaxBytes(bytes);
/// Creates a new frame from this rasterizer's surface, draws the given
/// [LayerTree] into it, and then submits the frame.
void draw(LayerTree layerTree) {

View File

@@ -38,6 +38,21 @@ class Surface {
CkSurface? _surface;
html.Element? htmlElement;
js.JsObject? _grContext;
int? _skiaCacheBytes;
/// Specify the GPU resource cache limits.
void setSkiaResourceCacheMaxBytes(int bytes) {
_skiaCacheBytes = bytes;
_syncCacheBytes();
}
void _syncCacheBytes() {
if(_skiaCacheBytes != null) {
_grContext?.callMethod('setResourceCacheLimitBytes', <dynamic>[
_skiaCacheBytes]);
}
}
bool _addedToScene = false;
@@ -110,16 +125,20 @@ class Surface {
// anti-aliased by setting their `Paint` object's `antialias` property.
js.JsObject.jsify({'antialias': 0}),
]);
final js.JsObject? grContext =
_grContext =
canvasKit.callMethod('MakeGrContext', <dynamic>[glContext]);
if (grContext == null) {
if (_grContext == null) {
throw CanvasKitError('Could not create a graphics context.');
}
// Set the cache byte limit for this grContext, if not specified it will use
// CanvasKit's default.
_syncCacheBytes();
final js.JsObject? skSurface =
canvasKit.callMethod('MakeOnScreenGLSurface', <dynamic>[
grContext,
_grContext,
size.width,
size.height,
canvasKit['SkColorSpace']['SRGB'],
@@ -130,7 +149,7 @@ class Surface {
}
htmlElement = htmlCanvas;
return CkSurface(skSurface, grContext, glContext);
return CkSurface(skSurface, _grContext!, glContext);
}
bool _presentSurface() {

View File

@@ -494,6 +494,19 @@ class EngineWindow extends ui.Window {
}
switch (name) {
/// This should be in sync with shell/common/shell.cc
case 'flutter/skia':
const MethodCodec codec = JSONMethodCodec();
final MethodCall decoded = codec.decodeMethodCall(data);
switch (decoded.method) {
case 'Skia.setResourceCacheMaxBytes':
if (decoded.arguments is int) {
rasterizer?.setSkiaResourceCacheMaxBytes(decoded.arguments);
}
break;
}
return;
case 'flutter/assets':
assert(ui.webOnlyAssetManager != null); // ignore: unnecessary_null_comparison
final String url = utf8.decode(data!.buffer.asUint8List());