Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / web / WebMediaPlayerClientImpl.cpp
index daf6809..743061e 100644 (file)
@@ -48,8 +48,6 @@
 #include "wtf/Assertions.h"
 #include "wtf/text/CString.h"
 
-using namespace WebCore;
-
 namespace blink {
 
 static PassOwnPtr<WebMediaPlayer> createWebMediaPlayer(WebMediaPlayerClient* client, const WebURL& url, LocalFrame* frame)
@@ -106,21 +104,11 @@ void WebMediaPlayerClientImpl::sizeChanged()
     m_client->mediaPlayerSizeChanged();
 }
 
-double WebMediaPlayerClientImpl::volume() const
-{
-    return mediaElement().playerVolume();
-}
-
 void WebMediaPlayerClientImpl::playbackStateChanged()
 {
     m_client->mediaPlayerPlaybackStateChanged();
 }
 
-WebMediaPlayer::Preload WebMediaPlayerClientImpl::preload() const
-{
-    return static_cast<WebMediaPlayer::Preload>(m_preload);
-}
-
 void WebMediaPlayerClientImpl::keyAdded(const WebString& keySystem, const WebString& sessionId)
 {
     HTMLMediaElementEncryptedMedia::keyAdded(mediaElement(), keySystem, sessionId);
@@ -141,7 +129,7 @@ void WebMediaPlayerClientImpl::keyNeeded(const WebString& contentType, const uns
     HTMLMediaElementEncryptedMedia::keyNeeded(mediaElement(), contentType, initData, initDataLength);
 }
 
-void WebMediaPlayerClientImpl::setWebLayer(blink::WebLayer* layer)
+void WebMediaPlayerClientImpl::setWebLayer(WebLayer* layer)
 {
     m_client->mediaPlayerSetWebLayer(layer);
 }
@@ -212,167 +200,21 @@ void WebMediaPlayerClientImpl::load(WebMediaPlayer::LoadType loadType, const WTF
     m_audioSourceProvider.wrap(m_webMediaPlayer->audioSourceProvider());
 #endif
 
-    m_webMediaPlayer->setVolume(mediaElement().playerVolume());
+    m_webMediaPlayer->setVolume(mediaElement().effectiveMediaVolume());
 
     m_webMediaPlayer->setPoster(poster);
 
-#if OS(ANDROID)
-    m_usePaintOnAndroid = (loadType != WebMediaPlayer::LoadTypeMediaStream);
-#endif
-
     // Tell WebMediaPlayer about any connected CDM (may be null).
     m_webMediaPlayer->setContentDecryptionModule(HTMLMediaElementEncryptedMedia::contentDecryptionModule(mediaElement()));
     m_webMediaPlayer->load(loadType, kurl, corsMode);
 }
 
-void WebMediaPlayerClientImpl::play()
-{
-    if (m_webMediaPlayer)
-        m_webMediaPlayer->play();
-}
-
-void WebMediaPlayerClientImpl::pause()
-{
-    if (m_webMediaPlayer)
-        m_webMediaPlayer->pause();
-}
-
-double WebMediaPlayerClientImpl::duration() const
-{
-    if (m_webMediaPlayer)
-        return m_webMediaPlayer->duration();
-    return 0.0;
-}
-
-double WebMediaPlayerClientImpl::currentTime() const
-{
-    if (m_webMediaPlayer)
-        return m_webMediaPlayer->currentTime();
-    return 0.0;
-}
-
-void WebMediaPlayerClientImpl::seek(double time)
-{
-    if (m_webMediaPlayer)
-        m_webMediaPlayer->seek(time);
-}
-
-bool WebMediaPlayerClientImpl::seeking() const
-{
-    if (m_webMediaPlayer)
-        return m_webMediaPlayer->seeking();
-    return false;
-}
-
-double WebMediaPlayerClientImpl::rate() const
-{
-    return m_rate;
-}
-
-void WebMediaPlayerClientImpl::setRate(double rate)
-{
-    m_rate = rate;
-    if (m_webMediaPlayer)
-        m_webMediaPlayer->setRate(rate);
-}
-
-bool WebMediaPlayerClientImpl::paused() const
-{
-    if (m_webMediaPlayer)
-        return m_webMediaPlayer->paused();
-    return false;
-}
-
-bool WebMediaPlayerClientImpl::supportsSave() const
-{
-    if (m_webMediaPlayer)
-        return m_webMediaPlayer->supportsSave();
-    return false;
-}
-
-void WebMediaPlayerClientImpl::setPoster(const KURL& poster)
-{
-    if (m_webMediaPlayer)
-        m_webMediaPlayer->setPoster(WebURL(poster));
-}
-
-MediaPlayer::NetworkState WebMediaPlayerClientImpl::networkState() const
-{
-    if (m_webMediaPlayer)
-        return static_cast<MediaPlayer::NetworkState>(m_webMediaPlayer->networkState());
-    return MediaPlayer::Empty;
-}
-
-double WebMediaPlayerClientImpl::maxTimeSeekable() const
-{
-    if (m_webMediaPlayer)
-        return m_webMediaPlayer->maxTimeSeekable();
-    return 0.0;
-}
-
-PassRefPtr<TimeRanges> WebMediaPlayerClientImpl::buffered() const
-{
-    if (m_webMediaPlayer)
-        return TimeRanges::create(m_webMediaPlayer->buffered());
-    return TimeRanges::create();
-}
-
-bool WebMediaPlayerClientImpl::didLoadingProgress() const
-{
-    return m_webMediaPlayer && m_webMediaPlayer->didLoadingProgress();
-}
-
-void WebMediaPlayerClientImpl::paint(GraphicsContext* context, const IntRect& rect)
-{
-    // Normally GraphicsContext operations do nothing when painting is disabled.
-    // Since we're accessing platformContext() directly we have to manually
-    // check.
-    if (m_webMediaPlayer && !context->paintingDisabled()) {
-        // On Android, video frame is emitted as GL_TEXTURE_EXTERNAL_OES texture. We use a different path to
-        // paint the video frame into the context.
-#if OS(ANDROID)
-        if (m_usePaintOnAndroid) {
-            paintOnAndroid(context, rect, context->getNormalizedAlpha());
-            return;
-        }
-#endif
-        WebCanvas* canvas = context->canvas();
-        m_webMediaPlayer->paint(canvas, rect, context->getNormalizedAlpha());
-    }
-}
-
-bool WebMediaPlayerClientImpl::copyVideoTextureToPlatformTexture(WebGraphicsContext3D* context, Platform3DObject texture, GLint level, GLenum type, GLenum internalFormat, bool premultiplyAlpha, bool flipY)
-{
-    if (!context || !m_webMediaPlayer)
-        return false;
-    if (!Extensions3DUtil::canUseCopyTextureCHROMIUM(internalFormat, type, level) || !context->makeContextCurrent())
-        return false;
-
-    return m_webMediaPlayer->copyVideoTextureToPlatformTexture(context, texture, level, internalFormat, type, premultiplyAlpha, flipY);
-}
-
 void WebMediaPlayerClientImpl::setPreload(MediaPlayer::Preload preload)
 {
-    m_preload = preload;
-
     if (m_webMediaPlayer)
         m_webMediaPlayer->setPreload(static_cast<WebMediaPlayer::Preload>(preload));
 }
 
-bool WebMediaPlayerClientImpl::hasSingleSecurityOrigin() const
-{
-    if (m_webMediaPlayer)
-        return m_webMediaPlayer->hasSingleSecurityOrigin();
-    return false;
-}
-
-double WebMediaPlayerClientImpl::mediaTimeForTimeValue(double timeValue) const
-{
-    if (m_webMediaPlayer)
-        return m_webMediaPlayer->mediaTimeForTimeValue(timeValue);
-    return timeValue;
-}
-
 #if ENABLE(WEB_AUDIO)
 AudioSourceProvider* WebMediaPlayerClientImpl::audioSourceProvider()
 {
@@ -385,55 +227,13 @@ PassOwnPtr<MediaPlayer> WebMediaPlayerClientImpl::create(MediaPlayerClient* clie
     return adoptPtr(new WebMediaPlayerClientImpl(client));
 }
 
-#if OS(ANDROID)
-void WebMediaPlayerClientImpl::paintOnAndroid(WebCore::GraphicsContext* context, const IntRect& rect, uint8_t alpha)
-{
-    OwnPtr<blink::WebGraphicsContext3DProvider> provider = adoptPtr(blink::Platform::current()->createSharedOffscreenGraphicsContext3DProvider());
-    if (!provider)
-        return;
-    WebGraphicsContext3D* context3D = provider->context3d();
-    if (!context || !context3D || !m_webMediaPlayer || context->paintingDisabled())
-        return;
-
-    if (!context3D->makeContextCurrent())
-        return;
-
-    // Copy video texture into a RGBA texture based bitmap first as video texture on Android is GL_TEXTURE_EXTERNAL_OES
-    // which is not supported by Skia yet. The bitmap's size needs to be the same as the video and use naturalSize() here.
-    // Check if we could reuse existing texture based bitmap.
-    // Otherwise, release existing texture based bitmap and allocate a new one based on video size.
-    if (!ensureTextureBackedSkBitmap(provider->grContext(), m_bitmap, m_webMediaPlayer->naturalSize(), kTopLeft_GrSurfaceOrigin, kSkia8888_GrPixelConfig))
-        return;
-
-    // Copy video texture to bitmap texture.
-    WebCanvas* canvas = context->canvas();
-    unsigned textureId = static_cast<unsigned>((m_bitmap.getTexture())->getTextureHandle());
-    if (!m_webMediaPlayer->copyVideoTextureToPlatformTexture(context3D, textureId, 0, GL_RGBA, GL_UNSIGNED_BYTE, true, false))
-        return;
-
-    // Draw the texture based bitmap onto the Canvas. If the canvas is hardware based, this will do a GPU-GPU texture copy. If the canvas is software based,
-    // the texture based bitmap will be readbacked to system memory then draw onto the canvas.
-    SkRect dest;
-    dest.set(rect.x(), rect.y(), rect.x() + rect.width(), rect.y() + rect.height());
-    SkPaint paint;
-    paint.setAlpha(alpha);
-    // It is not necessary to pass the dest into the drawBitmap call since all the context have been set up before calling paintCurrentFrameInContext.
-    canvas->drawBitmapRect(m_bitmap, NULL, dest, &paint);
-}
-#endif
-
 WebMediaPlayerClientImpl::WebMediaPlayerClientImpl(MediaPlayerClient* client)
     : m_client(client)
-    , m_preload(MediaPlayer::Auto)
-    , m_rate(1.0)
-#if OS(ANDROID)
-    , m_usePaintOnAndroid(false)
-#endif
 {
     ASSERT(m_client);
 }
 
-WebCore::HTMLMediaElement& WebMediaPlayerClientImpl::mediaElement() const
+HTMLMediaElement& WebMediaPlayerClientImpl::mediaElement() const
 {
     return *static_cast<HTMLMediaElement*>(m_client);
 }
@@ -456,7 +256,7 @@ void WebMediaPlayerClientImpl::AudioSourceProviderImpl::setClient(AudioSourcePro
     MutexLocker locker(provideInputLock);
 
     if (client)
-        m_client = adoptPtr(new WebMediaPlayerClientImpl::AudioClientImpl(client));
+        m_client = adoptPtrWillBeNoop(new WebMediaPlayerClientImpl::AudioClientImpl(client));
     else
         m_client.clear();
 
@@ -491,6 +291,11 @@ void WebMediaPlayerClientImpl::AudioClientImpl::setFormat(size_t numberOfChannel
         m_client->setFormat(numberOfChannels, sampleRate);
 }
 
+void WebMediaPlayerClientImpl::AudioClientImpl::trace(Visitor* visitor)
+{
+    visitor->trace(m_client);
+}
+
 #endif
 
 } // namespace blink