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/common/gpu/gpu_channel_manager.h" | 5 #include "content/common/gpu/gpu_channel_manager.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "content/common/gpu/gpu_channel.h" | 9 #include "content/common/gpu/gpu_channel.h" |
10 #include "content/common/gpu/gpu_memory_buffer_factory.h" | 10 #include "content/common/gpu/gpu_memory_buffer_factory.h" |
11 #include "content/common/gpu/gpu_memory_manager.h" | 11 #include "content/common/gpu/gpu_memory_manager.h" |
12 #include "content/common/gpu/gpu_messages.h" | 12 #include "content/common/gpu/gpu_messages.h" |
13 #include "content/common/gpu/sync_point_manager.h" | 13 #include "content/common/gpu/sync_point_manager.h" |
14 #include "content/common/message_router.h" | 14 #include "content/common/message_router.h" |
15 #include "gpu/command_buffer/service/feature_info.h" | 15 #include "gpu/command_buffer/service/feature_info.h" |
16 #include "gpu/command_buffer/service/gpu_switches.h" | 16 #include "gpu/command_buffer/service/gpu_switches.h" |
17 #include "gpu/command_buffer/service/mailbox_manager.h" | 17 #include "gpu/command_buffer/service/mailbox_manager.h" |
18 #include "gpu/command_buffer/service/memory_program_cache.h" | 18 #include "gpu/command_buffer/service/memory_program_cache.h" |
19 #include "gpu/command_buffer/service/shader_translator_cache.h" | 19 #include "gpu/command_buffer/service/shader_translator_cache.h" |
20 #include "ipc/message_filter.h" | |
20 #include "ui/gl/gl_bindings.h" | 21 #include "ui/gl/gl_bindings.h" |
21 #include "ui/gl/gl_share_group.h" | 22 #include "ui/gl/gl_share_group.h" |
22 | 23 |
23 namespace content { | 24 namespace content { |
24 | 25 |
25 GpuChannelManager::GpuMemoryBufferOperation::GpuMemoryBufferOperation( | 26 namespace { |
26 int32 sync_point, | |
27 base::Closure callback) | |
28 : sync_point(sync_point), callback(callback) { | |
29 } | |
30 | 27 |
31 GpuChannelManager::GpuMemoryBufferOperation::~GpuMemoryBufferOperation() { | 28 class GpuChannelManagerMessageFilter : public IPC::MessageFilter { |
reveman
2014/09/09 17:18:26
Just to be be sure. If we ever wanted to handle so
piman
2014/09/09 20:00:09
I think so. Filters have a non-0 cost, we're seein
alexst (slow to review)
2014/09/09 21:53:57
Yes, I don't see why not.
| |
32 } | 29 public: |
30 GpuChannelManagerMessageFilter( | |
31 GpuMemoryBufferFactory* gpu_memory_buffer_factory) | |
32 : sender_(NULL), gpu_memory_buffer_factory_(gpu_memory_buffer_factory) {} | |
33 | |
34 virtual void OnFilterAdded(IPC::Sender* sender) OVERRIDE { | |
35 DCHECK(!sender_); | |
36 sender_ = sender; | |
37 } | |
38 | |
39 virtual void OnFilterRemoved() OVERRIDE { | |
40 DCHECK(sender_); | |
41 sender_ = NULL; | |
42 } | |
43 | |
44 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE { | |
45 DCHECK(sender_); | |
46 bool handled = true; | |
47 IPC_BEGIN_MESSAGE_MAP(GpuChannelManagerMessageFilter, message) | |
48 IPC_MESSAGE_HANDLER(GpuMsg_CreateGpuMemoryBuffer, OnCreateGpuMemoryBuffer) | |
49 IPC_MESSAGE_UNHANDLED(handled = false) | |
50 IPC_END_MESSAGE_MAP() | |
51 return handled; | |
52 } | |
53 | |
54 protected: | |
55 virtual ~GpuChannelManagerMessageFilter() {} | |
56 | |
57 void OnCreateGpuMemoryBuffer(const gfx::GpuMemoryBufferHandle& handle, | |
58 const gfx::Size& size, | |
59 unsigned internalformat, | |
60 unsigned usage) { | |
61 TRACE_EVENT2("gpu", | |
62 "GpuChannelManagerMessageFilter::OnCreateGpuMemoryBuffer", | |
63 "primary_id", | |
64 handle.global_id.primary_id, | |
65 "secondary_id", | |
66 handle.global_id.secondary_id); | |
67 sender_->Send(new GpuHostMsg_GpuMemoryBufferCreated( | |
68 gpu_memory_buffer_factory_->CreateGpuMemoryBuffer( | |
69 handle, size, internalformat, usage))); | |
70 } | |
71 | |
72 IPC::Sender* sender_; | |
73 GpuMemoryBufferFactory* gpu_memory_buffer_factory_; | |
74 }; | |
75 | |
76 } // namespace | |
33 | 77 |
34 GpuChannelManager::GpuChannelManager(MessageRouter* router, | 78 GpuChannelManager::GpuChannelManager(MessageRouter* router, |
35 GpuWatchdog* watchdog, | 79 GpuWatchdog* watchdog, |
36 base::MessageLoopProxy* io_message_loop, | 80 base::MessageLoopProxy* io_message_loop, |
37 base::WaitableEvent* shutdown_event) | 81 base::WaitableEvent* shutdown_event, |
82 IPC::SyncChannel* channel) | |
38 : weak_factory_(this), | 83 : weak_factory_(this), |
39 io_message_loop_(io_message_loop), | 84 io_message_loop_(io_message_loop), |
40 shutdown_event_(shutdown_event), | 85 shutdown_event_(shutdown_event), |
41 router_(router), | 86 router_(router), |
42 gpu_memory_manager_( | 87 gpu_memory_manager_( |
43 this, | 88 this, |
44 GpuMemoryManager::kDefaultMaxSurfacesWithFrontbufferSoftLimit), | 89 GpuMemoryManager::kDefaultMaxSurfacesWithFrontbufferSoftLimit), |
45 watchdog_(watchdog), | 90 watchdog_(watchdog), |
46 sync_point_manager_(new SyncPointManager), | 91 sync_point_manager_(new SyncPointManager), |
47 gpu_memory_buffer_factory_(GpuMemoryBufferFactory::Create()) { | 92 gpu_memory_buffer_factory_(GpuMemoryBufferFactory::Create()), |
reveman
2014/09/09 17:18:26
could the ownership of the factory move to GpuChan
alexst (slow to review)
2014/09/09 21:53:57
I just tried moving ownership to the filter, but I
reveman
2014/09/09 23:17:54
Acknowledged.
| |
93 channel_(channel), | |
94 filter_(new GpuChannelManagerMessageFilter( | |
95 gpu_memory_buffer_factory_.get())) { | |
48 DCHECK(router_); | 96 DCHECK(router_); |
49 DCHECK(io_message_loop); | 97 DCHECK(io_message_loop); |
50 DCHECK(shutdown_event); | 98 DCHECK(shutdown_event); |
99 channel_->AddFilter(filter_.get()); | |
51 } | 100 } |
52 | 101 |
53 GpuChannelManager::~GpuChannelManager() { | 102 GpuChannelManager::~GpuChannelManager() { |
54 gpu_channels_.clear(); | 103 gpu_channels_.clear(); |
55 if (default_offscreen_surface_.get()) { | 104 if (default_offscreen_surface_.get()) { |
56 default_offscreen_surface_->Destroy(); | 105 default_offscreen_surface_->Destroy(); |
57 default_offscreen_surface_ = NULL; | 106 default_offscreen_surface_ = NULL; |
58 } | 107 } |
59 DCHECK(gpu_memory_buffer_operations_.empty()); | |
60 } | 108 } |
61 | 109 |
62 gpu::gles2::ProgramCache* GpuChannelManager::program_cache() { | 110 gpu::gles2::ProgramCache* GpuChannelManager::program_cache() { |
63 if (!program_cache_.get() && | 111 if (!program_cache_.get() && |
64 (gfx::g_driver_gl.ext.b_GL_ARB_get_program_binary || | 112 (gfx::g_driver_gl.ext.b_GL_ARB_get_program_binary || |
65 gfx::g_driver_gl.ext.b_GL_OES_get_program_binary) && | 113 gfx::g_driver_gl.ext.b_GL_OES_get_program_binary) && |
66 !CommandLine::ForCurrentProcess()->HasSwitch( | 114 !CommandLine::ForCurrentProcess()->HasSwitch( |
67 switches::kDisableGpuProgramCache)) { | 115 switches::kDisableGpuProgramCache)) { |
68 program_cache_.reset(new gpu::gles2::MemoryProgramCache()); | 116 program_cache_.reset(new gpu::gles2::MemoryProgramCache()); |
69 } | 117 } |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
103 return iter->second; | 151 return iter->second; |
104 } | 152 } |
105 | 153 |
106 bool GpuChannelManager::OnMessageReceived(const IPC::Message& msg) { | 154 bool GpuChannelManager::OnMessageReceived(const IPC::Message& msg) { |
107 bool handled = true; | 155 bool handled = true; |
108 IPC_BEGIN_MESSAGE_MAP(GpuChannelManager, msg) | 156 IPC_BEGIN_MESSAGE_MAP(GpuChannelManager, msg) |
109 IPC_MESSAGE_HANDLER(GpuMsg_EstablishChannel, OnEstablishChannel) | 157 IPC_MESSAGE_HANDLER(GpuMsg_EstablishChannel, OnEstablishChannel) |
110 IPC_MESSAGE_HANDLER(GpuMsg_CloseChannel, OnCloseChannel) | 158 IPC_MESSAGE_HANDLER(GpuMsg_CloseChannel, OnCloseChannel) |
111 IPC_MESSAGE_HANDLER(GpuMsg_CreateViewCommandBuffer, | 159 IPC_MESSAGE_HANDLER(GpuMsg_CreateViewCommandBuffer, |
112 OnCreateViewCommandBuffer) | 160 OnCreateViewCommandBuffer) |
113 IPC_MESSAGE_HANDLER(GpuMsg_CreateGpuMemoryBuffer, OnCreateGpuMemoryBuffer) | |
114 IPC_MESSAGE_HANDLER(GpuMsg_DestroyGpuMemoryBuffer, OnDestroyGpuMemoryBuffer) | 161 IPC_MESSAGE_HANDLER(GpuMsg_DestroyGpuMemoryBuffer, OnDestroyGpuMemoryBuffer) |
115 IPC_MESSAGE_HANDLER(GpuMsg_LoadedShader, OnLoadedShader) | 162 IPC_MESSAGE_HANDLER(GpuMsg_LoadedShader, OnLoadedShader) |
116 IPC_MESSAGE_UNHANDLED(handled = false) | 163 IPC_MESSAGE_UNHANDLED(handled = false) |
117 IPC_END_MESSAGE_MAP() | 164 IPC_END_MESSAGE_MAP() |
118 return handled; | 165 return handled; |
119 } | 166 } |
120 | 167 |
121 bool GpuChannelManager::Send(IPC::Message* msg) { return router_->Send(msg); } | 168 bool GpuChannelManager::Send(IPC::Message* msg) { return router_->Send(msg); } |
122 | 169 |
123 void GpuChannelManager::OnEstablishChannel(int client_id, | 170 void GpuChannelManager::OnEstablishChannel(int client_id, |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
181 CreateCommandBufferResult result = CREATE_COMMAND_BUFFER_FAILED; | 228 CreateCommandBufferResult result = CREATE_COMMAND_BUFFER_FAILED; |
182 | 229 |
183 GpuChannelMap::const_iterator iter = gpu_channels_.find(client_id); | 230 GpuChannelMap::const_iterator iter = gpu_channels_.find(client_id); |
184 if (iter != gpu_channels_.end()) { | 231 if (iter != gpu_channels_.end()) { |
185 result = iter->second->CreateViewCommandBuffer( | 232 result = iter->second->CreateViewCommandBuffer( |
186 window, surface_id, init_params, route_id); | 233 window, surface_id, init_params, route_id); |
187 } | 234 } |
188 | 235 |
189 Send(new GpuHostMsg_CommandBufferCreated(result)); | 236 Send(new GpuHostMsg_CommandBufferCreated(result)); |
190 } | 237 } |
191 | 238 void GpuChannelManager::DestroyGpuMemoryBuffer( |
192 void GpuChannelManager::CreateGpuMemoryBuffer( | 239 const gfx::GpuMemoryBufferHandle& handle) { |
193 const gfx::GpuMemoryBufferHandle& handle, | 240 io_message_loop_->PostTask( |
194 const gfx::Size& size, | 241 FROM_HERE, |
195 unsigned internalformat, | 242 base::Bind(&GpuChannelManager::DestroyGpuMemoryBufferOnIO, |
196 unsigned usage) { | 243 base::Unretained(this), |
197 Send(new GpuHostMsg_GpuMemoryBufferCreated( | 244 handle)); |
198 gpu_memory_buffer_factory_->CreateGpuMemoryBuffer( | |
199 handle, size, internalformat, usage))); | |
200 } | 245 } |
201 | 246 |
202 void GpuChannelManager::OnCreateGpuMemoryBuffer( | 247 void GpuChannelManager::DestroyGpuMemoryBufferOnIO( |
203 const gfx::GpuMemoryBufferHandle& handle, | |
204 const gfx::Size& size, | |
205 unsigned internalformat, | |
206 unsigned usage) { | |
207 if (gpu_memory_buffer_operations_.empty()) { | |
208 CreateGpuMemoryBuffer(handle, size, internalformat, usage); | |
209 } else { | |
210 gpu_memory_buffer_operations_.push_back(new GpuMemoryBufferOperation( | |
211 0, | |
212 base::Bind(&GpuChannelManager::CreateGpuMemoryBuffer, | |
213 base::Unretained(this), | |
214 handle, | |
215 size, | |
216 internalformat, | |
217 usage))); | |
218 } | |
219 } | |
220 | |
221 void GpuChannelManager::DestroyGpuMemoryBuffer( | |
222 const gfx::GpuMemoryBufferHandle& handle) { | 248 const gfx::GpuMemoryBufferHandle& handle) { |
223 gpu_memory_buffer_factory_->DestroyGpuMemoryBuffer(handle); | 249 gpu_memory_buffer_factory_->DestroyGpuMemoryBuffer(handle); |
224 } | 250 } |
225 | 251 |
226 void GpuChannelManager::OnDestroyGpuMemoryBuffer( | 252 void GpuChannelManager::OnDestroyGpuMemoryBuffer( |
227 const gfx::GpuMemoryBufferHandle& handle, | 253 const gfx::GpuMemoryBufferHandle& handle, |
228 int32 sync_point) { | 254 int32 sync_point) { |
229 if (!sync_point && gpu_memory_buffer_operations_.empty()) { | 255 if (!sync_point) { |
230 DestroyGpuMemoryBuffer(handle); | 256 DestroyGpuMemoryBuffer(handle); |
231 } else { | 257 } else { |
232 gpu_memory_buffer_operations_.push_back(new GpuMemoryBufferOperation( | 258 sync_point_manager()->AddSyncPointCallback( |
233 sync_point, | 259 sync_point, |
234 base::Bind(&GpuChannelManager::DestroyGpuMemoryBuffer, | 260 base::Bind(&GpuChannelManager::DestroyGpuMemoryBuffer, |
235 base::Unretained(this), | 261 base::Unretained(this), |
236 handle))); | 262 handle)); |
237 if (sync_point) { | |
238 sync_point_manager()->AddSyncPointCallback( | |
239 sync_point, | |
240 base::Bind( | |
241 &GpuChannelManager::OnDestroyGpuMemoryBufferSyncPointRetired, | |
242 base::Unretained(this), | |
243 gpu_memory_buffer_operations_.back())); | |
244 } | |
245 } | 263 } |
246 } | 264 } |
247 | 265 |
248 void GpuChannelManager::OnDestroyGpuMemoryBufferSyncPointRetired( | |
249 GpuMemoryBufferOperation* gpu_memory_buffer_operation) { | |
250 // Mark operation as no longer having a pending sync point. | |
251 gpu_memory_buffer_operation->sync_point = 0; | |
252 | |
253 // De-queue operations until we reach a pending sync point. | |
254 while (!gpu_memory_buffer_operations_.empty()) { | |
255 // Check if operation has a pending sync point. | |
256 if (gpu_memory_buffer_operations_.front()->sync_point) | |
257 break; | |
258 | |
259 gpu_memory_buffer_operations_.front()->callback.Run(); | |
260 delete gpu_memory_buffer_operations_.front(); | |
261 gpu_memory_buffer_operations_.pop_front(); | |
262 } | |
263 } | |
264 | |
265 void GpuChannelManager::OnLoadedShader(std::string program_proto) { | 266 void GpuChannelManager::OnLoadedShader(std::string program_proto) { |
266 if (program_cache()) | 267 if (program_cache()) |
267 program_cache()->LoadProgram(program_proto); | 268 program_cache()->LoadProgram(program_proto); |
268 } | 269 } |
269 | 270 |
270 bool GpuChannelManager::HandleMessagesScheduled() { | 271 bool GpuChannelManager::HandleMessagesScheduled() { |
271 for (GpuChannelMap::iterator iter = gpu_channels_.begin(); | 272 for (GpuChannelMap::iterator iter = gpu_channels_.begin(); |
272 iter != gpu_channels_.end(); ++iter) { | 273 iter != gpu_channels_.end(); ++iter) { |
273 if (iter->second->handle_messages_scheduled()) | 274 if (iter->second->handle_messages_scheduled()) |
274 return true; | 275 return true; |
(...skipping 28 matching lines...) Expand all Loading... | |
303 | 304 |
304 gfx::GLSurface* GpuChannelManager::GetDefaultOffscreenSurface() { | 305 gfx::GLSurface* GpuChannelManager::GetDefaultOffscreenSurface() { |
305 if (!default_offscreen_surface_.get()) { | 306 if (!default_offscreen_surface_.get()) { |
306 default_offscreen_surface_ = | 307 default_offscreen_surface_ = |
307 gfx::GLSurface::CreateOffscreenGLSurface(gfx::Size()); | 308 gfx::GLSurface::CreateOffscreenGLSurface(gfx::Size()); |
308 } | 309 } |
309 return default_offscreen_surface_.get(); | 310 return default_offscreen_surface_.get(); |
310 } | 311 } |
311 | 312 |
312 } // namespace content | 313 } // namespace content |
OLD | NEW |