diff --git a/engine/src/flutter/shell/BUILD.gn b/engine/src/flutter/shell/BUILD.gn index 3494b85863..32b1c6a582 100644 --- a/engine/src/flutter/shell/BUILD.gn +++ b/engine/src/flutter/shell/BUILD.gn @@ -29,6 +29,10 @@ shared_library("sky_shell") { "gpu/ganesh_surface.h", "gpu/rasterizer.cc", "gpu/rasterizer.h", + "ui/engine.cc", + "ui/engine.h", + "ui/platform_impl.cc", + "ui/platform_impl.h", "library_loader.cc", "shell.cc", "shell.h", @@ -38,12 +42,13 @@ shared_library("sky_shell") { "sky_view.h", ] - configs += [ "//third_party/khronos:khronos_headers" ] - deps = [ "//base", + "//base:i18n", "//build/config/sanitizers:deps", + "//mojo/edk/system", "//skia", + "//sky/engine", "//ui/gfx/geometry", "//ui/gl", ":jni_headers", diff --git a/engine/src/flutter/shell/shell.cc b/engine/src/flutter/shell/shell.cc index 757a9e91c2..3a54bb2c09 100644 --- a/engine/src/flutter/shell/shell.cc +++ b/engine/src/flutter/shell/shell.cc @@ -24,6 +24,13 @@ void Shell::Init() { gpu_thread_->Start(); rasterizer_.reset(new Rasterizer()); + ui_thread_.reset(new base::Thread("ui_thread")); + ui_thread_->Start(); + engine_.reset(new Engine()); + + ui_thread_->message_loop()->PostTask( + FROM_HERE, base::Bind(&Engine::Init, engine_->GetWeakPtr())); + view_.reset(new SkyView(this)); view_->Init(); } diff --git a/engine/src/flutter/shell/shell.h b/engine/src/flutter/shell/shell.h index eb69f669b0..bcb812e269 100644 --- a/engine/src/flutter/shell/shell.h +++ b/engine/src/flutter/shell/shell.h @@ -10,6 +10,7 @@ #include "base/memory/scoped_ptr.h" #include "sky/shell/gpu/rasterizer.h" #include "sky/shell/sky_view.h" +#include "sky/shell/ui/engine.h" namespace base { class Thread; @@ -33,9 +34,11 @@ class Shell : public SkyView::Delegate { scoped_refptr java_task_runner_; scoped_ptr gpu_thread_; + scoped_ptr ui_thread_; scoped_ptr view_; scoped_ptr rasterizer_; + scoped_ptr engine_; DISALLOW_COPY_AND_ASSIGN(Shell); }; diff --git a/engine/src/flutter/shell/sky_main.cc b/engine/src/flutter/shell/sky_main.cc index 4cbea0b0f6..4ae0b940be 100644 --- a/engine/src/flutter/shell/sky_main.cc +++ b/engine/src/flutter/shell/sky_main.cc @@ -10,6 +10,7 @@ #include "base/at_exit.h" #include "base/bind.h" #include "base/command_line.h" +#include "base/i18n/icu_util.h" #include "base/lazy_instance.h" #include "base/logging.h" #include "base/macros.h" @@ -63,6 +64,7 @@ static void Init(JNIEnv* env, g_java_message_loop.Get().reset(new base::MessageLoopForUI); base::MessageLoopForUI::current()->Start(); + base::i18n::InitializeICU(); gfx::GLSurface::InitializeOneOff(); g_shell.Get().reset(new Shell(g_java_message_loop.Get()->task_runner())); diff --git a/engine/src/flutter/shell/ui/engine.cc b/engine/src/flutter/shell/ui/engine.cc new file mode 100644 index 0000000000..ed1971d367 --- /dev/null +++ b/engine/src/flutter/shell/ui/engine.cc @@ -0,0 +1,36 @@ +// 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/ui/engine.h" + +#include "sky/engine/public/web/Sky.h" +#include "sky/engine/public/web/WebLocalFrame.h" +#include "sky/engine/public/web/WebView.h" +#include "sky/shell/ui/platform_impl.h" + +namespace sky { +namespace shell { + +Engine::Engine() : web_view_(nullptr), weak_factory_(this) { +} + +Engine::~Engine() { + if (web_view_) + web_view_->close(); +} + +base::WeakPtr Engine::GetWeakPtr() { + return weak_factory_.GetWeakPtr(); +} + +void Engine::Init() { + platform_impl_.reset(new PlatformImpl); + blink::initialize(platform_impl_.get()); + + web_view_ = blink::WebView::create(this); + web_view_->setMainFrame(blink::WebLocalFrame::create(this)); +} + +} // namespace shell +} // namespace sky diff --git a/engine/src/flutter/shell/ui/engine.h b/engine/src/flutter/shell/ui/engine.h new file mode 100644 index 0000000000..cba0c7a7ad --- /dev/null +++ b/engine/src/flutter/shell/ui/engine.h @@ -0,0 +1,40 @@ +// 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_UI_ENGINE_H_ +#define SKY_SHELL_UI_ENGINE_H_ + +#include "base/macros.h" +#include "base/memory/scoped_ptr.h" +#include "base/memory/weak_ptr.h" +#include "sky/engine/public/web/WebFrameClient.h" +#include "sky/engine/public/web/WebViewClient.h" + +namespace sky { +namespace shell { +class PlatformImpl; + +class Engine : public blink::WebFrameClient, + public blink::WebViewClient { + public: + Engine(); + ~Engine() override; + + base::WeakPtr GetWeakPtr(); + + void Init(); + + private: + scoped_ptr platform_impl_; + blink::WebView* web_view_; + + base::WeakPtrFactory weak_factory_; + + DISALLOW_COPY_AND_ASSIGN(Engine); +}; + +} // namespace shell +} // namespace sky + +#endif // SKY_SHELL_UI_ENGINE_H_ diff --git a/engine/src/flutter/shell/ui/platform_impl.cc b/engine/src/flutter/shell/ui/platform_impl.cc new file mode 100644 index 0000000000..dca0039fd3 --- /dev/null +++ b/engine/src/flutter/shell/ui/platform_impl.cc @@ -0,0 +1,26 @@ +// 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/ui/platform_impl.h" + +namespace sky { +namespace shell { + +PlatformImpl::PlatformImpl() + : main_thread_task_runner_(base::MessageLoop::current()->task_runner()) { +} + +PlatformImpl::~PlatformImpl() { +} + +blink::WebString PlatformImpl::defaultLocale() { + return blink::WebString::fromUTF8("en-US"); +} + +base::SingleThreadTaskRunner* PlatformImpl::mainThreadTaskRunner() { + return main_thread_task_runner_.get(); +} + +} // namespace shell +} // namespace sky diff --git a/engine/src/flutter/shell/ui/platform_impl.h b/engine/src/flutter/shell/ui/platform_impl.h new file mode 100644 index 0000000000..5a62d0e8f2 --- /dev/null +++ b/engine/src/flutter/shell/ui/platform_impl.h @@ -0,0 +1,32 @@ +// 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_UI_PLATFORM_IMPL_H_ +#define SKY_SHELL_UI_PLATFORM_IMPL_H_ + +#include "base/message_loop/message_loop.h" +#include "sky/engine/public/platform/Platform.h" + +namespace sky { +namespace shell { + +class PlatformImpl : public blink::Platform { + public: + PlatformImpl(); + ~PlatformImpl() override; + + // blink::Platform: + blink::WebString defaultLocale() override; + base::SingleThreadTaskRunner* mainThreadTaskRunner() override; + + private: + scoped_refptr main_thread_task_runner_; + + DISALLOW_COPY_AND_ASSIGN(PlatformImpl); +}; + +} // namespace shell +} // namespace sky + +#endif // SKY_SHELL_UI_PLATFORM_IMPL_H_