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, |
| 132 const char* file, |
| 133 int line, |
| 134 size_t message_start, |
| 135 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 |
144 GpuChildThread::GpuChildThread( | 143 GpuChildThread::GpuChildThread( |
145 GpuWatchdogThread* watchdog_thread, | 144 GpuWatchdogThread* watchdog_thread, |
146 bool dead_on_arrival, | 145 bool dead_on_arrival, |
147 const gpu::GPUInfo& gpu_info, | 146 const gpu::GPUInfo& gpu_info, |
148 const DeferredMessages& deferred_messages, | 147 const DeferredMessages& deferred_messages, |
149 gpu::GpuMemoryBufferFactory* gpu_memory_buffer_factory) | 148 gpu::GpuMemoryBufferFactory* gpu_memory_buffer_factory) |
150 : ChildThreadImpl(GetOptions(gpu_memory_buffer_factory)), | 149 : ChildThreadImpl(GetOptions(gpu_memory_buffer_factory)), |
151 dead_on_arrival_(dead_on_arrival), | 150 dead_on_arrival_(dead_on_arrival), |
152 gpu_info_(gpu_info), | 151 gpu_info_(gpu_info), |
153 deferred_messages_(deferred_messages), | 152 deferred_messages_(deferred_messages), |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 | 189 |
191 GpuChildThread::~GpuChildThread() { | 190 GpuChildThread::~GpuChildThread() { |
192 while (!deferred_messages_.empty()) { | 191 while (!deferred_messages_.empty()) { |
193 delete deferred_messages_.front(); | 192 delete deferred_messages_.front(); |
194 deferred_messages_.pop(); | 193 deferred_messages_.pop(); |
195 } | 194 } |
196 } | 195 } |
197 | 196 |
198 void GpuChildThread::Shutdown() { | 197 void GpuChildThread::Shutdown() { |
199 ChildThreadImpl::Shutdown(); | 198 ChildThreadImpl::Shutdown(); |
200 logging::SetLogMessageHandler(NULL); | 199 if (!in_browser_process_) |
| 200 log_listener_.reset(); |
201 } | 201 } |
202 | 202 |
203 void GpuChildThread::Init(const base::Time& process_start_time) { | 203 void GpuChildThread::Init(const base::Time& process_start_time) { |
204 process_start_time_ = process_start_time; | 204 process_start_time_ = process_start_time; |
205 | 205 |
206 #if defined(OS_ANDROID) | 206 #if defined(OS_ANDROID) |
207 // When running in in-process mode, this has been set in the browser at | 207 // When running in in-process mode, this has been set in the browser at |
208 // ChromeBrowserMainPartsAndroid::PreMainMessageLoopRun(). | 208 // ChromeBrowserMainPartsAndroid::PreMainMessageLoopRun(). |
209 if (!in_browser_process_) | 209 if (!in_browser_process_) |
210 media::SetMediaClientAndroid(GetContentClient()->GetMediaClientAndroid()); | 210 media::SetMediaClientAndroid(GetContentClient()->GetMediaClientAndroid()); |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 | 346 |
347 if (dead_on_arrival_) { | 347 if (dead_on_arrival_) { |
348 LOG(ERROR) << "Exiting GPU process due to errors during initialization"; | 348 LOG(ERROR) << "Exiting GPU process due to errors during initialization"; |
349 base::MessageLoop::current()->QuitWhenIdle(); | 349 base::MessageLoop::current()->QuitWhenIdle(); |
350 return; | 350 return; |
351 } | 351 } |
352 | 352 |
353 // We don't need to pipe log messages if we are running the GPU thread in | 353 // We don't need to pipe log messages if we are running the GPU thread in |
354 // the browser process. | 354 // the browser process. |
355 if (!in_browser_process_) | 355 if (!in_browser_process_) |
356 logging::SetLogMessageHandler(GpuProcessLogMessageHandler); | 356 log_listener_ = base::MakeUnique<GpuProcessLogMessageListener>(); |
357 | 357 |
358 gpu::SyncPointManager* sync_point_manager = nullptr; | 358 gpu::SyncPointManager* sync_point_manager = nullptr; |
359 // Note SyncPointManager from ContentGpuClient cannot be owned by this. | 359 // Note SyncPointManager from ContentGpuClient cannot be owned by this. |
360 if (GetContentClient()->gpu()) | 360 if (GetContentClient()->gpu()) |
361 sync_point_manager = GetContentClient()->gpu()->GetSyncPointManager(); | 361 sync_point_manager = GetContentClient()->gpu()->GetSyncPointManager(); |
362 if (!sync_point_manager) { | 362 if (!sync_point_manager) { |
363 if (!owned_sync_point_manager_) { | 363 if (!owned_sync_point_manager_) { |
364 owned_sync_point_manager_.reset(new gpu::SyncPointManager(false)); | 364 owned_sync_point_manager_.reset(new gpu::SyncPointManager(false)); |
365 } | 365 } |
366 sync_point_manager = owned_sync_point_manager_.get(); | 366 sync_point_manager = owned_sync_point_manager_.get(); |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
556 | 556 |
557 void GpuChildThread::BindServiceFactoryRequest( | 557 void GpuChildThread::BindServiceFactoryRequest( |
558 shell::mojom::ServiceFactoryRequest request) { | 558 shell::mojom::ServiceFactoryRequest request) { |
559 DVLOG(1) << "GPU: Binding shell::mojom::ServiceFactoryRequest"; | 559 DVLOG(1) << "GPU: Binding shell::mojom::ServiceFactoryRequest"; |
560 DCHECK(service_factory_); | 560 DCHECK(service_factory_); |
561 service_factory_bindings_.AddBinding(service_factory_.get(), | 561 service_factory_bindings_.AddBinding(service_factory_.get(), |
562 std::move(request)); | 562 std::move(request)); |
563 } | 563 } |
564 | 564 |
565 } // namespace content | 565 } // namespace content |
OLD | NEW |