From 7e9ccecf474a6670e3e532e8a871a53872a098fc Mon Sep 17 00:00:00 2001 From: Dan Field Date: Thu, 11 Jul 2019 16:46:54 -0700 Subject: [PATCH] Remove breaking asserts (flutter/engine#9797) --- engine/src/flutter/lib/ui/compositing.dart | 4 +++- engine/src/flutter/lib/ui/painting.dart | 20 +++++++++++-------- .../testing/dart/color_filter_test.dart | 8 ++++++++ 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/engine/src/flutter/lib/ui/compositing.dart b/engine/src/flutter/lib/ui/compositing.dart index 5f8fdbfe87..232514c0f1 100644 --- a/engine/src/flutter/lib/ui/compositing.dart +++ b/engine/src/flutter/lib/ui/compositing.dart @@ -390,7 +390,9 @@ class SceneBuilder extends NativeFieldWrapperClass2 { ColorFilterEngineLayer pushColorFilter(ColorFilter filter, { ColorFilterEngineLayer oldLayer }) { assert(filter != null); assert(_debugCheckCanBeUsedAsOldLayer(oldLayer, 'pushColorFilter')); - final ColorFilterEngineLayer layer = ColorFilterEngineLayer._(_pushColorFilter(filter._toNativeColorFilter())); + final _ColorFilter nativeFilter = filter._toNativeColorFilter(); + assert(nativeFilter != null); + final ColorFilterEngineLayer layer = ColorFilterEngineLayer._(_pushColorFilter(nativeFilter)); assert(_debugPushLayer(layer)); return layer; } diff --git a/engine/src/flutter/lib/ui/painting.dart b/engine/src/flutter/lib/ui/painting.dart index 36e8bf77d4..f5e11c1a65 100644 --- a/engine/src/flutter/lib/ui/painting.dart +++ b/engine/src/flutter/lib/ui/painting.dart @@ -1343,16 +1343,17 @@ class Paint { } set colorFilter(ColorFilter value) { - if (value == null) { + final _ColorFilter nativeFilter = value?._toNativeColorFilter(); + if (nativeFilter == null) { if (_objects != null) { _objects[_kColorFilterIndex] = null; } } else { if (_objects == null) { _objects = List(_kObjectCount); - _objects[_kColorFilterIndex] = value._toNativeColorFilter(); + _objects[_kColorFilterIndex] = nativeFilter; } else if (_objects[_kColorFilterIndex]?.creator != value) { - _objects[_kColorFilterIndex] = value._toNativeColorFilter(); + _objects[_kColorFilterIndex] = nativeFilter; } } } @@ -2489,9 +2490,7 @@ class ColorFilter { /// to the [Paint.blendMode], using the output of this filter as the source /// and the background as the destination. const ColorFilter.mode(Color color, BlendMode blendMode) - : assert(color != null), - assert(blendMode != null), - _color = color, + : _color = color, _blendMode = blendMode, _matrix = null, _type = _TypeMode; @@ -2500,8 +2499,7 @@ class ColorFilter { /// matrix is in row-major order and the translation column is specified in /// unnormalized, 0...255, space. const ColorFilter.matrix(List matrix) - : assert(matrix != null, 'Color Matrix argument was null.'), - _color = null, + : _color = null, _blendMode = null, _matrix = matrix, _type = _TypeMatrix; @@ -2555,8 +2553,14 @@ class ColorFilter { _ColorFilter _toNativeColorFilter() { switch (_type) { case _TypeMode: + if (_color == null || _blendMode == null) { + return null; + } return _ColorFilter.mode(this); case _TypeMatrix: + if (_matrix == null) { + return null; + } assert(_matrix.length == 20, 'Color Matrix must have 20 entries.'); return _ColorFilter.matrix(this); case _TypeLinearToSrgbGamma: diff --git a/engine/src/flutter/testing/dart/color_filter_test.dart b/engine/src/flutter/testing/dart/color_filter_test.dart index a2c80cebd2..444b8d3046 100644 --- a/engine/src/flutter/testing/dart/color_filter_test.dart +++ b/engine/src/flutter/testing/dart/color_filter_test.dart @@ -41,6 +41,14 @@ void main() { return bytes.buffer.asUint32List(); } + test('ColorFilter - nulls', () async { + final Paint paint = Paint()..colorFilter = ColorFilter.mode(null, null); + expect(paint.colorFilter, null); + + paint.colorFilter = ColorFilter.matrix(null); + expect(paint.colorFilter, null); + }); + test('ColorFilter - mode', () async { final Paint paint = Paint() ..color = green