OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "services/ui/gpu/gpu_main.h" | 5 #include "services/ui/gpu/gpu_main.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/message_loop/message_loop.h" | |
8 #include "gpu/ipc/common/gpu_memory_buffer_support.h" | 9 #include "gpu/ipc/common/gpu_memory_buffer_support.h" |
9 #include "gpu/ipc/service/gpu_memory_buffer_factory.h" | 10 #include "gpu/ipc/service/gpu_memory_buffer_factory.h" |
10 #include "gpu/ipc/service/gpu_watchdog_thread.h" | 11 #include "gpu/ipc/service/gpu_watchdog_thread.h" |
11 #include "services/ui/gpu/gpu_service_internal.h" | 12 #include "services/ui/gpu/gpu_service_internal.h" |
12 | 13 |
14 namespace { | |
15 | |
16 #if defined(OS_WIN) | |
17 std::unique_ptr<base::MessagePump> CreateMessagePumpWin() { | |
18 base::MessagePumpForGpu::InitFactory(); | |
19 return base::MessageLoop::CreateMessagePumpForType( | |
20 base::MessageLoop::TYPE_UI); | |
21 } | |
22 #endif // defined(OS_WIN) | |
23 | |
24 #if defined(USE_X11) | |
25 std::unique_ptr<base::MessagePump> CreateMessagePumpX11() { | |
26 // TODO(sad): This should create a TYPE_UI message pump, and create a | |
27 // PlatformEventSource when gpu process split happens. | |
28 return base::MessageLoop::CreateMessagePumpForType( | |
29 base::MessageLoop::TYPE_DEFAULT); | |
30 } | |
31 #endif // defined(USE_X11) | |
32 | |
33 #if defined(OS_MACOSX) | |
34 std::unique_ptr<base::MessagePump> CreateMessagePumpMac() { | |
35 return base::MakeUnique<base::MessagePumpCFRunLoop>(); | |
36 } | |
37 #endif // defined(OS_MACOSX) | |
38 | |
39 } // namespace | |
40 | |
13 namespace ui { | 41 namespace ui { |
14 | 42 |
15 GpuMain::GpuMain() { | 43 GpuMain::GpuMain() |
16 gpu_init_.set_sandbox_helper(this); | 44 : gpu_thread_("GpuThread"), io_thread_("GpuIOThread"), weak_factory_(this) { |
17 bool success = gpu_init_.InitializeAndStartSandbox( | 45 base::Thread::Options thread_options; |
46 | |
47 #if defined(OS_WIN) | |
48 thread_options.message_pump_factory = base::Bind(&CreateMessagePumpWin); | |
49 #elif defined(USE_X11) | |
50 thread_options.message_pump_factory = base::Bind(&CreateMessagePumpX11); | |
51 #elif defined(USE_OZONE) | |
52 thread_options.message_loop_type = base::MessageLoop::TYPE_UI; | |
rjkroege
2016/09/25 14:31:21
My intuition is that this is the not right. I pres
sadrul
2016/09/25 22:09:57
Yes. The 'main' thread is initialized in mojo-runn
| |
53 #elif defined(OS_LINUX) | |
54 thread_options.message_loop_type = base::MessageLoop::TYPE_DEFAULT; | |
55 #elif defined(OS_MACOSX) | |
56 thread_options.message_pump_factory = base::Bind(&CreateMessagePumpMac); | |
57 #else | |
58 thread_options.message_loop_type = base::MessageLoop::TYPE_IO; | |
59 #endif | |
60 | |
61 #if defined(OS_ANDROID) || defined(OS_CHROMEOS) | |
62 thread_options.priority = base::ThreadPriority::DISPLAY; | |
63 #endif | |
64 CHECK(gpu_thread_.StartWithOptions(thread_options)); | |
65 | |
66 // TODO(sad): We do not need the IO thread once gpu has a separate process. It | |
rjkroege
2016/09/25 14:31:21
why do we need it now?
sadrul
2016/09/25 22:09:57
I think we can get rid of it, and plan on just usi
| |
67 // should be possible to use |main_task_runner_| for doing IO tasks. | |
68 thread_options = base::Thread::Options(base::MessageLoop::TYPE_IO, 0); | |
69 thread_options.priority = base::ThreadPriority::NORMAL; | |
70 #if defined(OS_ANDROID) || defined(OS_CHROMEOS) | |
71 // TODO(reveman): Remove this in favor of setting it explicitly for each type | |
72 // of process. | |
73 thread_options.priority = base::ThreadPriority::DISPLAY; | |
74 #endif | |
75 CHECK(io_thread_.StartWithOptions(thread_options)); | |
76 } | |
77 | |
78 GpuMain::~GpuMain() { | |
79 // Unretained() is OK here since the thread/task runner is owned by |this|. | |
80 gpu_thread_.task_runner()->PostTask( | |
81 FROM_HERE, | |
82 base::Bind(&GpuMain::TearDownOnGpuThread, base::Unretained(this))); | |
83 gpu_thread_.Stop(); | |
84 io_thread_.Stop(); | |
85 } | |
86 | |
87 void GpuMain::OnStart() { | |
88 gpu_thread_.task_runner()->PostTask( | |
89 FROM_HERE, | |
90 base::Bind(&GpuMain::InitOnGpuThread, weak_factory_.GetWeakPtr())); | |
91 } | |
92 | |
93 void GpuMain::Create(mojom::GpuServiceInternalRequest request) { | |
94 gpu_thread_.task_runner()->PostTask( | |
95 FROM_HERE, | |
96 base::Bind(&GpuMain::CreateOnGpuThread, weak_factory_.GetWeakPtr(), | |
97 base::Passed(std::move(request)))); | |
98 } | |
99 | |
100 void GpuMain::InitOnGpuThread() { | |
101 gpu_init_.reset(new gpu::GpuInit()); | |
102 gpu_init_->set_sandbox_helper(this); | |
103 bool success = gpu_init_->InitializeAndStartSandbox( | |
18 *base::CommandLine::ForCurrentProcess()); | 104 *base::CommandLine::ForCurrentProcess()); |
19 if (success) { | 105 if (success) { |
20 if (gpu::GetNativeGpuMemoryBufferType() != gfx::EMPTY_BUFFER) { | 106 if (gpu::GetNativeGpuMemoryBufferType() != gfx::EMPTY_BUFFER) { |
21 gpu_memory_buffer_factory_ = | 107 gpu_memory_buffer_factory_ = |
22 gpu::GpuMemoryBufferFactory::CreateNativeType(); | 108 gpu::GpuMemoryBufferFactory::CreateNativeType(); |
23 } | 109 } |
24 gpu_service_internal_.reset(new GpuServiceInternal( | 110 gpu_service_internal_.reset(new GpuServiceInternal( |
25 gpu_init_.gpu_info(), gpu_init_.watchdog_thread(), | 111 gpu_init_->gpu_info(), gpu_init_->watchdog_thread(), |
26 gpu_memory_buffer_factory_.get())); | 112 gpu_memory_buffer_factory_.get(), io_thread_.task_runner())); |
27 } | 113 } |
28 } | 114 } |
29 | 115 |
30 GpuMain::~GpuMain() { | 116 void GpuMain::TearDownOnGpuThread() { |
31 if (gpu_init_.watchdog_thread()) | 117 gpu_service_internal_.reset(); |
32 gpu_init_.watchdog_thread()->Stop(); | 118 gpu_memory_buffer_factory_.reset(); |
119 if (gpu_init_->watchdog_thread()) | |
120 gpu_init_->watchdog_thread()->Stop(); | |
121 gpu_init_.reset(); | |
33 } | 122 } |
34 | 123 |
35 void GpuMain::Add(mojom::GpuServiceInternalRequest request) { | 124 void GpuMain::CreateOnGpuThread(mojom::GpuServiceInternalRequest request) { |
36 if (gpu_service_internal_) | 125 if (gpu_service_internal_) |
37 gpu_service_internal_->Add(std::move(request)); | 126 gpu_service_internal_->Add(std::move(request)); |
38 } | 127 } |
39 | 128 |
40 void GpuMain::PreSandboxStartup() { | 129 void GpuMain::PreSandboxStartup() { |
41 // TODO(sad): https://crbug.com/645602 | 130 // TODO(sad): https://crbug.com/645602 |
42 } | 131 } |
43 | 132 |
44 bool GpuMain::EnsureSandboxInitialized() { | 133 bool GpuMain::EnsureSandboxInitialized() { |
45 // TODO(sad): https://crbug.com/645602 | 134 // TODO(sad): https://crbug.com/645602 |
46 return true; | 135 return true; |
47 } | 136 } |
48 | 137 |
49 } // namespace ui | 138 } // namespace ui |
OLD | NEW |