| 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, |
| 90 base::Bind(&GpuMain::InitOnGpuThread, weak_factory_.GetWeakPtr())); | 104 base::Bind(&GpuMain::InitOnGpuThread, weak_factory_.GetWeakPtr(), |
| 105 io_thread_.task_runner(), compositor_thread_.task_runner())); |
| 91 } | 106 } |
| 92 | 107 |
| 93 void GpuMain::Create(mojom::GpuServiceInternalRequest request) { | 108 void GpuMain::Create(mojom::GpuServiceInternalRequest request) { |
| 94 gpu_thread_.task_runner()->PostTask( | 109 gpu_thread_.task_runner()->PostTask( |
| 95 FROM_HERE, | 110 FROM_HERE, |
| 96 base::Bind(&GpuMain::CreateOnGpuThread, weak_factory_.GetWeakPtr(), | 111 base::Bind(&GpuMain::CreateOnGpuThread, weak_factory_.GetWeakPtr(), |
| 97 base::Passed(std::move(request)))); | 112 base::Passed(std::move(request)))); |
| 98 } | 113 } |
| 99 | 114 |
| 100 void GpuMain::InitOnGpuThread() { | 115 void GpuMain::InitOnGpuThread( |
| 116 scoped_refptr<base::SingleThreadTaskRunner> io_runner, |
| 117 scoped_refptr<base::SingleThreadTaskRunner> compositor_runner) { |
| 101 gpu_init_.reset(new gpu::GpuInit()); | 118 gpu_init_.reset(new gpu::GpuInit()); |
| 102 gpu_init_->set_sandbox_helper(this); | 119 gpu_init_->set_sandbox_helper(this); |
| 103 bool success = gpu_init_->InitializeAndStartSandbox( | 120 bool success = gpu_init_->InitializeAndStartSandbox( |
| 104 *base::CommandLine::ForCurrentProcess()); | 121 *base::CommandLine::ForCurrentProcess()); |
| 105 if (success) { | 122 if (success) { |
| 106 if (gpu::GetNativeGpuMemoryBufferType() != gfx::EMPTY_BUFFER) { | 123 if (gpu::GetNativeGpuMemoryBufferType() != gfx::EMPTY_BUFFER) { |
| 107 gpu_memory_buffer_factory_ = | 124 gpu_memory_buffer_factory_ = |
| 108 gpu::GpuMemoryBufferFactory::CreateNativeType(); | 125 gpu::GpuMemoryBufferFactory::CreateNativeType(); |
| 109 } | 126 } |
| 110 gpu_service_internal_.reset(new GpuServiceInternal( | 127 gpu_service_internal_.reset(new GpuServiceInternal( |
| 111 gpu_init_->gpu_info(), gpu_init_->TakeWatchdogThread(), | 128 gpu_init_->gpu_info(), gpu_init_->TakeWatchdogThread(), |
| 112 gpu_memory_buffer_factory_.get(), io_thread_.task_runner())); | 129 gpu_memory_buffer_factory_.get(), io_runner, compositor_runner)); |
| 113 } | 130 } |
| 114 } | 131 } |
| 115 | 132 |
| 133 void GpuMain::TearDownOnCompositorThread() { |
| 134 if (gpu_service_internal_) |
| 135 gpu_service_internal_->DestroyDisplayCompositor(); |
| 136 } |
| 137 |
| 116 void GpuMain::TearDownOnGpuThread() { | 138 void GpuMain::TearDownOnGpuThread() { |
| 117 gpu_service_internal_.reset(); | 139 gpu_service_internal_.reset(); |
| 118 gpu_memory_buffer_factory_.reset(); | 140 gpu_memory_buffer_factory_.reset(); |
| 119 gpu_init_.reset(); | 141 gpu_init_.reset(); |
| 120 } | 142 } |
| 121 | 143 |
| 122 void GpuMain::CreateOnGpuThread(mojom::GpuServiceInternalRequest request) { | 144 void GpuMain::CreateOnGpuThread(mojom::GpuServiceInternalRequest request) { |
| 123 if (gpu_service_internal_) | 145 if (gpu_service_internal_) |
| 124 gpu_service_internal_->Add(std::move(request)); | 146 gpu_service_internal_->Add(std::move(request)); |
| 125 } | 147 } |
| 126 | 148 |
| 127 void GpuMain::PreSandboxStartup() { | 149 void GpuMain::PreSandboxStartup() { |
| 128 // TODO(sad): https://crbug.com/645602 | 150 // TODO(sad): https://crbug.com/645602 |
| 129 } | 151 } |
| 130 | 152 |
| 131 bool GpuMain::EnsureSandboxInitialized( | 153 bool GpuMain::EnsureSandboxInitialized( |
| 132 gpu::GpuWatchdogThread* watchdog_thread) { | 154 gpu::GpuWatchdogThread* watchdog_thread) { |
| 133 // TODO(sad): https://crbug.com/645602 | 155 // TODO(sad): https://crbug.com/645602 |
| 134 return true; | 156 return true; |
| 135 } | 157 } |
| 136 | 158 |
| 137 } // namespace ui | 159 } // namespace ui |
| OLD | NEW |