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 int num_buffers = |
| 367 // will leak. In otherwords, do not early out on error between here and the | 364 gpu::ImageFactory::GpuMemoryBufferCountForImageFormat(internalformat); |
| 368 // sending of the CreateImage IPC below. | |
| 369 bool requires_sync_point = false; | |
| 370 gfx::GpuMemoryBufferHandle handle = | |
| 371 channel_->ShareGpuMemoryBufferToGpuProcess(gpu_memory_buffer->GetHandle(), | |
| 372 &requires_sync_point); | |
| 373 | 365 |
| 374 DCHECK(gpu::ImageFactory::IsImageFormatCompatibleWithGpuMemoryBufferFormat( | 366 gfx::GpuMemoryBuffer* gpu_memory_buffers[num_buffers]; |
|
reveman
2015/03/05 19:35:32
nit: please avoid this array and use a temporary v
emircan
2015/03/09 21:07:22
Done.
| |
| 375 internalformat, gpu_memory_buffer->GetFormat())); | 367 std::vector<gfx::GpuMemoryBufferHandle> handles(num_buffers); |
|
reveman
2015/03/05 19:35:32
nit: I prefer if this is empty initially and inste
emircan
2015/03/09 21:07:22
Done.
| |
| 368 std::vector<gfx::GpuMemoryBuffer::Format> formats(num_buffers); | |
|
reveman
2015/03/05 19:35:32
ditto
emircan
2015/03/09 21:07:22
Done.
| |
| 369 bool requires_sync_point[num_buffers]; | |
|
reveman
2015/03/05 19:35:32
You can skip this array and simply set a destructi
emircan
2015/03/09 21:07:22
Done.
| |
| 370 for (int i = 0; i < num_buffers; ++i) { | |
| 371 gpu_memory_buffers[i] = | |
| 372 gpu_memory_buffer_manager->GpuMemoryBufferFromClientBuffer(buffers[i]); | |
| 373 DCHECK(gpu_memory_buffers[i]); | |
| 374 | |
| 375 formats[i] = gpu_memory_buffers[i]->GetFormat(); | |
| 376 DCHECK(gpu::ImageFactory::IsImageFormatCompatibleWithGpuMemoryBufferFormat( | |
| 377 internalformat, formats[i])); | |
| 378 | |
| 379 requires_sync_point[i] = false; | |
| 380 | |
| 381 // This handle is owned by the GPU process and must be passed to it or it | |
| 382 // will leak. In other words, do not early out on error between here and the | |
| 383 // sending of the CreateImage IPC below. | |
| 384 handles[i] = channel_->ShareGpuMemoryBufferToGpuProcess( | |
| 385 gpu_memory_buffers[i]->GetHandle(), &requires_sync_point[i]); | |
| 386 } | |
| 387 | |
| 376 if (!Send(new GpuCommandBufferMsg_CreateImage(route_id_, | 388 if (!Send(new GpuCommandBufferMsg_CreateImage(route_id_, |
| 377 new_id, | 389 new_id, |
| 378 handle, | 390 handles, |
| 379 gfx::Size(width, height), | 391 gfx::Size(width, height), |
| 380 gpu_memory_buffer->GetFormat(), | 392 formats, |
| 381 internalformat))) { | 393 internalformat))) { |
| 382 return -1; | 394 return -1; |
| 383 } | 395 } |
| 384 | 396 |
| 385 if (requires_sync_point) { | 397 for (int i = 0; i < num_buffers; ++i) { |
| 386 gpu_memory_buffer_manager->SetDestructionSyncPoint(gpu_memory_buffer, | 398 if (requires_sync_point[i]) { |
| 387 InsertSyncPoint()); | 399 gpu_memory_buffer_manager->SetDestructionSyncPoint(gpu_memory_buffers[i], |
| 400 InsertSyncPoint()); | |
|
reveman
2015/03/05 19:35:32
Each sync point has a significant cost. Please avo
emircan
2015/03/09 21:07:22
Done.
| |
| 401 } | |
| 388 } | 402 } |
| 389 | 403 |
| 390 return new_id; | 404 return new_id; |
| 391 } | 405 } |
| 392 | 406 |
| 393 void CommandBufferProxyImpl::DestroyImage(int32 id) { | 407 void CommandBufferProxyImpl::DestroyImage(int32 id) { |
| 394 CheckLock(); | 408 CheckLock(); |
| 395 if (last_state_.error != gpu::error::kNoError) | 409 if (last_state_.error != gpu::error::kNoError) |
| 396 return; | 410 return; |
| 397 | 411 |
| 398 Send(new GpuCommandBufferMsg_DestroyImage(route_id_, id)); | 412 Send(new GpuCommandBufferMsg_DestroyImage(route_id_, id)); |
| 399 } | 413 } |
| 400 | 414 |
| 401 int32_t CommandBufferProxyImpl::CreateGpuMemoryBufferImage( | 415 int32_t CommandBufferProxyImpl::CreateGpuMemoryBufferImage( |
| 402 size_t width, | 416 size_t width, |
| 403 size_t height, | 417 size_t height, |
| 404 unsigned internalformat, | 418 unsigned internalformat, |
| 405 unsigned usage) { | 419 unsigned usage) { |
| 406 CheckLock(); | 420 CheckLock(); |
| 407 scoped_ptr<gfx::GpuMemoryBuffer> buffer( | |
| 408 channel_->gpu_memory_buffer_manager()->AllocateGpuMemoryBuffer( | |
| 409 gfx::Size(width, height), | |
| 410 gpu::ImageFactory::ImageFormatToGpuMemoryBufferFormat(internalformat), | |
| 411 gpu::ImageFactory::ImageUsageToGpuMemoryBufferUsage(usage))); | |
| 412 if (!buffer) | |
| 413 return -1; | |
| 414 | 421 |
| 415 return CreateImage(buffer->AsClientBuffer(), width, height, internalformat); | 422 std::vector<gfx::GpuMemoryBuffer::Format> gpu_memory_buffer_formats; |
| 423 gpu::ImageFactory::ImageFormatToGpuMemoryBufferFormats( | |
|
reveman
2015/03/05 19:35:32
If you had a gpu::ImageFactory::ImageFormatToGpuMe
emircan
2015/03/09 21:07:22
Done.
| |
| 424 internalformat, &gpu_memory_buffer_formats); | |
| 425 int num_buffers = gpu_memory_buffer_formats.size(); | |
|
reveman
2015/03/05 19:35:32
I prefer if you use gpu::ImageFactory::GpuMemoryBu
emircan
2015/03/09 21:07:22
Done.
| |
| 426 | |
| 427 DCHECK_GE(num_buffers, 1); | |
| 428 | |
| 429 ScopedVector<gfx::GpuMemoryBuffer> buffers; | |
| 430 ClientBuffer client_buffers[num_buffers]; | |
| 431 for (int i = 0; i < num_buffers; ++i) { | |
| 432 buffers.push_back( | |
| 433 channel_->gpu_memory_buffer_manager()->AllocateGpuMemoryBuffer( | |
| 434 gfx::Size(width, height), gpu_memory_buffer_formats[i], | |
| 435 gpu::ImageFactory::ImageUsageToGpuMemoryBufferUsage(usage))); | |
| 436 | |
| 437 if (!buffers[i]) | |
| 438 return -1; | |
| 439 | |
| 440 client_buffers[i] = buffers[i]->AsClientBuffer(); | |
| 441 } | |
| 442 return CreateImage(client_buffers, width, height, internalformat); | |
| 416 } | 443 } |
| 417 | 444 |
| 418 int CommandBufferProxyImpl::GetRouteID() const { | 445 int CommandBufferProxyImpl::GetRouteID() const { |
| 419 return route_id_; | 446 return route_id_; |
| 420 } | 447 } |
| 421 | 448 |
| 422 uint32 CommandBufferProxyImpl::CreateStreamTexture(uint32 texture_id) { | 449 uint32 CommandBufferProxyImpl::CreateStreamTexture(uint32 texture_id) { |
| 423 CheckLock(); | 450 CheckLock(); |
| 424 if (last_state_.error != gpu::error::kNoError) | 451 if (last_state_.error != gpu::error::kNoError) |
| 425 return 0; | 452 return 0; |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 602 } | 629 } |
| 603 } | 630 } |
| 604 | 631 |
| 605 void CommandBufferProxyImpl::OnUpdateVSyncParameters(base::TimeTicks timebase, | 632 void CommandBufferProxyImpl::OnUpdateVSyncParameters(base::TimeTicks timebase, |
| 606 base::TimeDelta interval) { | 633 base::TimeDelta interval) { |
| 607 if (!update_vsync_parameters_completion_callback_.is_null()) | 634 if (!update_vsync_parameters_completion_callback_.is_null()) |
| 608 update_vsync_parameters_completion_callback_.Run(timebase, interval); | 635 update_vsync_parameters_completion_callback_.Run(timebase, interval); |
| 609 } | 636 } |
| 610 | 637 |
| 611 } // namespace content | 638 } // namespace content |
| OLD | NEW |