2 Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies)
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.
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.
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.
22 #if USE(UI_SIDE_COMPOSITING)
23 #include "LayerTreeCoordinatorProxy.h"
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"
38 using namespace WebCore;
40 LayerTreeCoordinatorProxy::LayerTreeCoordinatorProxy(DrawingAreaProxy* drawingAreaProxy)
41 : m_drawingAreaProxy(drawingAreaProxy)
42 #if !ENABLE(TIZEN_WEBKIT2_TILED_AC)
43 , m_renderer(adoptRef(new WebLayerTreeRenderer(this)))
45 , m_renderer(adoptRef(new WebLayerTreeRenderer(this, drawingAreaProxy)))
48 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
49 m_renderer->setActive(true);
53 #if ENABLE(TIZEN_RUNTIME_BACKEND_SELECTION)
54 LayerTreeCoordinatorProxy::LayerTreeCoordinatorProxy(DrawingAreaProxy* drawingAreaProxy, bool isGLMode)
55 : m_drawingAreaProxy(drawingAreaProxy)
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);
61 m_renderer = adoptRef(new WebLayerTreeRenderer(this, drawingAreaProxy, isGLMode));
62 #endif // ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE)
63 m_renderer->setActive(true);
65 #endif // ENABLE(TIZEN_RUNTIME_BACKEND_SELECTION)
67 LayerTreeCoordinatorProxy::~LayerTreeCoordinatorProxy()
72 void LayerTreeCoordinatorProxy::updateViewport()
74 m_drawingAreaProxy->updateViewport();
77 void LayerTreeCoordinatorProxy::dispatchUpdate(const Function<void()>& function)
79 m_renderer->appendUpdate(function);
82 void LayerTreeCoordinatorProxy::createTileForLayer(int layerID, int tileID, const IntRect& targetRect, const WebKit::SurfaceUpdateInfo& updateInfo)
84 dispatchUpdate(bind(&WebLayerTreeRenderer::createTile, m_renderer.get(), layerID, tileID, updateInfo.scaleFactor));
85 updateTileForLayer(layerID, tileID, targetRect, updateInfo);
88 void LayerTreeCoordinatorProxy::updateTileForLayer(int layerID, int tileID, const IntRect& targetRect, const WebKit::SurfaceUpdateInfo& updateInfo)
90 RefPtr<ShareableSurface> surface;
91 #if ENABLE(TIZEN_RUNTIME_BACKEND_SELECTION)
92 if (!m_renderer->isUsingPlatformSurface()) {
94 #if USE(GRAPHICS_SURFACE)
95 int token = updateInfo.surfaceHandle.graphicsSurfaceToken();
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);
102 surface = it->second;
104 surface = ShareableSurface::create(updateInfo.surfaceHandle);
106 surface = ShareableSurface::create(updateInfo.surfaceHandle);
108 #if ENABLE(TIZEN_RUNTIME_BACKEND_SELECTION)
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)));
116 dispatchUpdate(bind(&WebLayerTreeRenderer::updateTileWithUpdateInfo, m_renderer.get(), layerID, tileID, WebLayerTreeRenderer::TileUpdate(updateInfo.updateRect, targetRect, surface, updateInfo.surfaceOffset)));
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));
122 dispatchUpdate(bind(&WebLayerTreeRenderer::updateTile, m_renderer.get(), layerID, tileID, WebLayerTreeRenderer::TileUpdate(updateInfo.updateRect, targetRect, surface, updateInfo.surfaceOffset)));
127 void LayerTreeCoordinatorProxy::removeTileForLayer(int layerID, int tileID)
129 dispatchUpdate(bind(&WebLayerTreeRenderer::removeTile, m_renderer.get(), layerID, tileID));
132 void LayerTreeCoordinatorProxy::deleteCompositingLayer(WebLayerID id)
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.
143 void LayerTreeCoordinatorProxy::setRootCompositingLayer(WebLayerID id)
145 dispatchUpdate(bind(&WebLayerTreeRenderer::setRootLayerID, m_renderer.get(), id));
149 void LayerTreeCoordinatorProxy::setCompositingLayerState(WebLayerID id, const WebLayerInfo& info)
151 dispatchUpdate(bind(&WebLayerTreeRenderer::setLayerState, m_renderer.get(), id, info));
154 void LayerTreeCoordinatorProxy::setCompositingLayerChildren(WebLayerID id, const Vector<WebLayerID>& children)
156 dispatchUpdate(bind(&WebLayerTreeRenderer::setLayerChildren, m_renderer.get(), id, children));
159 #if ENABLE(CSS_FILTERS)
160 void LayerTreeCoordinatorProxy::setCompositingLayerFilters(WebLayerID id, const FilterOperations& filters)
162 dispatchUpdate(bind(&WebLayerTreeRenderer::setLayerFilters, m_renderer.get(), id, filters));
166 void LayerTreeCoordinatorProxy::didRenderFrame()
169 m_drawingAreaProxy->page()->didRenderFrame();
171 dispatchUpdate(bind(&WebLayerTreeRenderer::flushLayerChanges, m_renderer.get()));
173 m_renderer->syncRemoteContent();
178 void LayerTreeCoordinatorProxy::createDirectlyCompositedImage(int64_t key, const WebKit::ShareableBitmap::Handle& handle)
180 RefPtr<ShareableBitmap> bitmap = ShareableBitmap::create(handle);
181 dispatchUpdate(bind(&WebLayerTreeRenderer::createImage, m_renderer.get(), key, bitmap));
184 void LayerTreeCoordinatorProxy::destroyDirectlyCompositedImage(int64_t key)
186 dispatchUpdate(bind(&WebLayerTreeRenderer::destroyImage, m_renderer.get(), key));
189 void LayerTreeCoordinatorProxy::setContentsSize(const FloatSize& contentsSize)
191 dispatchUpdate(bind(&WebLayerTreeRenderer::setContentsSize, m_renderer.get(), contentsSize));
194 void LayerTreeCoordinatorProxy::setLayerAnimations(WebLayerID id, const GraphicsLayerAnimations& animations)
196 dispatchUpdate(bind(&WebLayerTreeRenderer::setLayerAnimations, m_renderer.get(), id, animations));
199 void LayerTreeCoordinatorProxy::setAnimationsLocked(bool locked)
201 dispatchUpdate(bind(&WebLayerTreeRenderer::setAnimationsLocked, m_renderer.get(), locked));
204 void LayerTreeCoordinatorProxy::setVisibleContentsRect(const IntRect& rect, float scale, const FloatPoint& trajectoryVector, const WebCore::FloatPoint& accurateVisibleContentsPosition)
206 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
207 m_renderer->setVisibleContentsRect(rect, scale, accurateVisibleContentsPosition);
209 dispatchUpdate(bind(&WebLayerTreeRenderer::setVisibleContentsRect, m_renderer.get(), rect, scale, accurateVisibleContentsPosition));
211 m_drawingAreaProxy->page()->process()->send(Messages::LayerTreeCoordinator::SetVisibleContentsRect(rect, scale, trajectoryVector), m_drawingAreaProxy->page()->pageID());
214 void LayerTreeCoordinatorProxy::renderNextFrame()
216 m_drawingAreaProxy->page()->process()->send(Messages::LayerTreeCoordinator::RenderNextFrame(), m_drawingAreaProxy->page()->pageID());
219 void LayerTreeCoordinatorProxy::didChangeScrollPosition(const IntPoint& position)
221 dispatchUpdate(bind(&WebLayerTreeRenderer::didChangeScrollPosition, m_renderer.get(), position));
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)
227 dispatchUpdate(bind(&WebLayerTreeRenderer::syncCanvas, m_renderer.get(), id, canvasSize, graphicsSurfaceToken, frontBuffer, flags));
230 void LayerTreeCoordinatorProxy::syncCanvas(uint32_t id, const IntSize& canvasSize, uint64_t graphicsSurfaceToken, uint32_t frontBuffer)
232 dispatchUpdate(bind(&WebLayerTreeRenderer::syncCanvas, m_renderer.get(), id, canvasSize, graphicsSurfaceToken, frontBuffer));
236 void LayerTreeCoordinatorProxy::purgeBackingStores()
238 m_drawingAreaProxy->page()->process()->send(Messages::LayerTreeCoordinator::PurgeBackingStores(), m_drawingAreaProxy->page()->pageID());
241 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
242 #if ENABLE(TIZEN_WEBKIT2_DIRECT_RENDERING)
243 void LayerTreeCoordinatorProxy::setAngle(int angle)
245 m_renderer->setAngle(angle);
249 void LayerTreeCoordinatorProxy::clearBackingStores()
251 m_renderer->syncRemoteContent();
252 m_renderer->clearBackingStores();
253 purgeBackingStores();
257 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION)
258 bool LayerTreeCoordinatorProxy::hasOverflowLayer() const
260 return m_renderer->scrollingContentsLayerCounts() ? true : false;
264 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION_ON_UI_SIDE)
265 bool LayerTreeCoordinatorProxy::setOffsetForFocusedScrollingContentsLayer(const WebCore::FloatPoint& offset)
267 return m_renderer && m_renderer->setOffset(m_renderer->focusedLayerID(), offset);
270 void LayerTreeCoordinatorProxy::setVisibleContentsRectForScrollingContentsLayers(const WebCore::IntRect& visibleRect)
273 m_renderer->setVisibleContentsRectForScrollingContentsLayers(visibleRect);
277 #if ENABLE(TIZEN_RUNTIME_BACKEND_SELECTION)
278 void LayerTreeCoordinatorProxy::initializeAcceleratedCompositingMode(bool isGLMode)
280 m_drawingAreaProxy->page()->process()->send(Messages::LayerTreeCoordinator::SetAccelerationMode(isGLMode), m_drawingAreaProxy->page()->pageID());
285 #endif // USE(UI_SIDE_COMPOSITING)