Chromium Code Reviews| 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 "base/message_loop/message_loop.h" |
| 9 #include "gpu/ipc/common/gpu_memory_buffer_support.h" | 9 #include "gpu/ipc/common/gpu_memory_buffer_support.h" |
| 10 #include "gpu/ipc/service/gpu_memory_buffer_factory.h" | 10 #include "gpu/ipc/service/gpu_memory_buffer_factory.h" |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 34 std::unique_ptr<base::MessagePump> CreateMessagePumpMac() { | 34 std::unique_ptr<base::MessagePump> CreateMessagePumpMac() { |
| 35 return base::MakeUnique<base::MessagePumpCFRunLoop>(); | 35 return base::MakeUnique<base::MessagePumpCFRunLoop>(); |
| 36 } | 36 } |
| 37 #endif // defined(OS_MACOSX) | 37 #endif // defined(OS_MACOSX) |
| 38 | 38 |
| 39 } // namespace | 39 } // namespace |
| 40 | 40 |
| 41 namespace ui { | 41 namespace ui { |
| 42 | 42 |
| 43 GpuMain::GpuMain() | 43 GpuMain::GpuMain() |
| 44 : gpu_thread_("GpuThread"), io_thread_("GpuIOThread"), weak_factory_(this) { | 44 : gpu_thread_("GpuThread"), |
| 45 io_thread_("GpuIOThread"), | |
| 46 compositor_thread_("DisplayCompositorThread"), | |
| 47 weak_factory_(this) { | |
| 45 base::Thread::Options thread_options; | 48 base::Thread::Options thread_options; |
| 46 | 49 |
| 47 #if defined(OS_WIN) | 50 #if defined(OS_WIN) |
| 48 thread_options.message_pump_factory = base::Bind(&CreateMessagePumpWin); | 51 thread_options.message_pump_factory = base::Bind(&CreateMessagePumpWin); |
| 49 #elif defined(USE_X11) | 52 #elif defined(USE_X11) |
| 50 thread_options.message_pump_factory = base::Bind(&CreateMessagePumpX11); | 53 thread_options.message_pump_factory = base::Bind(&CreateMessagePumpX11); |
| 51 #elif defined(USE_OZONE) | 54 #elif defined(USE_OZONE) |
| 52 thread_options.message_loop_type = base::MessageLoop::TYPE_UI; | 55 thread_options.message_loop_type = base::MessageLoop::TYPE_UI; |
| 53 #elif defined(OS_LINUX) | 56 #elif defined(OS_LINUX) |
| 54 thread_options.message_loop_type = base::MessageLoop::TYPE_DEFAULT; | 57 thread_options.message_loop_type = base::MessageLoop::TYPE_DEFAULT; |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 66 // TODO(sad): We do not need the IO thread once gpu has a separate process. It | 69 // TODO(sad): We do not need the IO thread once gpu has a separate process. It |
| 67 // should be possible to use |main_task_runner_| for doing IO tasks. | 70 // should be possible to use |main_task_runner_| for doing IO tasks. |
| 68 thread_options = base::Thread::Options(base::MessageLoop::TYPE_IO, 0); | 71 thread_options = base::Thread::Options(base::MessageLoop::TYPE_IO, 0); |
| 69 thread_options.priority = base::ThreadPriority::NORMAL; | 72 thread_options.priority = base::ThreadPriority::NORMAL; |
| 70 #if defined(OS_ANDROID) || defined(OS_CHROMEOS) | 73 #if defined(OS_ANDROID) || defined(OS_CHROMEOS) |
| 71 // TODO(reveman): Remove this in favor of setting it explicitly for each type | 74 // TODO(reveman): Remove this in favor of setting it explicitly for each type |
| 72 // of process. | 75 // of process. |
| 73 thread_options.priority = base::ThreadPriority::DISPLAY; | 76 thread_options.priority = base::ThreadPriority::DISPLAY; |
| 74 #endif | 77 #endif |
| 75 CHECK(io_thread_.StartWithOptions(thread_options)); | 78 CHECK(io_thread_.StartWithOptions(thread_options)); |
| 79 | |
| 80 // Start the compositor thread. | |
| 81 compositor_thread_.Start(); | |
| 76 } | 82 } |
| 77 | 83 |
| 78 GpuMain::~GpuMain() { | 84 GpuMain::~GpuMain() { |
| 79 // Unretained() is OK here since the thread/task runner is owned by |this|. | 85 // Unretained() is OK here since the thread/task runner is owned by |this|. |
| 86 compositor_thread_.task_runner()->PostTask( | |
| 87 FROM_HERE, | |
| 88 base::Bind(&GpuMain::TearDownOnCompositorThread, base::Unretained(this))); | |
| 89 // Block the main thread until the compositor thread terminates which blocks | |
| 90 // on the gpu thread. The Stop must be initiated from here instead of the gpu | |
| 91 // thread to avoid deadlock. | |
| 92 compositor_thread_.Stop(); | |
| 93 | |
| 80 gpu_thread_.task_runner()->PostTask( | 94 gpu_thread_.task_runner()->PostTask( |
| 81 FROM_HERE, | 95 FROM_HERE, |
| 82 base::Bind(&GpuMain::TearDownOnGpuThread, base::Unretained(this))); | 96 base::Bind(&GpuMain::TearDownOnGpuThread, base::Unretained(this))); |
| 83 gpu_thread_.Stop(); | 97 gpu_thread_.Stop(); |
| 84 io_thread_.Stop(); | 98 io_thread_.Stop(); |
| 85 } | 99 } |
| 86 | 100 |
| 87 void GpuMain::OnStart() { | 101 void GpuMain::OnStart() { |
| 88 gpu_thread_.task_runner()->PostTask( | 102 gpu_thread_.task_runner()->PostTask( |
| 89 FROM_HERE, | 103 FROM_HERE, |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 102 gpu_init_->set_sandbox_helper(this); | 116 gpu_init_->set_sandbox_helper(this); |
| 103 bool success = gpu_init_->InitializeAndStartSandbox( | 117 bool success = gpu_init_->InitializeAndStartSandbox( |
| 104 *base::CommandLine::ForCurrentProcess()); | 118 *base::CommandLine::ForCurrentProcess()); |
| 105 if (success) { | 119 if (success) { |
| 106 if (gpu::GetNativeGpuMemoryBufferType() != gfx::EMPTY_BUFFER) { | 120 if (gpu::GetNativeGpuMemoryBufferType() != gfx::EMPTY_BUFFER) { |
| 107 gpu_memory_buffer_factory_ = | 121 gpu_memory_buffer_factory_ = |
| 108 gpu::GpuMemoryBufferFactory::CreateNativeType(); | 122 gpu::GpuMemoryBufferFactory::CreateNativeType(); |
| 109 } | 123 } |
| 110 gpu_service_internal_.reset(new GpuServiceInternal( | 124 gpu_service_internal_.reset(new GpuServiceInternal( |
| 111 gpu_init_->gpu_info(), gpu_init_->TakeWatchdogThread(), | 125 gpu_init_->gpu_info(), gpu_init_->TakeWatchdogThread(), |
| 112 gpu_memory_buffer_factory_.get(), io_thread_.task_runner())); | 126 gpu_memory_buffer_factory_.get(), io_thread_.task_runner(), |
| 127 compositor_thread_.task_runner())); | |
| 113 } | 128 } |
| 114 } | 129 } |
| 115 | 130 |
| 131 void GpuMain::TearDownOnCompositorThread() { | |
| 132 gpu_service_internal_->DestroyDisplayCompositor(); | |
|
sadrul
2016/11/24 05:07:17
It is possible to be here without having the |gpu_
Fady Samuel
2016/11/24 05:21:55
The problem is "CreateDisplayCompositor" is part o
| |
| 133 } | |
| 134 | |
| 116 void GpuMain::TearDownOnGpuThread() { | 135 void GpuMain::TearDownOnGpuThread() { |
| 117 gpu_service_internal_.reset(); | 136 gpu_service_internal_.reset(); |
| 118 gpu_memory_buffer_factory_.reset(); | 137 gpu_memory_buffer_factory_.reset(); |
| 119 gpu_init_.reset(); | 138 gpu_init_.reset(); |
| 120 } | 139 } |
| 121 | 140 |
| 122 void GpuMain::CreateOnGpuThread(mojom::GpuServiceInternalRequest request) { | 141 void GpuMain::CreateOnGpuThread(mojom::GpuServiceInternalRequest request) { |
| 123 if (gpu_service_internal_) | 142 if (gpu_service_internal_) |
| 124 gpu_service_internal_->Add(std::move(request)); | 143 gpu_service_internal_->Add(std::move(request)); |
| 125 } | 144 } |
| 126 | 145 |
| 127 void GpuMain::PreSandboxStartup() { | 146 void GpuMain::PreSandboxStartup() { |
| 128 // TODO(sad): https://crbug.com/645602 | 147 // TODO(sad): https://crbug.com/645602 |
| 129 } | 148 } |
| 130 | 149 |
| 131 bool GpuMain::EnsureSandboxInitialized( | 150 bool GpuMain::EnsureSandboxInitialized( |
| 132 gpu::GpuWatchdogThread* watchdog_thread) { | 151 gpu::GpuWatchdogThread* watchdog_thread) { |
| 133 // TODO(sad): https://crbug.com/645602 | 152 // TODO(sad): https://crbug.com/645602 |
| 134 return true; | 153 return true; |
| 135 } | 154 } |
| 136 | 155 |
| 137 } // namespace ui | 156 } // namespace ui |
| OLD | NEW |