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

Commit 092710a

Browse files
authored
[Impeller] moved to bgra10_xr (#52019)
fixes flutter/flutter#145933 This required that we moved the golden image tests to arm64 since the wide gamut tests would now require BGRA10_XR and that's only available to arm64. tests: in framework repo https://github.com/flutter/flutter/tree/master/dev/integration_tests/wide_gamut_test. There was a test added to that suite specifically for this case when we turned off BGRA10_XR the first time. This has a dependency on #51998 which includes the necessary skia change. [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
1 parent 78e5d71 commit 092710a

File tree

10 files changed

+76
-34
lines changed

10 files changed

+76
-34
lines changed

ci/builders/mac_host_engine.json

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,6 @@
215215
"flutter/build/archives:archive_gen_snapshot",
216216
"flutter/build/archives:artifacts",
217217
"flutter/build/dart:copy_dart_sdk",
218-
"flutter/impeller/golden_tests:impeller_golden_tests",
219218
"flutter/shell/platform/darwin/macos:zip_macos_flutter_framework",
220219
"flutter/tools/font_subset",
221220
"flutter:unittests"
@@ -249,7 +248,7 @@
249248
"--variant",
250249
"ci/host_release",
251250
"--type",
252-
"dart,dart-host,engine,impeller-golden"
251+
"dart,dart-host,engine"
253252
]
254253
}
255254
]
@@ -405,7 +404,7 @@
405404
"drone_dimensions": [
406405
"device_type=none",
407406
"os=Mac-13",
408-
"cpu=x86"
407+
"cpu=arm64"
409408
],
410409
"gclient_variables": {
411410
"download_android_deps": false,
@@ -423,16 +422,21 @@
423422
"--prebuilt-dart-sdk",
424423
"--rbe",
425424
"--no-goma",
426-
"--xcode-symlinks"
425+
"--xcode-symlinks",
426+
"--use-glfw-swiftshader"
427427
],
428428
"name": "ci/mac_release_arm64",
429429
"description": "Produces release mode arm64 macOS host-side tooling.",
430430
"ninja": {
431431
"config": "ci/mac_release_arm64",
432432
"targets": [
433-
"flutter/tools/font_subset",
433+
"flutter:unittests",
434+
"flutter/build/archives:archive_gen_snapshot",
434435
"flutter/build/archives:artifacts",
435-
"flutter/shell/platform/darwin/macos:zip_macos_flutter_framework"
436+
"flutter/build/dart:copy_dart_sdk",
437+
"flutter/impeller/golden_tests:impeller_golden_tests",
438+
"flutter/shell/platform/darwin/macos:zip_macos_flutter_framework",
439+
"flutter/tools/font_subset"
436440
]
437441
},
438442
"postsubmit_overrides": {
@@ -454,7 +458,20 @@
454458
"$flutter/osx_sdk": {
455459
"sdk_version": "15a240d"
456460
}
457-
}
461+
},
462+
"tests": [
463+
{
464+
"language": "python3",
465+
"name": "Impeller-golden for host_release",
466+
"script": "flutter/testing/run_tests.py",
467+
"parameters": [
468+
"--variant",
469+
"ci/mac_release_arm64",
470+
"--type",
471+
"impeller-golden"
472+
]
473+
}
474+
]
458475
}
459476
],
460477
"generators": {

impeller/aiks/aiks_blend_unittests.cc

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,8 @@ TEST_P(AiksTest, PaintBlendModeIsRespected) {
132132

133133
// Bug: https://github.com/flutter/flutter/issues/142549
134134
TEST_P(AiksTest, BlendModePlusAlphaWideGamut) {
135-
if (GetParam() != PlaygroundBackend::kMetal) {
136-
GTEST_SKIP_("This backend doesn't yet support wide gamut.");
137-
}
138135
EXPECT_EQ(GetContext()->GetCapabilities()->GetDefaultColorFormat(),
139-
PixelFormat::kR16G16B16A16Float);
136+
PixelFormat::kB10G10R10A10XR);
140137
auto texture = CreateTextureForFixture("airplane.jpg",
141138
/*enable_mipmapping=*/true);
142139

@@ -158,11 +155,8 @@ TEST_P(AiksTest, BlendModePlusAlphaWideGamut) {
158155

159156
// Bug: https://github.com/flutter/flutter/issues/142549
160157
TEST_P(AiksTest, BlendModePlusAlphaColorFilterWideGamut) {
161-
if (GetParam() != PlaygroundBackend::kMetal) {
162-
GTEST_SKIP_("This backend doesn't yet support wide gamut.");
163-
}
164158
EXPECT_EQ(GetContext()->GetCapabilities()->GetDefaultColorFormat(),
165-
PixelFormat::kR16G16B16A16Float);
159+
PixelFormat::kB10G10R10A10XR);
166160
auto texture = CreateTextureForFixture("airplane.jpg",
167161
/*enable_mipmapping=*/true);
168162

impeller/aiks/aiks_unittests.cc

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -938,17 +938,14 @@ TEST_P(AiksTest, CanDrawPaintMultipleTimes) {
938938
}
939939

940940
// This makes sure the WideGamut named tests use 16bit float pixel format.
941-
TEST_P(AiksTest, F16WideGamut) {
942-
if (GetParam() != PlaygroundBackend::kMetal) {
943-
GTEST_SKIP_("This backend doesn't yet support wide gamut.");
944-
}
941+
TEST_P(AiksTest, FormatWideGamut) {
945942
EXPECT_EQ(GetContext()->GetCapabilities()->GetDefaultColorFormat(),
946-
PixelFormat::kR16G16B16A16Float);
947-
EXPECT_FALSE(IsAlphaClampedToOne(
943+
PixelFormat::kB10G10R10A10XR);
944+
EXPECT_TRUE(IsAlphaClampedToOne(
948945
GetContext()->GetCapabilities()->GetDefaultColorFormat()));
949946
}
950947

951-
TEST_P(AiksTest, NotF16) {
948+
TEST_P(AiksTest, FormatSRGB) {
952949
EXPECT_TRUE(IsAlphaClampedToOne(
953950
GetContext()->GetCapabilities()->GetDefaultColorFormat()));
954951
}
@@ -3107,12 +3104,8 @@ TEST_P(AiksTest, MipmapGenerationWorksCorrectly) {
31073104
}
31083105

31093106
TEST_P(AiksTest, DrawAtlasPlusWideGamut) {
3110-
if (GetParam() != PlaygroundBackend::kMetal) {
3111-
GTEST_SKIP_("This backend doesn't yet support wide gamut.");
3112-
}
3113-
31143107
EXPECT_EQ(GetContext()->GetCapabilities()->GetDefaultColorFormat(),
3115-
PixelFormat::kR16G16B16A16Float);
3108+
PixelFormat::kB10G10R10A10XR);
31163109

31173110
// Draws the image as four squares stiched together.
31183111
auto atlas =

impeller/golden_tests/golden_playground_test_mac.cc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,16 @@ void GoldenPlaygroundTest::TearDown() {
128128
ASSERT_FALSE(dlopen("/usr/local/lib/libMoltenVK.dylib", RTLD_NOLOAD));
129129
}
130130

131+
namespace {
132+
bool DoesSupportWideGamutTests() {
133+
#ifdef __arm64__
134+
return true;
135+
#else
136+
return false;
137+
#endif
138+
}
139+
} // namespace
140+
131141
void GoldenPlaygroundTest::SetUp() {
132142
std::filesystem::path testing_assets_path =
133143
flutter::testing::GetTestingAssetsPath();
@@ -142,17 +152,27 @@ void GoldenPlaygroundTest::SetUp() {
142152
bool enable_wide_gamut = test_name.find("WideGamut_") != std::string::npos;
143153
switch (GetParam()) {
144154
case PlaygroundBackend::kMetal:
155+
if (!DoesSupportWideGamutTests()) {
156+
GTEST_SKIP_(
157+
"This metal device doesn't support wide gamut golden tests.");
158+
}
145159
pimpl_->screenshotter =
146160
std::make_unique<testing::MetalScreenshotter>(enable_wide_gamut);
147161
break;
148162
case PlaygroundBackend::kVulkan: {
163+
if (enable_wide_gamut) {
164+
GTEST_SKIP_("Vulkan doesn't support wide gamut golden tests.");
165+
}
149166
const std::unique_ptr<PlaygroundImpl>& playground =
150167
GetSharedVulkanPlayground(/*enable_validations=*/true);
151168
pimpl_->screenshotter =
152169
std::make_unique<testing::VulkanScreenshotter>(playground);
153170
break;
154171
}
155172
case PlaygroundBackend::kOpenGLES: {
173+
if (enable_wide_gamut) {
174+
GTEST_SKIP_("OpenGLES doesn't support wide gamut golden tests.");
175+
}
156176
FML_CHECK(::glfwInit() == GLFW_TRUE);
157177
PlaygroundSwitches playground_switches;
158178
playground_switches.use_angle = true;

impeller/playground/backend/metal/playground_impl_mtl.mm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,12 @@
7373
if (!window) {
7474
return;
7575
}
76+
7677
auto context = ContextMTL::Create(
7778
ShaderLibraryMappingsForPlayground(), is_gpu_disabled_sync_switch_,
7879
"Playground Library",
7980
switches.enable_wide_gamut
80-
? std::optional<PixelFormat>(PixelFormat::kR16G16B16A16Float)
81+
? std::optional<PixelFormat>(PixelFormat::kB10G10R10A10XR)
8182
: std::nullopt);
8283
if (!context) {
8384
return;

impeller/playground/playground_test.cc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@ PlaygroundTest::PlaygroundTest()
1515

1616
PlaygroundTest::~PlaygroundTest() = default;
1717

18+
namespace {
19+
bool DoesSupportWideGamutTests() {
20+
#ifdef __arm64__
21+
return true;
22+
#else
23+
return false;
24+
#endif
25+
}
26+
} // namespace
27+
1828
void PlaygroundTest::SetUp() {
1929
if (!Playground::SupportsBackend(GetParam())) {
2030
GTEST_SKIP_("Playground doesn't support this backend type.");
@@ -34,6 +44,12 @@ void PlaygroundTest::SetUp() {
3444
switches.enable_wide_gamut =
3545
test_name.find("WideGamut/") != std::string::npos;
3646

47+
if (switches.enable_wide_gamut && (GetParam() != PlaygroundBackend::kMetal ||
48+
!DoesSupportWideGamutTests())) {
49+
GTEST_SKIP_("This backend doesn't yet support wide gamut.");
50+
return;
51+
}
52+
3753
SetupContext(GetParam(), switches);
3854
SetupWindow();
3955
}

lib/ui/painting/image_encoding_impeller.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ std::optional<SkColorType> ToSkColorType(impeller::PixelFormat format) {
2525
return SkColorType::kBGRA_8888_SkColorType;
2626
case impeller::PixelFormat::kB10G10R10XR:
2727
return SkColorType::kBGR_101010x_XR_SkColorType;
28+
case impeller::PixelFormat::kB10G10R10A10XR:
29+
return SkColorType::kBGRA_10101010_XR_SkColorType;
2830
default:
2931
return std::nullopt;
3032
}

shell/platform/darwin/ios/framework/Source/FlutterMetalLayer.mm

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,9 @@ - (IOSurface*)createIOSurface {
259259
} else if (self.pixelFormat == MTLPixelFormatBGRA8Unorm) {
260260
pixelFormat = kCVPixelFormatType_32BGRA;
261261
bytesPerElement = 4;
262+
} else if (self.pixelFormat == MTLPixelFormatBGRA10_XR) {
263+
pixelFormat = kCVPixelFormatType_40ARGBLEWideGamut;
264+
bytesPerElement = 8;
262265
} else {
263266
FML_LOG(ERROR) << "Unsupported pixel format: " << self.pixelFormat;
264267
return nil;

shell/platform/darwin/ios/framework/Source/FlutterOverlayView.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ - (instancetype)initWithContentsScale:(CGFloat)contentsScale
5959
CAMetalLayer* layer = (CAMetalLayer*)self.layer;
6060
#pragma clang diagnostic pop
6161
layer.pixelFormat = pixelFormat;
62-
if (pixelFormat == MTLPixelFormatRGBA16Float) {
62+
if (pixelFormat == MTLPixelFormatRGBA16Float || pixelFormat == MTLPixelFormatBGRA10_XR) {
6363
self->_colorSpaceRef = fml::CFRef(CGColorSpaceCreateWithName(kCGColorSpaceExtendedSRGB));
6464
layer.colorspace = self->_colorSpaceRef;
6565
}

shell/platform/darwin/ios/framework/Source/FlutterView.mm

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,7 @@ - (void)layoutSubviews {
122122
CGColorSpaceRef srgb = CGColorSpaceCreateWithName(kCGColorSpaceExtendedSRGB);
123123
layer.colorspace = srgb;
124124
CFRelease(srgb);
125-
// MTLPixelFormatRGBA16Float was chosen since it is compatible with
126-
// impeller's offscreen buffers which need to have transparency. Also,
127-
// F16 was chosen over BGRA10_XR since Skia does not support decoding
128-
// BGRA10_XR.
129-
layer.pixelFormat = MTLPixelFormatRGBA16Float;
125+
layer.pixelFormat = MTLPixelFormatBGRA10_XR;
130126
} else if (_isWideGamutEnabled && !isWideGamutSupported) {
131127
PrintWideGamutWarningOnce();
132128
}

0 commit comments

Comments
 (0)