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

Commit 9e9bed1

Browse files
committed
Doc
1 parent 42c75e0 commit 9e9bed1

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

lib/web_ui/test/html/image_test.dart

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,23 @@ Future<Image> _encodeToHtmlThenDecode(
7272
return (await (await descriptor.instantiateCodec()).getNextFrame()).image;
7373
}
7474

75-
Future<bool> imageRawUsesCorrectBehavior(PixelFormat format) async {
75+
// This utility function detects how the current Web engine decodes pixel data.
76+
//
77+
// The HTML renderer uses the BMP format to display pixel data, but it used to
78+
// uses a wrong implementation. The bug has been fixed, but the fix breaks apps
79+
// that had to provide incorrect data to work around this issue. This function
80+
// is used in the migration guide to assist libraries that would like to run on
81+
// both pre- and post-patch engines by testing the current behavior on a single
82+
// pixel, making use the fact that the patch fixes the pixel order.
83+
//
84+
// The `format` argument is used for testing. In the actual code it should be
85+
// replaced by `PixelFormat.rgba8888`.
86+
//
87+
// See also:
88+
//
89+
// * Patch: https://github.com/flutter/engine/pull/29448
90+
// * Migration guide: (TODO)
91+
Future<bool> rawImageUsesCorrectBehavior(PixelFormat format) async {
7692
final ImageDescriptor descriptor = ImageDescriptor.raw(
7793
await ImmutableBuffer.fromUint8List(Uint8List.fromList(<int>[0xED, 0, 0, 0])),
7894
width: 1, height: 1, pixelFormat: format);
@@ -156,23 +172,8 @@ Future<void> testMain() async {
156172
expect(actualPixels, listEqual(benchmarkPixels, tolerance: 1));
157173
});
158174

159-
test('Correctly encodes an opaque image in bgra8888', () async {
160-
// A 1x1 testing image without transparency.
161-
final Image sourceImage = await _encodeToHtmlThenDecode(
162-
_pixelsToBytes(<int>[0xFE0000FF]), 1, 1, pixelFormat: PixelFormat.rgba8888,
163-
);
164-
final Uint8List actualPixels = Uint8List.sublistView(
165-
(await sourceImage.toByteData(format: ImageByteFormat.rawStraightRgba))!);
166-
// The `benchmarkPixels` is the same as `sourceImage` except that the R and
167-
// G channels are swapped and the fully transparent last pixel is turned 0.
168-
final Uint8List benchmarkPixels = _pixelsToBytes(
169-
<int>[0x0201FFFF, 0x05FE04FF, 0xFD0807FF, 0x00000000],
170-
);
171-
expect(actualPixels, listEqual(benchmarkPixels));
172-
});
173-
174-
test('The check detector is correct', () async {
175-
expect(await imageRawUsesCorrectBehavior(PixelFormat.rgba8888), true);
176-
expect(await imageRawUsesCorrectBehavior(PixelFormat.bgra8888), false);
175+
test('The behavior detector works correctly', () async {
176+
expect(await rawImageUsesCorrectBehavior(PixelFormat.rgba8888), true);
177+
expect(await rawImageUsesCorrectBehavior(PixelFormat.bgra8888), false);
177178
});
178179
}

0 commit comments

Comments
 (0)