@@ -1058,6 +1058,7 @@ class Paint {
10581058 static const int _kMaskFilterBlurStyleIndex = 10 ;
10591059 static const int _kMaskFilterSigmaIndex = 11 ;
10601060 static const int _kInvertColorIndex = 12 ;
1061+ static const int _kDitherIndex = 13 ;
10611062
10621063 static const int _kIsAntiAliasOffset = _kIsAntiAliasIndex << 2 ;
10631064 static const int _kColorOffset = _kColorIndex << 2 ;
@@ -1072,8 +1073,9 @@ class Paint {
10721073 static const int _kMaskFilterBlurStyleOffset = _kMaskFilterBlurStyleIndex << 2 ;
10731074 static const int _kMaskFilterSigmaOffset = _kMaskFilterSigmaIndex << 2 ;
10741075 static const int _kInvertColorOffset = _kInvertColorIndex << 2 ;
1076+ static const int _kDitherOffset = _kDitherIndex << 2 ;
10751077 // If you add more fields, remember to update _kDataByteCount.
1076- static const int _kDataByteCount = 52 ;
1078+ static const int _kDataByteCount = 56 ;
10771079
10781080 // Binary format must match the deserialization code in paint.cc.
10791081 List <dynamic > _objects;
@@ -1401,6 +1403,25 @@ class Paint {
14011403 _data.setInt32 (_kInvertColorOffset, value ? 1 : 0 , _kFakeHostEndian);
14021404 }
14031405
1406+ /// Whether to dither the output when drawing images.
1407+ ///
1408+ /// If false, the default value, dithering will be enabled when the input
1409+ /// color depth is higher than the output color depth. For example,
1410+ /// drawing an RGB8 image onto an RGB565 canvas.
1411+ ///
1412+ /// This value also controls dithering of [shader] s, which can make
1413+ /// gradients appear smoother.
1414+ ///
1415+ /// Whether or not dithering affects the output is implementation defined.
1416+ /// Some implementations may choose to ignore this completely, if they're
1417+ /// unable to control dithering.
1418+ bool get dither {
1419+ return _data.getInt32 (_kDitherOffset, _kFakeHostEndian) == 1 ;
1420+ }
1421+ set dither (bool value) {
1422+ _data.setInt32 (_kDitherOffset, value ? 1 : 0 , _kFakeHostEndian);
1423+ }
1424+
14041425 @override
14051426 String toString () {
14061427 final StringBuffer result = StringBuffer ();
@@ -1459,6 +1480,8 @@ class Paint {
14591480 }
14601481 if (invertColors)
14611482 result.write ('${semicolon }invert: $invertColors ' );
1483+ if (dither)
1484+ result.write ('${semicolon }dither: $dither ' );
14621485 result.write (')' );
14631486 return result.toString ();
14641487 }
0 commit comments