Commit a641efaf authored by Christopher Cameron's avatar Christopher Cameron Committed by Commit Bot

MacOS: Use IOSurfaceAlignProperty on kIOSurfaceBytesPerRow et al

Use IOSurfaceAlignProperty to align the following properties:
- kIOSurfacePlaneBytesPerRow
- kIOSurfacePlaneSize
- kIOSurfacePlaneOffset
- kIOSurfaceBytesPerRow
- kIOSurfaceAllocSize
Clean up the structure of CreateIOSurface by merging the two
"if (num_planes > 1)" branches.

Bug: 1134712
Change-Id: Ib5d7c936b5f21359657af4f27f78fb1eca1d14e1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2518763Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Commit-Queue: ccameron <ccameron@chromium.org>
Cr-Commit-Position: refs/heads/master@{#824571}
parent cb77f7e4
......@@ -204,44 +204,65 @@ IOSurfaceRef CreateIOSurface(const gfx::Size& size,
TRACE_EVENT0("ui", "CreateIOSurface");
base::TimeTicks start_time = base::TimeTicks::Now();
size_t num_planes = gfx::NumberOfPlanesForLinearBufferFormat(format);
base::ScopedCFTypeRef<CFMutableArrayRef> planes(CFArrayCreateMutable(
kCFAllocatorDefault, num_planes, &kCFTypeArrayCallBacks));
base::ScopedCFTypeRef<CFMutableDictionaryRef> properties(
CFDictionaryCreateMutable(kCFAllocatorDefault, 0,
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks));
AddIntegerValue(properties, kIOSurfaceWidth, size.width());
AddIntegerValue(properties, kIOSurfaceHeight, size.height());
AddIntegerValue(properties, kIOSurfacePixelFormat,
BufferFormatToIOSurfacePixelFormat(format));
// Don't specify plane information unless there are indeed multiple planes
// because DisplayLink drivers do not support this.
// http://crbug.com/527556
size_t num_planes = gfx::NumberOfPlanesForLinearBufferFormat(format);
if (num_planes > 1) {
base::ScopedCFTypeRef<CFMutableArrayRef> planes(CFArrayCreateMutable(
kCFAllocatorDefault, num_planes, &kCFTypeArrayCallBacks));
size_t total_bytes_alloc = 0;
for (size_t plane = 0; plane < num_planes; ++plane) {
size_t factor = gfx::SubsamplingFactorForBufferFormat(format, plane);
const size_t factor =
gfx::SubsamplingFactorForBufferFormat(format, plane);
const size_t plane_width = size.width() / factor;
const size_t plane_height = size.height() / factor;
const size_t plane_bytes_per_element = BytesPerElement(format, plane);
const size_t plane_bytes_per_row = IOSurfaceAlignProperty(
kIOSurfacePlaneBytesPerRow, plane_width * plane_bytes_per_element);
const size_t plane_bytes_alloc = IOSurfaceAlignProperty(
kIOSurfacePlaneSize, plane_height * plane_bytes_per_row);
const size_t plane_offset =
IOSurfaceAlignProperty(kIOSurfacePlaneOffset, total_bytes_alloc);
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, kIOSurfacePlaneWidth, plane_width);
AddIntegerValue(plane_info, kIOSurfacePlaneHeight, plane_height);
AddIntegerValue(plane_info, kIOSurfacePlaneBytesPerElement,
BytesPerElement(format, plane));
plane_bytes_per_element);
AddIntegerValue(plane_info, kIOSurfacePlaneBytesPerRow,
plane_bytes_per_row);
AddIntegerValue(plane_info, kIOSurfacePlaneSize, plane_bytes_alloc);
AddIntegerValue(plane_info, kIOSurfacePlaneOffset, plane_offset);
CFArrayAppendValue(planes, plane_info);
total_bytes_alloc = plane_offset + plane_bytes_alloc;
}
}
base::ScopedCFTypeRef<CFMutableDictionaryRef> properties(
CFDictionaryCreateMutable(kCFAllocatorDefault, 0,
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks));
AddIntegerValue(properties, kIOSurfaceWidth, size.width());
AddIntegerValue(properties, kIOSurfaceHeight, size.height());
AddIntegerValue(properties, kIOSurfacePixelFormat,
BufferFormatToIOSurfacePixelFormat(format));
if (num_planes > 1) {
CFDictionaryAddValue(properties, kIOSurfacePlaneInfo, planes);
total_bytes_alloc =
IOSurfaceAlignProperty(kIOSurfaceAllocSize, total_bytes_alloc);
AddIntegerValue(properties, kIOSurfaceAllocSize, total_bytes_alloc);
} else {
AddIntegerValue(properties, kIOSurfaceBytesPerElement,
BytesPerElement(format, 0));
const size_t bytes_per_element = BytesPerElement(format, 0);
const size_t bytes_per_row = IOSurfaceAlignProperty(
kIOSurfaceBytesPerRow, size.width() * bytes_per_element);
const size_t bytes_alloc = IOSurfaceAlignProperty(
kIOSurfaceAllocSize, size.height() * bytes_per_row);
AddIntegerValue(properties, kIOSurfaceBytesPerElement, bytes_per_element);
AddIntegerValue(properties, kIOSurfaceBytesPerRow, bytes_per_row);
AddIntegerValue(properties, kIOSurfaceAllocSize, bytes_alloc);
}
IOSurfaceRef surface = IOSurfaceCreate(properties);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment