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

Unified Diff: content/common/gpu/client/gpu_memory_buffer_impl_shared_memory.cc

Issue 1062853002: Add gfx::GpuMemoryBuffer::YUV_420 and GpuMemoryBufferImplSharedMemory support (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: reveman@ comments. Created 5 years, 8 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 side-by-side diff with in-line comments
Download patch
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..cf6e20d86109d757bc3d41da000c296d12e8ae71 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 (!BufferSizeInBytes(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 (!BufferSizeInBytes(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 (!BufferSizeInBytes(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 || size.height() % factor)
+ return false;
+ }
+ return true;
+ }
}
NOTREACHED();
@@ -158,8 +152,19 @@ bool GpuMemoryBufferImplSharedMemory::IsSizeValidForFormat(
bool GpuMemoryBufferImplSharedMemory::Map(void** data) {
DCHECK(!mapped_);
+ data[0] = shared_memory_->memory();
+ // Map the other planes if they exist.
+ for (size_t i = 0; i < NumberOfPlanesForGpuMemoryBufferFormat(format_) - 1;
+ ++i) {
+ size_t stride_in_bytes = 0;
+ bool valid_stride =
+ StrideInBytes(size_.width(), format_, i, &stride_in_bytes);
+ DCHECK(valid_stride);
+ data[i + 1] =
+ reinterpret_cast<uint8*>(data[i]) +
+ stride_in_bytes * (size_.height() / SubsamplingFactor(format_, i));
+ }
mapped_ = true;
- *data = shared_memory_->memory();
return true;
}
@@ -169,10 +174,13 @@ void GpuMemoryBufferImplSharedMemory::Unmap() {
}
void GpuMemoryBufferImplSharedMemory::GetStride(uint32* stride) const {
- size_t stride_in_bytes = 0;
- 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) {
+ size_t stride_in_bytes = 0;
+ bool valid_stride =
+ StrideInBytes(size_.width(), format_, i, &stride_in_bytes);
+ DCHECK(valid_stride);
+ stride[i] = stride_in_bytes;
+ }
}
gfx::GpuMemoryBufferHandle GpuMemoryBufferImplSharedMemory::GetHandle() const {

Powered by Google App Engine
This is Rietveld 408576698