Skip to content

Commit 25e8021

Browse files
authored
[fuchsia] Convert Gfx PlatformView to use modern TouchSource API (flutter#35018)
Original PR: flutter#32877 Revert of flutter#32877: commit 1965c92 (flutter#33471) *This* patch: Revert of flutter#33471 fxbug.dev/85125
1 parent f182794 commit 25e8021

File tree

4 files changed

+29
-30
lines changed

4 files changed

+29
-30
lines changed

shell/platform/fuchsia/flutter/engine.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,8 @@ void Engine::Initialize(
166166
} else {
167167
gfx_protocols.set_view_focuser(focuser.NewRequest());
168168
gfx_protocols.set_view_ref_focused(view_ref_focused.NewRequest());
169-
// TODO(fxbug.dev/85125): Enable TouchSource for GFX.
170-
// gfx_protocols.set_touch_source(touch_source.NewRequest());
169+
gfx_protocols.set_touch_source(touch_source.NewRequest());
170+
// GFX used only on products without a mouse.
171171
}
172172
scenic->CreateSessionT(std::move(gfx_protocols), [] {});
173173

shell/platform/fuchsia/flutter/platform_view.cc

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -109,33 +109,31 @@ PlatformView::PlatformView(
109109
});
110110

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

120-
if (events.size() == 0) {
121-
return; // No work, bounce out.
122-
}
119+
if (events.empty()) {
120+
return; // No work, bounce out.
121+
}
123122

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

140138
// Configure the pointer injector delegate.
141139
pointer_injector_delegate_ = std::make_unique<PointerInjectorDelegate>(

shell/platform/fuchsia/flutter/platform_view_unittest.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1394,8 +1394,7 @@ TEST_F(PlatformViewTests, OnShaderWarmup) {
13941394
EXPECT_EQ(expected_result_string, response->result_string);
13951395
}
13961396

1397-
// TODO(fxbug.dev/85125): Enable when GFX converts to TouchSource.
1398-
TEST_F(PlatformViewTests, DISABLED_TouchSourceLogicalToPhysicalConversion) {
1397+
TEST_F(PlatformViewTests, TouchSourceLogicalToPhysicalConversion) {
13991398
constexpr std::array<std::array<float, 2>, 2> kRect = {{{0, 0}, {20, 20}}};
14001399
constexpr std::array<float, 9> kIdentity = {1, 0, 0, 0, 1, 0, 0, 0, 1};
14011400
constexpr fuchsia::ui::pointer::TouchInteractionId kIxnOne = {

shell/platform/fuchsia/flutter/pointer_delegate.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,9 @@ void PointerDelegate::WatchLoop(
447447
// Start watching both channels.
448448
touch_source_->Watch(std::move(touch_responses_), /*copy*/ touch_responder_);
449449
touch_responses_.clear();
450-
mouse_source_->Watch(/*copy*/ mouse_responder_);
450+
if (mouse_source_) {
451+
mouse_source_->Watch(/*copy*/ mouse_responder_);
452+
}
451453
}
452454

453455
} // namespace flutter_runner

0 commit comments

Comments
 (0)