Modified: trunk/Source/WebCore/platform/graphics/cocoa/IOSurface.mm (201477 => 201478)
--- trunk/Source/WebCore/platform/graphics/cocoa/IOSurface.mm 2016-05-28 00:44:13 UTC (rev 201477)
+++ trunk/Source/WebCore/platform/graphics/cocoa/IOSurface.mm 2016-05-28 01:22:50 UTC (rev 201478)
@@ -107,117 +107,102 @@
return WTFMove(imageBuffer->m_data.surface);
}
-IOSurface::IOSurface(IntSize size, ColorSpace colorSpace, Format format)
- : m_colorSpace(colorSpace)
- , m_size(size)
- , m_contextSize(size)
+static NSDictionary *optionsForBiplanarSurface(IntSize size, unsigned pixelFormat, size_t firstPlaneBytesPerPixel, size_t secondPlaneBytesPerPixel)
{
- unsigned pixelFormat;
- unsigned bytesPerPixel;
- unsigned bytesPerElement;
-
int width = size.width();
int height = size.height();
- NSDictionary *options;
+ size_t firstPlaneBytesPerRow = IOSurfaceAlignProperty(kIOSurfaceBytesPerRow, width * firstPlaneBytesPerPixel);
+ size_t firstPlaneTotalBytes = IOSurfaceAlignProperty(kIOSurfaceAllocSize, height * firstPlaneBytesPerRow);
+
+ size_t secondPlaneBytesPerRow = IOSurfaceAlignProperty(kIOSurfaceBytesPerRow, width * secondPlaneBytesPerPixel);
+ size_t secondPlaneTotalBytes = IOSurfaceAlignProperty(kIOSurfaceAllocSize, height * secondPlaneBytesPerRow);
- if (format == Format::RGB10A8) {
- pixelFormat = 'b3a8';
-
- // RGB plane (10-10-10)
- bytesPerPixel = 4;
- bytesPerElement = 4;
+ size_t totalBytes = firstPlaneTotalBytes + secondPlaneTotalBytes;
+ ASSERT(totalBytes);
- size_t rgbPlaneBytesPerRow = IOSurfaceAlignProperty(kIOSurfaceBytesPerRow, width * bytesPerElement);
- size_t rgbPlaneTotalBytes = IOSurfaceAlignProperty(kIOSurfaceAllocSize, height * rgbPlaneBytesPerRow);
+ NSArray *planeInfo = @[
+ @{
+ (id)kIOSurfacePlaneWidth: @(width),
+ (id)kIOSurfacePlaneHeight: @(height),
+ (id)kIOSurfacePlaneBytesPerRow: @(firstPlaneBytesPerRow),
+ (id)kIOSurfacePlaneOffset: @(0),
+ (id)kIOSurfacePlaneSize: @(firstPlaneTotalBytes)
+ },
+ @{
+ (id)kIOSurfacePlaneWidth: @(width),
+ (id)kIOSurfacePlaneHeight: @(height),
+ (id)kIOSurfacePlaneBytesPerRow: @(secondPlaneBytesPerRow),
+ (id)kIOSurfacePlaneOffset: @(firstPlaneTotalBytes),
+ (id)kIOSurfacePlaneSize: @(secondPlaneTotalBytes)
+ }
+ ];
- // Alpha plane (8)
- bytesPerElement = 1;
- size_t alphaPlaneBytesPerRow = IOSurfaceAlignProperty(kIOSurfaceBytesPerRow, width * bytesPerElement);
- size_t alphaPlaneTotalBytes = IOSurfaceAlignProperty(kIOSurfaceAllocSize, height * alphaPlaneBytesPerRow);
-
- m_totalBytes = rgbPlaneTotalBytes + alphaPlaneTotalBytes;
-
- NSArray *planeInfo = @[
- @{
- (id)kIOSurfacePlaneWidth: @(width),
- (id)kIOSurfacePlaneHeight: @(height),
- (id)kIOSurfacePlaneBytesPerRow: @(rgbPlaneBytesPerRow),
- (id)kIOSurfacePlaneOffset: @(0),
- (id)kIOSurfacePlaneSize: @(rgbPlaneTotalBytes)
- },
- @{
- (id)kIOSurfacePlaneWidth: @(width),
- (id)kIOSurfacePlaneHeight: @(height),
- (id)kIOSurfacePlaneBytesPerRow: @(alphaPlaneBytesPerRow),
- (id)kIOSurfacePlaneOffset: @(rgbPlaneTotalBytes),
- (id)kIOSurfacePlaneSize: @(alphaPlaneTotalBytes)
- }
- ];
-
- options = @{
- (id)kIOSurfaceWidth: @(width),
- (id)kIOSurfaceHeight: @(height),
- (id)kIOSurfacePixelFormat: @(pixelFormat),
- (id)kIOSurfaceAllocSize: @(m_totalBytes),
+ return @{
+ (id)kIOSurfaceWidth: @(width),
+ (id)kIOSurfaceHeight: @(height),
+ (id)kIOSurfacePixelFormat: @(pixelFormat),
+ (id)kIOSurfaceAllocSize: @(totalBytes),
#if PLATFORM(IOS)
- (id)kIOSurfaceCacheMode: @(kIOMapWriteCombineCache),
+ (id)kIOSurfaceCacheMode: @(kIOMapWriteCombineCache),
#endif
- (id)kIOSurfacePlaneInfo: planeInfo,
- };
- } else {
- unsigned elementWidth;
+ (id)kIOSurfacePlaneInfo: planeInfo,
+ };
+}
- switch (format) {
- case Format::RGBA:
- pixelFormat = 'BGRA';
- bytesPerPixel = 4;
- bytesPerElement = 4;
- elementWidth = 1;
- break;
- case Format::YUV422:
- pixelFormat = 'yuvf';
- bytesPerPixel = 2;
- bytesPerElement = 4;
- elementWidth = 2;
- break;
- case Format::RGB10:
- pixelFormat = 'w30r';
- bytesPerPixel = 4;
- bytesPerElement = 4;
- elementWidth = 1;
- break;
- case Format::RGB10A8:
- ASSERT_NOT_REACHED();
- pixelFormat = 'b3a8';
- bytesPerPixel = 1;
- bytesPerElement = 1;
- elementWidth = 1;
- break;
- }
+static NSDictionary *optionsFor32BitSurface(IntSize size, unsigned pixelFormat)
+{
+ int width = size.width();
+ int height = size.height();
- size_t bytesPerRow = IOSurfaceAlignProperty(kIOSurfaceBytesPerRow, width * bytesPerPixel);
- ASSERT(bytesPerRow);
+ unsigned bytesPerElement = 4;
+ unsigned bytesPerPixel = 4;
- m_totalBytes = IOSurfaceAlignProperty(kIOSurfaceAllocSize, height * bytesPerRow);
- ASSERT(m_totalBytes);
+ size_t bytesPerRow = IOSurfaceAlignProperty(kIOSurfaceBytesPerRow, width * bytesPerPixel);
+ ASSERT(bytesPerRow);
- options = @{
- (id)kIOSurfaceWidth: @(width),
- (id)kIOSurfaceHeight: @(height),
- (id)kIOSurfacePixelFormat: @(pixelFormat),
- (id)kIOSurfaceBytesPerElement: @(bytesPerElement),
- (id)kIOSurfaceBytesPerRow: @(bytesPerRow),
- (id)kIOSurfaceAllocSize: @(m_totalBytes),
+ size_t totalBytes = IOSurfaceAlignProperty(kIOSurfaceAllocSize, height * bytesPerRow);
+ ASSERT(totalBytes);
+
+ return @{
+ (id)kIOSurfaceWidth: @(width),
+ (id)kIOSurfaceHeight: @(height),
+ (id)kIOSurfacePixelFormat: @(pixelFormat),
+ (id)kIOSurfaceBytesPerElement: @(bytesPerElement),
+ (id)kIOSurfaceBytesPerRow: @(bytesPerRow),
+ (id)kIOSurfaceAllocSize: @(totalBytes),
#if PLATFORM(IOS)
- (id)kIOSurfaceCacheMode: @(kIOMapWriteCombineCache),
+ (id)kIOSurfaceCacheMode: @(kIOMapWriteCombineCache),
#endif
- (id)kIOSurfaceElementWidth: @(elementWidth),
- (id)kIOSurfaceElementHeight: @(1)
- };
+ (id)kIOSurfaceElementHeight: @(1)
+ };
+
+}
+
+IOSurface::IOSurface(IntSize size, ColorSpace colorSpace, Format format)
+ : m_colorSpace(colorSpace)
+ , m_size(size)
+ , m_contextSize(size)
+{
+ NSDictionary *options;
+
+ switch (format) {
+ case Format::RGBA:
+ options = optionsFor32BitSurface(size, 'BGRA');
+ break;
+ case Format::RGB10:
+ options = optionsFor32BitSurface(size, 'w30r');
+ break;
+ case Format::RGB10A8:
+ options = optionsForBiplanarSurface(size, 'b3a8', 4, 1);
+ break;
+ case Format::YUV422:
+ options = optionsForBiplanarSurface(size, '422f', 1, 1);
+ break;
}
m_surface = adoptCF(IOSurfaceCreate((CFDictionaryRef)options));
+ m_totalBytes = IOSurfaceGetAllocSize(m_surface.get());
if (!m_surface)
NSLog(@"Surface creation failed for options %@", options);
}
@@ -368,7 +353,7 @@
if (pixelFormat == 'b3a8')
return Format::RGB10A8;
- if (pixelFormat == 'yuvf')
+ if (pixelFormat == '422f')
return Format::YUV422;
ASSERT_NOT_REACHED();