Bug 1757637 - Use the ImageContainer to determine video{Width,Height} instead of passing through the state machine. r=alwu

This means there is significantly less chance of desynchronization between the
actual size of the image and the reported size of the image.

Differential Revision: https://phabricator.services.mozilla.com/D149150
This commit is contained in:
Paul Adenot 2022-07-11 13:32:40 +00:00
Родитель a57d022de1
Коммит 3037980689
2 изменённых файлов: 44 добавлений и 22 удалений

Просмотреть файл

@ -215,6 +215,44 @@ bool HTMLVideoElement::IsInteractiveHTMLContent() const {
HTMLMediaElement::IsInteractiveHTMLContent();
}
gfx::IntSize HTMLVideoElement::GetVideoIntrinsicDimensions() {
layers::ImageContainer* container = GetImageContainer();
// Prefer the size of the container as it's more up to date.
if (container && container->GetCurrentSize().width != 0) {
// But adjust to the aspect ratio of the container.
float dar = static_cast<float>(mMediaInfo.mVideo.mDisplay.width) /
mMediaInfo.mVideo.mDisplay.height;
gfx::IntSize size = container->GetCurrentSize();
float imageDar = static_cast<float>(size.width) / size.height;
return gfx::IntSize(int(size.width * (dar / imageDar)), size.height);
}
return mMediaInfo.mVideo.mDisplay;
}
uint32_t HTMLVideoElement::VideoWidth() {
if (!mMediaInfo.HasVideo()) {
return 0;
}
gfx::IntSize size = GetVideoIntrinsicDimensions();
if (mMediaInfo.mVideo.mRotation == VideoInfo::Rotation::kDegree_90 ||
mMediaInfo.mVideo.mRotation == VideoInfo::Rotation::kDegree_270) {
return size.height;
}
return size.width;
}
uint32_t HTMLVideoElement::VideoHeight() {
if (!mMediaInfo.HasVideo()) {
return 0;
}
gfx::IntSize size = GetVideoIntrinsicDimensions();
if (mMediaInfo.mVideo.mRotation == VideoInfo::Rotation::kDegree_90 ||
mMediaInfo.mVideo.mRotation == VideoInfo::Rotation::kDegree_270) {
return size.width;
}
return size.height;
}
uint32_t HTMLVideoElement::MozParsedFrames() const {
MOZ_ASSERT(NS_IsMainThread(), "Should be on main thread.");
if (!IsVideoStatsEnabled()) {
@ -241,7 +279,7 @@ uint32_t HTMLVideoElement::MozDecodedFrames() const {
return mDecoder ? mDecoder->GetFrameStatistics().GetDecodedFrames() : 0;
}
uint32_t HTMLVideoElement::MozPresentedFrames() const {
uint32_t HTMLVideoElement::MozPresentedFrames() {
MOZ_ASSERT(NS_IsMainThread(), "Should be on main thread.");
if (!IsVideoStatsEnabled()) {
return 0;

Просмотреть файл

@ -81,27 +81,9 @@ class HTMLVideoElement final : public HTMLMediaElement {
SetUnsignedIntAttr(nsGkAtoms::height, aValue, 0, aRv);
}
uint32_t VideoWidth() const {
if (mMediaInfo.HasVideo()) {
if (mMediaInfo.mVideo.mRotation == VideoInfo::Rotation::kDegree_90 ||
mMediaInfo.mVideo.mRotation == VideoInfo::Rotation::kDegree_270) {
return mMediaInfo.mVideo.mDisplay.height;
}
return mMediaInfo.mVideo.mDisplay.width;
}
return 0;
}
uint32_t VideoWidth();
uint32_t VideoHeight() const {
if (mMediaInfo.HasVideo()) {
if (mMediaInfo.mVideo.mRotation == VideoInfo::Rotation::kDegree_90 ||
mMediaInfo.mVideo.mRotation == VideoInfo::Rotation::kDegree_270) {
return mMediaInfo.mVideo.mDisplay.width;
}
return mMediaInfo.mVideo.mDisplay.height;
}
return 0;
}
uint32_t VideoHeight();
VideoInfo::Rotation RotationDegrees() const {
return mMediaInfo.mVideo.mRotation;
@ -120,7 +102,7 @@ class HTMLVideoElement final : public HTMLMediaElement {
uint32_t MozDecodedFrames() const;
uint32_t MozPresentedFrames() const;
uint32_t MozPresentedFrames();
uint32_t MozPaintedFrames();
@ -169,6 +151,8 @@ class HTMLVideoElement final : public HTMLMediaElement {
void CreateVideoWakeLockIfNeeded();
void ReleaseVideoWakeLockIfExists();
gfx::IntSize GetVideoIntrinsicDimensions();
RefPtr<WakeLock> mScreenWakeLock;
bool mIsOrientationLocked;