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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 #include "media/base/android/media_client_android.h" | 53 #include "media/base/android/media_client_android.h" |
54 #include "media/gpu/avda_surface_tracker.h" | 54 #include "media/gpu/avda_surface_tracker.h" |
55 #endif | 55 #endif |
56 | 56 |
57 namespace content { | 57 namespace content { |
58 namespace { | 58 namespace { |
59 | 59 |
60 static base::LazyInstance<scoped_refptr<ThreadSafeSender> > | 60 static base::LazyInstance<scoped_refptr<ThreadSafeSender> > |
61 g_thread_safe_sender = LAZY_INSTANCE_INITIALIZER; | 61 g_thread_safe_sender = LAZY_INSTANCE_INITIALIZER; |
62 | 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 | 63 // 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 | 64 // on the IO thread. This allows the UI thread in the browser process to remain |
78 // fast at all times. | 65 // fast at all times. |
79 class GpuMemoryBufferMessageFilter : public IPC::MessageFilter { | 66 class GpuMemoryBufferMessageFilter : public IPC::MessageFilter { |
80 public: | 67 public: |
81 explicit GpuMemoryBufferMessageFilter( | 68 explicit GpuMemoryBufferMessageFilter( |
82 gpu::GpuMemoryBufferFactory* gpu_memory_buffer_factory) | 69 gpu::GpuMemoryBufferFactory* gpu_memory_buffer_factory) |
83 : gpu_memory_buffer_factory_(gpu_memory_buffer_factory), | 70 : gpu_memory_buffer_factory_(gpu_memory_buffer_factory), |
84 sender_(nullptr) {} | 71 sender_(nullptr) {} |
85 | 72 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 ->GetMessageFilter(); | 121 ->GetMessageFilter(); |
135 if (message_filter) | 122 if (message_filter) |
136 builder.AddStartupFilter(message_filter); | 123 builder.AddStartupFilter(message_filter); |
137 #endif | 124 #endif |
138 | 125 |
139 return builder.Build(); | 126 return builder.Build(); |
140 } | 127 } |
141 | 128 |
142 } // namespace | 129 } // namespace |
143 | 130 |
| 131 void GpuProcessLogMessageListener::OnMessage(int severity, const char* file, |
| 132 int line, size_t message_start, const std::string& str) { |
| 133 std::string header = str.substr(0, message_start); |
| 134 std::string message = str.substr(message_start); |
| 135 |
| 136 g_thread_safe_sender.Get()->Send( |
| 137 new GpuHostMsg_OnLogMessage(severity, header, message)); |
| 138 } |
| 139 |
144 GpuChildThread::GpuChildThread( | 140 GpuChildThread::GpuChildThread( |
145 GpuWatchdogThread* watchdog_thread, | 141 GpuWatchdogThread* watchdog_thread, |
146 bool dead_on_arrival, | 142 bool dead_on_arrival, |
147 const gpu::GPUInfo& gpu_info, | 143 const gpu::GPUInfo& gpu_info, |
148 const DeferredMessages& deferred_messages, | 144 const DeferredMessages& deferred_messages, |
149 gpu::GpuMemoryBufferFactory* gpu_memory_buffer_factory) | 145 gpu::GpuMemoryBufferFactory* gpu_memory_buffer_factory) |
150 : ChildThreadImpl(GetOptions(gpu_memory_buffer_factory)), | 146 : ChildThreadImpl(GetOptions(gpu_memory_buffer_factory)), |
151 dead_on_arrival_(dead_on_arrival), | 147 dead_on_arrival_(dead_on_arrival), |
152 gpu_info_(gpu_info), | 148 gpu_info_(gpu_info), |
153 deferred_messages_(deferred_messages), | 149 deferred_messages_(deferred_messages), |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 | 186 |
191 GpuChildThread::~GpuChildThread() { | 187 GpuChildThread::~GpuChildThread() { |
192 while (!deferred_messages_.empty()) { | 188 while (!deferred_messages_.empty()) { |
193 delete deferred_messages_.front(); | 189 delete deferred_messages_.front(); |
194 deferred_messages_.pop(); | 190 deferred_messages_.pop(); |
195 } | 191 } |
196 } | 192 } |
197 | 193 |
198 void GpuChildThread::Shutdown() { | 194 void GpuChildThread::Shutdown() { |
199 ChildThreadImpl::Shutdown(); | 195 ChildThreadImpl::Shutdown(); |
200 logging::SetLogMessageHandler(NULL); | 196 if (!in_browser_process_) |
| 197 log_listener_.reset(); |
201 } | 198 } |
202 | 199 |
203 void GpuChildThread::Init(const base::Time& process_start_time) { | 200 void GpuChildThread::Init(const base::Time& process_start_time) { |
204 process_start_time_ = process_start_time; | 201 process_start_time_ = process_start_time; |
205 | 202 |
206 #if defined(OS_ANDROID) | 203 #if defined(OS_ANDROID) |
207 // When running in in-process mode, this has been set in the browser at | 204 // When running in in-process mode, this has been set in the browser at |
208 // ChromeBrowserMainPartsAndroid::PreMainMessageLoopRun(). | 205 // ChromeBrowserMainPartsAndroid::PreMainMessageLoopRun(). |
209 if (!in_browser_process_) | 206 if (!in_browser_process_) |
210 media::SetMediaClientAndroid(GetContentClient()->GetMediaClientAndroid()); | 207 media::SetMediaClientAndroid(GetContentClient()->GetMediaClientAndroid()); |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 | 343 |
347 if (dead_on_arrival_) { | 344 if (dead_on_arrival_) { |
348 LOG(ERROR) << "Exiting GPU process due to errors during initialization"; | 345 LOG(ERROR) << "Exiting GPU process due to errors during initialization"; |
349 base::MessageLoop::current()->QuitWhenIdle(); | 346 base::MessageLoop::current()->QuitWhenIdle(); |
350 return; | 347 return; |
351 } | 348 } |
352 | 349 |
353 // We don't need to pipe log messages if we are running the GPU thread in | 350 // We don't need to pipe log messages if we are running the GPU thread in |
354 // the browser process. | 351 // the browser process. |
355 if (!in_browser_process_) | 352 if (!in_browser_process_) |
356 logging::SetLogMessageHandler(GpuProcessLogMessageHandler); | 353 log_listener_ = base::MakeUnique<GpuProcessLogMessageListener>(); |
357 | 354 |
358 gpu::SyncPointManager* sync_point_manager = nullptr; | 355 gpu::SyncPointManager* sync_point_manager = nullptr; |
359 // Note SyncPointManager from ContentGpuClient cannot be owned by this. | 356 // Note SyncPointManager from ContentGpuClient cannot be owned by this. |
360 if (GetContentClient()->gpu()) | 357 if (GetContentClient()->gpu()) |
361 sync_point_manager = GetContentClient()->gpu()->GetSyncPointManager(); | 358 sync_point_manager = GetContentClient()->gpu()->GetSyncPointManager(); |
362 if (!sync_point_manager) { | 359 if (!sync_point_manager) { |
363 if (!owned_sync_point_manager_) { | 360 if (!owned_sync_point_manager_) { |
364 owned_sync_point_manager_.reset(new gpu::SyncPointManager(false)); | 361 owned_sync_point_manager_.reset(new gpu::SyncPointManager(false)); |
365 } | 362 } |
366 sync_point_manager = owned_sync_point_manager_.get(); | 363 sync_point_manager = owned_sync_point_manager_.get(); |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
556 | 553 |
557 void GpuChildThread::BindProcessControlRequest( | 554 void GpuChildThread::BindProcessControlRequest( |
558 mojom::ProcessControlRequest request) { | 555 mojom::ProcessControlRequest request) { |
559 DVLOG(1) << "GPU: Binding ProcessControl request"; | 556 DVLOG(1) << "GPU: Binding ProcessControl request"; |
560 DCHECK(process_control_); | 557 DCHECK(process_control_); |
561 process_control_bindings_.AddBinding(process_control_.get(), | 558 process_control_bindings_.AddBinding(process_control_.get(), |
562 std::move(request)); | 559 std::move(request)); |
563 } | 560 } |
564 | 561 |
565 } // namespace content | 562 } // namespace content |
OLD | NEW |