Skip to content

Commit

Permalink
Bug 1547892 - Load video element in VideoDocument slightly later duri…
Browse files Browse the repository at this point in the history
…ng load. r=bzbarsky

Currently when we create the video inside a VideoDocument, the PresShell isn't
created yet. This means the video element can't access information about the
compositor, which means it doesn't know whether it can create a hardware
accelerated video decoder, and so we end up falling back to using a software
decoder.

So this patch moves the creation of the video element to slightly later in the
load of a VideoDocument, so that the PresShell is available when we create the
VideoDocument's video element. This means VideoDocuments's video decoder can be
hardware accelerated

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

--HG--
extra : moz-landing-system : lando
  • Loading branch information
Chris Pearce committed May 14, 2019
1 parent 4b20fc8 commit 9048acc
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
2 changes: 1 addition & 1 deletion dom/html/MediaDocument.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class MediaDocument : public nsHTMLDocument {
virtual nsresult CreateSyntheticDocument();

friend class MediaDocumentStreamListener;
nsresult StartLayout();
virtual nsresult StartLayout();

void GetFileName(nsAString& aResult, nsIChannel* aChannel);

Expand Down
2 changes: 0 additions & 2 deletions dom/html/PluginDocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ class PluginDocument final : public MediaDocument, public nsIPluginDocument {
const nsCString& GetType() const { return mMimeType; }
Element* GetPluginContent() { return mPluginContent; }

void StartLayout() { MediaDocument::StartLayout(); }

virtual void Destroy() override {
if (mStreamListener) {
mStreamListener->DropDocumentRef();
Expand Down
33 changes: 21 additions & 12 deletions dom/html/VideoDocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,13 @@ class VideoDocument final : public MediaDocument {
MediaDocument::Destroy();
}

nsresult StartLayout() override;

protected:
nsresult CreateVideoElement();
// Sets document <title> to reflect the file name and description.
void UpdateTitle(nsIChannel* aChannel);

nsresult CreateSyntheticVideoDocument();

RefPtr<MediaDocumentStreamListener> mStreamListener;
};

Expand All @@ -62,18 +63,30 @@ nsresult VideoDocument::StartDocumentLoad(const char* aCommand,
return rv;
}

nsresult VideoDocument::StartLayout() {
// Create video element, and begin loading the media resource. Note we
// delay creating the video element until now (we're called from
// MediaDocumentStreamListener::OnStartRequest) as the PresShell is likely
// to have been created by now, so the MediaDecoder will be able to tell
// what kind of compositor we have, so the video element knows whether
// it can create a hardware accelerated video decoder or not.
nsresult rv = CreateVideoElement();
NS_ENSURE_SUCCESS(rv, rv);

rv = MediaDocument::StartLayout();
NS_ENSURE_SUCCESS(rv, rv);

return NS_OK;
}

void VideoDocument::SetScriptGlobalObject(
nsIScriptGlobalObject* aScriptGlobalObject) {
// Set the script global object on the superclass before doing
// anything that might require it....
MediaDocument::SetScriptGlobalObject(aScriptGlobalObject);

if (aScriptGlobalObject && !InitialSetupHasBeenDone()) {
// Create synthetic document
#ifdef DEBUG
nsresult rv =
#endif
CreateSyntheticVideoDocument();
DebugOnly<nsresult> rv = CreateSyntheticDocument();
NS_ASSERTION(NS_SUCCEEDED(rv), "failed to create synthetic video document");

if (!nsContentUtils::IsChildOfSameType(this)) {
Expand All @@ -88,11 +101,7 @@ void VideoDocument::SetScriptGlobalObject(
}
}

nsresult VideoDocument::CreateSyntheticVideoDocument() {
// make our generic document
nsresult rv = MediaDocument::CreateSyntheticDocument();
NS_ENSURE_SUCCESS(rv, rv);

nsresult VideoDocument::CreateVideoElement() {
Element* body = GetBodyElement();
if (!body) {
NS_WARNING("no body on video document!");
Expand Down

0 comments on commit 9048acc

Please sign in to comment.