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

Side by Side Diff: media/video/gpu_memory_buffer_video_frame_pool.cc

Issue 1412223009: Reland: GpuMemoryBuffer interface change: Map(**) to Map() and memory(plane); stride(plane) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Win X64 compile fix Created 5 years, 2 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
« no previous file with comments | « media/renderers/mock_gpu_video_accelerator_factories.cc ('k') | ui/gfx/buffer_format_util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "media/video/gpu_memory_buffer_video_frame_pool.h" 5 #include "media/video/gpu_memory_buffer_video_frame_pool.h"
6 6
7 #include <GLES2/gl2.h> 7 #include <GLES2/gl2.h>
8 #include <GLES2/gl2ext.h> 8 #include <GLES2/gl2ext.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 const size_t planes_per_copy = PlanesPerCopy(output_format_); 429 const size_t planes_per_copy = PlanesPerCopy(output_format_);
430 const gfx::Size size = video_frame->visible_rect().size(); 430 const gfx::Size size = video_frame->visible_rect().size();
431 size_t copies = 0; 431 size_t copies = 0;
432 for (size_t i = 0; i < num_planes; i += planes_per_copy) { 432 for (size_t i = 0; i < num_planes; i += planes_per_copy) {
433 const int rows = VideoFrame::Rows(i, output_format_, size.height()); 433 const int rows = VideoFrame::Rows(i, output_format_, size.height());
434 const int rows_per_copy = RowsPerCopy(i, output_format_, size.width()); 434 const int rows_per_copy = RowsPerCopy(i, output_format_, size.width());
435 copies += rows / rows_per_copy; 435 copies += rows / rows_per_copy;
436 if (rows % rows_per_copy) 436 if (rows % rows_per_copy)
437 ++copies; 437 ++copies;
438 } 438 }
439 base::Closure copies_done = 439 const base::Closure copies_done =
440 base::Bind(&PoolImpl::OnCopiesDone, this, video_frame, frame_resources, 440 base::Bind(&PoolImpl::OnCopiesDone, this, video_frame, frame_resources,
441 frame_ready_cb); 441 frame_ready_cb);
442 base::Closure barrier = base::BarrierClosure(copies, copies_done); 442 const base::Closure barrier = base::BarrierClosure(copies, copies_done);
443 443
444 // Post all the async tasks. 444 // Post all the async tasks.
445 for (size_t i = 0; i < num_planes; i += planes_per_copy) { 445 for (size_t i = 0; i < num_planes; i += planes_per_copy) {
446 gfx::GpuMemoryBuffer* buffer = 446 gfx::GpuMemoryBuffer* buffer =
447 frame_resources->plane_resources[i].gpu_memory_buffer.get(); 447 frame_resources->plane_resources[i].gpu_memory_buffer.get();
448 uint8* dest_buffers[VideoFrame::kMaxPlanes] = {0}; 448
449 int dest_strides[VideoFrame::kMaxPlanes] = {0}; 449 if (!buffer || !buffer->Map()) {
450 if (buffer) { 450 DLOG(ERROR) << "Could not get or Map() buffer";
451 DCHECK_EQ(planes_per_copy, 451 return;
452 gfx::NumberOfPlanesForBufferFormat(buffer->GetFormat()));
453 bool rv = buffer->Map(reinterpret_cast<void**>(dest_buffers));
454 DCHECK(rv);
455 buffer->GetStride(dest_strides);
456 } 452 }
453 DCHECK_EQ(planes_per_copy,
454 gfx::NumberOfPlanesForBufferFormat(buffer->GetFormat()));
457 455
458 const int rows = VideoFrame::Rows(i, output_format_, size.height()); 456 const int rows = VideoFrame::Rows(i, output_format_, size.height());
459 const int rows_per_copy = RowsPerCopy(i, output_format_, size.width()); 457 const int rows_per_copy = RowsPerCopy(i, output_format_, size.width());
460 458
461 for (int row = 0; row < rows; row += rows_per_copy) { 459 for (int row = 0; row < rows; row += rows_per_copy) {
462 const int rows_to_copy = std::min(rows_per_copy, rows - row); 460 const int rows_to_copy = std::min(rows_per_copy, rows - row);
463 switch (output_format_) { 461 switch (output_format_) {
464 case PIXEL_FORMAT_I420: { 462 case PIXEL_FORMAT_I420: {
465 const int bytes_per_row = 463 const int bytes_per_row =
466 VideoFrame::RowBytes(i, output_format_, size.width()); 464 VideoFrame::RowBytes(i, output_format_, size.width());
467 worker_task_runner_->PostTask( 465 worker_task_runner_->PostTask(
468 FROM_HERE, base::Bind(&CopyRowsToI420Buffer, row, rows_to_copy, 466 FROM_HERE, base::Bind(&CopyRowsToI420Buffer, row, rows_to_copy,
469 bytes_per_row, video_frame->visible_data(i), 467 bytes_per_row, video_frame->visible_data(i),
470 video_frame->stride(i), dest_buffers[0], 468 video_frame->stride(i),
471 dest_strides[0], barrier)); 469 static_cast<uint8_t*>(buffer->memory(0)),
470 buffer->stride(0), barrier));
472 break; 471 break;
473 } 472 }
474 case PIXEL_FORMAT_NV12: 473 case PIXEL_FORMAT_NV12:
475 worker_task_runner_->PostTask( 474 worker_task_runner_->PostTask(
476 FROM_HERE, 475 FROM_HERE,
477 base::Bind(&CopyRowsToNV12Buffer, row, rows_to_copy, 476 base::Bind(&CopyRowsToNV12Buffer, row, rows_to_copy, size.width(),
478 size.width(), video_frame, dest_buffers[0], 477 video_frame, static_cast<uint8_t*>(buffer->memory(0)),
479 dest_strides[0], dest_buffers[1], dest_strides[1], 478 buffer->stride(0),
480 barrier)); 479 static_cast<uint8_t*>(buffer->memory(1)),
480 buffer->stride(1), barrier));
481 break; 481 break;
482 case PIXEL_FORMAT_UYVY: 482 case PIXEL_FORMAT_UYVY:
483 worker_task_runner_->PostTask( 483 worker_task_runner_->PostTask(
484 FROM_HERE, 484 FROM_HERE,
485 base::Bind(&CopyRowsToUYVYBuffer, row, rows_to_copy, size.width(), 485 base::Bind(&CopyRowsToUYVYBuffer, row, rows_to_copy, size.width(),
486 video_frame, dest_buffers[0], dest_strides[0], 486 video_frame, static_cast<uint8_t*>(buffer->memory(0)),
487 barrier)); 487 buffer->stride(0), barrier));
488 break; 488 break;
489 default: 489 default:
490 NOTREACHED(); 490 NOTREACHED();
491 } 491 }
492 } 492 }
493 } 493 }
494 } 494 }
495 495
496 void GpuMemoryBufferVideoFramePool::PoolImpl:: 496 void GpuMemoryBufferVideoFramePool::PoolImpl::
497 BindAndCreateMailboxesHardwareFrameResources( 497 BindAndCreateMailboxesHardwareFrameResources(
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
702 } 702 }
703 703
704 void GpuMemoryBufferVideoFramePool::MaybeCreateHardwareFrame( 704 void GpuMemoryBufferVideoFramePool::MaybeCreateHardwareFrame(
705 const scoped_refptr<VideoFrame>& video_frame, 705 const scoped_refptr<VideoFrame>& video_frame,
706 const FrameReadyCB& frame_ready_cb) { 706 const FrameReadyCB& frame_ready_cb) {
707 DCHECK(video_frame); 707 DCHECK(video_frame);
708 pool_impl_->CreateHardwareFrame(video_frame, frame_ready_cb); 708 pool_impl_->CreateHardwareFrame(video_frame, frame_ready_cb);
709 } 709 }
710 710
711 } // namespace media 711 } // namespace media
OLDNEW
« no previous file with comments | « media/renderers/mock_gpu_video_accelerator_factories.cc ('k') | ui/gfx/buffer_format_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698