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 if (m_renderer->isUsingPlatformSurface())
158 dispatchUpdate(bind(&WebLayerTreeRenderer::updatePlatformSurfaceTile, m_renderer.get(), layerID, tileID, updateInfo.updateRect, updateInfo.platformSurfaceID, updateInfo.platformSurfaceSize));
161 dispatchUpdate(bind(&WebLayerTreeRenderer::updateTile, m_renderer.get(), layerID, tileID, WebLayerTreeRenderer::TileUpdate(updateInfo.updateRect, targetRect, surface, updateInfo.surfaceOffset)));
165 void LayerTreeCoordinatorProxy::removeTileForLayer(int layerID, int tileID)
167 dispatchUpdate(bind(&WebLayerTreeRenderer::removeTile, m_renderer.get(), layerID, tileID));
170 void LayerTreeCoordinatorProxy::deleteCompositingLayer(WebLayerID id)
172 dispatchUpdate(bind(&WebLayerTreeRenderer::deleteLayer, m_renderer.get(), id));
173 #if !ENABLE(TIZEN_WEBKIT2_TILED_AC)
174 // For efl port, we should not call updateViewport here immediately.
175 // This may trigger rendering with broken LayerTreeHost.
176 // And actually, we don't need to call this here, because it will be called by didRenderFrame for each update of LayerTreeHost.
181 void LayerTreeCoordinatorProxy::setRootCompositingLayer(WebLayerID id)
183 dispatchUpdate(bind(&WebLayerTreeRenderer::setRootLayerID, m_renderer.get(), id));
187 void LayerTreeCoordinatorProxy::setCompositingLayerState(WebLayerID id, const WebLayerInfo& info)
189 dispatchUpdate(bind(&WebLayerTreeRenderer::setLayerState, m_renderer.get(), id, info));
192 void LayerTreeCoordinatorProxy::setCompositingLayerChildren(WebLayerID id, const Vector<WebLayerID>& children)
194 dispatchUpdate(bind(&WebLayerTreeRenderer::setLayerChildren, m_renderer.get(), id, children));
197 #if ENABLE(CSS_FILTERS)
198 void LayerTreeCoordinatorProxy::setCompositingLayerFilters(WebLayerID id, const FilterOperations& filters)
200 dispatchUpdate(bind(&WebLayerTreeRenderer::setLayerFilters, m_renderer.get(), id, filters));
204 void LayerTreeCoordinatorProxy::didRenderFrame()
207 m_drawingAreaProxy->page()->didRenderFrame();
209 dispatchUpdate(bind(&WebLayerTreeRenderer::flushLayerChanges, m_renderer.get()));
211 m_renderer->syncRemoteContent();
216 void LayerTreeCoordinatorProxy::createDirectlyCompositedImage(int64_t key, const WebKit::ShareableBitmap::Handle& handle)
218 RefPtr<ShareableBitmap> bitmap = ShareableBitmap::create(handle);
219 dispatchUpdate(bind(&WebLayerTreeRenderer::createImage, m_renderer.get(), key, bitmap));
222 void LayerTreeCoordinatorProxy::destroyDirectlyCompositedImage(int64_t key)
224 dispatchUpdate(bind(&WebLayerTreeRenderer::destroyImage, m_renderer.get(), key));
227 void LayerTreeCoordinatorProxy::setContentsSize(const FloatSize& contentsSize)
229 dispatchUpdate(bind(&WebLayerTreeRenderer::setContentsSize, m_renderer.get(), contentsSize));
232 void LayerTreeCoordinatorProxy::setLayerAnimations(WebLayerID id, const GraphicsLayerAnimations& animations)
234 dispatchUpdate(bind(&WebLayerTreeRenderer::setLayerAnimations, m_renderer.get(), id, animations));
237 void LayerTreeCoordinatorProxy::setAnimationsLocked(bool locked)
239 dispatchUpdate(bind(&WebLayerTreeRenderer::setAnimationsLocked, m_renderer.get(), locked));
242 void LayerTreeCoordinatorProxy::setVisibleContentsRect(const IntRect& rect, float scale, const FloatPoint& trajectoryVector, const WebCore::FloatPoint& accurateVisibleContentsPosition)
244 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
245 m_renderer->setVisibleContentsRect(rect, scale, accurateVisibleContentsPosition);
247 dispatchUpdate(bind(&WebLayerTreeRenderer::setVisibleContentsRect, m_renderer.get(), rect, scale, accurateVisibleContentsPosition));
249 m_drawingAreaProxy->page()->process()->send(Messages::LayerTreeCoordinator::SetVisibleContentsRect(rect, scale, trajectoryVector), m_drawingAreaProxy->page()->pageID());
252 void LayerTreeCoordinatorProxy::renderNextFrame()
254 m_drawingAreaProxy->page()->process()->send(Messages::LayerTreeCoordinator::RenderNextFrame(), m_drawingAreaProxy->page()->pageID());
257 void LayerTreeCoordinatorProxy::didChangeScrollPosition(const IntPoint& position)
259 dispatchUpdate(bind(&WebLayerTreeRenderer::didChangeScrollPosition, m_renderer.get(), position));
262 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
263 void LayerTreeCoordinatorProxy::syncCanvas(uint32_t id, const IntSize& canvasSize, uint64_t graphicsSurfaceToken, uint32_t frontBuffer, int flags)
265 dispatchUpdate(bind(&WebLayerTreeRenderer::syncCanvas, m_renderer.get(), id, canvasSize, graphicsSurfaceToken, frontBuffer, flags));
268 void LayerTreeCoordinatorProxy::syncCanvas(uint32_t id, const IntSize& canvasSize, uint64_t graphicsSurfaceToken, uint32_t frontBuffer)
270 dispatchUpdate(bind(&WebLayerTreeRenderer::syncCanvas, m_renderer.get(), id, canvasSize, graphicsSurfaceToken, frontBuffer));
274 void LayerTreeCoordinatorProxy::purgeBackingStores()
276 m_drawingAreaProxy->page()->process()->send(Messages::LayerTreeCoordinator::PurgeBackingStores(), m_drawingAreaProxy->page()->pageID());
279 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
280 void LayerTreeCoordinatorProxy::clearBackingStores()
282 m_renderer->syncRemoteContent();
283 m_renderer->clearBackingStores();
284 purgeBackingStores();
288 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION)
289 bool LayerTreeCoordinatorProxy::hasOverflowLayer() const
291 return m_renderer->scrollingContentsLayerCounts() ? true : false;
295 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION_ON_UI_SIDE)
296 bool LayerTreeCoordinatorProxy::setOffsetForFocusedScrollingContentsLayer(const WebCore::FloatPoint& offset)
298 return m_renderer && m_renderer->setOffset(m_renderer->focusedLayerID(), offset);
301 void LayerTreeCoordinatorProxy::setVisibleContentsRectForScrollingContentsLayers(const WebCore::IntRect& visibleRect)
304 m_renderer->setVisibleContentsRectForScrollingContentsLayers(visibleRect);
308 #if ENABLE(TIZEN_RUNTIME_BACKEND_SELECTION)
309 void LayerTreeCoordinatorProxy::initializeAcceleratedCompositingMode(bool isGLMode)
311 m_drawingAreaProxy->page()->process()->send(Messages::LayerTreeCoordinator::SetAccelerationMode(isGLMode), m_drawingAreaProxy->page()->pageID());
316 #endif // USE(UI_SIDE_COMPOSITING)