Fix wide gamut macos integration test (#184427)
Fixes https://github.com/flutter/flutter/issues/182589.
CI machines don't have physical monitors, and the default virtual screen
given by MacOS doesn't report wide gamut support. This caused the check
in
https://github.com/flutter/flutter/blob/413244e157d7713a37ebcd892630c5bd5f6d4d30/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterViewController.mm#L808
to downgrade the color mode for the tests to sRGB, even though the
hardware supports wide-gamut.
This change overrides `updateWideGamutForScreen` to always enable wide
gamut for this test in CI.
This change also updates .ci.yaml to ensure that this test runs on Apple
Silicon hardware
## Pre-launch Checklist
- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [AI contribution guidelines] and understand my
responsibilities, or I am not using AI tools.
- [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] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [x] All existing and new tests are passing.
diff --git a/.ci.yaml b/.ci.yaml
index cb3dd3a..51e49f1 100644
--- a/.ci.yaml
+++ b/.ci.yaml
@@ -5398,6 +5398,8 @@
tags: >
["devicelab", "hostonly", "mac"]
task_name: wide_gamut_macos
+ drone_dimensions:
+ - gpu=apple
- name: Mac_x64_ios hot_mode_dev_cycle_ios__benchmark
recipe: devicelab/devicelab_drone
diff --git a/dev/integration_tests/wide_gamut_test/macos/Runner/MainFlutterWindow.swift b/dev/integration_tests/wide_gamut_test/macos/Runner/MainFlutterWindow.swift
new file mode 100644
index 0000000..c51076d
--- /dev/null
+++ b/dev/integration_tests/wide_gamut_test/macos/Runner/MainFlutterWindow.swift
@@ -0,0 +1,45 @@
+// Copyright 2014 The Flutter Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+import Cocoa
+import FlutterMacOS
+import Foundation
+
+class WideGamutViewController: FlutterViewController {
+
+ // This intercepts the private engine method called during window moves/resizes.
+ // By overriding it, we stop the engine from checking the screen and disabling wide-gamut.
+ @objc(updateWideGamutForScreen)
+ func updateWideGamutForScreen() {
+ let flutterView = self.view
+ let mySelector = Selector("setEnableWideGamut:")
+
+ // 1. Check if the object actually has this method
+ if flutterView.responds(to: mySelector) {
+ // 2. Call the method using reflection.
+ flutterView.perform(mySelector, with: true)
+ }
+ }
+
+ override func viewWillAppear() {
+ super.viewWillAppear()
+ // Force the surface to 10-bit during the initial view loading sequence.
+ self.updateWideGamutForScreen()
+ }
+}
+
+class MainFlutterWindow: NSWindow {
+ override func awakeFromNib() {
+ // Instantiate our custom subclass instead of the standard FlutterViewController.
+ let flutterViewController = WideGamutViewController()
+
+ let windowFrame = self.frame
+ self.contentViewController = flutterViewController
+ self.setFrame(windowFrame, display: true)
+
+ RegisterGeneratedPlugins(registry: flutterViewController)
+
+ super.awakeFromNib()
+ }
+}