Bug 1493198 - P4. Add support for 10/12 bits YUV image to WebRender (bindings) r=mattwoodrow

Depends on D6663

Differential Revision: https://phabricator.services.mozilla.com/D6688

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Jean-Yves Avenard 2018-09-26 14:58:25 +00:00
parent 8d44ed5ac7
commit a4846efef7
8 changed files with 69 additions and 5 deletions

View File

@ -656,8 +656,14 @@ BufferTextureHost::PushResourceUpdates(wr::TransactionBuilder& aResources,
MOZ_ASSERT(aImageKeys.length() == 3);
const layers::YCbCrDescriptor& desc = mDescriptor.get_YCbCrDescriptor();
wr::ImageDescriptor yDescriptor(desc.ySize(), desc.yStride(), gfx::SurfaceFormat::A8);
wr::ImageDescriptor cbcrDescriptor(desc.cbCrSize(), desc.cbCrStride(), gfx::SurfaceFormat::A8);
wr::ImageDescriptor yDescriptor(
desc.ySize(),
desc.yStride(),
SurfaceFormatForColorDepth(desc.colorDepth()));
wr::ImageDescriptor cbcrDescriptor(
desc.cbCrSize(),
desc.cbCrStride(),
SurfaceFormatForColorDepth(desc.colorDepth()));
(aResources.*method)(aImageKeys[0], yDescriptor, aExtID, bufferType, 0);
(aResources.*method)(aImageKeys[1], cbcrDescriptor, aExtID, bufferType, 1);
(aResources.*method)(aImageKeys[2], cbcrDescriptor, aExtID, bufferType, 2);
@ -683,6 +689,7 @@ BufferTextureHost::PushDisplayItems(wr::DisplayListBuilder& aBuilder,
aImageKeys[0],
aImageKeys[1],
aImageKeys[2],
wr::ToWrColorDepth(desc.colorDepth()),
wr::ToWrYuvColorSpace(desc.yUVColorSpace()),
aFilter);
}

View File

@ -1164,6 +1164,7 @@ DXGITextureHostD3D11::PushDisplayItems(wr::DisplayListBuilder& aBuilder,
true,
aImageKeys[0],
aImageKeys[1],
wr::ColorDepth::Color8,
wr::ToWrYuvColorSpace(YUVColorSpace::BT601),
aFilter);
break;
@ -1396,6 +1397,7 @@ DXGIYCbCrTextureHostD3D11::PushDisplayItems(wr::DisplayListBuilder& aBuilder,
aImageKeys[0],
aImageKeys[1],
aImageKeys[2],
wr::ToWrColorDepth(mColorDepth),
wr::ToWrYuvColorSpace(mYUVColorSpace),
aFilter);
}

View File

@ -228,10 +228,13 @@ MacIOSurfaceTextureHostOGL::PushDisplayItems(wr::DisplayListBuilder& aBuilder,
case gfx::SurfaceFormat::YUV422: {
MOZ_ASSERT(aImageKeys.length() == 1);
MOZ_ASSERT(mSurface->GetPlaneCount() == 0);
// Those images can only be generated at present by the Apple H264 decoder
// which only supports 8 bits color depth.
aBuilder.PushYCbCrInterleavedImage(aBounds,
aClip,
true,
aImageKeys[0],
wr::ColorDepth::Color8,
wr::ToWrYuvColorSpace(YUVColorSpace::BT601),
aFilter);
break;
@ -239,11 +242,14 @@ MacIOSurfaceTextureHostOGL::PushDisplayItems(wr::DisplayListBuilder& aBuilder,
case gfx::SurfaceFormat::NV12: {
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(YUVColorSpace::BT601),
aFilter);
break;

View File

@ -1122,6 +1122,7 @@ DisplayListBuilder::PushYCbCrPlanarImage(const wr::LayoutRect& aBounds,
wr::ImageKey aImageChannel0,
wr::ImageKey aImageChannel1,
wr::ImageKey aImageChannel2,
wr::WrColorDepth aColorDepth,
wr::WrYuvColorSpace aColorSpace,
wr::ImageRendering aRendering)
{
@ -1132,6 +1133,7 @@ DisplayListBuilder::PushYCbCrPlanarImage(const wr::LayoutRect& aBounds,
aImageChannel0,
aImageChannel1,
aImageChannel2,
aColorDepth,
aColorSpace,
aRendering);
}
@ -1142,6 +1144,7 @@ DisplayListBuilder::PushNV12Image(const wr::LayoutRect& aBounds,
bool aIsBackfaceVisible,
wr::ImageKey aImageChannel0,
wr::ImageKey aImageChannel1,
wr::WrColorDepth aColorDepth,
wr::WrYuvColorSpace aColorSpace,
wr::ImageRendering aRendering)
{
@ -1151,6 +1154,7 @@ DisplayListBuilder::PushNV12Image(const wr::LayoutRect& aBounds,
aIsBackfaceVisible,
aImageChannel0,
aImageChannel1,
aColorDepth,
aColorSpace,
aRendering);
}
@ -1160,6 +1164,7 @@ DisplayListBuilder::PushYCbCrInterleavedImage(const wr::LayoutRect& aBounds,
const wr::LayoutRect& aClip,
bool aIsBackfaceVisible,
wr::ImageKey aImageChannel0,
wr::WrColorDepth aColorDepth,
wr::WrYuvColorSpace aColorSpace,
wr::ImageRendering aRendering)
{
@ -1168,6 +1173,7 @@ DisplayListBuilder::PushYCbCrInterleavedImage(const wr::LayoutRect& aBounds,
MergeClipLeaf(aClip),
aIsBackfaceVisible,
aImageChannel0,
aColorDepth,
aColorSpace,
aRendering);
}

View File

@ -408,6 +408,7 @@ public:
wr::ImageKey aImageChannel0,
wr::ImageKey aImageChannel1,
wr::ImageKey aImageChannel2,
wr::WrColorDepth aColorDepth,
wr::WrYuvColorSpace aColorSpace,
wr::ImageRendering aFilter);
@ -416,6 +417,7 @@ public:
bool aIsBackfaceVisible,
wr::ImageKey aImageChannel0,
wr::ImageKey aImageChannel1,
wr::WrColorDepth aColorDepth,
wr::WrYuvColorSpace aColorSpace,
wr::ImageRendering aFilter);
@ -423,6 +425,7 @@ public:
const wr::LayoutRect& aClip,
bool aIsBackfaceVisible,
wr::ImageKey aImageChannel0,
wr::WrColorDepth aColorDepth,
wr::WrYuvColorSpace aColorSpace,
wr::ImageRendering aFilter);

View File

@ -73,6 +73,8 @@ SurfaceFormatToImageFormat(gfx::SurfaceFormat aFormat) {
return Some(wr::ImageFormat::BGRA8);
case gfx::SurfaceFormat::A8:
return Some(wr::ImageFormat::R8);
case gfx::SurfaceFormat::A16:
return Some(wr::ImageFormat::R16);
case gfx::SurfaceFormat::R8G8:
return Some(wr::ImageFormat::RG8);
case gfx::SurfaceFormat::UNKNOWN:
@ -88,6 +90,8 @@ ImageFormatToSurfaceFormat(ImageFormat aFormat) {
return gfx::SurfaceFormat::B8G8R8A8;
case ImageFormat::R8:
return gfx::SurfaceFormat::A8;
case ImageFormat::R16:
return gfx::SurfaceFormat::A16;
default:
return gfx::SurfaceFormat::UNKNOWN;
}
@ -844,6 +848,20 @@ static inline wr::WrYuvColorSpace ToWrYuvColorSpace(YUVColorSpace aYUVColorSpace
return wr::WrYuvColorSpace::Rec601;
}
static inline wr::WrColorDepth ToWrColorDepth(gfx::ColorDepth aColorDepth) {
switch (aColorDepth) {
case gfx::ColorDepth::COLOR_8:
return wr::WrColorDepth::Color8;
case gfx::ColorDepth::COLOR_10:
return wr::WrColorDepth::Color10;
case gfx::ColorDepth::COLOR_12:
return wr::WrColorDepth::Color12;
default:
MOZ_ASSERT_UNREACHABLE("Tried to convert invalid color depth value.");
}
return wr::WrColorDepth::Color8;
}
static inline wr::SyntheticItalics DegreesToSyntheticItalics(float aDegrees) {
wr::SyntheticItalics synthetic_italics;
synthetic_italics.angle = int16_t(std::min(std::max(aDegrees, -89.0f), 89.0f) * 256.0f);

View File

@ -84,6 +84,8 @@ pub type WrFontKey = FontKey;
pub type WrFontInstanceKey = FontInstanceKey;
/// cbindgen:field-names=[mNamespace, mHandle]
type WrYuvColorSpace = YuvColorSpace;
/// cbindgen:field-names=[mNamespace, mHandle]
type WrColorDepth = ColorDepth;
fn make_slice<'a, T>(ptr: *const T, len: usize) -> &'a [T] {
if ptr.is_null() {
@ -2047,6 +2049,7 @@ pub extern "C" fn wr_dp_push_yuv_planar_image(state: &mut WrState,
image_key_0: WrImageKey,
image_key_1: WrImageKey,
image_key_2: WrImageKey,
color_depth: WrColorDepth,
color_space: WrYuvColorSpace,
image_rendering: ImageRendering) {
debug_assert!(unsafe { is_in_main_thread() || is_in_compositor_thread() });
@ -2058,7 +2061,7 @@ pub extern "C" fn wr_dp_push_yuv_planar_image(state: &mut WrState,
.dl_builder
.push_yuv_image(&prim_info,
YuvData::PlanarYCbCr(image_key_0, image_key_1, image_key_2),
ColorDepth::Color8,
color_depth,
color_space,
image_rendering);
}
@ -2071,6 +2074,7 @@ pub extern "C" fn wr_dp_push_yuv_NV12_image(state: &mut WrState,
is_backface_visible: bool,
image_key_0: WrImageKey,
image_key_1: WrImageKey,
color_depth: WrColorDepth,
color_space: WrYuvColorSpace,
image_rendering: ImageRendering) {
debug_assert!(unsafe { is_in_main_thread() || is_in_compositor_thread() });
@ -2082,7 +2086,7 @@ pub extern "C" fn wr_dp_push_yuv_NV12_image(state: &mut WrState,
.dl_builder
.push_yuv_image(&prim_info,
YuvData::NV12(image_key_0, image_key_1),
ColorDepth::Color8,
color_depth,
color_space,
image_rendering);
}
@ -2094,6 +2098,7 @@ pub extern "C" fn wr_dp_push_yuv_interleaved_image(state: &mut WrState,
clip: LayoutRect,
is_backface_visible: bool,
image_key_0: WrImageKey,
color_depth: WrColorDepth,
color_space: WrYuvColorSpace,
image_rendering: ImageRendering) {
debug_assert!(unsafe { is_in_main_thread() || is_in_compositor_thread() });
@ -2105,7 +2110,7 @@ pub extern "C" fn wr_dp_push_yuv_interleaved_image(state: &mut WrState,
.dl_builder
.push_yuv_image(&prim_info,
YuvData::InterleavedYCbCr(image_key_0),
ColorDepth::Color8,
color_depth,
color_space,
image_rendering);
}

View File

@ -61,6 +61,18 @@ enum class ClipMode {
Sentinel /* this must be last for serialization purposes. */
};
// Specifies the color depth of an image. Currently only used for YUV images.
enum class ColorDepth : uint8_t {
// 8 bits image (most common)
Color8,
// 10 bits image
Color10,
// 12 bits image
Color12,
Sentinel /* this must be last for serialization purposes. */
};
enum class ExtendMode : uint32_t {
Clamp,
Repeat,
@ -934,6 +946,8 @@ struct GlyphOptions {
}
};
using WrColorDepth = ColorDepth;
using WrYuvColorSpace = YuvColorSpace;
struct ByteSlice {
@ -1490,6 +1504,7 @@ void wr_dp_push_yuv_NV12_image(WrState *aState,
bool aIsBackfaceVisible,
WrImageKey aImageKey0,
WrImageKey aImageKey1,
WrColorDepth aColorDepth,
WrYuvColorSpace aColorSpace,
ImageRendering aImageRendering)
WR_FUNC;
@ -1501,6 +1516,7 @@ void wr_dp_push_yuv_interleaved_image(WrState *aState,
LayoutRect aClip,
bool aIsBackfaceVisible,
WrImageKey aImageKey0,
WrColorDepth aColorDepth,
WrYuvColorSpace aColorSpace,
ImageRendering aImageRendering)
WR_FUNC;
@ -1514,6 +1530,7 @@ void wr_dp_push_yuv_planar_image(WrState *aState,
WrImageKey aImageKey0,
WrImageKey aImageKey1,
WrImageKey aImageKey2,
WrColorDepth aColorDepth,
WrYuvColorSpace aColorSpace,
ImageRendering aImageRendering)
WR_FUNC;