From c070ea1f0eaf50d8c6f6478725a81862c78088a0 Mon Sep 17 00:00:00 2001 From: Jean-Yves Avenard Date: Fri, 26 Jul 2019 08:45:35 +0000 Subject: [PATCH] Bug 1543359 - P3. Add kCVPixelFormatType_420YpCbCr8BiPlanarFullRange support to MacIOSurface. r=mattwoodrow This will allow to differentiate full range vs limited range YUV. Differential Revision: https://phabricator.services.mozilla.com/D27211 --HG-- extra : moz-landing-system : lando --- gfx/2d/MacIOSurface.cpp | 15 +++++++++------ gfx/2d/MacIOSurface.h | 3 +++ gfx/gl/GLBlitHelper.cpp | 2 +- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/gfx/2d/MacIOSurface.cpp b/gfx/2d/MacIOSurface.cpp index 16bffe04a4e4..d99c25b0dcc9 100644 --- a/gfx/2d/MacIOSurface.cpp +++ b/gfx/2d/MacIOSurface.cpp @@ -472,9 +472,10 @@ already_AddRefed MacIOSurface::GetAsSurface() { SurfaceFormat MacIOSurface::GetFormat() const { OSType pixelFormat = GetPixelFormat(); - if (pixelFormat == '420v') { + if (pixelFormat == kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange || + pixelFormat == kCVPixelFormatType_420YpCbCr8BiPlanarFullRange) { return SurfaceFormat::NV12; - } else if (pixelFormat == '2vuy') { + } else if (pixelFormat == kCVPixelFormatType_422YpCbCr8) { return SurfaceFormat::YUV422; } else { return HasAlpha() ? SurfaceFormat::R8G8B8A8 : SurfaceFormat::R8G8B8X8; @@ -483,9 +484,10 @@ SurfaceFormat MacIOSurface::GetFormat() const { SurfaceFormat MacIOSurface::GetReadFormat() const { OSType pixelFormat = GetPixelFormat(); - if (pixelFormat == '420v') { + if (pixelFormat == kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange || + pixelFormat == kCVPixelFormatType_420YpCbCr8BiPlanarFullRange) { return SurfaceFormat::NV12; - } else if (pixelFormat == '2vuy') { + } else if (pixelFormat == kCVPixelFormatType_422YpCbCr8) { return SurfaceFormat::R8G8B8X8; } else { return HasAlpha() ? SurfaceFormat::R8G8B8A8 : SurfaceFormat::R8G8B8X8; @@ -512,7 +514,8 @@ CGLError MacIOSurface::CGLTexImageIOSurface2D( GLenum internalFormat; GLenum format; GLenum type; - if (pixelFormat == '420v') { + if (pixelFormat == kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange || + pixelFormat == kCVPixelFormatType_420YpCbCr8BiPlanarFullRange) { MOZ_ASSERT(GetPlaneCount() == 2); MOZ_ASSERT(plane < 2); @@ -530,7 +533,7 @@ CGLError MacIOSurface::CGLTexImageIOSurface2D( if (aOutReadFormat) { *aOutReadFormat = mozilla::gfx::SurfaceFormat::NV12; } - } else if (pixelFormat == '2vuy') { + } else if (pixelFormat == kCVPixelFormatType_422YpCbCr8) { MOZ_ASSERT(plane == 0); // The YCBCR_422_APPLE ext is only available in compatibility profile. So, // we should use RGB_422_APPLE for core profile. The difference between diff --git a/gfx/2d/MacIOSurface.h b/gfx/2d/MacIOSurface.h index 95de67207532..42b37cb9182a 100644 --- a/gfx/2d/MacIOSurface.h +++ b/gfx/2d/MacIOSurface.h @@ -137,6 +137,9 @@ class MacIOSurface final mColorSpace = aColorSpace; } mozilla::gfx::YUVColorSpace GetYUVColorSpace() const { return mColorSpace; } + bool IsFullRange() const { + return GetPixelFormat() == kCVPixelFormatType_420YpCbCr8BiPlanarFullRange; + } // We would like to forward declare NSOpenGLContext, but it is an @interface // and this file is also used from c++, so we use a void *. diff --git a/gfx/gl/GLBlitHelper.cpp b/gfx/gl/GLBlitHelper.cpp index 2d2f8453627f..03f3e02f8c89 100644 --- a/gfx/gl/GLBlitHelper.cpp +++ b/gfx/gl/GLBlitHelper.cpp @@ -1008,7 +1008,7 @@ bool GLBlitHelper::BlitImage(layers::MacIOSurfaceImage* const srcImage, return false; } - if (pixelFormat == '2vuy') { + if (pixelFormat == kCVPixelFormatType_422YpCbCr8) { fragBody = kFragBody_CrYCb; // APPLE_rgb_422 adds RGB_RAW_422_APPLE for `internalFormat`, but only RGB // seems to work?