Skip to content

Commit

Permalink
Remove support for Paint.enableDithering=false in dart:ui. (flutt…
Browse files Browse the repository at this point in the history
…er#46745)

Work towards flutter/flutter#112498.

No behavioral changes to existing code, except `Paint.enableDithering = false` will no longer be an option.
  • Loading branch information
matanlurey authored Oct 11, 2023
1 parent e41c646 commit 8086814
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 51 deletions.
4 changes: 1 addition & 3 deletions flutter_frontend_server/test/to_string_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ Future<void> main(List<String> args) async {
]));
final ProcessResult runResult = Process.runSync(dart, <String>[regularDill]);
checkProcessResult(runResult);
// TODO(matanlurey): "dither: true" is now present by default, until it is
// remove entirely. See https://github.com/flutter/flutter/issues/112498.
String paintString = '"Paint.toString":"Paint(Color(0xffffffff); dither: true)"';
String paintString = '"Paint.toString":"Paint(Color(0xffffffff))"';
if (buildDir.contains('release')) {
paintString = '"Paint.toString":"Instance of \'Paint\'"';
}
Expand Down
30 changes: 5 additions & 25 deletions lib/ui/painting.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1091,9 +1091,8 @@ class Paint {
/// Constructs an empty [Paint] object with all fields initialized to
/// their defaults.
Paint() {
if (enableDithering) {
_dither = true;
}
// TODO(matanlurey): Remove as part of https://github.com/flutter/flutter/issues/112498.
_enableDithering();
}

// Paint objects are encoded in two buffers:
Expand Down Expand Up @@ -1479,27 +1478,11 @@ class Paint {
_data.setInt32(_kInvertColorOffset, value ? 1 : 0, _kFakeHostEndian);
}

bool get _dither {
return _data.getInt32(_kDitherOffset, _kFakeHostEndian) == 1;
}
set _dither(bool value) {
_data.setInt32(_kDitherOffset, value ? 1 : 0, _kFakeHostEndian);
// TODO(matanlurey): Remove as part of https://github.com/flutter/flutter/issues/112498.
void _enableDithering() {
_data.setInt32(_kDitherOffset, 1, _kFakeHostEndian);
}

/// Whether to dither the output when drawing some elements such as gradients.
///
/// It is not expected that this flag will be used in the future; please leave
/// feedback in <https://github.com/flutter/flutter/issues/112498> if there is
/// a use case for this flag to remain long term.
@Deprecated(
'Dithering is now enabled by default on some elements (such as gradients) '
'and further support for dithering is expected to be handled by custom '
'shaders, so this flag is being removed: '
'https://github.com/flutter/flutter/issues/112498.'
'This feature was deprecated after 3.14.0-0.1.pre.'
)
static bool enableDithering = true;

@override
String toString() {
if (const bool.fromEnvironment('dart.vm.product')) {
Expand Down Expand Up @@ -1562,9 +1545,6 @@ class Paint {
if (invertColors) {
result.write('${semicolon}invert: $invertColors');
}
if (_dither) {
result.write('${semicolon}dither: $_dither');
}
result.write(')');
return result.toString();
}
Expand Down
1 change: 0 additions & 1 deletion lib/web_ui/lib/painting.dart
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@ enum Clip {

abstract class Paint {
factory Paint() => engine.renderer.createPaint();
static bool enableDithering = false;
BlendMode get blendMode;
set blendMode(BlendMode value);
PaintingStyle get style;
Expand Down
23 changes: 1 addition & 22 deletions testing/dart/canvas_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -202,28 +202,7 @@ void main() {
);
}

test('Simple gradient', () async {
// TODO(matanl): While deprecated, we still don't want to accidentally
// change the behavior of the old API,
// https://github.com/flutter/flutter/issues/112498.
// ignore: deprecated_member_use
Paint.enableDithering = false;
final Image image = await toImage((Canvas canvas) {
final Paint paint = Paint()..shader = makeGradient();
canvas.drawPaint(paint);
}, 100, 100);
expect(image.width, equals(100));
expect(image.height, equals(100));

final bool areEqual =
await fuzzyGoldenImageCompare(image, 'canvas_test_gradient.png');
expect(areEqual, true);
}, skip: !Platform.isLinux); // https://github.com/flutter/flutter/issues/53784

test('Simple dithered gradient', () async {
// TODO(matanl): Reword this test once we remove the deprecated API.
// ignore: deprecated_member_use
Paint.enableDithering = true;
test('Simple gradient, which is implicitly dithered', () async {
final Image image = await toImage((Canvas canvas) {
final Paint paint = Paint()..shader = makeGradient();
canvas.drawPaint(paint);
Expand Down

0 comments on commit 8086814

Please sign in to comment.