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

Side by Side Diff: content/gpu/gpu_child_thread.cc

Issue 2763493002: gpu: Use mojom API for recording log messages to the host. (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 | « content/common/gpu_host_messages.h ('k') | services/ui/gpu/gpu_service.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/gpu/gpu_child_thread.h" 5 #include "content/gpu/gpu_child_thread.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/callback_helpers.h" 11 #include "base/callback_helpers.h"
12 #include "base/lazy_instance.h"
13 #include "base/strings/string_number_conversions.h" 12 #include "base/strings/string_number_conversions.h"
14 #include "base/threading/thread_local.h" 13 #include "base/threading/thread_local.h"
15 #include "base/threading/thread_task_runner_handle.h"
16 #include "base/threading/worker_pool.h" 14 #include "base/threading/worker_pool.h"
17 #include "build/build_config.h" 15 #include "build/build_config.h"
18 #include "content/child/child_process.h" 16 #include "content/child/child_process.h"
19 #include "content/child/thread_safe_sender.h" 17 #include "content/child/thread_safe_sender.h"
20 #include "content/common/gpu_host_messages.h" 18 #include "content/common/gpu_host_messages.h"
21 #include "content/gpu/gpu_service_factory.h" 19 #include "content/gpu/gpu_service_factory.h"
22 #include "content/public/common/content_client.h" 20 #include "content/public/common/content_client.h"
23 #include "content/public/common/content_switches.h" 21 #include "content/public/common/content_switches.h"
24 #include "content/public/common/service_manager_connection.h" 22 #include "content/public/common/service_manager_connection.h"
25 #include "content/public/gpu/content_gpu_client.h" 23 #include "content/public/gpu/content_gpu_client.h"
(...skipping 24 matching lines...) Expand all
50 #include "ui/ozone/public/ozone_platform.h" 48 #include "ui/ozone/public/ozone_platform.h"
51 #endif 49 #endif
52 50
53 #if defined(OS_ANDROID) 51 #if defined(OS_ANDROID)
54 #include "media/base/android/media_client_android.h" 52 #include "media/base/android/media_client_android.h"
55 #endif 53 #endif
56 54
57 namespace content { 55 namespace content {
58 namespace { 56 namespace {
59 57
60 static base::LazyInstance<scoped_refptr<ThreadSafeSender>>::DestructorAtExit
61 g_thread_safe_sender = LAZY_INSTANCE_INITIALIZER;
62
63 bool GpuProcessLogMessageHandler(int severity,
64 const char* file, int line,
65 size_t message_start,
66 const std::string& str) {
67 std::string header = str.substr(0, message_start);
68 std::string message = str.substr(message_start);
69
70 g_thread_safe_sender.Get()->Send(
71 new GpuHostMsg_OnLogMessage(severity, header, message));
72
73 return false;
74 }
75
76 // Message filter used to to handle GpuMsg_CreateGpuMemoryBuffer messages 58 // Message filter used to to handle GpuMsg_CreateGpuMemoryBuffer messages
77 // on the IO thread. This allows the UI thread in the browser process to remain 59 // on the IO thread. This allows the UI thread in the browser process to remain
78 // fast at all times. 60 // fast at all times.
79 class GpuMemoryBufferMessageFilter : public IPC::MessageFilter { 61 class GpuMemoryBufferMessageFilter : public IPC::MessageFilter {
80 public: 62 public:
81 explicit GpuMemoryBufferMessageFilter( 63 explicit GpuMemoryBufferMessageFilter(
82 gpu::GpuMemoryBufferFactory* gpu_memory_buffer_factory) 64 gpu::GpuMemoryBufferFactory* gpu_memory_buffer_factory)
83 : gpu_memory_buffer_factory_(gpu_memory_buffer_factory), 65 : gpu_memory_buffer_factory_(gpu_memory_buffer_factory),
84 sender_(nullptr) {} 66 sender_(nullptr) {}
85 67
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 in_browser_process_(false), 138 in_browser_process_(false),
157 gpu_service_(new ui::GpuService(gpu_info, 139 gpu_service_(new ui::GpuService(gpu_info,
158 std::move(watchdog_thread), 140 std::move(watchdog_thread),
159 gpu_memory_buffer_factory, 141 gpu_memory_buffer_factory,
160 ChildProcess::current()->io_task_runner(), 142 ChildProcess::current()->io_task_runner(),
161 gpu_feature_info)), 143 gpu_feature_info)),
162 gpu_main_binding_(this) { 144 gpu_main_binding_(this) {
163 #if defined(OS_WIN) 145 #if defined(OS_WIN)
164 target_services_ = NULL; 146 target_services_ = NULL;
165 #endif 147 #endif
166 g_thread_safe_sender.Get() = thread_safe_sender();
167 } 148 }
168 149
169 GpuChildThread::GpuChildThread( 150 GpuChildThread::GpuChildThread(
170 const InProcessChildThreadParams& params, 151 const InProcessChildThreadParams& params,
171 const gpu::GPUInfo& gpu_info, 152 const gpu::GPUInfo& gpu_info,
172 const gpu::GpuFeatureInfo& gpu_feature_info, 153 const gpu::GpuFeatureInfo& gpu_feature_info,
173 gpu::GpuMemoryBufferFactory* gpu_memory_buffer_factory) 154 gpu::GpuMemoryBufferFactory* gpu_memory_buffer_factory)
174 : ChildThreadImpl(ChildThreadImpl::Options::Builder() 155 : ChildThreadImpl(ChildThreadImpl::Options::Builder()
175 .InBrowserProcess(params) 156 .InBrowserProcess(params)
176 .AddStartupFilter(new GpuMemoryBufferMessageFilter( 157 .AddStartupFilter(new GpuMemoryBufferMessageFilter(
177 gpu_memory_buffer_factory)) 158 gpu_memory_buffer_factory))
178 .ConnectToBrowser(true) 159 .ConnectToBrowser(true)
179 .Build()), 160 .Build()),
180 dead_on_arrival_(false), 161 dead_on_arrival_(false),
181 gpu_info_(gpu_info), 162 gpu_info_(gpu_info),
182 in_browser_process_(true), 163 in_browser_process_(true),
183 gpu_service_(new ui::GpuService(gpu_info, 164 gpu_service_(new ui::GpuService(gpu_info,
184 nullptr /* watchdog thread */, 165 nullptr /* watchdog thread */,
185 gpu_memory_buffer_factory, 166 gpu_memory_buffer_factory,
186 ChildProcess::current()->io_task_runner(), 167 ChildProcess::current()->io_task_runner(),
187 gpu_feature_info)), 168 gpu_feature_info)),
188 gpu_main_binding_(this) { 169 gpu_main_binding_(this) {
189 #if defined(OS_WIN) 170 #if defined(OS_WIN)
190 target_services_ = NULL; 171 target_services_ = NULL;
191 #endif 172 #endif
192 DCHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( 173 DCHECK(base::CommandLine::ForCurrentProcess()->HasSwitch(
193 switches::kSingleProcess) || 174 switches::kSingleProcess) ||
194 base::CommandLine::ForCurrentProcess()->HasSwitch( 175 base::CommandLine::ForCurrentProcess()->HasSwitch(
195 switches::kInProcessGPU)); 176 switches::kInProcessGPU));
196
197 g_thread_safe_sender.Get() = thread_safe_sender();
198 } 177 }
199 178
200 GpuChildThread::~GpuChildThread() { 179 GpuChildThread::~GpuChildThread() {
201 } 180 }
202 181
203 void GpuChildThread::Shutdown() { 182 void GpuChildThread::Shutdown() {
204 ChildThreadImpl::Shutdown(); 183 ChildThreadImpl::Shutdown();
205 logging::SetLogMessageHandler(NULL);
206 } 184 }
207 185
208 void GpuChildThread::Init(const base::Time& process_start_time) { 186 void GpuChildThread::Init(const base::Time& process_start_time) {
209 process_start_time_ = process_start_time; 187 process_start_time_ = process_start_time;
188 gpu_service_->set_in_host_process(in_browser_process_);
210 189
211 #if defined(OS_ANDROID) 190 #if defined(OS_ANDROID)
212 // When running in in-process mode, this has been set in the browser at 191 // When running in in-process mode, this has been set in the browser at
213 // ChromeBrowserMainPartsAndroid::PreMainMessageLoopRun(). 192 // ChromeBrowserMainPartsAndroid::PreMainMessageLoopRun().
214 if (!in_browser_process_) 193 if (!in_browser_process_)
215 media::SetMediaClientAndroid(GetContentClient()->GetMediaClientAndroid()); 194 media::SetMediaClientAndroid(GetContentClient()->GetMediaClientAndroid());
216 #endif 195 #endif
217 // We don't want to process any incoming interface requests until 196 // We don't want to process any incoming interface requests until
218 // OnInitialize() is invoked. 197 // OnInitialize() is invoked.
219 GetInterfaceRegistry()->PauseBinding(); 198 GetInterfaceRegistry()->PauseBinding();
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 media::GpuJpegDecodeAcceleratorFactoryProvider:: 272 media::GpuJpegDecodeAcceleratorFactoryProvider::
294 IsAcceleratedJpegDecodeSupported(); 273 IsAcceleratedJpegDecodeSupported();
295 274
296 // Record initialization only after collecting the GPU info because that can 275 // Record initialization only after collecting the GPU info because that can
297 // take a significant amount of time. 276 // take a significant amount of time.
298 gpu_info_.initialization_time = base::Time::Now() - process_start_time_; 277 gpu_info_.initialization_time = base::Time::Now() - process_start_time_;
299 Send(new GpuHostMsg_Initialized(!dead_on_arrival_, gpu_info_, 278 Send(new GpuHostMsg_Initialized(!dead_on_arrival_, gpu_info_,
300 gpu_service_->gpu_feature_info())); 279 gpu_service_->gpu_feature_info()));
301 while (!deferred_messages_.empty()) { 280 while (!deferred_messages_.empty()) {
302 const LogMessage& log = deferred_messages_.front(); 281 const LogMessage& log = deferred_messages_.front();
303 Send(new GpuHostMsg_OnLogMessage(log.severity, log.header, log.message)); 282 gpu_host->RecordLogMessage(log.severity, log.header, log.message);
304 deferred_messages_.pop(); 283 deferred_messages_.pop();
305 } 284 }
306 285
307 if (dead_on_arrival_) { 286 if (dead_on_arrival_) {
308 LOG(ERROR) << "Exiting GPU process due to errors during initialization"; 287 LOG(ERROR) << "Exiting GPU process due to errors during initialization";
309 base::MessageLoop::current()->QuitWhenIdle(); 288 base::MessageLoop::current()->QuitWhenIdle();
310 return; 289 return;
311 } 290 }
312 291
313 // We don't need to pipe log messages if we are running the GPU thread in
314 // the browser process.
315 if (!in_browser_process_)
316 logging::SetLogMessageHandler(GpuProcessLogMessageHandler);
317
318 gpu::SyncPointManager* sync_point_manager = nullptr; 292 gpu::SyncPointManager* sync_point_manager = nullptr;
319 // Note SyncPointManager from ContentGpuClient cannot be owned by this. 293 // Note SyncPointManager from ContentGpuClient cannot be owned by this.
320 if (GetContentClient()->gpu()) 294 if (GetContentClient()->gpu())
321 sync_point_manager = GetContentClient()->gpu()->GetSyncPointManager(); 295 sync_point_manager = GetContentClient()->gpu()->GetSyncPointManager();
322 gpu_service_->InitializeWithHost( 296 gpu_service_->InitializeWithHost(
323 std::move(gpu_host), gpu_preferences, 297 std::move(gpu_host), gpu_preferences,
324 gpu::GpuProcessActivityFlags(std::move(activity_flags)), 298 gpu::GpuProcessActivityFlags(std::move(activity_flags)),
325 sync_point_manager, ChildProcess::current()->GetShutDownEvent()); 299 sync_point_manager, ChildProcess::current()->GetShutDownEvent());
326 CHECK(gpu_service_->media_gpu_channel_manager()); 300 CHECK(gpu_service_->media_gpu_channel_manager());
327 301
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 393
420 void GpuChildThread::BindServiceFactoryRequest( 394 void GpuChildThread::BindServiceFactoryRequest(
421 service_manager::mojom::ServiceFactoryRequest request) { 395 service_manager::mojom::ServiceFactoryRequest request) {
422 DVLOG(1) << "GPU: Binding service_manager::mojom::ServiceFactoryRequest"; 396 DVLOG(1) << "GPU: Binding service_manager::mojom::ServiceFactoryRequest";
423 DCHECK(service_factory_); 397 DCHECK(service_factory_);
424 service_factory_bindings_.AddBinding(service_factory_.get(), 398 service_factory_bindings_.AddBinding(service_factory_.get(),
425 std::move(request)); 399 std::move(request));
426 } 400 }
427 401
428 } // namespace content 402 } // namespace content
OLDNEW
« no previous file with comments | « content/common/gpu_host_messages.h ('k') | services/ui/gpu/gpu_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698