Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 489c399

Browse files
authored
Update (flipping the default from false -> true) and deprecate Paint.enableDithering. (#44705)
Update: Blocked on #44912 landing, and merging into google3. --- Partial work towards flutter/flutter#112498. _**tl;dr**: In Impeller's backend we intend to _always_ dither gradients, and never allow any changes long-term (i.e., write your own shader if you want different behavior) with the assumption that dithered gradients look better most of the time, and don't typically hurt elsewhere._ Note that, at the time of this writing, I couldn't find a single case of this being set explicitly to `true` inside Google, and there are between [100 and 200 publicly accessible on GitHub](https://github.com/search?q=%22Paint.enableDithering%22+language%3ADart&type=code&l=Dart), of which virtually all are setting it explicitly to `true`. There are some (valid) concerns this would cause a lot of golden-file image diffs, so I'm going to seek explicit approval from the Google testing team as well as someone from the framework team before landing this commit.
1 parent 66e53ee commit 489c399

File tree

10 files changed

+22
-17
lines changed

10 files changed

+22
-17
lines changed

flutter_frontend_server/test/to_string_test.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ Future<void> main(List<String> args) async {
4545
]));
4646
final ProcessResult runResult = Process.runSync(dart, <String>[regularDill]);
4747
checkProcessResult(runResult);
48-
String paintString = '"Paint.toString":"Paint(Color(0xffffffff))"';
48+
// TODO(matanlurey): "dither: true" is now present by default, until it is
49+
// remove entirely. See https://github.com/flutter/flutter/issues/112498.
50+
String paintString = '"Paint.toString":"Paint(Color(0xffffffff); dither: true)"';
4951
if (buildDir.contains('release')) {
5052
paintString = '"Paint.toString":"Instance of \'Paint\'"';
5153
}

lib/ui/painting.dart

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1487,22 +1487,19 @@ class Paint {
14871487
_data.setInt32(_kDitherOffset, value ? 1 : 0, _kFakeHostEndian);
14881488
}
14891489

1490-
/// Whether to dither the output when drawing images.
1491-
///
1492-
/// If false, the default value, dithering will be enabled when the input
1493-
/// color depth is higher than the output color depth. For example,
1494-
/// drawing an RGB8 image onto an RGB565 canvas.
1495-
///
1496-
/// This value also controls dithering of [shader]s, which can make
1497-
/// gradients appear smoother.
1498-
///
1499-
/// Whether or not dithering affects the output is implementation defined.
1500-
/// Some implementations may choose to ignore this completely, if they're
1501-
/// unable to control dithering.
1502-
///
1503-
/// To ensure that dithering is consistently enabled for your entire
1504-
/// application, set this to true before invoking any drawing related code.
1505-
static bool enableDithering = false;
1490+
/// Whether to dither the output when drawing some elements such as gradients.
1491+
///
1492+
/// It is not expected that this flag will be used in the future; please leave
1493+
/// feedback in <https://github.com/flutter/flutter/issues/112498> if there is
1494+
/// a use case for this flag to remain long term.
1495+
@Deprecated(
1496+
'Dithering is now enabled by default on some elements (such as gradients) '
1497+
'and further support for dithering is expected to be handled by custom '
1498+
'shaders, so this flag is being removed: '
1499+
'https://github.com/flutter/flutter/issues/112498.'
1500+
'This feature was deprecated after 3.14.0-0.1.pre.'
1501+
)
1502+
static bool enableDithering = true;
15061503

15071504
@override
15081505
String toString() {
27.3 KB
Loading
22.6 KB
Loading
37.5 KB
Loading
37.5 KB
Loading
7.12 KB
Loading
27.3 KB
Loading
37.5 KB
Loading

testing/dart/canvas_test.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,10 @@ void main() {
203203
}
204204

205205
test('Simple gradient', () async {
206+
// TODO(matanl): While deprecated, we still don't want to accidentally
207+
// change the behavior of the old API,
208+
// https://github.com/flutter/flutter/issues/112498.
209+
// ignore: deprecated_member_use
206210
Paint.enableDithering = false;
207211
final Image image = await toImage((Canvas canvas) {
208212
final Paint paint = Paint()..shader = makeGradient();
@@ -217,6 +221,8 @@ void main() {
217221
}, skip: !Platform.isLinux); // https://github.com/flutter/flutter/issues/53784
218222

219223
test('Simple dithered gradient', () async {
224+
// TODO(matanl): Reword this test once we remove the deprecated API.
225+
// ignore: deprecated_member_use
220226
Paint.enableDithering = true;
221227
final Image image = await toImage((Canvas canvas) {
222228
final Paint paint = Paint()..shader = makeGradient();

0 commit comments

Comments
 (0)