Chromium Code Reviews| 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 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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) { |
|
reveman
2014/07/10 22:33:11
Note: changes to this function and DestroyGpuMemor
| |
| 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 scoped_ptr<gfx::GpuMemoryBuffer> buffer( | |
| 311 channel_->factory()->AllocateGpuMemoryBuffer( | |
| 312 width, height, internalformat, usage)); | |
| 313 if (!buffer) | |
| 314 return NULL; | |
| 315 | |
| 316 DCHECK(GpuChannelHost::IsValidGpuMemoryBuffer(buffer->GetHandle())); | |
| 317 | |
| 310 int32 new_id = channel_->ReserveGpuMemoryBufferId(); | 318 int32 new_id = channel_->ReserveGpuMemoryBufferId(); |
| 311 DCHECK(gpu_memory_buffers_.find(new_id) == gpu_memory_buffers_.end()); | 319 DCHECK(gpu_memory_buffers_.find(new_id) == gpu_memory_buffers_.end()); |
| 312 | 320 |
| 313 scoped_ptr<gfx::GpuMemoryBuffer> gpu_memory_buffer( | |
| 314 channel_->factory()->AllocateGpuMemoryBuffer( | |
| 315 width, height, internalformat, usage)); | |
| 316 if (!gpu_memory_buffer) | |
| 317 return NULL; | |
| 318 | |
| 319 DCHECK(GpuChannelHost::IsValidGpuMemoryBuffer( | |
| 320 gpu_memory_buffer->GetHandle())); | |
| 321 | |
| 322 // This handle is owned by the GPU process and must be passed to it or it | 321 // 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 | 322 // will leak. In otherwords, do not early out on error between here and the |
| 324 // sending of the RegisterGpuMemoryBuffer IPC below. | 323 // sending of the RegisterGpuMemoryBuffer IPC below. |
| 325 gfx::GpuMemoryBufferHandle handle = | 324 gfx::GpuMemoryBufferHandle handle = |
| 326 channel_->ShareGpuMemoryBufferToGpuProcess( | 325 channel_->ShareGpuMemoryBufferToGpuProcess(buffer->GetHandle()); |
| 327 gpu_memory_buffer->GetHandle()); | |
| 328 | 326 |
| 329 if (!Send(new GpuCommandBufferMsg_RegisterGpuMemoryBuffer( | 327 if (!Send(new GpuCommandBufferMsg_RegisterGpuMemoryBuffer( |
| 330 route_id_, | 328 route_id_, |
| 331 new_id, | 329 new_id, |
| 332 handle, | 330 handle, |
| 333 width, | 331 width, |
| 334 height, | 332 height, |
| 335 internalformat))) { | 333 internalformat))) { |
| 336 return NULL; | 334 return NULL; |
| 337 } | 335 } |
| 338 | 336 |
| 339 *id = new_id; | 337 *id = new_id; |
| 340 gpu_memory_buffers_[new_id] = gpu_memory_buffer.release(); | 338 gpu_memory_buffers_.add(new_id, buffer.Pass()); |
| 341 return gpu_memory_buffers_[new_id]; | 339 return gpu_memory_buffers_.get(new_id); |
|
no sievers
2014/07/11 18:33:29
nit: can avoid the lookup here
reveman
2014/07/11 21:08:06
Done.
| |
| 342 } | 340 } |
| 343 | 341 |
| 344 void CommandBufferProxyImpl::DestroyGpuMemoryBuffer(int32 id) { | 342 void CommandBufferProxyImpl::DestroyGpuMemoryBuffer(int32 id) { |
| 345 if (last_state_.error != gpu::error::kNoError) | 343 if (last_state_.error != gpu::error::kNoError) |
| 346 return; | 344 return; |
| 347 | 345 |
| 346 Send(new GpuCommandBufferMsg_DestroyGpuMemoryBuffer(route_id_, id)); | |
| 347 | |
| 348 // Remove the gpu memory buffer from the client side cache. | 348 // Remove the gpu memory buffer from the client side cache. |
| 349 GpuMemoryBufferMap::iterator it = gpu_memory_buffers_.find(id); | 349 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 } | 350 } |
| 357 | 351 |
| 358 int CommandBufferProxyImpl::GetRouteID() const { | 352 int CommandBufferProxyImpl::GetRouteID() const { |
| 359 return route_id_; | 353 return route_id_; |
| 360 } | 354 } |
| 361 | 355 |
| 362 void CommandBufferProxyImpl::Echo(const base::Closure& callback) { | 356 void CommandBufferProxyImpl::Echo(const base::Closure& callback) { |
| 363 if (last_state_.error != gpu::error::kNoError) { | 357 if (last_state_.error != gpu::error::kNoError) { |
| 364 return; | 358 return; |
| 365 } | 359 } |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 524 if (last_state_.error == gpu::error::kNoError) | 518 if (last_state_.error == gpu::error::kNoError) |
| 525 shared_state()->Read(&last_state_); | 519 shared_state()->Read(&last_state_); |
| 526 } | 520 } |
| 527 | 521 |
| 528 gpu::CommandBufferSharedState* CommandBufferProxyImpl::shared_state() const { | 522 gpu::CommandBufferSharedState* CommandBufferProxyImpl::shared_state() const { |
| 529 return reinterpret_cast<gpu::CommandBufferSharedState*>( | 523 return reinterpret_cast<gpu::CommandBufferSharedState*>( |
| 530 shared_state_shm_->memory()); | 524 shared_state_shm_->memory()); |
| 531 } | 525 } |
| 532 | 526 |
| 533 } // namespace content | 527 } // namespace content |
| OLD | NEW |