#include "core/rendering/RenderVideo.h"
-#include "HTMLNames.h"
+#include "core/HTMLNames.h"
#include "core/dom/Document.h"
-#include "core/html/HTMLVideoElement.h"
-#include "core/frame/Frame.h"
#include "core/frame/FrameView.h"
-#include "core/page/Page.h"
-#include "core/platform/graphics/MediaPlayer.h"
+#include "core/frame/LocalFrame.h"
+#include "core/html/HTMLVideoElement.h"
+#include "core/paint/VideoPainter.h"
#include "core/rendering/PaintInfo.h"
#include "core/rendering/RenderFullScreen.h"
+#include "platform/graphics/media/MediaPlayer.h"
+#include "public/platform/WebLayer.h"
-namespace WebCore {
+namespace blink {
using namespace HTMLNames;
IntSize RenderVideo::defaultSize()
{
- // These values are specified in the spec.
- static const int cDefaultWidth = 300;
- static const int cDefaultHeight = 150;
-
- return IntSize(cDefaultWidth, cDefaultHeight);
+ return IntSize(defaultWidth, defaultHeight);
}
void RenderVideo::intrinsicSizeChanged()
setIntrinsicSize(size);
setPreferredLogicalWidthsDirty();
- setNeedsLayout();
+ setNeedsLayoutAndFullPaintInvalidation();
}
LayoutSize RenderVideo::calculateIntrinsicSize()
// The intrinsic height of a video element's playback area is the intrinsic height
// of the video resource, if that is available; otherwise it is the intrinsic
// height of the poster frame, if that is available; otherwise it is 150 CSS pixels.
- MediaPlayer* player = mediaElement()->player();
- if (player && video->readyState() >= HTMLVideoElement::HAVE_METADATA) {
- LayoutSize size = player->naturalSize();
+ WebMediaPlayer* webMediaPlayer = mediaElement()->webMediaPlayer();
+ if (webMediaPlayer && video->readyState() >= HTMLVideoElement::HAVE_METADATA) {
+ IntSize size = webMediaPlayer->naturalSize();
if (!size.isEmpty())
return size;
}
void RenderVideo::paintReplaced(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
{
- MediaPlayer* mediaPlayer = mediaElement()->player();
- bool displayingPoster = videoElement()->shouldDisplayPosterImage();
- if (!displayingPoster && !mediaPlayer)
- return;
-
- LayoutRect rect = videoBox();
- if (rect.isEmpty())
- return;
- rect.moveBy(paintOffset);
-
- LayoutRect contentRect = contentBoxRect();
- contentRect.moveBy(paintOffset);
- GraphicsContext* context = paintInfo.context;
- bool clip = !contentRect.contains(rect);
- if (clip) {
- context->save();
- context->clip(contentRect);
- }
-
- if (displayingPoster)
- paintIntoRect(context, rect);
- else if (document().view() && document().view()->paintBehavior() & PaintBehaviorFlattenCompositingLayers)
- mediaPlayer->paintCurrentFrameInContext(context, pixelSnappedIntRect(rect));
- else
- mediaPlayer->paint(context, pixelSnappedIntRect(rect));
+ VideoPainter(*this).paintReplaced(paintInfo, paintOffset);
+}
- if (clip)
- context->restore();
+bool RenderVideo::acceleratedRenderingInUse()
+{
+ WebLayer* webLayer = mediaElement()->platformLayer();
+ return webLayer && !webLayer->isOrphan();
}
void RenderVideo::layout()
HTMLVideoElement* RenderVideo::videoElement() const
{
- ASSERT(isHTMLVideoElement(node()));
return toHTMLVideoElement(node());
}
{
updateIntrinsicSize();
- MediaPlayer* mediaPlayer = mediaElement()->player();
+ WebMediaPlayer* mediaPlayer = mediaElement()->webMediaPlayer();
if (!mediaPlayer)
return;
if (!videoElement()->isActive())
return;
- contentChanged(VideoChanged);
+ videoElement()->setNeedsCompositingUpdate();
}
LayoutUnit RenderVideo::computeReplacedLogicalWidth(ShouldComputePreferred shouldComputePreferred) const
bool RenderVideo::supportsAcceleratedRendering() const
{
- MediaPlayer* p = mediaElement()->player();
- if (p)
- return p->supportsAcceleratedRendering();
-
- return false;
+ return !!mediaElement()->platformLayer();
}
static const RenderBlock* rendererPlaceholder(const RenderObject* renderer)
return RenderMedia::offsetHeight();
}
-} // namespace WebCore
+CompositingReasons RenderVideo::additionalCompositingReasons() const
+{
+ if (RuntimeEnabledFeatures::overlayFullscreenVideoEnabled()) {
+ HTMLMediaElement* media = toHTMLMediaElement(node());
+ if (media->isFullscreen())
+ return CompositingReasonVideo;
+ }
+
+ if (shouldDisplayVideo() && supportsAcceleratedRendering())
+ return CompositingReasonVideo;
+
+ return CompositingReasonNone;
+}
+
+} // namespace blink