[WK2] Build fix after r160464
[WebKit-https.git] / Source / WebKit2 / UIProcess / CoordinatedGraphics / CoordinatedLayerTreeHostProxy.cpp
1 /*
2     Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies)
3     Copyright (C) 2013 Company 100, Inc.
4
5     This library is free software; you can redistribute it and/or
6     modify it under the terms of the GNU Library General Public
7     License as published by the Free Software Foundation; either
8     version 2 of the License, or (at your option) any later version.
9
10     This library is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13     Library General Public License for more details.
14
15     You should have received a copy of the GNU Library General Public License
16     along with this library; see the file COPYING.LIB.  If not, write to
17     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18     Boston, MA 02110-1301, USA.
19 */
20
21 #include "config.h"
22
23 #if USE(COORDINATED_GRAPHICS)
24 #include "CoordinatedLayerTreeHostProxy.h"
25
26 #include "CoordinatedDrawingAreaProxy.h"
27 #include "CoordinatedLayerTreeHostMessages.h"
28 #include "CoordinatedLayerTreeHostProxyMessages.h"
29 #include "WebPageProxy.h"
30 #include "WebProcessProxy.h"
31 #include <WebCore/CoordinatedGraphicsState.h>
32
33 namespace WebKit {
34
35 using namespace WebCore;
36
37 CoordinatedLayerTreeHostProxy::CoordinatedLayerTreeHostProxy(CoordinatedDrawingAreaProxy* drawingAreaProxy)
38     : m_drawingAreaProxy(drawingAreaProxy)
39     , m_scene(adoptRef(new CoordinatedGraphicsScene(this)))
40 {
41     m_drawingAreaProxy->page()->process().addMessageReceiver(Messages::CoordinatedLayerTreeHostProxy::messageReceiverName(), m_drawingAreaProxy->page()->pageID(), *this);
42 }
43
44 CoordinatedLayerTreeHostProxy::~CoordinatedLayerTreeHostProxy()
45 {
46     m_drawingAreaProxy->page()->process().removeMessageReceiver(Messages::CoordinatedLayerTreeHostProxy::messageReceiverName(), m_drawingAreaProxy->page()->pageID());
47     m_scene->detach();
48 }
49
50 void CoordinatedLayerTreeHostProxy::updateViewport()
51 {
52     m_drawingAreaProxy->updateViewport();
53 }
54
55 void CoordinatedLayerTreeHostProxy::dispatchUpdate(const Function<void()>& function)
56 {
57     m_scene->appendUpdate(function);
58 }
59
60 void CoordinatedLayerTreeHostProxy::commitCoordinatedGraphicsState(const CoordinatedGraphicsState& graphicsState)
61 {
62     dispatchUpdate(bind(&CoordinatedGraphicsScene::commitSceneState, m_scene.get(), graphicsState));
63     updateViewport();
64 #if USE(TILED_BACKING_STORE)
65     m_drawingAreaProxy->page()->didRenderFrame(graphicsState.contentsSize, graphicsState.coveredRect);
66 #endif
67 }
68
69 void CoordinatedLayerTreeHostProxy::setVisibleContentsRect(const FloatRect& rect, const FloatPoint& trajectoryVector)
70 {
71     // Inform the renderer to adjust viewport-fixed layers.
72     dispatchUpdate(bind(&CoordinatedGraphicsScene::setScrollPosition, m_scene.get(), rect.location()));
73
74     if (rect == m_lastSentVisibleRect && trajectoryVector == m_lastSentTrajectoryVector)
75         return;
76
77     m_drawingAreaProxy->page()->process().send(Messages::CoordinatedLayerTreeHost::SetVisibleContentsRect(rect, trajectoryVector), m_drawingAreaProxy->page()->pageID());
78     m_lastSentVisibleRect = rect;
79     m_lastSentTrajectoryVector = trajectoryVector;
80 }
81
82 void CoordinatedLayerTreeHostProxy::renderNextFrame()
83 {
84     m_drawingAreaProxy->page()->process().send(Messages::CoordinatedLayerTreeHost::RenderNextFrame(), m_drawingAreaProxy->page()->pageID());
85 }
86
87 void CoordinatedLayerTreeHostProxy::purgeBackingStores()
88 {
89     m_drawingAreaProxy->page()->process().send(Messages::CoordinatedLayerTreeHost::PurgeBackingStores(), m_drawingAreaProxy->page()->pageID());
90 }
91
92 void CoordinatedLayerTreeHostProxy::setBackgroundColor(const Color& color)
93 {
94     dispatchUpdate(bind(&CoordinatedGraphicsScene::setBackgroundColor, m_scene.get(), color));
95 }
96
97 void CoordinatedLayerTreeHostProxy::commitScrollOffset(uint32_t layerID, const IntSize& offset)
98 {
99     m_drawingAreaProxy->page()->process().send(Messages::CoordinatedLayerTreeHost::CommitScrollOffset(layerID, offset), m_drawingAreaProxy->page()->pageID());
100 }
101
102 }
103 #endif // USE(COORDINATED_GRAPHICS)