From 334a0c6ff9c9d59288a0c04e85d63fa458210b4c Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Mon, 6 Dec 2021 08:44:41 -0800 Subject: [PATCH] Use MallocMapping for DispatchSemanticsAction data (flutter/engine#30149) In the Windows embedder, the data parameter of FlutterWindowsEngine::DispatchSemanticsAction was a vector of bytes. Here, we switch it to use MallocMapping since that is the type of the data paramater on the DispatchAccessibilityAction method of AccessibilityBridgeDelegate, which calls this method. This avoids an extra type conversion. --- .../platform/windows/flutter_windows_engine.cc | 7 ++++--- .../platform/windows/flutter_windows_engine.h | 2 +- .../windows/flutter_windows_engine_unittests.cc | 16 ++++++++-------- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/engine/src/flutter/shell/platform/windows/flutter_windows_engine.cc b/engine/src/flutter/shell/platform/windows/flutter_windows_engine.cc index 7b138f5ae7..418c1b5baf 100644 --- a/engine/src/flutter/shell/platform/windows/flutter_windows_engine.cc +++ b/engine/src/flutter/shell/platform/windows/flutter_windows_engine.cc @@ -471,9 +471,10 @@ bool FlutterWindowsEngine::MarkExternalTextureFrameAvailable( bool FlutterWindowsEngine::DispatchSemanticsAction( uint64_t target, FlutterSemanticsAction action, - const std::vector& data) { - return (embedder_api_.DispatchSemanticsAction( - engine_, target, action, data.data(), data.size()) == kSuccess); + fml::MallocMapping data) { + return (embedder_api_.DispatchSemanticsAction(engine_, target, action, + data.GetMapping(), + data.GetSize()) == kSuccess); } void FlutterWindowsEngine::UpdateSemanticsEnabled(bool enabled) { diff --git a/engine/src/flutter/shell/platform/windows/flutter_windows_engine.h b/engine/src/flutter/shell/platform/windows/flutter_windows_engine.h index 5386a914b7..831e669fb7 100644 --- a/engine/src/flutter/shell/platform/windows/flutter_windows_engine.h +++ b/engine/src/flutter/shell/platform/windows/flutter_windows_engine.h @@ -152,7 +152,7 @@ class FlutterWindowsEngine { // Dispatches a semantics action to the specified semantics node. bool DispatchSemanticsAction(uint64_t id, FlutterSemanticsAction action, - const std::vector& data); + fml::MallocMapping data); // Informs the engine that the semantics enabled state has changed. void UpdateSemanticsEnabled(bool enabled); diff --git a/engine/src/flutter/shell/platform/windows/flutter_windows_engine_unittests.cc b/engine/src/flutter/shell/platform/windows/flutter_windows_engine_unittests.cc index 6f40e3ae9b..36185b5b7c 100644 --- a/engine/src/flutter/shell/platform/windows/flutter_windows_engine_unittests.cc +++ b/engine/src/flutter/shell/platform/windows/flutter_windows_engine_unittests.cc @@ -236,22 +236,22 @@ TEST(FlutterWindowsEngine, DispatchSemanticsAction) { EngineModifier modifier(engine.get()); bool called = false; - std::string test_data = "Hello"; + std::string message = "Hello"; modifier.embedder_api().DispatchSemanticsAction = MOCK_ENGINE_PROC( DispatchSemanticsAction, - ([&called, &test_data](auto engine, auto target, auto action, auto data, - auto data_length) { + ([&called, &message](auto engine, auto target, auto action, auto data, + auto data_length) { called = true; EXPECT_EQ(target, 42); EXPECT_EQ(action, kFlutterSemanticsActionDismiss); - EXPECT_EQ(memcmp(data, test_data.c_str(), test_data.size()), 0); - EXPECT_EQ(data_length, test_data.size()); + EXPECT_EQ(memcmp(data, message.c_str(), message.size()), 0); + EXPECT_EQ(data_length, message.size()); return kSuccess; })); - engine->DispatchSemanticsAction( - 42, kFlutterSemanticsActionDismiss, - std::vector(test_data.begin(), test_data.end())); + auto data = fml::MallocMapping::Copy(message.c_str(), message.size()); + engine->DispatchSemanticsAction(42, kFlutterSemanticsActionDismiss, + std::move(data)); EXPECT_TRUE(called); }