Unverified Commit 28f30377 authored by Mouad Debbar's avatar Mouad Debbar Committed by GitHub

[web] Use plain platform views in benchmarks (#126080)

Removing the dependency between web benchmarks and `url_launcher`'s `Link` widget.
parent ad009fb7
lib/generated_plugin_registrant.dart
devtools_memory.json
*.sksl.json
vmservice.out
......@@ -3,49 +3,75 @@
// found in the LICENSE file.
import 'dart:async';
import 'dart:html' as html;
import 'package:flutter/material.dart';
import 'package:url_launcher/link.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 BenchLinkInfiniteScroll extends WidgetRecorder {
BenchLinkInfiniteScroll.forward()
: initialOffset = 0.0,
finalOffset = 30000.0,
super(name: benchmarkName);
class BenchPlatformViewInfiniteScroll extends WidgetRecorder {
BenchPlatformViewInfiniteScroll.forward()
: initialOffset = 0.0,
finalOffset = 30000.0,
super(name: benchmarkName) {
_registerFactory();
}
BenchLinkInfiniteScroll.backward()
: initialOffset = 30000.0,
finalOffset = 0.0,
super(name: benchmarkNameBackward);
BenchPlatformViewInfiniteScroll.backward()
: initialOffset = 30000.0,
finalOffset = 0.0,
super(name: benchmarkNameBackward) {
_registerFactory();
}
static const String benchmarkName = 'bench_link_infinite_scroll';
static const String benchmarkNameBackward = 'bench_link_infinite_scroll_backward';
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 Link Scroll Benchmark',
home: _InfiniteScrollLinks(initialOffset, finalOffset),
);
title: 'Infinite Platform View Scroll Benchmark',
home: _InfiniteScrollPlatformViews(initialOffset, finalOffset),
);
}
class _InfiniteScrollLinks extends StatefulWidget {
const _InfiniteScrollLinks(this.initialOffset, this.finalOffset);
class _InfiniteScrollPlatformViews extends StatefulWidget {
const _InfiniteScrollPlatformViews(this.initialOffset, this.finalOffset);
final double initialOffset;
final double finalOffset;
@override
State<_InfiniteScrollLinks> createState() => _InfiniteScrollLinksState();
State<_InfiniteScrollPlatformViews> createState() => _InfiniteScrollPlatformViewsState();
}
class _InfiniteScrollLinksState extends State<_InfiniteScrollLinks> {
class _InfiniteScrollPlatformViewsState extends State<_InfiniteScrollPlatformViews> {
static const Duration stepDuration = Duration(seconds: 20);
late ScrollController scrollController;
......@@ -83,15 +109,9 @@ class _InfiniteScrollLinksState extends State<_InfiniteScrollLinks> {
controller: scrollController,
itemExtent: 100.0,
itemBuilder: (BuildContext context, int index) {
return SizedBox(
return const 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'),
),
),
child: HtmlElementView(viewType: benchmarkViewType),
);
},
);
......
// 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}) {}
}
// 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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment