提交 166f44c0 编写于 作者: A Adam Barth 提交者: GitHub

Remove pointer.mojom (#3102)

This patch moves the rest of the clients to use the new PointerData
transport.
上级 1f15c2b8
...@@ -33,7 +33,6 @@ executable("content_handler") { ...@@ -33,7 +33,6 @@ executable("content_handler") {
"//flutter/lib/ui", "//flutter/lib/ui",
"//flutter/runtime", "//flutter/runtime",
"//flutter/services/engine:interfaces", "//flutter/services/engine:interfaces",
"//flutter/services/pointer:interfaces",
"//flutter/sky/engine/platform", "//flutter/sky/engine/platform",
"//lib/ftl", "//lib/ftl",
"//lib/mtl", "//lib/mtl",
......
...@@ -72,7 +72,6 @@ source_set("ui") { ...@@ -72,7 +72,6 @@ source_set("ui") {
"//flutter/flow", "//flutter/flow",
"//flutter/glue", "//flutter/glue",
"//flutter/services/engine:interfaces", "//flutter/services/engine:interfaces",
"//flutter/services/pointer:interfaces",
"//flutter/skia", "//flutter/skia",
"//flutter/sky/engine", "//flutter/sky/engine",
"//lib/tonic", "//lib/tonic",
......
...@@ -12,4 +12,26 @@ static constexpr int kPointerDataFieldCount = 19; ...@@ -12,4 +12,26 @@ static constexpr int kPointerDataFieldCount = 19;
static_assert(sizeof(PointerData) == sizeof(int64_t) * kPointerDataFieldCount, static_assert(sizeof(PointerData) == sizeof(int64_t) * kPointerDataFieldCount,
"PointerData has the wrong size"); "PointerData has the wrong size");
void PointerData::Clear() {
time_stamp = 0;
pointer = 0;
change = Change::kCancel;
kind = DeviceKind::kTouch;
physical_x = 0.0;
physical_y = 0.0;
buttons = 0;
obscured = 0;
pressure = 0.0;
pressure_min = 0.0;
pressure_max = 0.0;
distance = 0.0;
distance_max = 0.0;
radius_major = 0.0;
radius_minor = 0.0;
radius_min = 0.0;
radius_max = 0.0;
orientation = 0.0;
tilt = 0.0;
}
} // namespace blink } // namespace blink
...@@ -48,6 +48,8 @@ struct alignas(8) PointerData { ...@@ -48,6 +48,8 @@ struct alignas(8) PointerData {
double radius_max; double radius_max;
double orientation; double orientation;
double tilt; double tilt;
void Clear();
}; };
} // namespace blink } // namespace blink
......
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
#include "flutter/lib/ui/semantics/semantics_update.h" #include "flutter/lib/ui/semantics/semantics_update.h"
#include "flutter/lib/ui/window/pointer_data_packet.h" #include "flutter/lib/ui/window/pointer_data_packet.h"
#include "flutter/services/engine/sky_engine.mojom.h" #include "flutter/services/engine/sky_engine.mojom.h"
#include "flutter/services/pointer/pointer.mojom.h"
#include "lib/ftl/time/time_point.h" #include "lib/ftl/time/time_point.h"
#include "lib/tonic/dart_persistent_value.h" #include "lib/tonic/dart_persistent_value.h"
......
...@@ -74,7 +74,6 @@ source_set("runtime") { ...@@ -74,7 +74,6 @@ source_set("runtime") {
"//flutter/lib/mojo", "//flutter/lib/mojo",
"//flutter/lib/ui", "//flutter/lib/ui",
"//flutter/services/engine:interfaces", "//flutter/services/engine:interfaces",
"//flutter/services/pointer:interfaces",
"//flutter/skia", "//flutter/skia",
"//flutter/sky/engine/platform", "//flutter/sky/engine/platform",
"//lib/ftl", "//lib/ftl",
......
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
#include "flutter/lib/ui/window/pointer_data_packet.h" #include "flutter/lib/ui/window/pointer_data_packet.h"
#include "flutter/lib/ui/window/window.h" #include "flutter/lib/ui/window/window.h"
#include "flutter/services/engine/sky_engine.mojom.h" #include "flutter/services/engine/sky_engine.mojom.h"
#include "flutter/services/pointer/pointer.mojom.h"
#include "lib/ftl/macros.h" #include "lib/ftl/macros.h"
namespace blink { namespace blink {
......
...@@ -11,7 +11,6 @@ mojom("interfaces") { ...@@ -11,7 +11,6 @@ mojom("interfaces") {
] ]
deps = [ deps = [
"//flutter/services/pointer:interfaces",
"//mojo/public/interfaces/application", "//mojo/public/interfaces/application",
"//mojo/services/asset_bundle/interfaces", "//mojo/services/asset_bundle/interfaces",
] ]
......
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
module sky; module sky;
import "flutter/services/engine/input_event.mojom"; import "flutter/services/engine/input_event.mojom";
import "flutter/services/pointer/pointer.mojom";
import "mojo/public/interfaces/application/service_provider.mojom"; import "mojo/public/interfaces/application/service_provider.mojom";
import "mojo/public/interfaces/application/shell.mojom"; import "mojo/public/interfaces/application/shell.mojom";
import "mojo/services/asset_bundle/interfaces/asset_bundle.mojom"; import "mojo/services/asset_bundle/interfaces/asset_bundle.mojom";
...@@ -41,7 +40,6 @@ interface SkyEngine { ...@@ -41,7 +40,6 @@ interface SkyEngine {
OnViewportMetricsChanged(ViewportMetrics metrics); OnViewportMetricsChanged(ViewportMetrics metrics);
OnLocaleChanged(string language_code, string country_code); OnLocaleChanged(string language_code, string country_code);
OnPointerPacket(pointer.PointerPacket packet);
PushRoute(string route); PushRoute(string route);
PopRoute(); PopRoute();
......
# Copyright 2015 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//mojo/public/tools/bindings/mojom.gni")
mojom("interfaces") {
sources = [
"pointer.mojom",
]
}
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
[DartPackage="sky_services"]
module pointer;
// See https://github.com/flutter/engine/blob/master/sky/specs/pointer.md
enum PointerType {
DOWN,
UP,
MOVE,
CANCEL,
};
enum PointerKind {
TOUCH,
MOUSE,
STYLUS,
INVERTED_STYLUS,
};
struct Pointer {
int64 time_stamp;
int32 pointer;
PointerType type;
PointerKind kind;
float x;
float y;
int32 buttons;
bool down;
bool primary;
bool obscured;
float pressure;
float pressure_min;
float pressure_max;
float distance;
float distance_min;
float distance_max;
float radius_major;
float radius_minor;
float radius_min;
float radius_max;
float orientation;
float tilt;
};
struct PointerPacket {
array<Pointer> pointers;
};
[ServiceName="pointer::PointerListener"]
interface PointerListener {
OnPointerPacket(PointerPacket packet);
};
...@@ -45,37 +45,6 @@ std::string FindPackagesPath(const std::string& main_dart) { ...@@ -45,37 +45,6 @@ std::string FindPackagesPath(const std::string& main_dart) {
return packages_path; return packages_path;
} }
blink::PointerData::Change GetChangeFromPointerType(pointer::PointerType type) {
switch (type) {
case pointer::PointerType::DOWN:
return blink::PointerData::Change::kDown;
case pointer::PointerType::UP:
return blink::PointerData::Change::kUp;
case pointer::PointerType::MOVE:
return blink::PointerData::Change::kMove;
case pointer::PointerType::CANCEL:
return blink::PointerData::Change::kCancel;
}
FTL_NOTREACHED();
return blink::PointerData::Change::kCancel;
}
blink::PointerData::DeviceKind GetDeviceKindFromPointerKind(
pointer::PointerKind kind) {
switch (kind) {
case pointer::PointerKind::TOUCH:
return blink::PointerData::DeviceKind::kTouch;
case pointer::PointerKind::MOUSE:
return blink::PointerData::DeviceKind::kMouse;
case pointer::PointerKind::STYLUS:
return blink::PointerData::DeviceKind::kStylus;
case pointer::PointerKind::INVERTED_STYLUS:
return blink::PointerData::DeviceKind::kInvertedStylus;
}
FTL_NOTREACHED();
return blink::PointerData::DeviceKind::kTouch;
}
} // namespace } // namespace
Engine::Engine(Rasterizer* rasterizer) Engine::Engine(Rasterizer* rasterizer)
...@@ -191,41 +160,6 @@ void Engine::DispatchPointerDataPacket(const PointerDataPacket& packet) { ...@@ -191,41 +160,6 @@ void Engine::DispatchPointerDataPacket(const PointerDataPacket& packet) {
runtime_->DispatchPointerDataPacket(packet); runtime_->DispatchPointerDataPacket(packet);
} }
// TODO(abarth): Remove pointer::PointerPacketPtr and route PointerDataPacket
// here.
void Engine::OnPointerPacket(pointer::PointerPacketPtr packetPtr) {
TRACE_EVENT0("flutter", "Engine::OnPointerPacket");
if (runtime_) {
const size_t length = packetPtr->pointers.size();
PointerDataPacket packet(length);
for (size_t i = 0; i < length; ++i) {
const pointer::PointerPtr& pointer = packetPtr->pointers[i];
blink::PointerData pointer_data;
pointer_data.time_stamp = pointer->time_stamp;
pointer_data.pointer = pointer->pointer;
pointer_data.change = GetChangeFromPointerType(pointer->type);
pointer_data.kind = GetDeviceKindFromPointerKind(pointer->kind);
pointer_data.physical_x = pointer->x;
pointer_data.physical_y = pointer->y;
pointer_data.buttons = pointer->buttons;
pointer_data.obscured = pointer->obscured ? 1 : 0;
pointer_data.pressure = pointer->pressure;
pointer_data.pressure_min = pointer->pressure_min;
pointer_data.pressure_max = pointer->pressure_max;
pointer_data.distance = pointer->distance;
pointer_data.distance_max = pointer->distance_max;
pointer_data.radius_major = pointer->radius_major;
pointer_data.radius_minor = pointer->radius_minor;
pointer_data.radius_min = pointer->radius_min;
pointer_data.radius_max = pointer->radius_max;
pointer_data.orientation = pointer->orientation;
pointer_data.tilt = pointer->tilt;
packet.SetPointerData(i, pointer_data);
}
runtime_->DispatchPointerDataPacket(packet);
}
}
void Engine::RunFromSnapshotStream( void Engine::RunFromSnapshotStream(
const std::string& script_uri, const std::string& script_uri,
mojo::ScopedDataPipeConsumerHandle snapshot) { mojo::ScopedDataPipeConsumerHandle snapshot) {
......
...@@ -62,7 +62,6 @@ class Engine : public UIDelegate, ...@@ -62,7 +62,6 @@ class Engine : public UIDelegate,
void OnViewportMetricsChanged(sky::ViewportMetricsPtr metrics) override; void OnViewportMetricsChanged(sky::ViewportMetricsPtr metrics) override;
void OnLocaleChanged(const mojo::String& language_code, void OnLocaleChanged(const mojo::String& language_code,
const mojo::String& country_code) override; const mojo::String& country_code) override;
void OnPointerPacket(pointer::PointerPacketPtr packet) override;
void RunFromFile(const mojo::String& main, void RunFromFile(const mojo::String& main,
const mojo::String& packages, const mojo::String& packages,
......
...@@ -26,7 +26,6 @@ source_set("common") { ...@@ -26,7 +26,6 @@ source_set("common") {
"//flutter/services/engine:interfaces", "//flutter/services/engine:interfaces",
"//flutter/services/media", "//flutter/services/media",
"//flutter/services/platform", "//flutter/services/platform",
"//flutter/services/pointer:interfaces",
"//flutter/services/vsync", "//flutter/services/vsync",
"//flutter/shell/common", "//flutter/shell/common",
"//flutter/shell/gpu", "//flutter/shell/gpu",
......
...@@ -23,7 +23,7 @@ source_set("mac_desktop_platform") { ...@@ -23,7 +23,7 @@ source_set("mac_desktop_platform") {
deps = [ deps = [
"//base", "//base",
"//flutter/services/pointer:interfaces", "//flutter/common",
"//flutter/shell/common", "//flutter/shell/common",
"//flutter/shell/platform/darwin/common", "//flutter/shell/platform/darwin/common",
"//flutter/shell/testing", "//flutter/shell/testing",
......
...@@ -4,8 +4,8 @@ ...@@ -4,8 +4,8 @@
#import "sky_window.h" #import "sky_window.h"
#include "base/time/time.h" #include "lib/ftl/time/time_delta.h"
#include "flutter/services/pointer/pointer.mojom.h" #include "flutter/common/threads.h"
#include "flutter/shell/platform/darwin/desktop/platform_view_mac.h" #include "flutter/shell/platform/darwin/desktop/platform_view_mac.h"
@interface SkyWindow ()<NSWindowDelegate> @interface SkyWindow ()<NSWindowDelegate>
...@@ -15,30 +15,30 @@ ...@@ -15,30 +15,30 @@
@end @end
static inline pointer::PointerType EventTypeFromNSEventPhase( static inline blink::PointerData::Change PointerChangeFromNSEventPhase(
NSEventPhase phase) { NSEventPhase phase) {
switch (phase) { switch (phase) {
case NSEventPhaseNone: case NSEventPhaseNone:
return pointer::PointerType::CANCEL; return blink::PointerData::Change::kCancel;
case NSEventPhaseBegan: case NSEventPhaseBegan:
return pointer::PointerType::DOWN; return blink::PointerData::Change::kDown;
case NSEventPhaseStationary: case NSEventPhaseStationary:
// There is no EVENT_TYPE_POINTER_STATIONARY. So we just pass a move type // There is no EVENT_TYPE_POINTER_STATIONARY. So we just pass a move type
// with the same coordinates // with the same coordinates
case NSEventPhaseChanged: case NSEventPhaseChanged:
return pointer::PointerType::MOVE; return blink::PointerData::Change::kMove;
case NSEventPhaseEnded: case NSEventPhaseEnded:
return pointer::PointerType::UP; return blink::PointerData::Change::kUp;
case NSEventPhaseCancelled: case NSEventPhaseCancelled:
return pointer::PointerType::CANCEL; return blink::PointerData::Change::kCancel;
case NSEventPhaseMayBegin: case NSEventPhaseMayBegin:
return pointer::PointerType::CANCEL; return blink::PointerData::Change::kCancel;
} }
return pointer::PointerType::CANCEL; return blink::PointerData::Change::kCancel;
} }
@implementation SkyWindow { @implementation SkyWindow {
std::unique_ptr<shell::PlatformViewMac> _platform_view; std::unique_ptr<shell::PlatformViewMac> _platformView;
} }
@synthesize renderSurface = _renderSurface; @synthesize renderSurface = _renderSurface;
...@@ -53,18 +53,18 @@ static inline pointer::PointerType EventTypeFromNSEventPhase( ...@@ -53,18 +53,18 @@ static inline pointer::PointerType EventTypeFromNSEventPhase(
} }
- (void)setupPlatformView { - (void)setupPlatformView {
DCHECK(_platform_view == nullptr) DCHECK(_platformView == nullptr)
<< "The platform view must not already be set."; << "The platform view must not already be set.";
_platform_view.reset(new shell::PlatformViewMac(self.renderSurface)); _platformView.reset(new shell::PlatformViewMac(self.renderSurface));
_platform_view->SetupResourceContextOnIOThread(); _platformView->SetupResourceContextOnIOThread();
_platform_view->NotifyCreated(); _platformView->NotifyCreated();
} }
// TODO(eseidel): This does not belong in sky_window! // TODO(eseidel): This does not belong in sky_window!
// Probably belongs in NSApplicationDelegate didFinishLaunching. // Probably belongs in NSApplicationDelegate didFinishLaunching.
- (void)setupAndLoadDart { - (void)setupAndLoadDart {
_platform_view->SetupAndLoadDart(); _platformView->SetupAndLoadDart();
} }
- (void)windowDidResize:(NSNotification*)notification { - (void)windowDidResize:(NSNotification*)notification {
...@@ -80,7 +80,7 @@ static inline pointer::PointerType EventTypeFromNSEventPhase( ...@@ -80,7 +80,7 @@ static inline pointer::PointerType EventTypeFromNSEventPhase(
metrics->physical_height = size.height; metrics->physical_height = size.height;
metrics->device_pixel_ratio = 1.0; metrics->device_pixel_ratio = 1.0;
_platform_view->engineProxy()->OnViewportMetricsChanged(metrics.Pass()); _platformView->engineProxy()->OnViewportMetricsChanged(metrics.Pass());
} }
- (void)setupSurfaceIfNecessary { - (void)setupSurfaceIfNecessary {
...@@ -101,35 +101,25 @@ static inline pointer::PointerType EventTypeFromNSEventPhase( ...@@ -101,35 +101,25 @@ static inline pointer::PointerType EventTypeFromNSEventPhase(
[_renderSurface convertPoint:event.locationInWindow fromView:nil]; [_renderSurface convertPoint:event.locationInWindow fromView:nil];
location.y = _renderSurface.frame.size.height - location.y; location.y = _renderSurface.frame.size.height - location.y;
auto pointer_data = pointer::Pointer::New(); blink::PointerData pointer_data;
pointer_data.Clear();
pointer_data->time_stamp = pointer_data.time_stamp =
base::TimeDelta::FromSecondsD(event.timestamp).InMicroseconds(); ftl::TimeDelta::FromSeconds(event.timestamp).ToMicroseconds();
pointer_data->type = EventTypeFromNSEventPhase(phase); pointer_data.change = PointerChangeFromNSEventPhase(phase);
pointer_data->kind = pointer::PointerKind::TOUCH; pointer_data.kind = blink::PointerData::DeviceKind::kMouse;
pointer_data->pointer = 0; pointer_data.physical_x = location.x;
pointer_data->x = location.x; pointer_data.physical_y = location.y;
pointer_data->y = location.y; pointer_data.pressure = 1.0;
pointer_data->buttons = 0; pointer_data.pressure_max = 1.0;
pointer_data->down = false;
pointer_data->primary = false; blink::Threads::UI()->PostTask(
pointer_data->obscured = false; [ engine = _platformView->engine().GetWeakPtr(), pointer_data ] {
pointer_data->pressure = 1.0; if (engine.get()) {
pointer_data->pressure_min = 0.0; blink::PointerDataPacket packet(1);
pointer_data->pressure_max = 1.0; packet.SetPointerData(0, pointer_data);
pointer_data->distance = 0.0; engine->DispatchPointerDataPacket(packet);
pointer_data->distance_min = 0.0; }
pointer_data->distance_max = 0.0; });
pointer_data->radius_major = 0.0;
pointer_data->radius_minor = 0.0;
pointer_data->radius_min = 0.0;
pointer_data->radius_max = 0.0;
pointer_data->orientation = 0.0;
pointer_data->tilt = 0.0;
auto pointer_packet = pointer::PointerPacket::New();
pointer_packet->pointers.push_back(pointer_data.Pass());
_platform_view->engineProxy()->OnPointerPacket(pointer_packet.Pass());
} }
- (void)mouseDown:(NSEvent*)event { - (void)mouseDown:(NSEvent*)event {
...@@ -145,8 +135,8 @@ static inline pointer::PointerType EventTypeFromNSEventPhase( ...@@ -145,8 +135,8 @@ static inline pointer::PointerType EventTypeFromNSEventPhase(
} }
- (void)dealloc { - (void)dealloc {
if (_platform_view) { if (_platformView) {
_platform_view->NotifyDestroyed(); _platformView->NotifyDestroyed();
} }
[super dealloc]; [super dealloc];
......
...@@ -4,11 +4,15 @@ ...@@ -4,11 +4,15 @@
#import "flutter/shell/platform/darwin/ios/framework/Headers/FlutterViewController.h" #import "flutter/shell/platform/darwin/ios/framework/Headers/FlutterViewController.h"
#include <memory>
#include "base/mac/scoped_block.h" #include "base/mac/scoped_block.h"
#include "base/mac/scoped_nsobject.h" #include "base/mac/scoped_nsobject.h"
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#include "lib/ftl/time/time_delta.h"
#include "lib/ftl/functional/wrap_lambda.h"
#include "flutter/common/threads.h"
#include "flutter/services/platform/ios/system_chrome_impl.h" #include "flutter/services/platform/ios/system_chrome_impl.h"
#include "flutter/sky/engine/wtf/MakeUnique.h"
#include "flutter/shell/platform/darwin/ios/framework/Source/flutter_touch_mapper.h" #include "flutter/shell/platform/darwin/ios/framework/Source/flutter_touch_mapper.h"
#include "flutter/shell/platform/darwin/ios/framework/Source/FlutterDartProject_Internal.h" #include "flutter/shell/platform/darwin/ios/framework/Source/FlutterDartProject_Internal.h"
#include "flutter/shell/platform/darwin/ios/platform_view_ios.h" #include "flutter/shell/platform/darwin/ios/platform_view_ios.h"
...@@ -73,7 +77,7 @@ void FlutterInit(int argc, const char* argv[]) { ...@@ -73,7 +77,7 @@ void FlutterInit(int argc, const char* argv[]) {
_orientationPreferences = UIInterfaceOrientationMaskAll; _orientationPreferences = UIInterfaceOrientationMaskAll;
_statusBarStyle = UIStatusBarStyleDefault; _statusBarStyle = UIStatusBarStyleDefault;
_viewportMetrics = sky::ViewportMetrics::New(); _viewportMetrics = sky::ViewportMetrics::New();
_platformView = WTF::MakeUnique<shell::PlatformViewIOS>( _platformView = std::make_unique<shell::PlatformViewIOS>(
reinterpret_cast<CAEAGLLayer*>(self.view.layer)); reinterpret_cast<CAEAGLLayer*>(self.view.layer));
_platformView->SetupResourceContextOnIOThread(); _platformView->SetupResourceContextOnIOThread();
...@@ -194,36 +198,37 @@ enum MapperPhase { ...@@ -194,36 +198,37 @@ enum MapperPhase {
Removed, Removed,
}; };
using PointerTypeMapperPhase = std::pair<pointer::PointerType, MapperPhase>; using PointerChangeMapperPhase = std::pair<blink::PointerData::Change, MapperPhase>;
static inline PointerTypeMapperPhase PointerTypePhaseFromUITouchPhase( static inline PointerChangeMapperPhase PointerChangePhaseFromUITouchPhase(
UITouchPhase phase) { UITouchPhase phase) {
switch (phase) { switch (phase) {
case UITouchPhaseBegan: case UITouchPhaseBegan:
return PointerTypeMapperPhase(pointer::PointerType::DOWN, return PointerChangeMapperPhase(blink::PointerData::Change::kDown,
MapperPhase::Added); MapperPhase::Added);
case UITouchPhaseMoved: case UITouchPhaseMoved:
case UITouchPhaseStationary: case UITouchPhaseStationary:
// There is no EVENT_TYPE_POINTER_STATIONARY. So we just pass a move type // There is no EVENT_TYPE_POINTER_STATIONARY. So we just pass a move type
// with the same coordinates // with the same coordinates
return PointerTypeMapperPhase(pointer::PointerType::MOVE, return PointerChangeMapperPhase(blink::PointerData::Change::kMove,
MapperPhase::Accessed); MapperPhase::Accessed);
case UITouchPhaseEnded: case UITouchPhaseEnded:
return PointerTypeMapperPhase(pointer::PointerType::UP, return PointerChangeMapperPhase(blink::PointerData::Change::kUp,
MapperPhase::Removed); MapperPhase::Removed);
case UITouchPhaseCancelled: case UITouchPhaseCancelled:
return PointerTypeMapperPhase(pointer::PointerType::CANCEL, return PointerChangeMapperPhase(blink::PointerData::Change::kCancel,
MapperPhase::Removed); MapperPhase::Removed);
} }
return PointerTypeMapperPhase(pointer::PointerType::CANCEL, return PointerChangeMapperPhase(blink::PointerData::Change::kCancel,
MapperPhase::Accessed); MapperPhase::Accessed);
} }
- (void)dispatchTouches:(NSSet*)touches phase:(UITouchPhase)phase { - (void)dispatchTouches:(NSSet*)touches phase:(UITouchPhase)phase {
auto eventTypePhase = PointerTypePhaseFromUITouchPhase(phase); auto eventTypePhase = PointerChangePhaseFromUITouchPhase(phase);
const CGFloat scale = [UIScreen mainScreen].scale; const CGFloat scale = [UIScreen mainScreen].scale;
auto pointer_packet = pointer::PointerPacket::New(); auto packet = std::make_unique<blink::PointerDataPacket>(touches.count);
int i = 0;
for (UITouch* touch in touches) { for (UITouch* touch in touches) {
int touch_identifier = 0; int touch_identifier = 0;
...@@ -243,37 +248,30 @@ static inline PointerTypeMapperPhase PointerTypePhaseFromUITouchPhase( ...@@ -243,37 +248,30 @@ static inline PointerTypeMapperPhase PointerTypePhaseFromUITouchPhase(
CGPoint windowCoordinates = [touch locationInView:nil]; CGPoint windowCoordinates = [touch locationInView:nil];
auto pointer_time = auto pointer_time =
base::TimeDelta::FromSecondsD(touch.timestamp).InMicroseconds(); ftl::TimeDelta::FromSeconds(touch.timestamp).ToMicroseconds();
auto pointer_data = pointer::Pointer::New(); blink::PointerData pointer_data;
pointer_data.Clear();
pointer_data->time_stamp = pointer_time;
pointer_data->type = eventTypePhase.first; pointer_data.time_stamp = pointer_time;
pointer_data->kind = pointer::PointerKind::TOUCH; pointer_data.change = eventTypePhase.first;
pointer_data->pointer = touch_identifier; pointer_data.kind = blink::PointerData::DeviceKind::kTouch;
pointer_data->x = windowCoordinates.x * scale; pointer_data.pointer = touch_identifier;
pointer_data->y = windowCoordinates.y * scale; pointer_data.physical_x = windowCoordinates.x * scale;
pointer_data->buttons = 0; pointer_data.physical_y = windowCoordinates.y * scale;
pointer_data->down = false; pointer_data.pressure = 1.0;
pointer_data->primary = false; pointer_data.pressure_max = 1.0;
pointer_data->obscured = false;
pointer_data->pressure = 1.0; packet->SetPointerData(i++, pointer_data);
pointer_data->pressure_min = 0.0;
pointer_data->pressure_max = 1.0;
pointer_data->distance = 0.0;
pointer_data->distance_min = 0.0;
pointer_data->distance_max = 0.0;
pointer_data->radius_major = 0.0;
pointer_data->radius_minor = 0.0;
pointer_data->radius_min = 0.0;
pointer_data->radius_max = 0.0;
pointer_data->orientation = 0.0;
pointer_data->tilt = 0.0;
pointer_packet->pointers.push_back(pointer_data.Pass());
} }
_platformView->engineProxy()->OnPointerPacket(pointer_packet.Pass()); blink::Threads::UI()->PostTask(ftl::WrapLambda([
engine = _platformView->engine().GetWeakPtr(),
packet = std::move(packet)
] {
if (engine.get())
engine->DispatchPointerDataPacket(*packet);
}));
} }
- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event { - (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
......
...@@ -17,6 +17,7 @@ executable("linux") { ...@@ -17,6 +17,7 @@ executable("linux") {
deps = [ deps = [
"//base", "//base",
"//flutter/common",
"//flutter/services/engine:interfaces", "//flutter/services/engine:interfaces",
"//flutter/services/raw_keyboard:interfaces", "//flutter/services/raw_keyboard:interfaces",
"//flutter/shell/common", "//flutter/shell/common",
......
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
// found in the LICENSE file. // found in the LICENSE file.
#include "flutter/shell/platform/linux/platform_view_glfw.h" #include "flutter/shell/platform/linux/platform_view_glfw.h"
#include "flutter/common/threads.h"
#include "flutter/shell/platform/linux/glfw_service_provider.h" #include "flutter/shell/platform/linux/glfw_service_provider.h"
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
...@@ -110,16 +112,16 @@ void PlatformViewGLFW::OnWindowSizeChanged(int width, int height) { ...@@ -110,16 +112,16 @@ void PlatformViewGLFW::OnWindowSizeChanged(int width, int height) {
} }
void PlatformViewGLFW::OnMouseButtonChanged(int button, int action, int mods) { void PlatformViewGLFW::OnMouseButtonChanged(int button, int action, int mods) {
pointer::PointerType type; blink::PointerData::Change change = blink::PointerData::Change::kCancel;
if (action == GLFW_PRESS) { if (action == GLFW_PRESS) {
if (!buttons_) { if (!buttons_) {
type = pointer::PointerType::DOWN; change = blink::PointerData::Change::kDown;
glfwSetCursorPosCallback( glfwSetCursorPosCallback(
glfw_window_, [](GLFWwindow* window, double x, double y) { glfw_window_, [](GLFWwindow* window, double x, double y) {
ToPlatformView(window)->OnCursorPosChanged(x, y); ToPlatformView(window)->OnCursorPosChanged(x, y);
}); });
} else { } else {
type = pointer::PointerType::MOVE; change = blink::PointerData::Change::kMove;
} }
// GLFW's button order matches what we want: // GLFW's button order matches what we want:
// https://github.com/flutter/engine/blob/master/sky/specs/pointer.md // https://github.com/flutter/engine/blob/master/sky/specs/pointer.md
...@@ -128,52 +130,65 @@ void PlatformViewGLFW::OnMouseButtonChanged(int button, int action, int mods) { ...@@ -128,52 +130,65 @@ void PlatformViewGLFW::OnMouseButtonChanged(int button, int action, int mods) {
} else if (action == GLFW_RELEASE) { } else if (action == GLFW_RELEASE) {
buttons_ &= ~(1 << button); buttons_ &= ~(1 << button);
if (!buttons_) { if (!buttons_) {
type = pointer::PointerType::UP; change = blink::PointerData::Change::kUp;
glfwSetCursorPosCallback(glfw_window_, nullptr); glfwSetCursorPosCallback(glfw_window_, nullptr);
} else { } else {
type = pointer::PointerType::MOVE; change = blink::PointerData::Change::kMove;
} }
} else { } else {
DLOG(INFO) << "Unknown mouse action: " << action; DLOG(INFO) << "Unknown mouse action: " << action;
return; return;
} }
double x = 0.f, y = 0.f; double x = 0.0;
double y = 0.0;
glfwGetCursorPos(glfw_window_, &x, &y); glfwGetCursorPos(glfw_window_, &x, &y);
base::TimeDelta time_stamp = base::TimeTicks::Now() - base::TimeTicks(); base::TimeDelta time_stamp = base::TimeTicks::Now() - base::TimeTicks();
auto pointer_data = pointer::Pointer::New(); blink::PointerData pointer_data;
pointer_data->time_stamp = time_stamp.InMicroseconds(); pointer_data.Clear();
pointer_data->type = type; pointer_data.time_stamp = time_stamp.InMicroseconds();
pointer_data->kind = pointer::PointerKind::MOUSE; pointer_data.change = change;
pointer_data->x = x; pointer_data.kind = blink::PointerData::DeviceKind::kMouse;
pointer_data->y = y; pointer_data.physical_x = x;
pointer_data->buttons = buttons_; pointer_data.physical_y = y;
pointer_data->pressure = 1.0; pointer_data.buttons = buttons_;
pointer_data->pressure_max = 1.0; pointer_data.pressure = 1.0;
pointer_data.pressure_max = 1.0;
auto pointer_packet = pointer::PointerPacket::New();
pointer_packet->pointers.push_back(pointer_data.Pass()); blink::Threads::UI()->PostTask(
engine_->OnPointerPacket(pointer_packet.Pass()); [ engine = engine().GetWeakPtr(), pointer_data ] {
if (engine.get()) {
blink::PointerDataPacket packet(1);
packet.SetPointerData(0, pointer_data);
engine->DispatchPointerDataPacket(packet);
}
});
} }
void PlatformViewGLFW::OnCursorPosChanged(double x, double y) { void PlatformViewGLFW::OnCursorPosChanged(double x, double y) {
base::TimeDelta time_stamp = base::TimeTicks::Now() - base::TimeTicks(); base::TimeDelta time_stamp = base::TimeTicks::Now() - base::TimeTicks();
auto pointer_data = pointer::Pointer::New(); blink::PointerData pointer_data;
pointer_data->time_stamp = time_stamp.InMicroseconds(); pointer_data.Clear();
pointer_data->type = pointer::PointerType::MOVE; pointer_data.time_stamp = time_stamp.InMicroseconds();
pointer_data->kind = pointer::PointerKind::MOUSE; pointer_data.change = blink::PointerData::Change::kMove;
pointer_data->x = x; pointer_data.kind = blink::PointerData::DeviceKind::kMouse;
pointer_data->y = y; pointer_data.physical_x = x;
pointer_data->buttons = buttons_; pointer_data.physical_y = y;
pointer_data->pressure = 1.0; pointer_data.buttons = buttons_;
pointer_data->pressure_max = 1.0; pointer_data.pressure = 1.0;
pointer_data.pressure_max = 1.0;
auto pointer_packet = pointer::PointerPacket::New();
pointer_packet->pointers.push_back(pointer_data.Pass()); blink::Threads::UI()->PostTask(
engine_->OnPointerPacket(pointer_packet.Pass()); [ engine = engine().GetWeakPtr(), pointer_data ] {
if (engine.get()) {
blink::PointerDataPacket packet(1);
packet.SetPointerData(0, pointer_data);
engine->DispatchPointerDataPacket(packet);
}
});
} }
void PlatformViewGLFW::OnKeyEvent(int key, int scancode, int action, int mods) { void PlatformViewGLFW::OnKeyEvent(int key, int scancode, int action, int mods) {
......
...@@ -17,7 +17,6 @@ static_library("core") { ...@@ -17,7 +17,6 @@ static_library("core") {
"//flutter/assets", "//flutter/assets",
"//flutter/sky/engine/platform", "//flutter/sky/engine/platform",
"//flutter/services/engine:interfaces", "//flutter/services/engine:interfaces",
"//flutter/services/pointer:interfaces",
] ]
if (flutter_runtime_mode != "release" && !is_fuchsia) { if (flutter_runtime_mode != "release" && !is_fuchsia) {
......
/// Copyright 2016 The Chromium Authors. All rights reserved.
/// Use of this source code is governed by a BSD-style license that can be
/// found in the LICENSE file.
import 'package:sky_services/pointer/pointer.mojom.dart';
export 'package:sky_services/pointer/pointer.mojom.dart';
...@@ -27,7 +27,6 @@ dart_pkg("sky_services") { ...@@ -27,7 +27,6 @@ dart_pkg("sky_services") {
"//flutter/services/editing:interfaces", "//flutter/services/editing:interfaces",
"//flutter/services/media:interfaces", "//flutter/services/media:interfaces",
"//flutter/services/platform:interfaces", "//flutter/services/platform:interfaces",
"//flutter/services/pointer:interfaces",
"//flutter/services/raw_keyboard:interfaces", "//flutter/services/raw_keyboard:interfaces",
"//flutter/services/semantics:interfaces", "//flutter/services/semantics:interfaces",
] ]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册