From e143ac2d8504e9d53a4c0a06a56437d74b532879 Mon Sep 17 00:00:00 2001 From: Devon Carew Date: Mon, 11 Jan 2021 16:34:27 -0800 Subject: [PATCH] increase the value of debugImageOverheadAllowance from 104 bytes to 128kb (#73720) --- packages/flutter/lib/src/painting/debug.dart | 8 +++-- .../test/painting/paint_image_test.dart | 31 +++++++++++++++++++ 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/packages/flutter/lib/src/painting/debug.dart b/packages/flutter/lib/src/painting/debug.dart index 54692f7b76..f1a42f37e3 100644 --- a/packages/flutter/lib/src/painting/debug.dart +++ b/packages/flutter/lib/src/painting/debug.dart @@ -157,11 +157,13 @@ PaintImageCallback? debugOnPaintImage; /// This has no effect unless asserts are enabled. bool debugInvertOversizedImages = false; +const int _imageOverheadAllowanceDefault = 128 * 1024; + /// The number of bytes an image must use before it triggers inversion when /// [debugInvertOversizedImages] is true. /// -/// Default is 1024 (1kb). -int debugImageOverheadAllowance = 1024; +/// Default is 128kb. +int debugImageOverheadAllowance = _imageOverheadAllowanceDefault; /// Returns true if none of the painting library debug variables have been changed. /// @@ -180,7 +182,7 @@ bool debugAssertAllPaintingVarsUnset(String reason, { bool debugDisableShadowsOv debugNetworkImageHttpClientProvider != null || debugOnPaintImage != null || debugInvertOversizedImages == true || - debugImageOverheadAllowance != 1024) { + debugImageOverheadAllowance != _imageOverheadAllowanceDefault) { throw FlutterError(reason); } return true; diff --git a/packages/flutter/test/painting/paint_image_test.dart b/packages/flutter/test/painting/paint_image_test.dart index 1f52caa8f4..6f47cfca75 100644 --- a/packages/flutter/test/painting/paint_image_test.dart +++ b/packages/flutter/test/painting/paint_image_test.dart @@ -20,6 +20,7 @@ class TestCanvas implements Canvas { void main() { late ui.Image image300x300; late ui.Image image300x200; + setUpAll(() async { image300x300 = await createTestImage(width: 300, height: 300, cache: false); image300x200 = await createTestImage(width: 300, height: 200, cache: false); @@ -108,6 +109,36 @@ void main() { FlutterError.onError = oldFlutterError; }); + test('debugInvertOversizedImages smaller than overhead allowance', () async { + debugInvertOversizedImages = true; + final FlutterExceptionHandler? oldFlutterError = FlutterError.onError; + + final List messages = []; + FlutterError.onError = (FlutterErrorDetails details) { + messages.add(details.exceptionAsString()); + }; + + try { + // Create a 290x290 sized image, which is ~24kb less than the allocated size, + // and below the default debugImageOverheadAllowance size of 128kb. + const Rect rect = Rect.fromLTWH(50.0, 50.0, 290.0, 290.0); + final TestCanvas canvas = TestCanvas(); + + paintImage( + canvas: canvas, + rect: rect, + image: image300x300, + debugImageLabel: 'TestImage', + fit: BoxFit.fill, + ); + + expect(messages, isEmpty); + } finally { + debugInvertOversizedImages = false; + FlutterError.onError = oldFlutterError; + } + }); + test('centerSlice with scale ≠ 1', () async { final TestCanvas canvas = TestCanvas(); paintImage(