diff --git a/sky/shell/BUILD.gn b/sky/shell/BUILD.gn index ae169d3a4e85d2f862d16e4d3e9f446848726623..ac847120abd8315ceeaf1b02ee909454cd0710bb 100644 --- a/sky/shell/BUILD.gn +++ b/sky/shell/BUILD.gn @@ -158,9 +158,6 @@ if (is_android) { source_set(scaffolding_target) { sources = [ "ios/main_ios.mm", - "ios/platform_service_provider_ios.cc", - "ios/platform_view_ios.h", - "ios/platform_view_ios.mm", "ios/sky_app_delegate.h", "ios/sky_app_delegate.mm", "ios/sky_surface.h", @@ -169,10 +166,20 @@ if (is_android) { "ios/sky_view_controller.mm", ] + set_sources_assignment_filter([]) + sources += [ + "mac/platform_mac.h", + "mac/platform_mac.mm", + "mac/platform_service_provider_mac.cc", + "mac/platform_view_mac.h", + "mac/platform_view_mac.mm", + ] + set_sources_assignment_filter(sources_assignment_filter) + deps = common_deps + [ - ":common", - "//sky/services/ns_net", - ] + ":common", + "//sky/services/ns_net", + ] } deps = [ @@ -193,9 +200,57 @@ if (is_android) { ] deps = common_deps + [ - ":common", - "//sky/services/testing:interfaces", - ] + ":common", + "//sky/services/testing:interfaces", + ] + } +} else if (is_mac) { + import("//build/config/mac/rules.gni") + + mac_app("shell") { + app_name = "Sky" + info_plist = "mac/Info.plist" + scaffolding_target = "mac_scaffolding" + + # entitlements_path = "" + # code_signing_identity = "" + + xibs = [ + "mac/sky_mac.xib" + ] + + resource_copy_mac("sky_resources") { + resources = [ "//third_party/icu/android/icudtl.dat" ] + bundle_directory = "." + } + + source_set(scaffolding_target) { + sources = [ + "mac/main_mac.mm", + "mac/platform_mac.h", + "mac/platform_mac.mm", + "mac/platform_service_provider_mac.cc", + "mac/platform_view_mac.h", + "mac/platform_view_mac.mm", + "mac/sky_app_delegate.h", + "mac/sky_app_delegate.m", + "mac/sky_window.h", + "mac/sky_window.mm", + "testing/test_runner.cc", + "testing/test_runner.h", + ] + + deps = common_deps + [ + ":common", + "//sky/services/ns_net", + "//sky/services/testing:interfaces", + ] + } + + deps = [ + ":$scaffolding_target", + ":sky_resources", + ] } } else { assert(false, "Unsupported platform") diff --git a/sky/shell/ios/main_ios.mm b/sky/shell/ios/main_ios.mm index b0eb2042a8ad8fc219a1c37ab46e7ed65a7f1275..524b89f5b9a26e6f6beca8401e20d766dab5970e 100644 --- a/sky/shell/ios/main_ios.mm +++ b/sky/shell/ios/main_ios.mm @@ -3,14 +3,9 @@ // found in the LICENSE file. #import -#include -#import "sky_app_delegate.h" -#include "base/at_exit.h" -#include "base/logging.h" -#include "base/i18n/icu_util.h" -#include "base/command_line.h" -#include "base/mac/scoped_nsautorelease_pool.h" -#include "ui/gl/gl_surface.h" +#import "sky/shell/ios/sky_app_delegate.h" + +#include "sky/shell/mac/platform_mac.h" extern "C" { // TODO(csg): HACK! boringssl accesses this on Android using a weak symbol @@ -22,49 +17,9 @@ unsigned long getauxval(unsigned long type) { } } -static void InitializeLogging() { - logging::LoggingSettings settings; - settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; - logging::InitLogging(settings); - logging::SetLogItems(false, // Process ID - false, // Thread ID - false, // Timestamp - false); // Tick count -} - -static void RedirectIOConnectionsToSyslog() { - asl_log_descriptor(NULL, NULL, ASL_LEVEL_INFO, STDOUT_FILENO, - ASL_LOG_DESCRIPTOR_WRITE); - asl_log_descriptor(NULL, NULL, ASL_LEVEL_NOTICE, STDERR_FILENO, - ASL_LOG_DESCRIPTOR_WRITE); -} - -#ifndef NDEBUG - -static void SkyDebuggerHookMain(void) { - // By default, LLDB breaks way too early. This is before libraries have been - // loaded and __attribute__((constructor)) methods have been called. In most - // situations, this is unnecessary. Also, breakpoint resolution is not - // immediate. So we provide this hook to break on. -} - -#endif - -int main(int argc, char* argv[]) { -#ifndef NDEBUG - SkyDebuggerHookMain(); -#endif - base::mac::ScopedNSAutoreleasePool pool; - base::AtExitManager exit_manager; - RedirectIOConnectionsToSyslog(); - auto result = false; - result = base::CommandLine::Init(0, nullptr); - DLOG_ASSERT(result); - InitializeLogging(); - result = base::i18n::InitializeICU(); - DLOG_ASSERT(result); - result = gfx::GLSurface::InitializeOneOff(); - DLOG_ASSERT(result); - return UIApplicationMain(argc, argv, nil, - NSStringFromClass([SkyAppDelegate class])); +int main(int argc, const char * argv[]) { + return PlatformMacMain(argc, argv, ^(){ + return UIApplicationMain(argc, (char **)argv, nil, + NSStringFromClass([SkyAppDelegate class])); + }); } diff --git a/sky/shell/ios/sky_app_delegate.mm b/sky/shell/ios/sky_app_delegate.mm index ff7449daaa9c1e1549f3f6aa1c883511b4fb1677..add0a0dc4a864046bd422a3a003e5f0fb69d6ec4 100644 --- a/sky/shell/ios/sky_app_delegate.mm +++ b/sky/shell/ios/sky_app_delegate.mm @@ -5,41 +5,11 @@ #import "sky_app_delegate.h" #import "sky_view_controller.h" -#include "sky/shell/shell.h" -#include "sky/shell/service_provider.h" -#include "sky/shell/ui_delegate.h" -#include "base/lazy_instance.h" -#include "base/message_loop/message_loop.h" - -@implementation SkyAppDelegate { - base::LazyInstance> _main_message_loop; -} +@implementation SkyAppDelegate - (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions { - [self setupSkyShell]; - [self setupViewport]; - - return YES; -} - -- (void)setupSkyShell { - [self adoptPlatformRunLoop]; - auto service_provider_context = - make_scoped_ptr(new sky::shell::ServiceProviderContext( - _main_message_loop.Get()->task_runner())); - sky::shell::Shell::Init(service_provider_context.Pass()); -} - -- (void)adoptPlatformRunLoop { - _main_message_loop.Get().reset(new base::MessageLoopForUI); - // One cannot start the message loop on the platform main thread. Instead, - // we attach to the CFRunLoop - base::MessageLoopForUI::current()->Attach(); -} - -- (void)setupViewport { CGRect frame = [UIScreen mainScreen].bounds; UIWindow* window = [[UIWindow alloc] initWithFrame:frame]; SkyViewController* viewController = [[SkyViewController alloc] init]; @@ -48,6 +18,8 @@ self.window = window; [window release]; [self.window makeKeyAndVisible]; + + return YES; } @end diff --git a/sky/shell/ios/sky_surface.mm b/sky/shell/ios/sky_surface.mm index f63aa5492f7b3f6cf76959a1c8dfce5bfd7b8b0c..b33a063deafef914f8c814474a4891f16c74d23a 100644 --- a/sky/shell/ios/sky_surface.mm +++ b/sky/shell/ios/sky_surface.mm @@ -11,7 +11,7 @@ #include "base/time/time.h" #include "mojo/public/cpp/bindings/interface_request.h" #include "sky/services/engine/input_event.mojom.h" -#include "sky/shell/ios/platform_view_ios.h" +#include "sky/shell/mac/platform_view_mac.h" #include "sky/shell/shell_view.h" #include "sky/shell/shell.h" #include "sky/shell/ui_delegate.h" @@ -114,8 +114,8 @@ static sky::InputEventPtr BasicInputEventFromRecognizer( [self connectToEngineAndLoad]; } -- (sky::shell::PlatformViewIOS*)platformView { - auto view = static_cast(_shell_view->view()); +- (sky::shell::PlatformViewMac*)platformView { + auto view = static_cast(_shell_view->view()); DCHECK(view); return view; } diff --git a/sky/shell/mac/.gitignore b/sky/shell/mac/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..962db51bbdbb55f85c84958bf475a290e0fc6a3a --- /dev/null +++ b/sky/shell/mac/.gitignore @@ -0,0 +1,26 @@ +.idea/ +.sconsign.dblite +.svn/ + +.DS_Store +*.swp +*.lock +profile + +DerivedData/ +build/ + +*.pbxuser +*.mode1v3 +*.mode2v3 +*.perspectivev3 + +!default.pbxuser +!default.mode1v3 +!default.mode2v3 +!default.perspectivev3 + +xcuserdata + +*.moved-aside +Sky.xcodeproj/ diff --git a/sky/shell/mac/Info.plist b/sky/shell/mac/Info.plist new file mode 100644 index 0000000000000000000000000000000000000000..3e73f37a075e9e2023b4a7a738879b4d0b00ac1a --- /dev/null +++ b/sky/shell/mac/Info.plist @@ -0,0 +1,34 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + Sky + CFBundleIconFile + + CFBundleIdentifier + org.domokit.sky + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + Sky + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1 + LSMinimumSystemVersion + 10.6 + NSHumanReadableCopyright + Copyright © 2015 The Chromium Authors. All rights reserved. + NSMainNibFile + sky_mac + NSPrincipalClass + NSApplication + + diff --git a/sky/shell/mac/main_mac.mm b/sky/shell/mac/main_mac.mm new file mode 100644 index 0000000000000000000000000000000000000000..a6db5790343517795512e4f5727bb3b8ce45b8fb --- /dev/null +++ b/sky/shell/mac/main_mac.mm @@ -0,0 +1,83 @@ +// 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 +#include +#include "base/bind.h" +#include "base/message_loop/message_loop.h" +#include "sky/engine/public/web/WebRuntimeFeatures.h" +#include "sky/shell/mac/platform_mac.h" +#include "base/command_line.h" +#include "sky/shell/switches.h" +#include "sky/shell/testing/test_runner.h" + +namespace sky { +namespace shell { +namespace { + +bool FlagsValid() { + base::CommandLine& command_line = *base::CommandLine::ForCurrentProcess(); + + if (command_line.HasSwitch(sky::shell::switches::kHelp) || + (!command_line.HasSwitch(sky::shell::switches::kPackageRoot) && + !command_line.HasSwitch(sky::shell::switches::kSnapshot))) { + return false; + } + + return true; +} + +void Usage() { + std::cerr << "(For Test Shell) Usage: sky_shell" + << " --" << switches::kNonInteractive + << " --" << switches::kPackageRoot << "=PACKAGE_ROOT" + << " --" << switches::kSnapshot << "=SNAPSHOT" + << " [ MAIN_DART ]" << std::endl; +} + +void Init() { + base::CommandLine& command_line = *base::CommandLine::ForCurrentProcess(); + blink::WebRuntimeFeatures::enableObservatory( + !command_line.HasSwitch(switches::kNonInteractive)); + + // Explicitly boot the shared test runner. + TestRunner& runner = TestRunner::Shared(); + + std::string package_root = + command_line.GetSwitchValueASCII(switches::kPackageRoot); + runner.set_package_root(package_root); + + scoped_ptr single_test; + if (command_line.HasSwitch(switches::kSnapshot)) { + single_test.reset(new TestRunner::SingleTest); + single_test->path = command_line.GetSwitchValueASCII(switches::kSnapshot); + single_test->is_snapshot = true; + } else { + auto args = command_line.GetArgs(); + if (!args.empty()) { + single_test.reset(new TestRunner::SingleTest); + single_test->path = args[0]; + } + } + + runner.Start(single_test.Pass()); +} + +} // namespace +} // namespace shell +} // namespace sky + +int main(int argc, const char * argv[]) { + return PlatformMacMain(argc, argv, ^(){ + if (!sky::shell::FlagsValid()) { + sky::shell::Usage(); + return NSApplicationMain(argc, argv); + } else { + auto loop = base::MessageLoop::current(); + loop->PostTask(FROM_HERE, base::Bind(&sky::shell::Init)); + loop->Run(); + return EXIT_SUCCESS; + } + }); +} diff --git a/sky/shell/mac/platform_mac.h b/sky/shell/mac/platform_mac.h new file mode 100644 index 0000000000000000000000000000000000000000..25a479aa346bec5217761551be41a417e1abcf5a --- /dev/null +++ b/sky/shell/mac/platform_mac.h @@ -0,0 +1,21 @@ +// 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 SKY_SHELL_MAC_PLATFORM_MAC_H_ +#define SKY_SHELL_MAC_PLATFORM_MAC_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +typedef int(^PlatformMacMainCallback)(void); + +int PlatformMacMain(int argc, const char *argv[], + PlatformMacMainCallback callback); + +#ifdef __cplusplus +} +#endif + +#endif // SKY_SHELL_MAC_PLATFORM_MAC_H_ diff --git a/sky/shell/mac/platform_mac.mm b/sky/shell/mac/platform_mac.mm new file mode 100644 index 0000000000000000000000000000000000000000..2ba18ed2c1ac12a8fd14dd4b14de224f194e830c --- /dev/null +++ b/sky/shell/mac/platform_mac.mm @@ -0,0 +1,85 @@ +// 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 "sky/shell/mac/platform_mac.h" + +#include +#include "base/at_exit.h" +#include "base/logging.h" +#include "base/i18n/icu_util.h" +#include "base/command_line.h" +#include "base/mac/scoped_nsautorelease_pool.h" +#include "ui/gl/gl_surface.h" +#include "sky/shell/shell.h" +#include "sky/shell/service_provider.h" +#include "sky/shell/ui_delegate.h" +#include "base/lazy_instance.h" +#include "base/message_loop/message_loop.h" + +static void InitializeLogging() { + logging::LoggingSettings settings; + settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; + logging::InitLogging(settings); + logging::SetLogItems(false, // Process ID + false, // Thread ID + false, // Timestamp + false); // Tick count +} + +static void RedirectIOConnectionsToSyslog() { +#if TARGET_OS_IPHONE + asl_log_descriptor(NULL, NULL, ASL_LEVEL_INFO, STDOUT_FILENO, + ASL_LOG_DESCRIPTOR_WRITE); + asl_log_descriptor(NULL, NULL, ASL_LEVEL_NOTICE, STDERR_FILENO, + ASL_LOG_DESCRIPTOR_WRITE); +#endif +} + +int PlatformMacMain(int argc, const char *argv[], + PlatformMacMainCallback callback) { + + base::mac::ScopedNSAutoreleasePool pool; + + base::AtExitManager exit_manager; + + RedirectIOConnectionsToSyslog(); + + auto result = false; + + result = base::CommandLine::Init(argc, argv); + DLOG_ASSERT(result); + + InitializeLogging(); + + result = base::i18n::InitializeICU(); + DLOG_ASSERT(result); + + result = gfx::GLSurface::InitializeOneOff(); + DLOG_ASSERT(result); + + scoped_ptr main_message_loop( + new base::MessageLoopForUI()); + +#if TARGET_OS_IPHONE + // One cannot start the message loop on the platform main thread. Instead, + // we attach to the CFRunLoop + main_message_loop->Attach(); +#endif + + auto service_provider_context = + make_scoped_ptr(new sky::shell::ServiceProviderContext( + main_message_loop->task_runner())); + + sky::shell::Shell::Init(service_provider_context.Pass()); + + result = callback(); + +#if !TARGET_OS_IPHONE + if (result == EXIT_SUCCESS) { + main_message_loop->QuitNow(); + } +#endif + + return result; +} diff --git a/sky/shell/ios/platform_service_provider_ios.cc b/sky/shell/mac/platform_service_provider_mac.cc similarity index 100% rename from sky/shell/ios/platform_service_provider_ios.cc rename to sky/shell/mac/platform_service_provider_mac.cc diff --git a/sky/shell/ios/platform_view_ios.h b/sky/shell/mac/platform_view_mac.h similarity index 57% rename from sky/shell/ios/platform_view_ios.h rename to sky/shell/mac/platform_view_mac.h index a9e1ef6ffcff04fe6cd6fa01bc89c485bcdec981..d5fe68f731b4059a8674e25a02261bb26c0e2c5c 100644 --- a/sky/shell/ios/platform_view_ios.h +++ b/sky/shell/mac/platform_view_mac.h @@ -2,26 +2,26 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef SKY_SHELL_PLATFORM_VIEW_IOS_H_ -#define SKY_SHELL_PLATFORM_VIEW_IOS_H_ +#ifndef SKY_SHELL_PLATFORM_VIEW_MAC_H_ +#define SKY_SHELL_PLATFORM_VIEW_MAC_H_ #include "sky/shell/platform_view.h" namespace sky { namespace shell { -class PlatformViewIOS : public PlatformView { +class PlatformViewMac : public PlatformView { public: - explicit PlatformViewIOS(const Config& config); - ~PlatformViewIOS() override; + explicit PlatformViewMac(const Config& config); + ~PlatformViewMac() override; void SurfaceCreated(gfx::AcceleratedWidget widget); void SurfaceDestroyed(void); private: - DISALLOW_COPY_AND_ASSIGN(PlatformViewIOS); + DISALLOW_COPY_AND_ASSIGN(PlatformViewMac); }; } // namespace shell } // namespace sky -#endif // SKY_SHELL_PLATFORM_VIEW_IOS_H_ +#endif // SKY_SHELL_PLATFORM_VIEW_MAC_H_ diff --git a/sky/shell/ios/platform_view_ios.mm b/sky/shell/mac/platform_view_mac.mm similarity index 62% rename from sky/shell/ios/platform_view_ios.mm rename to sky/shell/mac/platform_view_mac.mm index 3c5f90d16077221a5ad5d0ca0e1205d01864efc2..459cbad8860a8058dc37651a9dee32645ed922bc 100644 --- a/sky/shell/ios/platform_view_ios.mm +++ b/sky/shell/mac/platform_view_mac.mm @@ -2,29 +2,29 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "platform_view_ios.h" +#include "sky/shell/mac/platform_view_mac.h" namespace sky { namespace shell { PlatformView* PlatformView::Create(const Config& config) { - return new PlatformViewIOS(config); + return new PlatformViewMac(config); } -PlatformViewIOS::PlatformViewIOS(const Config& config) +PlatformViewMac::PlatformViewMac(const Config& config) : PlatformView(config) { } -PlatformViewIOS::~PlatformViewIOS() { +PlatformViewMac::~PlatformViewMac() { } -void PlatformViewIOS::SurfaceCreated(gfx::AcceleratedWidget widget) { +void PlatformViewMac::SurfaceCreated(gfx::AcceleratedWidget widget) { DCHECK(window_ == 0); window_ = widget; SurfaceWasCreated(); } -void PlatformViewIOS::SurfaceDestroyed() { +void PlatformViewMac::SurfaceDestroyed() { DCHECK(window_); window_ = 0; SurfaceWasDestroyed(); diff --git a/sky/shell/mac/sky_app_delegate.h b/sky/shell/mac/sky_app_delegate.h new file mode 100644 index 0000000000000000000000000000000000000000..6326af00ce9954e3100d4db0bf0842f596e9de70 --- /dev/null +++ b/sky/shell/mac/sky_app_delegate.h @@ -0,0 +1,10 @@ +// 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 + +@interface SkyAppDelegate : NSObject + +@end + diff --git a/sky/shell/mac/sky_app_delegate.m b/sky/shell/mac/sky_app_delegate.m new file mode 100644 index 0000000000000000000000000000000000000000..4a527099828364cf94fcca54a7d715eacf6fcf05 --- /dev/null +++ b/sky/shell/mac/sky_app_delegate.m @@ -0,0 +1,15 @@ +// 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 "sky_app_delegate.h" + +@interface SkyAppDelegate () + +@property (assign) IBOutlet NSWindow *window; + +@end + +@implementation SkyAppDelegate + +@end diff --git a/sky/shell/mac/sky_mac.xib b/sky/shell/mac/sky_mac.xib new file mode 100644 index 0000000000000000000000000000000000000000..8abc72a57b9c3772d4863f0f9ed91543ce0244f4 --- /dev/null +++ b/sky/shell/mac/sky_mac.xib @@ -0,0 +1,695 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Default + + + + + + + Left to Right + + + + + + + Right to Left + + + + + + + + + + + Default + + + + + + + Left to Right + + + + + + + Right to Left + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sky/shell/mac/sky_window.h b/sky/shell/mac/sky_window.h new file mode 100644 index 0000000000000000000000000000000000000000..07540aba162b75b32ca42ec44362aab03cb205c3 --- /dev/null +++ b/sky/shell/mac/sky_window.h @@ -0,0 +1,9 @@ +// 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 + +@interface SkyWindow : NSWindow + +@end diff --git a/sky/shell/mac/sky_window.mm b/sky/shell/mac/sky_window.mm new file mode 100644 index 0000000000000000000000000000000000000000..bcad63cb0429dc9c40734e8a673a835a520c5592 --- /dev/null +++ b/sky/shell/mac/sky_window.mm @@ -0,0 +1,113 @@ +// 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 "sky_window.h" +#include "base/time/time.h" +#include "mojo/public/cpp/bindings/interface_request.h" +#include "sky/services/engine/input_event.mojom.h" +#include "sky/shell/mac/platform_view_mac.h" +#include "sky/shell/shell_view.h" +#include "sky/shell/shell.h" +#include "sky/shell/ui_delegate.h" + +@interface SkyWindow () + +@property (assign) IBOutlet NSOpenGLView *renderSurface; +@property (getter=isSurfaceSetup) BOOL surfaceSetup; + +@end + +@implementation SkyWindow { + sky::SkyEnginePtr _sky_engine; + scoped_ptr _shell_view; +} + +@synthesize renderSurface=_renderSurface; +@synthesize surfaceSetup=_surfaceSetup; + +-(void) awakeFromNib { + [super awakeFromNib]; + + self.delegate = self; + + [self windowDidResize:nil]; +} + +-(void) setupShell { + NSAssert(_shell_view == nullptr, @"The shell view must not already be set"); + auto shell_view = new sky::shell::ShellView(sky::shell::Shell::Shared()); + _shell_view.reset(shell_view); + + auto widget = reinterpret_cast(self.renderSurface); + self.platformView->SurfaceCreated(widget); +} + +-(NSString *) skyInitialLoadURL { + return @"http://localhost:8080/sky/sdk/example/rendering/simple_autolayout.dart"; +} + +-(void) setupAndLoadDart { + auto interface_request = mojo::GetProxy(&_sky_engine); + self.platformView->ConnectToEngine(interface_request.Pass()); + + mojo::String string(self.skyInitialLoadURL.UTF8String); + _sky_engine->RunFromNetwork(string); +} + +-(void) windowDidResize:(NSNotification *)notification { + [self setupSurfaceIfNecessary]; + + // Resize + + // sky::ViewportMetricsPtr metrics = sky::ViewportMetrics::New(); + // metrics->physical_width = size.width * scale; + // metrics->physical_height = size.height * scale; + // metrics->device_pixel_ratio = scale; + // _sky_engine->OnViewportMetricsChanged(metrics.Pass()); +} + +-(void) setupSurfaceIfNecessary { + if (self.isSurfaceSetup) { + return; + } + + self.surfaceSetup = YES; + + [self setupShell]; + [self setupAndLoadDart]; +} + +- (sky::shell::PlatformViewMac*)platformView { + auto view = static_cast(_shell_view->view()); + DCHECK(view); + return view; +} + +#pragma mark - Responder overrides + +- (void)dispatchEvent:(NSEvent *)event phase:(NSEventPhase) phase { + NSPoint location = [_renderSurface convertPoint:event.locationInWindow + fromView:nil]; + + location.y = _renderSurface.frame.size.height - location.y; +} + +- (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) dealloc { + self.platformView->SurfaceDestroyed(); + [super dealloc]; +} + +@end diff --git a/ui/gl/gl_surface_mac.cc b/ui/gl/gl_surface_mac.cc index 28a8b8513c02405050847b2de9de391dc3e39ba2..0686117cd354f3bf31462a48b40d8653dbb1261c 100644 --- a/ui/gl/gl_surface_mac.cc +++ b/ui/gl/gl_surface_mac.cc @@ -1,160 +1,73 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2014 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 "ui/gl/gl_surface.h" +#include "ui/gl/gl_surface_mac.h" -#include "base/basictypes.h" -#include "base/logging.h" -#include "base/memory/scoped_ptr.h" -#include "base/trace_event/trace_event.h" -#include "ui/gl/gl_bindings.h" +#include "base/mac/scoped_nsautorelease_pool.h" #include "ui/gl/gl_context.h" -#include "ui/gl/gl_implementation.h" -#include "ui/gl/gl_surface_stub.h" -#include "ui/gl/gpu_switching_manager.h" - -#include -#include - -extern "C" { -// The header may not be directly imported since it includes -// gltypes.h which conflict with the types already included -extern CGLError CGLChoosePixelFormat(const CGLPixelFormatAttribute *attribs, - CGLPixelFormatObj *pix, GLint *npix); -extern void CGLReleasePixelFormat(CGLPixelFormatObj pix); -} +#include "ui/gl/gl_enums.h" +#include "base/logging.h" namespace gfx { -namespace { - -// A "no-op" surface. It is not required that a CGLContextObj have an -// associated drawable (pbuffer or fullscreen context) in order to be -// made current. Everywhere this surface type is used, we allocate an -// FBO at the user level as the drawable of the associated context. -class GL_EXPORT NoOpGLSurface : public GLSurface { - public: - explicit NoOpGLSurface(const gfx::Size& size, - const gfx::SurfaceConfiguration conf) - : GLSurface(conf), - size_(size) {} - - // Implement GLSurface. - bool Initialize() override { return true; } - void Destroy() override {} - bool IsOffscreen() override { return true; } - bool SwapBuffers() override { - NOTREACHED() << "Cannot call SwapBuffers on a NoOpGLSurface."; - return false; - } - gfx::Size GetSize() override { return size_; } - void* GetHandle() override { return NULL; } - void* GetDisplay() override { return NULL; } - bool IsSurfaceless() const override { return true; } - - protected: - ~NoOpGLSurface() override {} - - private: - gfx::Size size_; - - DISALLOW_COPY_AND_ASSIGN(NoOpGLSurface); -}; -// static -bool InitializeOneOffForSandbox() { - static bool initialized = false; - if (initialized) - return true; - - // This is called from the sandbox warmup code on Mac OS X. - // GPU-related stuff is very slow without this, probably because - // the sandbox prevents loading graphics drivers or some such. - std::vector attribs; - if (ui::GpuSwitchingManager::GetInstance()->SupportsDualGpus()) { - // Avoid switching to the discrete GPU just for this pixel - // format selection. - attribs.push_back(kCGLPFAAllowOfflineRenderers); - } - if (GetGLImplementation() == kGLImplementationAppleGL) { - attribs.push_back(kCGLPFARendererID); - attribs.push_back(static_cast( - kCGLRendererGenericFloatID)); - } - attribs.push_back(static_cast(0)); - - CGLPixelFormatObj format; - GLint num_pixel_formats; - if (CGLChoosePixelFormat(&attribs.front(), - &format, - &num_pixel_formats) != kCGLNoError) { - LOG(ERROR) << "Error choosing pixel format."; - return false; - } - if (!format) { - LOG(ERROR) << "format == 0."; - return false; - } - CGLReleasePixelFormat(format); - DCHECK_NE(num_pixel_formats, 0); - initialized = true; - return true; +GLSurfaceMac::GLSurfaceMac(gfx::AcceleratedWidget widget, + const gfx::SurfaceConfiguration requested_configuration) + : GLSurface(requested_configuration), + widget_(widget) { } -} // namespace +GLSurfaceMac::~GLSurfaceMac() { + Destroy(); +} + +bool GLSurfaceMac::OnMakeCurrent(GLContext* context) { + DCHECK(false); + return false; +} + +bool GLSurfaceMac::SwapBuffers() { + DCHECK(false); + return false; +} + +void GLSurfaceMac::Destroy() { + DCHECK(false); +} + +bool GLSurfaceMac::IsOffscreen() { + DCHECK(false); + return false; +} + +gfx::Size GLSurfaceMac::GetSize() { + DCHECK(false); + return Size(0.0, 0.0); +} + +void* GLSurfaceMac::GetHandle() { + return (void*)widget_; +} bool GLSurface::InitializeOneOffInternal() { - switch (GetGLImplementation()) { - case kGLImplementationDesktopGL: - case kGLImplementationAppleGL: - if (!InitializeOneOffForSandbox()) { - LOG(ERROR) << "GLSurfaceCGL::InitializeOneOff failed."; - return false; - } - break; - default: - break; - } + // On EGL, this method is used to perfom one-time initialization tasks like + // initializing the display, setting up config lists, etc. There is no such + // setup on Mac. return true; } +// static scoped_refptr GLSurface::CreateViewGLSurface( - gfx::AcceleratedWidget window, - const gfx::SurfaceConfiguration& conf) { - TRACE_EVENT0("gpu", "GLSurface::CreateViewGLSurface"); - switch (GetGLImplementation()) { - case kGLImplementationDesktopGL: - case kGLImplementationAppleGL: { - NOTIMPLEMENTED() << "No onscreen support on Mac."; - return NULL; - } - case kGLImplementationMockGL: - return new GLSurfaceStub(conf); - default: - NOTREACHED(); - return NULL; - } -} + gfx::AcceleratedWidget window, + const gfx::SurfaceConfiguration& requested_configuration) { + DCHECK(window != kNullAcceleratedWidget); + scoped_refptr surface = + new GLSurfaceMac(window, requested_configuration); + + if (!surface->Initialize()) + return NULL; -scoped_refptr GLSurface::CreateOffscreenGLSurface( - const gfx::Size& size, - const gfx::SurfaceConfiguration& conf) { - TRACE_EVENT0("gpu", "GLSurface::CreateOffscreenGLSurface"); - switch (GetGLImplementation()) { - case kGLImplementationDesktopGL: - case kGLImplementationAppleGL: { - scoped_refptr surface(new NoOpGLSurface(size, conf)); - if (!surface->Initialize()) - return NULL; - - return surface; - } - case kGLImplementationMockGL: - return new GLSurfaceStub(conf); - default: - NOTREACHED(); - return NULL; - } + return surface; } } // namespace gfx diff --git a/ui/gl/gl_surface_mac.h b/ui/gl/gl_surface_mac.h new file mode 100644 index 0000000000000000000000000000000000000000..6257f909502eeb2dc1d7bd1369071d0bb9d2de18 --- /dev/null +++ b/ui/gl/gl_surface_mac.h @@ -0,0 +1,29 @@ +// Copyright 2014 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 "ui/gl/gl_surface.h" + +namespace gfx { + +class GL_EXPORT GLSurfaceMac : public GLSurface { + public: + GLSurfaceMac(gfx::AcceleratedWidget widget, + const gfx::SurfaceConfiguration requested_configuration); + + bool SwapBuffers() override; + void Destroy() override; + bool IsOffscreen() override; + gfx::Size GetSize() override; + void* GetHandle() override; + bool OnMakeCurrent(GLContext* context) override; + + private: + ~GLSurfaceMac() override; + + gfx::AcceleratedWidget widget_; + + DISALLOW_COPY_AND_ASSIGN(GLSurfaceMac); +}; + +} // namespace gfx