Changeset 163972 in webkit


Ignore:
Timestamp:
Feb 12, 2014 12:32:46 PM (10 years ago)
Author:
zandobersek@gmail.com
Message:

[CoordinatedGraphics] Move CoordinatedGraphicsScene, CoordinatedLayerTreeHostProxy to std::function
https://bugs.webkit.org/show_bug.cgi?id=128473

Reviewed by Anders Carlsson.

Source/WebCore:

Move the CoordinatedGraphicsScene class to using std::function instead of WTF::Functional and std::bind
instead of WTF::bind. The function wrapper is now moved through function calls and not passed by reference,
and lambda functions are inlined into the dispatchOnMainThread() calls, with the CoordinatedGraphicsScene
refcount-protected.

  • platform/graphics/texmap/coordinated/CoordinatedGraphicsScene.cpp:

(WebCore::CoordinatedGraphicsScene::dispatchOnMainThread):
(WebCore::CoordinatedGraphicsScene::paintToCurrentGLContext):
(WebCore::CoordinatedGraphicsScene::commitSceneState):
(WebCore::CoordinatedGraphicsScene::syncRemoteContent):
(WebCore::CoordinatedGraphicsScene::purgeGLResources):
(WebCore::CoordinatedGraphicsScene::commitScrollOffset):
(WebCore::CoordinatedGraphicsScene::appendUpdate):
(WebCore::CoordinatedGraphicsScene::setActive):

  • platform/graphics/texmap/coordinated/CoordinatedGraphicsScene.h:

Source/WebKit2:

Move the CoordinatedLayerTreeHostProxy class to using std::function instead of WTF::Functional. C++11
lambdas are used to construct the update functions, with the CoordinatedGraphicsScene refcount-protected
throughout the lifetime of the function wrapper.

  • UIProcess/CoordinatedGraphics/CoordinatedLayerTreeHostProxy.cpp:

(WebKit::CoordinatedLayerTreeHostProxy::dispatchUpdate):
(WebKit::CoordinatedLayerTreeHostProxy::commitCoordinatedGraphicsState):
(WebKit::CoordinatedLayerTreeHostProxy::setVisibleContentsRect):
(WebKit::CoordinatedLayerTreeHostProxy::setBackgroundColor):

  • UIProcess/CoordinatedGraphics/CoordinatedLayerTreeHostProxy.h:
Location:
trunk/Source
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r163971 r163972  
     12014-02-12  Zan Dobersek  <zdobersek@igalia.com>
     2
     3        [CoordinatedGraphics] Move CoordinatedGraphicsScene, CoordinatedLayerTreeHostProxy to std::function
     4        https://bugs.webkit.org/show_bug.cgi?id=128473
     5
     6        Reviewed by Anders Carlsson.
     7
     8
     9        Move the CoordinatedGraphicsScene class to using std::function instead of WTF::Functional and std::bind
     10        instead of WTF::bind. The function wrapper is now moved through function calls and not passed by reference,
     11        and lambda functions are inlined into the dispatchOnMainThread() calls, with the CoordinatedGraphicsScene
     12        refcount-protected.
     13
     14        * platform/graphics/texmap/coordinated/CoordinatedGraphicsScene.cpp:
     15        (WebCore::CoordinatedGraphicsScene::dispatchOnMainThread):
     16        (WebCore::CoordinatedGraphicsScene::paintToCurrentGLContext):
     17        (WebCore::CoordinatedGraphicsScene::commitSceneState):
     18        (WebCore::CoordinatedGraphicsScene::syncRemoteContent):
     19        (WebCore::CoordinatedGraphicsScene::purgeGLResources):
     20        (WebCore::CoordinatedGraphicsScene::commitScrollOffset):
     21        (WebCore::CoordinatedGraphicsScene::appendUpdate):
     22        (WebCore::CoordinatedGraphicsScene::setActive):
     23        * platform/graphics/texmap/coordinated/CoordinatedGraphicsScene.h:
     24
    1252014-02-12  Eric Carlson  <eric.carlson@apple.com>
    226
  • trunk/Source/WebCore/platform/graphics/texmap/coordinated/CoordinatedGraphicsScene.cpp

    r162644 r163972  
    3535namespace WebCore {
    3636
    37 void CoordinatedGraphicsScene::dispatchOnMainThread(const Function<void()>& function)
     37void CoordinatedGraphicsScene::dispatchOnMainThread(std::function<void()> function)
    3838{
    3939    if (isMainThread())
    4040        function();
    4141    else
    42         callOnMainThread(function);
     42        callOnMainThread(std::move(function));
    4343}
    4444
     
    9999    m_textureMapper->endPainting();
    100100
    101     if (currentRootLayer->descendantsOrSelfHaveRunningAnimations())
    102         dispatchOnMainThread(bind(&CoordinatedGraphicsScene::updateViewport, this));
     101    if (currentRootLayer->descendantsOrSelfHaveRunningAnimations()) {
     102        RefPtr<CoordinatedGraphicsScene> protector(this);
     103        dispatchOnMainThread([=] {
     104            protector->updateViewport();
     105        });
     106    }
    103107}
    104108
     
    577581
    578582    // The pending tiles state is on its way for the screen, tell the web process to render the next one.
    579     dispatchOnMainThread(bind(&CoordinatedGraphicsScene::renderNextFrame, this));
     583    RefPtr<CoordinatedGraphicsScene> protector(this);
     584    dispatchOnMainThread([=] {
     585        protector->renderNextFrame();
     586    });
    580587}
    581588
     
    608615    ensureRootLayer();
    609616
    610     Vector<Function<void()> > renderQueue;
     617    Vector<std::function<void()>> renderQueue;
    611618    bool calledOnMainThread = WTF::isMainThread();
    612619    if (!calledOnMainThread)
    613620        m_renderQueueMutex.lock();
    614     renderQueue.swap(m_renderQueue);
     621    renderQueue = std::move(m_renderQueue);
    615622    if (!calledOnMainThread)
    616623        m_renderQueueMutex.unlock();
    617624
    618     for (size_t i = 0; i < renderQueue.size(); ++i)
    619         renderQueue[i]();
     625    for (auto& function : renderQueue)
     626        function();
    620627}
    621628
     
    638645
    639646    setActive(false);
    640     dispatchOnMainThread(bind(&CoordinatedGraphicsScene::purgeBackingStores, this));
     647
     648    RefPtr<CoordinatedGraphicsScene> protector(this);
     649    dispatchOnMainThread([=] {
     650        protector->purgeBackingStores();
     651    });
    641652}
    642653
     
    648659void CoordinatedGraphicsScene::commitScrollOffset(uint32_t layerID, const IntSize& offset)
    649660{
    650     dispatchOnMainThread(bind(&CoordinatedGraphicsScene::dispatchCommitScrollOffset, this, layerID, offset));
     661    RefPtr<CoordinatedGraphicsScene> protector(this);
     662    dispatchOnMainThread([=] {
     663        protector->dispatchCommitScrollOffset(layerID, offset);
     664    });
    651665}
    652666
     
    672686}
    673687
    674 void CoordinatedGraphicsScene::appendUpdate(const Function<void()>& function)
     688void CoordinatedGraphicsScene::appendUpdate(std::function<void()> function)
    675689{
    676690    if (!m_isActive)
     
    679693    ASSERT(isMainThread());
    680694    MutexLocker locker(m_renderQueueMutex);
    681     m_renderQueue.append(function);
     695    m_renderQueue.append(std::move(function));
    682696}
    683697
     
    692706    m_renderQueue.clear();
    693707    m_isActive = active;
    694     if (m_isActive)
    695         dispatchOnMainThread(bind(&CoordinatedGraphicsScene::renderNextFrame, this));
     708    if (m_isActive) {
     709        RefPtr<CoordinatedGraphicsScene> protector(this);
     710        dispatchOnMainThread([=] {
     711            protector->renderNextFrame();
     712        });
     713    }
    696714}
    697715
  • trunk/Source/WebCore/platform/graphics/texmap/coordinated/CoordinatedGraphicsScene.h

    r162644 r163972  
    3636#include "TextureMapperLayer.h"
    3737#include "Timer.h"
    38 #include <wtf/Functional.h>
     38#include <functional>
    3939#include <wtf/HashSet.h>
    4040#include <wtf/ThreadingPrimitives.h>
     
    6666    void setScrollPosition(const FloatPoint&);
    6767    void detach();
    68     void appendUpdate(const Function<void()>&);
     68    void appendUpdate(std::function<void()>);
    6969
    7070    WebCore::TextureMapperLayer* findScrollableContentsLayerAt(const WebCore::FloatPoint&);
     
    126126    void adjustPositionForFixedLayers();
    127127
    128     void dispatchOnMainThread(const Function<void()>&);
     128    void dispatchOnMainThread(std::function<void()>);
    129129    void updateViewport();
    130130    void renderNextFrame();
     
    147147
    148148    // Render queue can be accessed ony from main thread or updatePaintNode call stack!
    149     Vector<Function<void()> > m_renderQueue;
     149    Vector<std::function<void()>> m_renderQueue;
    150150    Mutex m_renderQueueMutex;
    151151
  • trunk/Source/WebKit2/ChangeLog

    r163961 r163972  
     12014-02-12  Zan Dobersek  <zdobersek@igalia.com>
     2
     3        [CoordinatedGraphics] Move CoordinatedGraphicsScene, CoordinatedLayerTreeHostProxy to std::function
     4        https://bugs.webkit.org/show_bug.cgi?id=128473
     5
     6        Reviewed by Anders Carlsson.
     7
     8        Move the CoordinatedLayerTreeHostProxy class to using std::function instead of WTF::Functional. C++11
     9        lambdas are used to construct the update functions, with the CoordinatedGraphicsScene refcount-protected
     10        throughout the lifetime of the function wrapper.
     11
     12        * UIProcess/CoordinatedGraphics/CoordinatedLayerTreeHostProxy.cpp:
     13        (WebKit::CoordinatedLayerTreeHostProxy::dispatchUpdate):
     14        (WebKit::CoordinatedLayerTreeHostProxy::commitCoordinatedGraphicsState):
     15        (WebKit::CoordinatedLayerTreeHostProxy::setVisibleContentsRect):
     16        (WebKit::CoordinatedLayerTreeHostProxy::setBackgroundColor):
     17        * UIProcess/CoordinatedGraphics/CoordinatedLayerTreeHostProxy.h:
     18
    1192014-02-12  Dan Bernstein  <mitz@apple.com>
    220
  • trunk/Source/WebKit2/UIProcess/CoordinatedGraphics/CoordinatedLayerTreeHostProxy.cpp

    r160476 r163972  
    5353}
    5454
    55 void CoordinatedLayerTreeHostProxy::dispatchUpdate(const Function<void()>& function)
     55void CoordinatedLayerTreeHostProxy::dispatchUpdate(std::function<void()> function)
    5656{
    57     m_scene->appendUpdate(function);
     57    m_scene->appendUpdate(std::move(function));
    5858}
    5959
    6060void CoordinatedLayerTreeHostProxy::commitCoordinatedGraphicsState(const CoordinatedGraphicsState& graphicsState)
    6161{
    62     dispatchUpdate(bind(&CoordinatedGraphicsScene::commitSceneState, m_scene.get(), graphicsState));
     62    RefPtr<CoordinatedGraphicsScene> sceneProtector(m_scene);
     63    dispatchUpdate([=] {
     64        sceneProtector->commitSceneState(graphicsState);
     65    });
     66
    6367    updateViewport();
    6468#if USE(TILED_BACKING_STORE)
     
    7074{
    7175    // Inform the renderer to adjust viewport-fixed layers.
    72     dispatchUpdate(bind(&CoordinatedGraphicsScene::setScrollPosition, m_scene.get(), rect.location()));
     76    RefPtr<CoordinatedGraphicsScene> sceneProtector(m_scene);
     77    const FloatPoint& scrollPosition = rect.location();
     78    dispatchUpdate([=] {
     79        sceneProtector->setScrollPosition(scrollPosition);
     80    });
    7381
    7482    if (rect == m_lastSentVisibleRect && trajectoryVector == m_lastSentTrajectoryVector)
     
    92100void CoordinatedLayerTreeHostProxy::setBackgroundColor(const Color& color)
    93101{
    94     dispatchUpdate(bind(&CoordinatedGraphicsScene::setBackgroundColor, m_scene.get(), color));
     102    RefPtr<CoordinatedGraphicsScene> sceneProtector(m_scene);
     103    dispatchUpdate([=] {
     104        sceneProtector->setBackgroundColor(color);
     105    });
    95106}
    96107
  • trunk/Source/WebKit2/UIProcess/CoordinatedGraphics/CoordinatedLayerTreeHostProxy.h

    r162139 r163972  
    2727#include "MessageReceiver.h"
    2828#include <WebCore/CoordinatedGraphicsScene.h>
    29 #include <wtf/Functional.h>
     29#include <functional>
    3030
    3131namespace WebCore {
     
    5858
    5959protected:
    60     void dispatchUpdate(const Function<void()>&);
     60    void dispatchUpdate(std::function<void()>);
    6161
    6262    // IPC::MessageReceiver
Note: See TracChangeset for help on using the changeset viewer.