Chromium Code Reviews| 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 "base/threading/thread.h" | 9 #include "mojo/common/message_pump_mojo.h" |
| 10 #include "mojo/edk/embedder/embedder.h" | |
| 11 #include "mojo/edk/embedder/simple_platform_support.h" | |
| 10 #include "sky/shell/gpu/rasterizer.h" | 12 #include "sky/shell/gpu/rasterizer.h" |
| 11 #include "sky/shell/sky_view.h" | 13 #include "sky/shell/java_service_provider.h" |
| 14 #include "sky/shell/platform_view.h" | |
| 12 #include "sky/shell/ui/engine.h" | 15 #include "sky/shell/ui/engine.h" |
| 13 | 16 |
| 14 namespace sky { | 17 namespace sky { |
| 15 namespace shell { | 18 namespace shell { |
| 19 namespace { | |
| 20 | |
| 21 Shell* g_shell = nullptr; | |
| 22 | |
| 23 scoped_ptr<base::MessagePump> CreateMessagePumpMojo() { | |
| 24 return make_scoped_ptr(new mojo::common::MessagePumpMojo); | |
| 25 } | |
| 26 | |
| 27 } // namespace | |
| 16 | 28 |
| 17 Shell::Shell(scoped_refptr<base::SingleThreadTaskRunner> java_task_runner) | 29 Shell::Shell(scoped_refptr<base::SingleThreadTaskRunner> java_task_runner) |
| 18 : java_task_runner_(java_task_runner) { | 30 : java_task_runner_(java_task_runner) { |
| 31 DCHECK(!g_shell); | |
| 32 g_shell = this; | |
|
eseidel
2015/02/18 20:55:56
nit: imo it's nicer to have the caller of new set
| |
| 19 } | 33 } |
| 20 | 34 |
| 21 Shell::~Shell() { | 35 Shell::~Shell() { |
| 22 } | 36 } |
| 23 | 37 |
| 38 Shell& Shell::Current() { | |
|
eseidel
2015/02/18 20:55:56
Current implies that it could change. I might use
| |
| 39 DCHECK(g_shell); | |
| 40 return *g_shell; | |
| 41 } | |
| 42 | |
| 24 void Shell::Init() { | 43 void Shell::Init() { |
| 44 mojo::embedder::Init(scoped_ptr<mojo::embedder::PlatformSupport>( | |
| 45 new mojo::embedder::SimplePlatformSupport())); | |
| 46 | |
| 47 base::Thread::Options options; | |
| 48 options.message_pump_factory = base::Bind(&CreateMessagePumpMojo); | |
| 49 | |
| 50 InitGPU(options); | |
| 51 InitUI(options); | |
| 52 InitView(); | |
| 53 } | |
| 54 | |
| 55 void Shell::InitGPU(const base::Thread::Options& options) { | |
| 25 gpu_thread_.reset(new base::Thread("gpu_thread")); | 56 gpu_thread_.reset(new base::Thread("gpu_thread")); |
| 26 gpu_thread_->Start(); | 57 gpu_thread_->StartWithOptions(options); |
| 58 | |
| 27 rasterizer_.reset(new Rasterizer()); | 59 rasterizer_.reset(new Rasterizer()); |
| 60 } | |
| 28 | 61 |
| 62 void Shell::InitUI(const base::Thread::Options& options) { | |
| 29 ui_thread_.reset(new base::Thread("ui_thread")); | 63 ui_thread_.reset(new base::Thread("ui_thread")); |
| 30 ui_thread_->Start(); | 64 ui_thread_->StartWithOptions(options); |
| 31 engine_.reset(new Engine()); | 65 |
| 66 Engine::Config config; | |
| 67 config.gpu_task_runner = gpu_thread_->message_loop()->task_runner(); | |
| 68 config.gpu_delegate = rasterizer_->GetWeakPtr(); | |
| 69 engine_.reset(new Engine(config)); | |
| 32 | 70 |
| 33 ui_thread_->message_loop()->PostTask( | 71 ui_thread_->message_loop()->PostTask( |
| 34 FROM_HERE, base::Bind(&Engine::Init, engine_->GetWeakPtr())); | 72 FROM_HERE, base::Bind(&Engine::Init, engine_->GetWeakPtr(), |
| 73 base::Passed(CreateJavaServiceProvider()))); | |
| 74 } | |
| 35 | 75 |
| 36 SkyView::Config config; | 76 void Shell::InitView() { |
| 77 PlatformView::Config config; | |
| 37 config.gpu_task_runner = gpu_thread_->message_loop()->task_runner(); | 78 config.gpu_task_runner = gpu_thread_->message_loop()->task_runner(); |
| 38 config.gpu_delegate = rasterizer_->GetWeakPtr(); | 79 config.gpu_delegate = rasterizer_->GetWeakPtr(); |
| 39 config.ui_task_runner = ui_thread_->message_loop()->task_runner(); | 80 config.ui_task_runner = ui_thread_->message_loop()->task_runner(); |
| 40 config.ui_delegate = engine_->GetWeakPtr(); | 81 config.ui_delegate = engine_->GetWeakPtr(); |
| 41 | 82 view_.reset(new PlatformView(config)); |
| 42 view_.reset(new SkyView(config)); | |
| 43 } | 83 } |
| 44 | 84 |
| 45 } // namespace shell | 85 } // namespace shell |
| 46 } // namespace sky | 86 } // namespace sky |
| OLD | NEW |