tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 9a8c9e2eec5c6d8aaedb944c0b9593deca111464
parent cc59d41bd7cc4bf5b9bfa358dd6bad6a5027029b
Author: Andrew Osmond <aosmond@gmail.com>
Date:   Wed, 24 Dec 2025 03:56:26 +0000

Bug 2005011 - Part 3. Make gfxPlatform set the hardware codec-related gfxVars accurately on Android. r=media-playback-reviewers,padenot

This makes the gfxVars report based on the Java
HardwareCodecCapabilityUtils wrappers, so that when configure the ffmpeg
modules, we advertise the correct software/hardware support.

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

Diffstat:
Mgfx/thebes/gfxAndroidPlatform.cpp | 20++++++++++++++++++++
Mgfx/thebes/gfxAndroidPlatform.h | 4++++
Mgfx/thebes/gfxPlatform.cpp | 16++++++++++++++--
3 files changed, 38 insertions(+), 2 deletions(-)

diff --git a/gfx/thebes/gfxAndroidPlatform.cpp b/gfx/thebes/gfxAndroidPlatform.cpp @@ -13,6 +13,7 @@ #include "mozilla/intl/LocaleService.h" #include "mozilla/intl/OSPreferences.h" #include "mozilla/java/GeckoAppShellWrappers.h" +#include "mozilla/java/HardwareCodecCapabilityUtilsWrappers.h" #include "mozilla/jni/Utils.h" #include "mozilla/layers/AndroidHardwareBuffer.h" #include "mozilla/Preferences.h" @@ -136,6 +137,25 @@ void gfxAndroidPlatform::WaitForInitializeFontAPI() { } } +// static +bool gfxAndroidPlatform::IsHwCodecSupported(media::MediaCodec aCodec, + bool aEncoder) { + switch (aCodec) { + case media::MediaCodec::H264: + return java::HardwareCodecCapabilityUtils::HasHWH264(aEncoder); + case media::MediaCodec::VP8: + return java::HardwareCodecCapabilityUtils::HasHWVP8(aEncoder); + case media::MediaCodec::VP9: + return java::HardwareCodecCapabilityUtils::HasHWVP9(aEncoder); + case media::MediaCodec::AV1: + return java::HardwareCodecCapabilityUtils::HasHWAV1(aEncoder); + case media::MediaCodec::HEVC: + return java::HardwareCodecCapabilityUtils::HasHWHEVC(aEncoder); + default: + return false; + } +} + gfxAndroidPlatform::gfxAndroidPlatform() { // A custom allocator. It counts allocations, enabling memory reporting. sFreetypeMemoryRecord.user = nullptr; diff --git a/gfx/thebes/gfxAndroidPlatform.h b/gfx/thebes/gfxAndroidPlatform.h @@ -10,6 +10,7 @@ #include "gfxUserFontSet.h" #include "nsCOMPtr.h" #include "nsTArray.h" +#include "MediaCodecsSupport.h" class gfxAndroidPlatform final : public gfxPlatform { public: @@ -50,6 +51,9 @@ class gfxAndroidPlatform final : public gfxPlatform { static bool IsFontAPIDisabled(bool aDontCheckPref = false); + static bool IsHwCodecSupported(mozilla::media::MediaCodec aCodec, + bool aEncoder); + protected: void InitAcceleration() override; diff --git a/gfx/thebes/gfxPlatform.cpp b/gfx/thebes/gfxPlatform.cpp @@ -3054,12 +3054,23 @@ void gfxPlatform::InitHardwareVideoConfig() { gfxVars::SetCanUseHardwareVideoDecoding(featureDec.IsEnabled()); gfxVars::SetCanUseHardwareVideoEncoding(featureEnc.IsEnabled()); +#ifdef MOZ_WIDGET_ANDROID +# define CODEC_HW_FEATURE_SETUP_PLATFORM(name, type, encoder) \ + feature##type##name.SetDefault(gfxAndroidPlatform::IsHwCodecSupported( \ + media::MediaCodec::name, encoder), \ + FeatureStatus::Unavailable, \ + "Hardware codec not available"); +#else +# define CODEC_HW_FEATURE_SETUP_PLATFORM(name, type, encoder) \ + feature##type##name.EnableByDefault(); +#endif + #define CODEC_HW_FEATURE_SETUP(name) \ FeatureState& featureDec##name = \ gfxConfig::GetFeature(Feature::name##_HW_DECODE); \ featureDec##name.Reset(); \ if (featureDec.IsEnabled()) { \ - featureDec##name.EnableByDefault(); \ + CODEC_HW_FEATURE_SETUP_PLATFORM(name, Dec, false) \ if (!IsGfxInfoStatusOkay(nsIGfxInfo::FEATURE_##name##_HW_DECODE, &message, \ failureId)) { \ featureDec##name.Disable(FeatureStatus::Blocklisted, message.get(), \ @@ -3071,7 +3082,7 @@ void gfxPlatform::InitHardwareVideoConfig() { gfxConfig::GetFeature(Feature::name##_HW_ENCODE); \ featureEnc##name.Reset(); \ if (featureEnc.IsEnabled()) { \ - featureEnc##name.EnableByDefault(); \ + CODEC_HW_FEATURE_SETUP_PLATFORM(name, Enc, true) \ if (!IsGfxInfoStatusOkay(nsIGfxInfo::FEATURE_##name##_HW_ENCODE, &message, \ failureId)) { \ featureEnc##name.Disable(FeatureStatus::Blocklisted, message.get(), \ @@ -3095,6 +3106,7 @@ void gfxPlatform::InitHardwareVideoConfig() { java::HardwareCodecCapabilityUtils::HasHWVP9(false /* aIsEncoder */)); #endif +#undef CODEC_HW_FEATURE_SETUP_PLATFORM #undef CODEC_HW_FEATURE_SETUP }