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. |
367 // will leak. In otherwords, do not early out on error between here and the | 364 if (!gpu::ImageFactory::IsImageFormatSupported(internalformat)) { |
reveman
2015/03/18 16:59:00
nit: this is on the child process side so you can
emircan
2015/03/18 23:51:26
Done.
| |
368 // sending of the CreateImage IPC below. | 365 LOG(ERROR) << "Internalformat is not supported."; |
366 return -1; | |
367 } | |
368 | |
369 // Check the buffer count for the given |internalformat| and initialize the | |
370 // vectors where data will be passed. Log and return if the |internalformat| | |
371 // isn't supported. | |
372 size_t num_buffers = | |
373 gpu::ImageFactory::NumberOfPlanesForImageFormat(internalformat); | |
374 std::vector<gfx::GpuMemoryBufferHandle> handles; | |
375 std::vector<gfx::GpuMemoryBuffer::Format> formats; | |
369 bool requires_sync_point = false; | 376 bool requires_sync_point = false; |
370 gfx::GpuMemoryBufferHandle handle = | |
371 channel_->ShareGpuMemoryBufferToGpuProcess(gpu_memory_buffer->GetHandle(), | |
372 &requires_sync_point); | |
373 | 377 |
374 DCHECK(gpu::ImageFactory::IsImageSizeValidForGpuMemoryBufferFormat( | 378 for (size_t i = 0; i < num_buffers; ++i) { |
375 gfx::Size(width, height), gpu_memory_buffer->GetFormat())); | 379 gfx::GpuMemoryBuffer* gpu_memory_buffer = |
376 DCHECK(gpu::ImageFactory::IsImageFormatCompatibleWithGpuMemoryBufferFormat( | 380 gpu_memory_buffer_manager->GpuMemoryBufferFromClientBuffer(buffers[i]); |
377 internalformat, gpu_memory_buffer->GetFormat())); | 381 DCHECK(gpu_memory_buffer); |
382 | |
383 formats.push_back(gpu_memory_buffer->GetFormat()); | |
384 DCHECK(gpu::ImageFactory::IsImageSizeValidForGpuMemoryBufferFormat( | |
385 gfx::Size(width, height), formats[i])); | |
386 DCHECK(gpu::ImageFactory::IsImageFormatCompatibleWithGpuMemoryBufferFormat( | |
387 internalformat, i, formats[i])); | |
388 | |
389 bool buffer_requires_sync_point = false; | |
390 // This handle is owned by the GPU process and must be passed to it or it | |
391 // will leak. In other words, do not early out on error between here and the | |
392 // sending of the CreateImage IPC below. | |
393 handles.push_back(channel_->ShareGpuMemoryBufferToGpuProcess( | |
394 gpu_memory_buffer->GetHandle(), &buffer_requires_sync_point)); | |
395 | |
396 // We set a destruction sync point on all buffers if one happen to require | |
397 // one. | |
398 requires_sync_point |= buffer_requires_sync_point; | |
399 } | |
400 | |
378 if (!Send(new GpuCommandBufferMsg_CreateImage(route_id_, | 401 if (!Send(new GpuCommandBufferMsg_CreateImage(route_id_, |
379 new_id, | 402 new_id, |
380 handle, | 403 handles, |
381 gfx::Size(width, height), | 404 gfx::Size(width, height), |
382 gpu_memory_buffer->GetFormat(), | 405 formats, |
383 internalformat))) { | 406 internalformat))) { |
384 return -1; | 407 return -1; |
385 } | 408 } |
386 | 409 |
410 uint32 sync_point = InsertSyncPoint(); | |
reveman
2015/03/18 16:59:00
Please move this inside the "if (requires_sync_poi
emircan
2015/03/18 23:51:26
Done. Sorry for missing that.
| |
387 if (requires_sync_point) { | 411 if (requires_sync_point) { |
388 gpu_memory_buffer_manager->SetDestructionSyncPoint(gpu_memory_buffer, | 412 for (size_t i = 0; i < num_buffers; ++i) { |
389 InsertSyncPoint()); | 413 gfx::GpuMemoryBuffer* gpu_memory_buffer = |
414 gpu_memory_buffer_manager->GpuMemoryBufferFromClientBuffer( | |
415 buffers[i]); | |
416 gpu_memory_buffer_manager->SetDestructionSyncPoint(gpu_memory_buffer, | |
417 sync_point); | |
418 } | |
390 } | 419 } |
391 | 420 |
392 return new_id; | 421 return new_id; |
393 } | 422 } |
394 | 423 |
395 void CommandBufferProxyImpl::DestroyImage(int32 id) { | 424 void CommandBufferProxyImpl::DestroyImage(int32 id) { |
396 CheckLock(); | 425 CheckLock(); |
397 if (last_state_.error != gpu::error::kNoError) | 426 if (last_state_.error != gpu::error::kNoError) |
398 return; | 427 return; |
399 | 428 |
400 Send(new GpuCommandBufferMsg_DestroyImage(route_id_, id)); | 429 Send(new GpuCommandBufferMsg_DestroyImage(route_id_, id)); |
401 } | 430 } |
402 | 431 |
403 int32_t CommandBufferProxyImpl::CreateGpuMemoryBufferImage( | 432 int32_t CommandBufferProxyImpl::CreateGpuMemoryBufferImage( |
404 size_t width, | 433 size_t width, |
405 size_t height, | 434 size_t height, |
406 unsigned internalformat, | 435 unsigned internalformat, |
407 unsigned usage) { | 436 unsigned usage) { |
408 CheckLock(); | 437 CheckLock(); |
409 scoped_ptr<gfx::GpuMemoryBuffer> buffer( | 438 |
410 channel_->gpu_memory_buffer_manager()->AllocateGpuMemoryBuffer( | 439 size_t num_buffers = |
411 gfx::Size(width, height), | 440 gpu::ImageFactory::NumberOfPlanesForImageFormat(internalformat); |
412 gpu::ImageFactory::ImageFormatToGpuMemoryBufferFormat(internalformat), | 441 if (num_buffers < 1) { |
reveman
2015/03/18 16:59:00
Please DCHECK(gpu::ImageFactory::IsImageFormatSupp
emircan
2015/03/18 23:51:26
Done.
| |
413 gpu::ImageFactory::ImageUsageToGpuMemoryBufferUsage(usage))); | 442 LOG(ERROR) << "Internalformat is not supported."; |
414 if (!buffer) | |
415 return -1; | 443 return -1; |
444 } | |
416 | 445 |
417 return CreateImage(buffer->AsClientBuffer(), width, height, internalformat); | 446 ScopedVector<gfx::GpuMemoryBuffer> buffers; |
447 std::vector<ClientBuffer> client_buffers; | |
448 for (size_t i = 0; i < num_buffers; ++i) { | |
449 gfx::GpuMemoryBuffer::Format format = | |
450 gpu::ImageFactory::ImageFormatToGpuMemoryBufferFormat(internalformat, | |
451 i); | |
452 buffers.push_back( | |
453 channel_->gpu_memory_buffer_manager()->AllocateGpuMemoryBuffer( | |
454 gfx::Size(width, height), format, | |
455 gpu::ImageFactory::ImageUsageToGpuMemoryBufferUsage(usage))); | |
456 if (!buffers[i]) | |
457 return -1; | |
458 | |
459 client_buffers[i] = buffers[i]->AsClientBuffer(); | |
460 } | |
461 return CreateImage(client_buffers.data(), width, height, internalformat); | |
418 } | 462 } |
419 | 463 |
420 int CommandBufferProxyImpl::GetRouteID() const { | 464 int CommandBufferProxyImpl::GetRouteID() const { |
421 return route_id_; | 465 return route_id_; |
422 } | 466 } |
423 | 467 |
424 uint32 CommandBufferProxyImpl::CreateStreamTexture(uint32 texture_id) { | 468 uint32 CommandBufferProxyImpl::CreateStreamTexture(uint32 texture_id) { |
425 CheckLock(); | 469 CheckLock(); |
426 if (last_state_.error != gpu::error::kNoError) | 470 if (last_state_.error != gpu::error::kNoError) |
427 return 0; | 471 return 0; |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
604 } | 648 } |
605 } | 649 } |
606 | 650 |
607 void CommandBufferProxyImpl::OnUpdateVSyncParameters(base::TimeTicks timebase, | 651 void CommandBufferProxyImpl::OnUpdateVSyncParameters(base::TimeTicks timebase, |
608 base::TimeDelta interval) { | 652 base::TimeDelta interval) { |
609 if (!update_vsync_parameters_completion_callback_.is_null()) | 653 if (!update_vsync_parameters_completion_callback_.is_null()) |
610 update_vsync_parameters_completion_callback_.Run(timebase, interval); | 654 update_vsync_parameters_completion_callback_.Run(timebase, interval); |
611 } | 655 } |
612 | 656 |
613 } // namespace content | 657 } // namespace content |
OLD | NEW |