提交 82fbbd2f 编写于 作者: C Chinmay Garde 提交者: GitHub

In hot mode, allow reloading platform views that are already running. (#2949)

上级 19181be4
......@@ -4,32 +4,15 @@
#import "flutter/sky/shell/platform/ios/framework/Headers/FlutterViewController.h"
#include "base/bind.h"
#include "base/mac/scoped_block.h"
#include "base/mac/scoped_nsautorelease_pool.h"
#include "base/mac/scoped_nsobject.h"
#include "base/strings/sys_string_conversions.h"
#include "base/trace_event/trace_event.h"
#include "dart/runtime/include/dart_api.h"
#include "mojo/public/cpp/application/connect.h"
#include "mojo/public/interfaces/application/service_provider.mojom.h"
#include "flutter/sky/engine/wtf/MakeUnique.h"
#include "flutter/services/engine/sky_engine.mojom.h"
#include "flutter/services/platform/app_messages.mojom.h"
#include "flutter/services/platform/ios/system_chrome_impl.h"
#include "flutter/services/semantics/semantics.mojom.h"
#include "flutter/sky/shell/platform/ios/framework/Source/accessibility_bridge.h"
#include "flutter/sky/shell/platform/ios/framework/Source/application_messages_impl.h"
#include "flutter/sky/engine/wtf/MakeUnique.h"
#include "flutter/sky/shell/platform/ios/framework/Source/flutter_touch_mapper.h"
#include "flutter/sky/shell/platform/ios/framework/Source/FlutterDartProject_Internal.h"
#include "flutter/sky/shell/platform/ios/framework/Source/FlutterDynamicServiceLoader.h"
#include "flutter/sky/shell/platform/ios/framework/Source/FlutterView.h"
#include "flutter/sky/shell/platform/ios/platform_view_ios.h"
#include "flutter/sky/shell/platform/mac/platform_mac.h"
#include "flutter/sky/shell/platform/mac/platform_service_provider.h"
#include "flutter/sky/shell/platform/mac/view_service_provider.h"
#include "flutter/sky/shell/platform_view.h"
#include "flutter/sky/shell/shell.h"
@interface FlutterViewController ()<UIAlertViewDelegate>
@end
......@@ -44,15 +27,10 @@ void FlutterInit(int argc, const char* argv[]) {
base::scoped_nsprotocol<FlutterDartProject*> _dartProject;
UIInterfaceOrientationMask _orientationPreferences;
UIStatusBarStyle _statusBarStyle;
base::scoped_nsprotocol<FlutterDynamicServiceLoader*> _dynamicServiceLoader;
sky::ViewportMetricsPtr _viewportMetrics;
sky::shell::TouchMapper _touchMapper;
std::unique_ptr<sky::shell::PlatformViewIOS> _platformView;
sky::SkyEnginePtr _engine;
mojo::ServiceProviderPtr _dartServices;
std::unique_ptr<sky::shell::AccessibilityBridge> _accessibilityBridge;
flutter::platform::ApplicationMessagesPtr _appMessageSender;
sky::shell::ApplicationMessagesImpl _appMessageReceiver;
BOOL _initialized;
}
......@@ -94,7 +72,6 @@ void FlutterInit(int argc, const char* argv[]) {
_orientationPreferences = UIInterfaceOrientationMaskAll;
_statusBarStyle = UIStatusBarStyleDefault;
_dynamicServiceLoader.reset([[FlutterDynamicServiceLoader alloc] init]);
_viewportMetrics = sky::ViewportMetrics::New();
_platformView = WTF::MakeUnique<sky::shell::PlatformViewIOS>(
reinterpret_cast<CAEAGLLayer*>(self.view.layer));
......@@ -167,15 +144,13 @@ void FlutterInit(int argc, const char* argv[]) {
- (void)connectToEngineAndLoad {
TRACE_EVENT0("flutter", "connectToEngineAndLoad");
_platformView->ConnectToEngine(mojo::GetProxy(&_engine));
[self setupPlatformServiceProvider];
_platformView->ConnectToEngineAndSetupServices();
// We ask the VM to check what it supports.
const enum VMType type =
Dart_IsPrecompiledRuntime() ? VMTypePrecompilation : VMTypeInterpreter;
[_dartProject launchInEngine:_engine
[_dartProject launchInEngine:_platformView->engineProxy()
embedderVMType:type
result:^(BOOL success, NSString* message) {
if (!success) {
......@@ -189,49 +164,6 @@ void FlutterInit(int argc, const char* argv[]) {
[alert release];
}
}];
DCHECK(_dartServices);
mojo::ConnectToService(_dartServices.get(),
mojo::GetProxy(&_appMessageSender));
}
static void DynamicServiceResolve(void* baton,
const mojo::String& service_name,
mojo::ScopedMessagePipeHandle handle) {
base::mac::ScopedNSAutoreleasePool pool;
auto loader = reinterpret_cast<FlutterDynamicServiceLoader*>(baton);
[loader resolveService:@(service_name.data()) handle:handle.Pass()];
}
- (void)setupPlatformServiceProvider {
mojo::ServiceProviderPtr serviceProvider;
auto serviceProviderProxy = mojo::GetProxy(&serviceProvider);
// TODO(eseidel): this unretained reference might not be safe since
// the engine could outlive this controller
auto serviceResolutionCallback = base::Bind(
&DynamicServiceResolve,
base::Unretained(reinterpret_cast<void*>(_dynamicServiceLoader.get())));
new sky::shell::PlatformServiceProvider(serviceProviderProxy.Pass(),
serviceResolutionCallback);
ftl::WeakPtr<sky::shell::ApplicationMessagesImpl> appplication_messages_impl
= _appMessageReceiver.GetWeakPtr();
mojo::ServiceProviderPtr viewServiceProvider;
new sky::shell::ViewServiceProvider([appplication_messages_impl](
mojo::InterfaceRequest<flutter::platform::ApplicationMessages> request) {
if (appplication_messages_impl)
appplication_messages_impl->AddBinding(std::move(request));
},
mojo::GetProxy(&viewServiceProvider));
DCHECK(!_dartServices.is_bound());
sky::ServicesDataPtr services = sky::ServicesData::New();
services->incoming_services = serviceProvider.Pass();
services->outgoing_services = mojo::GetProxy(&_dartServices);
services->view_services = viewServiceProvider.Pass();
_engine->SetServices(services.Pass());
}
#pragma mark - Loading the view
......@@ -250,14 +182,16 @@ static void DynamicServiceResolve(void* baton,
#pragma mark - Application lifecycle notifications
- (void)applicationBecameActive:(NSNotification*)notification {
if (_engine) {
_engine->OnAppLifecycleStateChanged(sky::AppLifecycleState::RESUMED);
auto& engine = _platformView->engineProxy();
if (engine) {
engine->OnAppLifecycleStateChanged(sky::AppLifecycleState::RESUMED);
}
}
- (void)applicationWillResignActive:(NSNotification*)notification {
if (_engine) {
_engine->OnAppLifecycleStateChanged(sky::AppLifecycleState::PAUSED);
auto& engine = _platformView->engineProxy();
if (engine) {
engine->OnAppLifecycleStateChanged(sky::AppLifecycleState::PAUSED);
}
}
......@@ -348,7 +282,7 @@ static inline PointerTypeMapperPhase PointerTypePhaseFromUITouchPhase(
pointer_packet->pointers.push_back(pointer_data.Pass());
}
_engine->OnPointerPacket(pointer_packet.Pass());
_platformView->engineProxy()->OnPointerPacket(pointer_packet.Pass());
}
- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
......@@ -379,10 +313,10 @@ static inline PointerTypeMapperPhase PointerTypePhaseFromUITouchPhase(
_viewportMetrics->physical_padding_top =
[UIApplication sharedApplication].statusBarFrame.size.height * scale;
_engine->OnViewportMetricsChanged(_viewportMetrics.Clone());
_platformView->engineProxy()->OnViewportMetricsChanged(
_viewportMetrics.Clone());
}
#pragma mark - Keyboard events
- (void)keyboardWasShown:(NSNotification*)notification {
......@@ -391,12 +325,14 @@ static inline PointerTypeMapperPhase PointerTypePhaseFromUITouchPhase(
[[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue]);
CGFloat scale = [UIScreen mainScreen].scale;
_viewportMetrics->physical_padding_bottom = bottom * scale;
_engine->OnViewportMetricsChanged(_viewportMetrics.Clone());
_platformView->engineProxy()->OnViewportMetricsChanged(
_viewportMetrics.Clone());
}
- (void)keyboardWillBeHidden:(NSNotification*)notification {
_viewportMetrics->physical_padding_bottom = 0.0;
_engine->OnViewportMetricsChanged(_viewportMetrics.Clone());
_platformView->engineProxy()->OnViewportMetricsChanged(
_viewportMetrics.Clone());
}
#pragma mark - Orientation updates
......@@ -441,14 +377,7 @@ static inline PointerTypeMapperPhase PointerTypePhaseFromUITouchPhase(
#else
bool enable = UIAccessibilityIsVoiceOverRunning();
#endif
if (enable) {
if (!_accessibilityBridge && _dartServices.get() != nullptr) {
_accessibilityBridge.reset(
new sky::shell::AccessibilityBridge(self.view, _dartServices.get()));
}
} else {
_accessibilityBridge = nullptr;
}
_platformView->ToggleAccessibility(self.view, enable);
}
#pragma mark - Locale updates
......@@ -457,7 +386,8 @@ static inline PointerTypeMapperPhase PointerTypePhaseFromUITouchPhase(
NSLocale* currentLocale = [NSLocale currentLocale];
NSString* languageCode = [currentLocale objectForKey:NSLocaleLanguageCode];
NSString* countryCode = [currentLocale objectForKey:NSLocaleCountryCode];
_engine->OnLocaleChanged(languageCode.UTF8String, countryCode.UTF8String);
_platformView->engineProxy()->OnLocaleChanged(languageCode.UTF8String,
countryCode.UTF8String);
}
#pragma mark - Surface creation and teardown updates
......@@ -523,8 +453,9 @@ static inline PointerTypeMapperPhase PointerTypePhaseFromUITouchPhase(
- (void)sendString:(NSString*)message withMessageName:(NSString*)messageName {
NSAssert(message, @"The message must not be null");
NSAssert(messageName, @"The messageName must not be null");
_appMessageSender->SendString(messageName.UTF8String, message.UTF8String,
[](const mojo::String& response) {});
_platformView->AppMessageSender()->SendString(
messageName.UTF8String, message.UTF8String,
[](const mojo::String& response) {});
}
- (void)sendString:(NSString*)message
......@@ -535,7 +466,7 @@ static inline PointerTypeMapperPhase PointerTypePhaseFromUITouchPhase(
NSAssert(callback, @"The callback must not be null");
base::mac::ScopedBlock<void (^)(NSString*)> callback_ptr(
callback, base::scoped_policy::RETAIN);
_appMessageSender->SendString(
_platformView->AppMessageSender()->SendString(
messageName.UTF8String, message.UTF8String,
[callback_ptr](const mojo::String& response) {
callback_ptr.get()(base::SysUTF8ToNSString(response));
......@@ -546,14 +477,16 @@ static inline PointerTypeMapperPhase PointerTypePhaseFromUITouchPhase(
NSAssert(listener, @"The listener must not be null");
NSString* messageName = listener.messageName;
NSAssert(messageName, @"The messageName must not be null");
_appMessageReceiver.SetMessageListener(messageName.UTF8String, listener);
_platformView->AppMessageReceiver().SetMessageListener(messageName.UTF8String,
listener);
}
- (void)removeMessageListener:(NSObject<FlutterMessageListener>*)listener {
NSAssert(listener, @"The listener must not be null");
NSString* messageName = listener.messageName;
NSAssert(messageName, @"The messageName must not be null");
_appMessageReceiver.SetMessageListener(messageName.UTF8String, nil);
_platformView->AppMessageReceiver().SetMessageListener(messageName.UTF8String,
nil);
}
- (void)addAsyncMessageListener:
......@@ -561,7 +494,8 @@ static inline PointerTypeMapperPhase PointerTypePhaseFromUITouchPhase(
NSAssert(listener, @"The listener must not be null");
NSString* messageName = listener.messageName;
NSAssert(messageName, @"The messageName must not be null");
_appMessageReceiver.SetAsyncMessageListener(messageName.UTF8String, listener);
_platformView->AppMessageReceiver().SetAsyncMessageListener(
messageName.UTF8String, listener);
}
- (void)removeAsyncMessageListener:
......@@ -569,7 +503,8 @@ static inline PointerTypeMapperPhase PointerTypePhaseFromUITouchPhase(
NSAssert(listener, @"The listener must not be null");
NSString* messageName = listener.messageName;
NSAssert(messageName, @"The messageName must not be null");
_appMessageReceiver.SetAsyncMessageListener(messageName.UTF8String, nil);
_platformView->AppMessageReceiver().SetAsyncMessageListener(
messageName.UTF8String, nil);
}
@end
......@@ -7,12 +7,17 @@
#include <memory>
#include "base/mac/scoped_nsobject.h"
#include "lib/ftl/macros.h"
#include "lib/ftl/memory/weak_ptr.h"
#include "base/mac/scoped_nsobject.h"
#include "flutter/services/platform/app_messages.mojom.h"
#include "flutter/sky/shell/platform/ios/framework/Source/accessibility_bridge.h"
#include "flutter/sky/shell/platform/ios/framework/Source/application_messages_impl.h"
#include "flutter/sky/shell/platform/ios/framework/Source/FlutterDynamicServiceLoader.h"
#include "flutter/sky/shell/platform_view.h"
@class CAEAGLLayer;
@class UIView;
namespace sky {
namespace shell {
......@@ -25,7 +30,17 @@ class PlatformViewIOS : public PlatformView {
~PlatformViewIOS() override;
ftl::WeakPtr<sky::shell::PlatformView> GetWeakViewPtr() override;
void ToggleAccessibility(UIView* view, bool enable);
void ConnectToEngineAndSetupServices();
SkyEnginePtr& engineProxy();
flutter::platform::ApplicationMessagesPtr& AppMessageSender();
ApplicationMessagesImpl& AppMessageReceiver();
ftl::WeakPtr<PlatformView> GetWeakViewPtr() override;
uint64_t DefaultFramebuffer() const override;
......@@ -41,8 +56,18 @@ class PlatformViewIOS : public PlatformView {
private:
std::unique_ptr<IOSGLContext> context_;
SkyEnginePtr engine_;
mojo::ServiceProviderPtr dart_services_;
flutter::platform::ApplicationMessagesPtr app_message_sender_;
ApplicationMessagesImpl app_message_receiver_;
std::unique_ptr<AccessibilityBridge> accessibility_bridge_;
base::scoped_nsprotocol<FlutterDynamicServiceLoader*> dynamic_service_loader_;
ftl::WeakPtrFactory<PlatformViewIOS> weak_factory_;
void SetupAndLoadFromSource(const std::string& main,
const std::string& packages,
const std::string& assets_directory);
FTL_DISALLOW_COPY_AND_ASSIGN(PlatformViewIOS);
};
......
......@@ -7,6 +7,9 @@
#include "base/mac/scoped_nsautorelease_pool.h"
#include "base/trace_event/trace_event.h"
#include "flutter/sky/engine/wtf/MakeUnique.h"
#include "flutter/sky/shell/platform/mac/view_service_provider.h"
#include "lib/ftl/synchronization/waitable_event.h"
#include "mojo/public/cpp/application/connect.h"
#import <OpenGLES/ES2/gl.h>
#import <OpenGLES/ES2/glext.h>
......@@ -271,11 +274,89 @@ class IOSGLContext {
PlatformViewIOS::PlatformViewIOS(CAEAGLLayer* layer)
: context_(WTF::MakeUnique<IOSGLContext>(surface_config_, layer)),
dynamic_service_loader_([[FlutterDynamicServiceLoader alloc] init]),
weak_factory_(this) {}
PlatformViewIOS::~PlatformViewIOS() = default;
ftl::WeakPtr<sky::shell::PlatformView> PlatformViewIOS::GetWeakViewPtr() {
SkyEnginePtr& PlatformViewIOS::engineProxy() {
return engine_;
}
flutter::platform::ApplicationMessagesPtr& PlatformViewIOS::AppMessageSender() {
return app_message_sender_;
}
sky::shell::ApplicationMessagesImpl& PlatformViewIOS::AppMessageReceiver() {
return app_message_receiver_;
}
void PlatformViewIOS::ToggleAccessibility(UIView* view, bool enable) {
if (enable) {
if (!accessibility_bridge_ && dart_services_.get() != nullptr) {
accessibility_bridge_.reset(
new sky::shell::AccessibilityBridge(view, dart_services_.get()));
}
} else {
accessibility_bridge_ = nullptr;
}
}
static void DynamicServiceResolve(void* baton,
const mojo::String& service_name,
mojo::ScopedMessagePipeHandle handle) {
base::mac::ScopedNSAutoreleasePool pool;
auto loader = reinterpret_cast<FlutterDynamicServiceLoader*>(baton);
[loader resolveService:@(service_name.data()) handle:handle.Pass()];
}
void PlatformViewIOS::ConnectToEngineAndSetupServices() {
ConnectToEngine(mojo::GetProxy(&engine_));
mojo::ServiceProviderPtr service_provider;
auto service_provider_proxy = mojo::GetProxy(&service_provider);
auto service_resolution_callback = base::Bind(
&DynamicServiceResolve,
base::Unretained(reinterpret_cast<void*>(dynamic_service_loader_.get())));
new PlatformServiceProvider(service_provider_proxy.Pass(),
service_resolution_callback);
ftl::WeakPtr<ApplicationMessagesImpl> appplication_messages_impl =
app_message_receiver_.GetWeakPtr();
mojo::ServiceProviderPtr viewServiceProvider;
new ViewServiceProvider(
[appplication_messages_impl](
mojo::InterfaceRequest<flutter::platform::ApplicationMessages>
request) {
if (appplication_messages_impl)
appplication_messages_impl->AddBinding(std::move(request));
},
mojo::GetProxy(&viewServiceProvider));
sky::ServicesDataPtr services = sky::ServicesData::New();
services->incoming_services = service_provider.Pass();
services->outgoing_services = mojo::GetProxy(&dart_services_);
services->view_services = viewServiceProvider.Pass();
engine_->SetServices(services.Pass());
mojo::ConnectToService(dart_services_.get(),
mojo::GetProxy(&app_message_sender_));
}
void PlatformViewIOS::SetupAndLoadFromSource(
const std::string& main,
const std::string& packages,
const std::string& assets_directory) {
ConnectToEngineAndSetupServices();
engine_->RunFromFile(main, packages, assets_directory);
}
ftl::WeakPtr<PlatformView> PlatformViewIOS::GetWeakViewPtr() {
return weak_factory_.GetWeakPtr();
}
......@@ -299,9 +380,15 @@ bool PlatformViewIOS::SwapBuffers() {
void PlatformViewIOS::RunFromSource(const std::string& main,
const std::string& packages,
const std::string& assets_directory) {
// TODO(johnmccutchan): Call to the iOS UI thread so that services work
// properly like we do in PlatformViewAndroid.
engine().RunFromSource(main, packages, assets_directory);
auto latch = new ftl::ManualResetWaitableEvent();
dispatch_async(dispatch_get_main_queue(), ^{
SetupAndLoadFromSource(main, packages, assets_directory);
latch->Signal();
});
latch->Wait();
delete latch;
}
} // namespace shell
......
......@@ -21,6 +21,10 @@ class PlatformViewMac : public PlatformView {
~PlatformViewMac() override;
void SetupAndLoadDart();
SkyEnginePtr& engineProxy();
ftl::WeakPtr<PlatformView> GetWeakViewPtr() override;
uint64_t DefaultFramebuffer() const override;
......@@ -38,10 +42,17 @@ class PlatformViewMac : public PlatformView {
private:
base::scoped_nsobject<NSOpenGLView> opengl_view_;
base::scoped_nsobject<NSOpenGLContext> resource_loading_context_;
sky::SkyEnginePtr sky_engine_;
ftl::WeakPtrFactory<PlatformViewMac> weak_factory_;
bool IsValid() const;
void ConnectToEngineAndSetupServices();
void SetupAndLoadFromSource(const std::string& main,
const std::string& packages,
const std::string& assets_directory);
FTL_DISALLOW_COPY_AND_ASSIGN(PlatformViewMac);
};
......
......@@ -6,11 +6,23 @@
#include <AppKit/AppKit.h>
#include "base/command_line.h"
#include "base/trace_event/trace_event.h"
#include "flutter/sky/shell/switches.h"
#include "flutter/sky/shell/platform/mac/view_service_provider.h"
#include "flutter/sky/shell/platform/mac/platform_mac.h"
#include "flutter/sky/shell/platform/mac/platform_service_provider.h"
#include "lib/ftl/synchronization/waitable_event.h"
namespace sky {
namespace shell {
static void IgnoreRequest(
mojo::InterfaceRequest<flutter::platform::ApplicationMessages>) {}
static void DynamicServiceResolve(const mojo::String& service_name,
mojo::ScopedMessagePipeHandle handle) {}
PlatformViewMac::PlatformViewMac(NSOpenGLView* gl_view)
: opengl_view_([gl_view retain]),
resource_loading_context_([[NSOpenGLContext alloc]
......@@ -20,7 +32,63 @@ PlatformViewMac::PlatformViewMac(NSOpenGLView* gl_view)
PlatformViewMac::~PlatformViewMac() = default;
ftl::WeakPtr<sky::shell::PlatformView> PlatformViewMac::GetWeakViewPtr() {
void PlatformViewMac::ConnectToEngineAndSetupServices() {
ConnectToEngine(mojo::GetProxy(&sky_engine_));
mojo::ServiceProviderPtr service_provider;
new PlatformServiceProvider(mojo::GetProxy(&service_provider),
base::Bind(DynamicServiceResolve));
mojo::ServiceProviderPtr view_service_provider;
new ViewServiceProvider(IgnoreRequest,
mojo::GetProxy(&view_service_provider));
sky::ServicesDataPtr services = sky::ServicesData::New();
services->incoming_services = service_provider.Pass();
services->view_services = view_service_provider.Pass();
sky_engine_->SetServices(services.Pass());
}
void PlatformViewMac::SetupAndLoadDart() {
ConnectToEngineAndSetupServices();
if (AttemptLaunchFromCommandLineSwitches(sky_engine_)) {
// This attempts launching from an FLX bundle that does not contain a
// dart snapshot.
return;
}
base::CommandLine& command_line = *base::CommandLine::ForCurrentProcess();
std::string bundle_path = command_line.GetSwitchValueASCII(switches::kFLX);
if (!bundle_path.empty()) {
std::string script_uri = std::string("file://") + bundle_path;
sky_engine_->RunFromBundle(script_uri, bundle_path);
return;
}
auto args = command_line.GetArgs();
if (args.size() > 0) {
auto packages = command_line.GetSwitchValueASCII(switches::kPackages);
sky_engine_->RunFromFile(args[0], packages, "");
return;
}
}
void PlatformViewMac::SetupAndLoadFromSource(
const std::string& main,
const std::string& packages,
const std::string& assets_directory) {
ConnectToEngineAndSetupServices();
sky_engine_->RunFromFile(main, packages, assets_directory);
}
SkyEnginePtr& PlatformViewMac::engineProxy() {
return sky_engine_;
}
ftl::WeakPtr<PlatformView> PlatformViewMac::GetWeakViewPtr() {
return weak_factory_.GetWeakPtr();
}
......@@ -77,9 +145,15 @@ bool PlatformViewMac::IsValid() const {
void PlatformViewMac::RunFromSource(const std::string& main,
const std::string& packages,
const std::string& assets_directory) {
// TODO(johnmccutchan): Call to the Mac UI thread so that services work
// properly like we do in PlatformViewAndroid.
engine().RunFromSource(main, packages, assets_directory);
auto latch = new ftl::ManualResetWaitableEvent();
dispatch_async(dispatch_get_main_queue(), ^{
SetupAndLoadFromSource(main, packages, assets_directory);
latch->Signal();
});
latch->Wait();
delete latch;
}
} // namespace shell
......
......@@ -3,25 +3,10 @@
// found in the LICENSE file.
#import "sky_window.h"
#include "base/command_line.h"
#include "base/time/time.h"
#include "mojo/public/cpp/bindings/interface_request.h"
#include "flutter/services/engine/input_event.mojom.h"
#include "flutter/services/pointer/pointer.mojom.h"
#include "flutter/sky/shell/platform/mac/platform_mac.h"
#include "flutter/sky/shell/platform/mac/platform_view_mac.h"
#include "flutter/sky/shell/platform/mac/platform_service_provider.h"
#include "flutter/sky/shell/platform/mac/view_service_provider.h"
#include "flutter/sky/shell/shell.h"
#include "flutter/sky/shell/switches.h"
#include "flutter/sky/shell/ui_delegate.h"
static void IgnoreRequest(
mojo::InterfaceRequest<flutter::platform::ApplicationMessages>) {
}
static void DynamicServiceResolve(const mojo::String& service_name,
mojo::ScopedMessagePipeHandle handle) {}
@interface SkyWindow ()<NSWindowDelegate>
......@@ -53,7 +38,6 @@ static inline pointer::PointerType EventTypeFromNSEventPhase(
}
@implementation SkyWindow {
sky::SkyEnginePtr _sky_engine;
std::unique_ptr<sky::shell::PlatformViewMac> _platform_view;
}
......@@ -80,44 +64,7 @@ static inline pointer::PointerType EventTypeFromNSEventPhase(
// TODO(eseidel): This does not belong in sky_window!
// Probably belongs in NSApplicationDelegate didFinishLaunching.
- (void)setupAndLoadDart {
_platform_view->ConnectToEngine(mojo::GetProxy(&_sky_engine));
mojo::ServiceProviderPtr service_provider;
new sky::shell::PlatformServiceProvider(mojo::GetProxy(&service_provider),
base::Bind(DynamicServiceResolve));
mojo::ServiceProviderPtr view_service_provider;
new sky::shell::ViewServiceProvider(IgnoreRequest,
mojo::GetProxy(&view_service_provider));
sky::ServicesDataPtr services = sky::ServicesData::New();
services->incoming_services = service_provider.Pass();
services->view_services = view_service_provider.Pass();
_sky_engine->SetServices(services.Pass());
if (sky::shell::AttemptLaunchFromCommandLineSwitches(_sky_engine)) {
// This attempts launching from an FLX bundle that does not contain a
// dart snapshot.
return;
}
base::CommandLine& command_line = *base::CommandLine::ForCurrentProcess();
std::string bundle_path =
command_line.GetSwitchValueASCII(sky::shell::switches::kFLX);
if (!bundle_path.empty()) {
std::string script_uri = std::string("file://") + bundle_path;
_sky_engine->RunFromBundle(script_uri, bundle_path);
return;
}
auto args = command_line.GetArgs();
if (args.size() > 0) {
auto packages =
command_line.GetSwitchValueASCII(sky::shell::switches::kPackages);
_sky_engine->RunFromFile(args[0], packages, "");
return;
}
_platform_view->SetupAndLoadDart();
}
- (void)windowDidResize:(NSNotification*)notification {
......@@ -132,7 +79,8 @@ static inline pointer::PointerType EventTypeFromNSEventPhase(
metrics->physical_width = size.width;
metrics->physical_height = size.height;
metrics->device_pixel_ratio = 1.0;
_sky_engine->OnViewportMetricsChanged(metrics.Pass());
_platform_view->engineProxy()->OnViewportMetricsChanged(metrics.Pass());
}
- (void)setupSurfaceIfNecessary {
......@@ -181,7 +129,7 @@ static inline pointer::PointerType EventTypeFromNSEventPhase(
auto pointer_packet = pointer::PointerPacket::New();
pointer_packet->pointers.push_back(pointer_data.Pass());
_sky_engine->OnPointerPacket(pointer_packet.Pass());
_platform_view->engineProxy()->OnPointerPacket(pointer_packet.Pass());
}
- (void)mouseDown:(NSEvent*)event {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册