Bug 1745492 Part 2: Update MacIOSurface handling to deal with 10-bit formats. r=media-playback-reviewers,gfx-reviewers,lsalzman,alwu

This fixes an issue caused by landing Bug 1679927. Now that it's possible to
get 10-bit formats in macOS, the texture pipeline has to be updated to pass
those surfaces to WebRender.

This also contains a drive-by comment on D3D11 handing of 10-bit WebRender
display items. It was not clear why specifing 16-bit color depth for P010
format was correct there, but should be specified as 10-bit color elsewhere.

This also contains another drive-by fix to comments in webrender describing
the RG16 enum.

Differential Revision: https://phabricator.services.mozilla.com/D136823
This commit is contained in:
Brad Werth 2022-02-22 19:17:20 +00:00
parent 3b85c2d60c
commit 4b772da5ef
4 changed files with 39 additions and 6 deletions

View File

@ -404,10 +404,21 @@ already_AddRefed<mozilla::gfx::DrawTarget> MacIOSurface::GetAsDrawTargetLocked(
}
SurfaceFormat MacIOSurface::GetFormat() const {
#if !defined(MAC_OS_VERSION_10_13) || \
MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_VERSION_10_13
enum : OSType {
kCVPixelFormatType_420YpCbCr10BiPlanarVideoRange = 'x420',
kCVPixelFormatType_420YpCbCr10BiPlanarFullRange = 'xf20',
};
#endif
switch (GetPixelFormat()) {
case kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange:
case kCVPixelFormatType_420YpCbCr8BiPlanarFullRange:
return SurfaceFormat::NV12;
case kCVPixelFormatType_420YpCbCr10BiPlanarVideoRange:
case kCVPixelFormatType_420YpCbCr10BiPlanarFullRange:
return SurfaceFormat::P010;
case kCVPixelFormatType_422YpCbCr8_yuvs:
case kCVPixelFormatType_422YpCbCr8FullRange:
return SurfaceFormat::YUV422;

View File

@ -1034,6 +1034,11 @@ void DXGITextureHostD3D11::PushDisplayItems(
case gfx::SurfaceFormat::P010:
case gfx::SurfaceFormat::P016:
case gfx::SurfaceFormat::NV12: {
// DXGI_FORMAT_P010 stores its 10 bit value in the most significant bits
// of each 16 bit word with the unused lower bits cleared to zero so that
// it may be handled as if it was DXGI_FORMAT_P016. This is approximately
// perceptually correct. However, due to rounding error, the precise
// quantized value after sampling may be off by 1.
MOZ_ASSERT(aImageKeys.length() == 2);
aBuilder.PushNV12Image(
aBounds, aClip, true, aImageKeys[0], aImageKeys[1],

View File

@ -92,7 +92,8 @@ uint32_t MacIOSurfaceTextureHostOGL::NumSubTextures() {
case gfx::SurfaceFormat::YUV422: {
return 1;
}
case gfx::SurfaceFormat::NV12: {
case gfx::SurfaceFormat::NV12:
case gfx::SurfaceFormat::P010: {
return 2;
}
default: {
@ -153,6 +154,21 @@ void MacIOSurfaceTextureHostOGL::PushResourceUpdates(
(aResources.*method)(aImageKeys[1], descriptor1, aExtID, imageType, 1);
break;
}
case gfx::SurfaceFormat::P010: {
MOZ_ASSERT(aImageKeys.length() == 2);
MOZ_ASSERT(mSurface->GetPlaneCount() == 2);
wr::ImageDescriptor descriptor0(
gfx::IntSize(mSurface->GetDevicePixelWidth(0),
mSurface->GetDevicePixelHeight(0)),
gfx::SurfaceFormat::A16);
wr::ImageDescriptor descriptor1(
gfx::IntSize(mSurface->GetDevicePixelWidth(1),
mSurface->GetDevicePixelHeight(1)),
gfx::SurfaceFormat::R16G16);
(aResources.*method)(aImageKeys[0], descriptor0, aExtID, imageType, 0);
(aResources.*method)(aImageKeys[1], descriptor1, aExtID, imageType, 1);
break;
}
default: {
MOZ_ASSERT_UNREACHABLE("unexpected to be called");
}
@ -191,14 +207,15 @@ void MacIOSurfaceTextureHostOGL::PushDisplayItems(
/* aSupportsExternalCompositing */ true);
break;
}
case gfx::SurfaceFormat::NV12: {
case gfx::SurfaceFormat::NV12:
case gfx::SurfaceFormat::P010: {
MOZ_ASSERT(aImageKeys.length() == 2);
MOZ_ASSERT(mSurface->GetPlaneCount() == 2);
// Those images can only be generated at present by the Apple H264 decoder
// which only supports 8 bits color depth.
aBuilder.PushNV12Image(
aBounds, aClip, true, aImageKeys[0], aImageKeys[1],
wr::ColorDepth::Color8, wr::ToWrYuvColorSpace(GetYUVColorSpace()),
GetFormat() == gfx::SurfaceFormat::NV12 ? wr::ColorDepth::Color8
: wr::ColorDepth::Color10,
wr::ToWrYuvColorSpace(GetYUVColorSpace()),
wr::ToWrColorRange(GetColorRange()), aFilter, preferCompositorSurface,
/* aSupportsExternalCompositing */ true);
break;

View File

@ -160,7 +160,7 @@ pub enum ImageFormat {
/// Two-channels, byte storage. Similar to `R8`, this just means
/// "two channels" rather than "red and green".
RG8 = 5,
/// Two-channels, byte storage. Similar to `R16`, this just means
/// Two-channels, short storage. Similar to `R16`, this just means
/// "two channels" rather than "red and green".
RG16 = 6,