diff --git a/media/renderers/video_resource_updater.cc b/media/renderers/video_resource_updater.cc index 9e8ed53959b8d..bb62b7b7e95f6 100644 --- a/media/renderers/video_resource_updater.cc +++ b/media/renderers/video_resource_updater.cc @@ -180,17 +180,6 @@ viz::SharedImageFormat GetRGBSharedImageFormat(VideoPixelFormat format) { #endif } -viz::SharedImageFormat GetSingleChannel8BitFormat( - const gpu::Capabilities& caps, - const gpu::SharedImageCapabilities& shared_image_caps) { - if (caps.texture_rg && !shared_image_caps.disable_r8_shared_images) { - return viz::SinglePlaneFormat::kR_8; - } - - DCHECK(shared_image_caps.supports_luminance_shared_images); - return viz::SinglePlaneFormat::kLUMINANCE_8; -} - // Returns true if the input VideoFrame format can be stored directly in the // provided output shared image format. bool HasCompatibleRGBFormat(VideoPixelFormat input_format, @@ -214,20 +203,24 @@ bool IsFrameFormat32BitRGB(VideoPixelFormat frame_format) { frame_format == PIXEL_FORMAT_ABGR || frame_format == PIXEL_FORMAT_ARGB; } -bool IsFormat16BitFloat(viz::SharedImageFormat format) { - // Assume multiplanar SharedImageFormat with ChannelFormat::k16F is always - // used as LUMINANCEF16. - CHECK(format.is_multi_plane()); - return format.channel_format() == viz::SharedImageFormat::ChannelFormat::k16F; -} - viz::SharedImageFormat::ChannelFormat SupportedMultiPlaneChannelFormat( - viz::SharedImageFormat format) { - if (format == viz::SinglePlaneFormat::kR_16) { + const gpu::Capabilities& caps, + const gpu::SharedImageCapabilities& shared_image_caps, + int bits_per_channel) { + if (bits_per_channel <= 8) { + // Must support texture_rg or 8-bits luminance. + DCHECK(shared_image_caps.supports_luminance_shared_images || + caps.texture_rg); + return viz::SharedImageFormat::ChannelFormat::k8; + } + // Can support R_16 formats. + if (caps.texture_norm16 && shared_image_caps.supports_r16_shared_images) { return viz::SharedImageFormat::ChannelFormat::k16; } - if (format == viz::SinglePlaneFormat::kLUMINANCE_F16 || - format == viz::SinglePlaneFormat::kR_F16) { + // Can support R_F16 or LUMINANCE_F16 formats. + if (shared_image_caps.is_r16f_supported || + (caps.texture_half_float_linear && + shared_image_caps.supports_luminance_shared_images)) { return viz::SharedImageFormat::ChannelFormat::k16F; } return viz::SharedImageFormat::ChannelFormat::k8; @@ -857,30 +850,6 @@ VideoFrameExternalResource VideoResourceUpdater::CreateForHardwareFrame( return external_resource; } -viz::SharedImageFormat VideoResourceUpdater::YuvSharedImageFormat( - int bits_per_channel) { - DCHECK(context_provider_); - const auto& caps = context_provider_->ContextCapabilities(); - const auto& shared_image_caps = - context_provider_->SharedImageInterface()->GetCapabilities(); - if (bits_per_channel <= 8) { - DCHECK(shared_image_caps.supports_luminance_shared_images || - caps.texture_rg); - return GetSingleChannel8BitFormat(caps, shared_image_caps); - } - if (caps.texture_norm16 && shared_image_caps.supports_r16_shared_images) { - return viz::SinglePlaneFormat::kR_16; - } - if (shared_image_caps.is_r16f_supported) { - return viz::SinglePlaneFormat::kR_F16; - } - if (caps.texture_half_float_linear && - shared_image_caps.supports_luminance_shared_images) { - return viz::SinglePlaneFormat::kLUMINANCE_F16; - } - return GetSingleChannel8BitFormat(caps, shared_image_caps); -} - viz::SharedImageFormat VideoResourceUpdater::GetSoftwareOutputFormat( VideoPixelFormat input_frame_format, int bits_per_channel, @@ -906,6 +875,8 @@ viz::SharedImageFormat VideoResourceUpdater::GetSoftwareOutputFormat( return PaintCanvasVideoRenderer::GetRGBPixelsOutputFormat(); } + const auto& shared_image_caps = + context_provider_->SharedImageInterface()->GetCapabilities(); // Get the multiplanar shared image format for `input_frame_format`. auto yuv_si_format = VideoPixelFormatToMultiPlanarSharedImageFormat(input_frame_format); @@ -914,8 +885,6 @@ viz::SharedImageFormat VideoResourceUpdater::GetSoftwareOutputFormat( // Only 8-bit formats are supported with UV planes for software decoding. CHECK_EQ(yuv_si_format.channel_format(), viz::SharedImageFormat::ChannelFormat::k8); - const auto& shared_image_caps = - context_provider_->SharedImageInterface()->GetCapabilities(); // Two channel formats are supported only with texture_rg. if (!caps.texture_rg || shared_image_caps.disable_r8_shared_images) { texture_needs_rgb_conversion_out = true; @@ -924,8 +893,8 @@ viz::SharedImageFormat VideoResourceUpdater::GetSoftwareOutputFormat( } // Get the supported channel format for `yuv_si_format`'s first plane. - auto channel_format = - SupportedMultiPlaneChannelFormat(YuvSharedImageFormat(bits_per_channel)); + auto channel_format = SupportedMultiPlaneChannelFormat( + caps, shared_image_caps, bits_per_channel); if (yuv_si_format.channel_format() != channel_format) { // If the requested channel format is not supported, use the supported // channel format and downsample later if needed. @@ -1076,12 +1045,14 @@ bool VideoResourceUpdater::WriteYUVPixelsForAllPlanesToTexture( const bool needs_bit_upshifting = bits_per_channel > 8 && bits_per_channel < resource_bit_depth; + const bool is_16bit_float = yuv_si_format.channel_format() == + viz::SharedImageFormat::ChannelFormat::k16F; + // We need to convert the incoming data if we're transferring to half // float, if there is need for bit downshift or if the strides need to // be reconciled. - const bool needs_conversion = IsFormat16BitFloat(yuv_si_format) || - needs_bit_downshifting || - needs_bit_upshifting; + const bool needs_conversion = + is_16bit_float || needs_bit_downshifting || needs_bit_upshifting; const uint8_t* pixels; int pixels_stride_in_bytes; if (!needs_conversion) { @@ -1098,7 +1069,7 @@ bool VideoResourceUpdater::WriteYUVPixelsForAllPlanesToTexture( } } - if (IsFormat16BitFloat(yuv_si_format)) { + if (is_16bit_float) { int max_value = 1 << bits_per_channel; // Use 1.0/max_value to be consistent with multiplanar shared images // which create TextureDrawQuads and don't take in a multiplier, offset.