mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Pass _caretPrototype to prevent cache miss (#46720)
This commit is contained in:
parent
3fe6668849
commit
b011ea5468
@ -9,3 +9,4 @@ const String kPostBackdropFilterRouteName = '/post_backdrop_filter';
|
||||
const String kSimpleAnimationRouteName = '/simple_animation';
|
||||
const String kPictureCacheRouteName = '/picture_cache';
|
||||
const String kLargeImagesRouteName = '/large_images';
|
||||
const String kTextRouteName = '/text';
|
||||
|
||||
@ -12,6 +12,7 @@ import 'src/cubic_bezier.dart';
|
||||
import 'src/cull_opacity.dart';
|
||||
import 'src/post_backdrop_filter.dart';
|
||||
import 'src/simple_animation.dart';
|
||||
import 'src/text.dart';
|
||||
|
||||
const String kMacrobenchmarks ='Macrobenchmarks';
|
||||
|
||||
@ -34,6 +35,7 @@ class MacrobenchmarksApp extends StatelessWidget {
|
||||
kSimpleAnimationRouteName: (BuildContext conttext) => SimpleAnimationPage(),
|
||||
kPictureCacheRouteName: (BuildContext context) => PictureCachePage(),
|
||||
kLargeImagesRouteName: (BuildContext context) => LargeImagesPage(),
|
||||
kTextRouteName: (BuildContext context) => TextPage(),
|
||||
},
|
||||
);
|
||||
}
|
||||
@ -97,6 +99,13 @@ class HomePage extends StatelessWidget {
|
||||
Navigator.pushNamed(context, kLargeImagesRouteName);
|
||||
},
|
||||
),
|
||||
RaisedButton(
|
||||
key: const Key(kTextRouteName),
|
||||
child: const Text('Text'),
|
||||
onPressed: () {
|
||||
Navigator.pushNamed(context, kTextRouteName);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
22
dev/benchmarks/macrobenchmarks/lib/src/text.dart
Normal file
22
dev/benchmarks/macrobenchmarks/lib/src/text.dart
Normal file
@ -0,0 +1,22 @@
|
||||
// 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 'package:flutter/material.dart';
|
||||
|
||||
class TextPage extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
children: <Widget>[
|
||||
Container(
|
||||
width: 200,
|
||||
height: 100,
|
||||
child: const TextField(
|
||||
key: Key('basic-textfield'),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
// 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 'package:flutter_driver/driver_extension.dart';
|
||||
import 'package:macrobenchmarks/main.dart' as app;
|
||||
|
||||
void main() {
|
||||
enableFlutterDriverExtension();
|
||||
app.main();
|
||||
}
|
||||
@ -0,0 +1,21 @@
|
||||
// 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 'package:flutter_driver/flutter_driver.dart';
|
||||
import 'package:macrobenchmarks/common.dart';
|
||||
|
||||
import 'util.dart';
|
||||
|
||||
void main() {
|
||||
macroPerfTest(
|
||||
'textfield_perf',
|
||||
kTextRouteName,
|
||||
driverOps: (FlutterDriver driver) async {
|
||||
final SerializableFinder textfield = find.byValueKey('basic-textfield');
|
||||
driver.tap(textfield);
|
||||
// Caret should be cached, so repeated blinking should not require recompute.
|
||||
await Future<void>.delayed(const Duration(milliseconds: 5000));
|
||||
},
|
||||
);
|
||||
}
|
||||
14
dev/devicelab/bin/tasks/textfield_perf.dart
Normal file
14
dev/devicelab/bin/tasks/textfield_perf.dart
Normal file
@ -0,0 +1,14 @@
|
||||
// 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_devicelab/tasks/perf_tests.dart';
|
||||
import 'package:flutter_devicelab/framework/adb.dart';
|
||||
import 'package:flutter_devicelab/framework/framework.dart';
|
||||
|
||||
Future<void> main() async {
|
||||
deviceOperatingSystem = DeviceOperatingSystem.android;
|
||||
await task(createTextfieldPerfTest());
|
||||
}
|
||||
@ -156,6 +156,14 @@ TaskFunction createBasicMaterialCompileTest() {
|
||||
};
|
||||
}
|
||||
|
||||
TaskFunction createTextfieldPerfTest() {
|
||||
return PerfTest(
|
||||
'${flutterDirectory.path}/dev/benchmarks/macrobenchmarks',
|
||||
'test_driver/textfield_perf.dart',
|
||||
'textfield_perf',
|
||||
).run;
|
||||
}
|
||||
|
||||
|
||||
/// Measure application startup performance.
|
||||
class StartupTest {
|
||||
|
||||
@ -170,6 +170,8 @@ class TextPainter {
|
||||
void markNeedsLayout() {
|
||||
_paragraph = null;
|
||||
_needsLayout = true;
|
||||
_previousCaretPosition = null;
|
||||
_previousCaretPrototype = null;
|
||||
}
|
||||
|
||||
/// The (potentially styled) text to paint.
|
||||
|
||||
@ -365,7 +365,7 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin {
|
||||
|
||||
final Offset startOffset = _textPainter.getOffsetForCaret(
|
||||
TextPosition(offset: _selection.start, affinity: _selection.affinity),
|
||||
Rect.zero,
|
||||
_caretPrototype,
|
||||
);
|
||||
// TODO(justinmc): https://github.com/flutter/flutter/issues/31495
|
||||
// Check if the selection is visible with an approximation because a
|
||||
@ -381,7 +381,7 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin {
|
||||
|
||||
final Offset endOffset = _textPainter.getOffsetForCaret(
|
||||
TextPosition(offset: _selection.end, affinity: _selection.affinity),
|
||||
Rect.zero,
|
||||
_caretPrototype,
|
||||
);
|
||||
_selectionEndInViewport.value = visibleRegion
|
||||
.inflate(visibleRegionSlop)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user