Merge "Use EwkView's variables instead of drawingScaleFactor and drawingScrollPositio...
[framework/web/webkit-efl.git] / Source / WebKit2 / UIProcess / LayerTreeCoordinatorProxy.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(UI_SIDE_COMPOSITING)
23 #include "LayerTreeCoordinatorProxy.h"
24
25 #include "LayerTreeCoordinatorMessages.h"
26 #include "UpdateInfo.h"
27 #include "WebCoreArgumentCoders.h"
28 #include "WebLayerTreeInfo.h"
29 #include "WebLayerTreeRenderer.h"
30 #include "WebPageProxy.h"
31 #include "WebProcessProxy.h"
32 #if ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE)
33 #include "WebLayerTreeRendererTizen.h"
34 #endif
35
36 namespace WebKit {
37
38 using namespace WebCore;
39
40 LayerTreeCoordinatorProxy::LayerTreeCoordinatorProxy(DrawingAreaProxy* drawingAreaProxy)
41     : m_drawingAreaProxy(drawingAreaProxy)
42 #if !ENABLE(TIZEN_WEBKIT2_TILED_AC)
43     , m_renderer(adoptRef(new WebLayerTreeRenderer(this)))
44 #else
45     , m_renderer(adoptRef(new WebLayerTreeRenderer(this, drawingAreaProxy)))
46 #endif
47 {
48 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
49     m_renderer->setActive(true);
50 #endif
51 }
52
53 #if ENABLE(TIZEN_RUNTIME_BACKEND_SELECTION)
54 LayerTreeCoordinatorProxy::LayerTreeCoordinatorProxy(DrawingAreaProxy* drawingAreaProxy, bool isGLMode)
55     : m_drawingAreaProxy(drawingAreaProxy)
56 {
57 #if ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE)
58     WebLayerTreeRenderer* renderer = isGLMode ? new WebLayerTreeRendererTizen(this, drawingAreaProxy) : new WebLayerTreeRenderer(this, drawingAreaProxy, isGLMode);
59     m_renderer = adoptRef(renderer);
60 #else
61     m_renderer = adoptRef(new WebLayerTreeRenderer(this, drawingAreaProxy, isGLMode));
62 #endif // ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE)
63     m_renderer->setActive(true);
64 }
65 #endif // ENABLE(TIZEN_RUNTIME_BACKEND_SELECTION)
66
67 LayerTreeCoordinatorProxy::~LayerTreeCoordinatorProxy()
68 {
69     m_renderer->detach();
70 }
71
72 void LayerTreeCoordinatorProxy::updateViewport()
73 {
74     m_drawingAreaProxy->updateViewport();
75 }
76
77 void LayerTreeCoordinatorProxy::dispatchUpdate(const Function<void()>& function)
78 {
79     m_renderer->appendUpdate(function);
80 }
81
82 void LayerTreeCoordinatorProxy::createTileForLayer(int layerID, int tileID, const IntRect& targetRect, const WebKit::SurfaceUpdateInfo& updateInfo)
83 {
84     dispatchUpdate(bind(&WebLayerTreeRenderer::createTile, m_renderer.get(), layerID, tileID, updateInfo.scaleFactor));
85     updateTileForLayer(layerID, tileID, targetRect, updateInfo);
86 }
87
88 void LayerTreeCoordinatorProxy::updateTileForLayer(int layerID, int tileID, const IntRect& targetRect, const WebKit::SurfaceUpdateInfo& updateInfo)
89 {
90     RefPtr<ShareableSurface> surface;
91 #if ENABLE(TIZEN_RUNTIME_BACKEND_SELECTION)
92     if (!m_renderer->isUsingPlatformSurface()) {
93 #endif
94 #if USE(GRAPHICS_SURFACE)
95     int token = updateInfo.surfaceHandle.graphicsSurfaceToken();
96     if (token) {
97         HashMap<uint32_t, RefPtr<ShareableSurface> >::iterator it = m_surfaces.find(token);
98         if (it == m_surfaces.end()) {
99             surface = ShareableSurface::create(updateInfo.surfaceHandle);
100             m_surfaces.add(token, surface);
101         } else
102             surface = it->second;
103     } else
104         surface = ShareableSurface::create(updateInfo.surfaceHandle);
105 #else
106     surface = ShareableSurface::create(updateInfo.surfaceHandle);
107 #endif
108 #if ENABLE(TIZEN_RUNTIME_BACKEND_SELECTION)
109     }
110 #endif
111
112 #if ENABLE(TIZEN_RUNTIME_BACKEND_SELECTION)
113 #if ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE)
114     dispatchUpdate(bind(&WebLayerTreeRenderer::updateTileWithUpdateInfo, m_renderer.get(), layerID, tileID, WebLayerTreeRenderer::TileUpdate(updateInfo.updateRect, targetRect, surface, updateInfo.surfaceOffset, updateInfo.platformSurfaceID, updateInfo.platformSurfaceSize)));
115 #else
116     dispatchUpdate(bind(&WebLayerTreeRenderer::updateTileWithUpdateInfo, m_renderer.get(), layerID, tileID, WebLayerTreeRenderer::TileUpdate(updateInfo.updateRect, targetRect, surface, updateInfo.surfaceOffset)));
117 #endif
118 #else
119 #if ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE)
120     dispatchUpdate(bind(&WebLayerTreeRenderer::updatePlatformSurfaceTile, m_renderer.get(), layerID, tileID, updateInfo.updateRect, updateInfo.platformSurfaceID, updateInfo.platformSurfaceSize));
121 #else
122     dispatchUpdate(bind(&WebLayerTreeRenderer::updateTile, m_renderer.get(), layerID, tileID, WebLayerTreeRenderer::TileUpdate(updateInfo.updateRect, targetRect, surface, updateInfo.surfaceOffset)));
123 #endif
124 #endif
125 }
126
127 void LayerTreeCoordinatorProxy::removeTileForLayer(int layerID, int tileID)
128 {
129     dispatchUpdate(bind(&WebLayerTreeRenderer::removeTile, m_renderer.get(), layerID, tileID));
130 }
131
132 void LayerTreeCoordinatorProxy::deleteCompositingLayer(WebLayerID id)
133 {
134     dispatchUpdate(bind(&WebLayerTreeRenderer::deleteLayer, m_renderer.get(), id));
135 #if !ENABLE(TIZEN_WEBKIT2_TILED_AC)
136     // For efl port, we should not call updateViewport here immediately.
137     // This may trigger rendering with broken LayerTreeHost.
138     // And actually, we don't need to call this here, because it will be called by didRenderFrame for each update of LayerTreeHost.
139     updateViewport();
140 #endif
141 }
142
143 void LayerTreeCoordinatorProxy::setRootCompositingLayer(WebLayerID id)
144 {
145     dispatchUpdate(bind(&WebLayerTreeRenderer::setRootLayerID, m_renderer.get(), id));
146     updateViewport();
147 }
148
149 void LayerTreeCoordinatorProxy::setCompositingLayerState(WebLayerID id, const WebLayerInfo& info)
150 {
151     dispatchUpdate(bind(&WebLayerTreeRenderer::setLayerState, m_renderer.get(), id, info));
152 }
153
154 void LayerTreeCoordinatorProxy::setCompositingLayerChildren(WebLayerID id, const Vector<WebLayerID>& children)
155 {
156     dispatchUpdate(bind(&WebLayerTreeRenderer::setLayerChildren, m_renderer.get(), id, children));
157 }
158
159 #if ENABLE(CSS_FILTERS)
160 void LayerTreeCoordinatorProxy::setCompositingLayerFilters(WebLayerID id, const FilterOperations& filters)
161 {
162     dispatchUpdate(bind(&WebLayerTreeRenderer::setLayerFilters, m_renderer.get(), id, filters));
163 }
164 #endif
165
166 void LayerTreeCoordinatorProxy::didRenderFrame()
167 {
168 #if OS(TIZEN)
169     m_drawingAreaProxy->page()->didRenderFrame();
170 #endif
171     dispatchUpdate(bind(&WebLayerTreeRenderer::flushLayerChanges, m_renderer.get()));
172 #if OS(TIZEN)
173     m_renderer->syncRemoteContent();
174 #endif
175     updateViewport();
176 }
177
178 void LayerTreeCoordinatorProxy::createDirectlyCompositedImage(int64_t key, const WebKit::ShareableBitmap::Handle& handle)
179 {
180     RefPtr<ShareableBitmap> bitmap = ShareableBitmap::create(handle);
181     dispatchUpdate(bind(&WebLayerTreeRenderer::createImage, m_renderer.get(), key, bitmap));
182 }
183
184 void LayerTreeCoordinatorProxy::destroyDirectlyCompositedImage(int64_t key)
185 {
186     dispatchUpdate(bind(&WebLayerTreeRenderer::destroyImage, m_renderer.get(), key));
187 }
188
189 void LayerTreeCoordinatorProxy::setContentsSize(const FloatSize& contentsSize)
190 {
191     dispatchUpdate(bind(&WebLayerTreeRenderer::setContentsSize, m_renderer.get(), contentsSize));
192 }
193
194 void LayerTreeCoordinatorProxy::setLayerAnimations(WebLayerID id, const GraphicsLayerAnimations& animations)
195 {
196     dispatchUpdate(bind(&WebLayerTreeRenderer::setLayerAnimations, m_renderer.get(), id, animations));
197 }
198
199 void LayerTreeCoordinatorProxy::setAnimationsLocked(bool locked)
200 {
201     dispatchUpdate(bind(&WebLayerTreeRenderer::setAnimationsLocked, m_renderer.get(), locked));
202 }
203
204 void LayerTreeCoordinatorProxy::setVisibleContentsRect(const IntRect& rect, float scale, const FloatPoint& trajectoryVector, const WebCore::FloatPoint& accurateVisibleContentsPosition)
205 {
206 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
207     m_renderer->setVisibleContentsRect(rect, scale, accurateVisibleContentsPosition);
208 #else
209     dispatchUpdate(bind(&WebLayerTreeRenderer::setVisibleContentsRect, m_renderer.get(), rect, scale, accurateVisibleContentsPosition));
210 #endif
211     m_drawingAreaProxy->page()->process()->send(Messages::LayerTreeCoordinator::SetVisibleContentsRect(rect, scale, trajectoryVector), m_drawingAreaProxy->page()->pageID());
212 }
213
214 void LayerTreeCoordinatorProxy::renderNextFrame()
215 {
216     m_drawingAreaProxy->page()->process()->send(Messages::LayerTreeCoordinator::RenderNextFrame(), m_drawingAreaProxy->page()->pageID());
217 }
218
219 void LayerTreeCoordinatorProxy::didChangeScrollPosition(const IntPoint& position)
220 {
221     dispatchUpdate(bind(&WebLayerTreeRenderer::didChangeScrollPosition, m_renderer.get(), position));
222 }
223
224 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
225 void LayerTreeCoordinatorProxy::syncCanvas(uint32_t id, const IntSize& canvasSize, uint64_t graphicsSurfaceToken, uint32_t frontBuffer, int flags)
226 {
227     dispatchUpdate(bind(&WebLayerTreeRenderer::syncCanvas, m_renderer.get(), id, canvasSize, graphicsSurfaceToken, frontBuffer, flags));
228 }
229 #else
230 void LayerTreeCoordinatorProxy::syncCanvas(uint32_t id, const IntSize& canvasSize, uint64_t graphicsSurfaceToken, uint32_t frontBuffer)
231 {
232     dispatchUpdate(bind(&WebLayerTreeRenderer::syncCanvas, m_renderer.get(), id, canvasSize, graphicsSurfaceToken, frontBuffer));
233 }
234 #endif
235
236 void LayerTreeCoordinatorProxy::purgeBackingStores()
237 {
238     m_drawingAreaProxy->page()->process()->send(Messages::LayerTreeCoordinator::PurgeBackingStores(), m_drawingAreaProxy->page()->pageID());
239 }
240
241 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
242 #if ENABLE(TIZEN_WEBKIT2_DIRECT_RENDERING)
243 void LayerTreeCoordinatorProxy::setAngle(int angle)
244 {
245     m_renderer->setAngle(angle);
246 }
247 #endif
248
249 void LayerTreeCoordinatorProxy::clearBackingStores()
250 {
251     m_renderer->syncRemoteContent();
252     m_renderer->clearBackingStores();
253     purgeBackingStores();
254 }
255 #endif
256
257 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION)
258 bool LayerTreeCoordinatorProxy::hasOverflowLayer() const
259 {
260     return m_renderer->scrollingContentsLayerCounts() ? true : false;
261 }
262 #endif
263
264 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION_ON_UI_SIDE)
265 bool LayerTreeCoordinatorProxy::setOffsetForFocusedScrollingContentsLayer(const WebCore::FloatPoint& offset)
266 {
267     return m_renderer && m_renderer->setOffset(m_renderer->focusedLayerID(), offset);
268 }
269
270 void LayerTreeCoordinatorProxy::setVisibleContentsRectForScrollingContentsLayers(const WebCore::IntRect& visibleRect)
271 {
272     if (m_renderer)
273         m_renderer->setVisibleContentsRectForScrollingContentsLayers(visibleRect);
274 }
275 #endif
276
277 #if ENABLE(TIZEN_RUNTIME_BACKEND_SELECTION)
278 void LayerTreeCoordinatorProxy::initializeAcceleratedCompositingMode(bool isGLMode)
279 {
280     m_drawingAreaProxy->page()->process()->send(Messages::LayerTreeCoordinator::SetAccelerationMode(isGLMode), m_drawingAreaProxy->page()->pageID());
281 }
282 #endif
283
284 }
285 #endif // USE(UI_SIDE_COMPOSITING)