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

Side by Side Diff: content/browser/gpu/gpu_process_host.cc

Issue 2801943002: gpu: Some code cleanups. (Closed)
Patch Set: Created 3 years, 8 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
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/browser/gpu/gpu_process_host.h" 5 #include "content/browser/gpu/gpu_process_host.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <list> 10 #include <list>
(...skipping 16 matching lines...) Expand all
27 #include "base/trace_event/trace_event.h" 27 #include "base/trace_event/trace_event.h"
28 #include "build/build_config.h" 28 #include "build/build_config.h"
29 #include "components/tracing/common/tracing_switches.h" 29 #include "components/tracing/common/tracing_switches.h"
30 #include "content/browser/browser_child_process_host_impl.h" 30 #include "content/browser/browser_child_process_host_impl.h"
31 #include "content/browser/browser_main_loop.h" 31 #include "content/browser/browser_main_loop.h"
32 #include "content/browser/gpu/compositor_util.h" 32 #include "content/browser/gpu/compositor_util.h"
33 #include "content/browser/gpu/gpu_data_manager_impl.h" 33 #include "content/browser/gpu/gpu_data_manager_impl.h"
34 #include "content/browser/gpu/gpu_main_thread_factory.h" 34 #include "content/browser/gpu/gpu_main_thread_factory.h"
35 #include "content/browser/gpu/gpu_process_host_ui_shim.h" 35 #include "content/browser/gpu/gpu_process_host_ui_shim.h"
36 #include "content/browser/gpu/shader_cache_factory.h" 36 #include "content/browser/gpu/shader_cache_factory.h"
37 #include "content/browser/renderer_host/render_widget_host_impl.h"
38 #include "content/browser/renderer_host/render_widget_host_view_frame_subscriber .h"
39 #include "content/browser/service_manager/service_manager_context.h" 37 #include "content/browser/service_manager/service_manager_context.h"
40 #include "content/common/child_process_host_impl.h" 38 #include "content/common/child_process_host_impl.h"
41 #include "content/common/gpu_host_messages.h" 39 #include "content/common/gpu_host_messages.h"
42 #include "content/common/in_process_child_thread_params.h" 40 #include "content/common/in_process_child_thread_params.h"
43 #include "content/common/service_manager/child_connection.h" 41 #include "content/common/service_manager/child_connection.h"
44 #include "content/common/view_messages.h" 42 #include "content/common/view_messages.h"
45 #include "content/public/browser/browser_thread.h" 43 #include "content/public/browser/browser_thread.h"
46 #include "content/public/browser/content_browser_client.h" 44 #include "content/public/browser/content_browser_client.h"
47 #include "content/public/browser/gpu_utils.h" 45 #include "content/public/browser/gpu_utils.h"
48 #include "content/public/browser/render_process_host.h"
49 #include "content/public/browser/render_widget_host_view.h"
50 #include "content/public/common/connection_filter.h" 46 #include "content/public/common/connection_filter.h"
51 #include "content/public/common/content_client.h" 47 #include "content/public/common/content_client.h"
52 #include "content/public/common/content_switches.h" 48 #include "content/public/common/content_switches.h"
53 #include "content/public/common/mojo_channel_switches.h" 49 #include "content/public/common/mojo_channel_switches.h"
54 #include "content/public/common/result_codes.h" 50 #include "content/public/common/result_codes.h"
55 #include "content/public/common/sandbox_type.h" 51 #include "content/public/common/sandbox_type.h"
56 #include "content/public/common/sandboxed_process_launcher_delegate.h" 52 #include "content/public/common/sandboxed_process_launcher_delegate.h"
57 #include "content/public/common/service_manager_connection.h" 53 #include "content/public/common/service_manager_connection.h"
58 #include "content/public/common/service_names.mojom.h" 54 #include "content/public/common/service_names.mojom.h"
59 #include "gpu/command_buffer/service/gpu_preferences.h" 55 #include "gpu/command_buffer/service/gpu_preferences.h"
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 // only be accessed from the IO thread. 188 // only be accessed from the IO thread.
193 GpuProcessHost* g_gpu_process_hosts[GpuProcessHost::GPU_PROCESS_KIND_COUNT]; 189 GpuProcessHost* g_gpu_process_hosts[GpuProcessHost::GPU_PROCESS_KIND_COUNT];
194 190
195 void RunCallbackOnIO(GpuProcessHost::GpuProcessKind kind, 191 void RunCallbackOnIO(GpuProcessHost::GpuProcessKind kind,
196 bool force_create, 192 bool force_create,
197 const base::Callback<void(GpuProcessHost*)>& callback) { 193 const base::Callback<void(GpuProcessHost*)>& callback) {
198 GpuProcessHost* host = GpuProcessHost::Get(kind, force_create); 194 GpuProcessHost* host = GpuProcessHost::Get(kind, force_create);
199 callback.Run(host); 195 callback.Run(host);
200 } 196 }
201 197
202 #if defined(USE_OZONE)
203 void SendGpuProcessMessageByHostId(int host_id, IPC::Message* message) {
204 GpuProcessHost* host = GpuProcessHost::FromID(host_id);
205 if (host) {
206 host->Send(message);
207 } else {
208 delete message;
209 }
210 }
211 #endif
212
213 // NOTE: changes to this class need to be reviewed by the security team. 198 // NOTE: changes to this class need to be reviewed by the security team.
214 class GpuSandboxedProcessLauncherDelegate 199 class GpuSandboxedProcessLauncherDelegate
215 : public SandboxedProcessLauncherDelegate { 200 : public SandboxedProcessLauncherDelegate {
216 public: 201 public:
217 explicit GpuSandboxedProcessLauncherDelegate( 202 explicit GpuSandboxedProcessLauncherDelegate(
218 const base::CommandLine& cmd_line) 203 const base::CommandLine& cmd_line)
219 #if defined(OS_WIN) 204 #if defined(OS_WIN)
220 : cmd_line_(cmd_line) 205 : cmd_line_(cmd_line)
221 #endif 206 #endif
222 { 207 {
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 SandboxType GetSandboxType() override { 291 SandboxType GetSandboxType() override {
307 return SANDBOX_TYPE_GPU; 292 return SANDBOX_TYPE_GPU;
308 } 293 }
309 294
310 private: 295 private:
311 #if defined(OS_WIN) 296 #if defined(OS_WIN)
312 base::CommandLine cmd_line_; 297 base::CommandLine cmd_line_;
313 #endif // OS_WIN 298 #endif // OS_WIN
314 }; 299 };
315 300
316 void HostLoadedShader(int host_id,
317 const std::string& key,
318 const std::string& data) {
319 GpuProcessHost* host = GpuProcessHost::FromID(host_id);
320 if (host)
321 host->LoadedShader(key, data);
322 }
323
324 } // anonymous namespace 301 } // anonymous namespace
325 302
326 class GpuProcessHost::ConnectionFilterImpl : public ConnectionFilter { 303 class GpuProcessHost::ConnectionFilterImpl : public ConnectionFilter {
327 public: 304 public:
328 ConnectionFilterImpl() { 305 ConnectionFilterImpl() {
329 registry_.AddInterface( 306 registry_.AddInterface(
330 base::Bind( 307 base::Bind(
331 &memory_instrumentation::CoordinatorImpl::BindCoordinatorRequest, 308 &memory_instrumentation::CoordinatorImpl::BindCoordinatorRequest,
332 base::Unretained( 309 base::Unretained(
333 memory_instrumentation::CoordinatorImpl::GetInstance())), 310 memory_instrumentation::CoordinatorImpl::GetInstance())),
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
635 gpu_main_ptr_->CreateGpuService( 612 gpu_main_ptr_->CreateGpuService(
636 std::move(request), gpu_host_binding_.CreateInterfacePtrAndBind(), 613 std::move(request), gpu_host_binding_.CreateInterfacePtrAndBind(),
637 gpu_preferences, activity_flags_.CloneHandle()); 614 gpu_preferences, activity_flags_.CloneHandle());
638 615
639 #if defined(USE_OZONE) 616 #if defined(USE_OZONE)
640 // Ozone needs to send the primary DRM device to GPU process as early as 617 // Ozone needs to send the primary DRM device to GPU process as early as
641 // possible to ensure the latter always has a valid device. crbug.com/608839 618 // possible to ensure the latter always has a valid device. crbug.com/608839
642 ui::OzonePlatform::GetInstance() 619 ui::OzonePlatform::GetInstance()
643 ->GetGpuPlatformSupportHost() 620 ->GetGpuPlatformSupportHost()
644 ->OnGpuProcessLaunched( 621 ->OnGpuProcessLaunched(
645 host_id_, BrowserThread::GetTaskRunnerForThread(BrowserThread::IO), 622 host_id_, base::ThreadTaskRunnerHandle::Get(),
646 base::Bind(&SendGpuProcessMessageByHostId, host_id_)); 623 base::Bind(base::IgnoreResult(&GpuProcessHost::Send),
piman 2017/04/06 20:51:14 So, if the weak_ptr is null, the message will be l
sadrul 2017/04/07 02:16:12 Good catch! Done. (... although maybe IPC::Sender:
piman 2017/04/07 18:16:41 That would be ideal... but I think there's so many
624 weak_ptr_factory_.GetWeakPtr()));
647 #endif 625 #endif
648 626
649 return true; 627 return true;
650 } 628 }
651 629
652 void GpuProcessHost::RouteOnUIThread(const IPC::Message& message) { 630 void GpuProcessHost::RouteOnUIThread(const IPC::Message& message) {
653 BrowserThread::PostTask( 631 BrowserThread::PostTask(
654 BrowserThread::UI, 632 BrowserThread::UI,
655 FROM_HERE, 633 FROM_HERE,
656 base::Bind(&RouteToGpuProcessHostUIShimTask, host_id_, message)); 634 base::Bind(&RouteToGpuProcessHostUIShimTask, host_id_, message));
(...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after
1208 } 1186 }
1209 1187
1210 void GpuProcessHost::CreateChannelCache(int32_t client_id) { 1188 void GpuProcessHost::CreateChannelCache(int32_t client_id) {
1211 TRACE_EVENT0("gpu", "GpuProcessHost::CreateChannelCache"); 1189 TRACE_EVENT0("gpu", "GpuProcessHost::CreateChannelCache");
1212 1190
1213 scoped_refptr<gpu::ShaderDiskCache> cache = 1191 scoped_refptr<gpu::ShaderDiskCache> cache =
1214 GetShaderCacheFactorySingleton()->Get(client_id); 1192 GetShaderCacheFactorySingleton()->Get(client_id);
1215 if (!cache.get()) 1193 if (!cache.get())
1216 return; 1194 return;
1217 1195
1218 cache->set_shader_loaded_callback(base::Bind(&HostLoadedShader, host_id_)); 1196 cache->set_shader_loaded_callback(base::Bind(&GpuProcessHost::LoadedShader,
1197 weak_ptr_factory_.GetWeakPtr()));
1219 1198
1220 client_id_to_shader_cache_[client_id] = cache; 1199 client_id_to_shader_cache_[client_id] = cache;
1221 } 1200 }
1222 1201
1223 } // namespace content 1202 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698