Respond to Skia platform messages (flutter/engine#24880)
This commit is contained in:
@@ -333,9 +333,20 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher {
|
||||
final MethodCall decoded = codec.decodeMethodCall(data);
|
||||
switch (decoded.method) {
|
||||
case 'Skia.setResourceCacheMaxBytes':
|
||||
if (decoded.arguments is int) {
|
||||
rasterizer?.setSkiaResourceCacheMaxBytes(decoded.arguments);
|
||||
if (useCanvasKit) {
|
||||
// If we're in CanvasKit mode, we must also have a rasterizer.
|
||||
assert(rasterizer != null);
|
||||
assert(
|
||||
decoded.arguments is int,
|
||||
'Argument to Skia.setResourceCacheMaxBytes must be an int, but was ${decoded.arguments.runtimeType}',
|
||||
);
|
||||
final int cacheSizeInBytes = decoded.arguments as int;
|
||||
rasterizer!.setSkiaResourceCacheMaxBytes(cacheSizeInBytes);
|
||||
}
|
||||
|
||||
// Also respond in HTML mode. Otherwise, apps would have to detect
|
||||
// CanvasKit vs HTML before invoking this method.
|
||||
_replyToPlatformMessage(callback, codec.encodeSuccessEnvelope([true]));
|
||||
break;
|
||||
}
|
||||
return;
|
||||
@@ -896,9 +907,9 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher {
|
||||
/// messages and responses have to be exchanged asynchronously. We simulate
|
||||
/// that by adding a zero-length delay to the reply.
|
||||
void _replyToPlatformMessage(
|
||||
ui.PlatformMessageResponseCallback? callback,
|
||||
ByteData? data,
|
||||
) {
|
||||
ui.PlatformMessageResponseCallback? callback,
|
||||
ByteData? data,
|
||||
) {
|
||||
Future<void>.delayed(Duration.zero).then((_) {
|
||||
if (callback != null) {
|
||||
callback(data);
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// @dart = 2.12
|
||||
import 'dart:async';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:ui/src/engine.dart';
|
||||
import 'package:ui/ui.dart' as ui;
|
||||
|
||||
import 'package:test/bootstrap/browser.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'common.dart';
|
||||
|
||||
void main() {
|
||||
internalBootstrapBrowserTest(() => testMain);
|
||||
}
|
||||
|
||||
void testMain() {
|
||||
group('PlatformDispatcher', () {
|
||||
setUpCanvasKitTest();
|
||||
|
||||
test('responds to flutter/skia Skia.setResourceCacheMaxBytes', () async {
|
||||
const MethodCodec codec = JSONMethodCodec();
|
||||
final Completer<ByteData?> completer = Completer<ByteData?>();
|
||||
ui.PlatformDispatcher.instance.sendPlatformMessage(
|
||||
'flutter/skia',
|
||||
codec.encodeMethodCall(MethodCall(
|
||||
'Skia.setResourceCacheMaxBytes',
|
||||
512 * 1000 * 1000,
|
||||
)),
|
||||
completer.complete,
|
||||
);
|
||||
|
||||
final ByteData? response = await completer.future;
|
||||
expect(response, isNotNull);
|
||||
expect(
|
||||
codec.decodeEnvelope(response!),
|
||||
[true],
|
||||
);
|
||||
});
|
||||
// TODO: https://github.com/flutter/flutter/issues/60040
|
||||
}, skip: isIosSafari);
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// @dart = 2.12
|
||||
import 'dart:async';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:ui/src/engine.dart';
|
||||
import 'package:ui/ui.dart' as ui;
|
||||
|
||||
import 'package:test/bootstrap/browser.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
void main() {
|
||||
internalBootstrapBrowserTest(() => testMain);
|
||||
}
|
||||
|
||||
void testMain() {
|
||||
group('PlatformDispatcher', () {
|
||||
test('responds to flutter/skia Skia.setResourceCacheMaxBytes', () async {
|
||||
const MethodCodec codec = JSONMethodCodec();
|
||||
final Completer<ByteData?> completer = Completer<ByteData?>();
|
||||
ui.PlatformDispatcher.instance.sendPlatformMessage(
|
||||
'flutter/skia',
|
||||
codec.encodeMethodCall(MethodCall(
|
||||
'Skia.setResourceCacheMaxBytes',
|
||||
512 * 1000 * 1000,
|
||||
)),
|
||||
completer.complete,
|
||||
);
|
||||
|
||||
final ByteData? response = await completer.future;
|
||||
expect(response, isNotNull);
|
||||
expect(
|
||||
codec.decodeEnvelope(response!),
|
||||
[true],
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user