| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "core/paint/VideoPainter.h" | 5 #include "core/paint/VideoPainter.h" |
| 6 | 6 |
| 7 #include "core/dom/Document.h" | 7 #include "core/dom/Document.h" |
| 8 #include "core/frame/FrameView.h" | 8 #include "core/frame/FrameView.h" |
| 9 #include "core/html/HTMLVideoElement.h" | 9 #include "core/html/HTMLVideoElement.h" |
| 10 #include "core/layout/LayoutVideo.h" | 10 #include "core/layout/LayoutVideo.h" |
| 11 #include "core/paint/ImagePainter.h" | 11 #include "core/paint/ImagePainter.h" |
| 12 #include "core/paint/LayoutObjectDrawingRecorder.h" | 12 #include "core/paint/LayoutObjectDrawingRecorder.h" |
| 13 #include "core/paint/PaintInfo.h" | 13 #include "core/paint/PaintInfo.h" |
| 14 #include "platform/geometry/LayoutPoint.h" | 14 #include "platform/geometry/LayoutPoint.h" |
| 15 #include "platform/graphics/paint/ClipRecorder.h" | |
| 16 #include "platform/graphics/paint/ForeignLayerDisplayItem.h" | 15 #include "platform/graphics/paint/ForeignLayerDisplayItem.h" |
| 17 | 16 |
| 18 namespace blink { | 17 namespace blink { |
| 19 | 18 |
| 20 void VideoPainter::paintReplaced(const PaintInfo& paintInfo, const LayoutPoint&
paintOffset) | 19 void VideoPainter::paintReplaced(const PaintInfo& paintInfo, const LayoutPoint&
paintOffset) |
| 21 { | 20 { |
| 22 WebMediaPlayer* mediaPlayer = m_layoutVideo.mediaElement()->webMediaPlayer()
; | 21 WebMediaPlayer* mediaPlayer = m_layoutVideo.mediaElement()->webMediaPlayer()
; |
| 23 bool displayingPoster = m_layoutVideo.videoElement()->shouldDisplayPosterIma
ge(); | 22 bool displayingPoster = m_layoutVideo.videoElement()->shouldDisplayPosterIma
ge(); |
| 24 if (!displayingPoster && !mediaPlayer) | 23 if (!displayingPoster && !mediaPlayer) |
| 25 return; | 24 return; |
| 26 | 25 |
| 27 LayoutRect rect(m_layoutVideo.videoBox()); | 26 LayoutRect rect(m_layoutVideo.videoBox()); |
| 28 if (rect.isEmpty()) | 27 if (rect.isEmpty()) |
| 29 return; | 28 return; |
| 30 rect.moveBy(paintOffset); | 29 rect.moveBy(paintOffset); |
| 31 | 30 |
| 31 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(paintInfo.contex
t, m_layoutVideo, paintInfo.phase)) |
| 32 return; |
| 33 |
| 32 GraphicsContext& context = paintInfo.context; | 34 GraphicsContext& context = paintInfo.context; |
| 33 LayoutRect contentRect = m_layoutVideo.contentBoxRect(); | 35 LayoutRect contentRect = m_layoutVideo.contentBoxRect(); |
| 34 contentRect.moveBy(paintOffset); | 36 contentRect.moveBy(paintOffset); |
| 35 | 37 |
| 36 Optional<ClipRecorder> clipRecorder; | |
| 37 if (!contentRect.contains(rect)) | |
| 38 clipRecorder.emplace(context, m_layoutVideo, paintInfo.displayItemTypeFo
rClipping(), pixelSnappedIntRect(contentRect)); | |
| 39 | |
| 40 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(context, m_layou
tVideo, paintInfo.phase)) | |
| 41 return; | |
| 42 | |
| 43 | |
| 44 // Video frames are only painted in software for printing or capturing node
images via web APIs. | 38 // Video frames are only painted in software for printing or capturing node
images via web APIs. |
| 45 bool forceSoftwareVideoPaint = paintInfo.getGlobalPaintFlags() & GlobalPaint
FlattenCompositingLayers; | 39 bool forceSoftwareVideoPaint = paintInfo.getGlobalPaintFlags() & GlobalPaint
FlattenCompositingLayers; |
| 46 | 40 |
| 47 bool paintWithForeignLayer = | 41 bool paintWithForeignLayer = |
| 48 !displayingPoster && !forceSoftwareVideoPaint | 42 !displayingPoster && !forceSoftwareVideoPaint |
| 49 && RuntimeEnabledFeatures::slimmingPaintV2Enabled(); | 43 && RuntimeEnabledFeatures::slimmingPaintV2Enabled(); |
| 50 if (paintWithForeignLayer) { | 44 if (paintWithForeignLayer) { |
| 51 if (WebLayer* layer = m_layoutVideo.mediaElement()->platformLayer()) { | 45 if (WebLayer* layer = m_layoutVideo.mediaElement()->platformLayer()) { |
| 52 IntRect pixelSnappedRect = pixelSnappedIntRect(contentRect); | 46 IntRect pixelSnappedRect = pixelSnappedIntRect(contentRect); |
| 53 recordForeignLayer( | 47 recordForeignLayer( |
| 54 context, m_layoutVideo, DisplayItem::ForeignLayerVideo, layer, | 48 context, m_layoutVideo, DisplayItem::ForeignLayerVideo, layer, |
| 55 pixelSnappedRect.location(), pixelSnappedRect.size()); | 49 pixelSnappedRect.location(), pixelSnappedRect.size()); |
| 56 return; | 50 return; |
| 57 } | 51 } |
| 58 } | 52 } |
| 59 | 53 |
| 60 LayoutObjectDrawingRecorder drawingRecorder(context, m_layoutVideo, paintInf
o.phase, contentRect); | 54 LayoutObjectDrawingRecorder drawingRecorder(context, m_layoutVideo, paintInf
o.phase, contentRect); |
| 61 | 55 |
| 62 if (displayingPoster || !forceSoftwareVideoPaint) { | 56 if (displayingPoster || !forceSoftwareVideoPaint) { |
| 63 // This will display the poster image, if one is present, and otherwise
paint nothing. | 57 // This will display the poster image, if one is present, and otherwise
paint nothing. |
| 64 ImagePainter(m_layoutVideo).paintIntoRect(context, rect); | 58 ImagePainter(m_layoutVideo).paintIntoRect(context, rect, contentRect); |
| 65 } else { | 59 } else { |
| 66 SkPaint videoPaint = context.fillPaint(); | 60 SkPaint videoPaint = context.fillPaint(); |
| 67 videoPaint.setColor(SK_ColorBLACK); | 61 videoPaint.setColor(SK_ColorBLACK); |
| 68 m_layoutVideo.videoElement()->paintCurrentFrame(context.canvas(), pixelS
nappedIntRect(rect), &videoPaint); | 62 m_layoutVideo.videoElement()->paintCurrentFrame(context.canvas(), pixelS
nappedIntRect(rect), &videoPaint); |
| 69 } | 63 } |
| 70 } | 64 } |
| 71 | 65 |
| 72 } // namespace blink | 66 } // namespace blink |
| OLD | NEW |