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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 #endif | 50 #endif |
51 | 51 |
52 #if defined(OS_ANDROID) | 52 #if defined(OS_ANDROID) |
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 base::LazyInstance<base::ThreadLocalPointer<GpuChildThread>> g_lazy_tls = | |
61 LAZY_INSTANCE_INITIALIZER; | |
62 | |
63 static base::LazyInstance<scoped_refptr<ThreadSafeSender> > | 60 static base::LazyInstance<scoped_refptr<ThreadSafeSender> > |
64 g_thread_safe_sender = LAZY_INSTANCE_INITIALIZER; | 61 g_thread_safe_sender = LAZY_INSTANCE_INITIALIZER; |
65 | 62 |
66 bool GpuProcessLogMessageHandler(int severity, | 63 bool GpuProcessLogMessageHandler(int severity, |
67 const char* file, int line, | 64 const char* file, int line, |
68 size_t message_start, | 65 size_t message_start, |
69 const std::string& str) { | 66 const std::string& str) { |
70 std::string header = str.substr(0, message_start); | 67 std::string header = str.substr(0, message_start); |
71 std::string message = str.substr(message_start); | 68 std::string message = str.substr(message_start); |
72 | 69 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 ->GetMessageFilter(); | 134 ->GetMessageFilter(); |
138 if (message_filter) | 135 if (message_filter) |
139 builder.AddStartupFilter(message_filter); | 136 builder.AddStartupFilter(message_filter); |
140 #endif | 137 #endif |
141 | 138 |
142 return builder.Build(); | 139 return builder.Build(); |
143 } | 140 } |
144 | 141 |
145 } // namespace | 142 } // namespace |
146 | 143 |
147 // static | |
148 GpuChildThread* GpuChildThread::current() { | |
149 return g_lazy_tls.Pointer()->Get(); | |
150 } | |
151 | |
152 GpuChildThread::GpuChildThread( | 144 GpuChildThread::GpuChildThread( |
153 GpuWatchdogThread* watchdog_thread, | 145 GpuWatchdogThread* watchdog_thread, |
154 bool dead_on_arrival, | 146 bool dead_on_arrival, |
155 const gpu::GPUInfo& gpu_info, | 147 const gpu::GPUInfo& gpu_info, |
156 const DeferredMessages& deferred_messages, | 148 const DeferredMessages& deferred_messages, |
157 gpu::GpuMemoryBufferFactory* gpu_memory_buffer_factory) | 149 gpu::GpuMemoryBufferFactory* gpu_memory_buffer_factory) |
158 : ChildThreadImpl(GetOptions(gpu_memory_buffer_factory)), | 150 : ChildThreadImpl(GetOptions(gpu_memory_buffer_factory)), |
159 dead_on_arrival_(dead_on_arrival), | 151 dead_on_arrival_(dead_on_arrival), |
160 gpu_info_(gpu_info), | 152 gpu_info_(gpu_info), |
161 deferred_messages_(deferred_messages), | 153 deferred_messages_(deferred_messages), |
162 in_browser_process_(false), | 154 in_browser_process_(false), |
163 gpu_memory_buffer_factory_(gpu_memory_buffer_factory) { | 155 gpu_memory_buffer_factory_(gpu_memory_buffer_factory) { |
164 watchdog_thread_ = watchdog_thread; | 156 watchdog_thread_ = watchdog_thread; |
165 #if defined(OS_WIN) | 157 #if defined(OS_WIN) |
166 target_services_ = NULL; | 158 target_services_ = NULL; |
167 #endif | 159 #endif |
168 g_thread_safe_sender.Get() = thread_safe_sender(); | 160 g_thread_safe_sender.Get() = thread_safe_sender(); |
169 g_lazy_tls.Pointer()->Set(this); | |
170 } | 161 } |
171 | 162 |
172 GpuChildThread::GpuChildThread( | 163 GpuChildThread::GpuChildThread( |
173 const gpu::GpuPreferences& gpu_preferences, | 164 const gpu::GpuPreferences& gpu_preferences, |
174 const InProcessChildThreadParams& params, | 165 const InProcessChildThreadParams& params, |
175 gpu::GpuMemoryBufferFactory* gpu_memory_buffer_factory) | 166 gpu::GpuMemoryBufferFactory* gpu_memory_buffer_factory) |
176 : ChildThreadImpl(ChildThreadImpl::Options::Builder() | 167 : ChildThreadImpl(ChildThreadImpl::Options::Builder() |
177 .InBrowserProcess(params) | 168 .InBrowserProcess(params) |
178 .UseMojoChannel(true) | 169 .UseMojoChannel(true) |
179 .AddStartupFilter(new GpuMemoryBufferMessageFilter( | 170 .AddStartupFilter(new GpuMemoryBufferMessageFilter( |
180 gpu_memory_buffer_factory)) | 171 gpu_memory_buffer_factory)) |
181 .Build()), | 172 .Build()), |
182 gpu_preferences_(gpu_preferences), | 173 gpu_preferences_(gpu_preferences), |
183 dead_on_arrival_(false), | 174 dead_on_arrival_(false), |
184 in_browser_process_(true), | 175 in_browser_process_(true), |
185 gpu_memory_buffer_factory_(gpu_memory_buffer_factory) { | 176 gpu_memory_buffer_factory_(gpu_memory_buffer_factory) { |
186 #if defined(OS_WIN) | 177 #if defined(OS_WIN) |
187 target_services_ = NULL; | 178 target_services_ = NULL; |
188 #endif | 179 #endif |
189 DCHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( | 180 DCHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( |
190 switches::kSingleProcess) || | 181 switches::kSingleProcess) || |
191 base::CommandLine::ForCurrentProcess()->HasSwitch( | 182 base::CommandLine::ForCurrentProcess()->HasSwitch( |
192 switches::kInProcessGPU)); | 183 switches::kInProcessGPU)); |
193 | 184 |
194 if (!gl::init::InitializeGLOneOff()) | 185 if (!gl::init::InitializeGLOneOff()) |
195 VLOG(1) << "gl::init::InitializeGLOneOff failed"; | 186 VLOG(1) << "gl::init::InitializeGLOneOff failed"; |
196 | 187 |
197 g_thread_safe_sender.Get() = thread_safe_sender(); | 188 g_thread_safe_sender.Get() = thread_safe_sender(); |
198 g_lazy_tls.Pointer()->Set(this); | |
199 } | 189 } |
200 | 190 |
201 GpuChildThread::~GpuChildThread() { | 191 GpuChildThread::~GpuChildThread() { |
202 while (!deferred_messages_.empty()) { | 192 while (!deferred_messages_.empty()) { |
203 delete deferred_messages_.front(); | 193 delete deferred_messages_.front(); |
204 deferred_messages_.pop(); | 194 deferred_messages_.pop(); |
205 } | 195 } |
206 g_lazy_tls.Pointer()->Set(nullptr); | |
207 } | 196 } |
208 | 197 |
209 void GpuChildThread::Shutdown() { | 198 void GpuChildThread::Shutdown() { |
210 ChildThreadImpl::Shutdown(); | 199 ChildThreadImpl::Shutdown(); |
211 logging::SetLogMessageHandler(NULL); | 200 logging::SetLogMessageHandler(NULL); |
212 } | 201 } |
213 | 202 |
214 void GpuChildThread::Init(const base::Time& process_start_time) { | 203 void GpuChildThread::Init(const base::Time& process_start_time) { |
215 process_start_time_ = process_start_time; | 204 process_start_time_ = process_start_time; |
216 | 205 |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 #endif | 385 #endif |
397 | 386 |
398 // Only set once per process instance. | 387 // Only set once per process instance. |
399 process_control_.reset(new GpuProcessControlImpl()); | 388 process_control_.reset(new GpuProcessControlImpl()); |
400 | 389 |
401 GetInterfaceRegistry()->AddInterface(base::Bind( | 390 GetInterfaceRegistry()->AddInterface(base::Bind( |
402 &GpuChildThread::BindProcessControlRequest, base::Unretained(this))); | 391 &GpuChildThread::BindProcessControlRequest, base::Unretained(this))); |
403 | 392 |
404 if (GetContentClient()->gpu()) { // NULL in tests. | 393 if (GetContentClient()->gpu()) { // NULL in tests. |
405 GetContentClient()->gpu()->ExposeInterfacesToBrowser( | 394 GetContentClient()->gpu()->ExposeInterfacesToBrowser( |
406 GetInterfaceRegistry()); | 395 GetInterfaceRegistry(), gpu_preferences_); |
407 } | 396 } |
408 | 397 |
409 GetInterfaceRegistry()->ResumeBinding(); | 398 GetInterfaceRegistry()->ResumeBinding(); |
410 } | 399 } |
411 | 400 |
412 void GpuChildThread::OnFinalize() { | 401 void GpuChildThread::OnFinalize() { |
413 // Quit the GPU process | 402 // Quit the GPU process |
414 base::MessageLoop::current()->QuitWhenIdle(); | 403 base::MessageLoop::current()->QuitWhenIdle(); |
415 } | 404 } |
416 | 405 |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
567 | 556 |
568 void GpuChildThread::BindProcessControlRequest( | 557 void GpuChildThread::BindProcessControlRequest( |
569 mojom::ProcessControlRequest request) { | 558 mojom::ProcessControlRequest request) { |
570 DVLOG(1) << "GPU: Binding ProcessControl request"; | 559 DVLOG(1) << "GPU: Binding ProcessControl request"; |
571 DCHECK(process_control_); | 560 DCHECK(process_control_); |
572 process_control_bindings_.AddBinding(process_control_.get(), | 561 process_control_bindings_.AddBinding(process_control_.get(), |
573 std::move(request)); | 562 std::move(request)); |
574 } | 563 } |
575 | 564 |
576 } // namespace content | 565 } // namespace content |
OLD | NEW |