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 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 } | 304 } |
305 | 305 |
306 gpu::Capabilities CommandBufferProxyImpl::GetCapabilities() { | 306 gpu::Capabilities CommandBufferProxyImpl::GetCapabilities() { |
307 return capabilities_; | 307 return capabilities_; |
308 } | 308 } |
309 | 309 |
310 gfx::GpuMemoryBuffer* CommandBufferProxyImpl::CreateGpuMemoryBuffer( | 310 gfx::GpuMemoryBuffer* CommandBufferProxyImpl::CreateGpuMemoryBuffer( |
311 size_t width, | 311 size_t width, |
312 size_t height, | 312 size_t height, |
313 unsigned internalformat, | 313 unsigned internalformat, |
| 314 gfx::GpuMemoryBuffer::Usage usage, |
314 int32* id) { | 315 int32* id) { |
315 *id = -1; | 316 *id = -1; |
316 | 317 |
317 if (last_state_.error != gpu::error::kNoError) | 318 if (last_state_.error != gpu::error::kNoError) |
318 return NULL; | 319 return NULL; |
319 | 320 |
320 int32 new_id = channel_->ReserveGpuMemoryBufferId(); | 321 int32 new_id = channel_->ReserveGpuMemoryBufferId(); |
321 DCHECK(gpu_memory_buffers_.find(new_id) == gpu_memory_buffers_.end()); | 322 DCHECK(gpu_memory_buffers_.find(new_id) == gpu_memory_buffers_.end()); |
322 | 323 |
323 scoped_ptr<gfx::GpuMemoryBuffer> gpu_memory_buffer( | 324 scoped_ptr<gfx::GpuMemoryBuffer> gpu_memory_buffer( |
324 channel_->factory()->AllocateGpuMemoryBuffer(width, | 325 channel_->factory()->AllocateGpuMemoryBuffer( |
325 height, | 326 width, height, internalformat, usage)); |
326 internalformat)); | |
327 if (!gpu_memory_buffer) | 327 if (!gpu_memory_buffer) |
328 return NULL; | 328 return NULL; |
329 | 329 |
330 DCHECK(GpuChannelHost::IsValidGpuMemoryBuffer( | 330 DCHECK(GpuChannelHost::IsValidGpuMemoryBuffer( |
331 gpu_memory_buffer->GetHandle())); | 331 gpu_memory_buffer->GetHandle())); |
332 | 332 |
333 // This handle is owned by the GPU process and must be passed to it or it | 333 // This handle is owned by the GPU process and must be passed to it or it |
334 // will leak. In otherwords, do not early out on error between here and the | 334 // will leak. In otherwords, do not early out on error between here and the |
335 // sending of the RegisterGpuMemoryBuffer IPC below. | 335 // sending of the RegisterGpuMemoryBuffer IPC below. |
336 gfx::GpuMemoryBufferHandle handle = | 336 gfx::GpuMemoryBufferHandle handle = |
337 channel_->ShareGpuMemoryBufferToGpuProcess( | 337 channel_->ShareGpuMemoryBufferToGpuProcess( |
338 gpu_memory_buffer->GetHandle()); | 338 gpu_memory_buffer->GetHandle()); |
339 | 339 |
340 if (!Send(new GpuCommandBufferMsg_RegisterGpuMemoryBuffer( | 340 GpuCommandBufferMsg_RegisterGpuMemoryBuffer_Params params; |
341 route_id_, | 341 params.id = new_id; |
342 new_id, | 342 params.gpu_memory_buffer = handle; |
343 handle, | 343 params.width = width; |
344 width, | 344 params.height = height; |
345 height, | 345 params.internalformat = internalformat; |
346 internalformat))) { | 346 params.usage = usage; |
| 347 |
| 348 if (!Send( |
| 349 new GpuCommandBufferMsg_RegisterGpuMemoryBuffer(route_id_, params))) { |
347 return NULL; | 350 return NULL; |
348 } | 351 } |
349 | 352 |
350 *id = new_id; | 353 *id = new_id; |
351 gpu_memory_buffers_[new_id] = gpu_memory_buffer.release(); | 354 gpu_memory_buffers_[new_id] = gpu_memory_buffer.release(); |
352 return gpu_memory_buffers_[new_id]; | 355 return gpu_memory_buffers_[new_id]; |
353 } | 356 } |
354 | 357 |
355 void CommandBufferProxyImpl::DestroyGpuMemoryBuffer(int32 id) { | 358 void CommandBufferProxyImpl::DestroyGpuMemoryBuffer(int32 id) { |
356 if (last_state_.error != gpu::error::kNoError) | 359 if (last_state_.error != gpu::error::kNoError) |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
524 if (last_state_.error == gpu::error::kNoError) | 527 if (last_state_.error == gpu::error::kNoError) |
525 shared_state()->Read(&last_state_); | 528 shared_state()->Read(&last_state_); |
526 } | 529 } |
527 | 530 |
528 gpu::CommandBufferSharedState* CommandBufferProxyImpl::shared_state() const { | 531 gpu::CommandBufferSharedState* CommandBufferProxyImpl::shared_state() const { |
529 return reinterpret_cast<gpu::CommandBufferSharedState*>( | 532 return reinterpret_cast<gpu::CommandBufferSharedState*>( |
530 shared_state_shm_->memory()); | 533 shared_state_shm_->memory()); |
531 } | 534 } |
532 | 535 |
533 } // namespace content | 536 } // namespace content |
OLD | NEW |