Changeset 96481 in webkit


Ignore:
Timestamp:
Oct 2, 2011 6:11:45 PM (13 years ago)
Author:
commit-queue@webkit.org
Message:

[chromium] Add WebWidget API for accessing the current WebCompositor
https://bugs.webkit.org/show_bug.cgi?id=69181

Patch by James Robinson <jamesr@chromium.org> on 2011-10-02
Reviewed by Darin Fisher.

Add new WebWidgetClient::did(Activate|Deactivate)Compositor calls intended to replace
didActivateAccleratedCompositing(bool) so that the enable call can be parameterized.

Add a WebCompositor identifier parameter to didEnableAcceleratedCompositing that can be used on the compositor
thread to get access to a WebCompositor pointer.

  • public/WebWidget.h:

(WebKit::WebWidget::compositor):

  • src/WebViewImpl.cpp:

(WebKit::WebViewImpl::compositor):
(WebKit::WebViewImpl::setIsAcceleratedCompositingActive):

  • src/WebViewImpl.h:
Location:
trunk/Source/WebKit/chromium
Files:
9 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/chromium/ChangeLog

    r96454 r96481  
     12011-10-02  James Robinson  <jamesr@chromium.org>
     2
     3        [chromium] Add WebWidget API for accessing the current WebCompositor
     4        https://bugs.webkit.org/show_bug.cgi?id=69181
     5
     6        Reviewed by Darin Fisher.
     7
     8        Add new WebWidgetClient::did(Activate|Deactivate)Compositor calls intended to replace
     9        didActivateAccleratedCompositing(bool) so that the enable call can be parameterized.
     10
     11        Add a WebCompositor identifier parameter to didEnableAcceleratedCompositing that can be used on the compositor
     12        thread to get access to a WebCompositor pointer.
     13
     14        * public/WebWidget.h:
     15        (WebKit::WebWidget::compositor):
     16        * src/WebViewImpl.cpp:
     17        (WebKit::WebViewImpl::compositor):
     18        (WebKit::WebViewImpl::setIsAcceleratedCompositingActive):
     19        * src/WebViewImpl.h:
     20
    1212011-09-30  Adrienne Walker  <enne@google.com>
    222
  • trunk/Source/WebKit/chromium/WebKit.gypi

    r96454 r96481  
    7777            'tests/TreeTestHelpers.cpp',
    7878            'tests/TreeTestHelpers.h',
     79            'tests/WebCompositorImplTest.cpp',
    7980            'tests/WebFrameTest.cpp',
    8081            'tests/WebURLRequestTest.cpp',
  • trunk/Source/WebKit/chromium/public/WebCompositor.h

    r96392 r96481  
    4141    // This must be called once with a non-null WebThread before any compositors attempt to initialize.
    4242    WEBKIT_EXPORT static void setThread(WebThread*);
     43    WEBKIT_EXPORT static WebCompositor* fromIdentifier(int);
    4344
    4445    virtual void setClient(WebCompositorClient*) = 0;
  • trunk/Source/WebKit/chromium/public/WebWidgetClient.h

    r95901 r96481  
    5353
    5454    // Called when the compositor enables or disables.
     55    // FIXME: Remove when all implementations switch over to didEnable.../didDisable...
    5556    virtual void didActivateAcceleratedCompositing(bool active) { }
     57
     58    // Called when the compositor is enabled or disabled.
     59    // The WebCompositor identifier can be used on the compositor thread to get access
     60    // to the WebCompositor instance associated with this WebWidget.
     61    virtual void didActivateCompositor(int compositorIdentifier) { }
     62    virtual void didDeactivateCompositor() { }
    5663
    5764    // Called when a call to WebWidget::composite is required
  • trunk/Source/WebKit/chromium/src/WebCompositorImpl.cpp

    r96430 r96481  
    3232#include "WebInputEvent.h"
    3333#include "cc/CCThreadProxy.h"
     34#include <wtf/ThreadingPrimitives.h>
    3435
    3536using namespace WebCore;
     
    4344}
    4445
     46int WebCompositorImpl::s_nextAvailableIdentifier = 1;
     47
     48// These data structures are always allocated from the main thread, but may
     49// be accessed and mutated on the main or compositor thread.
     50// s_compositors is deleted when it has no elements. s_compositorsLock is never
     51// deleted.
     52HashSet<WebCompositorImpl*>* WebCompositorImpl::s_compositors = 0;
     53Mutex* WebCompositorImpl::s_compositorsLock = 0;
     54
     55WebCompositor* WebCompositor::fromIdentifier(int identifier)
     56{
     57    return WebCompositorImpl::fromIdentifier(identifier);
     58}
     59
     60WebCompositor* WebCompositorImpl::fromIdentifier(int identifier)
     61{
     62    ASSERT(CCProxy::isImplThread());
     63    if (!s_compositorsLock)
     64        return 0;
     65
     66    MutexLocker lock(*s_compositorsLock);
     67    if (!s_compositors)
     68        return 0;
     69
     70    for (HashSet<WebCompositorImpl*>::iterator it = s_compositors->begin(); it != s_compositors->end(); ++it) {
     71        if ((*it)->identifier() == identifier)
     72            return *it;
     73    }
     74    return 0;
     75}
     76
    4577WebCompositorImpl::WebCompositorImpl()
    4678    : m_client(0)
     79    , m_identifier(s_nextAvailableIdentifier++)
    4780{
     81    ASSERT(CCProxy::isMainThread());
     82    if (!s_compositorsLock)
     83        s_compositorsLock = new Mutex;
     84    MutexLocker lock(*s_compositorsLock);
     85    if (!s_compositors)
     86        s_compositors = new HashSet<WebCompositorImpl*>;
     87    s_compositors->add(this);
    4888}
    4989
    5090WebCompositorImpl::~WebCompositorImpl()
    5191{
     92    ASSERT(s_compositorsLock);
     93    MutexLocker lock(*s_compositorsLock);
     94    ASSERT(s_compositors);
     95    s_compositors->remove(this);
     96    if (!s_compositors->size()) {
     97        delete s_compositors;
     98        s_compositors = 0;
     99    }
    52100}
    53101
    54102void WebCompositorImpl::setClient(WebCompositorClient* client)
    55103{
     104    ASSERT(CCProxy::isImplThread());
    56105    ASSERT(client);
    57106    m_client = client;
     
    60109void WebCompositorImpl::handleInputEvent(const WebInputEvent& event)
    61110{
     111    ASSERT(CCProxy::isImplThread());
    62112    // FIXME: Do something interesting with the event here.
    63113    m_client->didHandleInputEvent(false);
  • trunk/Source/WebKit/chromium/src/WebCompositorImpl.h

    r96392 r96481  
    2828
    2929#include "WebCompositor.h"
     30
     31#include <wtf/HashSet.h>
    3032#include <wtf/Noncopyable.h>
    3133#include <wtf/PassOwnPtr.h>
     34
     35namespace WTF {
     36class Mutex;
     37}
    3238
    3339namespace WebKit {
     
    3844    WTF_MAKE_NONCOPYABLE(WebCompositorImpl);
    3945public:
     46    static WebCompositor* fromIdentifier(int identifier);
     47
    4048    static PassOwnPtr<WebCompositorImpl> create()
    4149    {
     
    4856    virtual void handleInputEvent(const WebInputEvent&);
    4957
     58    int identifier() const { return m_identifier; }
     59
    5060private:
    5161    WebCompositorImpl();
    5262
    5363    WebCompositorClient* m_client;
     64    int m_identifier;
     65
     66    static HashSet<WebCompositorImpl*>* s_compositors;
     67    static Mutex* s_compositorsLock;
     68
     69    static int s_nextAvailableIdentifier;
    5470};
    5571
  • trunk/Source/WebKit/chromium/src/WebViewImpl.cpp

    r96454 r96481  
    104104#include "WebAccessibilityObject.h"
    105105#include "WebAutofillClient.h"
     106#include "WebCompositorImpl.h"
    106107#include "WebDevToolsAgentImpl.h"
    107108#include "WebDevToolsAgentPrivate.h"
     
    26462647            m_layerTreeHost->finishAllRendering();
    26472648        m_client->didActivateAcceleratedCompositing(false);
     2649        m_client->didDeactivateCompositor();
    26482650    } else if (m_layerTreeHost) {
    26492651        m_isAcceleratedCompositingActive = true;
     
    26512653
    26522654        m_client->didActivateAcceleratedCompositing(true);
     2655        m_client->didActivateCompositor(m_webCompositorImpl->identifier());
    26532656    } else {
    26542657        TRACE_EVENT("WebViewImpl::setIsAcceleratedCompositingActive(true)", this, 0);
     
    26682671        m_layerTreeHost = CCLayerTreeHost::create(this, m_nonCompositedContentHost->topLevelRootLayer()->platformLayer(), ccSettings);
    26692672        if (m_layerTreeHost) {
     2673            m_webCompositorImpl = WebCompositorImpl::create();
     2674            // FIXME: Hook the m_webCompositorImpl up with the CCLayerTreeHost somehow.
    26702675            updateLayerTreeViewport();
    26712676            m_client->didActivateAcceleratedCompositing(true);
     2677            m_client->didActivateCompositor(m_webCompositorImpl->identifier());
    26722678            m_isAcceleratedCompositingActive = true;
    26732679            m_compositorCreationFailed = false;
     
    26772683            m_isAcceleratedCompositingActive = false;
    26782684            m_client->didActivateAcceleratedCompositing(false);
     2685            m_client->didDeactivateCompositor();
    26792686            m_compositorCreationFailed = true;
    26802687        }
  • trunk/Source/WebKit/chromium/src/WebViewImpl.h

    r96454 r96481  
    8383class SpeechInputClientImpl;
    8484class WebAccessibilityObject;
     85class WebCompositorImpl;
    8586class WebDevToolsAgentClient;
    8687class WebDevToolsAgentPrivate;
     
    576577    OwnPtr<WebCore::NonCompositedContentHost> m_nonCompositedContentHost;
    577578    RefPtr<WebCore::CCLayerTreeHost> m_layerTreeHost;
     579    OwnPtr<WebCompositorImpl> m_webCompositorImpl;
    578580    WebCore::GraphicsLayer* m_rootGraphicsLayer;
    579581    bool m_isAcceleratedCompositingActive;
  • trunk/Source/WebKit/chromium/tests/CCLayerTreeHostTest.cpp

    r96454 r96481  
    118118        bool success = initialize();
    119119        ASSERT(success);
     120        UNUSED_PARAM(success);
    120121    }
    121122
  • trunk/Source/WebKit/chromium/tests/WebCompositorImplTest.cpp

    r96480 r96481  
    2828#include "WebCompositorImpl.h"
    2929
    30 #include "CCThreadImpl.h"
    31 #include "WebCompositorClient.h"
    32 #include "WebInputEvent.h"
    33 #include "cc/CCThreadProxy.h"
     30#include "cc/CCProxy.h"
    3431
    35 using namespace WebCore;
     32#include <gtest/gtest.h>
     33#include <wtf/OwnPtr.h>
    3634
    37 namespace WebKit {
     35using WebKit::WebCompositor;
     36using WebKit::WebCompositorImpl;
    3837
    39 void WebCompositor::setThread(WebThread* compositorThread)
     38namespace {
     39
     40TEST(WebCompositorImpl, fromIdentifier)
    4041{
    41     ASSERT(compositorThread);
    42     CCThreadProxy::setThread(CCThreadImpl::create(compositorThread).leakPtr());
    43 }
     42#ifndef NDEBUG
     43    // WebCompositor APIs can only be called from the compositor thread.
     44    WebCore::CCProxy::setImplThread(true);
     45#endif
    4446
    45 WebCompositorImpl::WebCompositorImpl()
    46     : m_client(0)
    47 {
    48 }
     47    // Before creating any WebCompositors, lookups for any value should fail and not crash.
     48    EXPECT_EQ(0, WebCompositor::fromIdentifier(2));
     49    EXPECT_EQ(0, WebCompositor::fromIdentifier(0));
     50    EXPECT_EQ(0, WebCompositor::fromIdentifier(-1));
    4951
    50 WebCompositorImpl::~WebCompositorImpl()
    51 {
    52 }
     52    int compositorIdentifier = -1;
     53    {
     54#ifndef NDEBUG
     55        WebCore::CCProxy::setImplThread(false);
     56#endif
     57        OwnPtr<WebCompositorImpl> comp = WebCompositorImpl::create();
     58#ifndef NDEBUG
     59        WebCore::CCProxy::setImplThread(true);
     60#endif
     61        compositorIdentifier = comp->identifier();
     62        // The compositor we just created should be locatable.
     63        EXPECT_EQ(comp.get(), WebCompositor::fromIdentifier(compositorIdentifier));
    5364
    54 void WebCompositorImpl::setClient(WebCompositorClient* client)
    55 {
    56     ASSERT(client);
    57     m_client = client;
    58 }
     65        // But nothing else.
     66        EXPECT_EQ(0, WebCompositor::fromIdentifier(comp->identifier() + 10));
     67    }
    5968
    60 void WebCompositorImpl::handleInputEvent(const WebInputEvent& event)
    61 {
    62     // FIXME: Do something interesting with the event here.
    63     m_client->didHandleInputEvent(false);
     69    // After the compositor is destroyed, its entry should be removed from the map.
     70    EXPECT_EQ(0, WebCompositor::fromIdentifier(compositorIdentifier));
    6471}
    6572
    6673}
    67 
Note: See TracChangeset for help on using the changeset viewer.