diff --git a/dom/media/platforms/android/AndroidDecoderModule.cpp b/dom/media/platforms/android/AndroidDecoderModule.cpp index 60d1720e0e94..d93934bf1fca 100644 --- a/dom/media/platforms/android/AndroidDecoderModule.cpp +++ b/dom/media/platforms/android/AndroidDecoderModule.cpp @@ -13,6 +13,7 @@ #include "mozilla/ClearOnShutdown.h" #include "mozilla/Components.h" #include "mozilla/StaticPrefs_media.h" +#include "mozilla/gfx/gfxVars.h" #include "mozilla/java/HardwareCodecCapabilityUtilsWrappers.h" #include "nsIGfxInfo.h" #include "nsPromiseFlatString.h" @@ -45,17 +46,6 @@ const nsCString TranslateMimeType(const nsACString& aMimeType) { return nsCString(aMimeType); } -static bool GetFeatureStatus(int32_t aFeature) { - nsCOMPtr gfxInfo = components::GfxInfo::Service(); - int32_t status = nsIGfxInfo::FEATURE_STATUS_UNKNOWN; - nsCString discardFailureId; - if (!gfxInfo || NS_FAILED(gfxInfo->GetFeatureStatus( - aFeature, discardFailureId, &status))) { - return false; - } - return status == nsIGfxInfo::FEATURE_STATUS_OK; -}; - AndroidDecoderModule::AndroidDecoderModule(CDMProxy* aProxy) { mProxy = static_cast(aProxy); } @@ -85,9 +75,9 @@ bool AndroidDecoderModule::SupportsMimeType(const nsACString& aMimeType) { } if ((VPXDecoder::IsVPX(aMimeType, VPXDecoder::VP8) && - !GetFeatureStatus(nsIGfxInfo::FEATURE_VP8_HW_DECODE)) || + !gfx::gfxVars::UseVP8HwDecode()) || (VPXDecoder::IsVPX(aMimeType, VPXDecoder::VP9) && - !GetFeatureStatus(nsIGfxInfo::FEATURE_VP9_HW_DECODE))) { + !gfx::gfxVars::UseVP9HwDecode())) { return false; } diff --git a/gfx/config/gfxFeature.h b/gfx/config/gfxFeature.h index 3811ce2a1199..65572e5f20d1 100644 --- a/gfx/config/gfxFeature.h +++ b/gfx/config/gfxFeature.h @@ -41,7 +41,9 @@ namespace gfx { _(WINDOW_OCCLUSION, Feature, "WINDOW_OCCLUSION") \ _(VAAPI, Feature, "VA-API video decoding") \ _(VIDEO_OVERLAY, Feature, "video overlay") \ - /* Add new entries above this comment */ + _(VP8_HW_DECODE, Feature, "VP8 hardware decoding") \ + _(VP9_HW_DECODE, Feature, "VP9 hardware decoding") +/* Add new entries above this comment */ enum class Feature : uint32_t { #define MAKE_ENUM(name, type, desc) name, diff --git a/gfx/config/gfxVars.h b/gfx/config/gfxVars.h index be2c2969946b..ac0c5c8adf6b 100644 --- a/gfx/config/gfxVars.h +++ b/gfx/config/gfxVars.h @@ -88,7 +88,9 @@ class gfxVarReceiver; _(WebRenderRequiresHardwareDriver, bool, false) \ _(SupportsThreadsafeGL, bool, false) \ _(OffscreenCanvasDomainAllowlist, nsCString, nsCString()) \ - _(AllowWebGPU, bool, false) + _(AllowWebGPU, bool, false) \ + _(UseVP8HwDecode, bool, false) \ + _(UseVP9HwDecode, bool, false) /* Add new entries above this line. */ diff --git a/gfx/thebes/gfxPlatform.cpp b/gfx/thebes/gfxPlatform.cpp index 000e04e2c52e..fefeb7cfadf4 100644 --- a/gfx/thebes/gfxPlatform.cpp +++ b/gfx/thebes/gfxPlatform.cpp @@ -910,6 +910,7 @@ void gfxPlatform::Init() { gPlatform->InitAcceleration(); gPlatform->InitWebRenderConfig(); + gPlatform->InitHardwareVideoConfig(); gPlatform->InitWebGLConfig(); gPlatform->InitWebGPUConfig(); gPlatform->InitWindowOcclusionConfig(); @@ -2707,6 +2708,35 @@ void gfxPlatform::InitWebRenderConfig() { gfxUtils::RemoveShaderCacheFromDiskIfNecessary(); } +void gfxPlatform::InitHardwareVideoConfig() { + if (!XRE_IsParentProcess()) { + return; + } + + nsCString message; + nsCString failureId; + + FeatureState& featureVP8 = gfxConfig::GetFeature(Feature::VP8_HW_DECODE); + featureVP8.EnableByDefault(); + + if (!IsGfxInfoStatusOkay(nsIGfxInfo::FEATURE_VP8_HW_DECODE, &message, + failureId)) { + featureVP8.Disable(FeatureStatus::Blocklisted, message.get(), failureId); + } + + gfxVars::SetUseVP8HwDecode(featureVP8.IsEnabled()); + + FeatureState& featureVP9 = gfxConfig::GetFeature(Feature::VP9_HW_DECODE); + featureVP9.EnableByDefault(); + + if (!IsGfxInfoStatusOkay(nsIGfxInfo::FEATURE_VP9_HW_DECODE, &message, + failureId)) { + featureVP9.Disable(FeatureStatus::Blocklisted, message.get(), failureId); + } + + gfxVars::SetUseVP9HwDecode(featureVP9.IsEnabled()); +} + void gfxPlatform::InitWebGLConfig() { // Depends on InitWebRenderConfig() for UseWebRender(). diff --git a/gfx/thebes/gfxPlatform.h b/gfx/thebes/gfxPlatform.h index 5ed5239cb884..3ab56edaf3e5 100644 --- a/gfx/thebes/gfxPlatform.h +++ b/gfx/thebes/gfxPlatform.h @@ -805,6 +805,7 @@ class gfxPlatform : public mozilla::layers::MemoryPressureListener { virtual void InitAcceleration(); virtual void InitWebRenderConfig(); + void InitHardwareVideoConfig(); virtual void InitWebGLConfig(); virtual void InitWebGPUConfig(); virtual void InitWindowOcclusionConfig(); diff --git a/widget/GfxInfoBase.cpp b/widget/GfxInfoBase.cpp index 7a94c1f27902..db59d8b3d2e8 100644 --- a/widget/GfxInfoBase.cpp +++ b/widget/GfxInfoBase.cpp @@ -209,9 +209,10 @@ static const char* GetPrefNameForFeature(int32_t aFeature) { name = BLOCKLIST_PREF_BRANCH "dx.p016"; break; case nsIGfxInfo::FEATURE_VP8_HW_DECODE: + name = BLOCKLIST_PREF_BRANCH "vp8.hw-decode"; + break; case nsIGfxInfo::FEATURE_VP9_HW_DECODE: - // We don't provide prefs for these features as these are - // not handling downloadable blocklist. + name = BLOCKLIST_PREF_BRANCH "vp9.hw-decode"; break; case nsIGfxInfo::FEATURE_GL_SWIZZLE: name = BLOCKLIST_PREF_BRANCH "gl.swizzle"; @@ -472,8 +473,12 @@ static int32_t BlocklistFeatureToGfxFeature(const nsAString& aFeature) { if (aFeature.EqualsLiteral("DX_NV12")) { return nsIGfxInfo::FEATURE_DX_NV12; } - // We do not support FEATURE_VP8_HW_DECODE and FEATURE_VP9_HW_DECODE - // in downloadable blocklist. + if (aFeature.EqualsLiteral("VP8_HW_DECODE")) { + return nsIGfxInfo::FEATURE_VP8_HW_DECODE; + } + if (aFeature.EqualsLiteral("VP9_HW_DECODE")) { + return nsIGfxInfo::FEATURE_VP9_HW_DECODE; + } if (aFeature.EqualsLiteral("GL_SWIZZLE")) { return nsIGfxInfo::FEATURE_GL_SWIZZLE; }