| 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 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 NULL; |
| 309 | 309 |
| 310 int32 new_id = channel_->ReserveGpuMemoryBufferId(); | 310 scoped_ptr<gfx::GpuMemoryBuffer> buffer( |
| 311 DCHECK(gpu_memory_buffers_.find(new_id) == gpu_memory_buffers_.end()); | |
| 312 | |
| 313 scoped_ptr<gfx::GpuMemoryBuffer> gpu_memory_buffer( | |
| 314 channel_->factory()->AllocateGpuMemoryBuffer( | 311 channel_->factory()->AllocateGpuMemoryBuffer( |
| 315 width, height, internalformat, usage)); | 312 width, height, internalformat, usage)); |
| 316 if (!gpu_memory_buffer) | 313 if (!buffer) |
| 317 return NULL; | 314 return NULL; |
| 318 | 315 |
| 319 DCHECK(GpuChannelHost::IsValidGpuMemoryBuffer( | 316 DCHECK(GpuChannelHost::IsValidGpuMemoryBuffer(buffer->GetHandle())); |
| 320 gpu_memory_buffer->GetHandle())); | 317 |
| 318 int32 new_id = channel_->ReserveGpuMemoryBufferId(); |
| 321 | 319 |
| 322 // 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 |
| 323 // 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 |
| 324 // sending of the RegisterGpuMemoryBuffer IPC below. | 322 // sending of the RegisterGpuMemoryBuffer IPC below. |
| 325 gfx::GpuMemoryBufferHandle handle = | 323 gfx::GpuMemoryBufferHandle handle = |
| 326 channel_->ShareGpuMemoryBufferToGpuProcess( | 324 channel_->ShareGpuMemoryBufferToGpuProcess(buffer->GetHandle()); |
| 327 gpu_memory_buffer->GetHandle()); | |
| 328 | 325 |
| 329 if (!Send(new GpuCommandBufferMsg_RegisterGpuMemoryBuffer( | 326 if (!Send(new GpuCommandBufferMsg_RegisterGpuMemoryBuffer( |
| 330 route_id_, | 327 route_id_, |
| 331 new_id, | 328 new_id, |
| 332 handle, | 329 handle, |
| 333 width, | 330 width, |
| 334 height, | 331 height, |
| 335 internalformat))) { | 332 internalformat))) { |
| 336 return NULL; | 333 return NULL; |
| 337 } | 334 } |
| 338 | 335 |
| 339 *id = new_id; | 336 *id = new_id; |
| 340 gpu_memory_buffers_[new_id] = gpu_memory_buffer.release(); | 337 DCHECK(gpu_memory_buffers_.find(new_id) == gpu_memory_buffers_.end()); |
| 341 return gpu_memory_buffers_[new_id]; | 338 return gpu_memory_buffers_.add(new_id, buffer.Pass()).first->second; |
| 342 } | 339 } |
| 343 | 340 |
| 344 void CommandBufferProxyImpl::DestroyGpuMemoryBuffer(int32 id) { | 341 void CommandBufferProxyImpl::DestroyGpuMemoryBuffer(int32 id) { |
| 345 if (last_state_.error != gpu::error::kNoError) | 342 if (last_state_.error != gpu::error::kNoError) |
| 346 return; | 343 return; |
| 347 | 344 |
| 345 Send(new GpuCommandBufferMsg_DestroyGpuMemoryBuffer(route_id_, id)); |
| 346 |
| 348 // Remove the gpu memory buffer from the client side cache. | 347 // Remove the gpu memory buffer from the client side cache. |
| 349 GpuMemoryBufferMap::iterator it = gpu_memory_buffers_.find(id); | 348 gpu_memory_buffers_.erase(id); |
| 350 if (it != gpu_memory_buffers_.end()) { | |
| 351 delete it->second; | |
| 352 gpu_memory_buffers_.erase(it); | |
| 353 } | |
| 354 | |
| 355 Send(new GpuCommandBufferMsg_DestroyGpuMemoryBuffer(route_id_, id)); | |
| 356 } | 349 } |
| 357 | 350 |
| 358 int CommandBufferProxyImpl::GetRouteID() const { | 351 int CommandBufferProxyImpl::GetRouteID() const { |
| 359 return route_id_; | 352 return route_id_; |
| 360 } | 353 } |
| 361 | 354 |
| 362 void CommandBufferProxyImpl::Echo(const base::Closure& callback) { | 355 void CommandBufferProxyImpl::Echo(const base::Closure& callback) { |
| 363 if (last_state_.error != gpu::error::kNoError) { | 356 if (last_state_.error != gpu::error::kNoError) { |
| 364 return; | 357 return; |
| 365 } | 358 } |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 if (last_state_.error == gpu::error::kNoError) | 517 if (last_state_.error == gpu::error::kNoError) |
| 525 shared_state()->Read(&last_state_); | 518 shared_state()->Read(&last_state_); |
| 526 } | 519 } |
| 527 | 520 |
| 528 gpu::CommandBufferSharedState* CommandBufferProxyImpl::shared_state() const { | 521 gpu::CommandBufferSharedState* CommandBufferProxyImpl::shared_state() const { |
| 529 return reinterpret_cast<gpu::CommandBufferSharedState*>( | 522 return reinterpret_cast<gpu::CommandBufferSharedState*>( |
| 530 shared_state_shm_->memory()); | 523 shared_state_shm_->memory()); |
| 531 } | 524 } |
| 532 | 525 |
| 533 } // namespace content | 526 } // namespace content |
| OLD | NEW |