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]; |
375 internalformat, gpu_memory_buffer->GetFormat())); | 367 gfx::GpuMemoryBufferHandle* handles[num_buffers]; |
reveman
2015/03/04 05:56:00
A pointer to a handle is different from before. I
emircan
2015/03/04 23:31:50
Changed it std::vector<gfx::GpuMemoryBufferHandle>
| |
368 gfx::GpuMemoryBuffer::Format formats[num_buffers]; | |
369 bool requires_sync_point[num_buffers]; | |
370 for (int i = 0; i < num_buffers; ++i) { | |
371 gpu_memory_buffers[i] = | |
372 gpu_memory_buffer_manager->GpuMemoryBufferFromClientBuffer(buffers[0]); | |
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, |
reveman
2015/03/04 05:56:00
This doesn't work. You can't pass pointers over IP
emircan
2015/03/04 23:31:50
Changed it std::vector<gfx::GpuMemoryBufferHandle>
| |
379 gfx::Size(width, height), | 391 gfx::Size(width, height), |
380 gpu_memory_buffer->GetFormat(), | 392 formats, |
reveman
2015/03/04 05:56:00
ditto
emircan
2015/03/04 23:31:50
Changed it std::vector<gfx::GpuMemoryBuffer::Forma
| |
381 internalformat))) { | 393 internalformat))) { |
382 return -1; | 394 return -1; |
383 } | 395 } |
384 | 396 |
385 if (requires_sync_point) { | 397 for (size_t 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()); | |
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( | |
424 internalformat, &gpu_memory_buffer_formats); | |
425 int num_buffers = gpu_memory_buffer_formats.size(); | |
426 | |
427 DCHECK_GE(num_buffers, 1); | |
reveman
2015/03/04 05:56:00
if we're going to assume one buffer here, why deal
emircan
2015/03/04 23:31:50
We assume >=1 buffer.
I tried to account for the
reveman
2015/03/05 19:35:31
Sorry, misread that DCHECK.
| |
428 DCHECK(channel_->gpu_memory_buffer_manager()); | |
reveman
2015/03/04 05:56:00
any reason for adding this DCHECK? doesn't look li
emircan
2015/03/04 23:31:50
Removed.
| |
429 | |
430 ScopedVector<gfx::GpuMemoryBuffer> buffers; | |
431 ClientBuffer client_buffers[num_buffers]; | |
432 for (int i = 0; i < num_buffers; ++i) { | |
433 buffers.push_back( | |
434 channel_->gpu_memory_buffer_manager()->AllocateGpuMemoryBuffer( | |
435 gfx::Size(width, height), gpu_memory_buffer_formats[i], | |
436 gpu::ImageFactory::ImageUsageToGpuMemoryBufferUsage(usage))); | |
437 | |
438 if (!buffers[i]) | |
439 return -1; | |
440 | |
441 client_buffers[i] = buffers[i]->AsClientBuffer(); | |
442 } | |
443 return CreateImage(client_buffers, width, height, internalformat); | |
416 } | 444 } |
417 | 445 |
418 int CommandBufferProxyImpl::GetRouteID() const { | 446 int CommandBufferProxyImpl::GetRouteID() const { |
419 return route_id_; | 447 return route_id_; |
420 } | 448 } |
421 | 449 |
422 uint32 CommandBufferProxyImpl::CreateStreamTexture(uint32 texture_id) { | 450 uint32 CommandBufferProxyImpl::CreateStreamTexture(uint32 texture_id) { |
423 CheckLock(); | 451 CheckLock(); |
424 if (last_state_.error != gpu::error::kNoError) | 452 if (last_state_.error != gpu::error::kNoError) |
425 return 0; | 453 return 0; |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
602 } | 630 } |
603 } | 631 } |
604 | 632 |
605 void CommandBufferProxyImpl::OnUpdateVSyncParameters(base::TimeTicks timebase, | 633 void CommandBufferProxyImpl::OnUpdateVSyncParameters(base::TimeTicks timebase, |
606 base::TimeDelta interval) { | 634 base::TimeDelta interval) { |
607 if (!update_vsync_parameters_completion_callback_.is_null()) | 635 if (!update_vsync_parameters_completion_callback_.is_null()) |
608 update_vsync_parameters_completion_callback_.Run(timebase, interval); | 636 update_vsync_parameters_completion_callback_.Run(timebase, interval); |
609 } | 637 } |
610 | 638 |
611 } // namespace content | 639 } // namespace content |
OLD | NEW |