Coordinated Graphics: remove the DidChangeScrollPosition message.
[WebKit-https.git] / Source / WebKit2 / UIProcess / CoordinatedGraphics / CoordinatedLayerTreeHostProxy.cpp
1 /*
2     Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies)
3
4     This library is free software; you can redistribute it and/or
5     modify it under the terms of the GNU Library General Public
6     License as published by the Free Software Foundation; either
7     version 2 of the License, or (at your option) any later version.
8
9     This library is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12     Library General Public License for more details.
13
14     You should have received a copy of the GNU Library General Public License
15     along with this library; see the file COPYING.LIB.  If not, write to
16     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17     Boston, MA 02110-1301, USA.
18 */
19
20 #include "config.h"
21
22 #if USE(COORDINATED_GRAPHICS)
23 #include "CoordinatedLayerTreeHostProxy.h"
24
25 #include "CoordinatedLayerTreeHostMessages.h"
26 #include "CoordinatedLayerTreeHostProxyMessages.h"
27 #include "WebCoreArgumentCoders.h"
28 #include "WebPageProxy.h"
29 #include "WebProcessProxy.h"
30 #include <WebCore/CoordinatedLayerInfo.h>
31 #include <WebCore/GraphicsSurface.h>
32 #include <WebCore/SurfaceUpdateInfo.h>
33
34 #if ENABLE(CSS_SHADERS)
35 #include "CustomFilterProgramInfo.h"
36 #endif
37
38 namespace WebKit {
39
40 using namespace WebCore;
41
42 CoordinatedLayerTreeHostProxy::CoordinatedLayerTreeHostProxy(DrawingAreaProxy* drawingAreaProxy)
43     : m_drawingAreaProxy(drawingAreaProxy)
44     , m_scene(adoptRef(new CoordinatedGraphicsScene(this)))
45 {
46     m_drawingAreaProxy->page()->process()->addMessageReceiver(Messages::CoordinatedLayerTreeHostProxy::messageReceiverName(), m_drawingAreaProxy->page()->pageID(), this);
47 }
48
49 CoordinatedLayerTreeHostProxy::~CoordinatedLayerTreeHostProxy()
50 {
51     m_drawingAreaProxy->page()->process()->removeMessageReceiver(Messages::CoordinatedLayerTreeHostProxy::messageReceiverName(), m_drawingAreaProxy->page()->pageID());
52     m_scene->detach();
53 }
54
55 void CoordinatedLayerTreeHostProxy::updateViewport()
56 {
57     m_drawingAreaProxy->updateViewport();
58 }
59
60 void CoordinatedLayerTreeHostProxy::dispatchUpdate(const Function<void()>& function)
61 {
62     m_scene->appendUpdate(function);
63 }
64
65 void CoordinatedLayerTreeHostProxy::createTileForLayer(CoordinatedLayerID layerID, uint32_t tileID, const IntRect& tileRect, const SurfaceUpdateInfo& updateInfo)
66 {
67     dispatchUpdate(bind(&CoordinatedGraphicsScene::createTile, m_scene.get(), layerID, tileID, updateInfo.scaleFactor));
68     updateTileForLayer(layerID, tileID, tileRect, updateInfo);
69 }
70
71 void CoordinatedLayerTreeHostProxy::updateTileForLayer(CoordinatedLayerID layerID, uint32_t tileID, const IntRect& tileRect, const SurfaceUpdateInfo& updateInfo)
72 {
73     dispatchUpdate(bind(&CoordinatedGraphicsScene::updateTile, m_scene.get(), layerID, tileID, CoordinatedGraphicsScene::TileUpdate(updateInfo.updateRect, tileRect, updateInfo.atlasID, updateInfo.surfaceOffset)));
74 }
75
76 void CoordinatedLayerTreeHostProxy::removeTileForLayer(CoordinatedLayerID layerID, uint32_t tileID)
77 {
78     dispatchUpdate(bind(&CoordinatedGraphicsScene::removeTile, m_scene.get(), layerID, tileID));
79 }
80
81 void CoordinatedLayerTreeHostProxy::createUpdateAtlas(uint32_t atlasID, const WebCoordinatedSurface::Handle& handle)
82 {
83     dispatchUpdate(bind(&CoordinatedGraphicsScene::createUpdateAtlas, m_scene.get(), atlasID, WebCoordinatedSurface::create(handle)));
84 }
85
86 void CoordinatedLayerTreeHostProxy::removeUpdateAtlas(uint32_t atlasID)
87 {
88     dispatchUpdate(bind(&CoordinatedGraphicsScene::removeUpdateAtlas, m_scene.get(), atlasID));
89 }
90
91 void CoordinatedLayerTreeHostProxy::createCompositingLayers(const Vector<CoordinatedLayerID>& ids)
92 {
93     dispatchUpdate(bind(&CoordinatedGraphicsScene::createLayers, m_scene.get(), ids));
94 }
95
96 void CoordinatedLayerTreeHostProxy::deleteCompositingLayers(const Vector<CoordinatedLayerID>& ids)
97 {
98     dispatchUpdate(bind(&CoordinatedGraphicsScene::deleteLayers, m_scene.get(), ids));
99 }
100
101 void CoordinatedLayerTreeHostProxy::setRootCompositingLayer(CoordinatedLayerID id)
102 {
103     dispatchUpdate(bind(&CoordinatedGraphicsScene::setRootLayerID, m_scene.get(), id));
104 }
105
106 void CoordinatedLayerTreeHostProxy::setCompositingLayerState(CoordinatedLayerID id, const CoordinatedLayerInfo& info)
107 {
108     dispatchUpdate(bind(&CoordinatedGraphicsScene::setLayerState, m_scene.get(), id, info));
109 }
110
111 void CoordinatedLayerTreeHostProxy::setCompositingLayerChildren(CoordinatedLayerID id, const Vector<CoordinatedLayerID>& children)
112 {
113     dispatchUpdate(bind(&CoordinatedGraphicsScene::setLayerChildren, m_scene.get(), id, children));
114 }
115
116 #if ENABLE(CSS_FILTERS)
117 void CoordinatedLayerTreeHostProxy::setCompositingLayerFilters(CoordinatedLayerID id, const FilterOperations& filters)
118 {
119     dispatchUpdate(bind(&CoordinatedGraphicsScene::setLayerFilters, m_scene.get(), id, filters));
120 }
121 #endif
122
123 #if ENABLE(CSS_SHADERS)
124 void CoordinatedLayerTreeHostProxy::removeCustomFilterProgram(int id)
125 {
126     dispatchUpdate(bind(&CoordinatedGraphicsScene::removeCustomFilterProgram, m_scene.get(), id));
127 }
128 void CoordinatedLayerTreeHostProxy::createCustomFilterProgram(int id, const CustomFilterProgramInfo& programInfo)
129 {
130     dispatchUpdate(bind(&CoordinatedGraphicsScene::createCustomFilterProgram, m_scene.get(), id, programInfo));
131 }
132 #endif
133
134 void CoordinatedLayerTreeHostProxy::didRenderFrame(const FloatPoint& scrollPosition, const IntSize& contentsSize, const IntRect& coveredRect)
135 {
136     dispatchUpdate(bind(&CoordinatedGraphicsScene::flushLayerChanges, m_scene.get(), scrollPosition));
137     updateViewport();
138 #if USE(TILED_BACKING_STORE)
139     m_drawingAreaProxy->page()->didRenderFrame(contentsSize, coveredRect);
140 #else
141     UNUSED_PARAM(contentsSize);
142     UNUSED_PARAM(coveredRect);
143 #endif
144 }
145
146 void CoordinatedLayerTreeHostProxy::createImageBacking(CoordinatedImageBackingID imageID)
147 {
148     dispatchUpdate(bind(&CoordinatedGraphicsScene::createImageBacking, m_scene.get(), imageID));
149 }
150
151 void CoordinatedLayerTreeHostProxy::updateImageBacking(CoordinatedImageBackingID imageID, const WebCoordinatedSurface::Handle& handle)
152 {
153     dispatchUpdate(bind(&CoordinatedGraphicsScene::updateImageBacking, m_scene.get(), imageID, WebCoordinatedSurface::create(handle)));
154 }
155
156 void CoordinatedLayerTreeHostProxy::clearImageBackingContents(CoordinatedImageBackingID imageID)
157 {
158     dispatchUpdate(bind(&CoordinatedGraphicsScene::clearImageBackingContents, m_scene.get(), imageID));
159 }
160
161 void CoordinatedLayerTreeHostProxy::removeImageBacking(CoordinatedImageBackingID imageID)
162 {
163     dispatchUpdate(bind(&CoordinatedGraphicsScene::removeImageBacking, m_scene.get(), imageID));
164 }
165
166 void CoordinatedLayerTreeHostProxy::setContentsSize(const FloatSize& contentsSize)
167 {
168     dispatchUpdate(bind(&CoordinatedGraphicsScene::setContentsSize, m_scene.get(), contentsSize));
169 }
170
171 void CoordinatedLayerTreeHostProxy::setLayerAnimations(CoordinatedLayerID id, const GraphicsLayerAnimations& animations)
172 {
173     dispatchUpdate(bind(&CoordinatedGraphicsScene::setLayerAnimations, m_scene.get(), id, animations));
174 }
175
176 void CoordinatedLayerTreeHostProxy::setAnimationsLocked(bool locked)
177 {
178     dispatchUpdate(bind(&CoordinatedGraphicsScene::setAnimationsLocked, m_scene.get(), locked));
179 }
180
181 void CoordinatedLayerTreeHostProxy::setVisibleContentsRect(const FloatRect& rect, const FloatPoint& trajectoryVector)
182 {
183     // Inform the renderer to adjust viewport-fixed layers.
184     dispatchUpdate(bind(&CoordinatedGraphicsScene::setVisibleContentsRect, m_scene.get(), rect));
185
186     if (rect == m_lastSentVisibleRect && trajectoryVector == m_lastSentTrajectoryVector)
187         return;
188
189     m_drawingAreaProxy->page()->process()->send(Messages::CoordinatedLayerTreeHost::SetVisibleContentsRect(rect, trajectoryVector), m_drawingAreaProxy->page()->pageID());
190     m_lastSentVisibleRect = rect;
191     m_lastSentTrajectoryVector = trajectoryVector;
192 }
193
194 void CoordinatedLayerTreeHostProxy::renderNextFrame()
195 {
196     m_drawingAreaProxy->page()->process()->send(Messages::CoordinatedLayerTreeHost::RenderNextFrame(), m_drawingAreaProxy->page()->pageID());
197 }
198
199 #if ENABLE(REQUEST_ANIMATION_FRAME)
200 void CoordinatedLayerTreeHostProxy::requestAnimationFrame()
201 {
202     dispatchUpdate(bind(&CoordinatedGraphicsScene::requestAnimationFrame, m_scene.get()));
203     updateViewport();
204 }
205
206 void CoordinatedLayerTreeHostProxy::animationFrameReady()
207 {
208     m_drawingAreaProxy->page()->process()->send(Messages::CoordinatedLayerTreeHost::AnimationFrameReady(), m_drawingAreaProxy->page()->pageID());
209 }
210 #endif
211
212 #if USE(GRAPHICS_SURFACE)
213 void CoordinatedLayerTreeHostProxy::createCanvas(CoordinatedLayerID id, const IntSize& canvasSize, const GraphicsSurfaceToken& token)
214 {
215     GraphicsSurface::Flags surfaceFlags = GraphicsSurface::SupportsTextureTarget | GraphicsSurface::SupportsSharing;
216     dispatchUpdate(bind(&CoordinatedGraphicsScene::createCanvas, m_scene.get(), id, canvasSize, GraphicsSurface::create(canvasSize, surfaceFlags, token)));
217 }
218
219 void CoordinatedLayerTreeHostProxy::syncCanvas(CoordinatedLayerID id, uint32_t frontBuffer)
220 {
221     dispatchUpdate(bind(&CoordinatedGraphicsScene::syncCanvas, m_scene.get(), id, frontBuffer));
222 }
223
224 void CoordinatedLayerTreeHostProxy::destroyCanvas(CoordinatedLayerID id)
225 {
226     dispatchUpdate(bind(&CoordinatedGraphicsScene::destroyCanvas, m_scene.get(), id));
227 }
228 #endif
229
230 void CoordinatedLayerTreeHostProxy::setLayerRepaintCount(CoordinatedLayerID id, int value)
231 {
232     dispatchUpdate(bind(&CoordinatedGraphicsScene::setLayerRepaintCount, m_scene.get(), id, value));
233 }
234
235 void CoordinatedLayerTreeHostProxy::purgeBackingStores()
236 {
237     m_drawingAreaProxy->page()->process()->send(Messages::CoordinatedLayerTreeHost::PurgeBackingStores(), m_drawingAreaProxy->page()->pageID());
238 }
239
240 void CoordinatedLayerTreeHostProxy::setBackgroundColor(const Color& color)
241 {
242     dispatchUpdate(bind(&CoordinatedGraphicsScene::setBackgroundColor, m_scene.get(), color));
243 }
244
245 }
246 #endif // USE(COORDINATED_GRAPHICS)