Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
flutter_runner::PointerDelegate Class Reference

#include <pointer_delegate.h>

Public Member Functions

 PointerDelegate (fuchsia::ui::pointer::TouchSourceHandle touch_source, fuchsia::ui::pointer::MouseSourceHandle mouse_source)
 
void WatchLoop (std::function< void(std::vector< flutter::PointerData >)> callback)
 

Detailed Description

Definition at line 35 of file pointer_delegate.h.

Constructor & Destructor Documentation

◆ PointerDelegate()

flutter_runner::PointerDelegate::PointerDelegate ( fuchsia::ui::pointer::TouchSourceHandle  touch_source,
fuchsia::ui::pointer::MouseSourceHandle  mouse_source 
)

Definition at line 341 of file pointer_delegate.cc.

344 : touch_source_(touch_source.Bind()), mouse_source_(mouse_source.Bind()) {
345 if (touch_source_) {
346 touch_source_.set_error_handler([](zx_status_t status) {
347 FML_LOG(ERROR) << "TouchSource channel error: << "
348 << zx_status_get_string(status);
349 });
350 }
351 if (mouse_source_) {
352 mouse_source_.set_error_handler([](zx_status_t status) {
353 FML_LOG(ERROR) << "MouseSource channel error: << "
354 << zx_status_get_string(status);
355 });
356 }
357}
#define FML_LOG(severity)
Definition: logging.h:82
#define ERROR(message)
Definition: elf_loader.cc:260

Member Function Documentation

◆ WatchLoop()

void flutter_runner::PointerDelegate::WatchLoop ( std::function< void(std::vector< flutter::PointerData >)>  callback)

Definition at line 360 of file pointer_delegate.cc.

361 {
362 FML_LOG(INFO) << "Flutter - PointerDelegate started.";
363 if (touch_responder_) {
364 FML_LOG(ERROR) << "PointerDelegate::WatchLoop() must be called once.";
365 return;
366 }
367
368 touch_responder_ = [this, callback](std::vector<fup_TouchEvent> events) {
369 TRACE_EVENT0("flutter", "PointerDelegate::TouchHandler");
370 FML_DCHECK(touch_responses_.empty()) << "precondition";
371 std::vector<flutter::PointerData> to_client;
372 for (const fup_TouchEvent& event : events) {
373 IssueTouchTraceEvent(event);
375 response; // Response per event, matched on event's index.
376 if (event.has_view_parameters()) {
377 touch_view_parameters_ = std::move(event.view_parameters());
378 }
379 if (HasValidatedTouchSample(event)) {
380 const auto& sample = event.pointer_sample();
381 const auto& ixn = sample.interaction();
382 if (sample.phase() == fup_EventPhase::ADD &&
383 !event.has_interaction_result()) {
384 touch_buffer_.emplace(ixn, std::vector<flutter::PointerData>());
385 }
386
387 FML_DCHECK(touch_view_parameters_.has_value()) << "API guarantee";
388 auto events = CreateTouchDraft(event, touch_view_parameters_.value());
389 if (touch_buffer_.count(ixn) > 0) {
390 InsertIntoBuffer(std::move(events), &touch_buffer_[ixn]);
391 } else {
392 InsertIntoBuffer(std::move(events), &to_client);
393 }
394 // For this simple client, always claim we want the gesture.
395 response.set_response_type(fup_TouchResponseType::YES);
396 }
397 if (event.has_interaction_result()) {
398 const auto& result = event.interaction_result();
399 const auto& ixn = result.interaction;
400 if (result.status == fup_TouchIxnStatus::GRANTED &&
401 touch_buffer_.count(ixn) > 0) {
402 FML_DCHECK(to_client.empty()) << "invariant";
403 to_client.insert(to_client.end(), touch_buffer_[ixn].begin(),
404 touch_buffer_[ixn].end());
405 }
406 touch_buffer_.erase(ixn); // Result seen, delete the buffer.
407 }
408 touch_responses_.push_back(std::move(response));
409 }
410 callback(std::move(to_client)); // Notify client of touch events, if any.
411
412 touch_source_->Watch(std::move(touch_responses_),
413 /*copy*/ touch_responder_);
414 touch_responses_.clear();
415 };
416
417 mouse_responder_ = [this, callback](std::vector<fup_MouseEvent> events) {
418 TRACE_EVENT0("flutter", "PointerDelegate::MouseHandler");
419 std::vector<flutter::PointerData> to_client;
420 for (fup_MouseEvent& event : events) {
421 IssueMouseTraceEvent(event);
422 if (event.has_device_info()) {
423 const auto& id = event.device_info().id();
424 mouse_device_info_[id] = std::move(*event.mutable_device_info());
425 }
426 if (event.has_view_parameters()) {
427 mouse_view_parameters_ = std::move(event.view_parameters());
428 }
429 if (HasValidatedMouseSample(event)) {
430 const auto& sample = event.pointer_sample();
431 const auto& id = sample.device_id();
432 const bool any_button_down = sample.has_pressed_buttons();
433 FML_DCHECK(mouse_view_parameters_.has_value()) << "API guarantee";
434 FML_DCHECK(mouse_device_info_.count(id) > 0) << "API guarantee";
435
436 const auto phase = ComputePhase(any_button_down, mouse_down_, id);
438 CreateMouseDraft(event, phase, mouse_view_parameters_.value(),
439 mouse_device_info_[id]);
440 to_client.emplace_back(std::move(data));
441 }
442 }
443 callback(std::move(to_client));
444 mouse_source_->Watch(/*copy*/ mouse_responder_);
445 };
446
447 // Start watching both channels.
448 touch_source_->Watch(std::move(touch_responses_), /*copy*/ touch_responder_);
449 touch_responses_.clear();
450 if (mouse_source_) {
451 mouse_source_->Watch(/*copy*/ mouse_responder_);
452 }
453}
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
FlKeyEvent * event
GAsyncResult * result
#define FML_DCHECK(condition)
Definition: logging.h:103
fuchsia::ui::pointer::MouseEvent fup_MouseEvent
fuchsia::ui::pointer::TouchResponse fup_TouchResponse
fuchsia::ui::pointer::TouchEvent fup_TouchEvent
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63
const uintptr_t id
#define TRACE_EVENT0(category_group, name)
Definition: trace_event.h:131

The documentation for this class was generated from the following files: