mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Remove the unused Mac Desktop shell. (#6314)
This shell used to serve the dual purpose of running Flutter tests as well as optionally being able to run Flutter applications on a Mac desktop. After all the test runner targets were consolidated (flutter_tester), this target was no longer used to run the tests. This target is currently only used by engine developers to test changes quickly on the host. Even for this purpose, the Desktop embedders are more full featured and use the stable embedder API. The presence of a cross-platform tester target, alternatives for Desktop targets that use the stable embedder API and the fact that this target is no longer tested, makes having this code in the source entirely redundant.
This commit is contained in:
parent
57fd394e59
commit
e82db8668d
@ -200,7 +200,6 @@ FILE: ../../../flutter/lib/ui/window/window.h
|
||||
FILE: ../../../flutter/shell/common/skia_event_tracer_impl.cc
|
||||
FILE: ../../../flutter/shell/platform/android/apk_asset_provider.cc
|
||||
FILE: ../../../flutter/shell/platform/android/io/flutter/plugin/common/JSONUtil.java
|
||||
FILE: ../../../flutter/shell/platform/darwin/desktop/Info.plist
|
||||
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Flutter.podspec
|
||||
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Info.plist
|
||||
FILE: ../../../flutter/shell/platform/darwin/ios/framework/module.modulemap
|
||||
@ -271,8 +270,6 @@ FILE: ../../../flutter/shell/common/thread_host.cc
|
||||
FILE: ../../../flutter/shell/common/thread_host.h
|
||||
FILE: ../../../flutter/shell/platform/darwin/common/command_line.h
|
||||
FILE: ../../../flutter/shell/platform/darwin/common/command_line.mm
|
||||
FILE: ../../../flutter/shell/platform/darwin/desktop/flutter_application_delegate.h
|
||||
FILE: ../../../flutter/shell/platform/darwin/desktop/flutter_application_delegate.mm
|
||||
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController_Internal.h
|
||||
FILE: ../../../flutter/shell/platform/embedder/embedder.h
|
||||
FILE: ../../../flutter/shell/platform/embedder/embedder_engine.cc
|
||||
@ -382,7 +379,6 @@ FILE: ../../../flutter/shell/platform/android/io/flutter/view/VsyncWaiter.java
|
||||
FILE: ../../../flutter/shell/platform/android/vsync_waiter_android.cc
|
||||
FILE: ../../../flutter/shell/platform/android/vsync_waiter_android.h
|
||||
FILE: ../../../flutter/shell/platform/darwin/common/buffer_conversions.mm
|
||||
FILE: ../../../flutter/shell/platform/darwin/desktop/vsync_waiter_mac.h
|
||||
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Headers/Flutter.h
|
||||
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Headers/FlutterAppDelegate.h
|
||||
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Headers/FlutterDartProject.h
|
||||
@ -837,12 +833,6 @@ FILE: ../../../flutter/shell/platform/android/library_loader.cc
|
||||
FILE: ../../../flutter/shell/platform/android/platform_view_android.cc
|
||||
FILE: ../../../flutter/shell/platform/android/platform_view_android.h
|
||||
FILE: ../../../flutter/shell/platform/darwin/common/buffer_conversions.h
|
||||
FILE: ../../../flutter/shell/platform/darwin/desktop/flutter_window.h
|
||||
FILE: ../../../flutter/shell/platform/darwin/desktop/flutter_window.mm
|
||||
FILE: ../../../flutter/shell/platform/darwin/desktop/main_mac.mm
|
||||
FILE: ../../../flutter/shell/platform/darwin/desktop/platform_view_mac.h
|
||||
FILE: ../../../flutter/shell/platform/darwin/desktop/platform_view_mac.mm
|
||||
FILE: ../../../flutter/shell/platform/darwin/desktop/vsync_waiter_mac.cc
|
||||
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/FlutterAppDelegate.mm
|
||||
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/vsync_waiter_ios.h
|
||||
FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/vsync_waiter_ios.mm
|
||||
|
||||
@ -5,18 +5,10 @@
|
||||
assert(is_mac || is_ios)
|
||||
|
||||
group("darwin") {
|
||||
if (is_mac) {
|
||||
if (!is_fuchsia_host) {
|
||||
deps = [
|
||||
"desktop:shell_application_bundle",
|
||||
]
|
||||
}
|
||||
} else if (is_ios) {
|
||||
if (is_ios) {
|
||||
deps = [
|
||||
"ios:flutter_framework",
|
||||
]
|
||||
} else {
|
||||
assert(false, "Unknown darwin platform type.")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,64 +0,0 @@
|
||||
# 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.
|
||||
|
||||
assert(is_mac)
|
||||
|
||||
import("$flutter_root/shell/gpu/gpu.gni")
|
||||
|
||||
shell_gpu_configuration("darwin_desktop_gpu_configuration") {
|
||||
enable_software = false
|
||||
enable_vulkan = false
|
||||
enable_gl = true
|
||||
}
|
||||
|
||||
source_set("mac_desktop_platform") {
|
||||
visibility = [ ":*" ]
|
||||
|
||||
sources = [
|
||||
"flutter_application_delegate.h",
|
||||
"flutter_application_delegate.mm",
|
||||
"flutter_window.h",
|
||||
"flutter_window.mm",
|
||||
"main_mac.mm",
|
||||
"platform_view_mac.h",
|
||||
"platform_view_mac.mm",
|
||||
"vsync_waiter_mac.cc",
|
||||
"vsync_waiter_mac.h",
|
||||
]
|
||||
|
||||
deps = [
|
||||
":darwin_desktop_gpu_configuration",
|
||||
"$flutter_root/common",
|
||||
"$flutter_root/fml",
|
||||
"$flutter_root/lib/snapshot",
|
||||
"$flutter_root/shell/common",
|
||||
"$flutter_root/shell/platform/darwin/common",
|
||||
"$flutter_root/synchronization",
|
||||
"//third_party/dart/runtime:libdart_jit",
|
||||
"//third_party/skia",
|
||||
"//third_party/skia:gpu",
|
||||
]
|
||||
|
||||
public_configs = [ "$flutter_root:config" ]
|
||||
}
|
||||
|
||||
if (!is_fuchsia_host) {
|
||||
import("//build/config/mac/rules.gni")
|
||||
|
||||
resource_copy_mac("mac_desktop_resources") {
|
||||
app_name = "FlutterTester"
|
||||
resources = [ "//third_party/icu/flutter/icudtl.dat" ]
|
||||
bundle_directory = "."
|
||||
}
|
||||
|
||||
mac_app("shell_application_bundle") {
|
||||
app_name = "FlutterTester"
|
||||
info_plist = "Info.plist"
|
||||
|
||||
deps = [
|
||||
":mac_desktop_platform",
|
||||
":mac_desktop_resources",
|
||||
]
|
||||
}
|
||||
}
|
||||
@ -1,32 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>en</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>FlutterTester</string>
|
||||
<key>CFBundleIconFile</key>
|
||||
<string></string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>io.flutter.engine</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>Flutter Engine</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.0</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1</string>
|
||||
<key>LSMinimumSystemVersion</key>
|
||||
<string>10.6</string>
|
||||
<key>NSHumanReadableCopyright</key>
|
||||
<string>Copyright 2015 The Flutter Authors. All rights reserved.</string>
|
||||
<key>NSPrincipalClass</key>
|
||||
<string>NSApplication</string>
|
||||
</dict>
|
||||
</plist>
|
||||
@ -1,14 +0,0 @@
|
||||
// Copyright 2017 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef FLUTTER_SHELL_PLATFORM_DARWIN_DESKTOP_FLUTTER_APPLICATION_DELEGATE_H_
|
||||
#define FLUTTER_SHELL_PLATFORM_DARWIN_DESKTOP_FLUTTER_APPLICATION_DELEGATE_H_
|
||||
|
||||
#import <AppKit/AppKit.h>
|
||||
|
||||
@interface FlutterApplicationDelegate : NSObject<NSApplicationDelegate>
|
||||
|
||||
@end
|
||||
|
||||
#endif // FLUTTER_SHELL_PLATFORM_DARWIN_DESKTOP_FLUTTER_APPLICATION_DELEGATE_H_
|
||||
@ -1,80 +0,0 @@
|
||||
// Copyright 2017 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "flutter/shell/platform/darwin/desktop/flutter_application_delegate.h"
|
||||
#include "flutter/shell/platform/darwin/desktop/flutter_window.h"
|
||||
|
||||
#include <AppKit/AppKit.h>
|
||||
|
||||
@implementation FlutterApplicationDelegate
|
||||
|
||||
- (void)applicationWillFinishLaunching:(NSNotification*)notification {
|
||||
[self configureMainMenuBar];
|
||||
[self onNewFlutterWindow:self];
|
||||
}
|
||||
|
||||
- (void)configureMainMenuBar {
|
||||
NSMenu* mainMenu = [[[NSMenu alloc] initWithTitle:@"MainMenu"] autorelease];
|
||||
|
||||
NSMenuItem* engineItem =
|
||||
[[[NSMenuItem alloc] initWithTitle:@"Engine" action:NULL keyEquivalent:@""] autorelease];
|
||||
|
||||
NSMenu* engineMenu = [[[NSMenu alloc] initWithTitle:@"EngineMenu"] autorelease];
|
||||
|
||||
NSMenuItem* newEngineItem = [[[NSMenuItem alloc] initWithTitle:@"New Engine"
|
||||
action:@selector(onNewFlutterWindow:)
|
||||
keyEquivalent:@""] autorelease];
|
||||
newEngineItem.keyEquivalent = @"n";
|
||||
newEngineItem.keyEquivalentModifierMask = NSEventModifierFlagCommand;
|
||||
|
||||
NSMenuItem* shutdownEngineItem =
|
||||
[[[NSMenuItem alloc] initWithTitle:@"Shutdown Engine"
|
||||
action:@selector(onShutdownFlutterWindow:)
|
||||
keyEquivalent:@""] autorelease];
|
||||
shutdownEngineItem.keyEquivalent = @"w";
|
||||
shutdownEngineItem.keyEquivalentModifierMask = NSEventModifierFlagCommand;
|
||||
|
||||
NSMenuItem* quitItem = [[[NSMenuItem alloc] initWithTitle:@"Quit"
|
||||
action:@selector(onQuitFlutterApplication:)
|
||||
keyEquivalent:@""] autorelease];
|
||||
quitItem.keyEquivalent = @"q";
|
||||
quitItem.keyEquivalentModifierMask = NSEventModifierFlagCommand;
|
||||
|
||||
[mainMenu addItem:engineItem];
|
||||
[engineItem setSubmenu:engineMenu];
|
||||
[engineMenu addItem:newEngineItem];
|
||||
[engineMenu addItem:shutdownEngineItem];
|
||||
[engineMenu addItem:quitItem];
|
||||
|
||||
[NSApplication sharedApplication].mainMenu = mainMenu;
|
||||
}
|
||||
|
||||
- (void)onNewFlutterWindow:(id)sender {
|
||||
FlutterWindow* window = [[FlutterWindow alloc] init];
|
||||
[window setReleasedWhenClosed:YES];
|
||||
|
||||
NSWindow* currentKeyWindow = [NSApplication sharedApplication].keyWindow;
|
||||
|
||||
if (currentKeyWindow == nil) {
|
||||
[window center];
|
||||
} else {
|
||||
[window center];
|
||||
NSPoint currentWindowFrameOrigin = window.frame.origin;
|
||||
currentWindowFrameOrigin.x = currentKeyWindow.frame.origin.x + 20;
|
||||
currentWindowFrameOrigin.y = currentKeyWindow.frame.origin.y - 20;
|
||||
[window setFrameOrigin:currentWindowFrameOrigin];
|
||||
}
|
||||
|
||||
[window makeKeyAndOrderFront:sender];
|
||||
}
|
||||
|
||||
- (void)onShutdownFlutterWindow:(id)sender {
|
||||
[[NSApplication sharedApplication].keyWindow close];
|
||||
}
|
||||
|
||||
- (void)onQuitFlutterApplication:(id)sender {
|
||||
exit(0);
|
||||
}
|
||||
|
||||
@end
|
||||
@ -1,14 +0,0 @@
|
||||
// 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.
|
||||
|
||||
#ifndef SHELL_PLATFORM_DARWIN_DESKTOP_FLUTTER_WINDOW_H_
|
||||
#define SHELL_PLATFORM_DARWIN_DESKTOP_FLUTTER_WINDOW_H_
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
@interface FlutterWindow : NSWindow
|
||||
|
||||
@end
|
||||
|
||||
#endif // SHELL_PLATFORM_DARWIN_DESKTOP_FLUTTER_WINDOW_H_
|
||||
@ -1,271 +0,0 @@
|
||||
// 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.
|
||||
|
||||
#define FML_USED_ON_EMBEDDER
|
||||
|
||||
#import "flutter_window.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include "flutter/common/task_runners.h"
|
||||
#include "flutter/fml/make_copyable.h"
|
||||
#include "flutter/fml/message_loop.h"
|
||||
#include "flutter/shell/common/rasterizer.h"
|
||||
#include "flutter/shell/common/switches.h"
|
||||
#include "flutter/shell/common/thread_host.h"
|
||||
#include "flutter/shell/gpu/gpu_surface_gl.h"
|
||||
#include "flutter/shell/platform/darwin/common/command_line.h"
|
||||
#include "flutter/shell/platform/darwin/desktop/platform_view_mac.h"
|
||||
|
||||
@interface FlutterWindow () <NSWindowDelegate>
|
||||
|
||||
@property(strong) NSOpenGLView* renderSurface;
|
||||
|
||||
@end
|
||||
|
||||
static inline blink::PointerData::Change PointerChangeFromNSEventPhase(NSEventPhase phase) {
|
||||
switch (phase) {
|
||||
case NSEventPhaseNone:
|
||||
return blink::PointerData::Change::kCancel;
|
||||
case NSEventPhaseBegan:
|
||||
return blink::PointerData::Change::kDown;
|
||||
case NSEventPhaseStationary:
|
||||
// There is no EVENT_TYPE_POINTER_STATIONARY. So we just pass a move type
|
||||
// with the same coordinates
|
||||
case NSEventPhaseChanged:
|
||||
return blink::PointerData::Change::kMove;
|
||||
case NSEventPhaseEnded:
|
||||
return blink::PointerData::Change::kUp;
|
||||
case NSEventPhaseCancelled:
|
||||
return blink::PointerData::Change::kCancel;
|
||||
case NSEventPhaseMayBegin:
|
||||
return blink::PointerData::Change::kCancel;
|
||||
}
|
||||
return blink::PointerData::Change::kCancel;
|
||||
}
|
||||
|
||||
@implementation FlutterWindow {
|
||||
shell::ThreadHost _thread_host;
|
||||
std::unique_ptr<shell::Shell> _shell;
|
||||
bool _mouseIsDown;
|
||||
}
|
||||
|
||||
- (instancetype)init {
|
||||
self = [super initWithContentRect:NSMakeRect(10.0, 10.0, 800.0, 600.0)
|
||||
styleMask:NSWindowStyleMaskTitled | NSWindowStyleMaskClosable |
|
||||
NSWindowStyleMaskResizable
|
||||
backing:NSBackingStoreBuffered
|
||||
defer:YES];
|
||||
if (self) {
|
||||
self.delegate = self;
|
||||
[self setupRenderSurface];
|
||||
[self setupShell];
|
||||
[self updateWindowSize];
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)setupRenderSurface {
|
||||
NSOpenGLView* renderSurface = [[[NSOpenGLView alloc] init] autorelease];
|
||||
const NSOpenGLPixelFormatAttribute attrs[] = {
|
||||
NSOpenGLPFADoubleBuffer, //
|
||||
NSOpenGLPFAAllowOfflineRenderers, //
|
||||
0 //
|
||||
};
|
||||
renderSurface.pixelFormat = [[[NSOpenGLPixelFormat alloc] initWithAttributes:attrs] autorelease];
|
||||
renderSurface.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
|
||||
renderSurface.frame =
|
||||
NSMakeRect(0.0, 0.0, self.contentView.bounds.size.width, self.contentView.bounds.size.height);
|
||||
[self.contentView addSubview:renderSurface];
|
||||
self.renderSurface = renderSurface;
|
||||
}
|
||||
|
||||
static std::string CreateThreadLabel() {
|
||||
std::stringstream stream;
|
||||
static int index = 1;
|
||||
stream << "io.flutter." << index++;
|
||||
return stream.str();
|
||||
}
|
||||
|
||||
- (void)setupShell {
|
||||
FML_DCHECK(!_shell) << "The shell must not already be set.";
|
||||
|
||||
auto thread_label = CreateThreadLabel();
|
||||
|
||||
// Create the threads on which to run the shell.
|
||||
_thread_host = {thread_label, shell::ThreadHost::Type::GPU | shell::ThreadHost::Type::UI |
|
||||
shell::ThreadHost::Type::IO};
|
||||
|
||||
// Grab the task runners for the newly created threads.
|
||||
fml::MessageLoop::EnsureInitializedForCurrentThread();
|
||||
blink::TaskRunners task_runners(thread_label, // label
|
||||
fml::MessageLoop::GetCurrent().GetTaskRunner(), // platform
|
||||
_thread_host.gpu_thread->GetTaskRunner(), // GPU
|
||||
_thread_host.ui_thread->GetTaskRunner(), // UI
|
||||
_thread_host.io_thread->GetTaskRunner() // IO
|
||||
);
|
||||
|
||||
// Figure out the settings from the command line arguments.
|
||||
auto settings = shell::SettingsFromCommandLine(shell::CommandLineFromNSProcessInfo());
|
||||
|
||||
if (settings.icu_data_path.size() == 0) {
|
||||
settings.icu_data_path =
|
||||
[[NSBundle mainBundle] pathForResource:@"icudtl.dat" ofType:@""].UTF8String;
|
||||
}
|
||||
|
||||
settings.task_observer_add = [](intptr_t key, fml::closure callback) {
|
||||
fml::MessageLoop::GetCurrent().AddTaskObserver(key, std::move(callback));
|
||||
};
|
||||
|
||||
settings.task_observer_remove = [](intptr_t key) {
|
||||
fml::MessageLoop::GetCurrent().RemoveTaskObserver(key);
|
||||
};
|
||||
|
||||
// Setup the callback that will be run on the appropriate threads.
|
||||
shell::Shell::CreateCallback<shell::PlatformView> on_create_platform_view =
|
||||
[render_surface = self.renderSurface](shell::Shell& shell) {
|
||||
return std::make_unique<shell::PlatformViewMac>(shell, render_surface);
|
||||
};
|
||||
|
||||
shell::Shell::CreateCallback<shell::Rasterizer> on_create_rasterizer = [](shell::Shell& shell) {
|
||||
return std::make_unique<shell::Rasterizer>(shell.GetTaskRunners());
|
||||
};
|
||||
|
||||
// Finally, create the shell.
|
||||
_shell = shell::Shell::Create(std::move(task_runners), settings, on_create_platform_view,
|
||||
on_create_rasterizer);
|
||||
|
||||
// Launch the engine with the inferred run configuration.
|
||||
_shell->GetTaskRunners().GetUITaskRunner()->PostTask(fml::MakeCopyable(
|
||||
[engine = _shell->GetEngine(),
|
||||
config = shell::RunConfiguration::InferFromSettings(_shell->GetSettings())]() mutable {
|
||||
if (engine) {
|
||||
auto result = engine->Run(std::move(config));
|
||||
if (!result) {
|
||||
FML_LOG(ERROR) << "Could not launch the engine with configuration.";
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
[self notifySurfaceCreated];
|
||||
}
|
||||
|
||||
- (void)notifySurfaceCreated {
|
||||
if (!_shell || !_shell->IsSetup()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Tell the platform view that it has a GL surface.
|
||||
_shell->GetPlatformView()->NotifyCreated();
|
||||
}
|
||||
|
||||
- (void)notifySurfaceDestroyed {
|
||||
if (!_shell || !_shell->IsSetup()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Tell the platform view that its surface is about to be lost.
|
||||
_shell->GetPlatformView()->NotifyDestroyed();
|
||||
}
|
||||
|
||||
- (void)windowDidResize:(NSNotification*)notification {
|
||||
[self updateWindowSize];
|
||||
}
|
||||
|
||||
- (void)updateWindowSize {
|
||||
if (!_shell) {
|
||||
return;
|
||||
}
|
||||
|
||||
blink::ViewportMetrics metrics;
|
||||
auto size = self.renderSurface.frame.size;
|
||||
metrics.physical_width = size.width;
|
||||
metrics.physical_height = size.height;
|
||||
_shell->GetTaskRunners().GetUITaskRunner()->PostTask([engine = _shell->GetEngine(), metrics]() {
|
||||
if (engine) {
|
||||
engine->SetViewportMetrics(metrics);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
#pragma mark - Responder overrides
|
||||
|
||||
- (void)dispatchEvent:(NSEvent*)event phase:(NSEventPhase)phase {
|
||||
if (!_shell) {
|
||||
return;
|
||||
}
|
||||
|
||||
NSPoint location = [_renderSurface convertPoint:event.locationInWindow fromView:nil];
|
||||
location.y = _renderSurface.frame.size.height - location.y;
|
||||
|
||||
blink::PointerData pointer_data;
|
||||
pointer_data.Clear();
|
||||
|
||||
constexpr int kMicrosecondsPerSecond = 1000 * 1000;
|
||||
pointer_data.time_stamp = event.timestamp * kMicrosecondsPerSecond;
|
||||
pointer_data.change = PointerChangeFromNSEventPhase(phase);
|
||||
pointer_data.kind = blink::PointerData::DeviceKind::kMouse;
|
||||
pointer_data.physical_x = location.x;
|
||||
pointer_data.physical_y = location.y;
|
||||
pointer_data.pressure = 1.0;
|
||||
pointer_data.pressure_max = 1.0;
|
||||
|
||||
switch (pointer_data.change) {
|
||||
case blink::PointerData::Change::kDown:
|
||||
_mouseIsDown = true;
|
||||
break;
|
||||
case blink::PointerData::Change::kCancel:
|
||||
case blink::PointerData::Change::kUp:
|
||||
_mouseIsDown = false;
|
||||
break;
|
||||
case blink::PointerData::Change::kMove:
|
||||
if (!_mouseIsDown)
|
||||
pointer_data.change = blink::PointerData::Change::kHover;
|
||||
break;
|
||||
case blink::PointerData::Change::kAdd:
|
||||
case blink::PointerData::Change::kRemove:
|
||||
case blink::PointerData::Change::kHover:
|
||||
FML_DCHECK(!_mouseIsDown);
|
||||
break;
|
||||
}
|
||||
|
||||
_shell->GetTaskRunners().GetUITaskRunner()->PostTask(
|
||||
[engine = _shell->GetEngine(), pointer_data] {
|
||||
if (engine) {
|
||||
blink::PointerDataPacket packet(1);
|
||||
packet.SetPointerData(0, pointer_data);
|
||||
engine->DispatchPointerDataPacket(packet);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
- (void)mouseDown:(NSEvent*)event {
|
||||
[self dispatchEvent:event phase:NSEventPhaseBegan];
|
||||
}
|
||||
|
||||
- (void)mouseDragged:(NSEvent*)event {
|
||||
[self dispatchEvent:event phase:NSEventPhaseChanged];
|
||||
}
|
||||
|
||||
- (void)mouseUp:(NSEvent*)event {
|
||||
[self dispatchEvent:event phase:NSEventPhaseEnded];
|
||||
}
|
||||
|
||||
- (void)reset {
|
||||
[self notifySurfaceDestroyed];
|
||||
_shell.reset();
|
||||
_thread_host.Reset();
|
||||
}
|
||||
|
||||
- (void)windowWillClose:(NSNotification*)notification {
|
||||
[self reset];
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
[self reset];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
@end
|
||||
@ -1,34 +0,0 @@
|
||||
// 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 <Cocoa/Cocoa.h>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "flutter/fml/command_line.h"
|
||||
#include "flutter/fml/logging.h"
|
||||
#include "flutter/fml/message_loop.h"
|
||||
#include "flutter/shell/common/shell.h"
|
||||
#include "flutter/shell/common/switches.h"
|
||||
#include "flutter/shell/platform/darwin/desktop/flutter_application_delegate.h"
|
||||
|
||||
int main(int argc, const char* argv[]) {
|
||||
std::vector<std::string> args_vector;
|
||||
|
||||
for (NSString* arg in [NSProcessInfo processInfo].arguments) {
|
||||
args_vector.emplace_back(arg.UTF8String);
|
||||
}
|
||||
|
||||
auto command_line = fml::CommandLineFromIterators(args_vector.begin(), args_vector.end());
|
||||
|
||||
// Print help.
|
||||
if (command_line.HasOption(shell::FlagForSwitch(shell::Switch::Help))) {
|
||||
shell::PrintUsage([NSProcessInfo processInfo].processName.UTF8String);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
[NSApplication sharedApplication].delegate =
|
||||
[[[FlutterApplicationDelegate alloc] init] autorelease];
|
||||
return NSApplicationMain(argc, argv);
|
||||
}
|
||||
@ -1,52 +0,0 @@
|
||||
// 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.
|
||||
|
||||
#ifndef SHELL_PLATFORM_MAC_PLATFORM_VIEW_MAC_H_
|
||||
#define SHELL_PLATFORM_MAC_PLATFORM_VIEW_MAC_H_
|
||||
|
||||
#include "flutter/fml/memory/weak_ptr.h"
|
||||
#include "flutter/fml/platform/darwin/scoped_nsobject.h"
|
||||
#include "flutter/shell/common/platform_view.h"
|
||||
#include "flutter/shell/common/shell.h"
|
||||
#include "flutter/shell/gpu/gpu_surface_gl.h"
|
||||
|
||||
@class NSOpenGLView;
|
||||
@class NSOpenGLContext;
|
||||
|
||||
namespace shell {
|
||||
|
||||
class PlatformViewMac final : public PlatformView, public GPUSurfaceGLDelegate {
|
||||
public:
|
||||
PlatformViewMac(Shell& shell, NSOpenGLView* gl_view);
|
||||
|
||||
~PlatformViewMac() override;
|
||||
|
||||
std::unique_ptr<VsyncWaiter> CreateVSyncWaiter() override;
|
||||
|
||||
bool GLContextMakeCurrent() override;
|
||||
|
||||
bool GLContextClearCurrent() override;
|
||||
|
||||
bool GLContextPresent() override;
|
||||
|
||||
intptr_t GLContextFBO() const override;
|
||||
|
||||
private:
|
||||
fml::scoped_nsobject<NSOpenGLView> opengl_view_;
|
||||
fml::scoped_nsobject<NSOpenGLContext> resource_loading_context_;
|
||||
|
||||
bool IsValid() const;
|
||||
|
||||
// |shell::PlatformView|
|
||||
std::unique_ptr<Surface> CreateRenderingSurface() override;
|
||||
|
||||
// |shell::PlatformView|
|
||||
sk_sp<GrContext> CreateResourceContext() const override;
|
||||
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(PlatformViewMac);
|
||||
};
|
||||
|
||||
} // namespace shell
|
||||
|
||||
#endif // SHELL_PLATFORM_MAC_PLATFORM_VIEW_MAC_H_
|
||||
@ -1,90 +0,0 @@
|
||||
// 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.
|
||||
|
||||
#include "flutter/shell/platform/darwin/desktop/platform_view_mac.h"
|
||||
|
||||
#include <AppKit/AppKit.h>
|
||||
#include <Foundation/Foundation.h>
|
||||
|
||||
#include "flutter/fml/command_line.h"
|
||||
#include "flutter/fml/synchronization/waitable_event.h"
|
||||
#include "flutter/fml/trace_event.h"
|
||||
#include "flutter/shell/common/io_manager.h"
|
||||
#include "flutter/shell/common/rasterizer.h"
|
||||
#include "flutter/shell/common/switches.h"
|
||||
#include "flutter/shell/platform/darwin/desktop/vsync_waiter_mac.h"
|
||||
|
||||
namespace shell {
|
||||
|
||||
PlatformViewMac::PlatformViewMac(Shell& shell, NSOpenGLView* gl_view)
|
||||
: PlatformView(shell, shell.GetTaskRunners()),
|
||||
opengl_view_([gl_view retain]),
|
||||
resource_loading_context_([[NSOpenGLContext alloc] initWithFormat:gl_view.pixelFormat
|
||||
shareContext:gl_view.openGLContext]) {}
|
||||
|
||||
PlatformViewMac::~PlatformViewMac() = default;
|
||||
|
||||
std::unique_ptr<VsyncWaiter> PlatformViewMac::CreateVSyncWaiter() {
|
||||
return std::make_unique<VsyncWaiterMac>(task_runners_);
|
||||
}
|
||||
|
||||
intptr_t PlatformViewMac::GLContextFBO() const {
|
||||
// Default window bound framebuffer FBO 0.
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool PlatformViewMac::GLContextMakeCurrent() {
|
||||
TRACE_EVENT0("flutter", "PlatformViewMac::GLContextMakeCurrent");
|
||||
if (!IsValid()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
[opengl_view_.get().openGLContext makeCurrentContext];
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PlatformViewMac::GLContextClearCurrent() {
|
||||
TRACE_EVENT0("flutter", "PlatformViewMac::GLContextClearCurrent");
|
||||
if (!IsValid()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
[NSOpenGLContext clearCurrentContext];
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PlatformViewMac::GLContextPresent() {
|
||||
TRACE_EVENT0("flutter", "PlatformViewMac::GLContextPresent");
|
||||
if (!IsValid()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
[opengl_view_.get().openGLContext flushBuffer];
|
||||
return true;
|
||||
}
|
||||
|
||||
sk_sp<GrContext> PlatformViewMac::CreateResourceContext() const {
|
||||
[resource_loading_context_.get() makeCurrentContext];
|
||||
return IOManager::CreateCompatibleResourceLoadingContext(GrBackend::kOpenGL_GrBackend);
|
||||
}
|
||||
|
||||
bool PlatformViewMac::IsValid() const {
|
||||
if (opengl_view_ == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto context = opengl_view_.get().openGLContext;
|
||||
|
||||
if (context == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
std::unique_ptr<Surface> PlatformViewMac::CreateRenderingSurface() {
|
||||
return std::make_unique<GPUSurfaceGL>(this);
|
||||
}
|
||||
|
||||
} // namespace shell
|
||||
@ -1,58 +0,0 @@
|
||||
// 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.
|
||||
|
||||
#include "flutter/shell/platform/darwin/desktop/vsync_waiter_mac.h"
|
||||
|
||||
#include <CoreVideo/CoreVideo.h>
|
||||
|
||||
#include "flutter/fml/logging.h"
|
||||
|
||||
namespace shell {
|
||||
|
||||
#define link_ (reinterpret_cast<CVDisplayLinkRef>(opaque_))
|
||||
|
||||
VsyncWaiterMac::VsyncWaiterMac(blink::TaskRunners task_runners)
|
||||
: VsyncWaiter(std::move(task_runners)), opaque_(nullptr) {
|
||||
// Create the link.
|
||||
CVDisplayLinkRef link = nullptr;
|
||||
CVDisplayLinkCreateWithActiveCGDisplays(&link);
|
||||
opaque_ = link;
|
||||
|
||||
// Set the output callback.
|
||||
CVDisplayLinkSetOutputCallback(
|
||||
link_,
|
||||
[](CVDisplayLinkRef link, const CVTimeStamp* now,
|
||||
const CVTimeStamp* output, CVOptionFlags flags_in,
|
||||
CVOptionFlags* flags_out, void* context) -> CVReturn {
|
||||
OnDisplayLink(context);
|
||||
return kCVReturnSuccess;
|
||||
},
|
||||
this);
|
||||
}
|
||||
|
||||
VsyncWaiterMac::~VsyncWaiterMac() {
|
||||
CVDisplayLinkRelease(link_);
|
||||
}
|
||||
|
||||
void VsyncWaiterMac::OnDisplayLink(void* context) {
|
||||
reinterpret_cast<VsyncWaiterMac*>(context)->OnDisplayLink();
|
||||
}
|
||||
|
||||
void VsyncWaiterMac::OnDisplayLink() {
|
||||
fml::TimePoint frame_start_time = fml::TimePoint::Now();
|
||||
fml::TimePoint frame_target_time =
|
||||
frame_start_time +
|
||||
fml::TimeDelta::FromSecondsF(
|
||||
CVDisplayLinkGetActualOutputVideoRefreshPeriod(link_));
|
||||
|
||||
CVDisplayLinkStop(link_);
|
||||
|
||||
FireCallback(frame_start_time, frame_target_time);
|
||||
}
|
||||
|
||||
void VsyncWaiterMac::AwaitVSync() {
|
||||
CVDisplayLinkStart(link_);
|
||||
}
|
||||
|
||||
} // namespace shell
|
||||
@ -1,33 +0,0 @@
|
||||
// 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.
|
||||
|
||||
#ifndef FLUTTER_SHELL_PLATFORM_DARWIN_DESKTOP_VSYNC_WAITER_MAC_H_
|
||||
#define FLUTTER_SHELL_PLATFORM_DARWIN_DESKTOP_VSYNC_WAITER_MAC_H_
|
||||
|
||||
#include "flutter/fml/macros.h"
|
||||
#include "flutter/shell/common/vsync_waiter.h"
|
||||
|
||||
namespace shell {
|
||||
|
||||
class VsyncWaiterMac final : public VsyncWaiter {
|
||||
public:
|
||||
VsyncWaiterMac(blink::TaskRunners task_runners);
|
||||
|
||||
~VsyncWaiterMac() override;
|
||||
|
||||
private:
|
||||
void* opaque_;
|
||||
|
||||
void AwaitVSync() override;
|
||||
|
||||
static void OnDisplayLink(void* context);
|
||||
|
||||
void OnDisplayLink();
|
||||
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(VsyncWaiterMac);
|
||||
};
|
||||
|
||||
} // namespace shell
|
||||
|
||||
#endif // FLUTTER_SHELL_PLATFORM_DARWIN_DESKTOP_VSYNC_WAITER_MAC_H_
|
||||
Loading…
x
Reference in New Issue
Block a user