| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2007, 2008, 2009, 2010 Apple Inc. All rights reserved. | |
| 3 * | |
| 4 * Redistribution and use in source and binary forms, with or without | |
| 5 * modification, are permitted provided that the following conditions | |
| 6 * are met: | |
| 7 * 1. Redistributions of source code must retain the above copyright | |
| 8 * notice, this list of conditions and the following disclaimer. | |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | |
| 10 * notice, this list of conditions and the following disclaimer in the | |
| 11 * documentation and/or other materials provided with the distribution. | |
| 12 * | |
| 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY | |
| 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
| 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
| 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | |
| 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
| 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
| 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
| 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | |
| 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 24 */ | |
| 25 | |
| 26 #include "config.h" | |
| 27 | |
| 28 #include "core/rendering/RenderVideo.h" | |
| 29 | |
| 30 #include "core/dom/Document.h" | |
| 31 #include "core/frame/FrameView.h" | |
| 32 #include "core/frame/LocalFrame.h" | |
| 33 #include "core/html/HTMLVideoElement.h" | |
| 34 #include "core/rendering/PaintInfo.h" | |
| 35 #include "platform/graphics/media/MediaPlayer.h" | |
| 36 #include "public/platform/WebLayer.h" | |
| 37 | |
| 38 namespace blink { | |
| 39 | |
| 40 RenderVideo::RenderVideo(HTMLVideoElement* video) | |
| 41 : RenderMedia(video) | |
| 42 { | |
| 43 setIntrinsicSize(calculateIntrinsicSize()); | |
| 44 } | |
| 45 | |
| 46 RenderVideo::~RenderVideo() | |
| 47 { | |
| 48 } | |
| 49 | |
| 50 IntSize RenderVideo::defaultSize() | |
| 51 { | |
| 52 return IntSize(defaultWidth, defaultHeight); | |
| 53 } | |
| 54 | |
| 55 void RenderVideo::intrinsicSizeChanged() | |
| 56 { | |
| 57 if (videoElement()->shouldDisplayPosterImage()) | |
| 58 RenderMedia::intrinsicSizeChanged(); | |
| 59 updateIntrinsicSize(); | |
| 60 } | |
| 61 | |
| 62 void RenderVideo::updateIntrinsicSize() | |
| 63 { | |
| 64 LayoutSize size = calculateIntrinsicSize(); | |
| 65 size.scale(style()->effectiveZoom()); | |
| 66 | |
| 67 if (size == intrinsicSize()) | |
| 68 return; | |
| 69 | |
| 70 setIntrinsicSize(size); | |
| 71 setPreferredLogicalWidthsDirty(); | |
| 72 setNeedsLayoutAndFullPaintInvalidation(); | |
| 73 } | |
| 74 | |
| 75 LayoutSize RenderVideo::calculateIntrinsicSize() | |
| 76 { | |
| 77 HTMLVideoElement* video = videoElement(); | |
| 78 | |
| 79 // Spec text from 4.8.6 | |
| 80 // | |
| 81 // The intrinsic width of a video element's playback area is the intrinsic w
idth | |
| 82 // of the video resource, if that is available; otherwise it is the intrinsi
c | |
| 83 // width of the poster frame, if that is available; otherwise it is 300 CSS
pixels. | |
| 84 // | |
| 85 // The intrinsic height of a video element's playback area is the intrinsic
height | |
| 86 // of the video resource, if that is available; otherwise it is the intrinsi
c | |
| 87 // height of the poster frame, if that is available; otherwise it is 150 CSS
pixels. | |
| 88 WebMediaPlayer* webMediaPlayer = mediaElement()->webMediaPlayer(); | |
| 89 if (webMediaPlayer && video->readyState() >= HTMLVideoElement::HAVE_METADATA
) { | |
| 90 IntSize size = webMediaPlayer->naturalSize(); | |
| 91 if (!size.isEmpty()) | |
| 92 return size; | |
| 93 } | |
| 94 | |
| 95 if (video->shouldDisplayPosterImage() && !m_cachedImageSize.isEmpty() && !im
ageResource()->errorOccurred()) | |
| 96 return m_cachedImageSize; | |
| 97 | |
| 98 return defaultSize(); | |
| 99 } | |
| 100 | |
| 101 void RenderVideo::imageChanged(WrappedImagePtr newImage, const IntRect* rect) | |
| 102 { | |
| 103 RenderMedia::imageChanged(newImage, rect); | |
| 104 | |
| 105 // Cache the image intrinsic size so we can continue to use it to draw the i
mage correctly | |
| 106 // even if we know the video intrinsic size but aren't able to draw video fr
ames yet | |
| 107 // (we don't want to scale the poster to the video size without keeping aspe
ct ratio). | |
| 108 if (videoElement()->shouldDisplayPosterImage()) | |
| 109 m_cachedImageSize = intrinsicSize(); | |
| 110 | |
| 111 // The intrinsic size is now that of the image, but in case we already had t
he | |
| 112 // intrinsic size of the video we call this here to restore the video size. | |
| 113 updateIntrinsicSize(); | |
| 114 } | |
| 115 | |
| 116 IntRect RenderVideo::videoBox() const | |
| 117 { | |
| 118 const LayoutSize* overriddenIntrinsicSize = 0; | |
| 119 if (videoElement()->shouldDisplayPosterImage()) | |
| 120 overriddenIntrinsicSize = &m_cachedImageSize; | |
| 121 | |
| 122 return pixelSnappedIntRect(replacedContentRect(overriddenIntrinsicSize)); | |
| 123 } | |
| 124 | |
| 125 bool RenderVideo::shouldDisplayVideo() const | |
| 126 { | |
| 127 return !videoElement()->shouldDisplayPosterImage(); | |
| 128 } | |
| 129 | |
| 130 void RenderVideo::paintReplaced(PaintInfo& paintInfo, const LayoutPoint& paintOf
fset) | |
| 131 { | |
| 132 MediaPlayer* mediaPlayer = mediaElement()->player(); | |
| 133 bool displayingPoster = videoElement()->shouldDisplayPosterImage(); | |
| 134 if (!displayingPoster && !mediaPlayer) | |
| 135 return; | |
| 136 | |
| 137 LayoutRect rect = videoBox(); | |
| 138 if (rect.isEmpty()) | |
| 139 return; | |
| 140 rect.moveBy(paintOffset); | |
| 141 | |
| 142 LayoutRect contentRect = contentBoxRect(); | |
| 143 contentRect.moveBy(paintOffset); | |
| 144 GraphicsContext* context = paintInfo.context; | |
| 145 bool clip = !contentRect.contains(rect); | |
| 146 if (clip) { | |
| 147 context->save(); | |
| 148 context->clip(contentRect); | |
| 149 } | |
| 150 | |
| 151 if (displayingPoster) | |
| 152 paintIntoRect(context, rect); | |
| 153 else if ((document().view() && document().view()->paintBehavior() & PaintBeh
aviorFlattenCompositingLayers) || !acceleratedRenderingInUse()) | |
| 154 videoElement()->paintCurrentFrameInContext(context, pixelSnappedIntRect(
rect)); | |
| 155 | |
| 156 if (clip) | |
| 157 context->restore(); | |
| 158 } | |
| 159 | |
| 160 bool RenderVideo::acceleratedRenderingInUse() | |
| 161 { | |
| 162 WebLayer* webLayer = mediaElement()->platformLayer(); | |
| 163 return webLayer && !webLayer->isOrphan(); | |
| 164 } | |
| 165 | |
| 166 void RenderVideo::layout() | |
| 167 { | |
| 168 updatePlayer(); | |
| 169 RenderMedia::layout(); | |
| 170 } | |
| 171 | |
| 172 HTMLVideoElement* RenderVideo::videoElement() const | |
| 173 { | |
| 174 return toHTMLVideoElement(node()); | |
| 175 } | |
| 176 | |
| 177 void RenderVideo::updateFromElement() | |
| 178 { | |
| 179 RenderMedia::updateFromElement(); | |
| 180 updatePlayer(); | |
| 181 } | |
| 182 | |
| 183 void RenderVideo::updatePlayer() | |
| 184 { | |
| 185 updateIntrinsicSize(); | |
| 186 | |
| 187 MediaPlayer* mediaPlayer = mediaElement()->player(); | |
| 188 if (!mediaPlayer) | |
| 189 return; | |
| 190 | |
| 191 if (!videoElement()->isActive()) | |
| 192 return; | |
| 193 | |
| 194 videoElement()->setNeedsCompositingUpdate(); | |
| 195 } | |
| 196 | |
| 197 LayoutUnit RenderVideo::computeReplacedLogicalWidth(ShouldComputePreferred shoul
dComputePreferred) const | |
| 198 { | |
| 199 return RenderReplaced::computeReplacedLogicalWidth(shouldComputePreferred); | |
| 200 } | |
| 201 | |
| 202 LayoutUnit RenderVideo::computeReplacedLogicalHeight() const | |
| 203 { | |
| 204 return RenderReplaced::computeReplacedLogicalHeight(); | |
| 205 } | |
| 206 | |
| 207 LayoutUnit RenderVideo::minimumReplacedHeight() const | |
| 208 { | |
| 209 return RenderReplaced::minimumReplacedHeight(); | |
| 210 } | |
| 211 | |
| 212 bool RenderVideo::supportsAcceleratedRendering() const | |
| 213 { | |
| 214 return !!mediaElement()->platformLayer(); | |
| 215 } | |
| 216 | |
| 217 CompositingReasons RenderVideo::additionalCompositingReasons() const | |
| 218 { | |
| 219 if (RuntimeEnabledFeatures::overlayFullscreenVideoEnabled()) { | |
| 220 HTMLMediaElement* media = toHTMLMediaElement(node()); | |
| 221 if (media->isFullscreen()) | |
| 222 return CompositingReasonVideo; | |
| 223 } | |
| 224 | |
| 225 if (shouldDisplayVideo() && supportsAcceleratedRendering()) | |
| 226 return CompositingReasonVideo; | |
| 227 | |
| 228 return CompositingReasonNone; | |
| 229 } | |
| 230 | |
| 231 } // namespace blink | |
| OLD | NEW |