From d5b9a341b8fc83017590d4a435bee27c5a106c66 Mon Sep 17 00:00:00 2001 From: "Matt A. Tobin" Date: Tue, 17 May 2022 00:13:54 -0500 Subject: [DOM:Media] Revert Bug 1212323 Parts 2 and 3 where supportsHardwareH264Decoding() uses a promise if MP4 Hardware Acceleration to about:support This concern was largely Mac-specific but I did leave Part 1 intact because the Mozilla Bug makes a good point that some systems may always software render a 64x64 video (specifically apple but other implementations could adopt this nonsense as well). Personally I want accelerated video.. damn it! The real question is.. Why was the promise never resolving in the first place? Is it fall out from killing DOM Promise? It used jsval but who the hell knows or even cares.. It works and can once again be queried without jumping through god damned hoops. --- dom/base/nsDOMWindowUtils.cpp | 36 +++++++++----------- dom/interfaces/base/nsIDOMWindowUtils.idl | 9 +++-- dom/media/fmp4/MP4Decoder.cpp | 56 +++++-------------------------- dom/media/fmp4/MP4Decoder.h | 3 +- modules/Troubleshoot.jsm | 23 ++----------- 5 files changed, 32 insertions(+), 95 deletions(-) diff --git a/dom/base/nsDOMWindowUtils.cpp b/dom/base/nsDOMWindowUtils.cpp index 7bac1c22a..e62344601 100644 --- a/dom/base/nsDOMWindowUtils.cpp +++ b/dom/base/nsDOMWindowUtils.cpp @@ -106,7 +106,6 @@ #include "nsCSSPseudoElements.h" // for CSSPseudoElementType #include "nsNetUtil.h" #include "mozilla/layers/APZCTreeManager.h" // for layers::ZoomToRectBehavior -#include "mozilla/dom/Promise.h" #include "mozilla/StyleSheetInlines.h" #include "mozilla/gfx/GPUProcessManager.h" @@ -2333,34 +2332,31 @@ nsDOMWindowUtils::GetLayerManagerRemote(bool* retval) } NS_IMETHODIMP -nsDOMWindowUtils::GetSupportsHardwareH264Decoding(JS::MutableHandle aPromise) +nsDOMWindowUtils::GetSupportsHardwareH264Decoding(nsAString& aRetval) { - nsCOMPtr window = do_QueryReferent(mWindow); - NS_ENSURE_STATE(window); - nsCOMPtr parentObject = - do_QueryInterface(window->GetCurrentInnerWindow()); - NS_ENSURE_STATE(parentObject); #ifdef MOZ_FMP4 nsCOMPtr widget = GetWidget(); - NS_ENSURE_STATE(widget); + if (!widget) + return NS_ERROR_FAILURE; + LayerManager *mgr = widget->GetLayerManager(); - NS_ENSURE_STATE(mgr); - RefPtr promise = - MP4Decoder::IsVideoAccelerated(mgr->AsShadowForwarder(), parentObject); - NS_ENSURE_STATE(promise); - aPromise.setObject(*promise->PromiseObj()); -#else - ErrorResult rv; - RefPtr promise = Promise::Create(parentObject, rv); - if (rv.Failed()) { - return rv.StealNSResult(); + if (!mgr) + return NS_ERROR_FAILURE; + + nsCString failureReason; + if (MP4Decoder::IsVideoAccelerated(mgr->AsShadowForwarder(), failureReason)) { + aRetval.AssignLiteral("Yes"); + } else { + aRetval.AssignLiteral("No; "); + AppendUTF8toUTF16(failureReason, aRetval); } - promise->MaybeResolve(NS_LITERAL_STRING("No; Compiled without MP4 support.")); - aPromise.setObject(*promise->PromiseObj()); +#else + aRetval.AssignLiteral("No; Compiled without MP4 support."); #endif return NS_OK; } + NS_IMETHODIMP nsDOMWindowUtils::GetCurrentAudioBackend(nsAString& aBackend) { diff --git a/dom/interfaces/base/nsIDOMWindowUtils.idl b/dom/interfaces/base/nsIDOMWindowUtils.idl index 8293c6c86..548214adc 100644 --- a/dom/interfaces/base/nsIDOMWindowUtils.idl +++ b/dom/interfaces/base/nsIDOMWindowUtils.idl @@ -50,7 +50,7 @@ interface nsIJSRAIIHelper; interface nsIContentPermissionRequest; interface nsIObserver; -[scriptable, uuid(7fcc7958-77d9-45ff-8c81-277bde5f0dc8)] +[scriptable, uuid(e23b3d3a-aa0c-4433-acab-07d4d25c1cc7)] interface nsIDOMWindowUtils : nsISupports { /** @@ -1414,12 +1414,11 @@ interface nsIDOMWindowUtils : nsISupports { readonly attribute boolean layerManagerRemote; /** - * Returns a Promise that will be resolved with a string once the capabilities - * of the h264 decoder have been determined. - * Success does not mean that all h264 video decoding will be done + * True if we can initialize a hardware-backed h264 decoder for a simple + * test video, does not mean that all h264 video decoding will be done * in hardware. */ - readonly attribute jsval supportsHardwareH264Decoding; + readonly attribute AString supportsHardwareH264Decoding; /** * Returns the current audio backend as a free-form string. diff --git a/dom/media/fmp4/MP4Decoder.cpp b/dom/media/fmp4/MP4Decoder.cpp index 9b0886e74..c0c954198 100644 --- a/dom/media/fmp4/MP4Decoder.cpp +++ b/dom/media/fmp4/MP4Decoder.cpp @@ -248,58 +248,18 @@ CreateTestH264Decoder(layers::KnowsCompositor* aKnowsCompositor, return decoder.forget(); } -/* static */ already_AddRefed -MP4Decoder::IsVideoAccelerated(layers::KnowsCompositor* aKnowsCompositor, nsIGlobalObject* aParent) +/* static */ bool +MP4Decoder::IsVideoAccelerated(layers::KnowsCompositor* aKnowsCompositor, nsACString& aFailureReason) { - MOZ_ASSERT(NS_IsMainThread()); - - ErrorResult rv; - RefPtr promise; - promise = dom::Promise::Create(aParent, rv); - if (rv.Failed()) { - rv.SuppressException(); - return nullptr; - } - - RefPtr taskQueue = - new TaskQueue(GetMediaThreadPool(MediaThreadType::PLATFORM_DECODER)); VideoInfo config; - RefPtr decoder(CreateTestH264Decoder(aKnowsCompositor, config, taskQueue)); + RefPtr decoder(CreateTestH264Decoder(aKnowsCompositor, config, nullptr)); if (!decoder) { - taskQueue->BeginShutdown(); - taskQueue->AwaitShutdownAndIdle(); - promise->MaybeResolve(NS_LITERAL_STRING("No; Failed to create H264 decoder")); - return promise.forget(); + aFailureReason.AssignLiteral("Failed to create H264 decoder"); + return false; } - - decoder->Init() - ->Then(AbstractThread::MainThread(), __func__, - [promise, decoder, taskQueue] (TrackInfo::TrackType aTrack) { - nsCString failureReason; - bool ok = decoder->IsHardwareAccelerated(failureReason); - nsAutoString result; - if (ok) { - result.AssignLiteral("Yes"); - } else { - result.AssignLiteral("No"); - } - if (failureReason.Length()) { - result.AppendLiteral("; "); - AppendUTF8toUTF16(failureReason, result); - } - decoder->Shutdown(); - taskQueue->BeginShutdown(); - taskQueue->AwaitShutdownAndIdle(); - promise->MaybeResolve(result); - }, - [promise, decoder, taskQueue] (MediaResult aError) { - decoder->Shutdown(); - taskQueue->BeginShutdown(); - taskQueue->AwaitShutdownAndIdle(); - promise->MaybeResolve(NS_LITERAL_STRING("No; Failed to initialize H264 decoder")); - }); - - return promise.forget(); + bool result = decoder->IsHardwareAccelerated(aFailureReason); + decoder->Shutdown(); + return result; } void diff --git a/dom/media/fmp4/MP4Decoder.h b/dom/media/fmp4/MP4Decoder.h index ad5fba7b5..def4b4f99 100644 --- a/dom/media/fmp4/MP4Decoder.h +++ b/dom/media/fmp4/MP4Decoder.h @@ -48,8 +48,7 @@ public: // Returns true if the MP4 backend is preffed on. static bool IsEnabled(); - static already_AddRefed - IsVideoAccelerated(layers::KnowsCompositor* aKnowsCompositor, nsIGlobalObject* aParent); + static bool IsVideoAccelerated(layers::KnowsCompositor* aKnowsCompositor, nsACString& aFailureReason); void GetMozDebugReaderData(nsAString& aString) override; diff --git a/modules/Troubleshoot.jsm b/modules/Troubleshoot.jsm index d8f485d2c..47e9b1d37 100644 --- a/modules/Troubleshoot.jsm +++ b/modules/Troubleshoot.jsm @@ -302,13 +302,6 @@ var dataProviders = { } catch (e) {} - let promises = []; - // done will be called upon all pending promises being resolved. - // add your pending promise to promises when adding new ones. - function completed() { - Promise.all(promises).then(() => done(data)); - } - data.numTotalWindows = 0; data.numAcceleratedWindows = 0; let winEnumer = Services.ww.getWindowEnumerator(); @@ -324,6 +317,7 @@ var dataProviders = { data.numTotalWindows++; data.windowLayerManagerType = winUtils.layerManagerType; data.windowLayerManagerRemote = winUtils.layerManagerRemote; + data.supportsHardwareH264 = winUtils.supportsHardwareH264Decoding; } catch (e) { continue; @@ -332,17 +326,6 @@ var dataProviders = { data.numAcceleratedWindows++; } - data.supportsHardwareH264 = "Unknown"; - try { - // After restart - data may not be available - let promise = winUtils.supportsHardwareH264Decoding; - promise.then(function(v) { - data.supportsHardwareH264 = v; - }); - promises.push(promise); - } catch (e) {} - - if (!data.numAcceleratedWindows && gfxInfo) { #ifdef XP_WIN let feature = gfxInfo.FEATURE_DIRECT3D_9_LAYERS; @@ -353,7 +336,7 @@ var dataProviders = { } if (!gfxInfo) { - completed(); + done(data); return; } @@ -485,7 +468,7 @@ var dataProviders = { data.featureLog = gfxInfo.getFeatureLog(); data.crashGuards = gfxInfo.getActiveCrashGuards(); - completed(); + done(data); }, media: function media(done) { -- cgit v1.2.3