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"
41 using namespace WebCore;
43 // FIXME: This function needs a better place
44 static bool supportsLockSurfaceExtension()
46 static bool extSupportQueried = false;
47 static bool supportLockSurfaceExt = false;
49 if (extSupportQueried)
50 return supportLockSurfaceExt;
52 extSupportQueried = true;
53 Display* nativeDisplay = 0;
54 EGLDisplay display = eglGetCurrentDisplay();
56 if (display == EGL_NO_DISPLAY) {
57 nativeDisplay = XOpenDisplay(0);
58 display = eglGetDisplay(reinterpret_cast<EGLNativeDisplayType>(nativeDisplay));
59 eglInitialize(display, 0, 0);
62 if (display != EGL_NO_DISPLAY) {
63 String rawExtensions = reinterpret_cast<const char*>(eglQueryString(display, EGL_EXTENSIONS));
64 Vector<String> extNames;
65 rawExtensions.lower().split(" ", extNames);
67 if (extNames.contains("egl_khr_lock_surface"))
68 supportLockSurfaceExt = true;
73 return supportLockSurfaceExt;
76 LayerTreeCoordinatorProxy::LayerTreeCoordinatorProxy(DrawingAreaProxy* drawingAreaProxy)
77 : m_drawingAreaProxy(drawingAreaProxy)
78 #if !ENABLE(TIZEN_WEBKIT2_TILED_AC)
79 , m_renderer(adoptRef(new WebLayerTreeRenderer(this)))
81 , m_renderer(adoptRef(new WebLayerTreeRenderer(this, drawingAreaProxy)))
84 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
85 m_renderer->setActive(true);
89 #if ENABLE(TIZEN_RUNTIME_BACKEND_SELECTION)
90 LayerTreeCoordinatorProxy::LayerTreeCoordinatorProxy(DrawingAreaProxy* drawingAreaProxy, bool isGLMode)
91 : m_drawingAreaProxy(drawingAreaProxy)
93 #if ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE)
94 WebLayerTreeRenderer* renderer = (isGLMode && supportsLockSurfaceExtension()) ? new WebLayerTreeRendererTizen(this, drawingAreaProxy) : new WebLayerTreeRenderer(this, drawingAreaProxy, isGLMode);
95 m_renderer = adoptRef(renderer);
97 m_renderer = adoptRef(new WebLayerTreeRenderer(this, drawingAreaProxy, isGLMode));
98 #endif // ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE)
99 m_renderer->setActive(true);
101 #endif // ENABLE(TIZEN_RUNTIME_BACKEND_SELECTION)
103 LayerTreeCoordinatorProxy::~LayerTreeCoordinatorProxy()
105 m_renderer->detach();
108 void LayerTreeCoordinatorProxy::updateViewport()
110 m_drawingAreaProxy->updateViewport();
113 void LayerTreeCoordinatorProxy::dispatchUpdate(const Function<void()>& function)
115 m_renderer->appendUpdate(function);
118 void LayerTreeCoordinatorProxy::createTileForLayer(int layerID, int tileID, const IntRect& targetRect, const WebKit::SurfaceUpdateInfo& updateInfo)
120 dispatchUpdate(bind(&WebLayerTreeRenderer::createTile, m_renderer.get(), layerID, tileID, updateInfo.scaleFactor));
121 updateTileForLayer(layerID, tileID, targetRect, updateInfo);
124 void LayerTreeCoordinatorProxy::updateTileForLayer(int layerID, int tileID, const IntRect& targetRect, const WebKit::SurfaceUpdateInfo& updateInfo)
126 RefPtr<ShareableSurface> surface;
127 #if ENABLE(TIZEN_RUNTIME_BACKEND_SELECTION)
128 if (!m_renderer->isUsingPlatformSurface()) {
130 #if USE(GRAPHICS_SURFACE)
131 int token = updateInfo.surfaceHandle.graphicsSurfaceToken();
133 HashMap<uint32_t, RefPtr<ShareableSurface> >::iterator it = m_surfaces.find(token);
134 if (it == m_surfaces.end()) {
135 surface = ShareableSurface::create(updateInfo.surfaceHandle);
136 m_surfaces.add(token, surface);
138 surface = it->second;
140 surface = ShareableSurface::create(updateInfo.surfaceHandle);
142 surface = ShareableSurface::create(updateInfo.surfaceHandle);
144 #if ENABLE(TIZEN_RUNTIME_BACKEND_SELECTION)
148 #if ENABLE(TIZEN_RUNTIME_BACKEND_SELECTION)
149 #if ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE)
150 if (m_renderer->isUsingPlatformSurface())
151 dispatchUpdate(bind(&WebLayerTreeRenderer::updateTileWithUpdateInfo, m_renderer.get(), layerID, tileID, WebLayerTreeRenderer::TileUpdate(updateInfo.updateRect, targetRect, surface, updateInfo.surfaceOffset, updateInfo.platformSurfaceID, updateInfo.platformSurfaceSize)));
154 dispatchUpdate(bind(&WebLayerTreeRenderer::updateTileWithUpdateInfo, m_renderer.get(), layerID, tileID, WebLayerTreeRenderer::TileUpdate(updateInfo.updateRect, targetRect, surface, updateInfo.surfaceOffset)));
156 #if ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE)
157 dispatchUpdate(bind(&WebLayerTreeRenderer::updatePlatformSurfaceTile, m_renderer.get(), layerID, tileID, updateInfo.updateRect, updateInfo.platformSurfaceID, updateInfo.platformSurfaceSize));
159 dispatchUpdate(bind(&WebLayerTreeRenderer::updateTile, m_renderer.get(), layerID, tileID, WebLayerTreeRenderer::TileUpdate(updateInfo.updateRect, targetRect, surface, updateInfo.surfaceOffset)));
164 void LayerTreeCoordinatorProxy::removeTileForLayer(int layerID, int tileID)
166 dispatchUpdate(bind(&WebLayerTreeRenderer::removeTile, m_renderer.get(), layerID, tileID));
169 void LayerTreeCoordinatorProxy::deleteCompositingLayer(WebLayerID id)
171 dispatchUpdate(bind(&WebLayerTreeRenderer::deleteLayer, m_renderer.get(), id));
172 #if !ENABLE(TIZEN_WEBKIT2_TILED_AC)
173 // For efl port, we should not call updateViewport here immediately.
174 // This may trigger rendering with broken LayerTreeHost.
175 // And actually, we don't need to call this here, because it will be called by didRenderFrame for each update of LayerTreeHost.
180 void LayerTreeCoordinatorProxy::setRootCompositingLayer(WebLayerID id)
182 dispatchUpdate(bind(&WebLayerTreeRenderer::setRootLayerID, m_renderer.get(), id));
186 void LayerTreeCoordinatorProxy::setCompositingLayerState(WebLayerID id, const WebLayerInfo& info)
188 dispatchUpdate(bind(&WebLayerTreeRenderer::setLayerState, m_renderer.get(), id, info));
191 void LayerTreeCoordinatorProxy::setCompositingLayerChildren(WebLayerID id, const Vector<WebLayerID>& children)
193 dispatchUpdate(bind(&WebLayerTreeRenderer::setLayerChildren, m_renderer.get(), id, children));
196 #if ENABLE(CSS_FILTERS)
197 void LayerTreeCoordinatorProxy::setCompositingLayerFilters(WebLayerID id, const FilterOperations& filters)
199 dispatchUpdate(bind(&WebLayerTreeRenderer::setLayerFilters, m_renderer.get(), id, filters));
203 void LayerTreeCoordinatorProxy::didRenderFrame()
206 m_drawingAreaProxy->page()->didRenderFrame();
208 dispatchUpdate(bind(&WebLayerTreeRenderer::flushLayerChanges, m_renderer.get()));
210 m_renderer->syncRemoteContent();
215 void LayerTreeCoordinatorProxy::createDirectlyCompositedImage(int64_t key, const WebKit::ShareableBitmap::Handle& handle)
217 RefPtr<ShareableBitmap> bitmap = ShareableBitmap::create(handle);
218 dispatchUpdate(bind(&WebLayerTreeRenderer::createImage, m_renderer.get(), key, bitmap));
221 void LayerTreeCoordinatorProxy::destroyDirectlyCompositedImage(int64_t key)
223 dispatchUpdate(bind(&WebLayerTreeRenderer::destroyImage, m_renderer.get(), key));
226 void LayerTreeCoordinatorProxy::setContentsSize(const FloatSize& contentsSize)
228 dispatchUpdate(bind(&WebLayerTreeRenderer::setContentsSize, m_renderer.get(), contentsSize));
231 void LayerTreeCoordinatorProxy::setLayerAnimations(WebLayerID id, const GraphicsLayerAnimations& animations)
233 dispatchUpdate(bind(&WebLayerTreeRenderer::setLayerAnimations, m_renderer.get(), id, animations));
236 void LayerTreeCoordinatorProxy::setAnimationsLocked(bool locked)
238 dispatchUpdate(bind(&WebLayerTreeRenderer::setAnimationsLocked, m_renderer.get(), locked));
241 void LayerTreeCoordinatorProxy::setVisibleContentsRect(const IntRect& rect, float scale, const FloatPoint& trajectoryVector, const WebCore::FloatPoint& accurateVisibleContentsPosition)
243 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
244 m_renderer->setVisibleContentsRect(rect, scale, accurateVisibleContentsPosition);
246 dispatchUpdate(bind(&WebLayerTreeRenderer::setVisibleContentsRect, m_renderer.get(), rect, scale, accurateVisibleContentsPosition));
248 m_drawingAreaProxy->page()->process()->send(Messages::LayerTreeCoordinator::SetVisibleContentsRect(rect, scale, trajectoryVector), m_drawingAreaProxy->page()->pageID());
251 void LayerTreeCoordinatorProxy::renderNextFrame()
253 m_drawingAreaProxy->page()->process()->send(Messages::LayerTreeCoordinator::RenderNextFrame(), m_drawingAreaProxy->page()->pageID());
256 void LayerTreeCoordinatorProxy::didChangeScrollPosition(const IntPoint& position)
258 dispatchUpdate(bind(&WebLayerTreeRenderer::didChangeScrollPosition, m_renderer.get(), position));
261 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
262 void LayerTreeCoordinatorProxy::syncCanvas(uint32_t id, const IntSize& canvasSize, uint64_t graphicsSurfaceToken, uint32_t frontBuffer, int flags)
264 dispatchUpdate(bind(&WebLayerTreeRenderer::syncCanvas, m_renderer.get(), id, canvasSize, graphicsSurfaceToken, frontBuffer, flags));
267 void LayerTreeCoordinatorProxy::syncCanvas(uint32_t id, const IntSize& canvasSize, uint64_t graphicsSurfaceToken, uint32_t frontBuffer)
269 dispatchUpdate(bind(&WebLayerTreeRenderer::syncCanvas, m_renderer.get(), id, canvasSize, graphicsSurfaceToken, frontBuffer));
273 void LayerTreeCoordinatorProxy::purgeBackingStores()
275 m_drawingAreaProxy->page()->process()->send(Messages::LayerTreeCoordinator::PurgeBackingStores(), m_drawingAreaProxy->page()->pageID());
278 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
279 void LayerTreeCoordinatorProxy::clearBackingStores()
281 m_renderer->syncRemoteContent();
282 m_renderer->clearBackingStores();
283 purgeBackingStores();
287 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION)
288 bool LayerTreeCoordinatorProxy::hasOverflowLayer() const
290 return m_renderer->scrollingContentsLayerCounts() ? true : false;
294 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION_ON_UI_SIDE)
295 bool LayerTreeCoordinatorProxy::setOffsetForFocusedScrollingContentsLayer(const WebCore::FloatPoint& offset)
297 return m_renderer && m_renderer->setOffset(m_renderer->focusedLayerID(), offset);
300 void LayerTreeCoordinatorProxy::setVisibleContentsRectForScrollingContentsLayers(const WebCore::IntRect& visibleRect)
303 m_renderer->setVisibleContentsRectForScrollingContentsLayers(visibleRect);
307 #if ENABLE(TIZEN_RUNTIME_BACKEND_SELECTION)
308 void LayerTreeCoordinatorProxy::initializeAcceleratedCompositingMode(bool isGLMode)
310 m_drawingAreaProxy->page()->process()->send(Messages::LayerTreeCoordinator::SetAccelerationMode(isGLMode), m_drawingAreaProxy->page()->pageID());
315 #endif // USE(UI_SIDE_COMPOSITING)