mirror of
https://github.com/flutter/flutter
synced 2024-10-13 11:42:54 +00:00
Move intrinsics tests to test mode only. (#10796)
This should improve debug-time performance.
This commit is contained in:
parent
2d79ce8419
commit
5344ffc790
|
@ -1587,9 +1587,6 @@ abstract class RenderBox extends RenderObject {
|
||||||
@override
|
@override
|
||||||
BoxConstraints get constraints => super.constraints;
|
BoxConstraints get constraints => super.constraints;
|
||||||
|
|
||||||
// We check the intrinsic sizes of each render box once by default.
|
|
||||||
bool _debugNeedsIntrinsicSizeCheck = true;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void debugAssertDoesMeetConstraints() {
|
void debugAssertDoesMeetConstraints() {
|
||||||
assert(constraints != null);
|
assert(constraints != null);
|
||||||
|
@ -1657,7 +1654,7 @@ abstract class RenderBox extends RenderObject {
|
||||||
'your fault. Contact support: https://github.com/flutter/flutter/issues/new'
|
'your fault. Contact support: https://github.com/flutter/flutter/issues/new'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (_debugNeedsIntrinsicSizeCheck || debugCheckIntrinsicSizes) {
|
if (debugCheckIntrinsicSizes) {
|
||||||
// verify that the intrinsics are sane
|
// verify that the intrinsics are sane
|
||||||
assert(!RenderObject.debugCheckingIntrinsics);
|
assert(!RenderObject.debugCheckingIntrinsics);
|
||||||
RenderObject.debugCheckingIntrinsics = true;
|
RenderObject.debugCheckingIntrinsics = true;
|
||||||
|
@ -1696,7 +1693,6 @@ abstract class RenderBox extends RenderObject {
|
||||||
// TODO(ianh): Test that values are internally consistent in more ways than the above.
|
// TODO(ianh): Test that values are internally consistent in more ways than the above.
|
||||||
|
|
||||||
RenderObject.debugCheckingIntrinsics = false;
|
RenderObject.debugCheckingIntrinsics = false;
|
||||||
_debugNeedsIntrinsicSizeCheck = false;
|
|
||||||
if (failures.isNotEmpty) {
|
if (failures.isNotEmpty) {
|
||||||
assert(failureCount > 0);
|
assert(failureCount > 0);
|
||||||
throw new FlutterError(
|
throw new FlutterError(
|
||||||
|
|
|
@ -106,6 +106,9 @@ bool debugPrintMarkNeedsPaintStacks = false;
|
||||||
bool debugPrintMarkNeedsLayoutStacks = false;
|
bool debugPrintMarkNeedsLayoutStacks = false;
|
||||||
|
|
||||||
/// Check the intrinsic sizes of each [RenderBox] during layout.
|
/// Check the intrinsic sizes of each [RenderBox] during layout.
|
||||||
|
///
|
||||||
|
/// By default this is turned off since these checks are expensive, but it is
|
||||||
|
/// enabled by the test framework.
|
||||||
bool debugCheckIntrinsicSizes = false;
|
bool debugCheckIntrinsicSizes = false;
|
||||||
|
|
||||||
/// Adds [dart:developer.Timeline] events for every [RenderObject] painted.
|
/// Adds [dart:developer.Timeline] events for every [RenderObject] painted.
|
||||||
|
@ -161,9 +164,13 @@ void debugPaintPadding(Canvas canvas, Rect outerRect, Rect innerRect, { double o
|
||||||
/// This function is used by the test framework to ensure that debug variables
|
/// This function is used by the test framework to ensure that debug variables
|
||||||
/// haven't been inadvertently changed.
|
/// haven't been inadvertently changed.
|
||||||
///
|
///
|
||||||
/// See [https://docs.flutter.io/flutter/rendering/rendering-library.html] for
|
/// See <https://docs.flutter.io/flutter/rendering/rendering-library.html> for
|
||||||
/// a complete list.
|
/// a complete list.
|
||||||
bool debugAssertAllRenderVarsUnset(String reason) {
|
///
|
||||||
|
/// The `debugCheckIntrinsicSizesOverride` argument can be provided to override
|
||||||
|
/// the expected value for [debugCheckIntrinsicSizes]. (This exists because the
|
||||||
|
/// test framework itself overrides this value in some cases.)
|
||||||
|
bool debugAssertAllRenderVarsUnset(String reason, { bool debugCheckIntrinsicSizesOverride: false }) {
|
||||||
assert(() {
|
assert(() {
|
||||||
if (debugPaintSizeEnabled ||
|
if (debugPaintSizeEnabled ||
|
||||||
debugPaintBaselinesEnabled ||
|
debugPaintBaselinesEnabled ||
|
||||||
|
@ -173,7 +180,7 @@ bool debugAssertAllRenderVarsUnset(String reason) {
|
||||||
debugRepaintTextRainbowEnabled ||
|
debugRepaintTextRainbowEnabled ||
|
||||||
debugPrintMarkNeedsPaintStacks ||
|
debugPrintMarkNeedsPaintStacks ||
|
||||||
debugPrintMarkNeedsLayoutStacks ||
|
debugPrintMarkNeedsLayoutStacks ||
|
||||||
debugCheckIntrinsicSizes ||
|
debugCheckIntrinsicSizes != debugCheckIntrinsicSizesOverride ||
|
||||||
debugProfilePaintsEnabled ||
|
debugProfilePaintsEnabled ||
|
||||||
debugPaintSizeColor != _kDebugPaintSizeColor ||
|
debugPaintSizeColor != _kDebugPaintSizeColor ||
|
||||||
debugPaintSpacingColor != _kDebugPaintSpacingColor ||
|
debugPaintSpacingColor != _kDebugPaintSpacingColor ||
|
||||||
|
|
|
@ -477,8 +477,17 @@ class RenderEditable extends RenderBox {
|
||||||
_layoutText(constraints.maxWidth);
|
_layoutText(constraints.maxWidth);
|
||||||
_caretPrototype = new Rect.fromLTWH(0.0, _kCaretHeightOffset, _kCaretWidth, _preferredLineHeight - 2.0 * _kCaretHeightOffset);
|
_caretPrototype = new Rect.fromLTWH(0.0, _kCaretHeightOffset, _kCaretWidth, _preferredLineHeight - 2.0 * _kCaretHeightOffset);
|
||||||
_selectionRects = null;
|
_selectionRects = null;
|
||||||
|
// We grab _textPainter.size here because assigning to `size` on the next
|
||||||
|
// line will trigger us to validate our intrinsic sizes, which will change
|
||||||
|
// _textPainter's layout because the intrinsic size calculations are
|
||||||
|
// destructive, which would mean we would get different results if we later
|
||||||
|
// used properties on _textPainter in this method.
|
||||||
|
// Other _textPainter state like didExceedMaxLines will also be affected,
|
||||||
|
// though we currently don't use those here.
|
||||||
|
// See also RenderParagraph which has a similar issue.
|
||||||
|
final Size textPainterSize = _textPainter.size;
|
||||||
size = new Size(constraints.maxWidth, constraints.constrainHeight(_preferredHeight(constraints.maxWidth)));
|
size = new Size(constraints.maxWidth, constraints.constrainHeight(_preferredHeight(constraints.maxWidth)));
|
||||||
final Size contentSize = new Size(_textPainter.width + _kCaretGap + _kCaretWidth, _textPainter.height);
|
final Size contentSize = new Size(textPainterSize.width + _kCaretGap + _kCaretWidth, textPainterSize.height);
|
||||||
final double _maxScrollExtent = _getMaxScrollExtent(contentSize);
|
final double _maxScrollExtent = _getMaxScrollExtent(contentSize);
|
||||||
_hasVisualOverflow = _maxScrollExtent > 0.0;
|
_hasVisualOverflow = _maxScrollExtent > 0.0;
|
||||||
offset.applyViewportDimension(_viewportExtent);
|
offset.applyViewportDimension(_viewportExtent);
|
||||||
|
|
|
@ -213,6 +213,7 @@ class RenderParagraph extends RenderBox {
|
||||||
// us to validate our intrinsic sizes, which will change _textPainter's
|
// us to validate our intrinsic sizes, which will change _textPainter's
|
||||||
// layout because the intrinsic size calculations are destructive.
|
// layout because the intrinsic size calculations are destructive.
|
||||||
// Other _textPainter state like didExceedMaxLines will also be affected.
|
// Other _textPainter state like didExceedMaxLines will also be affected.
|
||||||
|
// See also RenderEditable which has a similar issue.
|
||||||
final Size textSize = _textPainter.size;
|
final Size textSize = _textPainter.size;
|
||||||
final bool didOverflowHeight = _textPainter.didExceedMaxLines;
|
final bool didOverflowHeight = _textPainter.didExceedMaxLines;
|
||||||
size = constraints.constrain(textSize);
|
size = constraints.constrain(textSize);
|
||||||
|
|
|
@ -2862,6 +2862,23 @@ class RenderSemanticsGestureHandler extends RenderProxyBox implements SemanticsA
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void debugFillDescription(List<String> description) {
|
||||||
|
super.debugFillDescription(description);
|
||||||
|
final List<String> gestures = <String>[];
|
||||||
|
if (onTap != null)
|
||||||
|
gestures.add('tap');
|
||||||
|
if (onLongPress != null)
|
||||||
|
gestures.add('long press');
|
||||||
|
if (onHorizontalDragUpdate != null)
|
||||||
|
gestures.add('horizontal scroll');
|
||||||
|
if (onVerticalDragUpdate != null)
|
||||||
|
gestures.add('vertical scroll');
|
||||||
|
if (gestures.isEmpty)
|
||||||
|
gestures.add('<none>');
|
||||||
|
description.add('gestures: ${gestures.join(", ")}');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Add annotations to the [SemanticsNode] for this subtree.
|
/// Add annotations to the [SemanticsNode] for this subtree.
|
||||||
|
|
|
@ -95,11 +95,15 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
|
||||||
/// [debugPrintOverride], which can be overridden by subclasses.
|
/// [debugPrintOverride], which can be overridden by subclasses.
|
||||||
TestWidgetsFlutterBinding() {
|
TestWidgetsFlutterBinding() {
|
||||||
debugPrint = debugPrintOverride;
|
debugPrint = debugPrintOverride;
|
||||||
|
debugCheckIntrinsicSizes = checkIntrinsicSizes;
|
||||||
}
|
}
|
||||||
|
|
||||||
@protected
|
@protected
|
||||||
DebugPrintCallback get debugPrintOverride => debugPrint;
|
DebugPrintCallback get debugPrintOverride => debugPrint;
|
||||||
|
|
||||||
|
@protected
|
||||||
|
bool get checkIntrinsicSizes => false;
|
||||||
|
|
||||||
/// Creates and initializes the binding. This function is
|
/// Creates and initializes the binding. This function is
|
||||||
/// idempotent; calling it a second time will just return the
|
/// idempotent; calling it a second time will just return the
|
||||||
/// previously-created instance.
|
/// previously-created instance.
|
||||||
|
@ -460,13 +464,14 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
|
||||||
debugPrintOverride: debugPrintOverride,
|
debugPrintOverride: debugPrintOverride,
|
||||||
));
|
));
|
||||||
assert(debugAssertAllRenderVarsUnset(
|
assert(debugAssertAllRenderVarsUnset(
|
||||||
'The value of a rendering debug variable was changed by the test.'
|
'The value of a rendering debug variable was changed by the test.',
|
||||||
|
debugCheckIntrinsicSizesOverride: checkIntrinsicSizes,
|
||||||
));
|
));
|
||||||
assert(debugAssertAllWidgetVarsUnset(
|
assert(debugAssertAllWidgetVarsUnset(
|
||||||
'The value of a widget debug variable was changed by the test.'
|
'The value of a widget debug variable was changed by the test.',
|
||||||
));
|
));
|
||||||
assert(debugAssertAllSchedulerVarsUnset(
|
assert(debugAssertAllSchedulerVarsUnset(
|
||||||
'The value of a scheduler debug variable was changed by the test.'
|
'The value of a scheduler debug variable was changed by the test.',
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -505,6 +510,9 @@ class AutomatedTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding {
|
||||||
@override
|
@override
|
||||||
DebugPrintCallback get debugPrintOverride => debugPrintSynchronously;
|
DebugPrintCallback get debugPrintOverride => debugPrintSynchronously;
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool get checkIntrinsicSizes => true;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
test_package.Timeout get defaultTestTimeout => const test_package.Timeout(const Duration(seconds: 5));
|
test_package.Timeout get defaultTestTimeout => const test_package.Timeout(const Duration(seconds: 5));
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue