This repository was archived by the owner on Feb 25, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +100
-3
lines changed Expand file tree Collapse file tree 3 files changed +100
-3
lines changed Original file line number Diff line number Diff line change @@ -333,10 +333,20 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher {
333333 final MethodCall decoded = codec.decodeMethodCall (data);
334334 switch (decoded.method) {
335335 case 'Skia.setResourceCacheMaxBytes' :
336- if (decoded.arguments is int ) {
337- rasterizer? .setSkiaResourceCacheMaxBytes (decoded.arguments);
336+ if (useCanvasKit) {
337+ // If we're in CanvasKit mode, we must also have a rasterizer.
338+ assert (rasterizer != null );
339+ assert (
340+ decoded.arguments is int ,
341+ 'Argument to Skia.setResourceCacheMaxBytes must be an int, but was ${decoded .arguments .runtimeType }' ,
342+ );
343+ final int cacheSizeInBytes = decoded.arguments as int ;
344+ rasterizer! .setSkiaResourceCacheMaxBytes (cacheSizeInBytes);
338345 }
339- _replyToPlatformMessage (callback, codec.encodeSuccessEnvelope (true ));
346+
347+ // Also respond in HTML mode. Otherwise, apps would have to detect
348+ // CanvasKit vs HTML before invoking this method.
349+ _replyToPlatformMessage (callback, codec.encodeSuccessEnvelope ([true ]));
340350 break ;
341351 }
342352 return ;
Original file line number Diff line number Diff line change 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+
5+ // @dart = 2.12
6+ import 'dart:async' ;
7+ import 'dart:typed_data' ;
8+
9+ import 'package:ui/src/engine.dart' ;
10+ import 'package:ui/ui.dart' as ui;
11+
12+ import 'package:test/bootstrap/browser.dart' ;
13+ import 'package:test/test.dart' ;
14+
15+ import 'common.dart' ;
16+
17+ void main () {
18+ internalBootstrapBrowserTest (() => testMain);
19+ }
20+
21+ void testMain () {
22+ group ('PlatformDispatcher' , () {
23+ setUpCanvasKitTest ();
24+
25+ test ('responds to flutter/skia Skia.setResourceCacheMaxBytes' , () async {
26+ const MethodCodec codec = JSONMethodCodec ();
27+ final Completer <ByteData ?> completer = Completer <ByteData ?>();
28+ ui.PlatformDispatcher .instance.sendPlatformMessage (
29+ 'flutter/skia' ,
30+ codec.encodeMethodCall (MethodCall (
31+ 'Skia.setResourceCacheMaxBytes' ,
32+ 512 * 1000 * 1000 ,
33+ )),
34+ completer.complete,
35+ );
36+
37+ final ByteData ? response = await completer.future;
38+ expect (response, isNotNull);
39+ expect (
40+ codec.decodeEnvelope (response! ),
41+ [true ],
42+ );
43+ });
44+ // TODO: https://github.com/flutter/flutter/issues/60040
45+ }, skip: isIosSafari);
46+ }
Original file line number Diff line number Diff line change 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+
5+ // @dart = 2.12
6+ import 'dart:async' ;
7+ import 'dart:typed_data' ;
8+
9+ import 'package:ui/src/engine.dart' ;
10+ import 'package:ui/ui.dart' as ui;
11+
12+ import 'package:test/bootstrap/browser.dart' ;
13+ import 'package:test/test.dart' ;
14+
15+ void main () {
16+ internalBootstrapBrowserTest (() => testMain);
17+ }
18+
19+ void testMain () {
20+ group ('PlatformDispatcher' , () {
21+ test ('responds to flutter/skia Skia.setResourceCacheMaxBytes' , () async {
22+ const MethodCodec codec = JSONMethodCodec ();
23+ final Completer <ByteData ?> completer = Completer <ByteData ?>();
24+ ui.PlatformDispatcher .instance.sendPlatformMessage (
25+ 'flutter/skia' ,
26+ codec.encodeMethodCall (MethodCall (
27+ 'Skia.setResourceCacheMaxBytes' ,
28+ 512 * 1000 * 1000 ,
29+ )),
30+ completer.complete,
31+ );
32+
33+ final ByteData ? response = await completer.future;
34+ expect (response, isNotNull);
35+ expect (
36+ codec.decodeEnvelope (response! ),
37+ [true ],
38+ );
39+ });
40+ });
41+ }
You can’t perform that action at this time.
0 commit comments