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 { |
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(handle)); | |
piman
2014/09/04 18:08:52
Lost the gpu_memory_buffer_factory_->CreateGpuMemo
alexst (slow to review)
2014/09/04 18:45:11
Gaah! Thanks for catching it!
| |
68 } | |
69 | |
70 IPC::Sender* sender_; | |
71 GpuMemoryBufferFactory* gpu_memory_buffer_factory_; | |
72 }; | |
32 } | 73 } |
33 | 74 |
34 GpuChannelManager::GpuChannelManager(MessageRouter* router, | 75 GpuChannelManager::GpuChannelManager(MessageRouter* router, |
35 GpuWatchdog* watchdog, | 76 GpuWatchdog* watchdog, |
36 base::MessageLoopProxy* io_message_loop, | 77 base::MessageLoopProxy* io_message_loop, |
37 base::WaitableEvent* shutdown_event) | 78 base::WaitableEvent* shutdown_event, |
79 IPC::SyncChannel* channel) | |
38 : weak_factory_(this), | 80 : weak_factory_(this), |
39 io_message_loop_(io_message_loop), | 81 io_message_loop_(io_message_loop), |
40 shutdown_event_(shutdown_event), | 82 shutdown_event_(shutdown_event), |
41 router_(router), | 83 router_(router), |
42 gpu_memory_manager_( | 84 gpu_memory_manager_( |
43 this, | 85 this, |
44 GpuMemoryManager::kDefaultMaxSurfacesWithFrontbufferSoftLimit), | 86 GpuMemoryManager::kDefaultMaxSurfacesWithFrontbufferSoftLimit), |
45 watchdog_(watchdog), | 87 watchdog_(watchdog), |
46 sync_point_manager_(new SyncPointManager), | 88 sync_point_manager_(new SyncPointManager), |
47 gpu_memory_buffer_factory_(GpuMemoryBufferFactory::Create()) { | 89 gpu_memory_buffer_factory_(GpuMemoryBufferFactory::Create()), |
90 channel_(channel), | |
91 filter_(new GpuChannelManagerMessageFilter( | |
92 gpu_memory_buffer_factory_.get())) { | |
48 DCHECK(router_); | 93 DCHECK(router_); |
49 DCHECK(io_message_loop); | 94 DCHECK(io_message_loop); |
50 DCHECK(shutdown_event); | 95 DCHECK(shutdown_event); |
96 channel_->AddFilter(filter_.get()); | |
51 } | 97 } |
52 | 98 |
53 GpuChannelManager::~GpuChannelManager() { | 99 GpuChannelManager::~GpuChannelManager() { |
54 gpu_channels_.clear(); | 100 gpu_channels_.clear(); |
55 if (default_offscreen_surface_.get()) { | 101 if (default_offscreen_surface_.get()) { |
56 default_offscreen_surface_->Destroy(); | 102 default_offscreen_surface_->Destroy(); |
57 default_offscreen_surface_ = NULL; | 103 default_offscreen_surface_ = NULL; |
58 } | 104 } |
59 DCHECK(gpu_memory_buffer_operations_.empty()); | |
60 } | 105 } |
61 | 106 |
62 gpu::gles2::ProgramCache* GpuChannelManager::program_cache() { | 107 gpu::gles2::ProgramCache* GpuChannelManager::program_cache() { |
63 if (!program_cache_.get() && | 108 if (!program_cache_.get() && |
64 (gfx::g_driver_gl.ext.b_GL_ARB_get_program_binary || | 109 (gfx::g_driver_gl.ext.b_GL_ARB_get_program_binary || |
65 gfx::g_driver_gl.ext.b_GL_OES_get_program_binary) && | 110 gfx::g_driver_gl.ext.b_GL_OES_get_program_binary) && |
66 !CommandLine::ForCurrentProcess()->HasSwitch( | 111 !CommandLine::ForCurrentProcess()->HasSwitch( |
67 switches::kDisableGpuProgramCache)) { | 112 switches::kDisableGpuProgramCache)) { |
68 program_cache_.reset(new gpu::gles2::MemoryProgramCache()); | 113 program_cache_.reset(new gpu::gles2::MemoryProgramCache()); |
69 } | 114 } |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
103 return iter->second; | 148 return iter->second; |
104 } | 149 } |
105 | 150 |
106 bool GpuChannelManager::OnMessageReceived(const IPC::Message& msg) { | 151 bool GpuChannelManager::OnMessageReceived(const IPC::Message& msg) { |
107 bool handled = true; | 152 bool handled = true; |
108 IPC_BEGIN_MESSAGE_MAP(GpuChannelManager, msg) | 153 IPC_BEGIN_MESSAGE_MAP(GpuChannelManager, msg) |
109 IPC_MESSAGE_HANDLER(GpuMsg_EstablishChannel, OnEstablishChannel) | 154 IPC_MESSAGE_HANDLER(GpuMsg_EstablishChannel, OnEstablishChannel) |
110 IPC_MESSAGE_HANDLER(GpuMsg_CloseChannel, OnCloseChannel) | 155 IPC_MESSAGE_HANDLER(GpuMsg_CloseChannel, OnCloseChannel) |
111 IPC_MESSAGE_HANDLER(GpuMsg_CreateViewCommandBuffer, | 156 IPC_MESSAGE_HANDLER(GpuMsg_CreateViewCommandBuffer, |
112 OnCreateViewCommandBuffer) | 157 OnCreateViewCommandBuffer) |
113 IPC_MESSAGE_HANDLER(GpuMsg_CreateGpuMemoryBuffer, OnCreateGpuMemoryBuffer) | |
114 IPC_MESSAGE_HANDLER(GpuMsg_DestroyGpuMemoryBuffer, OnDestroyGpuMemoryBuffer) | 158 IPC_MESSAGE_HANDLER(GpuMsg_DestroyGpuMemoryBuffer, OnDestroyGpuMemoryBuffer) |
115 IPC_MESSAGE_HANDLER(GpuMsg_LoadedShader, OnLoadedShader) | 159 IPC_MESSAGE_HANDLER(GpuMsg_LoadedShader, OnLoadedShader) |
116 IPC_MESSAGE_UNHANDLED(handled = false) | 160 IPC_MESSAGE_UNHANDLED(handled = false) |
117 IPC_END_MESSAGE_MAP() | 161 IPC_END_MESSAGE_MAP() |
118 return handled; | 162 return handled; |
119 } | 163 } |
120 | 164 |
121 bool GpuChannelManager::Send(IPC::Message* msg) { return router_->Send(msg); } | 165 bool GpuChannelManager::Send(IPC::Message* msg) { return router_->Send(msg); } |
122 | 166 |
123 void GpuChannelManager::OnEstablishChannel(int client_id, | 167 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; | 225 CreateCommandBufferResult result = CREATE_COMMAND_BUFFER_FAILED; |
182 | 226 |
183 GpuChannelMap::const_iterator iter = gpu_channels_.find(client_id); | 227 GpuChannelMap::const_iterator iter = gpu_channels_.find(client_id); |
184 if (iter != gpu_channels_.end()) { | 228 if (iter != gpu_channels_.end()) { |
185 result = iter->second->CreateViewCommandBuffer( | 229 result = iter->second->CreateViewCommandBuffer( |
186 window, surface_id, init_params, route_id); | 230 window, surface_id, init_params, route_id); |
187 } | 231 } |
188 | 232 |
189 Send(new GpuHostMsg_CommandBufferCreated(result)); | 233 Send(new GpuHostMsg_CommandBufferCreated(result)); |
190 } | 234 } |
191 | 235 void GpuChannelManager::DestroyGpuMemoryBuffer( |
192 void GpuChannelManager::CreateGpuMemoryBuffer( | 236 const gfx::GpuMemoryBufferHandle& handle) { |
193 const gfx::GpuMemoryBufferHandle& handle, | 237 io_message_loop_->PostTask( |
194 const gfx::Size& size, | 238 FROM_HERE, |
195 unsigned internalformat, | 239 base::Bind(&GpuChannelManager::DestroyGpuMemoryBufferOnIO, |
196 unsigned usage) { | 240 base::Unretained(this), |
197 Send(new GpuHostMsg_GpuMemoryBufferCreated( | 241 handle)); |
198 gpu_memory_buffer_factory_->CreateGpuMemoryBuffer( | |
199 handle, size, internalformat, usage))); | |
200 } | 242 } |
201 | 243 |
202 void GpuChannelManager::OnCreateGpuMemoryBuffer( | 244 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) { | 245 const gfx::GpuMemoryBufferHandle& handle) { |
223 gpu_memory_buffer_factory_->DestroyGpuMemoryBuffer(handle); | 246 gpu_memory_buffer_factory_->DestroyGpuMemoryBuffer(handle); |
224 } | 247 } |
225 | 248 |
226 void GpuChannelManager::OnDestroyGpuMemoryBuffer( | 249 void GpuChannelManager::OnDestroyGpuMemoryBuffer( |
227 const gfx::GpuMemoryBufferHandle& handle, | 250 const gfx::GpuMemoryBufferHandle& handle, |
228 int32 sync_point) { | 251 int32 sync_point) { |
229 if (!sync_point && gpu_memory_buffer_operations_.empty()) { | 252 if (!sync_point) { |
230 DestroyGpuMemoryBuffer(handle); | 253 DestroyGpuMemoryBuffer(handle); |
231 } else { | 254 } else { |
232 gpu_memory_buffer_operations_.push_back(new GpuMemoryBufferOperation( | |
233 sync_point, | |
234 base::Bind(&GpuChannelManager::DestroyGpuMemoryBuffer, | |
235 base::Unretained(this), | |
236 handle))); | |
237 if (sync_point) { | |
238 sync_point_manager()->AddSyncPointCallback( | 255 sync_point_manager()->AddSyncPointCallback( |
239 sync_point, | 256 sync_point, |
240 base::Bind( | 257 base::Bind( |
241 &GpuChannelManager::OnDestroyGpuMemoryBufferSyncPointRetired, | 258 &GpuChannelManager::DestroyGpuMemoryBuffer, |
242 base::Unretained(this), | 259 base::Unretained(this), |
243 gpu_memory_buffer_operations_.back())); | 260 handle)); |
244 } | |
245 } | 261 } |
246 } | 262 } |
247 | 263 |
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) { | 264 void GpuChannelManager::OnLoadedShader(std::string program_proto) { |
266 if (program_cache()) | 265 if (program_cache()) |
267 program_cache()->LoadProgram(program_proto); | 266 program_cache()->LoadProgram(program_proto); |
268 } | 267 } |
269 | 268 |
270 bool GpuChannelManager::HandleMessagesScheduled() { | 269 bool GpuChannelManager::HandleMessagesScheduled() { |
271 for (GpuChannelMap::iterator iter = gpu_channels_.begin(); | 270 for (GpuChannelMap::iterator iter = gpu_channels_.begin(); |
272 iter != gpu_channels_.end(); ++iter) { | 271 iter != gpu_channels_.end(); ++iter) { |
273 if (iter->second->handle_messages_scheduled()) | 272 if (iter->second->handle_messages_scheduled()) |
274 return true; | 273 return true; |
(...skipping 28 matching lines...) Expand all Loading... | |
303 | 302 |
304 gfx::GLSurface* GpuChannelManager::GetDefaultOffscreenSurface() { | 303 gfx::GLSurface* GpuChannelManager::GetDefaultOffscreenSurface() { |
305 if (!default_offscreen_surface_.get()) { | 304 if (!default_offscreen_surface_.get()) { |
306 default_offscreen_surface_ = | 305 default_offscreen_surface_ = |
307 gfx::GLSurface::CreateOffscreenGLSurface(gfx::Size()); | 306 gfx::GLSurface::CreateOffscreenGLSurface(gfx::Size()); |
308 } | 307 } |
309 return default_offscreen_surface_.get(); | 308 return default_offscreen_surface_.get(); |
310 } | 309 } |
311 | 310 |
312 } // namespace content | 311 } // namespace content |
OLD | NEW |