| 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 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 NOTREACHED(); | 360 NOTREACHED(); |
| 361 } | 361 } |
| 362 | 362 |
| 363 void CommandBufferProxyImpl::SetContextLostReason( | 363 void CommandBufferProxyImpl::SetContextLostReason( |
| 364 gpu::error::ContextLostReason reason) { | 364 gpu::error::ContextLostReason reason) { |
| 365 // Not implemented in proxy. | 365 // Not implemented in proxy. |
| 366 NOTREACHED(); | 366 NOTREACHED(); |
| 367 } | 367 } |
| 368 | 368 |
| 369 bool CommandBufferProxyImpl::SupportsGpuMemoryBuffer() { | 369 bool CommandBufferProxyImpl::SupportsGpuMemoryBuffer() { |
| 370 return false; | 370 return true; |
| 371 } | 371 } |
| 372 | 372 |
| 373 gfx::GpuMemoryBuffer* CommandBufferProxyImpl::CreateGpuMemoryBuffer( | 373 gfx::GpuMemoryBuffer* CommandBufferProxyImpl::CreateGpuMemoryBuffer( |
| 374 size_t width, | 374 size_t width, |
| 375 size_t height, | 375 size_t height, |
| 376 unsigned internalformat, | 376 unsigned internalformat, |
| 377 int32* id) { | 377 int32* id) { |
| 378 NOTREACHED(); | 378 *id = -1; |
| 379 return NULL; | 379 |
| 380 if (last_state_.error != gpu::error::kNoError) |
| 381 return NULL; |
| 382 |
| 383 int32 new_id = channel_->ReserveGpuMemoryBufferId(); |
| 384 DCHECK(gpu_memory_buffers_.find(new_id) == gpu_memory_buffers_.end()); |
| 385 |
| 386 scoped_ptr<gfx::GpuMemoryBuffer> gpu_memory_buffer( |
| 387 channel_->factory()->AllocateGpuMemoryBuffer(width, |
| 388 height, |
| 389 internalformat)); |
| 390 if (!gpu_memory_buffer) |
| 391 return NULL; |
| 392 |
| 393 DCHECK(GpuChannelHost::IsValidGpuMemoryBuffer( |
| 394 gpu_memory_buffer->GetHandle())); |
| 395 |
| 396 // This handle is owned by the GPU process and must be passed to it or it |
| 397 // will leak. In otherwords, do not early out on error between here and the |
| 398 // sending of the RegisterGpuMemoryBuffer IPC below. |
| 399 gfx::GpuMemoryBufferHandle handle = |
| 400 channel_->ShareGpuMemoryBufferToGpuProcess( |
| 401 gpu_memory_buffer->GetHandle()); |
| 402 |
| 403 if (!Send(new GpuCommandBufferMsg_RegisterGpuMemoryBuffer( |
| 404 route_id_, |
| 405 new_id, |
| 406 handle, |
| 407 width, |
| 408 height, |
| 409 internalformat))) { |
| 410 return NULL; |
| 411 } |
| 412 |
| 413 *id = new_id; |
| 414 gpu_memory_buffers_[new_id] = gpu_memory_buffer.release(); |
| 415 return gpu_memory_buffers_[new_id]; |
| 380 } | 416 } |
| 381 | 417 |
| 382 void CommandBufferProxyImpl::DestroyGpuMemoryBuffer(int32 id) { | 418 void CommandBufferProxyImpl::DestroyGpuMemoryBuffer(int32 id) { |
| 383 NOTREACHED(); | 419 if (last_state_.error != gpu::error::kNoError) |
| 420 return; |
| 421 |
| 422 // Remove the gpu memory buffer from the client side cache. |
| 423 GpuMemoryBufferMap::iterator it = gpu_memory_buffers_.find(id); |
| 424 if (it != gpu_memory_buffers_.end()) { |
| 425 delete it->second; |
| 426 gpu_memory_buffers_.erase(it); |
| 427 } |
| 428 |
| 429 Send(new GpuCommandBufferMsg_DestroyGpuMemoryBuffer(route_id_, id)); |
| 384 } | 430 } |
| 385 | 431 |
| 386 int CommandBufferProxyImpl::GetRouteID() const { | 432 int CommandBufferProxyImpl::GetRouteID() const { |
| 387 return route_id_; | 433 return route_id_; |
| 388 } | 434 } |
| 389 | 435 |
| 390 bool CommandBufferProxyImpl::Echo(const base::Closure& callback) { | 436 bool CommandBufferProxyImpl::Echo(const base::Closure& callback) { |
| 391 if (last_state_.error != gpu::error::kNoError) { | 437 if (last_state_.error != gpu::error::kNoError) { |
| 392 return false; | 438 return false; |
| 393 } | 439 } |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 558 void CommandBufferProxyImpl::SendManagedMemoryStats( | 604 void CommandBufferProxyImpl::SendManagedMemoryStats( |
| 559 const GpuManagedMemoryStats& stats) { | 605 const GpuManagedMemoryStats& stats) { |
| 560 if (last_state_.error != gpu::error::kNoError) | 606 if (last_state_.error != gpu::error::kNoError) |
| 561 return; | 607 return; |
| 562 | 608 |
| 563 Send(new GpuCommandBufferMsg_SendClientManagedMemoryStats(route_id_, | 609 Send(new GpuCommandBufferMsg_SendClientManagedMemoryStats(route_id_, |
| 564 stats)); | 610 stats)); |
| 565 } | 611 } |
| 566 | 612 |
| 567 } // namespace content | 613 } // namespace content |
| OLD | NEW |