Skip to content

Commit 658a1a2

Browse files
authored
Adds support for f16 surfaces to wide gamut unit tests. (#126712)
issue: flutter/flutter#126620 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/wiki/Tree-hygiene#overview [Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene [test-exempt]: https://github.com/flutter/flutter/wiki/Tree-hygiene#tests [Flutter Style Guide]: https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo [Features we expect every widget to implement]: https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/wiki/Chat
1 parent d3e0e03 commit 658a1a2

File tree

1 file changed

+40
-0
lines changed
  • dev/integration_tests/wide_gamut_test/integration_test

1 file changed

+40
-0
lines changed

dev/integration_tests/wide_gamut_test/integration_test/app_test.dart

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
import 'dart:math' as math;
56
import 'dart:typed_data';
67

78
import 'package:flutter/services.dart';
@@ -19,12 +20,49 @@ double _decodeBGR10(int x) {
1920
return (x * slope) + intercept;
2021
}
2122

23+
double _decodeHalf(int x) {
24+
if (x == 0x7c00) {
25+
return double.infinity;
26+
}
27+
if (x == 0xfc00) {
28+
return -double.infinity;
29+
}
30+
final double sign = x & 0x8000 == 0 ? 1.0 : -1.0;
31+
final int exponent = (x >> 10) & 0x1f;
32+
final int fraction = x & 0x3ff;
33+
if (exponent == 0) {
34+
return sign * math.pow(2.0, -14) * (fraction / 1024.0);
35+
} else {
36+
return sign * math.pow(2.0, exponent - 15) * (1.0 + fraction / 1024.0);
37+
}
38+
}
39+
2240
bool _isAlmost(double x, double y, double epsilon) {
2341
return (x - y).abs() < epsilon;
2442
}
2543

2644
List<double> _deepRed = <double>[1.0931, -0.2268, -0.1501];
2745

46+
bool _findRGBAF16Color(
47+
Uint8List bytes, int width, int height, List<double> color) {
48+
final ByteData byteData = ByteData.sublistView(bytes);
49+
expect(bytes.lengthInBytes, width * height * 8);
50+
expect(bytes.lengthInBytes, byteData.lengthInBytes);
51+
bool foundDeepRed = false;
52+
for (int i = 0; i < bytes.lengthInBytes; i += 8) {
53+
final int pixel = byteData.getUint64(i, Endian.host);
54+
final double blue = _decodeHalf((pixel >> 32) & 0xffff);
55+
final double green = _decodeHalf((pixel >> 16) & 0xffff);
56+
final double red = _decodeHalf((pixel >> 0) & 0xffff);
57+
if (_isAlmost(red, color[0], 0.01) &&
58+
_isAlmost(green, color[1], 0.01) &&
59+
_isAlmost(blue, color[2], 0.01)) {
60+
foundDeepRed = true;
61+
}
62+
}
63+
return foundDeepRed;
64+
}
65+
2866
bool _findBGRA10Color(
2967
Uint8List bytes, int width, int height, List<double> color) {
3068
final ByteData byteData = ByteData.sublistView(bytes);
@@ -75,6 +113,8 @@ bool _findColor(List<Object?> result, List<double> color) {
75113
return _findBGR10Color((result[3] as Uint8List?)!, width, height, color);
76114
} else if (format == 'MTLPixelFormatBGRA10_XR') {
77115
return _findBGRA10Color((result[3] as Uint8List?)!, width, height, color);
116+
} else if (format == 'MTLPixelFormatRGBA16Float') {
117+
return _findRGBAF16Color((result[3] as Uint8List?)!, width, height, color);
78118
} else {
79119
fail('Unsupported pixel format: $format');
80120
}

0 commit comments

Comments
 (0)