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

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, 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
« 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 #include "ui/ozone/public/ozone_platform.h" 48 #include "ui/ozone/public/ozone_platform.h"
49 #endif 49 #endif
50 50
51 #if defined(OS_ANDROID) 51 #if defined(OS_ANDROID)
52 #include "media/base/android/media_drm_bridge_client.h" 52 #include "media/base/android/media_drm_bridge_client.h"
53 #endif 53 #endif
54 54
55 namespace content { 55 namespace content {
56 namespace { 56 namespace {
57 57
58 // Message filter used to to handle GpuMsg_CreateGpuMemoryBuffer messages 58 ChildThreadImpl::Options GetOptions() {
59 // on the IO thread. This allows the UI thread in the browser process to remain
60 // fast at all times.
61 class GpuMemoryBufferMessageFilter : public IPC::MessageFilter {
62 public:
63 explicit GpuMemoryBufferMessageFilter(
64 gpu::GpuMemoryBufferFactory* gpu_memory_buffer_factory)
65 : gpu_memory_buffer_factory_(gpu_memory_buffer_factory),
66 sender_(nullptr) {}
67
68 // Overridden from IPC::MessageFilter:
69 void OnFilterAdded(IPC::Channel* channel) override {
70 DCHECK(!sender_);
71 sender_ = channel;
72 }
73 void OnFilterRemoved() override {
74 DCHECK(sender_);
75 sender_ = nullptr;
76 }
77 bool OnMessageReceived(const IPC::Message& message) override {
78 DCHECK(sender_);
79 bool handled = true;
80 IPC_BEGIN_MESSAGE_MAP(GpuMemoryBufferMessageFilter, message)
81 IPC_MESSAGE_HANDLER(GpuMsg_CreateGpuMemoryBuffer, OnCreateGpuMemoryBuffer)
82 IPC_MESSAGE_UNHANDLED(handled = false)
83 IPC_END_MESSAGE_MAP()
84 return handled;
85 }
86
87 protected:
88 ~GpuMemoryBufferMessageFilter() override {}
89
90 void OnCreateGpuMemoryBuffer(
91 const GpuMsg_CreateGpuMemoryBuffer_Params& params) {
92 TRACE_EVENT2("gpu", "GpuMemoryBufferMessageFilter::OnCreateGpuMemoryBuffer",
93 "id", params.id.id, "client_id", params.client_id);
94
95 DCHECK(gpu_memory_buffer_factory_);
96 sender_->Send(new GpuHostMsg_GpuMemoryBufferCreated(
97 gpu_memory_buffer_factory_->CreateGpuMemoryBuffer(
98 params.id, params.size, params.format, params.usage,
99 params.client_id, params.surface_handle)));
100 }
101
102 gpu::GpuMemoryBufferFactory* const gpu_memory_buffer_factory_;
103 IPC::Sender* sender_;
104 };
105
106 ChildThreadImpl::Options GetOptions(
107 gpu::GpuMemoryBufferFactory* gpu_memory_buffer_factory) {
108 ChildThreadImpl::Options::Builder builder; 59 ChildThreadImpl::Options::Builder builder;
109 60
110 builder.AddStartupFilter(
111 new GpuMemoryBufferMessageFilter(gpu_memory_buffer_factory));
112
113 #if defined(USE_OZONE) 61 #if defined(USE_OZONE)
114 IPC::MessageFilter* message_filter = 62 IPC::MessageFilter* message_filter =
115 ui::OzonePlatform::GetInstance()->GetGpuMessageFilter(); 63 ui::OzonePlatform::GetInstance()->GetGpuMessageFilter();
116 if (message_filter) 64 if (message_filter)
117 builder.AddStartupFilter(message_filter); 65 builder.AddStartupFilter(message_filter);
118 #endif 66 #endif
119 67
120 builder.ConnectToBrowser(true); 68 builder.ConnectToBrowser(true);
121 69
122 return builder.Build(); 70 return builder.Build();
123 } 71 }
124 72
125 } // namespace 73 } // namespace
126 74
127 GpuChildThread::GpuChildThread( 75 GpuChildThread::GpuChildThread(
128 std::unique_ptr<gpu::GpuWatchdogThread> watchdog_thread, 76 std::unique_ptr<gpu::GpuWatchdogThread> watchdog_thread,
129 bool dead_on_arrival, 77 bool dead_on_arrival,
130 const gpu::GPUInfo& gpu_info, 78 const gpu::GPUInfo& gpu_info,
131 const gpu::GpuFeatureInfo& gpu_feature_info, 79 const gpu::GpuFeatureInfo& gpu_feature_info,
132 DeferredMessages deferred_messages, 80 DeferredMessages deferred_messages,
133 gpu::GpuMemoryBufferFactory* gpu_memory_buffer_factory) 81 gpu::GpuMemoryBufferFactory* gpu_memory_buffer_factory)
134 : GpuChildThread(GetOptions(gpu_memory_buffer_factory), 82 : GpuChildThread(GetOptions(),
135 std::move(watchdog_thread), 83 std::move(watchdog_thread),
136 dead_on_arrival, 84 dead_on_arrival,
137 false /* in_browser_process */, 85 false /* in_browser_process */,
138 gpu_info, 86 gpu_info,
139 gpu_feature_info, 87 gpu_feature_info,
140 gpu_memory_buffer_factory) { 88 gpu_memory_buffer_factory) {
141 deferred_messages_ = std::move(deferred_messages); 89 deferred_messages_ = std::move(deferred_messages);
142 } 90 }
143 91
144 GpuChildThread::GpuChildThread( 92 GpuChildThread::GpuChildThread(
145 const InProcessChildThreadParams& params, 93 const InProcessChildThreadParams& params,
146 const gpu::GPUInfo& gpu_info, 94 const gpu::GPUInfo& gpu_info,
147 const gpu::GpuFeatureInfo& gpu_feature_info, 95 const gpu::GpuFeatureInfo& gpu_feature_info,
148 gpu::GpuMemoryBufferFactory* gpu_memory_buffer_factory) 96 gpu::GpuMemoryBufferFactory* gpu_memory_buffer_factory)
149 : GpuChildThread(ChildThreadImpl::Options::Builder() 97 : GpuChildThread(ChildThreadImpl::Options::Builder()
150 .InBrowserProcess(params) 98 .InBrowserProcess(params)
151 .AddStartupFilter(new GpuMemoryBufferMessageFilter(
152 gpu_memory_buffer_factory))
153 .ConnectToBrowser(true) 99 .ConnectToBrowser(true)
154 .Build(), 100 .Build(),
155 nullptr /* watchdog_thread */, 101 nullptr /* watchdog_thread */,
156 false /* dead_on_arrival */, 102 false /* dead_on_arrival */,
157 true /* in_browser_process */, 103 true /* in_browser_process */,
158 gpu_info, 104 gpu_info,
159 gpu_feature_info, 105 gpu_feature_info,
160 gpu_memory_buffer_factory) {} 106 gpu_memory_buffer_factory) {}
161 107
162 GpuChildThread::GpuChildThread( 108 GpuChildThread::GpuChildThread(
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 bool GpuChildThread::OnControlMessageReceived(const IPC::Message& msg) { 176 bool GpuChildThread::OnControlMessageReceived(const IPC::Message& msg) {
231 bool handled = true; 177 bool handled = true;
232 IPC_BEGIN_MESSAGE_MAP(GpuChildThread, msg) 178 IPC_BEGIN_MESSAGE_MAP(GpuChildThread, msg)
233 IPC_MESSAGE_HANDLER(GpuMsg_GpuSwitched, OnGpuSwitched) 179 IPC_MESSAGE_HANDLER(GpuMsg_GpuSwitched, OnGpuSwitched)
234 IPC_MESSAGE_UNHANDLED(handled = false) 180 IPC_MESSAGE_UNHANDLED(handled = false)
235 IPC_END_MESSAGE_MAP() 181 IPC_END_MESSAGE_MAP()
236 182
237 return handled; 183 return handled;
238 } 184 }
239 185
240 bool GpuChildThread::OnMessageReceived(const IPC::Message& msg) {
241 if (ChildThreadImpl::OnMessageReceived(msg))
242 return true;
243
244 bool handled = true;
245 IPC_BEGIN_MESSAGE_MAP(GpuChildThread, msg)
246 IPC_MESSAGE_HANDLER(GpuMsg_DestroyGpuMemoryBuffer, OnDestroyGpuMemoryBuffer)
247 IPC_MESSAGE_UNHANDLED(handled = false)
248 IPC_END_MESSAGE_MAP()
249 if (handled)
250 return true;
251
252 return false;
253 }
254
255 void GpuChildThread::OnAssociatedInterfaceRequest( 186 void GpuChildThread::OnAssociatedInterfaceRequest(
256 const std::string& name, 187 const std::string& name,
257 mojo::ScopedInterfaceEndpointHandle handle) { 188 mojo::ScopedInterfaceEndpointHandle handle) {
258 if (associated_interfaces_.CanBindRequest(name)) 189 if (associated_interfaces_.CanBindRequest(name))
259 associated_interfaces_.BindRequest(name, std::move(handle)); 190 associated_interfaces_.BindRequest(name, std::move(handle));
260 else 191 else
261 ChildThreadImpl::OnAssociatedInterfaceRequest(name, std::move(handle)); 192 ChildThreadImpl::OnAssociatedInterfaceRequest(name, std::move(handle));
262 } 193 }
263 194
264 void GpuChildThread::CreateGpuService( 195 void GpuChildThread::CreateGpuService(
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 NOTREACHED(); 243 NOTREACHED();
313 } 244 }
314 245
315 void GpuChildThread::OnGpuSwitched() { 246 void GpuChildThread::OnGpuSwitched() {
316 DVLOG(1) << "GPU: GPU has switched"; 247 DVLOG(1) << "GPU: GPU has switched";
317 // Notify observers in the GPU process. 248 // Notify observers in the GPU process.
318 if (!in_browser_process_) 249 if (!in_browser_process_)
319 ui::GpuSwitchingManager::GetInstance()->NotifyGpuSwitched(); 250 ui::GpuSwitchingManager::GetInstance()->NotifyGpuSwitched();
320 } 251 }
321 252
322 void GpuChildThread::OnDestroyGpuMemoryBuffer(
323 gfx::GpuMemoryBufferId id,
324 int client_id,
325 const gpu::SyncToken& sync_token) {
326 if (gpu_channel_manager())
327 gpu_channel_manager()->DestroyGpuMemoryBuffer(id, client_id, sync_token);
328 }
329
330 void GpuChildThread::BindServiceFactoryRequest( 253 void GpuChildThread::BindServiceFactoryRequest(
331 service_manager::mojom::ServiceFactoryRequest request) { 254 service_manager::mojom::ServiceFactoryRequest request) {
332 DVLOG(1) << "GPU: Binding service_manager::mojom::ServiceFactoryRequest"; 255 DVLOG(1) << "GPU: Binding service_manager::mojom::ServiceFactoryRequest";
333 DCHECK(service_factory_); 256 DCHECK(service_factory_);
334 service_factory_bindings_.AddBinding(service_factory_.get(), 257 service_factory_bindings_.AddBinding(service_factory_.get(),
335 std::move(request)); 258 std::move(request));
336 } 259 }
337 260
338 } // namespace content 261 } // 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