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/client/command_buffer_proxy_impl.h" | 5 #include "content/common/gpu/client/command_buffer_proxy_impl.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/shared_memory.h" | 10 #include "base/memory/shared_memory.h" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 DCHECK(handled); | 55 DCHECK(handled); |
56 return handled; | 56 return handled; |
57 } | 57 } |
58 | 58 |
59 void CommandBufferProxyImpl::OnChannelError() { | 59 void CommandBufferProxyImpl::OnChannelError() { |
60 OnDestroyed(gpu::error::kUnknown); | 60 OnDestroyed(gpu::error::kUnknown); |
61 } | 61 } |
62 | 62 |
63 void CommandBufferProxyImpl::OnDestroyed(gpu::error::ContextLostReason reason) { | 63 void CommandBufferProxyImpl::OnDestroyed(gpu::error::ContextLostReason reason) { |
64 // Prevent any further messages from being sent. | 64 // Prevent any further messages from being sent. |
65 channel_ = NULL; | 65 channel_ = nullptr; |
66 | 66 |
67 // When the client sees that the context is lost, they should delete this | 67 // When the client sees that the context is lost, they should delete this |
68 // CommandBufferProxyImpl and create a new one. | 68 // CommandBufferProxyImpl and create a new one. |
69 last_state_.error = gpu::error::kLostContext; | 69 last_state_.error = gpu::error::kLostContext; |
70 last_state_.context_lost_reason = reason; | 70 last_state_.context_lost_reason = reason; |
71 | 71 |
72 if (!channel_error_callback_.is_null()) { | 72 if (!channel_error_callback_.is_null()) { |
73 channel_error_callback_.Run(); | 73 channel_error_callback_.Run(); |
74 // Avoid calling the error callback more than once. | 74 // Avoid calling the error callback more than once. |
75 channel_error_callback_.Reset(); | 75 channel_error_callback_.Reset(); |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 Send(new GpuCommandBufferMsg_SetGetBuffer(route_id_, shm_id)); | 244 Send(new GpuCommandBufferMsg_SetGetBuffer(route_id_, shm_id)); |
245 last_put_offset_ = -1; | 245 last_put_offset_ = -1; |
246 } | 246 } |
247 | 247 |
248 scoped_refptr<gpu::Buffer> CommandBufferProxyImpl::CreateTransferBuffer( | 248 scoped_refptr<gpu::Buffer> CommandBufferProxyImpl::CreateTransferBuffer( |
249 size_t size, | 249 size_t size, |
250 int32* id) { | 250 int32* id) { |
251 *id = -1; | 251 *id = -1; |
252 | 252 |
253 if (last_state_.error != gpu::error::kNoError) | 253 if (last_state_.error != gpu::error::kNoError) |
254 return NULL; | 254 return nullptr; |
255 | 255 |
256 int32 new_id = channel_->ReserveTransferBufferId(); | 256 int32 new_id = channel_->ReserveTransferBufferId(); |
257 | 257 |
258 scoped_ptr<base::SharedMemory> shared_memory( | 258 scoped_ptr<base::SharedMemory> shared_memory( |
259 channel_->factory()->AllocateSharedMemory(size)); | 259 channel_->factory()->AllocateSharedMemory(size)); |
260 if (!shared_memory) | 260 if (!shared_memory) |
261 return NULL; | 261 return nullptr; |
262 | 262 |
263 DCHECK(!shared_memory->memory()); | 263 DCHECK(!shared_memory->memory()); |
264 if (!shared_memory->Map(size)) | 264 if (!shared_memory->Map(size)) |
265 return NULL; | 265 return nullptr; |
266 | 266 |
267 // This handle is owned by the GPU process and must be passed to it or it | 267 // This handle is owned by the GPU process and must be passed to it or it |
268 // will leak. In otherwords, do not early out on error between here and the | 268 // will leak. In otherwords, do not early out on error between here and the |
269 // sending of the RegisterTransferBuffer IPC below. | 269 // sending of the RegisterTransferBuffer IPC below. |
270 base::SharedMemoryHandle handle = | 270 base::SharedMemoryHandle handle = |
271 channel_->ShareToGpuProcess(shared_memory->handle()); | 271 channel_->ShareToGpuProcess(shared_memory->handle()); |
272 if (!base::SharedMemory::IsHandleValid(handle)) | 272 if (!base::SharedMemory::IsHandleValid(handle)) |
273 return NULL; | 273 return nullptr; |
274 | 274 |
275 if (!Send(new GpuCommandBufferMsg_RegisterTransferBuffer(route_id_, | 275 if (!Send(new GpuCommandBufferMsg_RegisterTransferBuffer(route_id_, |
276 new_id, | 276 new_id, |
277 handle, | 277 handle, |
278 size))) { | 278 size))) { |
279 return NULL; | 279 return nullptr; |
280 } | 280 } |
281 | 281 |
282 *id = new_id; | 282 *id = new_id; |
283 scoped_refptr<gpu::Buffer> buffer( | 283 scoped_refptr<gpu::Buffer> buffer( |
284 gpu::MakeBufferFromSharedMemory(shared_memory.Pass(), size)); | 284 gpu::MakeBufferFromSharedMemory(shared_memory.Pass(), size)); |
285 return buffer; | 285 return buffer; |
286 } | 286 } |
287 | 287 |
288 void CommandBufferProxyImpl::DestroyTransferBuffer(int32 id) { | 288 void CommandBufferProxyImpl::DestroyTransferBuffer(int32 id) { |
289 if (last_state_.error != gpu::error::kNoError) | 289 if (last_state_.error != gpu::error::kNoError) |
290 return; | 290 return; |
291 | 291 |
292 Send(new GpuCommandBufferMsg_DestroyTransferBuffer(route_id_, id)); | 292 Send(new GpuCommandBufferMsg_DestroyTransferBuffer(route_id_, id)); |
293 } | 293 } |
294 | 294 |
295 gpu::Capabilities CommandBufferProxyImpl::GetCapabilities() { | 295 gpu::Capabilities CommandBufferProxyImpl::GetCapabilities() { |
296 return capabilities_; | 296 return capabilities_; |
297 } | 297 } |
298 | 298 |
299 gfx::GpuMemoryBuffer* CommandBufferProxyImpl::CreateGpuMemoryBuffer( | 299 gfx::GpuMemoryBuffer* CommandBufferProxyImpl::CreateGpuMemoryBuffer( |
300 size_t width, | 300 size_t width, |
301 size_t height, | 301 size_t height, |
302 unsigned internalformat, | 302 unsigned internalformat, |
303 unsigned usage, | 303 unsigned usage, |
304 int32* id) { | 304 int32* id) { |
305 *id = -1; | 305 *id = -1; |
306 | 306 |
307 if (last_state_.error != gpu::error::kNoError) | 307 if (last_state_.error != gpu::error::kNoError) |
308 return NULL; | 308 return nullptr; |
309 | 309 |
310 scoped_ptr<gfx::GpuMemoryBuffer> buffer( | 310 scoped_ptr<gfx::GpuMemoryBuffer> buffer( |
311 channel_->factory()->AllocateGpuMemoryBuffer( | 311 channel_->factory()->AllocateGpuMemoryBuffer( |
312 width, height, internalformat, usage)); | 312 width, height, internalformat, usage)); |
313 if (!buffer) | 313 if (!buffer) |
314 return NULL; | 314 return nullptr; |
315 | 315 |
316 DCHECK(GpuChannelHost::IsValidGpuMemoryBuffer(buffer->GetHandle())); | 316 DCHECK(GpuChannelHost::IsValidGpuMemoryBuffer(buffer->GetHandle())); |
317 | 317 |
318 int32 new_id = channel_->ReserveGpuMemoryBufferId(); | 318 int32 new_id = channel_->ReserveGpuMemoryBufferId(); |
319 | 319 |
320 // This handle is owned by the GPU process and must be passed to it or it | 320 // This handle is owned by the GPU process and must be passed to it or it |
321 // will leak. In otherwords, do not early out on error between here and the | 321 // will leak. In otherwords, do not early out on error between here and the |
322 // sending of the RegisterGpuMemoryBuffer IPC below. | 322 // sending of the RegisterGpuMemoryBuffer IPC below. |
323 gfx::GpuMemoryBufferHandle handle = | 323 gfx::GpuMemoryBufferHandle handle = |
324 channel_->ShareGpuMemoryBufferToGpuProcess(buffer->GetHandle()); | 324 channel_->ShareGpuMemoryBufferToGpuProcess(buffer->GetHandle()); |
325 | 325 |
326 if (!Send(new GpuCommandBufferMsg_RegisterGpuMemoryBuffer( | 326 if (!Send(new GpuCommandBufferMsg_RegisterGpuMemoryBuffer( |
327 route_id_, | 327 route_id_, |
328 new_id, | 328 new_id, |
329 handle, | 329 handle, |
330 width, | 330 width, |
331 height, | 331 height, |
332 internalformat))) { | 332 internalformat))) { |
333 return NULL; | 333 return nullptr; |
334 } | 334 } |
335 | 335 |
336 *id = new_id; | 336 *id = new_id; |
337 DCHECK(gpu_memory_buffers_.find(new_id) == gpu_memory_buffers_.end()); | 337 DCHECK(gpu_memory_buffers_.find(new_id) == gpu_memory_buffers_.end()); |
338 return gpu_memory_buffers_.add(new_id, buffer.Pass()).first->second; | 338 return gpu_memory_buffers_.add(new_id, buffer.Pass()).first->second; |
339 } | 339 } |
340 | 340 |
341 void CommandBufferProxyImpl::DestroyGpuMemoryBuffer(int32 id) { | 341 void CommandBufferProxyImpl::DestroyGpuMemoryBuffer(int32 id) { |
342 if (last_state_.error != gpu::error::kNoError) | 342 if (last_state_.error != gpu::error::kNoError) |
343 return; | 343 return; |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
517 if (!ui::LatencyInfo::Verify( | 517 if (!ui::LatencyInfo::Verify( |
518 latency_info, "CommandBufferProxyImpl::OnSwapBuffersCompleted")) { | 518 latency_info, "CommandBufferProxyImpl::OnSwapBuffersCompleted")) { |
519 swap_buffers_completion_callback_.Run(std::vector<ui::LatencyInfo>()); | 519 swap_buffers_completion_callback_.Run(std::vector<ui::LatencyInfo>()); |
520 return; | 520 return; |
521 } | 521 } |
522 swap_buffers_completion_callback_.Run(latency_info); | 522 swap_buffers_completion_callback_.Run(latency_info); |
523 } | 523 } |
524 } | 524 } |
525 | 525 |
526 } // namespace content | 526 } // namespace content |
OLD | NEW |