зеркало из https://github.com/mozilla/gecko-dev.git
Bug 449142. Scale video so that it fits in the content-box of the element and has the same aspect ratio as the video source. Also adds some Ogg video reftests. r=doublec,sr=dbaron
This commit is contained in:
Родитель
9d2aaab3a6
Коммит
e427173bab
|
@ -205,6 +205,9 @@ void nsMediaDecoder::Paint(gfxContext* aContext, const gfxRect& aRect)
|
|||
|
||||
// Make the source image fill the rectangle completely
|
||||
pat->SetMatrix(gfxMatrix().Scale(mRGBWidth/aRect.Width(), mRGBHeight/aRect.Height()));
|
||||
// Set PAD mode so that when the video is being scaled, we do not sample
|
||||
// outside the bounds of the video image.
|
||||
pat->SetExtend(gfxPattern::EXTEND_PAD);
|
||||
|
||||
/* Draw RGB surface onto frame */
|
||||
aContext->NewPath();
|
||||
|
|
|
@ -123,22 +123,40 @@ nsVideoFrame::IsLeaf() const
|
|||
return PR_TRUE;
|
||||
}
|
||||
|
||||
// Return the largest rectangle that fits in aRect and has the
|
||||
// same aspect ratio as aRatio, centered at the center of aRect
|
||||
static gfxRect
|
||||
CorrectForAspectRatio(const gfxRect& aRect, const nsIntSize& aRatio)
|
||||
{
|
||||
NS_ASSERTION(aRatio.width > 0 && aRatio.height > 0 && !aRect.IsEmpty(),
|
||||
"Nothing to draw");
|
||||
// Choose scale factor that scales aRatio to just fit into aRect
|
||||
gfxFloat scale =
|
||||
PR_MIN(aRect.Width()/aRatio.width, aRect.Height()/aRatio.height);
|
||||
gfxSize scaledRatio(scale*aRatio.width, scale*aRatio.height);
|
||||
gfxPoint topLeft((aRect.Width() - scaledRatio.width)/2,
|
||||
(aRect.Height() - scaledRatio.height)/2);
|
||||
return gfxRect(aRect.TopLeft() + topLeft, scaledRatio);
|
||||
}
|
||||
|
||||
void
|
||||
nsVideoFrame::PaintVideo(nsIRenderingContext& aRenderingContext,
|
||||
const nsRect& aDirtyRect, nsPoint aPt)
|
||||
{
|
||||
gfxContext* ctx = static_cast<gfxContext*>(aRenderingContext.GetNativeGraphicData(nsIRenderingContext::NATIVE_THEBES_CONTEXT));
|
||||
// TODO: handle the situation where the frame size is not the same as the
|
||||
// video size, by drawing to the largest rectangle that fits in the frame
|
||||
// whose aspect ratio equals the video's aspect ratio
|
||||
nsRect area = GetContentRect() - GetPosition() + aPt;
|
||||
nsHTMLVideoElement* element = static_cast<nsHTMLVideoElement*>(GetContent());
|
||||
nsIntSize videoSize = element->GetVideoSize(nsIntSize(0, 0));
|
||||
if (videoSize.width <= 0 || videoSize.height <= 0 || area.IsEmpty())
|
||||
return;
|
||||
|
||||
gfxContext* ctx = static_cast<gfxContext*>(aRenderingContext.GetNativeGraphicData(nsIRenderingContext::NATIVE_THEBES_CONTEXT));
|
||||
nsPresContext* presContext = PresContext();
|
||||
gfxRect r = gfxRect(presContext->AppUnitsToGfxUnits(area.x),
|
||||
presContext->AppUnitsToGfxUnits(area.y),
|
||||
presContext->AppUnitsToGfxUnits(area.width),
|
||||
presContext->AppUnitsToGfxUnits(area.height));
|
||||
|
||||
nsHTMLVideoElement* element = static_cast<nsHTMLVideoElement*>(GetContent());
|
||||
r = CorrectForAspectRatio(r, videoSize);
|
||||
element->Paint(ctx, r);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<body style="background:white;">
|
||||
<div style="width:140px; height:100px; position:relative; left:100px; top:100px; background:black;"></div>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,8 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html class="reftest-wait">
|
||||
<body style="background:white;">
|
||||
<video id="v" src="black140x100.ogv"
|
||||
style="width:340px; height:100px; position:relative; top:100px;"
|
||||
onloadeddata="document.documentElement.removeAttribute('class')"></video>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,8 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html class="reftest-wait">
|
||||
<body style="background:white;">
|
||||
<video id="v" src="black140x100.ogv"
|
||||
style="width:140px; height:300px; position:relative; left:100px;"
|
||||
onloadeddata="document.documentElement.removeAttribute('class')"></video>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,6 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<body style="background:white;">
|
||||
<div style="width:280px; height:200px; position:relative; left:200px; top:200px; background:black;"></div>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,8 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html class="reftest-wait">
|
||||
<body style="background:white;">
|
||||
<video id="v" src="black140x100.ogv"
|
||||
style="width:680px; height:200px; position:relative; top:200px;"
|
||||
onloadeddata="document.documentElement.removeAttribute('class')"></video>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,8 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html class="reftest-wait">
|
||||
<body style="background:white;">
|
||||
<video id="v" src="black140x100.ogv"
|
||||
style="width:280px; height:600px; position:relative; left:200px;"
|
||||
onloadeddata="document.documentElement.removeAttribute('class')"></video>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,6 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<body style="background:white;">
|
||||
<div style="width:140px; height:100px; background:black;"></div>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,7 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html class="reftest-wait">
|
||||
<body style="background:white;">
|
||||
<video id="v" src="black140x100.ogv"
|
||||
onloadeddata="document.documentElement.removeAttribute('class')"></video>
|
||||
</body>
|
||||
</html>
|
Двоичный файл не отображается.
|
@ -0,0 +1,5 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<body style="background:white;">
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,7 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html class="reftest-wait">
|
||||
<body style="background:white;">
|
||||
<video id="v" src="black140x100.ogv" style="width:0"
|
||||
onloadeddata="document.documentElement.removeAttribute('class')"></video>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,7 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html class="reftest-wait">
|
||||
<body style="background:white;">
|
||||
<video id="v" src="black140x100.ogv" style="height:0"
|
||||
onloadeddata="document.documentElement.removeAttribute('class')"></video>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,8 @@
|
|||
== aspect-ratio-1a.html aspect-ratio-1-ref.html
|
||||
== aspect-ratio-1b.html aspect-ratio-1-ref.html
|
||||
== aspect-ratio-2a.html aspect-ratio-2-ref.html
|
||||
== aspect-ratio-2b.html aspect-ratio-2-ref.html
|
||||
== basic-1.html basic-1-ref.html
|
||||
== empty-1a.html empty-1-ref.html
|
||||
== empty-1b.html empty-1-ref.html
|
||||
== zoomed-1.html zoomed-1-ref.html
|
|
@ -0,0 +1,6 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<body style="background:white; margin:0;">
|
||||
<div style="width:210px; height:150px; background:black;"></div>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,7 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html class="reftest-wait" reftest-zoom="1.5">
|
||||
<body style="background:white; margin:0">
|
||||
<video id="v" src="black140x100.ogv"
|
||||
onloadeddata="document.documentElement.removeAttribute('class')"></video>
|
||||
</body>
|
||||
</html>
|
|
@ -83,6 +83,9 @@ include native-theme/reftest.list
|
|||
# object/
|
||||
include object/reftest.list
|
||||
|
||||
# ogg-video/
|
||||
include ogg-video/reftest.list
|
||||
|
||||
# percent-overflow-sizing/
|
||||
include percent-overflow-sizing/reftest.list
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче