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.
This commit is contained in:
@@ -471,9 +471,10 @@ bool FlutterWindowsEngine::MarkExternalTextureFrameAvailable(
|
||||
bool FlutterWindowsEngine::DispatchSemanticsAction(
|
||||
uint64_t target,
|
||||
FlutterSemanticsAction action,
|
||||
const std::vector<uint8_t>& 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) {
|
||||
|
||||
@@ -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<uint8_t>& data);
|
||||
fml::MallocMapping data);
|
||||
|
||||
// Informs the engine that the semantics enabled state has changed.
|
||||
void UpdateSemanticsEnabled(bool enabled);
|
||||
|
||||
@@ -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<uint8_t>(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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user