diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/tests/integration/embedder/BUILD.gn b/engine/src/flutter/shell/platform/fuchsia/flutter/tests/integration/embedder/BUILD.gn index 392a271be8..9b60781b57 100644 --- a/engine/src/flutter/shell/platform/fuchsia/flutter/tests/integration/embedder/BUILD.gn +++ b/engine/src/flutter/shell/platform/fuchsia/flutter/tests/integration/embedder/BUILD.gn @@ -27,6 +27,7 @@ executable("flutter-embedder-test-bin") { "$fuchsia_sdk_root/fidl:fuchsia.tracing.provider", "$fuchsia_sdk_root/fidl:fuchsia.ui.app", "$fuchsia_sdk_root/fidl:fuchsia.ui.composition", + "$fuchsia_sdk_root/fidl:fuchsia.ui.display.singleton", "$fuchsia_sdk_root/fidl:fuchsia.ui.observation.geometry", "$fuchsia_sdk_root/fidl:fuchsia.ui.scenic", "$fuchsia_sdk_root/fidl:fuchsia.ui.test.input", @@ -39,7 +40,6 @@ executable("flutter-embedder-test-bin") { "$fuchsia_sdk_root/pkg:zx", "//flutter/fml", "//flutter/shell/platform/fuchsia/flutter/tests/integration/utils:check_view", - "//flutter/shell/platform/fuchsia/flutter/tests/integration/utils:color", "//flutter/shell/platform/fuchsia/flutter/tests/integration/utils:screenshot", "//third_party/googletest:gtest", "//third_party/googletest:gtest_main", diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/tests/integration/embedder/flutter-embedder-test.cc b/engine/src/flutter/shell/platform/fuchsia/flutter/tests/integration/embedder/flutter-embedder-test.cc index 02b8da8c05..6135912ed3 100644 --- a/engine/src/flutter/shell/platform/fuchsia/flutter/tests/integration/embedder/flutter-embedder-test.cc +++ b/engine/src/flutter/shell/platform/fuchsia/flutter/tests/integration/embedder/flutter-embedder-test.cc @@ -6,8 +6,8 @@ #include #include #include +#include #include -#include #include #include #include @@ -15,7 +15,6 @@ #include #include #include -#include #include #include #include @@ -27,7 +26,6 @@ #include "gtest/gtest.h" #include "flutter/shell/platform/fuchsia/flutter/tests/integration/utils/check_view.h" -#include "flutter/shell/platform/fuchsia/flutter/tests/integration/utils/color.h" #include "flutter/shell/platform/fuchsia/flutter/tests/integration/utils/screenshot.h" namespace flutter_embedder_test { @@ -66,7 +64,8 @@ constexpr char kChildViewUrl[] = constexpr char kParentViewUrl[] = "fuchsia-pkg://fuchsia.com/parent-view#meta/parent-view.cm"; static constexpr auto kTestUiStackUrl = - "fuchsia-pkg://fuchsia.com/test-ui-stack#meta/test-ui-stack.cm"; + "fuchsia-pkg://fuchsia.com/flatland-scene-manager-test-ui-stack#meta/" + "test-ui-stack.cm"; constexpr auto kFlutterRunnerEnvironment = "flutter_runner_env"; constexpr auto kFlutterJitRunner = "flutter_jit_runner"; @@ -84,36 +83,26 @@ constexpr auto kParentViewRef = ChildRef{kParentView}; constexpr auto kTestUiStack = "ui"; constexpr auto kTestUiStackRef = ChildRef{kTestUiStack}; -constexpr fuchsia_test_utils::Color kParentBackgroundColor = {0x00, 0x00, 0xFF, - 0xFF}; // Blue -constexpr fuchsia_test_utils::Color kChildBackgroundColor = {0xFF, 0x00, 0xFF, - 0xFF}; // Pink +// Background and foreground color values. +const fuchsia_test_utils::Pixel kParentBackgroundColor(0xFF, + 0x00, + 0x00, + 0xFF); // Blue +const fuchsia_test_utils::Pixel kChildBackgroundColor(0xFF, + 0x00, + 0xFF, + 0xFF); // Pink +const fuchsia_test_utils::Pixel kFlatlandOverlayColor(0x00, + 0xFF, + 0x00, + 0xFF); // Green -// TODO(fxb/64201): Remove forced opacity colors when Flatland is enabled. -constexpr fuchsia_test_utils::Color kOverlayBackgroundColor1 = { - 0x00, 0xFF, 0x0E, 0xFF}; // Green, blended with blue (FEMU local) -constexpr fuchsia_test_utils::Color kOverlayBackgroundColor2 = { - 0x0E, 0xFF, 0x0E, 0xFF}; // Green, blended with pink (FEMU local) -constexpr fuchsia_test_utils::Color kOverlayBackgroundColor3 = { - 0x00, 0xFF, 0x0D, 0xFF}; // Green, blended with blue (AEMU infra) -constexpr fuchsia_test_utils::Color kOverlayBackgroundColor4 = { - 0x0D, 0xFF, 0x0D, 0xFF}; // Green, blended with pink (AEMU infra) -constexpr fuchsia_test_utils::Color kOverlayBackgroundColor5 = { - 0x00, 0xFE, 0x0D, 0xFF}; // Green, blended with blue (NUC) -constexpr fuchsia_test_utils::Color kOverlayBackgroundColor6 = { - 0x0D, 0xFF, 0x00, 0xFF}; // Green, blended with pink (NUC) - -static size_t OverlayPixelCount( - std::map& histogram) { - return histogram[kOverlayBackgroundColor1] + - histogram[kOverlayBackgroundColor2] + - histogram[kOverlayBackgroundColor3] + - histogram[kOverlayBackgroundColor4] + - histogram[kOverlayBackgroundColor5] + - histogram[kOverlayBackgroundColor6]; +static uint32_t OverlayPixelCount( + std::map& histogram) { + return histogram[kFlatlandOverlayColor]; } -// Timeout for Scenic's |TakeScreenshot| FIDL call. +// Timeout for |TakeScreenshot| FIDL call. constexpr zx::duration kScreenshotTimeout = zx::sec(10); // Timeout to fail the test if it goes beyond this duration. constexpr zx::duration kTestTimeout = zx::min(1); @@ -151,23 +140,24 @@ class FlutterEmbedderTest : public ::loop_fixture::RealLoop, fuchsia_test_utils::Screenshot TakeScreenshot(); bool TakeScreenshotUntil( - fuchsia_test_utils::Color color, - fit::function)> + fuchsia_test_utils::Pixel color, + fit::function)> callback = nullptr, zx::duration timeout = kTestTimeout); private: - fuchsia::ui::scenic::Scenic* scenic() { return scenic_.get(); } - void SetUpRealmBase(); - fuchsia::ui::scenic::ScenicPtr scenic_; fuchsia::ui::test::scene::ControllerPtr scene_provider_; fuchsia::ui::observation::geometry::ViewTreeWatcherPtr view_tree_watcher_; + fuchsia::ui::composition::ScreenshotPtr screenshot_; // Wrapped in optional since the view is not created until the middle of SetUp component_testing::RealmBuilder realm_builder_; std::unique_ptr realm_; + + uint64_t display_width_ = 0; + uint64_t display_height_ = 0; }; void FlutterEmbedderTest::SetUpRealmBase() { @@ -261,19 +251,20 @@ void FlutterEmbedderTest::SetUpRealmBase() { // Route UI capabilities from test UI stack to flutter runners. realm_builder_.AddRoute(Route{ - .capabilities = {Protocol{fuchsia::ui::composition::Flatland::Name_}, - Protocol{fuchsia::ui::scenic::Scenic::Name_}}, + .capabilities = {Protocol{fuchsia::ui::composition::Allocator::Name_}, + Protocol{fuchsia::ui::composition::Flatland::Name_}}, .source = kTestUiStackRef, .targets = {kFlutterJitRunnerRef, kFlutterJitProductRunnerRef, kFlutterAotRunnerRef, kFlutterAotProductRunnerRef}}); // Route test capabilities from test UI stack to test driver. realm_builder_.AddRoute(Route{ - .capabilities = {Protocol{fuchsia::ui::test::input::Registry::Name_}, + .capabilities = {Protocol{fuchsia::ui::composition::Screenshot::Name_}, + Protocol{fuchsia::ui::test::input::Registry::Name_}, Protocol{fuchsia::ui::test::scene::Controller::Name_}, - Protocol{fuchsia::ui::scenic::Scenic::Name_}}, + Protocol{fuchsia::ui::display::singleton::Info::Name_}}, .source = kTestUiStackRef, - .targets = {ParentRef{}}}); + .targets = {ParentRef()}}); // Route ViewProvider from child to parent, and parent to test. realm_builder_.AddRoute( @@ -328,6 +319,21 @@ void FlutterEmbedderTest::LaunchParentViewInRealm( } realm_ = std::make_unique(realm_builder_.Build()); + // Get the display information using the |fuchsia.ui.display.singleton.Info|. + std::optional display_metrics_obtained; + fuchsia::ui::display::singleton::InfoPtr display_info = + realm_->component().Connect(); + display_info->GetMetrics([this, &display_metrics_obtained](auto info) { + display_width_ = info.extent_in_px().width; + display_height_ = info.extent_in_px().height; + display_metrics_obtained = true; + }); + RunLoopUntil([&display_metrics_obtained] { + return display_metrics_obtained.has_value(); + }); + FML_LOG(INFO) << "Got display_width " << display_width_ << " display_height " + << display_height_; + // Instruct Test UI Stack to present parent-view's View. std::optional view_ref_koid; scene_provider_ = @@ -357,30 +363,34 @@ void FlutterEmbedderTest::LaunchParentViewInRealm( }); FML_LOG(INFO) << "Client view has rendered"; - scenic_ = realm_->component().Connect(); + screenshot_ = + realm_->component().Connect(); FML_LOG(INFO) << "Launched parent-view"; } fuchsia_test_utils::Screenshot FlutterEmbedderTest::TakeScreenshot() { FML_LOG(INFO) << "Taking screenshot... "; - fuchsia::ui::scenic::ScreenshotData screenshot_out; - scenic_->TakeScreenshot( - [this, &screenshot_out](fuchsia::ui::scenic::ScreenshotData screenshot, - bool status) { - EXPECT_TRUE(status) << "Failed to take screenshot"; - screenshot_out = std::move(screenshot); - QuitLoop(); - }); + + fuchsia::ui::composition::ScreenshotTakeRequest request; + request.set_format(fuchsia::ui::composition::ScreenshotFormat::BGRA_RAW); + + std::optional response; + screenshot_->Take(std::move(request), [this, &response](auto screenshot) { + response = std::move(screenshot); + QuitLoop(); + }); + EXPECT_FALSE(RunLoopWithTimeout(kScreenshotTimeout)) << "Timed out waiting for screenshot."; FML_LOG(INFO) << "Screenshot captured."; - return fuchsia_test_utils::Screenshot(screenshot_out); + return fuchsia_test_utils::Screenshot( + response->vmo(), display_width_, display_height_, /*display_rotation*/ 0); } bool FlutterEmbedderTest::TakeScreenshotUntil( - fuchsia_test_utils::Color color, - fit::function)> callback, + fuchsia_test_utils::Pixel color, + fit::function)> callback, zx::duration timeout) { return RunLoopWithTimeoutOrUntil( [this, &callback, &color] { @@ -402,7 +412,7 @@ TEST_F(FlutterEmbedderTest, Embedding) { // Take screenshot until we see the child-view's embedded color. ASSERT_TRUE(TakeScreenshotUntil( kChildBackgroundColor, - [](std::map histogram) { + [](std::map histogram) { // Expect parent and child background colors, with parent color > child // color. EXPECT_GT(histogram[kParentBackgroundColor], 0u); @@ -418,10 +428,10 @@ TEST_F(FlutterEmbedderTest, EmbeddingWithOverlay) { // Take screenshot until we see the child-view's embedded color. ASSERT_TRUE(TakeScreenshotUntil( kChildBackgroundColor, - [](std::map histogram) { + [](std::map histogram) { // Expect parent, overlay and child background colors. // With parent color > child color and overlay color > child color. - const size_t overlay_pixel_count = OverlayPixelCount(histogram); + const uint32_t overlay_pixel_count = OverlayPixelCount(histogram); EXPECT_GT(histogram[kParentBackgroundColor], 0u); EXPECT_GT(overlay_pixel_count, 0u); EXPECT_GT(histogram[kChildBackgroundColor], 0u); diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/tests/integration/embedder/meta/flutter-embedder-test.cml b/engine/src/flutter/shell/platform/fuchsia/flutter/tests/integration/embedder/meta/flutter-embedder-test.cml index 8ff1e67899..e0f267a348 100644 --- a/engine/src/flutter/shell/platform/fuchsia/flutter/tests/integration/embedder/meta/flutter-embedder-test.cml +++ b/engine/src/flutter/shell/platform/fuchsia/flutter/tests/integration/embedder/meta/flutter-embedder-test.cml @@ -32,6 +32,7 @@ "fuchsia.test": { "deprecated-allowed-packages": [ "child-view", + "flatland-scene-manager-test-ui-stack", "oot_flutter_aot_runner", "oot_flutter_jit_runner", "oot_flutter_jit_product_runner", diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/tests/integration/embedder/parent-view/lib/parent_view.dart b/engine/src/flutter/shell/platform/fuchsia/flutter/tests/integration/embedder/parent-view/lib/parent_view.dart index e94bab84a2..8cb272e34d 100644 --- a/engine/src/flutter/shell/platform/fuchsia/flutter/tests/integration/embedder/parent-view/lib/parent_view.dart +++ b/engine/src/flutter/shell/platform/fuchsia/flutter/tests/integration/embedder/parent-view/lib/parent_view.dart @@ -19,20 +19,16 @@ void main(List args) async { args = args + _GetArgsFromConfigFile(); final parser = ArgParser() ..addFlag('showOverlay', defaultsTo: false) - ..addFlag('hitTestable', defaultsTo: true) - ..addFlag('focusable', defaultsTo: true) - ..addFlag('useFlatland', defaultsTo: false); + ..addFlag('focusable', defaultsTo: true); final arguments = parser.parse(args); for (final option in arguments.options) { print('parent-view: $option: ${arguments[option]}'); } TestApp app; - final useFlatland = arguments['useFlatland']; app = TestApp( - ChildView(await _launchChildView(useFlatland)), + ChildView(await _launchChildView()), showOverlay: arguments['showOverlay'], - hitTestable: arguments['hitTestable'], focusable: arguments['focusable'], ); @@ -45,18 +41,16 @@ class TestApp { final ChildView childView; final bool showOverlay; - final bool hitTestable; final bool focusable; Color _backgroundColor = _blue; TestApp(this.childView, {this.showOverlay = false, - this.hitTestable = true, this.focusable = true}) {} void run() { - childView.create(hitTestable, focusable, (ByteData reply) { + childView.create(focusable, (ByteData reply) { // Set up window allbacks. window.onPointerDataPacket = (PointerDataPacket packet) { for (final data in packet.data) { @@ -150,7 +144,7 @@ class ChildView { ChildView(this.viewId); - void create(bool hitTestable, bool focusable, + void create(bool focusable, PlatformMessageResponseCallback callback) { // Construct the dart:ui platform message to create the view, and when the // return callback is invoked, build the scene. At that point, it is safe @@ -159,7 +153,8 @@ class ChildView { final Map args = { 'viewId': viewId, - 'hitTestable': hitTestable, + // Flatland doesn't support disabling hit testing. + 'hitTestable': true, 'focusable': focusable, 'viewOcclusionHintLTRB': [ viewOcclusionHint.left, @@ -182,8 +177,8 @@ class ChildView { } } -Future _launchChildView(bool useFlatland) async { - final message = Int8List.fromList([useFlatland ? 0x31 : 0x30]); +Future _launchChildView() async { + final message = Int8List.fromList([0x31]); final completer = new Completer(); PlatformDispatcher.instance.sendPlatformMessage( 'fuchsia/child_view', ByteData.sublistView(message), (ByteData reply) { diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/tests/integration/text-input/BUILD.gn b/engine/src/flutter/shell/platform/fuchsia/flutter/tests/integration/text-input/BUILD.gn index b45ea72458..266cb8cd83 100644 --- a/engine/src/flutter/shell/platform/fuchsia/flutter/tests/integration/text-input/BUILD.gn +++ b/engine/src/flutter/shell/platform/fuchsia/flutter/tests/integration/text-input/BUILD.gn @@ -44,9 +44,7 @@ executable("text-input-test-bin") { "//build/fuchsia/fidl:fuchsia.ui.gfx", "//flutter/fml", "//flutter/shell/platform/fuchsia/flutter/tests/integration/utils:check_view", - "//flutter/shell/platform/fuchsia/flutter/tests/integration/utils:color", "//flutter/shell/platform/fuchsia/flutter/tests/integration/utils:portable_ui_test", - "//flutter/shell/platform/fuchsia/flutter/tests/integration/utils:screenshot", "//third_party/googletest:gtest", "//third_party/googletest:gtest_main", ] diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/tests/integration/touch-input/BUILD.gn b/engine/src/flutter/shell/platform/fuchsia/flutter/tests/integration/touch-input/BUILD.gn index 051fc40bbf..03a92db6e3 100644 --- a/engine/src/flutter/shell/platform/fuchsia/flutter/tests/integration/touch-input/BUILD.gn +++ b/engine/src/flutter/shell/platform/fuchsia/flutter/tests/integration/touch-input/BUILD.gn @@ -33,6 +33,7 @@ executable("touch-input-test-bin") { "$fuchsia_sdk_root/fidl:fuchsia.net.interfaces", "$fuchsia_sdk_root/fidl:fuchsia.tracing.provider", "$fuchsia_sdk_root/fidl:fuchsia.ui.app", + "$fuchsia_sdk_root/fidl:fuchsia.ui.display.singleton", "$fuchsia_sdk_root/fidl:fuchsia.ui.input", "$fuchsia_sdk_root/fidl:fuchsia.ui.pointerinjector", "$fuchsia_sdk_root/fidl:fuchsia.ui.policy", diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/tests/integration/touch-input/embedding-flutter-view/lib/embedding-flutter-view.dart b/engine/src/flutter/shell/platform/fuchsia/flutter/tests/integration/touch-input/embedding-flutter-view/lib/embedding-flutter-view.dart index 732e422421..4f36134278 100644 --- a/engine/src/flutter/shell/platform/fuchsia/flutter/tests/integration/touch-input/embedding-flutter-view/lib/embedding-flutter-view.dart +++ b/engine/src/flutter/shell/platform/fuchsia/flutter/tests/integration/touch-input/embedding-flutter-view/lib/embedding-flutter-view.dart @@ -20,7 +20,6 @@ void main(List args) async { args = args + _GetArgsFromConfigFile(); final parser = ArgParser() ..addFlag('showOverlay', defaultsTo: false) - ..addFlag('hitTestable', defaultsTo: true) ..addFlag('focusable', defaultsTo: true); final arguments = parser.parse(args); @@ -28,11 +27,9 @@ void main(List args) async { print('embedding-flutter-view args: $option: ${arguments[option]}'); } - // TODO(fxbug.dev/125514): Support Flatland Child View. TestApp app = TestApp( - ChildView(await _launchChildView(false)), + ChildView(await _launchChildView()), showOverlay: arguments['showOverlay'], - hitTestable: arguments['hitTestable'], focusable: arguments['focusable'], ); @@ -45,7 +42,6 @@ class TestApp { final ChildView childView; final bool showOverlay; - final bool hitTestable; final bool focusable; Color _backgroundColor = _blue; @@ -53,12 +49,11 @@ class TestApp { TestApp( this.childView, {this.showOverlay = false, - this.hitTestable = true, this.focusable = true}) { } void run() { - childView.create(hitTestable, focusable, (ByteData reply) { + childView.create(focusable, (ByteData reply) { // Set up window callbacks. window.onPointerDataPacket = (PointerDataPacket packet) { this.pointerDataPacket(packet); @@ -185,7 +180,6 @@ class ChildView { ChildView(this.viewId); void create( - bool hitTestable, bool focusable, PlatformMessageResponseCallback callback) { // Construct the dart:ui platform message to create the view, and when the @@ -194,7 +188,8 @@ class ChildView { final viewOcclusionHint = Rect.zero; final Map args = { 'viewId': viewId, - 'hitTestable': hitTestable, + // Flatland doesn't support disabling hit testing. + 'hitTestable': true, 'focusable': focusable, 'viewOcclusionHintLTRB': [ viewOcclusionHint.left, @@ -220,8 +215,8 @@ class ChildView { } } -Future _launchChildView(bool useFlatland) async { - final message = Int8List.fromList([useFlatland ? 0x31 : 0x30]); +Future _launchChildView() async { + final message = Int8List.fromList([0x31]); final completer = new Completer(); PlatformDispatcher.instance.sendPlatformMessage( 'fuchsia/child_view', ByteData.sublistView(message), (ByteData reply) { diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/tests/integration/touch-input/meta/touch-input-test.cml b/engine/src/flutter/shell/platform/fuchsia/flutter/tests/integration/touch-input/meta/touch-input-test.cml index a5a34384e0..613142eae2 100644 --- a/engine/src/flutter/shell/platform/fuchsia/flutter/tests/integration/touch-input/meta/touch-input-test.cml +++ b/engine/src/flutter/shell/platform/fuchsia/flutter/tests/integration/touch-input/meta/touch-input-test.cml @@ -55,7 +55,6 @@ "fuchsia.test": { "deprecated-allowed-packages": [ "embedding-flutter-view", - "gfx-scene-manager-test-ui-stack", "flatland-scene-manager-test-ui-stack", "oot_flutter_aot_runner", "oot_flutter_jit_runner", diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/tests/integration/touch-input/touch-input-test.cc b/engine/src/flutter/shell/platform/fuchsia/flutter/tests/integration/touch-input/touch-input-test.cc index d9c1f430cf..c2f27251c9 100644 --- a/engine/src/flutter/shell/platform/fuchsia/flutter/tests/integration/touch-input/touch-input-test.cc +++ b/engine/src/flutter/shell/platform/fuchsia/flutter/tests/integration/touch-input/touch-input-test.cc @@ -14,9 +14,9 @@ #include #include #include +#include #include #include -#include #include #include #include @@ -26,9 +26,6 @@ #include #include #include -#include -#include -#include #include #include #include @@ -127,9 +124,6 @@ using RealmBuilder = component_testing::RealmBuilder; // Set this as low as you can that still works across all test platforms. constexpr zx::duration kTimeout = zx::min(1); -constexpr auto kGfxTestUIStackUrl = - "fuchsia-pkg://fuchsia.com/gfx-scene-manager-test-ui-stack#meta/" - "test-ui-stack.cm"; constexpr auto kTestUIStackUrl = "fuchsia-pkg://fuchsia.com/flatland-scene-manager-test-ui-stack#meta/" "test-ui-stack.cm"; @@ -205,9 +199,7 @@ class TouchInputListenerServer events_received_; }; -class FlutterTapTestBase : public PortableUITest, - public ::testing::Test, - public ::testing::WithParamInterface { +class FlutterTapTestBase : public PortableUITest, public ::testing::Test { protected: ~FlutterTapTestBase() override { FML_CHECK(touch_injection_request_count() > 0) @@ -226,17 +218,22 @@ class FlutterTapTestBase : public PortableUITest, }, kTimeout); - // Get the display dimensions. + // Get the display information using the + // |fuchsia.ui.display.singleton.Info|. FML_LOG(INFO) << "Waiting for scenic display info"; - scenic_ = realm_root()->component().Connect(); - scenic_->GetDisplayInfo([this](fuchsia::ui::gfx::DisplayInfo display_info) { - display_width_ = display_info.width_in_px; - display_height_ = display_info.height_in_px; - FML_LOG(INFO) << "Got display_width = " << display_width_ - << " and display_height = " << display_height_; + std::optional display_metrics_obtained; + fuchsia::ui::display::singleton::InfoPtr display_info = + realm_root() + ->component() + .Connect(); + display_info->GetMetrics([this, &display_metrics_obtained](auto info) { + display_width_ = info.extent_in_px().width; + display_height_ = info.extent_in_px().height; + display_metrics_obtained = true; + }); + RunLoopUntil([&display_metrics_obtained] { + return display_metrics_obtained.has_value(); }); - RunLoopUntil( - [this] { return display_width_ != 0 && display_height_ != 0; }); // Register input injection device. FML_LOG(INFO) << "Registering input injection device"; @@ -287,7 +284,7 @@ class FlutterTapTestBase : public PortableUITest, uint32_t display_width() const { return display_width_; } uint32_t display_height() const { return display_height_; } - ParamType GetTestUIStackUrl() override { return GetParam(); }; + std::string GetTestUIStackUrl() override { return kTestUIStackUrl; }; TouchInputListenerServer* touch_input_listener_server_; }; @@ -345,17 +342,22 @@ class FlutterEmbedTapTest : public FlutterTapTestBase { void LaunchClientWithEmbeddedView() { BuildRealm(); - // Get the display dimensions. + // Get the display information using the + // |fuchsia.ui.display.singleton.Info|. FML_LOG(INFO) << "Waiting for scenic display info"; - scenic_ = realm_root()->component().Connect(); - scenic_->GetDisplayInfo([this](fuchsia::ui::gfx::DisplayInfo display_info) { - display_width_ = display_info.width_in_px; - display_height_ = display_info.height_in_px; - FML_LOG(INFO) << "Got display_width = " << display_width_ - << " and display_height = " << display_height_; + std::optional display_metrics_obtained; + fuchsia::ui::display::singleton::InfoPtr display_info = + realm_root() + ->component() + .Connect(); + display_info->GetMetrics([this, &display_metrics_obtained](auto info) { + display_width_ = info.extent_in_px().width; + display_height_ = info.extent_in_px().height; + display_metrics_obtained = true; + }); + RunLoopUntil([&display_metrics_obtained] { + return display_metrics_obtained.has_value(); }); - RunLoopUntil( - [this] { return display_width_ != 0 && display_height_ != 0; }); // Register input injection device. FML_LOG(INFO) << "Registering input injection device"; @@ -424,16 +426,7 @@ class FlutterEmbedTapTest : public FlutterTapTestBase { } }; -// Makes use of gtest's parameterized testing, allowing us -// to test different combinations of test-ui-stack + runners. Currently, there -// are both GFX and Flatland variants. Documentation: -// http://go/gunitadvanced#value-parameterized-tests -INSTANTIATE_TEST_SUITE_P(FlutterTapTestParameterized, - FlutterTapTest, - ::testing::Values(kGfxTestUIStackUrl, - kTestUIStackUrl)); - -TEST_P(FlutterTapTest, FlutterTap) { +TEST_F(FlutterTapTest, FlutterTap) { // Launch client view, and wait until it's rendering to proceed with the test. FML_LOG(INFO) << "Initializing scene"; LaunchClient(); @@ -457,13 +450,7 @@ TEST_P(FlutterTapTest, FlutterTap) { ASSERT_EQ(touch_injection_request_count(), 1); } -// TODO(fxbug.dev/125514): Embedded Child View needs to support Flatland. -// Only test GFX Test UI stack for embedded test cases for now. -INSTANTIATE_TEST_SUITE_P(FlutterEmbedTapTestParameterized, - FlutterEmbedTapTest, - ::testing::Values(kGfxTestUIStackUrl)); - -TEST_P(FlutterEmbedTapTest, FlutterEmbedTap) { +TEST_F(FlutterEmbedTapTest, FlutterEmbedTap) { // Launch view FML_LOG(INFO) << "Initializing scene"; LaunchClientWithEmbeddedView(); @@ -497,29 +484,7 @@ TEST_P(FlutterEmbedTapTest, FlutterEmbedTap) { ASSERT_EQ(touch_injection_request_count(), 2); } -TEST_P(FlutterEmbedTapTest, FlutterEmbedHittestDisabled) { - FML_LOG(INFO) << "Initializing scene"; - AddComponentArgument("--no-hitTestable"); - LaunchClientWithEmbeddedView(); - FML_LOG(INFO) << "Client launched"; - - // Embedded child view takes up the center of the screen - // hitTestable is turned off for the embedded child view - // Expect the parent (embedding-flutter-view) to respond if we inject a tap - // there - InjectTap(0, 0); - RunLoopUntil([this] { - return LastEventReceivedMatches( - /*expected_x=*/static_cast(display_width() / 2.0f), - /*expected_y=*/static_cast(display_height() / 2.0f), - /*component_name=*/"embedding-flutter-view"); - }); - - // There should be 1 injected tap - ASSERT_EQ(touch_injection_request_count(), 1); -} - -TEST_P(FlutterEmbedTapTest, FlutterEmbedOverlayEnabled) { +TEST_F(FlutterEmbedTapTest, FlutterEmbedOverlayEnabled) { FML_LOG(INFO) << "Initializing scene"; AddComponentArgument("--showOverlay"); LaunchClientWithEmbeddedView(); diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/tests/integration/utils/BUILD.gn b/engine/src/flutter/shell/platform/fuchsia/flutter/tests/integration/utils/BUILD.gn index dd4ae203bf..f72e9ffcd6 100644 --- a/engine/src/flutter/shell/platform/fuchsia/flutter/tests/integration/utils/BUILD.gn +++ b/engine/src/flutter/shell/platform/fuchsia/flutter/tests/integration/utils/BUILD.gn @@ -19,13 +19,6 @@ source_set("check_view") { ] } -source_set("color") { - sources = [ - "color.cc", - "color.h", - ] -} - source_set("screenshot") { sources = [ "screenshot.cc", @@ -33,9 +26,7 @@ source_set("screenshot") { ] deps = [ - ":color", "$fuchsia_sdk_root/fidl:fuchsia.logger", - "$fuchsia_sdk_root/fidl:fuchsia.ui.scenic", "$fuchsia_sdk_root/pkg:zx", "//flutter/fml", ] @@ -50,7 +41,9 @@ source_set("portable_ui_test") { deps = [ ":check_view", + "$fuchsia_sdk_root/fidl:fuchsia.logger", "$fuchsia_sdk_root/fidl:fuchsia.ui.app", + "$fuchsia_sdk_root/fidl:fuchsia.ui.display.singleton", "$fuchsia_sdk_root/fidl:fuchsia.ui.input", "$fuchsia_sdk_root/fidl:fuchsia.ui.observation.geometry", "$fuchsia_sdk_root/fidl:fuchsia.ui.policy", diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/tests/integration/utils/color.cc b/engine/src/flutter/shell/platform/fuchsia/flutter/tests/integration/utils/color.cc deleted file mode 100644 index 818c4c8cc6..0000000000 --- a/engine/src/flutter/shell/platform/fuchsia/flutter/tests/integration/utils/color.cc +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2013 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. - -#include "color.h" - -namespace fuchsia_test_utils { - -// RGBA hex dump -std::ostream& operator<<(std::ostream& os, const Color& c) { - char rgba[9] = {}; - snprintf(rgba, (sizeof(rgba) / sizeof(char)), "%02X%02X%02X%02X", c.r, c.g, - c.b, c.a); - return os << rgba; -} - -} // namespace fuchsia_test_utils diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/tests/integration/utils/color.h b/engine/src/flutter/shell/platform/fuchsia/flutter/tests/integration/utils/color.h deleted file mode 100644 index 4cb1c328fe..0000000000 --- a/engine/src/flutter/shell/platform/fuchsia/flutter/tests/integration/utils/color.h +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2013 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. - -#ifndef FLUTTER_SHELL_PLATFORM_FUCHSIA_FLUTTER_TESTS_INTEGRATION_UTILS_COLOR_H_ -#define FLUTTER_SHELL_PLATFORM_FUCHSIA_FLUTTER_TESTS_INTEGRATION_UTILS_COLOR_H_ - -#include -#include -#include - -namespace fuchsia_test_utils { - -struct Color { - // Constructor is idiomatic RGBA, but memory layout is native BGRA. - constexpr Color(uint8_t r, uint8_t g, uint8_t b, uint8_t a) - : b(b), g(g), r(r), a(a) {} - - uint8_t b; - uint8_t g; - uint8_t r; - uint8_t a; -}; - -inline bool operator==(const Color& a, const Color& b) { - return a.r == b.r && a.g == b.g && a.b == b.b && a.a == b.a; -} - -inline bool operator<(const Color& a, const Color& b) { - return std::tie(a.r, a.g, a.b, a.a) < std::tie(b.r, b.g, b.b, b.a); -} - -// RGBA hex dump. Note that this differs from the internal BGRA memory layout. -std::ostream& operator<<(std::ostream& os, const Color& c); - -} // namespace fuchsia_test_utils - -#endif // FLUTTER_SHELL_PLATFORM_FUCHSIA_FLUTTER_TESTS_INTEGRATION_UTILS_COLOR_H_ diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/tests/integration/utils/portable_ui_test.cc b/engine/src/flutter/shell/platform/fuchsia/flutter/tests/integration/utils/portable_ui_test.cc index e3c9bc06ef..12984d8b90 100644 --- a/engine/src/flutter/shell/platform/fuchsia/flutter/tests/integration/utils/portable_ui_test.cc +++ b/engine/src/flutter/shell/platform/fuchsia/flutter/tests/integration/utils/portable_ui_test.cc @@ -93,6 +93,7 @@ void PortableUITest::SetUpRealmBase() { Protocol{fuchsia::ui::scenic::Scenic::Name_}, Protocol{fuchsia::ui::test::input::Registry::Name_}, Protocol{fuchsia::ui::test::scene::Controller::Name_}, + Protocol{fuchsia::ui::display::singleton::Info::Name_}, Protocol{kPointerInjectorRegistryName}}, .source = kTestUIStackRef, .targets = {ParentRef(), kFlutterJitRunnerRef}}); diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/tests/integration/utils/portable_ui_test.h b/engine/src/flutter/shell/platform/fuchsia/flutter/tests/integration/utils/portable_ui_test.h index 7440dc52aa..9ee454b502 100644 --- a/engine/src/flutter/shell/platform/fuchsia/flutter/tests/integration/utils/portable_ui_test.h +++ b/engine/src/flutter/shell/platform/fuchsia/flutter/tests/integration/utils/portable_ui_test.h @@ -7,6 +7,7 @@ #include #include +#include #include #include #include diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/tests/integration/utils/screenshot.cc b/engine/src/flutter/shell/platform/fuchsia/flutter/tests/integration/utils/screenshot.cc index e3abfb6476..6e25e5815f 100644 --- a/engine/src/flutter/shell/platform/fuchsia/flutter/tests/integration/utils/screenshot.cc +++ b/engine/src/flutter/shell/platform/fuchsia/flutter/tests/integration/utils/screenshot.cc @@ -4,67 +4,102 @@ #include "screenshot.h" -#include +#include + +#include +#include +#include +#include #include "flutter/fml/logging.h" namespace fuchsia_test_utils { +namespace { +constexpr uint64_t kBytesPerPixel = 4; +} // namespace -Screenshot::Screenshot( - const fuchsia::ui::scenic::ScreenshotData& screenshot_data) - : width_(screenshot_data.info.width), height_(screenshot_data.info.height) { - FML_CHECK(screenshot_data.info.pixel_format == - fuchsia::images::PixelFormat::BGRA_8) - << "Non-BGRA_8 pixel formats not supported"; - - const auto& buffer = screenshot_data.data.vmo; - const auto num_bytes = screenshot_data.data.size; - - data_.resize(num_bytes); - - if (num_bytes == 0) { - return; +Screenshot::Screenshot(const zx::vmo& screenshot_vmo, + uint64_t width, + uint64_t height, + int rotation) + : width_(width), height_(height) { + FML_CHECK(rotation == 0 || rotation == 90 || rotation == 270); + if (rotation == 90 || rotation == 270) { + std::swap(width_, height_); } + // Populate |screenshot_| from |screenshot_vmo|. + uint64_t vmo_size; + screenshot_vmo.get_prop_content_size(&vmo_size); + FML_CHECK(vmo_size == kBytesPerPixel * width_ * height_); + uint8_t* vmo_host = nullptr; + auto status = zx::vmar::root_self()->map( + ZX_VM_PERM_READ, /*vmar_offset*/ 0, screenshot_vmo, + /*vmo_offset*/ 0, vmo_size, reinterpret_cast(&vmo_host)); + FML_CHECK(status == ZX_OK); + ExtractScreenshotFromVMO(vmo_host); + // map the pointer. + uintptr_t address = reinterpret_cast(vmo_host); + status = zx::vmar::root_self()->unmap(address, vmo_size); + FML_CHECK(status == ZX_OK); +} - zx_status_t status = buffer.read(&data_[0], 0, num_bytes); - if (status < 0) { - FML_LOG(WARNING) << "zx::vmo::read failed " << zx_status_get_string(status); +std::ostream& operator<<(std::ostream& stream, const Pixel& pixel) { + return stream << "{Pixel:" + << " r:" << static_cast(pixel.red) + << " g:" << static_cast(pixel.green) + << " b:" << static_cast(pixel.blue) + << " a:" << static_cast(pixel.alpha) << "}"; +} + +Pixel Screenshot::GetPixelAt(uint64_t x, uint64_t y) const { + FML_CHECK(x >= 0 && x < width_ && y >= 0 && y < height_) + << "Index out of bounds"; + return screenshot_[y][x]; +} + +std::map Screenshot::Histogram() const { + std::map histogram; + FML_CHECK(screenshot_.size() == height_ && screenshot_[0].size() == width_); + for (size_t i = 0; i < height_; i++) { + for (size_t j = 0; j < width_; j++) { + histogram[screenshot_[i][j]]++; + } } -} - -const Color* Screenshot::operator[](size_t row) const { - return &begin()[row * width_]; -} - -const Color& Screenshot::ColorAt(float x, float y) const { - FML_CHECK(x >= 0 && x < 1 && y >= 0 && y < 1) - << "(" << x << ", " << y << ") is out of bounds [0, 1) x [0, 1)"; - const size_t ix = static_cast(x * static_cast(width_)); - const size_t iy = static_cast(y * static_cast(height_)); - return (*this)[iy][ix]; -} - -const Color& Screenshot::ColorAtPixelXY(size_t ix, size_t iy) const { - FML_CHECK(ix < width_ && iy < height_); - return (*this)[iy][ix]; -} - -const Color* Screenshot::begin() const { - return reinterpret_cast(data_.data()); -} - -const Color* Screenshot::end() const { - return &begin()[width_ * height_]; -} - -std::map Screenshot::Histogram() const { - std::map histogram; - - for (const auto color : *this) { - ++histogram[color]; - } - return histogram; } +void Screenshot::ExtractScreenshotFromVMO(uint8_t* screenshot_vmo) { + FML_CHECK(screenshot_vmo); + for (size_t i = 0; i < height_; i++) { + // The head index of the ith row in the screenshot is |i* width_* + // KbytesPerPixel|. + screenshot_.push_back(GetPixelsInRow(screenshot_vmo, i)); + } +} + +std::vector Screenshot::GetPixelsInRow(uint8_t* screenshot_vmo, + size_t row_index) { + std::vector row; + for (size_t col_idx = 0; + col_idx < static_cast(width_ * kBytesPerPixel); + col_idx += kBytesPerPixel) { + // Each row in the screenshot has |kBytesPerPixel * width_| elements. + // Therefore in order to reach the first pixel of the |row_index| row, we + // have to jump |row_index * width_ * kBytesPerPixel| positions. + auto pixel_start_index = row_index * width_ * kBytesPerPixel; + // Every |kBytesPerPixel| bytes represents the BGRA values of a pixel. Skip + // |kBytesPerPixel| bytes to get to the BGRA values of the next pixel. Each + // row in a screenshot has |kBytesPerPixel * width_| bytes of data. + // Example:- + // auto data = TakeScreenshot(); + // data[0-3] -> RGBA of pixel 0. + // data[4-7] -> RGBA pf pixel 1. + row.emplace_back(screenshot_vmo[pixel_start_index + col_idx], + screenshot_vmo[pixel_start_index + col_idx + 1], + screenshot_vmo[pixel_start_index + col_idx + 2], + screenshot_vmo[pixel_start_index + col_idx + 3]); + } + return row; +} + } // namespace fuchsia_test_utils diff --git a/engine/src/flutter/shell/platform/fuchsia/flutter/tests/integration/utils/screenshot.h b/engine/src/flutter/shell/platform/fuchsia/flutter/tests/integration/utils/screenshot.h index f2090eb7a4..717089d9d9 100644 --- a/engine/src/flutter/shell/platform/fuchsia/flutter/tests/integration/utils/screenshot.h +++ b/engine/src/flutter/shell/platform/fuchsia/flutter/tests/integration/utils/screenshot.h @@ -5,52 +5,106 @@ #ifndef FLUTTER_SHELL_PLATFORM_FUCHSIA_FLUTTER_TESTS_INTEGRATION_UTILS_SCREENSHOT_H_ #define FLUTTER_SHELL_PLATFORM_FUCHSIA_FLUTTER_TESTS_INTEGRATION_UTILS_SCREENSHOT_H_ -#include +#include +#include +#include +#include #include -#include #include - -#include "color.h" +#include namespace fuchsia_test_utils { +// Represents a Pixel in BGRA format. +// Uses the sRGB color space. +struct Pixel { + uint8_t blue = 0; + uint8_t green = 0; + uint8_t red = 0; + uint8_t alpha = 0; -/// A screenshot that has been taken from a Fuchsia device. + Pixel(uint8_t blue, uint8_t green, uint8_t red, uint8_t alpha) + : blue(blue), green(green), red(red), alpha(alpha) {} + + bool operator==(const Pixel& rhs) const { + return blue == rhs.blue && green == rhs.green && red == rhs.red && + alpha == rhs.alpha; + } + + inline bool operator!=(const Pixel& rhs) const { return !(*this == rhs); } + + bool operator<(const Pixel& other) const { + return std::tie(blue, green, red, alpha) < + std::tie(other.blue, other.green, other.red, other.alpha); + } +}; + +std::ostream& operator<<(std::ostream& stream, const Pixel& pixel); + +// Helper class to get information about a screenshot returned by +// |fuchsia.ui.composition.Screenshot| protocol. class Screenshot { public: - Screenshot(const fuchsia::ui::scenic::ScreenshotData& screenshot_data); + // BGRA format. + inline static const Pixel kBlack = Pixel(0, 0, 0, 255); + inline static const Pixel kBlue = Pixel(255, 0, 0, 255); + inline static const Pixel kRed = Pixel(0, 0, 255, 255); + inline static const Pixel kMagenta = Pixel(255, 0, 255, 255); + inline static const Pixel kGreen = Pixel(0, 255, 0, 255); - size_t width() const { return width_; } - size_t height() const { return height_; } - bool empty() const { return width_ == 0 || height_ == 0; } + // Params:- + // |screenshot_vmo| - The VMO returned by + // fuchsia.ui.composition.Screenshot.Take representing the screenshot data. + // |width|, |height| - Width and height of the physical display in pixels as + // returned by |fuchsia.ui.display.singleton.Info|. + // |rotation| - The display rotation value in degrees. The width and the + // height of the screenshot are flipped if this value is 90 or 270 degrees, + // as the screenshot shows how content is seen by the user. + Screenshot(const zx::vmo& screenshot_vmo, + uint64_t width, + uint64_t height, + int rotation); - // Notably the indexer behaves like a row-major matrix, whereas the iterator - // behaves like a flat array. *IMPORTANT*: Use caution because index values - // are not validated, and out of bounds indexes can introduce memory errors. - // Also when indexing a specific pixel with |screenshot[a][b]|, note that - // the order of the indexes is non-traditional. The first index is for the - // |y| position (the row), followed by the |x| position. Consider using - // |ColorAtPixelXY()| instead. - const Color* operator[](size_t row) const; - - // Coordinates are in the range [0, 1). - const Color& ColorAt(float x, float y) const; - - // Returns the color of a pixel at the integer x and y indexes, after - // asserting that the indexes are in range. - const Color& ColorAtPixelXY(size_t ix, size_t iy) const; - - // Notably the iterator behaves like a flat array, whereas the indexer behaves - // like a row-major matrix. - const Color* begin() const; - const Color* end() const; + // Returns the |Pixel| located at (x,y) coordinates. |x| and |y| should range + // from [0,width_) and [0,height_) respectively. + // + // (0,0)________________width_____________(w-1,0) + // | | | + // | | y |h + // | x | |e + // |-----------------------X |i + // | |g + // | |h + // | |t + // |_________________________________| + // (0,h-1) screenshot (w-1,h-1) + // + // Clients should only use this function to get the pixel data. + Pixel GetPixelAt(uint64_t x, uint64_t y) const; // Counts the frequencies of each color in a screenshot. - std::map Histogram() const; + std::map Histogram() const; + + // Returns a 2D vector of size |height_ * width_|. Each value in the vector + // corresponds to a pixel in the screenshot. + std::vector> screenshot() const { return screenshot_; } + + uint64_t width() const { return width_; } + + uint64_t height() const { return height_; } private: - const size_t width_, height_; - std::vector data_; + // Populates |screenshot_| by converting the linear array of bytes in + // |screenshot_vmo| of size |kBytesPerPixel * width_ * height_| to a 2D vector + // of |Pixel|s of size |height_ * width_|. + void ExtractScreenshotFromVMO(uint8_t* screenshot_vmo); + + // Returns the |Pixel|s in the |row_index| row of the screenshot. + std::vector GetPixelsInRow(uint8_t* screenshot_vmo, size_t row_index); + + uint64_t width_ = 0; + uint64_t height_ = 0; + std::vector> screenshot_; }; } // namespace fuchsia_test_utils