Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(100)

Side by Side Diff: content/common/gpu/client/command_buffer_proxy_impl.cc

Issue 962723002: Change CHROMIUM_image declarations to support multi planar input. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added implementations of ImageFactory::CreateImageForGpuMemoryBuffers(). Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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. 365 std::vector<gfx::GpuMemoryBufferHandle> handles;
366 handles.reserve(num_buffers);
367 std::vector<gfx::GpuMemoryBuffer::Format> formats;
368 formats.reserve(num_buffers);
369 bool requires_sync_point = false; 369 bool requires_sync_point = false;
370 gfx::GpuMemoryBufferHandle handle =
371 channel_->ShareGpuMemoryBufferToGpuProcess(gpu_memory_buffer->GetHandle(),
372 &requires_sync_point);
373 370
374 DCHECK(gpu::ImageFactory::IsImageSizeValidForGpuMemoryBufferFormat( 371 for (int i = 0; i < num_buffers; ++i) {
375 gfx::Size(width, height), gpu_memory_buffer->GetFormat())); 372 gfx::GpuMemoryBuffer* gpu_memory_buffer =
376 DCHECK(gpu::ImageFactory::IsImageFormatCompatibleWithGpuMemoryBufferFormat( 373 gpu_memory_buffer_manager->GpuMemoryBufferFromClientBuffer(buffers[i]);
377 internalformat, gpu_memory_buffer->GetFormat())); 374 DCHECK(gpu_memory_buffer);
375
376 formats.push_back(gpu_memory_buffer->GetFormat());
377 DCHECK(gpu::ImageFactory::IsImageSizeValidForGpuMemoryBufferFormat(
378 gfx::Size(width, height), formats[i]));
379 DCHECK(gpu::ImageFactory::IsImageFormatCompatibleWithGpuMemoryBufferFormat(
380 internalformat, i, formats[i]));
381
382 bool buffer_requires_sync_point = false;
383 // This handle is owned by the GPU process and must be passed to it or it
384 // will leak. In other words, do not early out on error between here and the
385 // sending of the CreateImage IPC below.
386 handles[i] = channel_->ShareGpuMemoryBufferToGpuProcess(
387 gpu_memory_buffer->GetHandle(), &buffer_requires_sync_point);
388
389 // We want to set a destruction sync point on all buffers if one happen to
390 // require one.
391 requires_sync_point |= buffer_requires_sync_point;
392 }
393
378 if (!Send(new GpuCommandBufferMsg_CreateImage(route_id_, 394 if (!Send(new GpuCommandBufferMsg_CreateImage(route_id_,
379 new_id, 395 new_id,
380 handle, 396 handles,
381 gfx::Size(width, height), 397 gfx::Size(width, height),
382 gpu_memory_buffer->GetFormat(), 398 formats,
383 internalformat))) { 399 internalformat))) {
384 return -1; 400 return -1;
385 } 401 }
386 402
387 if (requires_sync_point) { 403 if (requires_sync_point) {
388 gpu_memory_buffer_manager->SetDestructionSyncPoint(gpu_memory_buffer, 404 for (int i = 0; i < num_buffers; ++i) {
389 InsertSyncPoint()); 405 gfx::GpuMemoryBuffer* gpu_memory_buffer =
406 gpu_memory_buffer_manager->GpuMemoryBufferFromClientBuffer(
407 buffers[i]);
408 gpu_memory_buffer_manager->SetDestructionSyncPoint(gpu_memory_buffer,
409 InsertSyncPoint());
410 }
390 } 411 }
391 412
392 return new_id; 413 return new_id;
393 } 414 }
394 415
395 void CommandBufferProxyImpl::DestroyImage(int32 id) { 416 void CommandBufferProxyImpl::DestroyImage(int32 id) {
396 CheckLock(); 417 CheckLock();
397 if (last_state_.error != gpu::error::kNoError) 418 if (last_state_.error != gpu::error::kNoError)
398 return; 419 return;
399 420
400 Send(new GpuCommandBufferMsg_DestroyImage(route_id_, id)); 421 Send(new GpuCommandBufferMsg_DestroyImage(route_id_, id));
401 } 422 }
402 423
403 int32_t CommandBufferProxyImpl::CreateGpuMemoryBufferImage( 424 int32_t CommandBufferProxyImpl::CreateGpuMemoryBufferImage(
404 size_t width, 425 size_t width,
405 size_t height, 426 size_t height,
406 unsigned internalformat, 427 unsigned internalformat,
407 unsigned usage) { 428 unsigned usage) {
408 CheckLock(); 429 CheckLock();
409 scoped_ptr<gfx::GpuMemoryBuffer> buffer(
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 430
417 return CreateImage(buffer->AsClientBuffer(), width, height, internalformat); 431 int num_buffers =
432 gpu::ImageFactory::GpuMemoryBufferCountForImageFormat(internalformat);
433 DCHECK_GE(num_buffers, 1);
434
435 ScopedVector<gfx::GpuMemoryBuffer> buffers;
436 ClientBuffer client_buffers[num_buffers];
437 for (int i = 0; i < num_buffers; ++i) {
438 gfx::GpuMemoryBuffer::Format format =
439 gpu::ImageFactory::ImageFormatToGpuMemoryBufferFormat(internalformat,
440 i);
441 buffers.push_back(
442 channel_->gpu_memory_buffer_manager()->AllocateGpuMemoryBuffer(
443 gfx::Size(width, height), format,
444 gpu::ImageFactory::ImageUsageToGpuMemoryBufferUsage(usage)));
445
446 if (!buffers[i])
447 return -1;
448
449 client_buffers[i] = buffers[i]->AsClientBuffer();
450 }
451 return CreateImage(client_buffers, width, height, internalformat);
418 } 452 }
419 453
420 int CommandBufferProxyImpl::GetRouteID() const { 454 int CommandBufferProxyImpl::GetRouteID() const {
421 return route_id_; 455 return route_id_;
422 } 456 }
423 457
424 uint32 CommandBufferProxyImpl::CreateStreamTexture(uint32 texture_id) { 458 uint32 CommandBufferProxyImpl::CreateStreamTexture(uint32 texture_id) {
425 CheckLock(); 459 CheckLock();
426 if (last_state_.error != gpu::error::kNoError) 460 if (last_state_.error != gpu::error::kNoError)
427 return 0; 461 return 0;
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
604 } 638 }
605 } 639 }
606 640
607 void CommandBufferProxyImpl::OnUpdateVSyncParameters(base::TimeTicks timebase, 641 void CommandBufferProxyImpl::OnUpdateVSyncParameters(base::TimeTicks timebase,
608 base::TimeDelta interval) { 642 base::TimeDelta interval) {
609 if (!update_vsync_parameters_completion_callback_.is_null()) 643 if (!update_vsync_parameters_completion_callback_.is_null())
610 update_vsync_parameters_completion_callback_.Run(timebase, interval); 644 update_vsync_parameters_completion_callback_.Run(timebase, interval);
611 } 645 }
612 646
613 } // namespace content 647 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698