[canvaskit] Remove Cobalt-specific code (flutter/engine#37047)

This commit is contained in:
Harry Terkelsen 2022-10-27 12:12:58 -07:00 committed by GitHub
parent b34da51ee8
commit 82f27bc9e2
4 changed files with 0 additions and 116 deletions

View File

@ -25,14 +25,6 @@ import '../profiler.dart';
/// Entrypoint into the CanvasKit API.
late CanvasKit canvasKit;
/// Whether to use a CanvasKit implementation provided by a JavaScript
/// `window.h5vcc.canvasKit` object.
///
/// Cobalt may use this object to expose a native implementation of the
/// CanvasKit bindings. If this exists, use it instead of using the normal
/// downloaded CanvasKit library.
final bool useH5vccCanvasKit = h5vcc != null;
/// Sets the [CanvasKit] object on `window` so we can use `@JS()` to bind to
/// static APIs.
///
@ -47,21 +39,6 @@ external set windowFlutterCanvasKit(CanvasKit? value);
@JS('window.flutterCanvasKit')
external CanvasKit? get windowFlutterCanvasKit;
@JS('window.h5vcc')
external H5vcc? get h5vcc;
@JS('window.h5vcc')
external set debugH5vccSetter(H5vcc? value);
@JS()
@anonymous
@staticInterop
abstract class H5vcc {}
extension H5vccExtension on H5vcc {
external CanvasKit? get canvasKit;
}
@JS()
@anonymous
@staticInterop
@ -159,15 +136,6 @@ extension CanvasKitExtension on CanvasKit {
Object src,
SkPartialImageInfo info,
);
/// Gets a Skia surface from Cobalt's h5vcc object.
///
/// This is only applicable when running on Cobalt and when using Cobalt's
/// h5vcc CanvasKit bindings.
///
/// On Cobalt, this is the only way to get a Skia surface. Other CanvasKit
/// Make...Surface methods are not supported.
external SkSurface getH5vccSkSurface();
}
@JS('window.CanvasKitInit')

View File

@ -25,7 +25,6 @@ import 'picture_recorder.dart';
import 'rasterizer.dart';
import 'shader.dart';
import 'text.dart';
import 'util.dart';
import 'vertices.dart';
class CanvasKitRenderer implements Renderer {
@ -52,12 +51,6 @@ class CanvasKitRenderer implements Renderer {
Future<void> initialize() async {
if (windowFlutterCanvasKit != null) {
canvasKit = windowFlutterCanvasKit!;
} else if (useH5vccCanvasKit) {
if (h5vcc?.canvasKit == null) {
throw CanvasKitError('H5vcc CanvasKit implementation not found.');
}
canvasKit = h5vcc!.canvasKit!;
windowFlutterCanvasKit = canvasKit;
} else {
canvasKit = await downloadCanvasKit();
windowFlutterCanvasKit = canvasKit;

View File

@ -142,11 +142,6 @@ class Surface {
/// Creates a <canvas> and SkSurface for the given [size].
CkSurface createOrUpdateSurface(ui.Size size) {
if (useH5vccCanvasKit) {
_surface ??= CkSurface(canvasKit.getH5vccSkSurface(), null);
return _surface!;
}
if (size.isEmpty) {
throw CanvasKitError('Cannot create surfaces of empty size.');
}

View File

@ -1,72 +0,0 @@
// 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.
import 'package:js/js.dart';
import 'package:js/js_util.dart' as js_util;
import 'package:test/bootstrap/browser.dart';
import 'package:test/test.dart';
import 'package:ui/src/engine.dart';
import 'package:ui/ui.dart' as ui;
import 'common.dart';
void main() {
internalBootstrapBrowserTest(() => testMain);
}
void testMain() {
group('H5vcc patched CanvasKit', () {
int getH5vccSkSurfaceCalledCount = 0;
setUpAll(() async {
// Set `window.h5vcc` to PatchedH5vcc which uses a downloaded CanvasKit.
final CanvasKit downloadedCanvasKit = await downloadCanvasKit();
debugH5vccSetter = PatchedH5vcc(canvasKit: downloadedCanvasKit);
// Monkey-patch the getH5vccSkSurface function of
// `window.h5vcc.canvasKit`.
js_util.setProperty(h5vcc!.canvasKit!, 'getH5vccSkSurface', allowInterop(() {
getH5vccSkSurfaceCalledCount++;
// Returns a fake [SkSurface] object with a minimal implementation.
return js_util.jsify(<String, dynamic>{
'dispose': allowInterop(() {})
});
}));
});
setUpCanvasKitTest();
setUp(() {
getH5vccSkSurfaceCalledCount = 0;
});
test('sets useH5vccCanvasKit', () {
expect(useH5vccCanvasKit, true);
});
test('API includes patched getH5vccSkSurface', () {
expect(canvasKit.getH5vccSkSurface, isNotNull);
});
test('Surface acquireFrame uses getH5vccSkSurface', () {
final Surface surface = SurfaceFactory.instance.getSurface()!;
surface.acquireFrame(ui.Size.zero);
expect(getH5vccSkSurfaceCalledCount, 1);
// No <canvas> element should be created.
expect(
flutterViewEmbedder.glassPaneElement!.querySelectorAll('canvas'),
isEmpty,
);
});
}, testOn: 'chrome');
}
@JS()
@anonymous
@staticInterop
class PatchedH5vcc implements H5vcc {
external factory PatchedH5vcc({CanvasKit canvasKit});
}