Chromium Code Reviews| Index: content/common/gpu/gpu_memory_buffer_factory_io_surface.cc |
| diff --git a/content/common/gpu/gpu_memory_buffer_factory_io_surface.cc b/content/common/gpu/gpu_memory_buffer_factory_io_surface.cc |
| index eeec46039404502fccf79b4e59ea3d3154d6dc90..b286a9baf8a3d8364e12df58ae234adb00fd4c7e 100644 |
| --- a/content/common/gpu/gpu_memory_buffer_factory_io_surface.cc |
| +++ b/content/common/gpu/gpu_memory_buffer_factory_io_surface.cc |
| @@ -9,7 +9,9 @@ |
| #include <vector> |
| #include "base/logging.h" |
| +#include "content/common/gpu/client/gpu_memory_buffer_impl.h" |
| #include "content/common/mac/io_surface_manager.h" |
| +#include "ui/gfx/buffer_format_util.h" |
| #include "ui/gl/gl_image_io_surface.h" |
| namespace content { |
| @@ -23,12 +25,15 @@ void AddIntegerValue(CFMutableDictionaryRef dictionary, |
| CFDictionaryAddValue(dictionary, key, number.get()); |
| } |
| -int32 BytesPerPixel(gfx::BufferFormat format) { |
| +int32 BytesPerElement(gfx::BufferFormat format, size_t plane) { |
|
reveman
2015/08/11 19:10:10
nit: s/size_t/int/
Andre
2015/08/11 19:46:22
Done.
|
| switch (format) { |
| case gfx::BufferFormat::R_8: |
| return 1; |
|
reveman
2015/08/11 19:10:10
nit: DCHECK_EQ(plane, 0)
Andre
2015/08/11 19:46:21
Done.
|
| case gfx::BufferFormat::BGRA_8888: |
| return 4; |
|
reveman
2015/08/11 19:10:10
nit: DCHECK_EQ(plane, 0)
Andre
2015/08/11 19:46:21
Done.
|
| + case gfx::BufferFormat::YUV_420_BIPLANAR: |
| + DCHECK_LT(plane, 2u); |
| + return plane == 0 ? 1 : 2; |
|
reveman
2015/08/11 19:10:10
nit: for consistency with ::SubsamplingFactor:
st
Andre
2015/08/11 19:46:21
Done.
|
| case gfx::BufferFormat::ATC: |
| case gfx::BufferFormat::ATCIA: |
| case gfx::BufferFormat::DXT1: |
| @@ -52,6 +57,8 @@ int32 PixelFormat(gfx::BufferFormat format) { |
| return 'L008'; |
| case gfx::BufferFormat::BGRA_8888: |
| return 'BGRA'; |
| + case gfx::BufferFormat::YUV_420_BIPLANAR: |
| + return '420v'; |
| case gfx::BufferFormat::ATC: |
| case gfx::BufferFormat::ATCIA: |
| case gfx::BufferFormat::DXT1: |
| @@ -74,7 +81,10 @@ const GpuMemoryBufferFactory::Configuration kSupportedConfigurations[] = { |
| {gfx::BufferFormat::R_8, gfx::BufferUsage::PERSISTENT_MAP}, |
| {gfx::BufferFormat::R_8, gfx::BufferUsage::MAP}, |
| {gfx::BufferFormat::BGRA_8888, gfx::BufferUsage::PERSISTENT_MAP}, |
| - {gfx::BufferFormat::BGRA_8888, gfx::BufferUsage::MAP}}; |
| + {gfx::BufferFormat::BGRA_8888, gfx::BufferUsage::MAP}, |
| + {gfx::BufferFormat::YUV_420_BIPLANAR, gfx::BufferUsage::MAP}, |
| + {gfx::BufferFormat::YUV_420_BIPLANAR, gfx::BufferUsage::PERSISTENT_MAP}, |
| +}; |
| } // namespace |
| @@ -111,15 +121,34 @@ GpuMemoryBufferFactoryIOSurface::CreateGpuMemoryBuffer( |
| gfx::BufferUsage usage, |
| int client_id, |
| gfx::PluginWindowHandle surface_handle) { |
| - base::ScopedCFTypeRef<CFMutableDictionaryRef> properties; |
| - properties.reset(CFDictionaryCreateMutable(kCFAllocatorDefault, |
| - 0, |
| - &kCFTypeDictionaryKeyCallBacks, |
| - &kCFTypeDictionaryValueCallBacks)); |
| + size_t num_planes = gfx::NumberOfPlanesForBufferFormat(format); |
| + DCHECK_GT(num_planes, 0u); |
|
reveman
2015/08/11 19:10:10
nit: not sure this DCHECK is necessary. NumberOfPl
Andre
2015/08/11 19:46:21
Removed.
|
| + base::ScopedCFTypeRef<CFMutableArrayRef> planes(CFArrayCreateMutable( |
| + kCFAllocatorDefault, num_planes, &kCFTypeArrayCallBacks)); |
| + |
| + for (size_t plane = 0; plane < num_planes; ++plane) { |
| + size_t factor = GpuMemoryBufferImpl::SubsamplingFactor(format, plane); |
| + |
| + base::ScopedCFTypeRef<CFMutableDictionaryRef> plane_info( |
| + CFDictionaryCreateMutable(kCFAllocatorDefault, 0, |
| + &kCFTypeDictionaryKeyCallBacks, |
| + &kCFTypeDictionaryValueCallBacks)); |
| + AddIntegerValue(plane_info, kIOSurfacePlaneWidth, size.width() / factor); |
| + AddIntegerValue(plane_info, kIOSurfacePlaneHeight, size.height() / factor); |
| + AddIntegerValue(plane_info, kIOSurfacePlaneBytesPerElement, |
| + BytesPerElement(format, plane)); |
| + |
| + CFArrayAppendValue(planes, plane_info); |
| + } |
| + |
| + base::ScopedCFTypeRef<CFMutableDictionaryRef> properties( |
| + CFDictionaryCreateMutable(kCFAllocatorDefault, 0, |
| + &kCFTypeDictionaryKeyCallBacks, |
| + &kCFTypeDictionaryValueCallBacks)); |
| AddIntegerValue(properties, kIOSurfaceWidth, size.width()); |
| AddIntegerValue(properties, kIOSurfaceHeight, size.height()); |
| - AddIntegerValue(properties, kIOSurfaceBytesPerElement, BytesPerPixel(format)); |
| AddIntegerValue(properties, kIOSurfacePixelFormat, PixelFormat(format)); |
| + CFDictionaryAddValue(properties, kIOSurfacePlaneInfo, planes); |
| base::ScopedCFTypeRef<IOSurfaceRef> io_surface(IOSurfaceCreate(properties)); |
| if (!io_surface) |