diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
commit | 1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch) | |
tree | 46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/WebCore/rendering/RenderVideo.cpp | |
parent | 32761a6cee1d0dee366b885b7b9c777e67885688 (diff) | |
download | WebKitGtk-tarball-master.tar.gz |
webkitgtk-2.16.5HEADwebkitgtk-2.16.5master
Diffstat (limited to 'Source/WebCore/rendering/RenderVideo.cpp')
-rw-r--r-- | Source/WebCore/rendering/RenderVideo.cpp | 102 |
1 files changed, 48 insertions, 54 deletions
diff --git a/Source/WebCore/rendering/RenderVideo.cpp b/Source/WebCore/rendering/RenderVideo.cpp index f63982c0b..07a5c3862 100644 --- a/Source/WebCore/rendering/RenderVideo.cpp +++ b/Source/WebCore/rendering/RenderVideo.cpp @@ -10,10 +10,10 @@ * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR @@ -48,18 +48,23 @@ namespace WebCore { using namespace HTMLNames; -RenderVideo::RenderVideo(HTMLVideoElement& element, PassRef<RenderStyle> style) - : RenderMedia(element, std::move(style)) +RenderVideo::RenderVideo(HTMLVideoElement& element, RenderStyle&& style) + : RenderMedia(element, WTFMove(style)) { setIntrinsicSize(calculateIntrinsicSize()); } RenderVideo::~RenderVideo() { - if (MediaPlayer* player = videoElement().player()) { + // Do not add any code here. Add it to willBeDestroyed() instead. +} + +void RenderVideo::willBeDestroyed() +{ + if (MediaPlayer* player = videoElement().player()) player->setVisible(false); - player->setFrameView(0); - } + + RenderMedia::willBeDestroyed(); } IntSize RenderVideo::defaultSize() @@ -78,21 +83,22 @@ void RenderVideo::intrinsicSizeChanged() updateIntrinsicSize(); } -void RenderVideo::updateIntrinsicSize() +bool RenderVideo::updateIntrinsicSize() { LayoutSize size = calculateIntrinsicSize(); size.scale(style().effectiveZoom()); // Never set the element size to zero when in a media document. if (size.isEmpty() && document().isMediaDocument()) - return; + return false; if (size == intrinsicSize()) - return; + return false; setIntrinsicSize(size); setPreferredLogicalWidthsDirty(true); setNeedsLayout(); + return true; } LayoutSize RenderVideo::calculateIntrinsicSize() @@ -108,7 +114,7 @@ LayoutSize RenderVideo::calculateIntrinsicSize() // height of the poster frame, if that is available; otherwise it is 150 CSS pixels. MediaPlayer* player = videoElement().player(); if (player && videoElement().readyState() >= HTMLVideoElement::HAVE_METADATA) { - LayoutSize size = player->naturalSize(); + LayoutSize size(player->naturalSize()); if (!size.isEmpty()) return size; } @@ -148,7 +154,7 @@ IntRect RenderVideo::videoBox() const if (videoElement().shouldDisplayPosterImage()) intrinsicSize = m_cachedImageSize; - return pixelSnappedIntRect(replacedContentRect(intrinsicSize)); + return snappedIntRect(replacedContentRect(intrinsicSize)); } bool RenderVideo::shouldDisplayVideo() const @@ -161,51 +167,52 @@ void RenderVideo::paintReplaced(PaintInfo& paintInfo, const LayoutPoint& paintOf MediaPlayer* mediaPlayer = videoElement().player(); bool displayingPoster = videoElement().shouldDisplayPosterImage(); - Page* page = frame().page(); - if (!displayingPoster && !mediaPlayer) { - if (page && paintInfo.phase == PaintPhaseForeground) - page->addRelevantUnpaintedObject(this, visualOverflowRect()); + if (paintInfo.phase == PaintPhaseForeground) + page().addRelevantUnpaintedObject(this, visualOverflowRect()); return; } LayoutRect rect = videoBox(); if (rect.isEmpty()) { - if (page && paintInfo.phase == PaintPhaseForeground) - page->addRelevantUnpaintedObject(this, visualOverflowRect()); + if (paintInfo.phase == PaintPhaseForeground) + page().addRelevantUnpaintedObject(this, visualOverflowRect()); return; } rect.moveBy(paintOffset); - if (page && paintInfo.phase == PaintPhaseForeground) - page->addRelevantRepaintedObject(this, rect); + if (paintInfo.phase == PaintPhaseForeground) + page().addRelevantRepaintedObject(this, rect); LayoutRect contentRect = contentBoxRect(); contentRect.moveBy(paintOffset); - GraphicsContext* context = paintInfo.context; + GraphicsContext& context = paintInfo.context(); bool clip = !contentRect.contains(rect); - GraphicsContextStateSaver stateSaver(*context, clip); + GraphicsContextStateSaver stateSaver(context, clip); if (clip) - context->clip(contentRect); + context.clip(contentRect); if (displayingPoster) paintIntoRect(context, rect); - else if (view().frameView().paintBehavior() & PaintBehaviorFlattenCompositingLayers) - mediaPlayer->paintCurrentFrameInContext(context, pixelSnappedIntRect(rect)); - else - mediaPlayer->paint(context, pixelSnappedIntRect(rect)); + else if (!videoElement().isFullscreen() || !mediaPlayer->supportsAcceleratedRendering()) { + if (view().frameView().paintBehavior() & PaintBehaviorFlattenCompositingLayers) + mediaPlayer->paintCurrentFrameInContext(context, rect); + else + mediaPlayer->paint(context, rect); + } } void RenderVideo::layout() { StackStats::LayoutCheckPoint layoutCheckPoint; + updateIntrinsicSize(); RenderMedia::layout(); updatePlayer(); } HTMLVideoElement& RenderVideo::videoElement() const { - return toHTMLVideoElement(RenderMedia::mediaElement()); + return downcast<HTMLVideoElement>(RenderMedia::mediaElement()); } void RenderVideo::updateFromElement() @@ -216,10 +223,12 @@ void RenderVideo::updateFromElement() void RenderVideo::updatePlayer() { - if (documentBeingDestroyed()) + if (renderTreeBeingDestroyed()) return; - updateIntrinsicSize(); + bool intrinsicSizeChanged; + intrinsicSizeChanged = updateIntrinsicSize(); + ASSERT_UNUSED(intrinsicSizeChanged, !intrinsicSizeChanged || !view().frameView().isInRenderTreeLayout()); MediaPlayer* mediaPlayer = videoElement().player(); if (!mediaPlayer) @@ -230,12 +239,9 @@ void RenderVideo::updatePlayer() return; } -#if USE(ACCELERATED_COMPOSITING) contentChanged(VideoChanged); -#endif IntRect videoBounds = videoBox(); - mediaPlayer->setFrameView(&view().frameView()); mediaPlayer->setSize(IntSize(videoBounds.width(), videoBounds.height())); mediaPlayer->setVisible(true); mediaPlayer->setShouldMaintainAspectRatio(style().objectFit() != ObjectFitFill); @@ -246,17 +252,11 @@ LayoutUnit RenderVideo::computeReplacedLogicalWidth(ShouldComputePreferred shoul return RenderReplaced::computeReplacedLogicalWidth(shouldComputePreferred); } -LayoutUnit RenderVideo::computeReplacedLogicalHeight() const -{ - return RenderReplaced::computeReplacedLogicalHeight(); -} - LayoutUnit RenderVideo::minimumReplacedHeight() const { return RenderReplaced::minimumReplacedHeight(); } -#if USE(ACCELERATED_COMPOSITING) bool RenderVideo::supportsAcceleratedRendering() const { if (MediaPlayer* player = videoElement().player()) @@ -269,7 +269,6 @@ void RenderVideo::acceleratedRenderingStateChanged() if (MediaPlayer* player = videoElement().player()) player->acceleratedRenderingStateChanged(); } -#endif // USE(ACCELERATED_COMPOSITING) bool RenderVideo::requiresImmediateCompositing() const { @@ -278,46 +277,41 @@ bool RenderVideo::requiresImmediateCompositing() const } #if ENABLE(FULLSCREEN_API) -static const RenderBlock* rendererPlaceholder(const RenderObject* renderer) + +static const RenderBlock* placeholder(const RenderVideo& renderer) { - RenderObject* parent = renderer->parent(); - if (!parent) - return 0; - - RenderFullScreen* fullScreen = parent->isRenderFullScreen() ? toRenderFullScreen(parent) : 0; - if (!fullScreen) - return 0; - - return fullScreen->placeholder(); + auto* parent = renderer.parent(); + return is<RenderFullScreen>(parent) ? downcast<RenderFullScreen>(*parent).placeholder() : nullptr; } LayoutUnit RenderVideo::offsetLeft() const { - if (const RenderBlock* block = rendererPlaceholder(this)) + if (auto* block = placeholder(*this)) return block->offsetLeft(); return RenderMedia::offsetLeft(); } LayoutUnit RenderVideo::offsetTop() const { - if (const RenderBlock* block = rendererPlaceholder(this)) + if (auto* block = placeholder(*this)) return block->offsetTop(); return RenderMedia::offsetTop(); } LayoutUnit RenderVideo::offsetWidth() const { - if (const RenderBlock* block = rendererPlaceholder(this)) + if (auto* block = placeholder(*this)) return block->offsetWidth(); return RenderMedia::offsetWidth(); } LayoutUnit RenderVideo::offsetHeight() const { - if (const RenderBlock* block = rendererPlaceholder(this)) + if (auto* block = placeholder(*this)) return block->offsetHeight(); return RenderMedia::offsetHeight(); } + #endif bool RenderVideo::foregroundIsKnownToBeOpaqueInRect(const LayoutRect& localRect, unsigned maxDepthToTest) const |