Changeset 205395 in webkit


Ignore:
Timestamp:
Sep 2, 2016 10:45:10 PM (8 years ago)
Author:
Carlos Garcia Campos
Message:

[Threaded Compositor] Move the viewport controller off the compositing thread
https://bugs.webkit.org/show_bug.cgi?id=161532

Reviewed by Michael Catanzaro.

While working on bug #161242 I've realized that having the view port controller in the compositing thread makes
everything more complex. The viewport controller receives changes about things like contents size, viewport
size, etc. and uses that information to compute the visible contents rect and page scale factor. Then it
notifies back to main thread about the computed visible contents rect and page scale. Those computations are not
heave at all, so they could be done in the main thread and we would avoid communications between the main and
compositing thread in both directions. The main thread needs the visible contents rect to notify the compositing
coordinator and the page cale to scale the page in case of pixed layout. But the compositing thread only needs
to know the effective scale and scroll position. So, instead of going to the compositing thread after every
change that might update the visible contents rect and page scale factor, we could do those calculations in the
main thread and only notify the compositing thread about the actual changes in the scroll position and effective scale.

  • Shared/CoordinatedGraphics/CoordinatedGraphicsScene.cpp:

(WebKit::CoordinatedGraphicsScene::createTilesIfNeeded): Return early if backingStore is nullptr, which can
happen if the layer shouldn't have a backing store and was removed by the previous call to prepareContentBackingStore().
(WebKit::CoordinatedGraphicsScene::updateTilesIfNeeded): Ditto.

  • Shared/CoordinatedGraphics/SimpleViewportController.cpp:

(WebKit::SimpleViewportController::SimpleViewportController): Remove the client since we no longer need to
notify about changes.
(WebKit::SimpleViewportController::didChangeViewportSize): Remove call to syncVisibleContents().
(WebKit::SimpleViewportController::didChangeContentsSize): Ditto.
(WebKit::SimpleViewportController::didChangeViewportAttributes): Ditto.
(WebKit::SimpleViewportController::didScroll): Removed unused scrollBy methods and renamed scrollTo as
didiScroll for consistency. Save the position without calling boundContentsPosition, because that's already
donde when the position is used to compute the contents visible rectangle.
(WebKit::SimpleViewportController::visibleContentsRect): No need to notify about the changes.
(WebKit::SimpleViewportController::visibleContentsSize): Deleted.

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

(WebKit::ThreadedCompositor::create): Pass a reference to the client instead of a pointer. It's no longer
possible to have a valid pointer when the object has been destroyed, so we can better use a reference now.
(WebKit::ThreadedCompositor::ThreadedCompositor): Ditto.
(WebKit::ThreadedCompositor::~ThreadedCompositor): Remove assert.
(WebKit::ThreadedCompositor::invalidate): No need to invalidate the client.
(WebKit::ThreadedCompositor::setScaleFactor): Set the effective scale factor that should be used for rendering.
(WebKit::ThreadedCompositor::setScrollPosition): Set the current scroll position and effective scale factor.
(WebKit::ThreadedCompositor::setViewportSize): Set the viewport size and effective scale factor.
(WebKit::ThreadedCompositor::renderNextFrame): Update m_client use that is no longer a pointer.
(WebKit::ThreadedCompositor::commitScrollOffset): Ditto.
(WebKit::ThreadedCompositor::renderLayerTree): Call glViewport after a resize and use m_viewportSize,
m_scrollPosition and m_scaleFactor members.
(WebKit::ThreadedCompositor::didChangeVisibleRect): Deleted.

  • Shared/CoordinatedGraphics/threadedcompositor/ThreadedCompositor.h:
  • WebProcess/WebPage/CoordinatedGraphics/ThreadedCoordinatedLayerTreeHost.cpp:

(WebKit::ThreadedCoordinatedLayerTreeHost::ThreadedCoordinatedLayerTreeHost): Pass the compositor client as a
reference to ThreadedCompositor constructor.
(WebKit::ThreadedCoordinatedLayerTreeHost::scrollNonCompositedContents): Update the viewport and call didChangeViewport().
(WebKit::ThreadedCoordinatedLayerTreeHost::contentsSizeChanged): Ditto.
(WebKit::ThreadedCoordinatedLayerTreeHost::deviceOrPageScaleFactorChanged): Pass the effective scale factor to
the compositor.
(WebKit::ThreadedCoordinatedLayerTreeHost::sizeDidChange): Update the viewport, the compositor and call didChangeViewport().
(WebKit::ThreadedCoordinatedLayerTreeHost::didChangeViewportProperties): Update the viewport and call didChangeViewport().
(WebKit::ThreadedCoordinatedLayerTreeHost::didChangeViewport): Notify the compositing coordinator about the new
visible contents rectangle, and update the threaded compositor if needed.

  • WebProcess/WebPage/CoordinatedGraphics/ThreadedCoordinatedLayerTreeHost.h:
Location:
trunk/Source/WebKit2
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r205381 r205395  
     12016-09-02  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [Threaded Compositor] Move the viewport controller off the compositing thread
     4        https://bugs.webkit.org/show_bug.cgi?id=161532
     5
     6        Reviewed by Michael Catanzaro.
     7
     8        While working on bug #161242 I've realized that having the view port controller in the compositing thread makes
     9        everything more complex. The viewport controller receives changes about things like contents size, viewport
     10        size, etc. and uses that information to compute the visible contents rect and page scale factor. Then it
     11        notifies back to main thread about the computed visible contents rect and page scale. Those computations are not
     12        heave at all, so they could be done in the main thread and we would avoid communications between the main and
     13        compositing thread in both directions. The main thread needs the visible contents rect to notify the compositing
     14        coordinator and the page cale to scale the page in case of pixed layout. But the compositing thread only needs
     15        to know the effective scale and scroll position. So, instead of going to the compositing thread after every
     16        change that might update the visible contents rect and page scale factor, we could do those calculations in the
     17        main thread and only notify the compositing thread about the actual changes in the scroll position and effective scale.
     18
     19        * Shared/CoordinatedGraphics/CoordinatedGraphicsScene.cpp:
     20        (WebKit::CoordinatedGraphicsScene::createTilesIfNeeded): Return early if backingStore is nullptr, which can
     21        happen if the layer shouldn't have a backing store and was removed by the previous call to prepareContentBackingStore().
     22        (WebKit::CoordinatedGraphicsScene::updateTilesIfNeeded): Ditto.
     23        * Shared/CoordinatedGraphics/SimpleViewportController.cpp:
     24        (WebKit::SimpleViewportController::SimpleViewportController): Remove the client since we no longer need to
     25        notify about changes.
     26        (WebKit::SimpleViewportController::didChangeViewportSize): Remove call to syncVisibleContents().
     27        (WebKit::SimpleViewportController::didChangeContentsSize): Ditto.
     28        (WebKit::SimpleViewportController::didChangeViewportAttributes): Ditto.
     29        (WebKit::SimpleViewportController::didScroll): Removed unused scrollBy methods and renamed scrollTo as
     30        didiScroll for consistency. Save the position without calling boundContentsPosition, because that's already
     31        donde when the position is used to compute the contents visible rectangle.
     32        (WebKit::SimpleViewportController::visibleContentsRect): No need to notify about the changes.
     33        (WebKit::SimpleViewportController::visibleContentsSize): Deleted.
     34        * Shared/CoordinatedGraphics/SimpleViewportController.h:
     35        * Shared/CoordinatedGraphics/threadedcompositor/ThreadedCompositor.cpp:
     36        (WebKit::ThreadedCompositor::create): Pass a reference to the client instead of a pointer. It's no longer
     37        possible to have a valid pointer when the object has been destroyed, so we can better use a reference now.
     38        (WebKit::ThreadedCompositor::ThreadedCompositor): Ditto.
     39        (WebKit::ThreadedCompositor::~ThreadedCompositor): Remove assert.
     40        (WebKit::ThreadedCompositor::invalidate): No need to invalidate the client.
     41        (WebKit::ThreadedCompositor::setScaleFactor): Set the effective scale factor that should be used for rendering.
     42        (WebKit::ThreadedCompositor::setScrollPosition): Set the current scroll position and effective scale factor.
     43        (WebKit::ThreadedCompositor::setViewportSize): Set the viewport size and effective scale factor.
     44        (WebKit::ThreadedCompositor::renderNextFrame): Update m_client use that is no longer a pointer.
     45        (WebKit::ThreadedCompositor::commitScrollOffset): Ditto.
     46        (WebKit::ThreadedCompositor::renderLayerTree): Call glViewport after a resize and use m_viewportSize,
     47        m_scrollPosition and m_scaleFactor members.
     48        (WebKit::ThreadedCompositor::didChangeVisibleRect): Deleted.
     49        * Shared/CoordinatedGraphics/threadedcompositor/ThreadedCompositor.h:
     50        * WebProcess/WebPage/CoordinatedGraphics/ThreadedCoordinatedLayerTreeHost.cpp:
     51        (WebKit::ThreadedCoordinatedLayerTreeHost::ThreadedCoordinatedLayerTreeHost): Pass the compositor client as a
     52        reference to ThreadedCompositor constructor.
     53        (WebKit::ThreadedCoordinatedLayerTreeHost::scrollNonCompositedContents): Update the viewport and call didChangeViewport().
     54        (WebKit::ThreadedCoordinatedLayerTreeHost::contentsSizeChanged): Ditto.
     55        (WebKit::ThreadedCoordinatedLayerTreeHost::deviceOrPageScaleFactorChanged): Pass the effective scale factor to
     56        the compositor.
     57        (WebKit::ThreadedCoordinatedLayerTreeHost::sizeDidChange): Update the viewport, the compositor and call didChangeViewport().
     58        (WebKit::ThreadedCoordinatedLayerTreeHost::didChangeViewportProperties): Update the viewport and call didChangeViewport().
     59        (WebKit::ThreadedCoordinatedLayerTreeHost::didChangeViewport): Notify the compositing coordinator about the new
     60        visible contents rectangle, and update the threaded compositor if needed.
     61        * WebProcess/WebPage/CoordinatedGraphics/ThreadedCoordinatedLayerTreeHost.h:
     62
    1632016-09-02  Beth Dakin  <bdakin@apple.com>
    264
  • trunk/Source/WebKit2/Shared/CoordinatedGraphics/CoordinatedGraphicsScene.cpp

    r203776 r205395  
    446446
    447447    RefPtr<CoordinatedBackingStore> backingStore = m_backingStores.get(layer);
    448     ASSERT(backingStore);
     448    ASSERT(backingStore || !layerShouldHaveBackingStore(layer));
     449    if (!backingStore)
     450        return;
    449451
    450452    for (auto& tile : state.tilesToCreate)
     
    473475
    474476    RefPtr<CoordinatedBackingStore> backingStore = m_backingStores.get(layer);
    475     ASSERT(backingStore);
     477    ASSERT(backingStore || !layerShouldHaveBackingStore(layer));
     478    if (!backingStore)
     479        return;
    476480
    477481    for (auto& tile : state.tilesToUpdate) {
  • trunk/Source/WebKit2/Shared/CoordinatedGraphics/SimpleViewportController.cpp

    r177276 r205395  
    2121
    2222#include "config.h"
     23#include "SimpleViewportController.h"
    2324
    2425#if USE(COORDINATED_GRAPHICS_THREADED)
    25 #include "SimpleViewportController.h"
    2626
    2727using namespace WebCore;
     
    2929namespace WebKit {
    3030
    31 SimpleViewportController::SimpleViewportController(Client* client)
    32     : m_client(client)
    33     , m_contentsPosition(FloatPoint())
    34     , m_contentsSize(FloatSize())
    35     , m_viewportSize(FloatSize())
    36     , m_allowsUserScaling(false)
    37     , m_initiallyFitToViewport(true)
    38     , m_hasViewportAttribute(false)
     31SimpleViewportController::SimpleViewportController()
    3932{
    4033    resetViewportToDefaultState();
    4134}
    4235
    43 void SimpleViewportController::didChangeViewportSize(const FloatSize& newSize)
     36void SimpleViewportController::didChangeViewportSize(const IntSize& newSize)
    4437{
    4538    if (newSize.isEmpty())
     
    4841    m_viewportSize = newSize;
    4942    updateMinimumScaleToFit();
    50     syncVisibleContents();
    5143}
    5244
     
    6355        restrictScaleFactorToInitialScaleIfNotUserScalable(m_rawAttributes);
    6456    }
    65 
    66     syncVisibleContents();
    6757}
    6858
    69 void SimpleViewportController::didChangeViewportAttribute(const ViewportAttributes& newAttributes)
     59void SimpleViewportController::didChangeViewportAttributes(const ViewportAttributes& newAttributes)
    7060{
    7161    if (newAttributes.layoutSize.isEmpty()) {
     
    8474
    8575    updateMinimumScaleToFit();
    86 
    87     syncVisibleContents();
    8876}
    8977
    90 void SimpleViewportController::scrollBy(const IntSize& scrollOffset)
     78void SimpleViewportController::didScroll(const IntPoint& position)
    9179{
    92     m_contentsPosition.move(scrollOffset);
    93     m_contentsPosition = boundContentsPosition(m_contentsPosition);
    94 
    95     syncVisibleContents();
    96 }
    97 
    98 void SimpleViewportController::scrollTo(const IntPoint& position)
    99 {
    100     if (m_contentsPosition == boundContentsPosition(position))
    101         return;
    102 
    103     m_contentsPosition = boundContentsPosition(position);
    104     syncVisibleContents();
    105 }
    106 
    107 void SimpleViewportController::syncVisibleContents()
    108 {
    109     if (m_viewportSize.isEmpty() || m_contentsSize.isEmpty())
    110         return;
    111 
    112     m_client->didChangeVisibleRect();
     80    m_contentsPosition = position;
    11381}
    11482
    11583FloatRect SimpleViewportController::visibleContentsRect() const
    11684{
     85    if (m_viewportSize.isEmpty() || m_contentsSize.isEmpty())
     86        return { };
     87
    11788    FloatRect visibleContentsRect(boundContentsPosition(m_contentsPosition), visibleContentsSize());
    11889    visibleContentsRect.intersect(FloatRect(FloatPoint::zero(), m_contentsSize));
    119 
    12090    return visibleContentsRect;
    12191}
  • trunk/Source/WebKit2/Shared/CoordinatedGraphics/SimpleViewportController.h

    r177276 r205395  
    3838    WTF_MAKE_NONCOPYABLE(SimpleViewportController);
    3939public:
    40     class Client {
    41     public:
    42         virtual void didChangeVisibleRect() = 0;
    43     };
     40    SimpleViewportController();
    4441
    45     explicit SimpleViewportController(Client*);
    46 
    47     void didChangeViewportSize(const WebCore::FloatSize&);
     42    void didChangeViewportSize(const WebCore::IntSize&);
    4843    void didChangeContentsSize(const WebCore::IntSize&);
    49     void didChangeViewportAttribute(const WebCore::ViewportAttributes&);
    50 
    51     void scrollBy(const WebCore::IntSize&);
    52     void scrollTo(const WebCore::IntPoint&);
     44    void didChangeViewportAttributes(const WebCore::ViewportAttributes&);
     45    void didScroll(const WebCore::IntPoint&);
    5346
    5447    WebCore::FloatRect visibleContentsRect() const;
     
    5649
    5750private:
    58 
    5951    WebCore::FloatSize visibleContentsSize() const;
    60 
    61     void syncVisibleContents();
    6252
    6353    void applyScaleAfterRenderingContents(float scale);
     
    7262    void resetViewportToDefaultState();
    7363
    74     Client* m_client;
    75 
    76     WebCore::FloatPoint m_contentsPosition;
     64    WebCore::IntPoint m_contentsPosition;
    7765    WebCore::FloatSize m_contentsSize;
    7866    WebCore::FloatSize m_viewportSize;
    79     float m_pageScaleFactor;
     67    float m_pageScaleFactor { 1 };
    8068
    81     bool m_allowsUserScaling;
    82     float m_minimumScaleToFit;
    83     bool m_initiallyFitToViewport;
     69    bool m_allowsUserScaling { false };
     70    float m_minimumScaleToFit { 1 };
     71    bool m_initiallyFitToViewport { false };
    8472
    85     bool m_hasViewportAttribute;
     73    bool m_hasViewportAttribute { false };
    8674    WebCore::ViewportAttributes m_rawAttributes;
    8775};
  • trunk/Source/WebKit2/Shared/CoordinatedGraphics/threadedcompositor/ThreadedCompositor.cpp

    r205116 r205395  
    4343namespace WebKit {
    4444
    45 Ref<ThreadedCompositor> ThreadedCompositor::create(Client* client, uint64_t nativeSurfaceHandle, ShouldDoFrameSync doFrameSync)
     45Ref<ThreadedCompositor> ThreadedCompositor::create(Client& client, uint64_t nativeSurfaceHandle, ShouldDoFrameSync doFrameSync)
    4646{
    4747    return adoptRef(*new ThreadedCompositor(client, nativeSurfaceHandle, doFrameSync));
    4848}
    4949
    50 ThreadedCompositor::ThreadedCompositor(Client* client, uint64_t nativeSurfaceHandle, ShouldDoFrameSync doFrameSync)
     50ThreadedCompositor::ThreadedCompositor(Client& client, uint64_t nativeSurfaceHandle, ShouldDoFrameSync doFrameSync)
    5151    : m_client(client)
    5252    , m_nativeSurfaceHandle(nativeSurfaceHandle)
     
    5656    m_compositingRunLoop->performTaskSync([this, protectedThis = makeRef(*this)] {
    5757        m_scene = adoptRef(new CoordinatedGraphicsScene(this));
    58         m_viewportController = std::make_unique<SimpleViewportController>(this);
    5958        m_scene->setActive(!!m_nativeSurfaceHandle);
    6059    });
     
    6362ThreadedCompositor::~ThreadedCompositor()
    6463{
    65     ASSERT(!m_client);
    6664}
    6765
     
    7472        m_context = nullptr;
    7573        m_scene = nullptr;
    76         m_viewportController = nullptr;
    7774    });
    7875    m_compositingRunLoop = nullptr;
    79     m_client = nullptr;
    8076}
    8177
     
    9490}
    9591
    96 void ThreadedCompositor::setDeviceScaleFactor(float scale)
     92void ThreadedCompositor::setScaleFactor(float scale)
    9793{
    9894    m_compositingRunLoop->performTask([this, protectedThis = makeRef(*this), scale] {
    99         m_deviceScaleFactor = scale;
     95        m_scaleFactor = scale;
     96        scheduleDisplayImmediately();
     97    });
     98}
     99
     100void ThreadedCompositor::setScrollPosition(const IntPoint& scrollPosition, float scale)
     101{
     102    m_compositingRunLoop->performTask([this, protectedThis = makeRef(*this), scrollPosition, scale] {
     103        m_scrollPosition = scrollPosition;
     104        m_scaleFactor = scale;
     105        scheduleDisplayImmediately();
     106    });
     107}
     108
     109void ThreadedCompositor::setViewportSize(const IntSize& viewportSize, float scale)
     110{
     111    m_compositingRunLoop->performTaskSync([this, protectedThis = makeRef(*this), viewportSize, scale] {
     112        m_viewportSize = viewportSize;
     113        m_scaleFactor = scale;
     114        m_needsResize = true;
    100115        scheduleDisplayImmediately();
    101116    });
     
    110125}
    111126
    112 void ThreadedCompositor::didChangeViewportSize(const IntSize& size)
    113 {
    114     m_compositingRunLoop->performTaskSync([this, protectedThis = makeRef(*this), size] {
    115         m_viewportController->didChangeViewportSize(size);
    116     });
    117 }
    118 
    119 void ThreadedCompositor::didChangeViewportAttribute(const ViewportAttributes& attr)
    120 {
    121     m_compositingRunLoop->performTask([this, protectedThis = makeRef(*this), attr] {
    122         m_viewportController->didChangeViewportAttribute(attr);
    123     });
    124 }
    125 
    126 void ThreadedCompositor::didChangeContentsSize(const IntSize& size)
    127 {
    128     m_compositingRunLoop->performTask([this, protectedThis = makeRef(*this), size] {
    129         m_viewportController->didChangeContentsSize(size);
    130     });
    131 }
    132 
    133 void ThreadedCompositor::scrollTo(const IntPoint& position)
    134 {
    135     m_compositingRunLoop->performTask([this, protectedThis = makeRef(*this), position] {
    136         m_viewportController->scrollTo(position);
    137     });
    138 }
    139 
    140 void ThreadedCompositor::scrollBy(const IntSize& delta)
    141 {
    142     m_compositingRunLoop->performTask([this, protectedThis = makeRef(*this), delta] {
    143         m_viewportController->scrollBy(delta);
    144     });
    145 }
    146 
    147127void ThreadedCompositor::renderNextFrame()
    148128{
    149129    ASSERT(isMainThread());
    150     m_client->renderNextFrame();
     130    m_client.renderNextFrame();
    151131}
    152132
     
    154134{
    155135    ASSERT(isMainThread());
    156     m_client->commitScrollOffset(layerID, offset);
     136    m_client.commitScrollOffset(layerID, offset);
    157137}
    158138
     
    195175}
    196176
    197 void ThreadedCompositor::didChangeVisibleRect()
    198 {
    199     RunLoop::main().dispatch([this, protectedThis = makeRef(*this), visibleRect = m_viewportController->visibleContentsRect(), scale = m_viewportController->pageScaleFactor()] {
    200         if (m_client)
    201             m_client->setVisibleContentsRect(visibleRect, FloatPoint::zero(), scale);
    202     });
    203 
    204     scheduleDisplayImmediately();
    205 }
    206 
    207177void ThreadedCompositor::renderLayerTree()
    208178{
     
    213183        return;
    214184
    215     // The window size may be out of sync with the page size at this point, and getting
    216     // the viewport parameters incorrect, means that the content will be misplaced. Thus,
    217     // we set the viewport parameters directly from the window size.
    218     IntSize contextSize = m_context->defaultFrameBufferSize();
    219     if (m_viewportSize != contextSize) {
    220         glViewport(0, 0, contextSize.width(), contextSize.height());
    221         m_viewportSize = contextSize;
     185    if (m_needsResize) {
     186        glViewport(0, 0, m_viewportSize.width(), m_viewportSize.height());
     187        m_needsResize = false;
    222188    }
    223 
    224189    FloatRect clipRect(0, 0, m_viewportSize.width(), m_viewportSize.height());
    225190
    226191    TransformationMatrix viewportTransform;
    227     FloatPoint scrollPostion = m_viewportController->visibleContentsRect().location();
    228     viewportTransform.scale(m_viewportController->pageScaleFactor() * m_deviceScaleFactor);
    229     viewportTransform.translate(-scrollPostion.x(), -scrollPostion.y());
     192    viewportTransform.scale(m_scaleFactor);
     193    viewportTransform.translate(-m_scrollPosition.x(), -m_scrollPosition.y());
    230194
    231195    if (!m_drawsBackground) {
     
    233197        glClear(GL_COLOR_BUFFER_BIT);
    234198    }
    235     m_scene->paintToCurrentGLContext(viewportTransform, 1, clipRect, Color::transparent, !m_drawsBackground, scrollPostion);
     199    m_scene->paintToCurrentGLContext(viewportTransform, 1, clipRect, Color::transparent, !m_drawsBackground, m_scrollPosition);
    236200
    237201    m_context->swapBuffers();
  • trunk/Source/WebKit2/Shared/CoordinatedGraphics/threadedcompositor/ThreadedCompositor.h

    r205116 r205395  
    3131#include "CompositingRunLoop.h"
    3232#include "CoordinatedGraphicsScene.h"
    33 #include "SimpleViewportController.h"
    3433#include <WebCore/GLContext.h>
    3534#include <WebCore/IntSize.h>
     
    4746class CoordinatedGraphicsSceneClient;
    4847
    49 class ThreadedCompositor : public SimpleViewportController::Client, public CoordinatedGraphicsSceneClient, public ThreadSafeRefCounted<ThreadedCompositor> {
     48class ThreadedCompositor : public CoordinatedGraphicsSceneClient, public ThreadSafeRefCounted<ThreadedCompositor> {
    5049    WTF_MAKE_NONCOPYABLE(ThreadedCompositor);
    5150    WTF_MAKE_FAST_ALLOCATED;
     
    5352    class Client {
    5453    public:
    55         virtual void setVisibleContentsRect(const WebCore::FloatRect&, const WebCore::FloatPoint&, float) = 0;
    5654        virtual void renderNextFrame() = 0;
    5755        virtual void commitScrollOffset(uint32_t layerID, const WebCore::IntSize& offset) = 0;
     
    6058    enum class ShouldDoFrameSync { No, Yes };
    6159
    62     static Ref<ThreadedCompositor> create(Client*, uint64_t nativeSurfaceHandle = 0, ShouldDoFrameSync = ShouldDoFrameSync::Yes);
     60    static Ref<ThreadedCompositor> create(Client&, uint64_t nativeSurfaceHandle = 0, ShouldDoFrameSync = ShouldDoFrameSync::Yes);
    6361    virtual ~ThreadedCompositor();
    6462
    6563    void setNativeSurfaceHandleForCompositing(uint64_t);
    66     void setDeviceScaleFactor(float);
     64    void setScaleFactor(float);
     65    void setScrollPosition(const WebCore::IntPoint&, float scale);
     66    void setViewportSize(const WebCore::IntSize&, float scale);
    6767    void setDrawsBackground(bool);
    6868
    6969    void updateSceneState(const WebCore::CoordinatedGraphicsState&);
    70 
    71     void didChangeViewportSize(const WebCore::IntSize&);
    72     void didChangeViewportAttribute(const WebCore::ViewportAttributes&);
    73     void didChangeContentsSize(const WebCore::IntSize&);
    74     void scrollTo(const WebCore::IntPoint&);
    75     void scrollBy(const WebCore::IntSize&);
    7670
    7771    void invalidate();
     
    8074
    8175private:
    82     ThreadedCompositor(Client*, uint64_t nativeSurfaceHandle, ShouldDoFrameSync);
     76    ThreadedCompositor(Client&, uint64_t nativeSurfaceHandle, ShouldDoFrameSync);
    8377
    8478    // CoordinatedGraphicsSceneClient
     
    8781    void commitScrollOffset(uint32_t layerID, const WebCore::IntSize& offset) override;
    8882
    89     // SimpleViewportController::Client.
    90     void didChangeVisibleRect() override;
    91 
    9283    void renderLayerTree();
    9384    void scheduleDisplayImmediately();
     
    9586    bool makeContextCurrent();
    9687
    97     Client* m_client { nullptr };
     88    Client& m_client;
    9889    RefPtr<CoordinatedGraphicsScene> m_scene;
    99     std::unique_ptr<SimpleViewportController> m_viewportController;
    10090    std::unique_ptr<WebCore::GLContext> m_context;
    10191
    10292    WebCore::IntSize m_viewportSize;
    103     float m_deviceScaleFactor { 1 };
     93    WebCore::IntPoint m_scrollPosition;
     94    float m_scaleFactor { 1 };
    10495    bool m_drawsBackground { true };
    10596    uint64_t m_nativeSurfaceHandle;
    10697    ShouldDoFrameSync m_doFrameSync;
     98    bool m_needsResize { false };
    10799
    108100    std::unique_ptr<CompositingRunLoop> m_compositingRunLoop;
  • trunk/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/ThreadedCoordinatedLayerTreeHost.cpp

    r205116 r205395  
    5959        // Rendering to the actual screen will happen later anyway since the UI process schedules a redraw for every update,
    6060        // the compositor will take care of syncing to vblank.
    61         m_compositor = ThreadedCompositor::create(&m_compositorClient, m_surface->window(), ThreadedCompositor::ShouldDoFrameSync::No);
     61        m_compositor = ThreadedCompositor::create(m_compositorClient, m_surface->window(), ThreadedCompositor::ShouldDoFrameSync::No);
    6262        m_layerTreeContext.contextID = m_surface->surfaceID();
    6363    } else
    64         m_compositor = ThreadedCompositor::create(&m_compositorClient);
     64        m_compositor = ThreadedCompositor::create(m_compositorClient);
    6565}
    6666
     
    7878}
    7979
    80 void ThreadedCoordinatedLayerTreeHost::scrollNonCompositedContents(const WebCore::IntRect& rect)
     80void ThreadedCoordinatedLayerTreeHost::scrollNonCompositedContents(const IntRect& rect)
    8181{
    82     m_compositor->scrollTo(rect.location());
    83     scheduleLayerFlush();
     82    m_viewportController.didScroll(rect.location());
     83    didChangeViewport();
    8484}
    8585
    86 void ThreadedCoordinatedLayerTreeHost::contentsSizeChanged(const WebCore::IntSize& newSize)
     86void ThreadedCoordinatedLayerTreeHost::contentsSizeChanged(const IntSize& newSize)
    8787{
    88     m_compositor->didChangeContentsSize(newSize);
     88    m_viewportController.didChangeContentsSize(newSize);
     89    didChangeViewport();
    8990}
    9091
     
    9596
    9697    CoordinatedLayerTreeHost::deviceOrPageScaleFactorChanged();
    97     m_compositor->setDeviceScaleFactor(m_webPage.deviceScaleFactor());
     98    m_compositor->setScaleFactor(m_webPage.deviceScaleFactor() * m_viewportController.pageScaleFactor());
    9899}
    99100
     
    110111
    111112    CoordinatedLayerTreeHost::sizeDidChange(size);
    112     m_compositor->didChangeViewportSize(size);
     113    m_viewportController.didChangeViewportSize(size);
     114    IntSize scaledSize(size);
     115    scaledSize.scale(m_webPage.deviceScaleFactor());
     116    m_compositor->setViewportSize(scaledSize, m_webPage.deviceScaleFactor() * m_viewportController.pageScaleFactor());
     117    didChangeViewport();
    113118}
    114119
    115 void ThreadedCoordinatedLayerTreeHost::didChangeViewportProperties(const WebCore::ViewportAttributes& attr)
     120void ThreadedCoordinatedLayerTreeHost::didChangeViewportProperties(const ViewportAttributes& attr)
    116121{
    117     m_compositor->didChangeViewportAttribute(attr);
    118 }
    119 
    120 void ThreadedCoordinatedLayerTreeHost::didScaleFactorChanged(float scale, const IntPoint& origin)
    121 {
    122     m_webPage.scalePage(scale, origin);
     122    m_viewportController.didChangeViewportAttributes(attr);
     123    didChangeViewport();
    123124}
    124125
     
    132133#endif
    133134
    134 void ThreadedCoordinatedLayerTreeHost::setVisibleContentsRect(const FloatRect& rect, const FloatPoint& trajectoryVector, float scale)
     135void ThreadedCoordinatedLayerTreeHost::didChangeViewport()
    135136{
    136     FloatRect visibleRect(rect);
     137    FloatRect visibleRect(m_viewportController.visibleContentsRect());
     138    if (visibleRect.isEmpty())
     139        return;
    137140
    138141    // When using non overlay scrollbars, the contents size doesn't include the scrollbars, but we need to include them
     
    147150        visibleRect.expand(0, scrollbar->height());
    148151
    149     CoordinatedLayerTreeHost::setVisibleContentsRect(visibleRect, trajectoryVector);
    150     if (m_lastScrollPosition != roundedIntPoint(visibleRect.location())) {
    151         m_lastScrollPosition = roundedIntPoint(visibleRect.location());
     152    CoordinatedLayerTreeHost::setVisibleContentsRect(visibleRect, FloatPoint::zero());
     153
     154    float pageScale = m_viewportController.pageScaleFactor();
     155    IntPoint scrollPosition = roundedIntPoint(visibleRect.location());
     156    if (m_lastScrollPosition != scrollPosition) {
     157        m_lastScrollPosition = scrollPosition;
     158        m_compositor->setScrollPosition(m_lastScrollPosition, m_webPage.deviceScaleFactor() * pageScale);
    152159
    153160        if (!view->useFixedLayout())
     
    155162    }
    156163
    157     if (m_lastScaleFactor != scale) {
    158         m_lastScaleFactor = scale;
    159         didScaleFactorChanged(m_lastScaleFactor, m_lastScrollPosition);
     164    if (m_lastPageScaleFactor != pageScale) {
     165        m_lastPageScaleFactor = pageScale;
     166        m_webPage.scalePage(pageScale, m_lastScrollPosition);
    160167    }
    161168}
  • trunk/Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/ThreadedCoordinatedLayerTreeHost.h

    r205116 r205395  
    3232
    3333#include "CoordinatedLayerTreeHost.h"
     34#include "SimpleViewportController.h"
    3435#include "ThreadedCompositor.h"
    3536
     
    7980
    8081    private:
    81         void setVisibleContentsRect(const WebCore::FloatRect& rect, const WebCore::FloatPoint& trajectoryVector, float scale) override
    82         {
    83             m_layerTreeHost.setVisibleContentsRect(rect, trajectoryVector, scale);
    84         }
    85 
    8682        void renderNextFrame() override
    8783        {
     
    9793    };
    9894
    99     void didScaleFactorChanged(float scale, const WebCore::IntPoint& origin);
    100 
    101     void setVisibleContentsRect(const WebCore::FloatRect&, const WebCore::FloatPoint&, float);
     95    void didChangeViewport();
    10296
    10397    // CompositingCoordinator::Client
     
    108102    std::unique_ptr<AcceleratedSurface> m_surface;
    109103    RefPtr<ThreadedCompositor> m_compositor;
    110     float m_lastScaleFactor { 1 };
    111     WebCore::IntPoint m_prevScrollPosition;
     104    SimpleViewportController m_viewportController;
     105    float m_lastPageScaleFactor { 1 };
    112106    WebCore::IntPoint m_lastScrollPosition;
    113107};
Note: See TracChangeset for help on using the changeset viewer.