| 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/platform_view.h" | |
| 13 #include "sky/shell/gpu/rasterizer.h" | |
| 14 #include "sky/shell/ui/engine.h" | 12 #include "sky/shell/ui/engine.h" |
| 15 | 13 |
| 16 namespace sky { | 14 namespace sky { |
| 17 namespace shell { | 15 namespace shell { |
| 18 namespace { | 16 namespace { |
| 19 | 17 |
| 20 static Shell* g_shell = nullptr; | 18 static Shell* g_shell = nullptr; |
| 21 | 19 |
| 22 scoped_ptr<base::MessagePump> CreateMessagePumpMojo() { | 20 scoped_ptr<base::MessagePump> CreateMessagePumpMojo() { |
| 23 return make_scoped_ptr(new mojo::common::MessagePumpMojo); | 21 return make_scoped_ptr(new mojo::common::MessagePumpMojo); |
| 24 } | 22 } |
| 25 | 23 |
| 26 } // namespace | 24 } // namespace |
| 27 | 25 |
| 28 Shell::Shell(scoped_ptr<ServiceProviderContext> service_provider_context) | 26 Shell::Shell(scoped_ptr<ServiceProviderContext> service_provider_context) |
| 29 : service_provider_context_(service_provider_context.Pass()) { | 27 : service_provider_context_(service_provider_context.Pass()) { |
| 30 DCHECK(!g_shell); | 28 DCHECK(!g_shell); |
| 31 mojo::embedder::Init(scoped_ptr<mojo::embedder::PlatformSupport>( | 29 mojo::embedder::Init(scoped_ptr<mojo::embedder::PlatformSupport>( |
| 32 new mojo::embedder::SimplePlatformSupport())); | 30 new mojo::embedder::SimplePlatformSupport())); |
| 33 | 31 |
| 34 base::Thread::Options options; | 32 base::Thread::Options options; |
| 35 options.message_pump_factory = base::Bind(&CreateMessagePumpMojo); | 33 options.message_pump_factory = base::Bind(&CreateMessagePumpMojo); |
| 36 | 34 |
| 37 InitGPU(options); | 35 gpu_thread_.reset(new base::Thread("gpu_thread")); |
| 38 InitUI(options); | 36 gpu_thread_->StartWithOptions(options); |
| 39 InitView(); | 37 |
| 38 ui_thread_.reset(new base::Thread("ui_thread")); |
| 39 ui_thread_->StartWithOptions(options); |
| 40 |
| 41 ui_task_runner()->PostTask( |
| 42 FROM_HERE, base::Bind(&Engine::Init, service_provider_context_.get())); |
| 40 } | 43 } |
| 41 | 44 |
| 42 Shell::~Shell() { | 45 Shell::~Shell() { |
| 43 } | 46 } |
| 44 | 47 |
| 45 void Shell::Init(scoped_ptr<ServiceProviderContext> service_provider_context) { | 48 void Shell::Init(scoped_ptr<ServiceProviderContext> service_provider_context) { |
| 46 g_shell = new Shell(service_provider_context.Pass()); | 49 g_shell = new Shell(service_provider_context.Pass()); |
| 47 } | 50 } |
| 48 | 51 |
| 49 Shell& Shell::Shared() { | 52 Shell& Shell::Shared() { |
| 50 DCHECK(g_shell); | 53 DCHECK(g_shell); |
| 51 return *g_shell; | 54 return *g_shell; |
| 52 } | 55 } |
| 53 | 56 |
| 54 void Shell::InitGPU(const base::Thread::Options& options) { | |
| 55 gpu_thread_.reset(new base::Thread("gpu_thread")); | |
| 56 gpu_thread_->StartWithOptions(options); | |
| 57 | |
| 58 rasterizer_.reset(new Rasterizer()); | |
| 59 } | |
| 60 | |
| 61 void Shell::InitUI(const base::Thread::Options& options) { | |
| 62 ui_thread_.reset(new base::Thread("ui_thread")); | |
| 63 ui_thread_->StartWithOptions(options); | |
| 64 | |
| 65 Engine::Config config; | |
| 66 config.service_provider_context = service_provider_context_.get(); | |
| 67 config.gpu_task_runner = gpu_thread_->message_loop()->task_runner(); | |
| 68 config.gpu_delegate = rasterizer_->GetWeakPtr(); | |
| 69 engine_.reset(new Engine(config)); | |
| 70 | |
| 71 ui_thread_->message_loop()->PostTask( | |
| 72 FROM_HERE, base::Bind(&Engine::Init, engine_->GetWeakPtr())); | |
| 73 } | |
| 74 | |
| 75 void Shell::InitView() { | |
| 76 PlatformView::Config config; | |
| 77 config.ui_task_runner = ui_thread_->message_loop()->task_runner(); | |
| 78 config.ui_delegate = engine_->GetWeakPtr(); | |
| 79 view_.reset(new PlatformView(config)); | |
| 80 } | |
| 81 | |
| 82 } // namespace shell | 57 } // namespace shell |
| 83 } // namespace sky | 58 } // namespace sky |
| OLD | NEW |