Changeset 220700 in webkit


Ignore:
Timestamp:
Aug 14, 2017 9:41:18 AM (7 years ago)
Author:
zandobersek@gmail.com
Message:

[CoordGraphics] Simplify CoordinatedGraphicsScene state updates
https://bugs.webkit.org/show_bug.cgi?id=175528

Reviewed by Carlos Garcia Campos.

Hold the information about state updates in ThreadedCompositor, in the
m_attributes struct. This way we don't need to store the updates in
functors and accumulate them in the CoordinatedGraphicsScene class, but
instead just apply any pending state update or atlas removal before the
scene is rendered.

This removes the need to update the CoordinatedGraphicsScene object from
the main thread with data that ultimately has to be handled on the
composition thread. Similarly, when updating CoordinatedGraphicsScene, we
only need to synchronize on the m_attributes lock object once in order to
retrieve the scene update information, instead of having each functor do
that repeatedly.

  • Shared/CoordinatedGraphics/CoordinatedGraphicsScene.cpp:

(WebKit::CoordinatedGraphicsScene::applyStateChanges):
(WebKit::CoordinatedGraphicsScene::paintToCurrentGLContext):
(WebKit::CoordinatedGraphicsScene::detach):
(WebKit::CoordinatedGraphicsScene::setActive):
(WebKit::CoordinatedGraphicsScene::syncRemoteContent): Deleted.
(WebKit::CoordinatedGraphicsScene::appendUpdate): Deleted.

  • Shared/CoordinatedGraphics/CoordinatedGraphicsScene.h:
  • Shared/CoordinatedGraphics/threadedcompositor/ThreadedCompositor.cpp:

(WebKit::ThreadedCompositor::renderLayerTree):
(WebKit::ThreadedCompositor::updateSceneState):
(WebKit::ThreadedCompositor::releaseUpdateAtlases):

  • Shared/CoordinatedGraphics/threadedcompositor/ThreadedCompositor.h:
Location:
trunk/Source/WebKit
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r220694 r220700  
     12017-08-14  Zan Dobersek  <zdobersek@igalia.com>
     2
     3        [CoordGraphics] Simplify CoordinatedGraphicsScene state updates
     4        https://bugs.webkit.org/show_bug.cgi?id=175528
     5
     6        Reviewed by Carlos Garcia Campos.
     7
     8        Hold the information about state updates in ThreadedCompositor, in the
     9        m_attributes struct. This way we don't need to store the updates in
     10        functors and accumulate them in the CoordinatedGraphicsScene class, but
     11        instead just apply any pending state update or atlas removal before the
     12        scene is rendered.
     13
     14        This removes the need to update the CoordinatedGraphicsScene object from
     15        the main thread with data that ultimately has to be handled on the
     16        composition thread. Similarly, when updating CoordinatedGraphicsScene, we
     17        only need to synchronize on the m_attributes lock object once in order to
     18        retrieve the scene update information, instead of having each functor do
     19        that repeatedly.
     20
     21        * Shared/CoordinatedGraphics/CoordinatedGraphicsScene.cpp:
     22        (WebKit::CoordinatedGraphicsScene::applyStateChanges):
     23        (WebKit::CoordinatedGraphicsScene::paintToCurrentGLContext):
     24        (WebKit::CoordinatedGraphicsScene::detach):
     25        (WebKit::CoordinatedGraphicsScene::setActive):
     26        (WebKit::CoordinatedGraphicsScene::syncRemoteContent): Deleted.
     27        (WebKit::CoordinatedGraphicsScene::appendUpdate): Deleted.
     28        * Shared/CoordinatedGraphics/CoordinatedGraphicsScene.h:
     29        * Shared/CoordinatedGraphics/threadedcompositor/ThreadedCompositor.cpp:
     30        (WebKit::ThreadedCompositor::renderLayerTree):
     31        (WebKit::ThreadedCompositor::updateSceneState):
     32        (WebKit::ThreadedCompositor::releaseUpdateAtlases):
     33        * Shared/CoordinatedGraphics/threadedcompositor/ThreadedCompositor.h:
     34
    1352017-08-14  Carlos Garcia Campos  <cgarcia@igalia.com>
    236
  • trunk/Source/WebKit/Shared/CoordinatedGraphics/CoordinatedGraphicsScene.cpp

    r220391 r220700  
    7878}
    7979
    80 void CoordinatedGraphicsScene::paintToCurrentGLContext(const TransformationMatrix& matrix, float opacity, const FloatRect& clipRect, const Color& backgroundColor, bool drawsBackground, const FloatPoint& contentPosition, TextureMapper::PaintFlags PaintFlags)
     80void CoordinatedGraphicsScene::applyStateChanges(const Vector<CoordinatedGraphicsState>& states)
    8181{
    8282    if (!m_textureMapper) {
     
    8585    }
    8686
    87     syncRemoteContent();
    88 
     87    ensureRootLayer();
     88
     89    for (auto& state : states)
     90        commitSceneState(state);
     91}
     92
     93void CoordinatedGraphicsScene::paintToCurrentGLContext(const TransformationMatrix& matrix, float opacity, const FloatRect& clipRect, const Color& backgroundColor, bool drawsBackground, const FloatPoint& contentPosition, TextureMapper::PaintFlags PaintFlags)
     94{
    8995    adjustPositionForFixedLayers(contentPosition);
    9096    TextureMapperLayer* currentRootLayer = rootLayer();
     
    581587}
    582588
    583 void CoordinatedGraphicsScene::syncRemoteContent()
    584 {
    585     // We enqueue messages and execute them during paint, as they require an active GL context.
    586     ensureRootLayer();
    587 
    588     Vector<Function<void()>> renderQueue;
    589     bool calledOnMainThread = RunLoop::isMain();
    590     if (!calledOnMainThread)
    591         m_renderQueueMutex.lock();
    592     renderQueue = WTFMove(m_renderQueue);
    593     if (!calledOnMainThread)
    594         m_renderQueueMutex.unlock();
    595 
    596     for (auto& function : renderQueue)
    597         function();
    598 }
    599 
    600589void CoordinatedGraphicsScene::purgeGLResources()
    601590{
     
    643632    m_isActive = false;
    644633    m_client = nullptr;
    645     LockHolder locker(m_renderQueueMutex);
    646     m_renderQueue.clear();
    647 }
    648 
    649 void CoordinatedGraphicsScene::appendUpdate(Function<void()>&& function)
    650 {
    651     if (!m_isActive)
    652         return;
    653 
    654     ASSERT(RunLoop::isMain());
    655     LockHolder locker(m_renderQueueMutex);
    656     m_renderQueue.append(WTFMove(function));
    657634}
    658635
    659636void CoordinatedGraphicsScene::setActive(bool active)
    660637{
    661     if (!m_client)
    662         return;
    663 
    664     if (m_isActive == active)
    665         return;
    666 
    667     // Have to clear render queue in both cases.
    668     // If there are some updates in queue during activation then those updates are from previous instance of paint node
    669     // and cannot be applied to the newly created instance.
    670     m_renderQueue.clear();
     638    if (!m_client || m_isActive == active)
     639        return;
     640
    671641    m_isActive = active;
    672642    if (m_isActive)
  • trunk/Source/WebKit/Shared/CoordinatedGraphics/CoordinatedGraphicsScene.h

    r218745 r220700  
    6969    explicit CoordinatedGraphicsScene(CoordinatedGraphicsSceneClient*);
    7070    virtual ~CoordinatedGraphicsScene();
     71
     72    void applyStateChanges(const Vector<WebCore::CoordinatedGraphicsState>&);
    7173    void paintToCurrentGLContext(const WebCore::TransformationMatrix&, float, const WebCore::FloatRect&, const WebCore::Color& backgroundColor, bool drawsBackground, const WebCore::FloatPoint&, WebCore::TextureMapper::PaintFlags = 0);
    7274    void detach();
    73     void appendUpdate(Function<void()>&&);
    7475
    7576    WebCore::TextureMapperLayer* findScrollableContentsLayerAt(const WebCore::FloatPoint&);
     
    125126    WebCore::TextureMapperLayer* rootLayer() { return m_rootLayer.get(); }
    126127
    127     void syncRemoteContent();
    128128    void adjustPositionForFixedLayers(const WebCore::FloatPoint& contentPosition);
    129129
     
    149149    WebCore::TextureMapperGL* texmapGL() override;
    150150#endif
    151 
    152     // Render queue can be accessed ony from main thread or updatePaintNode call stack!
    153     Vector<Function<void()>> m_renderQueue;
    154     Lock m_renderQueueMutex;
    155151
    156152    std::unique_ptr<WebCore::TextureMapper> m_textureMapper;
  • trunk/Source/WebKit/Shared/CoordinatedGraphics/threadedcompositor/ThreadedCompositor.cpp

    r220672 r220700  
    209209    bool drawsBackground;
    210210    bool needsResize;
     211    Vector<WebCore::CoordinatedGraphicsState> states;
     212    Vector<uint32_t> atlasesToRemove;
     213
    211214    {
    212215        LockHolder locker(m_attributes.lock);
     
    217220        needsResize = m_attributes.needsResize;
    218221
     222        states = WTFMove(m_attributes.states);
     223        atlasesToRemove = WTFMove(m_attributes.atlasesToRemove);
     224
     225        if (!states.isEmpty()) {
     226            // Client has to be notified upon finishing this scene update.
     227            m_attributes.clientRendersNextFrame = true;
     228
     229            // Coordinate scene update completion with the client in case of changed or updated platform layers.
     230            // But do not change coordinateUpdateCompletionWithClient while in force repaint because that
     231            // demands immediate scene update completion regardless of platform layers.
     232            if (!m_inForceRepaint) {
     233                bool coordinateUpdate = false;
     234                for (auto& state : states)
     235                    coordinateUpdate |= std::any_of(state.layersToUpdate.begin(), state.layersToUpdate.end(),
     236                        [](auto& it) { return it.second.platformLayerChanged || it.second.platformLayerUpdated; });
     237                m_attributes.coordinateUpdateCompletionWithClient = coordinateUpdate;
     238            }
     239        }
     240
    219241        // Reset the needsResize attribute to false.
    220242        m_attributes.needsResize = false;
     
    233255    }
    234256
     257    m_scene->applyStateChanges(states);
     258    m_scene->releaseUpdateAtlases(atlasesToRemove);
    235259    m_scene->paintToCurrentGLContext(viewportTransform, 1, FloatRect { FloatPoint { }, viewportSize },
    236260        Color::transparent, !drawsBackground, scrollPosition, m_paintFlags);
     
    279303void ThreadedCompositor::updateSceneState(const CoordinatedGraphicsState& state)
    280304{
    281     ASSERT(RunLoop::isMain());
    282     m_scene->appendUpdate([this, scene = makeRef(*m_scene), state] {
    283         scene->commitSceneState(state);
    284 
    285         LockHolder locker(m_attributes.lock);
    286 
    287         // Client has to be notified upon finishing this scene update.
    288         m_attributes.clientRendersNextFrame = true;
    289 
    290         // Coordinate scene update completion with the client in case of changed or updated platform layers.
    291         // Do not change m_coordinateUpdateCompletionWithClient while in force repaint.
    292         bool coordinateUpdate = !m_inForceRepaint && std::any_of(state.layersToUpdate.begin(), state.layersToUpdate.end(),
    293             [](const std::pair<CoordinatedLayerID, CoordinatedGraphicsLayerState>& it) {
    294                 return it.second.platformLayerChanged || it.second.platformLayerUpdated;
    295             });
    296 
    297         m_attributes.coordinateUpdateCompletionWithClient |= coordinateUpdate;
    298     });
    299 
     305    LockHolder locker(m_attributes.lock);
     306    m_attributes.states.append(state);
    300307    m_compositingRunLoop->scheduleUpdate();
    301308}
     
    303310void ThreadedCompositor::releaseUpdateAtlases(Vector<uint32_t>&& atlasesToRemove)
    304311{
    305     ASSERT(RunLoop::isMain());
    306     m_scene->appendUpdate([scene = makeRef(*m_scene), atlasesToRemove = WTFMove(atlasesToRemove)] {
    307         scene->releaseUpdateAtlases(atlasesToRemove);
    308     });
     312    LockHolder locker(m_attributes.lock);
     313    m_attributes.atlasesToRemove.appendVector(atlasesToRemove);
    309314    m_compositingRunLoop->scheduleUpdate();
    310315}
  • trunk/Source/WebKit/Shared/CoordinatedGraphics/threadedcompositor/ThreadedCompositor.h

    r220672 r220700  
    3030#include "CompositingRunLoop.h"
    3131#include "CoordinatedGraphicsScene.h"
     32#include <WebCore/CoordinatedGraphicsState.h>
    3233#include <WebCore/GLContext.h>
    3334#include <WebCore/IntSize.h>
     
    4142#include <WebCore/DisplayRefreshMonitor.h>
    4243#endif
    43 
    44 namespace WebCore {
    45 struct CoordinatedGraphicsState;
    46 }
    4744
    4845namespace WebKit {
     
    127124        bool needsResize { false };
    128125
     126        Vector<WebCore::CoordinatedGraphicsState> states;
     127        Vector<uint32_t> atlasesToRemove;
     128
    129129        bool clientRendersNextFrame { false };
    130130        bool coordinateUpdateCompletionWithClient { false };
Note: See TracChangeset for help on using the changeset viewer.