| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "sky/shell/shell.h" | 5 #include "sky/shell/shell.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/single_thread_task_runner.h" | 8 #include "base/single_thread_task_runner.h" |
| 9 #include "mojo/common/message_pump_mojo.h" | 9 #include "mojo/common/message_pump_mojo.h" |
| 10 #include "mojo/edk/embedder/embedder.h" | 10 #include "mojo/edk/embedder/embedder.h" |
| 11 #include "mojo/edk/embedder/simple_platform_support.h" | 11 #include "mojo/edk/embedder/simple_platform_support.h" |
| 12 #include "sky/shell/android/platform_service_provider.h" |
| 13 #include "sky/shell/android/platform_view.h" |
| 12 #include "sky/shell/gpu/rasterizer.h" | 14 #include "sky/shell/gpu/rasterizer.h" |
| 13 #include "sky/shell/java_service_provider.h" | |
| 14 #include "sky/shell/platform_view.h" | |
| 15 #include "sky/shell/ui/engine.h" | 15 #include "sky/shell/ui/engine.h" |
| 16 | 16 |
| 17 namespace sky { | 17 namespace sky { |
| 18 namespace shell { | 18 namespace shell { |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 static Shell* g_shell = nullptr; | 21 static Shell* g_shell = nullptr; |
| 22 | 22 |
| 23 scoped_ptr<base::MessagePump> CreateMessagePumpMojo() { | 23 scoped_ptr<base::MessagePump> CreateMessagePumpMojo() { |
| 24 return make_scoped_ptr(new mojo::common::MessagePumpMojo); | 24 return make_scoped_ptr(new mojo::common::MessagePumpMojo); |
| 25 } | 25 } |
| 26 | 26 |
| 27 } // namespace | 27 } // namespace |
| 28 | 28 |
| 29 Shell::Shell(scoped_refptr<base::SingleThreadTaskRunner> java_task_runner) | 29 Shell::Shell(scoped_ptr<ServiceProviderContext> service_provider_context) |
| 30 : java_task_runner_(java_task_runner) { | 30 : service_provider_context_(service_provider_context.Pass()) { |
| 31 DCHECK(!g_shell); | 31 DCHECK(!g_shell); |
| 32 mojo::embedder::Init(scoped_ptr<mojo::embedder::PlatformSupport>( | 32 mojo::embedder::Init(scoped_ptr<mojo::embedder::PlatformSupport>( |
| 33 new mojo::embedder::SimplePlatformSupport())); | 33 new mojo::embedder::SimplePlatformSupport())); |
| 34 | 34 |
| 35 base::Thread::Options options; | 35 base::Thread::Options options; |
| 36 options.message_pump_factory = base::Bind(&CreateMessagePumpMojo); | 36 options.message_pump_factory = base::Bind(&CreateMessagePumpMojo); |
| 37 | 37 |
| 38 InitGPU(options); | 38 InitGPU(options); |
| 39 InitUI(options); | 39 InitUI(options); |
| 40 InitView(); | 40 InitView(); |
| 41 } | 41 } |
| 42 | 42 |
| 43 Shell::~Shell() { | 43 Shell::~Shell() { |
| 44 } | 44 } |
| 45 | 45 |
| 46 void Shell::Init(scoped_refptr<base::SingleThreadTaskRunner> java_task_runner) { | 46 void Shell::Init(scoped_ptr<ServiceProviderContext> service_provider_context) { |
| 47 g_shell = new Shell(java_task_runner); | 47 g_shell = new Shell(service_provider_context.Pass()); |
| 48 } | 48 } |
| 49 | 49 |
| 50 Shell& Shell::Shared() { | 50 Shell& Shell::Shared() { |
| 51 DCHECK(g_shell); | 51 DCHECK(g_shell); |
| 52 return *g_shell; | 52 return *g_shell; |
| 53 } | 53 } |
| 54 | 54 |
| 55 void Shell::InitGPU(const base::Thread::Options& options) { | 55 void Shell::InitGPU(const base::Thread::Options& options) { |
| 56 gpu_thread_.reset(new base::Thread("gpu_thread")); | 56 gpu_thread_.reset(new base::Thread("gpu_thread")); |
| 57 gpu_thread_->StartWithOptions(options); | 57 gpu_thread_->StartWithOptions(options); |
| 58 | 58 |
| 59 rasterizer_.reset(new Rasterizer()); | 59 rasterizer_.reset(new Rasterizer()); |
| 60 } | 60 } |
| 61 | 61 |
| 62 void Shell::InitUI(const base::Thread::Options& options) { | 62 void Shell::InitUI(const base::Thread::Options& options) { |
| 63 ui_thread_.reset(new base::Thread("ui_thread")); | 63 ui_thread_.reset(new base::Thread("ui_thread")); |
| 64 ui_thread_->StartWithOptions(options); | 64 ui_thread_->StartWithOptions(options); |
| 65 | 65 |
| 66 Engine::Config config; | 66 Engine::Config config; |
| 67 config.java_task_runner = java_task_runner_; | 67 config.service_provider_context = service_provider_context_.get(); |
| 68 config.gpu_task_runner = gpu_thread_->message_loop()->task_runner(); | 68 config.gpu_task_runner = gpu_thread_->message_loop()->task_runner(); |
| 69 config.gpu_delegate = rasterizer_->GetWeakPtr(); | 69 config.gpu_delegate = rasterizer_->GetWeakPtr(); |
| 70 engine_.reset(new Engine(config)); | 70 engine_.reset(new Engine(config)); |
| 71 | 71 |
| 72 ui_thread_->message_loop()->PostTask( | 72 ui_thread_->message_loop()->PostTask( |
| 73 FROM_HERE, base::Bind(&Engine::Init, engine_->GetWeakPtr())); | 73 FROM_HERE, base::Bind(&Engine::Init, engine_->GetWeakPtr())); |
| 74 } | 74 } |
| 75 | 75 |
| 76 void Shell::InitView() { | 76 void Shell::InitView() { |
| 77 PlatformView::Config config; | 77 PlatformView::Config config; |
| 78 config.ui_task_runner = ui_thread_->message_loop()->task_runner(); | 78 config.ui_task_runner = ui_thread_->message_loop()->task_runner(); |
| 79 config.ui_delegate = engine_->GetWeakPtr(); | 79 config.ui_delegate = engine_->GetWeakPtr(); |
| 80 view_.reset(new PlatformView(config)); | 80 view_.reset(new PlatformView(config)); |
| 81 } | 81 } |
| 82 | 82 |
| 83 } // namespace shell | 83 } // namespace shell |
| 84 } // namespace sky | 84 } // namespace sky |
| OLD | NEW |