mirror of
https://github.com/flutter/flutter
synced 2024-08-27 20:10:11 +00:00
[web] Use plain platform views in benchmarks (#126080)
Removing the dependency between web benchmarks and `url_launcher`'s `Link` widget.
This commit is contained in:
parent
ad009fb7ac
commit
28f3037758
1
dev/benchmarks/macrobenchmarks/.gitignore
vendored
1
dev/benchmarks/macrobenchmarks/.gitignore
vendored
|
@ -1,4 +1,3 @@
|
|||
lib/generated_plugin_registrant.dart
|
||||
devtools_memory.json
|
||||
*.sksl.json
|
||||
vmservice.out
|
||||
|
|
|
@ -1,99 +0,0 @@
|
|||
// Copyright 2014 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 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:url_launcher/link.dart';
|
||||
|
||||
|
||||
import 'recorder.dart';
|
||||
|
||||
/// Creates an infinite list of Link widgets and scrolls it.
|
||||
class BenchLinkInfiniteScroll extends WidgetRecorder {
|
||||
BenchLinkInfiniteScroll.forward()
|
||||
: initialOffset = 0.0,
|
||||
finalOffset = 30000.0,
|
||||
super(name: benchmarkName);
|
||||
|
||||
BenchLinkInfiniteScroll.backward()
|
||||
: initialOffset = 30000.0,
|
||||
finalOffset = 0.0,
|
||||
super(name: benchmarkNameBackward);
|
||||
|
||||
static const String benchmarkName = 'bench_link_infinite_scroll';
|
||||
static const String benchmarkNameBackward = 'bench_link_infinite_scroll_backward';
|
||||
|
||||
final double initialOffset;
|
||||
final double finalOffset;
|
||||
|
||||
@override
|
||||
Widget createWidget() => MaterialApp(
|
||||
title: 'Infinite Link Scroll Benchmark',
|
||||
home: _InfiniteScrollLinks(initialOffset, finalOffset),
|
||||
);
|
||||
}
|
||||
|
||||
class _InfiniteScrollLinks extends StatefulWidget {
|
||||
const _InfiniteScrollLinks(this.initialOffset, this.finalOffset);
|
||||
|
||||
final double initialOffset;
|
||||
final double finalOffset;
|
||||
|
||||
@override
|
||||
State<_InfiniteScrollLinks> createState() => _InfiniteScrollLinksState();
|
||||
}
|
||||
|
||||
class _InfiniteScrollLinksState extends State<_InfiniteScrollLinks> {
|
||||
static const Duration stepDuration = Duration(seconds: 20);
|
||||
|
||||
late ScrollController scrollController;
|
||||
late double offset;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
offset = widget.initialOffset;
|
||||
|
||||
scrollController = ScrollController(
|
||||
initialScrollOffset: offset,
|
||||
);
|
||||
|
||||
// Without the timer the animation doesn't begin.
|
||||
Timer.run(() async {
|
||||
await scrollController.animateTo(
|
||||
widget.finalOffset,
|
||||
curve: Curves.linear,
|
||||
duration: stepDuration,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
scrollController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ListView.builder(
|
||||
controller: scrollController,
|
||||
itemExtent: 100.0,
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
return SizedBox(
|
||||
height: 100.0,
|
||||
child: Link(
|
||||
uri: Uri.parse('https://www.google.com'),
|
||||
builder: (BuildContext context, FollowLink? followLink) => ElevatedButton(
|
||||
onPressed: followLink,
|
||||
child: const Text('Google'),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,119 @@
|
|||
// Copyright 2014 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 'dart:async';
|
||||
import 'dart:html' as html;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
// TODO(mdebbar): flutter/flutter#55000 Remove this conditional import once
|
||||
// web-only dart:ui_web APIs are exposed from a dedicated place.
|
||||
import 'platform_views/non_web.dart'
|
||||
if (dart.library.html) 'platform_views/web.dart';
|
||||
import 'recorder.dart';
|
||||
|
||||
const String benchmarkViewType = 'benchmark_element';
|
||||
|
||||
void _registerFactory() {
|
||||
platformViewRegistry.registerViewFactory(benchmarkViewType, (int viewId) {
|
||||
final html.Element htmlElement = html.DivElement();
|
||||
htmlElement.id = '${benchmarkViewType}_$viewId';
|
||||
htmlElement.innerText = 'Google';
|
||||
htmlElement.style
|
||||
..width = '100%'
|
||||
..height = '100%'
|
||||
..color = 'black'
|
||||
..backgroundColor = 'rgba(0, 255, 0, .5)'
|
||||
..textAlign = 'center'
|
||||
..border = '1px solid black';
|
||||
return htmlElement;
|
||||
});
|
||||
}
|
||||
|
||||
/// Creates an infinite list of Link widgets and scrolls it.
|
||||
class BenchPlatformViewInfiniteScroll extends WidgetRecorder {
|
||||
BenchPlatformViewInfiniteScroll.forward()
|
||||
: initialOffset = 0.0,
|
||||
finalOffset = 30000.0,
|
||||
super(name: benchmarkName) {
|
||||
_registerFactory();
|
||||
}
|
||||
|
||||
BenchPlatformViewInfiniteScroll.backward()
|
||||
: initialOffset = 30000.0,
|
||||
finalOffset = 0.0,
|
||||
super(name: benchmarkNameBackward) {
|
||||
_registerFactory();
|
||||
}
|
||||
|
||||
static const String benchmarkName = 'bench_platform_view_infinite_scroll';
|
||||
static const String benchmarkNameBackward =
|
||||
'bench_platform_view_infinite_scroll_backward';
|
||||
|
||||
final double initialOffset;
|
||||
final double finalOffset;
|
||||
|
||||
@override
|
||||
Widget createWidget() => MaterialApp(
|
||||
title: 'Infinite Platform View Scroll Benchmark',
|
||||
home: _InfiniteScrollPlatformViews(initialOffset, finalOffset),
|
||||
);
|
||||
}
|
||||
|
||||
class _InfiniteScrollPlatformViews extends StatefulWidget {
|
||||
const _InfiniteScrollPlatformViews(this.initialOffset, this.finalOffset);
|
||||
|
||||
final double initialOffset;
|
||||
final double finalOffset;
|
||||
|
||||
@override
|
||||
State<_InfiniteScrollPlatformViews> createState() => _InfiniteScrollPlatformViewsState();
|
||||
}
|
||||
|
||||
class _InfiniteScrollPlatformViewsState extends State<_InfiniteScrollPlatformViews> {
|
||||
static const Duration stepDuration = Duration(seconds: 20);
|
||||
|
||||
late ScrollController scrollController;
|
||||
late double offset;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
offset = widget.initialOffset;
|
||||
|
||||
scrollController = ScrollController(
|
||||
initialScrollOffset: offset,
|
||||
);
|
||||
|
||||
// Without the timer the animation doesn't begin.
|
||||
Timer.run(() async {
|
||||
await scrollController.animateTo(
|
||||
widget.finalOffset,
|
||||
curve: Curves.linear,
|
||||
duration: stepDuration,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
scrollController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ListView.builder(
|
||||
controller: scrollController,
|
||||
itemExtent: 100.0,
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
return const SizedBox(
|
||||
height: 100.0,
|
||||
child: HtmlElementView(viewType: benchmarkViewType),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
// Copyright 2014 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.
|
||||
|
||||
// ignore: avoid_classes_with_only_static_members
|
||||
/// Shim for web_ui engine.PlatformViewRegistry
|
||||
/// https://github.com/flutter/engine/blob/master/lib/web_ui/lib/ui.dart#L62
|
||||
// ignore: camel_case_types
|
||||
class platformViewRegistry {
|
||||
/// Shim for registerViewFactory
|
||||
/// https://github.com/flutter/engine/blob/master/lib/web_ui/lib/ui.dart#L72
|
||||
static void registerViewFactory(
|
||||
String viewTypeId, dynamic Function(int viewId) viewFactory,
|
||||
{bool isVisible = true}) {}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
// Copyright 2014 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.
|
||||
|
||||
export 'dart:ui';
|
|
@ -16,7 +16,6 @@ import 'src/web/bench_default_target_platform.dart';
|
|||
import 'src/web/bench_draw_rect.dart';
|
||||
import 'src/web/bench_dynamic_clip_on_static_picture.dart';
|
||||
import 'src/web/bench_image_decoding.dart';
|
||||
import 'src/web/bench_link_infinite_scroll.dart';
|
||||
import 'src/web/bench_material_3.dart';
|
||||
import 'src/web/bench_mouse_region_grid_hover.dart';
|
||||
import 'src/web/bench_mouse_region_grid_scroll.dart';
|
||||
|
@ -24,6 +23,7 @@ import 'src/web/bench_mouse_region_mixed_grid_hover.dart';
|
|||
import 'src/web/bench_pageview_scroll_linethrough.dart';
|
||||
import 'src/web/bench_paths.dart';
|
||||
import 'src/web/bench_picture_recording.dart';
|
||||
import 'src/web/bench_platform_view_infinite_scroll.dart';
|
||||
import 'src/web/bench_simple_lazy_text_scroll.dart';
|
||||
import 'src/web/bench_text_layout.dart';
|
||||
import 'src/web/bench_text_out_of_picture_bounds.dart';
|
||||
|
@ -59,8 +59,8 @@ final Map<String, RecorderFactory> benchmarks = <String, RecorderFactory>{
|
|||
BenchMouseRegionGridHover.benchmarkName: () => BenchMouseRegionGridHover(),
|
||||
BenchMouseRegionMixedGridHover.benchmarkName: () => BenchMouseRegionMixedGridHover(),
|
||||
BenchWrapBoxScroll.benchmarkName: () => BenchWrapBoxScroll(),
|
||||
BenchLinkInfiniteScroll.benchmarkName: () => BenchLinkInfiniteScroll.forward(),
|
||||
BenchLinkInfiniteScroll.benchmarkNameBackward: () => BenchLinkInfiniteScroll.backward(),
|
||||
BenchPlatformViewInfiniteScroll.benchmarkName: () => BenchPlatformViewInfiniteScroll.forward(),
|
||||
BenchPlatformViewInfiniteScroll.benchmarkNameBackward: () => BenchPlatformViewInfiniteScroll.backward(),
|
||||
BenchMaterial3Components.benchmarkName: () => BenchMaterial3Components(),
|
||||
|
||||
// CanvasKit-only benchmarks
|
||||
|
|
Loading…
Reference in a new issue