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

[fuchsia] Convert Gfx PlatformView to use modern TouchSource API, take 2 #35018

Merged
merged 1 commit into from
Aug 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions shell/platform/fuchsia/flutter/engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ void Engine::Initialize(
} else {
gfx_protocols.set_view_focuser(focuser.NewRequest());
gfx_protocols.set_view_ref_focused(view_ref_focused.NewRequest());
// TODO(fxbug.dev/85125): Enable TouchSource for GFX.
// gfx_protocols.set_touch_source(touch_source.NewRequest());
gfx_protocols.set_touch_source(touch_source.NewRequest());
// GFX used only on products without a mouse.
}
scenic->CreateSessionT(std::move(gfx_protocols), [] {});

Expand Down
48 changes: 23 additions & 25 deletions shell/platform/fuchsia/flutter/platform_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -109,33 +109,31 @@ PlatformView::PlatformView(
});

// Begin watching for pointer events.
if (is_flatland) { // TODO(fxbug.dev/85125): make unconditional
pointer_delegate_->WatchLoop([weak = weak_factory_.GetWeakPtr()](
std::vector<flutter::PointerData> events) {
if (!weak) {
FML_LOG(WARNING) << "PlatformView use-after-free attempted. Ignoring.";
return;
}
pointer_delegate_->WatchLoop([weak = weak_factory_.GetWeakPtr()](
std::vector<flutter::PointerData> events) {
if (!weak) {
FML_LOG(WARNING) << "PlatformView use-after-free attempted. Ignoring.";
return;
}

if (events.size() == 0) {
return; // No work, bounce out.
}
if (events.empty()) {
return; // No work, bounce out.
}

// If pixel ratio hasn't been set, use a default value of 1.
const float pixel_ratio = weak->view_pixel_ratio_.value_or(1.f);
auto packet = std::make_unique<flutter::PointerDataPacket>(events.size());
for (size_t i = 0; i < events.size(); ++i) {
auto& event = events[i];
// Translate logical to physical coordinates, as per
// flutter::PointerData contract. Done here because pixel ratio comes
// from the graphics API.
event.physical_x = event.physical_x * pixel_ratio;
event.physical_y = event.physical_y * pixel_ratio;
packet->SetPointerData(i, event);
}
weak->DispatchPointerDataPacket(std::move(packet));
});
}
// If pixel ratio hasn't been set, use a default value of 1.
const float pixel_ratio = weak->view_pixel_ratio_.value_or(1.f);
auto packet = std::make_unique<flutter::PointerDataPacket>(events.size());
for (size_t i = 0; i < events.size(); ++i) {
auto& event = events[i];
// Translate logical to physical coordinates, as per
// flutter::PointerData contract. Done here because pixel ratio comes
// from the graphics API.
event.physical_x = event.physical_x * pixel_ratio;
event.physical_y = event.physical_y * pixel_ratio;
packet->SetPointerData(i, event);
}
weak->DispatchPointerDataPacket(std::move(packet));
});

// Configure the pointer injector delegate.
pointer_injector_delegate_ = std::make_unique<PointerInjectorDelegate>(
Expand Down
3 changes: 1 addition & 2 deletions shell/platform/fuchsia/flutter/platform_view_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1394,8 +1394,7 @@ TEST_F(PlatformViewTests, OnShaderWarmup) {
EXPECT_EQ(expected_result_string, response->result_string);
}

// TODO(fxbug.dev/85125): Enable when GFX converts to TouchSource.
TEST_F(PlatformViewTests, DISABLED_TouchSourceLogicalToPhysicalConversion) {
TEST_F(PlatformViewTests, TouchSourceLogicalToPhysicalConversion) {
constexpr std::array<std::array<float, 2>, 2> kRect = {{{0, 0}, {20, 20}}};
constexpr std::array<float, 9> kIdentity = {1, 0, 0, 0, 1, 0, 0, 0, 1};
constexpr fuchsia::ui::pointer::TouchInteractionId kIxnOne = {
Expand Down
4 changes: 3 additions & 1 deletion shell/platform/fuchsia/flutter/pointer_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,9 @@ void PointerDelegate::WatchLoop(
// Start watching both channels.
touch_source_->Watch(std::move(touch_responses_), /*copy*/ touch_responder_);
touch_responses_.clear();
mouse_source_->Watch(/*copy*/ mouse_responder_);
if (mouse_source_) {
mouse_source_->Watch(/*copy*/ mouse_responder_);
}
}

} // namespace flutter_runner