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

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

Issue 2701233002: gpu: Use mojom.GpuService API for memory allocation. (Closed)
Patch Set: Created 3 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
« no previous file with comments | « content/gpu/gpu_child_thread.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 const std::string& str) { 68 const std::string& str) {
69 std::string header = str.substr(0, message_start); 69 std::string header = str.substr(0, message_start);
70 std::string message = str.substr(message_start); 70 std::string message = str.substr(message_start);
71 71
72 g_thread_safe_sender.Get()->Send( 72 g_thread_safe_sender.Get()->Send(
73 new GpuHostMsg_OnLogMessage(severity, header, message)); 73 new GpuHostMsg_OnLogMessage(severity, header, message));
74 74
75 return false; 75 return false;
76 } 76 }
77 77
78 // Message filter used to to handle GpuMsg_CreateGpuMemoryBuffer messages 78 ChildThreadImpl::Options GetOptions() {
79 // on the IO thread. This allows the UI thread in the browser process to remain
jbauman 2017/02/22 02:49:45 I think we want to continue to be able to create t
sadrul 2017/02/22 03:08:51 Having the allocation messages come to a different
80 // fast at all times.
81 class GpuMemoryBufferMessageFilter : public IPC::MessageFilter {
82 public:
83 explicit GpuMemoryBufferMessageFilter(
84 gpu::GpuMemoryBufferFactory* gpu_memory_buffer_factory)
85 : gpu_memory_buffer_factory_(gpu_memory_buffer_factory),
86 sender_(nullptr) {}
87
88 // Overridden from IPC::MessageFilter:
89 void OnFilterAdded(IPC::Channel* channel) override {
90 DCHECK(!sender_);
91 sender_ = channel;
92 }
93 void OnFilterRemoved() override {
94 DCHECK(sender_);
95 sender_ = nullptr;
96 }
97 bool OnMessageReceived(const IPC::Message& message) override {
98 DCHECK(sender_);
99 bool handled = true;
100 IPC_BEGIN_MESSAGE_MAP(GpuMemoryBufferMessageFilter, message)
101 IPC_MESSAGE_HANDLER(GpuMsg_CreateGpuMemoryBuffer, OnCreateGpuMemoryBuffer)
102 IPC_MESSAGE_UNHANDLED(handled = false)
103 IPC_END_MESSAGE_MAP()
104 return handled;
105 }
106
107 protected:
108 ~GpuMemoryBufferMessageFilter() override {}
109
110 void OnCreateGpuMemoryBuffer(
111 const GpuMsg_CreateGpuMemoryBuffer_Params& params) {
112 TRACE_EVENT2("gpu", "GpuMemoryBufferMessageFilter::OnCreateGpuMemoryBuffer",
113 "id", params.id.id, "client_id", params.client_id);
114
115 DCHECK(gpu_memory_buffer_factory_);
116 sender_->Send(new GpuHostMsg_GpuMemoryBufferCreated(
117 gpu_memory_buffer_factory_->CreateGpuMemoryBuffer(
118 params.id, params.size, params.format, params.usage,
119 params.client_id, params.surface_handle)));
120 }
121
122 gpu::GpuMemoryBufferFactory* const gpu_memory_buffer_factory_;
123 IPC::Sender* sender_;
124 };
125
126 ChildThreadImpl::Options GetOptions(
127 gpu::GpuMemoryBufferFactory* gpu_memory_buffer_factory) {
128 ChildThreadImpl::Options::Builder builder; 79 ChildThreadImpl::Options::Builder builder;
129 80
130 builder.AddStartupFilter(
131 new GpuMemoryBufferMessageFilter(gpu_memory_buffer_factory));
132
133 #if defined(USE_OZONE) 81 #if defined(USE_OZONE)
134 IPC::MessageFilter* message_filter = 82 IPC::MessageFilter* message_filter =
135 ui::OzonePlatform::GetInstance()->GetGpuMessageFilter(); 83 ui::OzonePlatform::GetInstance()->GetGpuMessageFilter();
136 if (message_filter) 84 if (message_filter)
137 builder.AddStartupFilter(message_filter); 85 builder.AddStartupFilter(message_filter);
138 #endif 86 #endif
139 87
140 builder.ConnectToBrowser(true); 88 builder.ConnectToBrowser(true);
141 89
142 return builder.Build(); 90 return builder.Build();
143 } 91 }
144 92
145 } // namespace 93 } // namespace
146 94
147 GpuChildThread::GpuChildThread( 95 GpuChildThread::GpuChildThread(
148 std::unique_ptr<gpu::GpuWatchdogThread> watchdog_thread, 96 std::unique_ptr<gpu::GpuWatchdogThread> watchdog_thread,
149 bool dead_on_arrival, 97 bool dead_on_arrival,
150 const gpu::GPUInfo& gpu_info, 98 const gpu::GPUInfo& gpu_info,
151 const gpu::GpuFeatureInfo& gpu_feature_info, 99 const gpu::GpuFeatureInfo& gpu_feature_info,
152 const DeferredMessages& deferred_messages, 100 const DeferredMessages& deferred_messages,
153 gpu::GpuMemoryBufferFactory* gpu_memory_buffer_factory) 101 gpu::GpuMemoryBufferFactory* gpu_memory_buffer_factory)
154 : ChildThreadImpl(GetOptions(gpu_memory_buffer_factory)), 102 : ChildThreadImpl(GetOptions()),
155 dead_on_arrival_(dead_on_arrival), 103 dead_on_arrival_(dead_on_arrival),
156 gpu_info_(gpu_info), 104 gpu_info_(gpu_info),
157 deferred_messages_(deferred_messages), 105 deferred_messages_(deferred_messages),
158 in_browser_process_(false), 106 in_browser_process_(false),
159 gpu_service_(new ui::GpuService(gpu_info, 107 gpu_service_(new ui::GpuService(gpu_info,
160 std::move(watchdog_thread), 108 std::move(watchdog_thread),
161 gpu_memory_buffer_factory, 109 gpu_memory_buffer_factory,
162 ChildProcess::current()->io_task_runner(), 110 ChildProcess::current()->io_task_runner(),
163 gpu_feature_info)), 111 gpu_feature_info)),
164 gpu_main_binding_(this) { 112 gpu_main_binding_(this) {
165 #if defined(OS_WIN) 113 #if defined(OS_WIN)
166 target_services_ = NULL; 114 target_services_ = NULL;
167 #endif 115 #endif
168 g_thread_safe_sender.Get() = thread_safe_sender(); 116 g_thread_safe_sender.Get() = thread_safe_sender();
169 } 117 }
170 118
171 GpuChildThread::GpuChildThread( 119 GpuChildThread::GpuChildThread(
172 const InProcessChildThreadParams& params, 120 const InProcessChildThreadParams& params,
173 const gpu::GPUInfo& gpu_info, 121 const gpu::GPUInfo& gpu_info,
174 const gpu::GpuFeatureInfo& gpu_feature_info, 122 const gpu::GpuFeatureInfo& gpu_feature_info,
175 gpu::GpuMemoryBufferFactory* gpu_memory_buffer_factory) 123 gpu::GpuMemoryBufferFactory* gpu_memory_buffer_factory)
176 : ChildThreadImpl(ChildThreadImpl::Options::Builder() 124 : ChildThreadImpl(ChildThreadImpl::Options::Builder()
177 .InBrowserProcess(params) 125 .InBrowserProcess(params)
178 .AddStartupFilter(new GpuMemoryBufferMessageFilter(
179 gpu_memory_buffer_factory))
180 .ConnectToBrowser(true) 126 .ConnectToBrowser(true)
181 .Build()), 127 .Build()),
182 dead_on_arrival_(false), 128 dead_on_arrival_(false),
183 gpu_info_(gpu_info), 129 gpu_info_(gpu_info),
184 in_browser_process_(true), 130 in_browser_process_(true),
185 gpu_service_(new ui::GpuService(gpu_info, 131 gpu_service_(new ui::GpuService(gpu_info,
186 nullptr /* watchdog thread */, 132 nullptr /* watchdog thread */,
187 gpu_memory_buffer_factory, 133 gpu_memory_buffer_factory,
188 ChildProcess::current()->io_task_runner(), 134 ChildProcess::current()->io_task_runner(),
189 gpu_feature_info)), 135 gpu_feature_info)),
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 return handled; 211 return handled;
266 } 212 }
267 213
268 bool GpuChildThread::OnMessageReceived(const IPC::Message& msg) { 214 bool GpuChildThread::OnMessageReceived(const IPC::Message& msg) {
269 if (ChildThreadImpl::OnMessageReceived(msg)) 215 if (ChildThreadImpl::OnMessageReceived(msg))
270 return true; 216 return true;
271 217
272 bool handled = true; 218 bool handled = true;
273 IPC_BEGIN_MESSAGE_MAP(GpuChildThread, msg) 219 IPC_BEGIN_MESSAGE_MAP(GpuChildThread, msg)
274 IPC_MESSAGE_HANDLER(GpuMsg_CloseChannel, OnCloseChannel) 220 IPC_MESSAGE_HANDLER(GpuMsg_CloseChannel, OnCloseChannel)
275 IPC_MESSAGE_HANDLER(GpuMsg_DestroyGpuMemoryBuffer, OnDestroyGpuMemoryBuffer)
276 IPC_MESSAGE_HANDLER(GpuMsg_LoadedShader, OnLoadedShader) 221 IPC_MESSAGE_HANDLER(GpuMsg_LoadedShader, OnLoadedShader)
277 #if defined(OS_ANDROID) 222 #if defined(OS_ANDROID)
278 IPC_MESSAGE_HANDLER(GpuMsg_WakeUpGpu, OnWakeUpGpu); 223 IPC_MESSAGE_HANDLER(GpuMsg_WakeUpGpu, OnWakeUpGpu);
279 IPC_MESSAGE_HANDLER(GpuMsg_DestroyingVideoSurface, 224 IPC_MESSAGE_HANDLER(GpuMsg_DestroyingVideoSurface,
280 OnDestroyingVideoSurface); 225 OnDestroyingVideoSurface);
281 #endif 226 #endif
282 IPC_MESSAGE_UNHANDLED(handled = false) 227 IPC_MESSAGE_UNHANDLED(handled = false)
283 IPC_END_MESSAGE_MAP() 228 IPC_END_MESSAGE_MAP()
284 if (handled) 229 if (handled)
285 return true; 230 return true;
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 void GpuChildThread::OnCloseChannel(int32_t client_id) { 413 void GpuChildThread::OnCloseChannel(int32_t client_id) {
469 if (gpu_channel_manager()) 414 if (gpu_channel_manager())
470 gpu_channel_manager()->RemoveChannel(client_id); 415 gpu_channel_manager()->RemoveChannel(client_id);
471 } 416 }
472 417
473 void GpuChildThread::OnLoadedShader(const std::string& shader) { 418 void GpuChildThread::OnLoadedShader(const std::string& shader) {
474 if (gpu_channel_manager()) 419 if (gpu_channel_manager())
475 gpu_channel_manager()->PopulateShaderCache(shader); 420 gpu_channel_manager()->PopulateShaderCache(shader);
476 } 421 }
477 422
478 void GpuChildThread::OnDestroyGpuMemoryBuffer(
479 gfx::GpuMemoryBufferId id,
480 int client_id,
481 const gpu::SyncToken& sync_token) {
482 if (gpu_channel_manager())
483 gpu_channel_manager()->DestroyGpuMemoryBuffer(id, client_id, sync_token);
484 }
485
486 #if defined(OS_ANDROID) 423 #if defined(OS_ANDROID)
487 void GpuChildThread::OnWakeUpGpu() { 424 void GpuChildThread::OnWakeUpGpu() {
488 if (gpu_channel_manager()) 425 if (gpu_channel_manager())
489 gpu_channel_manager()->WakeUpGpu(); 426 gpu_channel_manager()->WakeUpGpu();
490 } 427 }
491 428
492 void GpuChildThread::OnDestroyingVideoSurface(int surface_id) { 429 void GpuChildThread::OnDestroyingVideoSurface(int surface_id) {
493 media::AVDACodecAllocator::Instance()->OnSurfaceDestroyed(surface_id); 430 media::AVDACodecAllocator::Instance()->OnSurfaceDestroyed(surface_id);
494 Send(new GpuHostMsg_DestroyingVideoSurfaceAck(surface_id)); 431 Send(new GpuHostMsg_DestroyingVideoSurfaceAck(surface_id));
495 } 432 }
496 #endif 433 #endif
497 434
498 void GpuChildThread::BindServiceFactoryRequest( 435 void GpuChildThread::BindServiceFactoryRequest(
499 service_manager::mojom::ServiceFactoryRequest request) { 436 service_manager::mojom::ServiceFactoryRequest request) {
500 DVLOG(1) << "GPU: Binding service_manager::mojom::ServiceFactoryRequest"; 437 DVLOG(1) << "GPU: Binding service_manager::mojom::ServiceFactoryRequest";
501 DCHECK(service_factory_); 438 DCHECK(service_factory_);
502 service_factory_bindings_.AddBinding(service_factory_.get(), 439 service_factory_bindings_.AddBinding(service_factory_.get(),
503 std::move(request)); 440 std::move(request));
504 } 441 }
505 442
506 } // namespace content 443 } // namespace content
OLDNEW
« no previous file with comments | « content/gpu/gpu_child_thread.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698