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/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/memory/shared_memory.h" | 9 #include "base/memory/shared_memory.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 340 if (last_state_.error != gpu::error::kNoError) | 340 if (last_state_.error != gpu::error::kNoError) |
| 341 return; | 341 return; |
| 342 | 342 |
| 343 Send(new GpuCommandBufferMsg_DestroyTransferBuffer(route_id_, id)); | 343 Send(new GpuCommandBufferMsg_DestroyTransferBuffer(route_id_, id)); |
| 344 } | 344 } |
| 345 | 345 |
| 346 gpu::Capabilities CommandBufferProxyImpl::GetCapabilities() { | 346 gpu::Capabilities CommandBufferProxyImpl::GetCapabilities() { |
| 347 return capabilities_; | 347 return capabilities_; |
| 348 } | 348 } |
| 349 | 349 |
| 350 int32_t CommandBufferProxyImpl::CreateImage(ClientBuffer buffer, | 350 int32_t CommandBufferProxyImpl::CreateImage(ClientBuffer* const buffers, |
| 351 size_t width, | 351 size_t width, |
| 352 size_t height, | 352 size_t height, |
| 353 unsigned internalformat) { | 353 unsigned internalformat) { |
| 354 CheckLock(); | 354 CheckLock(); |
| 355 if (last_state_.error != gpu::error::kNoError) | 355 if (last_state_.error != gpu::error::kNoError) |
| 356 return -1; | 356 return -1; |
| 357 | 357 |
| 358 int32 new_id = channel_->ReserveImageId(); | 358 int32 new_id = channel_->ReserveImageId(); |
| 359 | 359 |
| 360 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager = | 360 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager = |
| 361 channel_->gpu_memory_buffer_manager(); | 361 channel_->gpu_memory_buffer_manager(); |
| 362 gfx::GpuMemoryBuffer* gpu_memory_buffer = | |
| 363 gpu_memory_buffer_manager->GpuMemoryBufferFromClientBuffer(buffer); | |
| 364 DCHECK(gpu_memory_buffer); | |
| 365 | 362 |
| 366 // This handle is owned by the GPU process and must be passed to it or it | 363 // Log and return if the |internalformat| isn't supported. |
|
reveman
2015/03/19 15:39:45
This comment is incorrect
| |
| 367 // will leak. In otherwords, do not early out on error between here and the | 364 DCHECK(gpu::ImageFactory::IsImageFormatSupported(internalformat)); |
| 368 // sending of the CreateImage IPC below. | 365 |
| 366 // Check the buffer count for the given |internalformat| and initialize the | |
| 367 // vectors where data will be passed. Log and return if the |internalformat| | |
| 368 // isn't supported. | |
|
reveman
2015/03/19 15:39:45
Log and return... ? Please update comment
| |
| 369 size_t num_buffers = | |
| 370 gpu::ImageFactory::NumberOfPlanesForImageFormat(internalformat); | |
| 371 std::vector<gfx::GpuMemoryBufferHandle> handles; | |
| 372 std::vector<gfx::GpuMemoryBuffer::Format> formats; | |
| 369 bool requires_sync_point = false; | 373 bool requires_sync_point = false; |
| 370 gfx::GpuMemoryBufferHandle handle = | |
| 371 channel_->ShareGpuMemoryBufferToGpuProcess(gpu_memory_buffer->GetHandle(), | |
| 372 &requires_sync_point); | |
| 373 | 374 |
| 374 DCHECK(gpu::ImageFactory::IsImageSizeValidForGpuMemoryBufferFormat( | 375 for (size_t i = 0; i < num_buffers; ++i) { |
| 375 gfx::Size(width, height), gpu_memory_buffer->GetFormat())); | 376 gfx::GpuMemoryBuffer* gpu_memory_buffer = |
| 376 DCHECK(gpu::ImageFactory::IsImageFormatCompatibleWithGpuMemoryBufferFormat( | 377 gpu_memory_buffer_manager->GpuMemoryBufferFromClientBuffer(buffers[i]); |
| 377 internalformat, gpu_memory_buffer->GetFormat())); | 378 DCHECK(gpu_memory_buffer); |
| 379 | |
| 380 formats.push_back(gpu_memory_buffer->GetFormat()); | |
| 381 DCHECK(gpu::ImageFactory::IsImageSizeValidForGpuMemoryBufferFormat( | |
| 382 gfx::Size(width, height), formats[i])); | |
| 383 DCHECK(gpu::ImageFactory::IsImageFormatCompatibleWithGpuMemoryBufferFormat( | |
| 384 internalformat, i, formats[i])); | |
| 385 | |
| 386 bool buffer_requires_sync_point = false; | |
| 387 // This handle is owned by the GPU process and must be passed to it or it | |
| 388 // will leak. In other words, do not early out on error between here and the | |
| 389 // sending of the CreateImage IPC below. | |
| 390 handles.push_back(channel_->ShareGpuMemoryBufferToGpuProcess( | |
| 391 gpu_memory_buffer->GetHandle(), &buffer_requires_sync_point)); | |
| 392 | |
| 393 // We set a destruction sync point on all buffers if one happen to require | |
| 394 // one. | |
| 395 requires_sync_point |= buffer_requires_sync_point; | |
| 396 } | |
| 397 | |
| 378 if (!Send(new GpuCommandBufferMsg_CreateImage(route_id_, | 398 if (!Send(new GpuCommandBufferMsg_CreateImage(route_id_, |
| 379 new_id, | 399 new_id, |
| 380 handle, | 400 handles, |
| 381 gfx::Size(width, height), | 401 gfx::Size(width, height), |
| 382 gpu_memory_buffer->GetFormat(), | 402 formats, |
| 383 internalformat))) { | 403 internalformat))) { |
| 384 return -1; | 404 return -1; |
| 385 } | 405 } |
| 386 | 406 |
| 387 if (requires_sync_point) { | 407 if (requires_sync_point) { |
| 388 gpu_memory_buffer_manager->SetDestructionSyncPoint(gpu_memory_buffer, | 408 uint32 sync_point = InsertSyncPoint(); |
| 389 InsertSyncPoint()); | 409 for (size_t i = 0; i < num_buffers; ++i) { |
| 410 gfx::GpuMemoryBuffer* gpu_memory_buffer = | |
| 411 gpu_memory_buffer_manager->GpuMemoryBufferFromClientBuffer( | |
| 412 buffers[i]); | |
| 413 gpu_memory_buffer_manager->SetDestructionSyncPoint(gpu_memory_buffer, | |
| 414 sync_point); | |
| 415 } | |
| 390 } | 416 } |
| 391 | 417 |
| 392 return new_id; | 418 return new_id; |
| 393 } | 419 } |
| 394 | 420 |
| 395 void CommandBufferProxyImpl::DestroyImage(int32 id) { | 421 void CommandBufferProxyImpl::DestroyImage(int32 id) { |
| 396 CheckLock(); | 422 CheckLock(); |
| 397 if (last_state_.error != gpu::error::kNoError) | 423 if (last_state_.error != gpu::error::kNoError) |
| 398 return; | 424 return; |
| 399 | 425 |
| 400 Send(new GpuCommandBufferMsg_DestroyImage(route_id_, id)); | 426 Send(new GpuCommandBufferMsg_DestroyImage(route_id_, id)); |
| 401 } | 427 } |
| 402 | 428 |
| 403 int32_t CommandBufferProxyImpl::CreateGpuMemoryBufferImage( | 429 int32_t CommandBufferProxyImpl::CreateGpuMemoryBufferImage( |
| 404 size_t width, | 430 size_t width, |
| 405 size_t height, | 431 size_t height, |
| 406 unsigned internalformat, | 432 unsigned internalformat, |
| 407 unsigned usage) { | 433 unsigned usage) { |
| 408 CheckLock(); | 434 CheckLock(); |
| 409 scoped_ptr<gfx::GpuMemoryBuffer> buffer( | 435 DCHECK(gpu::ImageFactory::IsImageFormatSupported(internalformat)); |
| 410 channel_->gpu_memory_buffer_manager()->AllocateGpuMemoryBuffer( | |
| 411 gfx::Size(width, height), | |
| 412 gpu::ImageFactory::ImageFormatToGpuMemoryBufferFormat(internalformat), | |
| 413 gpu::ImageFactory::ImageUsageToGpuMemoryBufferUsage(usage))); | |
| 414 if (!buffer) | |
| 415 return -1; | |
| 416 | 436 |
| 417 return CreateImage(buffer->AsClientBuffer(), width, height, internalformat); | 437 size_t num_buffers = |
| 438 gpu::ImageFactory::NumberOfPlanesForImageFormat(internalformat); | |
| 439 ScopedVector<gfx::GpuMemoryBuffer> buffers; | |
| 440 std::vector<ClientBuffer> client_buffers; | |
| 441 | |
| 442 for (size_t i = 0; i < num_buffers; ++i) { | |
| 443 gfx::GpuMemoryBuffer::Format format = | |
| 444 gpu::ImageFactory::ImageFormatToGpuMemoryBufferFormat(internalformat, | |
| 445 i); | |
| 446 buffers.push_back( | |
| 447 channel_->gpu_memory_buffer_manager()->AllocateGpuMemoryBuffer( | |
| 448 gfx::Size(width, height), format, | |
| 449 gpu::ImageFactory::ImageUsageToGpuMemoryBufferUsage(usage))); | |
| 450 if (!buffers[i]) | |
| 451 return -1; | |
| 452 | |
| 453 client_buffers[i] = buffers[i]->AsClientBuffer(); | |
| 454 } | |
| 455 return CreateImage(client_buffers.data(), width, height, internalformat); | |
| 418 } | 456 } |
| 419 | 457 |
| 420 int CommandBufferProxyImpl::GetRouteID() const { | 458 int CommandBufferProxyImpl::GetRouteID() const { |
| 421 return route_id_; | 459 return route_id_; |
| 422 } | 460 } |
| 423 | 461 |
| 424 uint32 CommandBufferProxyImpl::CreateStreamTexture(uint32 texture_id) { | 462 uint32 CommandBufferProxyImpl::CreateStreamTexture(uint32 texture_id) { |
| 425 CheckLock(); | 463 CheckLock(); |
| 426 if (last_state_.error != gpu::error::kNoError) | 464 if (last_state_.error != gpu::error::kNoError) |
| 427 return 0; | 465 return 0; |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 604 } | 642 } |
| 605 } | 643 } |
| 606 | 644 |
| 607 void CommandBufferProxyImpl::OnUpdateVSyncParameters(base::TimeTicks timebase, | 645 void CommandBufferProxyImpl::OnUpdateVSyncParameters(base::TimeTicks timebase, |
| 608 base::TimeDelta interval) { | 646 base::TimeDelta interval) { |
| 609 if (!update_vsync_parameters_completion_callback_.is_null()) | 647 if (!update_vsync_parameters_completion_callback_.is_null()) |
| 610 update_vsync_parameters_completion_callback_.Run(timebase, interval); | 648 update_vsync_parameters_completion_callback_.Run(timebase, interval); |
| 611 } | 649 } |
| 612 | 650 |
| 613 } // namespace content | 651 } // namespace content |
| OLD | NEW |