From f2d4007ad908079ac59a4fca175dae74dbed8d03 Mon Sep 17 00:00:00 2001 From: Markus Stange Date: Tue, 19 Oct 2021 19:18:56 +0000 Subject: [PATCH] Bug 1736626 - Properly align more IOSurface properties. r=jrmuizel This allows us to achieve detachment for software-decoded NV12 video on M1 Macs. Differential Revision: https://phabricator.services.mozilla.com/D128914 --- gfx/2d/MacIOSurface.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/gfx/2d/MacIOSurface.cpp b/gfx/2d/MacIOSurface.cpp index 62c8b117675d..59ecee8a48b6 100644 --- a/gfx/2d/MacIOSurface.cpp +++ b/gfx/2d/MacIOSurface.cpp @@ -97,11 +97,11 @@ already_AddRefed MacIOSurface::CreateIOSurface(int aWidth, size_t CreatePlaneDictionary(CFTypeRefPtr& aDict, const gfx::IntSize& aSize, size_t aOffset, size_t aBytesPerPixel) { - size_t bytesPerRow = IOSurfaceAlignProperty(kIOSurfaceBytesPerRow, + size_t bytesPerRow = IOSurfaceAlignProperty(kIOSurfacePlaneBytesPerRow, aSize.width * aBytesPerPixel); // Add a SIMD register worth of extra bytes to the end of the allocation for // SWGL. - size_t totalBytes = IOSurfaceAlignProperty(kIOSurfaceAllocSize, + size_t totalBytes = IOSurfaceAlignProperty(kIOSurfacePlaneSize, aSize.height * bytesPerRow + 16); aDict = CFTypeRefPtr::WrapUnderCreateRule( @@ -150,11 +150,15 @@ already_AddRefed MacIOSurface::CreateNV12Surface( } CFTypeRefPtr planeProps[2]; - size_t planeTotalBytes = CreatePlaneDictionary(planeProps[0], aYSize, 0, 1); - planeTotalBytes += - CreatePlaneDictionary(planeProps[1], aCbCrSize, planeTotalBytes, 2); + size_t yPlaneBytes = CreatePlaneDictionary(planeProps[0], aYSize, 0, 1); + size_t cbCrOffset = + IOSurfaceAlignProperty(kIOSurfacePlaneOffset, yPlaneBytes); + size_t cbCrPlaneBytes = + CreatePlaneDictionary(planeProps[1], aCbCrSize, cbCrOffset, 2); + size_t totalBytes = + IOSurfaceAlignProperty(kIOSurfaceAllocSize, cbCrOffset + cbCrPlaneBytes); - AddDictionaryInt(props, kIOSurfaceAllocSize, planeTotalBytes); + AddDictionaryInt(props, kIOSurfaceAllocSize, totalBytes); auto array = CFTypeRefPtr::WrapUnderCreateRule( CFArrayCreate(kCFAllocatorDefault, (const void**)planeProps, 2,