Bug 1409664 - P18. Properly pass KnowsCompositor object to decoder. r=bryce, r=bz

Summary:
To properly determine if a decoder is hardware accelerated, we must pass information about the compositor to the decoder.

Depends on D1631

Tags: #secure-revision

Bug #: 1409664

Differential Revision: https://phabricator.services.mozilla.com/D1632
This commit is contained in:
Jean-Yves Avenard 2018-06-29 16:50:53 +02:00
parent 34e1735ed0
commit f07b7bee8b
2 changed files with 34 additions and 1 deletions

View File

@ -6,6 +6,7 @@
#include "MediaCapabilities.h"
#include "DecoderTraits.h"
#include "Layers.h"
#include "MediaInfo.h"
#include "MediaRecorder.h"
#include "PDMFactory.h"
@ -18,6 +19,8 @@
#include "mozilla/dom/Promise.h"
#include "mozilla/dom/WorkerPrivate.h"
#include "mozilla/dom/WorkerRef.h"
#include "mozilla/layers/KnowsCompositor.h"
#include "nsContentUtils.h"
namespace mozilla {
namespace dom {
@ -160,16 +163,18 @@ MediaCapabilities::DecodingInfo(
// supporting MTA, which the main thread doesn't. So we use our task queue
// to create such decoder and perform initialization.
RefPtr<layers::KnowsCompositor> compositor = GetCompositor();
double frameRate = videoContainer->ExtendedType().GetFramerate().ref();
promises.AppendElement(InvokeAsync(
taskQueue,
__func__,
[taskQueue, frameRate, config = std::move(config)]() mutable
[taskQueue, frameRate, compositor, config = std::move(config)]() mutable
-> RefPtr<CapabilitiesPromise> {
// MediaDataDecoder keeps a reference to the config object, so we must
// keep it alive until the decoder has been shutdown.
CreateDecoderParams params{ *config,
taskQueue,
compositor,
CreateDecoderParams::VideoFrameRate(
frameRate),
TrackInfo::kVideoTrack };
@ -390,6 +395,30 @@ MediaCapabilities::CheckTypeForEncoder(const nsAString& aType)
return MediaRecorder::IsTypeSupported(aType);
}
already_AddRefed<layers::KnowsCompositor>
MediaCapabilities::GetCompositor()
{
nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(GetParentObject());
if (NS_WARN_IF(!window)) {
return nullptr;
}
nsCOMPtr<nsIDocument> doc = window->GetExtantDoc();
if (NS_WARN_IF(!doc)) {
return nullptr;
}
RefPtr<layers::LayerManager> layerManager =
nsContentUtils::LayerManagerForDocument(doc);
if (NS_WARN_IF(!layerManager)) {
return nullptr;
}
RefPtr<layers::KnowsCompositor> knows = layerManager->AsKnowsCompositor();
if (NS_WARN_IF(!knows)) {
return nullptr;
}
return knows->GetForMedia().forget();
}
bool
MediaCapabilities::Enabled(JSContext* aCx, JSObject* aGlobal)
{

View File

@ -20,6 +20,9 @@
#include "nsWrapperCache.h"
namespace mozilla {
namespace layers {
class KnowsCompositor;
}
namespace dom {
struct MediaDecodingConfiguration;
@ -63,6 +66,7 @@ private:
bool CheckTypeForMediaSource(const nsAString& aType);
bool CheckTypeForFile(const nsAString& aType);
bool CheckTypeForEncoder(const nsAString& aType);
already_AddRefed<layers::KnowsCompositor> GetCompositor();
nsCOMPtr<nsIGlobalObject> mParent;
};