1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
6 #include "core/paint/VideoPainter.h"
8 #include "core/dom/Document.h"
9 #include "core/frame/FrameView.h"
10 #include "core/html/HTMLVideoElement.h"
11 #include "core/layout/LayoutVideo.h"
12 #include "core/paint/ImagePainter.h"
13 #include "core/paint/LayoutObjectDrawingRecorder.h"
14 #include "core/paint/PaintInfo.h"
15 #include "platform/geometry/LayoutPoint.h"
16 #include "platform/graphics/paint/ClipRecorder.h"
20 void VideoPainter::paintReplaced(const PaintInfo
& paintInfo
, const LayoutPoint
& paintOffset
)
22 WebMediaPlayer
* mediaPlayer
= m_layoutVideo
.mediaElement()->webMediaPlayer();
23 bool displayingPoster
= m_layoutVideo
.videoElement()->shouldDisplayPosterImage();
24 if (!displayingPoster
&& !mediaPlayer
)
27 LayoutRect
rect(m_layoutVideo
.videoBox());
30 rect
.moveBy(paintOffset
);
32 GraphicsContext
* context
= paintInfo
.context
;
33 LayoutRect contentRect
= m_layoutVideo
.contentBoxRect();
34 contentRect
.moveBy(paintOffset
);
36 Optional
<ClipRecorder
> clipRecorder
;
37 if (!contentRect
.contains(rect
)) {
38 clipRecorder
.emplace(*context
, m_layoutVideo
, paintInfo
.displayItemTypeForClipping(), contentRect
);
41 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(*context
, m_layoutVideo
, paintInfo
.phase
, paintOffset
))
44 LayoutObjectDrawingRecorder
drawingRecorder(*context
, m_layoutVideo
, paintInfo
.phase
, contentRect
, paintOffset
);
46 if (displayingPoster
) {
47 ImagePainter(m_layoutVideo
).paintIntoRect(context
, rect
);
48 } else if ((paintInfo
.globalPaintFlags() & GlobalPaintFlattenCompositingLayers
) || !m_layoutVideo
.acceleratedRenderingInUse()) {
49 SkPaint videoPaint
= context
->fillPaint();
50 videoPaint
.setColor(SK_ColorBLACK
);
51 m_layoutVideo
.videoElement()->paintCurrentFrame(context
->canvas(), pixelSnappedIntRect(rect
), &videoPaint
);