[chromium] Move ownership of compositor VideoLayer to WebMediaPlayer
authordanakj@chromium.org <danakj@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 26 Mar 2013 03:02:47 +0000 (03:02 +0000)
committerdanakj@chromium.org <danakj@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 26 Mar 2013 03:02:47 +0000 (03:02 +0000)
https://bugs.webkit.org/show_bug.cgi?id=112971

Reviewed by James Robinson.

Source/Platform:

Defines REMOVE_WEBVIDEOFRAME in related headers to enable this code
path in chromium.

* chromium/public/WebVideoFrame.h:
* chromium/public/WebVideoFrameProvider.h:

Source/WebKit/chromium:

This moves ownership of the compositor's video layer over to the
implementation of WebMediaPlayer, as well as all interaction
between the media player system and the compositor layer or its
interfaces such as cc::VideoFrameProvider.

Now, the WebMediaPlayer implementation calls setWebLayer() to
provide the WebLayer* to the WebMediaPlayerClientImpl so that
it can be inserted into the GraphicsLayer tree appropriately.

Defines REMOVE_WEBVIDEOFRAME in related headers to enable this code
path in chromium.

Once chromium removes its use of WebVideoFrame and its related
classes, we can remove them from WebKit entirely.

* WebKit.gypi:
* public/WebMediaPlayer.h:
(WebKit):
* public/WebMediaPlayerClient.h:
* public/WebStreamTextureClient.h:
* src/WebMediaPlayerClientImpl.cpp:
(WebKit::WebMediaPlayerClientImpl::~WebMediaPlayerClientImpl):
(WebKit::WebMediaPlayerClientImpl::readyStateChanged):
(WebKit::WebMediaPlayerClientImpl::repaint):
(WebKit::WebMediaPlayerClientImpl::setOpaque):
(WebKit::WebMediaPlayerClientImpl::setWebLayer):
(WebKit::WebMediaPlayerClientImpl::loadRequested):
(WebKit::WebMediaPlayerClientImpl::platformLayer):
(WebKit::WebMediaPlayerClientImpl::paint):
(WebKit::WebMediaPlayerClientImpl::needsWebLayer):
(WebKit::WebMediaPlayerClientImpl::supportsAcceleratedRendering):
(WebKit::WebMediaPlayerClientImpl::acceleratedRenderingInUse):
(WebKit::WebMediaPlayerClientImpl::create):
(WebKit::WebMediaPlayerClientImpl::supportsType):
* src/WebMediaPlayerClientImpl.h:
(WebKit):
(WebMediaPlayerClientImpl):
* tests/WebMediaPlayerClientImplTest.cpp: Removed.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@146843 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/Platform/ChangeLog
Source/Platform/chromium/public/WebVideoFrame.h
Source/WebKit/chromium/ChangeLog
Source/WebKit/chromium/WebKit.gypi
Source/WebKit/chromium/public/WebMediaPlayerClient.h
Source/WebKit/chromium/src/WebMediaPlayerClientImpl.cpp
Source/WebKit/chromium/src/WebMediaPlayerClientImpl.h
Source/WebKit/chromium/tests/WebMediaPlayerClientImplTest.cpp [deleted file]

index b62997b..5822342 100644 (file)
@@ -1,3 +1,16 @@
+2013-03-25  Dana Jansens  <danakj@chromium.org>
+
+        [chromium] Move ownership of compositor VideoLayer to WebMediaPlayer
+        https://bugs.webkit.org/show_bug.cgi?id=112971
+
+        Reviewed by James Robinson.
+
+        Defines REMOVE_WEBVIDEOFRAME in related headers to enable this code
+        path in chromium.
+
+        * chromium/public/WebVideoFrame.h:
+        * chromium/public/WebVideoFrameProvider.h:
+
 2013-03-25  Sheriff Bot  <webkit.review.bot@gmail.com>
 
         Unreviewed, rolling out r146819.
index 0cf3e7c..36dc2e4 100644 (file)
@@ -31,6 +31,8 @@
 #ifndef WebVideoFrame_h
 #define WebVideoFrame_h
 
+#define REMOVE_WEBVIDEOFRAME
+
 #include "WebRect.h"
 #include "WebSize.h"
 
index 0f10ae7..2497649 100644 (file)
@@ -1,3 +1,49 @@
+2013-03-25  Dana Jansens  <danakj@chromium.org>
+
+        [chromium] Move ownership of compositor VideoLayer to WebMediaPlayer
+        https://bugs.webkit.org/show_bug.cgi?id=112971
+
+        Reviewed by James Robinson.
+
+        This moves ownership of the compositor's video layer over to the
+        implementation of WebMediaPlayer, as well as all interaction
+        between the media player system and the compositor layer or its
+        interfaces such as cc::VideoFrameProvider.
+
+        Now, the WebMediaPlayer implementation calls setWebLayer() to
+        provide the WebLayer* to the WebMediaPlayerClientImpl so that
+        it can be inserted into the GraphicsLayer tree appropriately.
+
+        Defines REMOVE_WEBVIDEOFRAME in related headers to enable this code
+        path in chromium.
+
+        Once chromium removes its use of WebVideoFrame and its related
+        classes, we can remove them from WebKit entirely.
+
+        * WebKit.gypi:
+        * public/WebMediaPlayer.h:
+        (WebKit):
+        * public/WebMediaPlayerClient.h:
+        * public/WebStreamTextureClient.h:
+        * src/WebMediaPlayerClientImpl.cpp:
+        (WebKit::WebMediaPlayerClientImpl::~WebMediaPlayerClientImpl):
+        (WebKit::WebMediaPlayerClientImpl::readyStateChanged):
+        (WebKit::WebMediaPlayerClientImpl::repaint):
+        (WebKit::WebMediaPlayerClientImpl::setOpaque):
+        (WebKit::WebMediaPlayerClientImpl::setWebLayer):
+        (WebKit::WebMediaPlayerClientImpl::loadRequested):
+        (WebKit::WebMediaPlayerClientImpl::platformLayer):
+        (WebKit::WebMediaPlayerClientImpl::paint):
+        (WebKit::WebMediaPlayerClientImpl::needsWebLayer):
+        (WebKit::WebMediaPlayerClientImpl::supportsAcceleratedRendering):
+        (WebKit::WebMediaPlayerClientImpl::acceleratedRenderingInUse):
+        (WebKit::WebMediaPlayerClientImpl::create):
+        (WebKit::WebMediaPlayerClientImpl::supportsType):
+        * src/WebMediaPlayerClientImpl.h:
+        (WebKit):
+        (WebMediaPlayerClientImpl):
+        * tests/WebMediaPlayerClientImplTest.cpp: Removed.
+
 2013-03-25  Sheriff Bot  <webkit.review.bot@gmail.com>
 
         Unreviewed.  Rolled Chromium DEPS to r190515.  Requested by
index 89c8259..6e4a4d8 100644 (file)
             'tests/WebImageTest.cpp',
             'tests/WebInputEventConversionTest.cpp',
             'tests/WebInputEventFactoryTestMac.mm',
-            'tests/WebMediaPlayerClientImplTest.cpp',
             'tests/WebPageNewSerializerTest.cpp',
             'tests/WebPageSerializerTest.cpp',
             'tests/WebPluginContainerTest.cpp',
index 089937c..8161ae6 100644 (file)
@@ -36,6 +36,7 @@
 namespace WebKit {
 
 class WebFrame;
+class WebLayer;
 class WebMediaSource;
 class WebPlugin;
 class WebRequest;
@@ -80,7 +81,8 @@ public:
     // Returns 0 if the plugin could not be instantiated.
     virtual WebPlugin* createHelperPlugin(const WebString& pluginType, WebFrame*) = 0;
     virtual void closeHelperPlugin() = 0;
-    virtual void disableAcceleratedCompositing() = 0;
+    virtual bool needsWebLayerForVideo() const = 0;
+    virtual void setWebLayer(WebLayer*) = 0;
 protected:
     ~WebMediaPlayerClient() { }
 };
index aab74e2..bc77af2 100644 (file)
@@ -39,7 +39,6 @@
 #include <public/WebSize.h>
 #include <public/WebString.h>
 #include <public/WebURL.h>
-#include <public/WebVideoLayer.h>
 
 #if USE(ACCELERATED_COMPOSITING)
 #include "RenderLayerCompositor.h"
@@ -94,21 +93,6 @@ WebMediaPlayer* WebMediaPlayerClientImpl::mediaPlayer() const
 
 WebMediaPlayerClientImpl::~WebMediaPlayerClientImpl()
 {
-#if USE(ACCELERATED_COMPOSITING)
-    if (m_videoFrameProviderClient)
-        m_videoFrameProviderClient->stopUsingProvider();
-    // No need for a lock here, as getCurrentFrame/putCurrentFrame can't be
-    // called now that the client is no longer using this provider. Also, load()
-    // and this destructor are called from the same thread.
-    if (m_webMediaPlayer)
-        m_webMediaPlayer->setStreamTextureClient(0);
-#endif
-
-#if USE(ACCELERATED_COMPOSITING)
-    if (m_videoLayer)
-        GraphicsLayerChromium::unregisterContentsLayer(m_videoLayer->layer());
-#endif
-
     // Explicitly destroy the WebMediaPlayer to allow verification of tear down.
     m_webMediaPlayer.clear();
 
@@ -130,14 +114,6 @@ void WebMediaPlayerClientImpl::readyStateChanged()
 {
     ASSERT(m_mediaPlayer);
     m_mediaPlayer->readyStateChanged();
-#if USE(ACCELERATED_COMPOSITING)
-    if (hasVideo() && supportsAcceleratedRendering() && !m_videoLayer) {
-        m_videoLayer = adoptPtr(Platform::current()->compositorSupport()->createVideoLayer(this));
-
-        m_videoLayer->layer()->setOpaque(m_opaque);
-        GraphicsLayerChromium::registerContentsLayer(m_videoLayer->layer());
-    }
-#endif
 }
 
 void WebMediaPlayerClientImpl::volumeChanged(float newVolume)
@@ -161,10 +137,8 @@ void WebMediaPlayerClientImpl::timeChanged()
 void WebMediaPlayerClientImpl::repaint()
 {
     ASSERT(m_mediaPlayer);
-#if USE(ACCELERATED_COMPOSITING)
-    if (m_videoLayer && supportsAcceleratedRendering())
-        m_videoLayer->layer()->invalidate();
-#endif
+    if (m_videoLayer)
+        m_videoLayer->invalidate();
     m_mediaPlayer->repaint();
 }
 
@@ -191,7 +165,7 @@ void WebMediaPlayerClientImpl::setOpaque(bool opaque)
 #if USE(ACCELERATED_COMPOSITING)
     m_opaque = opaque;
     if (m_videoLayer)
-        m_videoLayer->layer()->setOpaque(m_opaque);
+        m_videoLayer->setOpaque(m_opaque);
 #endif
 }
 
@@ -299,9 +273,25 @@ void WebMediaPlayerClientImpl::closeHelperPlugin()
     m_helperPlugin = 0;
 }
 
-void WebMediaPlayerClientImpl::disableAcceleratedCompositing()
+void WebMediaPlayerClientImpl::setWebLayer(WebLayer* layer)
 {
-    m_supportsAcceleratedCompositing = false;
+    if (layer == m_videoLayer)
+        return;
+
+    // If either of the layers is null we need to enable or disable compositing. This is done by triggering a style recalc.
+    if (!m_videoLayer || !layer) {
+        HTMLMediaElement* element = static_cast<HTMLMediaElement*>(m_mediaPlayer->mediaPlayerClient());
+        if (element)
+            element->setNeedsStyleRecalc(WebCore::SyntheticStyleChange);
+    }
+
+    if (m_videoLayer)
+        GraphicsLayerChromium::unregisterContentsLayer(m_videoLayer);
+    m_videoLayer = layer;
+    if (m_videoLayer) {
+        m_videoLayer->setOpaque(m_opaque);
+        GraphicsLayerChromium::registerContentsLayer(m_videoLayer);
+    }
 }
 
 // MediaPlayerPrivateInterface -------------------------------------------------
@@ -326,7 +316,6 @@ void WebMediaPlayerClientImpl::load(const String& url, PassRefPtr<WebCore::Media
 
 void WebMediaPlayerClientImpl::loadRequested()
 {
-    MutexLocker locker(m_webMediaPlayerMutex);
     if (m_preload == MediaPlayer::None) {
 #if ENABLE(WEB_AUDIO)
         m_audioSourceProvider.wrap(0); // Clear weak reference to m_webMediaPlayer's WebAudioSourceProvider.
@@ -344,6 +333,13 @@ void WebMediaPlayerClientImpl::loadInternal()
 #endif
 
     Frame* frame = static_cast<HTMLMediaElement*>(m_mediaPlayer->mediaPlayerClient())->document()->frame();
+
+    // This does not actually check whether the hardware can support accelerated
+    // compositing, but only if the flag is set. However, this is checked lazily
+    // in WebViewImpl::setIsAcceleratedCompositingActive() and will fail there
+    // if necessary.
+    m_needsWebLayerForVideo = frame->contentRenderer()->compositor()->hasAcceleratedCompositing();
+
     m_webMediaPlayer = createWebMediaPlayer(this, m_url, frame);
     if (m_webMediaPlayer) {
 #if ENABLE(WEB_AUDIO)
@@ -368,13 +364,10 @@ void WebMediaPlayerClientImpl::cancelLoad()
         m_webMediaPlayer->cancelLoad();
 }
 
-#if USE(ACCELERATED_COMPOSITING)
 WebLayer* WebMediaPlayerClientImpl::platformLayer() const
 {
-    ASSERT(m_supportsAcceleratedCompositing);
-    return m_videoLayer ? m_videoLayer->layer() : 0;
+    return m_videoLayer;
 }
-#endif
 
 PlatformMedia WebMediaPlayerClientImpl::platformMedia() const
 {
@@ -612,12 +605,10 @@ void WebMediaPlayerClientImpl::setSize(const IntSize& size)
 
 void WebMediaPlayerClientImpl::paint(GraphicsContext* context, const IntRect& rect)
 {
-#if USE(ACCELERATED_COMPOSITING)
     // If we are using GPU to render video, ignore requests to paint frames into
-    // canvas because it will be taken care of by WebVideoLayer.
+    // canvas because it will be taken care of by the VideoLayer.
     if (acceleratedRenderingInUse())
         return;
-#endif
     paintCurrentFrameInContext(context, rect);
 }
 
@@ -719,69 +710,25 @@ AudioSourceProvider* WebMediaPlayerClientImpl::audioSourceProvider()
 }
 #endif
 
-#if USE(ACCELERATED_COMPOSITING)
-bool WebMediaPlayerClientImpl::supportsAcceleratedRendering() const
-{
-    return m_supportsAcceleratedCompositing;
-}
-
-bool WebMediaPlayerClientImpl::acceleratedRenderingInUse()
-{
-    return m_videoLayer && m_videoLayer->active();
-}
-
-void WebMediaPlayerClientImpl::setVideoFrameProviderClient(WebVideoFrameProvider::Client* client)
+bool WebMediaPlayerClientImpl::needsWebLayerForVideo() const
 {
-    MutexLocker locker(m_webMediaPlayerMutex);
-    if (m_videoFrameProviderClient)
-        m_videoFrameProviderClient->stopUsingProvider();
-    m_videoFrameProviderClient = client;
-    if (m_webMediaPlayer)
-        m_webMediaPlayer->setStreamTextureClient(client ? this : 0);
+    return m_needsWebLayerForVideo;
 }
 
-WebVideoFrame* WebMediaPlayerClientImpl::getCurrentFrame()
+bool WebMediaPlayerClientImpl::supportsAcceleratedRendering() const
 {
-    // This function is called only by the client.
-    MutexLocker locker(m_webMediaPlayerMutex);
-    ASSERT(!m_currentVideoFrame);
-    ASSERT(m_videoFrameProviderClient);
-    if (m_webMediaPlayer)
-        m_currentVideoFrame = m_webMediaPlayer->getCurrentFrame();
-    return m_currentVideoFrame;
+    return !!m_videoLayer;
 }
 
-void WebMediaPlayerClientImpl::putCurrentFrame(WebVideoFrame* videoFrame)
+bool WebMediaPlayerClientImpl::acceleratedRenderingInUse()
 {
-    // This function is called only by the client.
-    MutexLocker locker(m_webMediaPlayerMutex);
-    ASSERT(videoFrame == m_currentVideoFrame);
-    ASSERT(m_videoFrameProviderClient);
-    if (!videoFrame)
-        return;
-    if (m_webMediaPlayer)
-        m_webMediaPlayer->putCurrentFrame(videoFrame);
-    m_currentVideoFrame = 0;
+    return m_videoLayer && !m_videoLayer->isOrphan();
 }
-#endif
 
 PassOwnPtr<MediaPlayerPrivateInterface> WebMediaPlayerClientImpl::create(MediaPlayer* player)
 {
     OwnPtr<WebMediaPlayerClientImpl> client = adoptPtr(new WebMediaPlayerClientImpl());
     client->m_mediaPlayer = player;
-
-#if USE(ACCELERATED_COMPOSITING)
-    Frame* frame = static_cast<HTMLMediaElement*>(
-        client->m_mediaPlayer->mediaPlayerClient())->document()->frame();
-
-    // This does not actually check whether the hardware can support accelerated
-    // compositing, but only if the flag is set. However, this is checked lazily
-    // in WebViewImpl::setIsAcceleratedCompositingActive() and will fail there
-    // if necessary.
-    client->m_supportsAcceleratedCompositing =
-        frame->contentRenderer()->compositor()->hasAcceleratedCompositing();
-#endif
-
     return client.release();
 }
 
@@ -829,28 +776,13 @@ void WebMediaPlayerClientImpl::startDelayedLoad()
     loadInternal();
 }
 
-void WebMediaPlayerClientImpl::didReceiveFrame()
-{
-    // No lock since this gets called on the client's thread.
-    m_videoFrameProviderClient->didReceiveFrame();
-}
-
-void WebMediaPlayerClientImpl::didUpdateMatrix(const float* matrix)
-{
-    // No lock since this gets called on the client's thread.
-    m_videoFrameProviderClient->didUpdateMatrix(matrix);
-}
-
 WebMediaPlayerClientImpl::WebMediaPlayerClientImpl()
     : m_mediaPlayer(0)
-    , m_currentVideoFrame(0)
     , m_delayingLoad(false)
     , m_preload(MediaPlayer::MetaData)
-#if USE(ACCELERATED_COMPOSITING)
-    , m_supportsAcceleratedCompositing(false)
+    , m_videoLayer(0)
     , m_opaque(false)
-    , m_videoFrameProviderClient(0)
-#endif
+    , m_needsWebLayerForVideo(false)
 {
 }
 
index 82d8f27..32e3c4d 100644 (file)
@@ -37,8 +37,6 @@
 #include "MediaPlayerPrivate.h"
 #include "WebAudioSourceProviderClient.h"
 #include "WebMediaPlayerClient.h"
-#include "WebStreamTextureClient.h"
-#include <public/WebVideoFrameProvider.h>
 #include <wtf/OwnPtr.h>
 #include <wtf/PassOwnPtr.h>
 
@@ -49,16 +47,10 @@ namespace WebKit {
 class WebHelperPluginImpl;
 class WebAudioSourceProvider;
 class WebMediaPlayer;
-class WebVideoLayer;
 
 // This class serves as a bridge between WebCore::MediaPlayer and
 // WebKit::WebMediaPlayer.
-class WebMediaPlayerClientImpl : public WebCore::MediaPlayerPrivateInterface
-#if USE(ACCELERATED_COMPOSITING)
-                               , public WebVideoFrameProvider
-#endif
-                               , public WebMediaPlayerClient
-                               , public WebStreamTextureClient {
+class WebMediaPlayerClientImpl : public WebCore::MediaPlayerPrivateInterface, public WebMediaPlayerClient {
 
 public:
     static bool isEnabled();
@@ -90,7 +82,8 @@ public:
     virtual void keyNeeded(const WebString& keySystem, const WebString& sessionId, const unsigned char* initData, unsigned initDataLength);
     virtual WebPlugin* createHelperPlugin(const WebString& pluginType, WebFrame*);
     virtual void closeHelperPlugin();
-    virtual void disableAcceleratedCompositing();
+    virtual bool needsWebLayerForVideo() const;
+    virtual void setWebLayer(WebLayer*);
 
     // MediaPlayerPrivateInterface methods:
     virtual void load(const WTF::String& url);
@@ -150,25 +143,14 @@ public:
     virtual WebCore::AudioSourceProvider* audioSourceProvider();
 #endif
 
-#if USE(ACCELERATED_COMPOSITING)
     virtual bool supportsAcceleratedRendering() const;
 
-    // WebVideoFrameProvider methods:
-    virtual void setVideoFrameProviderClient(WebVideoFrameProvider::Client*);
-    virtual WebVideoFrame* getCurrentFrame();
-    virtual void putCurrentFrame(WebVideoFrame*);
-#endif
-
 #if ENABLE(ENCRYPTED_MEDIA)
     virtual WebCore::MediaPlayer::MediaKeyException generateKeyRequest(const String& keySystem, const unsigned char* initData, unsigned initDataLength) OVERRIDE;
     virtual WebCore::MediaPlayer::MediaKeyException addKey(const String& keySystem, const unsigned char* key, unsigned keyLength, const unsigned char* initData, unsigned initDataLength, const String& sessionId) OVERRIDE;
     virtual WebCore::MediaPlayer::MediaKeyException cancelKeyRequest(const String& keySystem, const String& sessionId) OVERRIDE;
 #endif
 
-    // WebStreamTextureClient methods:
-    virtual void didReceiveFrame();
-    virtual void didUpdateMatrix(const float*);
-
 protected:
     WebMediaPlayerClientImpl();
 private:
@@ -189,20 +171,15 @@ private:
     bool acceleratedRenderingInUse();
 #endif
 
-    Mutex m_webMediaPlayerMutex; // Guards the m_webMediaPlayer
     WebCore::MediaPlayer* m_mediaPlayer;
     OwnPtr<WebMediaPlayer> m_webMediaPlayer;
-    WebVideoFrame* m_currentVideoFrame;
     WebCore::KURL m_url;
     bool m_delayingLoad;
     WebCore::MediaPlayer::Preload m_preload;
     RefPtr<WebHelperPluginImpl> m_helperPlugin;
-#if USE(ACCELERATED_COMPOSITING)
-    OwnPtr<WebVideoLayer> m_videoLayer;
-    bool m_supportsAcceleratedCompositing;
+    WebLayer* m_videoLayer;
     bool m_opaque;
-    WebVideoFrameProvider::Client* m_videoFrameProviderClient;
-#endif
+    bool m_needsWebLayerForVideo;
     static bool m_isEnabled;
 
 #if ENABLE(WEB_AUDIO)
diff --git a/Source/WebKit/chromium/tests/WebMediaPlayerClientImplTest.cpp b/Source/WebKit/chromium/tests/WebMediaPlayerClientImplTest.cpp
deleted file mode 100644 (file)
index 56a1a6e..0000000
+++ /dev/null
@@ -1,120 +0,0 @@
-/*
- * Copyright (C) 2012 Google Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1.  Redistributions of source code must retain the above copyright
- *     notice, this list of conditions and the following disclaimer.
- * 2.  Redistributions in binary form must reproduce the above copyright
- *     notice, this list of conditions and the following disclaimer in the
- *     documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "config.h"
-
-#include "WebMediaPlayerClientImpl.h"
-
-#include <gtest/gtest.h>
-#include <wtf/PassOwnPtr.h>
-
-using namespace WebKit;
-
-namespace {
-
-class FakeWebMediaPlayerClientImpl : public WebMediaPlayerClientImpl {
-public:
-    static PassOwnPtr<FakeWebMediaPlayerClientImpl> create() { return adoptPtr(new FakeWebMediaPlayerClientImpl()); }
-
-private:
-    FakeWebMediaPlayerClientImpl() { }
-};
-
-class FakeVideoFrameProviderClient : public WebVideoFrameProvider::Client {
-public:
-    static PassOwnPtr<FakeVideoFrameProviderClient> create(WebVideoFrameProvider* provider)
-    {
-        return adoptPtr(new FakeVideoFrameProviderClient(provider));
-    }
-
-    virtual ~FakeVideoFrameProviderClient()
-    {
-        if (m_provider)
-            m_provider->setVideoFrameProviderClient(0);
-    }
-
-    // WebKit::WebVideoFrameProvider::Client implementation.
-    virtual void didReceiveFrame() { }
-    virtual void didUpdateMatrix(const float*) { }
-    virtual void stopUsingProvider()
-    {
-        m_provider = 0;
-    }
-
-    WebVideoFrameProvider* provider() const { return m_provider; }
-
-private:
-    FakeVideoFrameProviderClient(WebVideoFrameProvider* provider)
-        : m_provider(provider)
-    {
-        m_provider->setVideoFrameProviderClient(this);
-    }
-
-    WebVideoFrameProvider* m_provider;
-};
-
-TEST(WebMediaPlayerClientImplTest, InitialNullVideoClient)
-{
-    // No explict checks in this test; just make sure it doesn't crash.
-    OwnPtr<WebMediaPlayerClientImpl> provider(FakeWebMediaPlayerClientImpl::create());
-    provider->setVideoFrameProviderClient(0);
-}
-
-TEST(WebMediaPlayerClientImplTest, SetAndUnsetVideoClient)
-{
-    OwnPtr<WebMediaPlayerClientImpl> provider(FakeWebMediaPlayerClientImpl::create());
-    OwnPtr<FakeVideoFrameProviderClient> client(FakeVideoFrameProviderClient::create(provider.get()));
-
-    EXPECT_EQ(client->provider(), provider.get());
-
-    provider->setVideoFrameProviderClient(0);
-    ASSERT_FALSE(client->provider());
-}
-
-TEST(WebMediaPlayerClientImplTest, DestroyProvider)
-{
-    OwnPtr<WebMediaPlayerClientImpl> provider(FakeWebMediaPlayerClientImpl::create());
-    OwnPtr<FakeVideoFrameProviderClient> client(FakeVideoFrameProviderClient::create(provider.get()));
-
-    EXPECT_EQ(client->provider(), provider);
-    provider.clear();
-    ASSERT_FALSE(client->provider());
-}
-
-TEST(WebMediaPlayerClientImplTest, SetMultipleVideoClients)
-{
-    OwnPtr<WebMediaPlayerClientImpl> provider(FakeWebMediaPlayerClientImpl::create());
-    OwnPtr<FakeVideoFrameProviderClient> firstClient(FakeVideoFrameProviderClient::create(provider.get()));
-    EXPECT_EQ(firstClient->provider(), provider);
-
-    OwnPtr<FakeVideoFrameProviderClient> secondClient(FakeVideoFrameProviderClient::create(provider.get()));
-    EXPECT_FALSE(firstClient->provider());
-    EXPECT_EQ(secondClient->provider(), provider);
-
-    provider.clear();
-    ASSERT_FALSE(firstClient->provider());
-    ASSERT_FALSE(secondClient->provider());
-}
-
-}