Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
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
Next Next commit
Impl
  • Loading branch information
dkwingsmt committed Sep 22, 2023
commit 449ba202f0f20f0aa89b6f22422b055fed0d6612
4 changes: 4 additions & 0 deletions examples/glfw_drm/FlutterEmbedderGLFW.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ static const size_t kInitialWindowHeight = 600;
// Maximum damage history - for triple buffering we need to store damage for
// last two frames; Some Android devices (Pixel 4) use quad buffering.
static const int kMaxHistorySize = 10;
static constexpr int64_t kImplicitViewId = 0;

// Keeps track of the most recent frame damages so that existing damage can
// be easily computed.
Expand Down Expand Up @@ -56,6 +57,9 @@ void GLFWcursorPositionCallbackAtPhase(GLFWwindow* window,
std::chrono::duration_cast<std::chrono::microseconds>(
std::chrono::high_resolution_clock::now().time_since_epoch())
.count();
// TODO(loicsharma): This assumes all pointer events are on the implicit
// view and should be updated to support multiple views.
event.view_id = 0;
FlutterEngineSendPointerEvent(
reinterpret_cast<FlutterEngine>(glfwGetWindowUserPointer(window)), &event,
1);
Expand Down
4 changes: 3 additions & 1 deletion lib/ui/platform_dispatcher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -417,10 +417,11 @@ class PlatformDispatcher {

// If this value changes, update the encoding code in the following files:
//
// * pointer_data.h
// * pointer_data.cc
// * pointer.dart
// * AndroidTouchProcessor.java
static const int _kPointerDataFieldCount = 35;
static const int _kPointerDataFieldCount = 36;

static PointerDataPacket _unpackPointerDataPacket(ByteData packet) {
const int kStride = Int64List.bytesPerElement;
Expand Down Expand Up @@ -467,6 +468,7 @@ class PlatformDispatcher {
panDeltaY: packet.getFloat64(kStride * offset++, _kFakeHostEndian),
scale: packet.getFloat64(kStride * offset++, _kFakeHostEndian),
rotation: packet.getFloat64(kStride * offset++, _kFakeHostEndian),
viewId: packet.getInt64(kStride * offset++, _kFakeHostEndian),
));
assert(offset == (i + 1) * _kPointerDataFieldCount);
}
Expand Down
3 changes: 2 additions & 1 deletion lib/ui/pointer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,8 @@ class PointerData {
'panDeltaX: $panDeltaX, '
'panDeltaY: $panDeltaY, '
'scale: $scale, '
'rotation: $rotation'
'rotation: $rotation, '
'viewId: $viewId '
')';
}
}
Expand Down
5 changes: 3 additions & 2 deletions lib/ui/window/pointer_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace flutter {

// If this value changes, update the pointer data unpacking code in
// platform_dispatcher.dart.
static constexpr int kPointerDataFieldCount = 35;
static constexpr int kPointerDataFieldCount = 36;
static constexpr int kBytesPerField = sizeof(int64_t);
// Must match the button constants in events.dart.
enum PointerButtonMouse : int64_t {
Expand All @@ -32,7 +32,7 @@ enum PointerButtonStylus : int64_t {
kPointerButtonStylusSecondary = 1 << 2,
};

// This structure is unpacked by hooks.dart.
// This structure is unpacked by platform_dispatcher.dart.
struct alignas(8) PointerData {
// Must match the PointerChange enum in pointer.dart.
enum class Change : int64_t {
Expand Down Expand Up @@ -100,6 +100,7 @@ struct alignas(8) PointerData {
double pan_delta_y;
double scale;
double rotation;
int64_t view_id;

void Clear();
};
Expand Down
6 changes: 5 additions & 1 deletion lib/ui/window/pointer_data_packet_converter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ void PointerDataPacketConverter::ConvertPointerData(
break;
}
case PointerData::Change::kAdd: {
FML_DCHECK(states_.find(pointer_data.device) == states_.end());
// TODO(loicsharma): The macOS embedder does not share
// its mouse state across its view controllers, resulting
// in multiple pointer adds for the same pointer.
// See: https://github.com/flutter/flutter/issues/125931
// FML_DCHECK(states_.find(pointer_data.device) == states_.end());
EnsurePointerState(pointer_data);
converted_pointers.push_back(pointer_data);
break;
Expand Down
1 change: 1 addition & 0 deletions lib/ui/window/pointer_data_packet_converter_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ void CreateSimulatedTrackpadGestureData(PointerData& data, // NOLINT
data.pan_delta_y = 0.0;
data.scale = scale;
data.rotation = rotation;
data.view_id = 0;
}

void UnpackPointerPacket(std::vector<PointerData>& output, // NOLINT
Expand Down
3 changes: 2 additions & 1 deletion lib/web_ui/lib/pointer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ class PointerData {
'panDeltaX: $panDeltaX, '
'panDeltaY: $panDeltaY, '
'scale: $scale, '
'rotation: $rotation'
'rotation: $rotation, '
'viewId: $viewId'
')';
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ public class AndroidTouchProcessor {
int UNKNOWN = 4;
}

// Must match the unpacking code in hooks.dart.
private static final int POINTER_DATA_FIELD_COUNT = 35;
// Must match the unpacking code in platform_dispatcher.dart.
private static final int POINTER_DATA_FIELD_COUNT = 36;
@VisibleForTesting static final int BYTES_PER_FIELD = 8;

// Default if context is null, chosen to ensure reasonable speed scrolling.
Expand Down Expand Up @@ -411,6 +411,9 @@ private void addPointerForIndex(
packet.putDouble(0.0); // pan_delta_y
packet.putDouble(1.0); // scale
packet.putDouble(0.0); // rotation
// TODO(loicsharma): This assumes all pointer events are on the implicit
// view and should be updated to support multiple views.
packet.putLong(0); // view_id

if (isTrackpadPan && (panZoomType == PointerChange.PAN_ZOOM_END)) {
ongoingPans.remove(pointerId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1176,6 +1176,10 @@ - (void)dispatchTouches:(NSSet*)touches

pointer_data.device = reinterpret_cast<int64_t>(touch);

// TODO(loicsharma): This assumes all pointer events are on the implicit
// view and should be updated to support multiple views.
pointer_data.view_id = 0;

// Pointer will be generated in pointer_data_packet_converter.cc.
pointer_data.pointer_identifier = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,7 @@ - (void)dispatchMouseEvent:(NSEvent*)event phase:(FlutterPointerPhase)phase {
.device_kind = deviceKind,
// If a click triggered a synthesized kAdd, don't pass the buttons in that event.
.buttons = phase == kAdd ? 0 : _mouseState.buttons,
.view_id = static_cast<int64_t>(_viewId),
};

if (phase == kPanZoomUpdate) {
Expand Down Expand Up @@ -1077,6 +1078,7 @@ - (void)touchesBeganWithEvent:(NSEvent*)event {
.device = kPointerPanZoomDeviceId,
.signal_kind = kFlutterPointerSignalKindScrollInertiaCancel,
.device_kind = kFlutterPointerDeviceKindTrackpad,
.view_id = static_cast<int64_t>(_viewId),
};

[_engine sendPointerEvent:flutterEvent];
Expand Down
2 changes: 2 additions & 0 deletions shell/platform/embedder/embedder.h
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,8 @@ typedef struct {
double scale;
/// The rotation of the pan/zoom in radians, where 0.0 is the initial angle.
double rotation;
/// The identifier of the view that received the pointer event.
int64_t view_id;
} FlutterPointerEvent;

typedef enum {
Expand Down
4 changes: 4 additions & 0 deletions shell/platform/glfw/flutter_glfw.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <iostream>
#include <string>

#include "flutter/common/constants.h"
#include "flutter/shell/platform/common/client_wrapper/include/flutter/plugin_registrar.h"
#include "flutter/shell/platform/common/incoming_message_dispatcher.h"
#include "flutter/shell/platform/common/path_utils.h"
Expand Down Expand Up @@ -391,6 +392,9 @@ static void SendPointerEventWithData(GLFWwindow* window,
event.y *= pixels_per_coordinate;
event.scroll_delta_x *= pixels_per_coordinate;
event.scroll_delta_y *= pixels_per_coordinate;
// TODO(loicsharma): This assumes all pointer events are on the implicit
// view and should be updated to support multiple views.
event.view_id = flutter::kFlutterImplicitViewId;

FlutterEngineSendPointerEvent(controller->engine->flutter_engine, &event, 1);

Expand Down
4 changes: 4 additions & 0 deletions shell/platform/linux/fl_engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <string>
#include <vector>

#include "flutter/common/constants.h"
#include "flutter/shell/platform/common/app_lifecycle_state.h"
#include "flutter/shell/platform/common/engine_switches.h"
#include "flutter/shell/platform/embedder/embedder.h"
Expand Down Expand Up @@ -832,6 +833,9 @@ void fl_engine_send_pointer_pan_zoom_event(FlEngine* self,
fl_event.rotation = rotation;
fl_event.device = kPointerPanZoomDeviceId;
fl_event.device_kind = kFlutterPointerDeviceKindTrackpad;
// TODO(loicsharma): This assumes all pointer events are on the implicit
// view and should be updated to support multiple views.
fl_event.view_id = flutter::kFlutterImplicitViewId;
self->embedder_api.SendPointerEvent(self->engine, &fl_event, 1);
}

Expand Down
9 changes: 9 additions & 0 deletions shell/platform/windows/flutter_windows_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,9 @@ void FlutterWindowsView::SendPointerPanZoomEnd(int32_t device_id) {
event.x = state->pan_zoom_start_x;
event.y = state->pan_zoom_start_y;
event.phase = FlutterPointerPhase::kPanZoomEnd;
// TODO(loicsharma): This assumes all pointer events are on the implicit
// view and should be updated to support multiple views.
event.view_id = 0;
SendPointerEventWithData(event, state);
}

Expand Down Expand Up @@ -490,6 +493,10 @@ void FlutterWindowsView::SendScrollInertiaCancel(int32_t device_id,
void FlutterWindowsView::SendPointerEventWithData(
const FlutterPointerEvent& event_data,
PointerState* state) {
// TODO(dkwingsmt): The Windows embedder doesn't support multi-view for now.
// Use the real view ID when it does.
int64_t view_id = kImplicitViewId;

// If sending anything other than an add, and the pointer isn't already added,
// synthesize an add to satisfy Flutter's expectations about events.
if (!state->flutter_state_is_added &&
Expand All @@ -499,6 +506,7 @@ void FlutterWindowsView::SendPointerEventWithData(
event.x = event_data.x;
event.y = event_data.y;
event.buttons = 0;
event.view_id = view_id;
SendPointerEventWithData(event, state);
}

Expand All @@ -513,6 +521,7 @@ void FlutterWindowsView::SendPointerEventWithData(
event.device_kind = state->device_kind;
event.device = state->pointer_id;
event.buttons = state->buttons;
event.view_id = view_id_;

// Set metadata that's always the same regardless of the event.
event.struct_size = sizeof(event);
Expand Down