Skip to content

Commit

Permalink
Revert Resizing video on YouTube can result in aliasing
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=259171
<radar://113731917>

Unreviewed revert 266284@main as it causes a regression opening to fullscreen.

* Source/WebCore/rendering/RenderVideo.cpp:
(WebCore::areAspectRatiosEssentiallyEqual):
(WebCore::RenderVideo::videoBox const):
(WebCore::RenderVideo::updatePlayer):
(WebCore::contentSizeAlmostEqualsFrameSize): Deleted.
(WebCore::RenderVideo::inElementOrVideoFullscreen const): Deleted.
* Source/WebCore/rendering/RenderVideo.h:

Canonical link: https://commits.webkit.org/266809@main
  • Loading branch information
mwyrzykowski committed Aug 11, 2023
1 parent a5ea288 commit deb6f17
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 16 deletions.
19 changes: 4 additions & 15 deletions Source/WebCore/rendering/RenderVideo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#include "RenderVideo.h"

#include "Document.h"
#include "FullscreenManager.h"
#include "GraphicsContext.h"
#include "HTMLNames.h"
#include "HTMLVideoElement.h"
Expand Down Expand Up @@ -176,10 +175,9 @@ void RenderVideo::imageChanged(WrappedImagePtr newImage, const IntRect* rect)
updateIntrinsicSize();
}

static bool contentSizeAlmostEqualsFrameSize(const IntSize& frameContentsSize, const LayoutSize& contentSize, float deviceScaleFactor)
static bool areAspectRatiosEssentiallyEqual(const LayoutSize& intrinsicSize, const LayoutSize& contentSize, float deviceScaleFactor)
{
LayoutUnit pointSizeLayoutUnits = LayoutUnit(deviceScaleFactor);
return absoluteValue(frameContentsSize.width() - contentSize.width()) <= pointSizeLayoutUnits && absoluteValue(frameContentsSize.height() - contentSize.height()) <= pointSizeLayoutUnits;
return WTF::areEssentiallyEqual(intrinsicSize.aspectRatio(), contentSize.aspectRatio(), deviceScaleFactor / std::min<LayoutUnit>(contentSize.width(), contentSize.height()));
}

IntRect RenderVideo::videoBox() const
Expand All @@ -193,7 +191,7 @@ IntRect RenderVideo::videoBox() const
if (videoElement().shouldDisplayPosterImage())
intrinsicSize = m_cachedImageSize;

if (inElementOrVideoFullscreen() && contentSizeAlmostEqualsFrameSize(view().frameView().layoutSize(), contentSize(), page().deviceScaleFactor()))
if (videoElement().isFullscreen() && areAspectRatiosEssentiallyEqual(intrinsicSize, contentSize(), page().deviceScaleFactor()))
return snappedIntRect({ contentBoxLocation(), contentSize().fitToAspectRatio(intrinsicSize, AspectRatioFitGrow) });

return snappedIntRect(replacedContentRect(intrinsicSize));
Expand Down Expand Up @@ -296,15 +294,6 @@ void RenderVideo::updateFromElement()
updatePlayer();
}

bool RenderVideo::inElementOrVideoFullscreen() const
{
bool result = videoElement().isFullscreen();
#if ENABLE(FULLSCREEN_API)
result = result || document().fullscreenManager().isFullscreen();
#endif
return result;
}

void RenderVideo::updatePlayer()
{
if (renderTreeBeingDestroyed())
Expand All @@ -321,7 +310,7 @@ void RenderVideo::updatePlayer()
if (videoElement().inActiveDocument())
contentChanged(VideoChanged);

bool fitToFillInFullscreen = inElementOrVideoFullscreen() && contentSizeAlmostEqualsFrameSize(view().frameView().layoutSize(), contentSize(), page().deviceScaleFactor());
bool fitToFillInFullscreen = videoElement().isFullscreen() && areAspectRatiosEssentiallyEqual(intrinsicSize(), contentSize(), page().deviceScaleFactor());
videoElement().updateMediaPlayer(videoBox().size(), style().objectFit() != ObjectFit::Fill && !fitToFillInFullscreen);
}

Expand Down
1 change: 0 additions & 1 deletion Source/WebCore/rendering/RenderVideo.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ class RenderVideo final : public RenderMedia {
void updatePlayer();

bool foregroundIsKnownToBeOpaqueInRect(const LayoutRect& localRect, unsigned maxDepthToTest) const final;
bool inElementOrVideoFullscreen() const;

LayoutSize m_cachedImageSize;
};
Expand Down

0 comments on commit deb6f17

Please sign in to comment.