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

Side by Side Diff: services/ui/gpu/gpu_main.cc

Issue 2736693003: GpuMain: Fix thread_runner() access DCHECK fail (Closed)
Patch Set: Created 3 years, 9 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 unified diff | Download patch
« no previous file with comments | « services/ui/gpu/gpu_main.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "gpu/ipc/common/gpu_memory_buffer_support.h" 10 #include "gpu/ipc/common/gpu_memory_buffer_support.h"
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 #elif defined(OS_MACOSX) 64 #elif defined(OS_MACOSX)
65 thread_options.message_pump_factory = base::Bind(&CreateMessagePumpMac); 65 thread_options.message_pump_factory = base::Bind(&CreateMessagePumpMac);
66 #else 66 #else
67 thread_options.message_loop_type = base::MessageLoop::TYPE_IO; 67 thread_options.message_loop_type = base::MessageLoop::TYPE_IO;
68 #endif 68 #endif
69 69
70 #if defined(OS_ANDROID) || defined(OS_CHROMEOS) 70 #if defined(OS_ANDROID) || defined(OS_CHROMEOS)
71 thread_options.priority = base::ThreadPriority::DISPLAY; 71 thread_options.priority = base::ThreadPriority::DISPLAY;
72 #endif 72 #endif
73 CHECK(gpu_thread_.StartWithOptions(thread_options)); 73 CHECK(gpu_thread_.StartWithOptions(thread_options));
74 gpu_thread_task_runner_ = gpu_thread_.task_runner();
74 75
75 // TODO(sad): We do not need the IO thread once gpu has a separate process. It 76 // TODO(sad): We do not need the IO thread once gpu has a separate process. It
76 // should be possible to use |main_task_runner_| for doing IO tasks. 77 // should be possible to use |main_task_runner_| for doing IO tasks.
77 thread_options = base::Thread::Options(base::MessageLoop::TYPE_IO, 0); 78 thread_options = base::Thread::Options(base::MessageLoop::TYPE_IO, 0);
78 thread_options.priority = base::ThreadPriority::NORMAL; 79 thread_options.priority = base::ThreadPriority::NORMAL;
79 #if defined(OS_ANDROID) || defined(OS_CHROMEOS) 80 #if defined(OS_ANDROID) || defined(OS_CHROMEOS)
80 // TODO(reveman): Remove this in favor of setting it explicitly for each type 81 // TODO(reveman): Remove this in favor of setting it explicitly for each type
81 // of process. 82 // of process.
82 thread_options.priority = base::ThreadPriority::DISPLAY; 83 thread_options.priority = base::ThreadPriority::DISPLAY;
83 #endif 84 #endif
84 CHECK(io_thread_.StartWithOptions(thread_options)); 85 CHECK(io_thread_.StartWithOptions(thread_options));
85 86
86 // Start the compositor thread. 87 // Start the compositor thread.
87 compositor_thread_.Start(); 88 compositor_thread_.Start();
89 compositor_thread_task_runner_ = compositor_thread_.task_runner();
88 } 90 }
89 91
90 GpuMain::~GpuMain() { 92 GpuMain::~GpuMain() {
91 // Unretained() is OK here since the thread/task runner is owned by |this|. 93 // Unretained() is OK here since the thread/task runner is owned by |this|.
92 compositor_thread_.task_runner()->PostTask( 94 compositor_thread_task_runner_->PostTask(
93 FROM_HERE, 95 FROM_HERE,
94 base::Bind(&GpuMain::TearDownOnCompositorThread, base::Unretained(this))); 96 base::Bind(&GpuMain::TearDownOnCompositorThread, base::Unretained(this)));
95 97
96 // Block the main thread until the compositor thread terminates which blocks 98 // Block the main thread until the compositor thread terminates which blocks
97 // on the gpu thread. The Stop must be initiated from here instead of the gpu 99 // on the gpu thread. The Stop must be initiated from here instead of the gpu
98 // thread to avoid deadlock. 100 // thread to avoid deadlock.
99 compositor_thread_.Stop(); 101 compositor_thread_.Stop();
100 102
101 gpu_thread_.task_runner()->PostTask( 103 gpu_thread_task_runner_->PostTask(
102 FROM_HERE, 104 FROM_HERE,
103 base::Bind(&GpuMain::TearDownOnGpuThread, base::Unretained(this))); 105 base::Bind(&GpuMain::TearDownOnGpuThread, base::Unretained(this)));
104 gpu_thread_.Stop(); 106 gpu_thread_.Stop();
105 io_thread_.Stop(); 107 io_thread_.Stop();
106 } 108 }
107 109
108 void GpuMain::OnStart() { 110 void GpuMain::OnStart() {
109 // |this| will outlive the gpu thread and so it's safe to use 111 // |this| will outlive the gpu thread and so it's safe to use
110 // base::Unretained here. 112 // base::Unretained here.
111 gpu_thread_.task_runner()->PostTask( 113 gpu_thread_task_runner_->PostTask(
112 FROM_HERE, 114 FROM_HERE,
113 base::Bind(&GpuMain::InitOnGpuThread, base::Unretained(this), 115 base::Bind(&GpuMain::InitOnGpuThread, base::Unretained(this),
114 io_thread_.task_runner(), compositor_thread_.task_runner())); 116 io_thread_.task_runner(), compositor_thread_task_runner_));
115 } 117 }
116 118
117 void GpuMain::CreateGpuService(mojom::GpuServiceRequest request, 119 void GpuMain::CreateGpuService(mojom::GpuServiceRequest request,
118 mojom::GpuHostPtr gpu_host, 120 mojom::GpuHostPtr gpu_host,
119 const gpu::GpuPreferences& preferences) { 121 const gpu::GpuPreferences& preferences) {
120 // |this| will outlive the gpu thread and so it's safe to use 122 // |this| will outlive the gpu thread and so it's safe to use
121 // base::Unretained here. 123 // base::Unretained here.
122 gpu_thread_.task_runner()->PostTask( 124 gpu_thread_task_runner_->PostTask(
123 FROM_HERE, 125 FROM_HERE,
124 base::Bind(&GpuMain::CreateGpuServiceOnGpuThread, base::Unretained(this), 126 base::Bind(&GpuMain::CreateGpuServiceOnGpuThread, base::Unretained(this),
125 base::Passed(std::move(request)), 127 base::Passed(std::move(request)),
126 base::Passed(gpu_host.PassInterface()), preferences)); 128 base::Passed(gpu_host.PassInterface()), preferences));
127 } 129 }
128 130
129 void GpuMain::CreateDisplayCompositor( 131 void GpuMain::CreateDisplayCompositor(
130 cc::mojom::DisplayCompositorRequest request, 132 cc::mojom::DisplayCompositorRequest request,
131 cc::mojom::DisplayCompositorClientPtr client) { 133 cc::mojom::DisplayCompositorClientPtr client) {
132 if (!gpu_service_) { 134 if (!gpu_service_) {
(...skipping 23 matching lines...) Expand all
156 gpu_init_->gpu_info(), gpu_init_->TakeWatchdogThread(), 158 gpu_init_->gpu_info(), gpu_init_->TakeWatchdogThread(),
157 gpu_memory_buffer_factory_.get(), io_runner, 159 gpu_memory_buffer_factory_.get(), io_runner,
158 gpu_init_->gpu_feature_info()); 160 gpu_init_->gpu_feature_info());
159 } 161 }
160 162
161 void GpuMain::CreateDisplayCompositorInternal( 163 void GpuMain::CreateDisplayCompositorInternal(
162 cc::mojom::DisplayCompositorRequest request, 164 cc::mojom::DisplayCompositorRequest request,
163 cc::mojom::DisplayCompositorClientPtrInfo client_info) { 165 cc::mojom::DisplayCompositorClientPtrInfo client_info) {
164 DCHECK(!gpu_command_service_); 166 DCHECK(!gpu_command_service_);
165 gpu_command_service_ = new gpu::GpuInProcessThreadService( 167 gpu_command_service_ = new gpu::GpuInProcessThreadService(
166 gpu_thread_.task_runner(), gpu_service_->sync_point_manager(), 168 gpu_thread_task_runner_, gpu_service_->sync_point_manager(),
167 gpu_service_->mailbox_manager(), gpu_service_->share_group()); 169 gpu_service_->mailbox_manager(), gpu_service_->share_group());
168 170
169 // |gpu_memory_buffer_factory_| is null in tests. 171 // |gpu_memory_buffer_factory_| is null in tests.
170 gpu::ImageFactory* image_factory = 172 gpu::ImageFactory* image_factory =
171 gpu_memory_buffer_factory_ ? gpu_memory_buffer_factory_->AsImageFactory() 173 gpu_memory_buffer_factory_ ? gpu_memory_buffer_factory_->AsImageFactory()
172 : nullptr; 174 : nullptr;
173 175
174 mojom::GpuServicePtr gpu_service; 176 mojom::GpuServicePtr gpu_service;
175 mojom::GpuServiceRequest gpu_service_request(&gpu_service); 177 mojom::GpuServiceRequest gpu_service_request(&gpu_service);
176 178
177 if (gpu_thread_.task_runner()->BelongsToCurrentThread()) { 179 if (gpu_thread_task_runner_->BelongsToCurrentThread()) {
178 // If the DisplayCompositor creation was delayed because GpuService 180 // If the DisplayCompositor creation was delayed because GpuService
179 // had not been created yet, then this is called, in gpu thread, right after 181 // had not been created yet, then this is called, in gpu thread, right after
180 // GpuService is created. 182 // GpuService is created.
181 BindGpuInternalOnGpuThread(std::move(gpu_service_request)); 183 BindGpuInternalOnGpuThread(std::move(gpu_service_request));
182 } else { 184 } else {
183 gpu_thread_.task_runner()->PostTask( 185 gpu_thread_task_runner_->PostTask(
184 FROM_HERE, 186 FROM_HERE,
185 base::Bind(&GpuMain::BindGpuInternalOnGpuThread, base::Unretained(this), 187 base::Bind(&GpuMain::BindGpuInternalOnGpuThread, base::Unretained(this),
186 base::Passed(std::move(gpu_service_request)))); 188 base::Passed(std::move(gpu_service_request))));
187 } 189 }
188 190
189 compositor_thread_.task_runner()->PostTask( 191 compositor_thread_task_runner_->PostTask(
190 FROM_HERE, base::Bind(&GpuMain::CreateDisplayCompositorOnCompositorThread, 192 FROM_HERE, base::Bind(&GpuMain::CreateDisplayCompositorOnCompositorThread,
191 base::Unretained(this), image_factory, 193 base::Unretained(this), image_factory,
192 base::Passed(gpu_service.PassInterface()), 194 base::Passed(gpu_service.PassInterface()),
193 base::Passed(std::move(request)), 195 base::Passed(std::move(request)),
194 base::Passed(std::move(client_info)))); 196 base::Passed(std::move(client_info))));
195 } 197 }
196 198
197 void GpuMain::CreateDisplayCompositorOnCompositorThread( 199 void GpuMain::CreateDisplayCompositorOnCompositorThread(
198 gpu::ImageFactory* image_factory, 200 gpu::ImageFactory* image_factory,
199 mojom::GpuServicePtrInfo gpu_service_info, 201 mojom::GpuServicePtrInfo gpu_service_info,
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 // TODO(sad): https://crbug.com/645602 248 // TODO(sad): https://crbug.com/645602
247 } 249 }
248 250
249 bool GpuMain::EnsureSandboxInitialized( 251 bool GpuMain::EnsureSandboxInitialized(
250 gpu::GpuWatchdogThread* watchdog_thread) { 252 gpu::GpuWatchdogThread* watchdog_thread) {
251 // TODO(sad): https://crbug.com/645602 253 // TODO(sad): https://crbug.com/645602
252 return true; 254 return true;
253 } 255 }
254 256
255 } // namespace ui 257 } // namespace ui
OLDNEW
« no previous file with comments | « services/ui/gpu/gpu_main.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698