Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(441)

Unified Diff: services/ui/gpu/gpu_main.cc

Issue 2366623002: services/ui: Initialize all of gpu in one thread. (Closed)
Patch Set: . Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « services/ui/gpu/gpu_main.h ('k') | services/ui/gpu/gpu_service_internal.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: services/ui/gpu/gpu_main.cc
diff --git a/services/ui/gpu/gpu_main.cc b/services/ui/gpu/gpu_main.cc
index ae9d93c694a5116cd287548b4f56838d69c84e20..a6b4e4b52b237eb5e1d8379460d45acf53b358b9 100644
--- a/services/ui/gpu/gpu_main.cc
+++ b/services/ui/gpu/gpu_main.cc
@@ -5,16 +5,102 @@
#include "services/ui/gpu/gpu_main.h"
#include "base/command_line.h"
+#include "base/message_loop/message_loop.h"
#include "gpu/ipc/common/gpu_memory_buffer_support.h"
#include "gpu/ipc/service/gpu_memory_buffer_factory.h"
#include "gpu/ipc/service/gpu_watchdog_thread.h"
#include "services/ui/gpu/gpu_service_internal.h"
+namespace {
+
+#if defined(OS_WIN)
+std::unique_ptr<base::MessagePump> CreateMessagePumpWin() {
+ base::MessagePumpForGpu::InitFactory();
+ return base::MessageLoop::CreateMessagePumpForType(
+ base::MessageLoop::TYPE_UI);
+}
+#endif // defined(OS_WIN)
+
+#if defined(USE_X11)
+std::unique_ptr<base::MessagePump> CreateMessagePumpX11() {
+ // TODO(sad): This should create a TYPE_UI message pump, and create a
+ // PlatformEventSource when gpu process split happens.
+ return base::MessageLoop::CreateMessagePumpForType(
+ base::MessageLoop::TYPE_DEFAULT);
+}
+#endif // defined(USE_X11)
+
+#if defined(OS_MACOSX)
+std::unique_ptr<base::MessagePump> CreateMessagePumpMac() {
+ return base::MakeUnique<base::MessagePumpCFRunLoop>();
+}
+#endif // defined(OS_MACOSX)
+
+} // namespace
+
namespace ui {
-GpuMain::GpuMain() {
- gpu_init_.set_sandbox_helper(this);
- bool success = gpu_init_.InitializeAndStartSandbox(
+GpuMain::GpuMain()
+ : gpu_thread_("GpuThread"), io_thread_("GpuIOThread"), weak_factory_(this) {
+ base::Thread::Options thread_options;
+
+#if defined(OS_WIN)
+ thread_options.message_pump_factory = base::Bind(&CreateMessagePumpWin);
+#elif defined(USE_X11)
+ thread_options.message_pump_factory = base::Bind(&CreateMessagePumpX11);
+#elif defined(USE_OZONE)
+ 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
+#elif defined(OS_LINUX)
+ thread_options.message_loop_type = base::MessageLoop::TYPE_DEFAULT;
+#elif defined(OS_MACOSX)
+ thread_options.message_pump_factory = base::Bind(&CreateMessagePumpMac);
+#else
+ thread_options.message_loop_type = base::MessageLoop::TYPE_IO;
+#endif
+
+#if defined(OS_ANDROID) || defined(OS_CHROMEOS)
+ thread_options.priority = base::ThreadPriority::DISPLAY;
+#endif
+ CHECK(gpu_thread_.StartWithOptions(thread_options));
+
+ // 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
+ // should be possible to use |main_task_runner_| for doing IO tasks.
+ thread_options = base::Thread::Options(base::MessageLoop::TYPE_IO, 0);
+ thread_options.priority = base::ThreadPriority::NORMAL;
+#if defined(OS_ANDROID) || defined(OS_CHROMEOS)
+ // TODO(reveman): Remove this in favor of setting it explicitly for each type
+ // of process.
+ thread_options.priority = base::ThreadPriority::DISPLAY;
+#endif
+ CHECK(io_thread_.StartWithOptions(thread_options));
+}
+
+GpuMain::~GpuMain() {
+ // Unretained() is OK here since the thread/task runner is owned by |this|.
+ gpu_thread_.task_runner()->PostTask(
+ FROM_HERE,
+ base::Bind(&GpuMain::TearDownOnGpuThread, base::Unretained(this)));
+ gpu_thread_.Stop();
+ io_thread_.Stop();
+}
+
+void GpuMain::OnStart() {
+ gpu_thread_.task_runner()->PostTask(
+ FROM_HERE,
+ base::Bind(&GpuMain::InitOnGpuThread, weak_factory_.GetWeakPtr()));
+}
+
+void GpuMain::Create(mojom::GpuServiceInternalRequest request) {
+ gpu_thread_.task_runner()->PostTask(
+ FROM_HERE,
+ base::Bind(&GpuMain::CreateOnGpuThread, weak_factory_.GetWeakPtr(),
+ base::Passed(std::move(request))));
+}
+
+void GpuMain::InitOnGpuThread() {
+ gpu_init_.reset(new gpu::GpuInit());
+ gpu_init_->set_sandbox_helper(this);
+ bool success = gpu_init_->InitializeAndStartSandbox(
*base::CommandLine::ForCurrentProcess());
if (success) {
if (gpu::GetNativeGpuMemoryBufferType() != gfx::EMPTY_BUFFER) {
@@ -22,17 +108,20 @@ GpuMain::GpuMain() {
gpu::GpuMemoryBufferFactory::CreateNativeType();
}
gpu_service_internal_.reset(new GpuServiceInternal(
- gpu_init_.gpu_info(), gpu_init_.watchdog_thread(),
- gpu_memory_buffer_factory_.get()));
+ gpu_init_->gpu_info(), gpu_init_->watchdog_thread(),
+ gpu_memory_buffer_factory_.get(), io_thread_.task_runner()));
}
}
-GpuMain::~GpuMain() {
- if (gpu_init_.watchdog_thread())
- gpu_init_.watchdog_thread()->Stop();
+void GpuMain::TearDownOnGpuThread() {
+ gpu_service_internal_.reset();
+ gpu_memory_buffer_factory_.reset();
+ if (gpu_init_->watchdog_thread())
+ gpu_init_->watchdog_thread()->Stop();
+ gpu_init_.reset();
}
-void GpuMain::Add(mojom::GpuServiceInternalRequest request) {
+void GpuMain::CreateOnGpuThread(mojom::GpuServiceInternalRequest request) {
if (gpu_service_internal_)
gpu_service_internal_->Add(std::move(request));
}
« no previous file with comments | « services/ui/gpu/gpu_main.h ('k') | services/ui/gpu/gpu_service_internal.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698