Chromium Code Reviews| Index: content/common/gpu/client/gpu_memory_buffer_impl_shared_memory.cc |
| diff --git a/content/common/gpu/client/gpu_memory_buffer_impl_shared_memory.cc b/content/common/gpu/client/gpu_memory_buffer_impl_shared_memory.cc |
| index 3d3aee965a3d5aaa526538d9b1aff7d6923e1d24..76e60c2abb6b4286c5afb30db59a5ce4f892e15d 100644 |
| --- a/content/common/gpu/client/gpu_memory_buffer_impl_shared_memory.cc |
| +++ b/content/common/gpu/client/gpu_memory_buffer_impl_shared_memory.cc |
| @@ -36,18 +36,12 @@ scoped_ptr<GpuMemoryBufferImpl> GpuMemoryBufferImplSharedMemory::Create( |
| gfx::GpuMemoryBufferId id, |
| const gfx::Size& size, |
| Format format) { |
| - scoped_ptr<base::SharedMemory> shared_memory(new base::SharedMemory()); |
| - |
| - size_t stride_in_bytes = 0; |
| - if (!StrideInBytes(size.width(), format, &stride_in_bytes)) |
| - return scoped_ptr<GpuMemoryBufferImpl>(); |
| - |
| - base::CheckedNumeric<size_t> size_in_bytes = stride_in_bytes; |
| - size_in_bytes *= size.height(); |
| - if (!size_in_bytes.IsValid()) |
| + size_t buffer_size = 0u; |
| + if (!TotalBufferSizeInBytes(size, format, &buffer_size)) |
| return scoped_ptr<GpuMemoryBufferImpl>(); |
| - if (!shared_memory->CreateAndMapAnonymous(size_in_bytes.ValueOrDie())) |
| + scoped_ptr<base::SharedMemory> shared_memory(new base::SharedMemory()); |
| + if (!shared_memory->CreateAndMapAnonymous(buffer_size)) |
| return scoped_ptr<GpuMemoryBufferImpl>(); |
| return make_scoped_ptr(new GpuMemoryBufferImplSharedMemory( |
| @@ -61,17 +55,12 @@ GpuMemoryBufferImplSharedMemory::AllocateForChildProcess( |
| const gfx::Size& size, |
| Format format, |
| base::ProcessHandle child_process) { |
| - size_t stride_in_bytes = 0; |
| - if (!StrideInBytes(size.width(), format, &stride_in_bytes)) |
| - return gfx::GpuMemoryBufferHandle(); |
| - |
| - base::CheckedNumeric<int> buffer_size = stride_in_bytes; |
| - buffer_size *= size.height(); |
| - if (!buffer_size.IsValid()) |
| + size_t buffer_size = 0u; |
| + if (!TotalBufferSizeInBytes(size, format, &buffer_size)) |
| return gfx::GpuMemoryBufferHandle(); |
| base::SharedMemory shared_memory; |
| - if (!shared_memory.CreateAnonymous(buffer_size.ValueOrDie())) |
| + if (!shared_memory.CreateAnonymous(buffer_size)) |
| return gfx::GpuMemoryBufferHandle(); |
| gfx::GpuMemoryBufferHandle handle; |
| @@ -91,18 +80,13 @@ GpuMemoryBufferImplSharedMemory::CreateFromHandle( |
| if (!base::SharedMemory::IsHandleValid(handle.handle)) |
| return scoped_ptr<GpuMemoryBufferImpl>(); |
| - size_t stride_in_bytes = 0; |
| - if (!StrideInBytes(size.width(), format, &stride_in_bytes)) |
| - return scoped_ptr<GpuMemoryBufferImpl>(); |
| - |
| - base::CheckedNumeric<size_t> size_in_bytes = stride_in_bytes; |
| - size_in_bytes *= size.height(); |
| - if (!size_in_bytes.IsValid()) |
| + size_t buffer_size = 0u; |
| + if (!TotalBufferSizeInBytes(size, format, &buffer_size)) |
| return scoped_ptr<GpuMemoryBufferImpl>(); |
| scoped_ptr<base::SharedMemory> shared_memory( |
| new base::SharedMemory(handle.handle, false)); |
| - if (!shared_memory->Map(size_in_bytes.ValueOrDie())) |
| + if (!shared_memory->Map(buffer_size)) |
| return scoped_ptr<GpuMemoryBufferImpl>(); |
| return make_scoped_ptr<GpuMemoryBufferImpl>( |
| @@ -124,6 +108,7 @@ bool GpuMemoryBufferImplSharedMemory::IsFormatSupported(Format format) { |
| case ETC1: |
| case RGBA_8888: |
| case BGRA_8888: |
| + case YUV_420: |
| return true; |
| case RGBX_8888: |
| return false; |
| @@ -150,6 +135,15 @@ bool GpuMemoryBufferImplSharedMemory::IsSizeValidForFormat( |
| case BGRA_8888: |
| case RGBX_8888: |
| return true; |
| + case YUV_420: { |
| + for (size_t i = 0; i < NumberOfPlanesForGpuMemoryBufferFormat(format); |
| + ++i) { |
| + size_t factor = SubsamplingFactor(format, i); |
| + if (size.width() % factor != 0 || size.height() % factor != 0) |
|
reveman
2015/04/07 19:03:25
nit: style guide prefers "size.width() % factor ||
emircan
2015/04/07 20:08:12
Done.
|
| + return false; |
| + } |
| + return true; |
| + } |
| } |
| NOTREACHED(); |
| @@ -158,8 +152,21 @@ bool GpuMemoryBufferImplSharedMemory::IsSizeValidForFormat( |
| bool GpuMemoryBufferImplSharedMemory::Map(void** data) { |
| DCHECK(!mapped_); |
| + data[0] = shared_memory_->memory(); |
| + |
| + // Map the other planes if they exist. |
| + size_t num_planes = NumberOfPlanesForGpuMemoryBufferFormat(format_); |
| + if (num_planes > 1) { |
|
reveman
2015/04/07 19:03:25
nit: this if statement is not necessary, the for l
emircan
2015/04/07 20:08:12
Done.
|
| + size_t stride_in_bytes = 0; |
|
reveman
2015/04/07 19:03:25
nit: you can move this into the for-loop scope
emircan
2015/04/07 20:08:12
Done.
|
| + for (size_t i = 0; i < num_planes - 1; ++i) { |
| + if (!StrideInBytes(size_.width(), format_, i, &stride_in_bytes)) |
|
reveman
2015/04/07 19:03:25
nit: it's better to DCHECK here if this fails just
emircan
2015/04/07 20:08:12
Done.
|
| + return false; |
| + data[i + 1] = |
| + reinterpret_cast<uint8*>(data[i]) + |
| + stride_in_bytes * (size_.height() / SubsamplingFactor(format_, i)); |
| + } |
| + } |
| mapped_ = true; |
| - *data = shared_memory_->memory(); |
| return true; |
| } |
| @@ -170,9 +177,12 @@ void GpuMemoryBufferImplSharedMemory::Unmap() { |
| void GpuMemoryBufferImplSharedMemory::GetStride(uint32* stride) const { |
| size_t stride_in_bytes = 0; |
|
reveman
2015/04/07 19:03:25
nit: you can move this into the for-loop scope
emircan
2015/04/07 20:08:12
Done.
|
| - bool valid_stride = StrideInBytes(size_.width(), format_, &stride_in_bytes); |
| - DCHECK(valid_stride); |
| - *stride = stride_in_bytes; |
| + for (size_t i = 0; i < NumberOfPlanesForGpuMemoryBufferFormat(format_); ++i) { |
| + bool valid_stride = |
| + StrideInBytes(size_.width(), format_, i, &stride_in_bytes); |
| + DCHECK(valid_stride); |
| + stride[i] = stride_in_bytes; |
| + } |
| } |
| gfx::GpuMemoryBufferHandle GpuMemoryBufferImplSharedMemory::GetHandle() const { |