OLD | NEW |
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" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 | 56 |
57 namespace content { | 57 namespace content { |
58 namespace { | 58 namespace { |
59 | 59 |
60 base::LazyInstance<base::ThreadLocalPointer<GpuChildThread>> g_lazy_tls = | 60 base::LazyInstance<base::ThreadLocalPointer<GpuChildThread>> g_lazy_tls = |
61 LAZY_INSTANCE_INITIALIZER; | 61 LAZY_INSTANCE_INITIALIZER; |
62 | 62 |
63 static base::LazyInstance<scoped_refptr<ThreadSafeSender> > | 63 static base::LazyInstance<scoped_refptr<ThreadSafeSender> > |
64 g_thread_safe_sender = LAZY_INSTANCE_INITIALIZER; | 64 g_thread_safe_sender = LAZY_INSTANCE_INITIALIZER; |
65 | 65 |
66 bool GpuProcessLogMessageHandler(int severity, | |
67 const char* file, int line, | |
68 size_t message_start, | |
69 const std::string& str) { | |
70 std::string header = str.substr(0, message_start); | |
71 std::string message = str.substr(message_start); | |
72 | |
73 g_thread_safe_sender.Get()->Send( | |
74 new GpuHostMsg_OnLogMessage(severity, header, message)); | |
75 | |
76 return false; | |
77 } | |
78 | |
79 // Message filter used to to handle GpuMsg_CreateGpuMemoryBuffer messages | 66 // Message filter used to to handle GpuMsg_CreateGpuMemoryBuffer messages |
80 // on the IO thread. This allows the UI thread in the browser process to remain | 67 // on the IO thread. This allows the UI thread in the browser process to remain |
81 // fast at all times. | 68 // fast at all times. |
82 class GpuMemoryBufferMessageFilter : public IPC::MessageFilter { | 69 class GpuMemoryBufferMessageFilter : public IPC::MessageFilter { |
83 public: | 70 public: |
84 explicit GpuMemoryBufferMessageFilter( | 71 explicit GpuMemoryBufferMessageFilter( |
85 gpu::GpuMemoryBufferFactory* gpu_memory_buffer_factory) | 72 gpu::GpuMemoryBufferFactory* gpu_memory_buffer_factory) |
86 : gpu_memory_buffer_factory_(gpu_memory_buffer_factory), | 73 : gpu_memory_buffer_factory_(gpu_memory_buffer_factory), |
87 sender_(nullptr) {} | 74 sender_(nullptr) {} |
88 | 75 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 ->GetMessageFilter(); | 124 ->GetMessageFilter(); |
138 if (message_filter) | 125 if (message_filter) |
139 builder.AddStartupFilter(message_filter); | 126 builder.AddStartupFilter(message_filter); |
140 #endif | 127 #endif |
141 | 128 |
142 return builder.Build(); | 129 return builder.Build(); |
143 } | 130 } |
144 | 131 |
145 } // namespace | 132 } // namespace |
146 | 133 |
| 134 void GpuProcessLogMessageListener::OnMessage(int severity, const char* file, |
| 135 int line, size_t message_start, const std::string& str) { |
| 136 std::string header = str.substr(0, message_start); |
| 137 std::string message = str.substr(message_start); |
| 138 |
| 139 g_thread_safe_sender.Get()->Send( |
| 140 new GpuHostMsg_OnLogMessage(severity, header, message)); |
| 141 } |
| 142 |
147 // static | 143 // static |
148 GpuChildThread* GpuChildThread::current() { | 144 GpuChildThread* GpuChildThread::current() { |
149 return g_lazy_tls.Pointer()->Get(); | 145 return g_lazy_tls.Pointer()->Get(); |
150 } | 146 } |
151 | 147 |
152 GpuChildThread::GpuChildThread( | 148 GpuChildThread::GpuChildThread( |
153 GpuWatchdogThread* watchdog_thread, | 149 GpuWatchdogThread* watchdog_thread, |
154 bool dead_on_arrival, | 150 bool dead_on_arrival, |
155 const gpu::GPUInfo& gpu_info, | 151 const gpu::GPUInfo& gpu_info, |
156 const DeferredMessages& deferred_messages, | 152 const DeferredMessages& deferred_messages, |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 GpuChildThread::~GpuChildThread() { | 197 GpuChildThread::~GpuChildThread() { |
202 while (!deferred_messages_.empty()) { | 198 while (!deferred_messages_.empty()) { |
203 delete deferred_messages_.front(); | 199 delete deferred_messages_.front(); |
204 deferred_messages_.pop(); | 200 deferred_messages_.pop(); |
205 } | 201 } |
206 g_lazy_tls.Pointer()->Set(nullptr); | 202 g_lazy_tls.Pointer()->Set(nullptr); |
207 } | 203 } |
208 | 204 |
209 void GpuChildThread::Shutdown() { | 205 void GpuChildThread::Shutdown() { |
210 ChildThreadImpl::Shutdown(); | 206 ChildThreadImpl::Shutdown(); |
211 logging::SetLogMessageHandler(NULL); | 207 if (!in_browser_process_) |
| 208 log_listener_.reset(); |
212 } | 209 } |
213 | 210 |
214 void GpuChildThread::Init(const base::Time& process_start_time) { | 211 void GpuChildThread::Init(const base::Time& process_start_time) { |
215 process_start_time_ = process_start_time; | 212 process_start_time_ = process_start_time; |
216 | 213 |
217 #if defined(OS_ANDROID) | 214 #if defined(OS_ANDROID) |
218 // When running in in-process mode, this has been set in the browser at | 215 // When running in in-process mode, this has been set in the browser at |
219 // ChromeBrowserMainPartsAndroid::PreMainMessageLoopRun(). | 216 // ChromeBrowserMainPartsAndroid::PreMainMessageLoopRun(). |
220 if (!in_browser_process_) | 217 if (!in_browser_process_) |
221 media::SetMediaClientAndroid(GetContentClient()->GetMediaClientAndroid()); | 218 media::SetMediaClientAndroid(GetContentClient()->GetMediaClientAndroid()); |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 | 368 |
372 if (dead_on_arrival_) { | 369 if (dead_on_arrival_) { |
373 LOG(ERROR) << "Exiting GPU process due to errors during initialization"; | 370 LOG(ERROR) << "Exiting GPU process due to errors during initialization"; |
374 base::MessageLoop::current()->QuitWhenIdle(); | 371 base::MessageLoop::current()->QuitWhenIdle(); |
375 return; | 372 return; |
376 } | 373 } |
377 | 374 |
378 // We don't need to pipe log messages if we are running the GPU thread in | 375 // We don't need to pipe log messages if we are running the GPU thread in |
379 // the browser process. | 376 // the browser process. |
380 if (!in_browser_process_) | 377 if (!in_browser_process_) |
381 logging::SetLogMessageHandler(GpuProcessLogMessageHandler); | 378 log_listener_ = base::MakeUnique<GpuProcessLogMessageListener>(); |
382 | 379 |
383 gpu::SyncPointManager* sync_point_manager = nullptr; | 380 gpu::SyncPointManager* sync_point_manager = nullptr; |
384 // Note SyncPointManager from ContentGpuClient cannot be owned by this. | 381 // Note SyncPointManager from ContentGpuClient cannot be owned by this. |
385 if (GetContentClient()->gpu()) | 382 if (GetContentClient()->gpu()) |
386 sync_point_manager = GetContentClient()->gpu()->GetSyncPointManager(); | 383 sync_point_manager = GetContentClient()->gpu()->GetSyncPointManager(); |
387 if (!sync_point_manager) { | 384 if (!sync_point_manager) { |
388 if (!owned_sync_point_manager_) { | 385 if (!owned_sync_point_manager_) { |
389 owned_sync_point_manager_.reset(new gpu::SyncPointManager(false)); | 386 owned_sync_point_manager_.reset(new gpu::SyncPointManager(false)); |
390 } | 387 } |
391 sync_point_manager = owned_sync_point_manager_.get(); | 388 sync_point_manager = owned_sync_point_manager_.get(); |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
568 | 565 |
569 void GpuChildThread::BindProcessControlRequest( | 566 void GpuChildThread::BindProcessControlRequest( |
570 mojom::ProcessControlRequest request) { | 567 mojom::ProcessControlRequest request) { |
571 DVLOG(1) << "GPU: Binding ProcessControl request"; | 568 DVLOG(1) << "GPU: Binding ProcessControl request"; |
572 DCHECK(process_control_); | 569 DCHECK(process_control_); |
573 process_control_bindings_.AddBinding(process_control_.get(), | 570 process_control_bindings_.AddBinding(process_control_.get(), |
574 std::move(request)); | 571 std::move(request)); |
575 } | 572 } |
576 | 573 |
577 } // namespace content | 574 } // namespace content |
OLD | NEW |