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

Side by Side Diff: content/gpu/gpu_child_thread.cc

Issue 1656433002: Sample code: IPC Transport object for GPU Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: GpuMemoryBufferService + Transport object. TODO: Eliminate ChildThreadImpl dependency Created 4 years, 10 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/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"
11 #include "base/lazy_instance.h" 11 #include "base/lazy_instance.h"
12 #include "base/threading/worker_pool.h" 12 #include "base/threading/worker_pool.h"
13 #include "build/build_config.h" 13 #include "build/build_config.h"
14 #include "content/child/child_process.h" 14 #include "content/child/child_process.h"
15 #include "content/child/thread_safe_sender.h" 15 #include "content/child/thread_safe_sender.h"
16 #include "content/common/gpu/gpu_memory_buffer_factory.h" 16 #include "content/common/gpu/gpu_memory_buffer_factory.h"
17 #include "content/common/gpu/gpu_messages.h" 17 #include "content/common/gpu/gpu_messages.h"
18 #include "content/gpu/chrome_gpu_memory_buffer_service_ipc_transport.h"
19 #include "content/gpu/gpu_memory_buffer_service.h"
18 #include "content/gpu/gpu_process_control_impl.h" 20 #include "content/gpu/gpu_process_control_impl.h"
19 #include "content/gpu/gpu_watchdog_thread.h" 21 #include "content/gpu/gpu_watchdog_thread.h"
20 #include "content/public/common/content_client.h" 22 #include "content/public/common/content_client.h"
21 #include "content/public/common/content_switches.h" 23 #include "content/public/common/content_switches.h"
22 #include "gpu/config/gpu_info_collector.h" 24 #include "gpu/config/gpu_info_collector.h"
23 #include "ipc/ipc_channel_handle.h" 25 #include "ipc/ipc_channel_handle.h"
24 #include "ipc/ipc_sync_message_filter.h" 26 #include "ipc/ipc_sync_message_filter.h"
25 #include "ui/gl/gl_implementation.h" 27 #include "ui/gl/gl_implementation.h"
26 #include "ui/gl/gpu_switching_manager.h" 28 #include "ui/gl/gpu_switching_manager.h"
27 29
(...skipping 14 matching lines...) Expand all
42 const std::string& str) { 44 const std::string& str) {
43 std::string header = str.substr(0, message_start); 45 std::string header = str.substr(0, message_start);
44 std::string message = str.substr(message_start); 46 std::string message = str.substr(message_start);
45 47
46 g_thread_safe_sender.Get()->Send(new GpuHostMsg_OnLogMessage( 48 g_thread_safe_sender.Get()->Send(new GpuHostMsg_OnLogMessage(
47 severity, header, message)); 49 severity, header, message));
48 50
49 return false; 51 return false;
50 } 52 }
51 53
52 // Message filter used to to handle GpuMsg_CreateGpuMemoryBuffer messages on
53 // the IO thread. This allows the UI thread in the browser process to remain
54 // fast at all times.
55 class GpuMemoryBufferMessageFilter : public IPC::MessageFilter {
56 public:
57 explicit GpuMemoryBufferMessageFilter(
58 GpuMemoryBufferFactory* gpu_memory_buffer_factory)
59 : gpu_memory_buffer_factory_(gpu_memory_buffer_factory),
60 sender_(nullptr) {}
61
62 // Overridden from IPC::MessageFilter:
63 void OnFilterAdded(IPC::Sender* sender) override {
64 DCHECK(!sender_);
65 sender_ = sender;
66 }
67 void OnFilterRemoved() override {
68 DCHECK(sender_);
69 sender_ = nullptr;
70 }
71 bool OnMessageReceived(const IPC::Message& message) override {
72 DCHECK(sender_);
73 bool handled = true;
74 IPC_BEGIN_MESSAGE_MAP(GpuMemoryBufferMessageFilter, message)
75 IPC_MESSAGE_HANDLER(GpuMsg_CreateGpuMemoryBuffer, OnCreateGpuMemoryBuffer)
76 IPC_MESSAGE_HANDLER(GpuMsg_CreateGpuMemoryBufferFromHandle,
77 OnCreateGpuMemoryBufferFromHandle)
78 IPC_MESSAGE_UNHANDLED(handled = false)
79 IPC_END_MESSAGE_MAP()
80 return handled;
81 }
82
83 protected:
84 ~GpuMemoryBufferMessageFilter() override {}
85
86 void OnCreateGpuMemoryBuffer(
87 const GpuMsg_CreateGpuMemoryBuffer_Params& params) {
88 TRACE_EVENT2("gpu", "GpuMemoryBufferMessageFilter::OnCreateGpuMemoryBuffer",
89 "id", params.id.id, "client_id", params.client_id);
90
91 DCHECK(gpu_memory_buffer_factory_);
92 sender_->Send(new GpuHostMsg_GpuMemoryBufferCreated(
93 gpu_memory_buffer_factory_->CreateGpuMemoryBuffer(
94 params.id, params.size, params.format, params.usage,
95 params.client_id, params.surface_handle)));
96 }
97
98 void OnCreateGpuMemoryBufferFromHandle(
99 const GpuMsg_CreateGpuMemoryBufferFromHandle_Params& params) {
100 TRACE_EVENT2(
101 "gpu",
102 "GpuMemoryBufferMessageFilter::OnCreateGpuMemoryBufferFromHandle", "id",
103 params.id.id, "client_id", params.client_id);
104 sender_->Send(new GpuHostMsg_GpuMemoryBufferCreated(
105 gpu_memory_buffer_factory_->CreateGpuMemoryBufferFromHandle(
106 params.handle, params.id, params.size, params.format,
107 params.client_id)));
108 }
109
110 GpuMemoryBufferFactory* const gpu_memory_buffer_factory_;
111 IPC::Sender* sender_;
112 };
113
114 ChildThreadImpl::Options GetOptions( 54 ChildThreadImpl::Options GetOptions(
115 GpuMemoryBufferFactory* gpu_memory_buffer_factory) { 55 GpuMemoryBufferFactory* gpu_memory_buffer_factory) {
116 ChildThreadImpl::Options::Builder builder; 56 ChildThreadImpl::Options::Builder builder;
117 57
118 builder.AddStartupFilter( 58 builder.AddStartupFilter(
119 new GpuMemoryBufferMessageFilter(gpu_memory_buffer_factory)); 59 static_cast<ChromeGpuMemoryBufferServiceIPCTransport*>(
60 (new GpuMemoryBufferService(gpu_memory_buffer_factory))->transport())
61 ->filter());
120 62
121 #if defined(USE_OZONE) 63 #if defined(USE_OZONE)
122 IPC::MessageFilter* message_filter = ui::OzonePlatform::GetInstance() 64 IPC::MessageFilter* message_filter = ui::OzonePlatform::GetInstance()
123 ->GetGpuPlatformSupport() 65 ->GetGpuPlatformSupport()
124 ->GetMessageFilter(); 66 ->GetMessageFilter();
125 if (message_filter) 67 if (message_filter)
126 builder.AddStartupFilter(message_filter); 68 builder.AddStartupFilter(message_filter);
127 #endif 69 #endif
128 70
129 return builder.Build(); 71 return builder.Build();
(...skipping 19 matching lines...) Expand all
149 #if defined(OS_WIN) 91 #if defined(OS_WIN)
150 target_services_ = NULL; 92 target_services_ = NULL;
151 #endif 93 #endif
152 g_thread_safe_sender.Get() = thread_safe_sender(); 94 g_thread_safe_sender.Get() = thread_safe_sender();
153 } 95 }
154 96
155 GpuChildThread::GpuChildThread( 97 GpuChildThread::GpuChildThread(
156 const InProcessChildThreadParams& params, 98 const InProcessChildThreadParams& params,
157 GpuMemoryBufferFactory* gpu_memory_buffer_factory, 99 GpuMemoryBufferFactory* gpu_memory_buffer_factory,
158 gpu::SyncPointManager* sync_point_manager) 100 gpu::SyncPointManager* sync_point_manager)
159 : ChildThreadImpl(ChildThreadImpl::Options::Builder() 101 : ChildThreadImpl(
160 .InBrowserProcess(params) 102 ChildThreadImpl::Options::Builder()
161 .AddStartupFilter(new GpuMemoryBufferMessageFilter( 103 .InBrowserProcess(params)
162 gpu_memory_buffer_factory)) 104 .AddStartupFilter(
163 .Build()), 105 static_cast<ChromeGpuMemoryBufferServiceIPCTransport*>(
106 (new GpuMemoryBufferService(gpu_memory_buffer_factory))
107 ->transport())
108 ->filter())
109 .Build()),
164 dead_on_arrival_(false), 110 dead_on_arrival_(false),
165 sync_point_manager_(sync_point_manager), 111 sync_point_manager_(sync_point_manager),
166 in_browser_process_(true), 112 in_browser_process_(true),
167 gpu_memory_buffer_factory_(gpu_memory_buffer_factory) { 113 gpu_memory_buffer_factory_(gpu_memory_buffer_factory) {
168 #if defined(OS_WIN) 114 #if defined(OS_WIN)
169 target_services_ = NULL; 115 target_services_ = NULL;
170 #endif 116 #endif
171 DCHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( 117 DCHECK(base::CommandLine::ForCurrentProcess()->HasSwitch(
172 switches::kSingleProcess) || 118 switches::kSingleProcess) ||
173 base::CommandLine::ForCurrentProcess()->HasSwitch( 119 base::CommandLine::ForCurrentProcess()->HasSwitch(
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 339
394 void GpuChildThread::BindProcessControlRequest( 340 void GpuChildThread::BindProcessControlRequest(
395 mojo::InterfaceRequest<ProcessControl> request) { 341 mojo::InterfaceRequest<ProcessControl> request) {
396 DVLOG(1) << "GPU: Binding ProcessControl request"; 342 DVLOG(1) << "GPU: Binding ProcessControl request";
397 DCHECK(process_control_); 343 DCHECK(process_control_);
398 process_control_bindings_.AddBinding(process_control_.get(), 344 process_control_bindings_.AddBinding(process_control_.get(),
399 std::move(request)); 345 std::move(request));
400 } 346 }
401 347
402 } // namespace content 348 } // namespace content
OLDNEW
« no previous file with comments | « content/gpu/chrome_gpu_memory_buffer_service_ipc_transport.cc ('k') | content/gpu/gpu_memory_buffer_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698