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(COORDINATED_GRAPHICS)
23 #include "CoordinatedLayerTreeHostProxy.h"
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>
34 #if ENABLE(CSS_SHADERS)
35 #include "CustomFilterProgramInfo.h"
40 using namespace WebCore;
42 CoordinatedLayerTreeHostProxy::CoordinatedLayerTreeHostProxy(DrawingAreaProxy* drawingAreaProxy)
43 : m_drawingAreaProxy(drawingAreaProxy)
44 , m_scene(adoptRef(new CoordinatedGraphicsScene(this)))
46 m_drawingAreaProxy->page()->process()->addMessageReceiver(Messages::CoordinatedLayerTreeHostProxy::messageReceiverName(), m_drawingAreaProxy->page()->pageID(), this);
49 CoordinatedLayerTreeHostProxy::~CoordinatedLayerTreeHostProxy()
51 m_drawingAreaProxy->page()->process()->removeMessageReceiver(Messages::CoordinatedLayerTreeHostProxy::messageReceiverName(), m_drawingAreaProxy->page()->pageID());
55 void CoordinatedLayerTreeHostProxy::updateViewport()
57 m_drawingAreaProxy->updateViewport();
60 void CoordinatedLayerTreeHostProxy::dispatchUpdate(const Function<void()>& function)
62 m_scene->appendUpdate(function);
65 void CoordinatedLayerTreeHostProxy::createTileForLayer(CoordinatedLayerID layerID, uint32_t tileID, const IntRect& tileRect, const SurfaceUpdateInfo& updateInfo)
67 dispatchUpdate(bind(&CoordinatedGraphicsScene::createTile, m_scene.get(), layerID, tileID, updateInfo.scaleFactor));
68 updateTileForLayer(layerID, tileID, tileRect, updateInfo);
71 void CoordinatedLayerTreeHostProxy::updateTileForLayer(CoordinatedLayerID layerID, uint32_t tileID, const IntRect& tileRect, const SurfaceUpdateInfo& updateInfo)
73 dispatchUpdate(bind(&CoordinatedGraphicsScene::updateTile, m_scene.get(), layerID, tileID, CoordinatedGraphicsScene::TileUpdate(updateInfo.updateRect, tileRect, updateInfo.atlasID, updateInfo.surfaceOffset)));
76 void CoordinatedLayerTreeHostProxy::removeTileForLayer(CoordinatedLayerID layerID, uint32_t tileID)
78 dispatchUpdate(bind(&CoordinatedGraphicsScene::removeTile, m_scene.get(), layerID, tileID));
81 void CoordinatedLayerTreeHostProxy::createUpdateAtlas(uint32_t atlasID, const WebCoordinatedSurface::Handle& handle)
83 dispatchUpdate(bind(&CoordinatedGraphicsScene::createUpdateAtlas, m_scene.get(), atlasID, WebCoordinatedSurface::create(handle)));
86 void CoordinatedLayerTreeHostProxy::removeUpdateAtlas(uint32_t atlasID)
88 dispatchUpdate(bind(&CoordinatedGraphicsScene::removeUpdateAtlas, m_scene.get(), atlasID));
91 void CoordinatedLayerTreeHostProxy::createCompositingLayers(const Vector<CoordinatedLayerID>& ids)
93 dispatchUpdate(bind(&CoordinatedGraphicsScene::createLayers, m_scene.get(), ids));
96 void CoordinatedLayerTreeHostProxy::deleteCompositingLayers(const Vector<CoordinatedLayerID>& ids)
98 dispatchUpdate(bind(&CoordinatedGraphicsScene::deleteLayers, m_scene.get(), ids));
101 void CoordinatedLayerTreeHostProxy::setRootCompositingLayer(CoordinatedLayerID id)
103 dispatchUpdate(bind(&CoordinatedGraphicsScene::setRootLayerID, m_scene.get(), id));
106 void CoordinatedLayerTreeHostProxy::setCompositingLayerState(CoordinatedLayerID id, const CoordinatedLayerInfo& info)
108 dispatchUpdate(bind(&CoordinatedGraphicsScene::setLayerState, m_scene.get(), id, info));
111 void CoordinatedLayerTreeHostProxy::setCompositingLayerChildren(CoordinatedLayerID id, const Vector<CoordinatedLayerID>& children)
113 dispatchUpdate(bind(&CoordinatedGraphicsScene::setLayerChildren, m_scene.get(), id, children));
116 #if ENABLE(CSS_FILTERS)
117 void CoordinatedLayerTreeHostProxy::setCompositingLayerFilters(CoordinatedLayerID id, const FilterOperations& filters)
119 dispatchUpdate(bind(&CoordinatedGraphicsScene::setLayerFilters, m_scene.get(), id, filters));
123 #if ENABLE(CSS_SHADERS)
124 void CoordinatedLayerTreeHostProxy::removeCustomFilterProgram(int id)
126 dispatchUpdate(bind(&CoordinatedGraphicsScene::removeCustomFilterProgram, m_scene.get(), id));
128 void CoordinatedLayerTreeHostProxy::createCustomFilterProgram(int id, const CustomFilterProgramInfo& programInfo)
130 dispatchUpdate(bind(&CoordinatedGraphicsScene::createCustomFilterProgram, m_scene.get(), id, programInfo));
134 void CoordinatedLayerTreeHostProxy::didRenderFrame(const IntSize& contentsSize, const IntRect& coveredRect)
136 dispatchUpdate(bind(&CoordinatedGraphicsScene::flushLayerChanges, m_scene.get()));
138 #if USE(TILED_BACKING_STORE)
139 m_drawingAreaProxy->page()->didRenderFrame(contentsSize, coveredRect);
141 UNUSED_PARAM(contentsSize);
142 UNUSED_PARAM(coveredRect);
146 void CoordinatedLayerTreeHostProxy::createImageBacking(CoordinatedImageBackingID imageID)
148 dispatchUpdate(bind(&CoordinatedGraphicsScene::createImageBacking, m_scene.get(), imageID));
151 void CoordinatedLayerTreeHostProxy::updateImageBacking(CoordinatedImageBackingID imageID, const WebCoordinatedSurface::Handle& handle)
153 dispatchUpdate(bind(&CoordinatedGraphicsScene::updateImageBacking, m_scene.get(), imageID, WebCoordinatedSurface::create(handle)));
156 void CoordinatedLayerTreeHostProxy::clearImageBackingContents(CoordinatedImageBackingID imageID)
158 dispatchUpdate(bind(&CoordinatedGraphicsScene::clearImageBackingContents, m_scene.get(), imageID));
161 void CoordinatedLayerTreeHostProxy::removeImageBacking(CoordinatedImageBackingID imageID)
163 dispatchUpdate(bind(&CoordinatedGraphicsScene::removeImageBacking, m_scene.get(), imageID));
166 void CoordinatedLayerTreeHostProxy::setContentsSize(const FloatSize& contentsSize)
168 dispatchUpdate(bind(&CoordinatedGraphicsScene::setContentsSize, m_scene.get(), contentsSize));
171 void CoordinatedLayerTreeHostProxy::setLayerAnimations(CoordinatedLayerID id, const GraphicsLayerAnimations& animations)
173 dispatchUpdate(bind(&CoordinatedGraphicsScene::setLayerAnimations, m_scene.get(), id, animations));
176 void CoordinatedLayerTreeHostProxy::setAnimationsLocked(bool locked)
178 dispatchUpdate(bind(&CoordinatedGraphicsScene::setAnimationsLocked, m_scene.get(), locked));
181 void CoordinatedLayerTreeHostProxy::setVisibleContentsRect(const FloatRect& rect, const FloatPoint& trajectoryVector)
183 // Inform the renderer to adjust viewport-fixed layers.
184 dispatchUpdate(bind(&CoordinatedGraphicsScene::setVisibleContentsRect, m_scene.get(), rect));
186 if (rect == m_lastSentVisibleRect && trajectoryVector == m_lastSentTrajectoryVector)
189 m_drawingAreaProxy->page()->process()->send(Messages::CoordinatedLayerTreeHost::SetVisibleContentsRect(rect, trajectoryVector), m_drawingAreaProxy->page()->pageID());
190 m_lastSentVisibleRect = rect;
191 m_lastSentTrajectoryVector = trajectoryVector;
194 void CoordinatedLayerTreeHostProxy::renderNextFrame()
196 m_drawingAreaProxy->page()->process()->send(Messages::CoordinatedLayerTreeHost::RenderNextFrame(), m_drawingAreaProxy->page()->pageID());
199 #if ENABLE(REQUEST_ANIMATION_FRAME)
200 void CoordinatedLayerTreeHostProxy::requestAnimationFrame()
202 dispatchUpdate(bind(&CoordinatedGraphicsScene::requestAnimationFrame, m_scene.get()));
206 void CoordinatedLayerTreeHostProxy::animationFrameReady()
208 m_drawingAreaProxy->page()->process()->send(Messages::CoordinatedLayerTreeHost::AnimationFrameReady(), m_drawingAreaProxy->page()->pageID());
212 void CoordinatedLayerTreeHostProxy::didChangeScrollPosition(const FloatPoint& position)
214 dispatchUpdate(bind(&CoordinatedGraphicsScene::didChangeScrollPosition, m_scene.get(), position));
217 #if USE(GRAPHICS_SURFACE)
218 void CoordinatedLayerTreeHostProxy::createCanvas(CoordinatedLayerID id, const IntSize& canvasSize, const GraphicsSurfaceToken& token)
220 GraphicsSurface::Flags surfaceFlags = GraphicsSurface::SupportsTextureTarget | GraphicsSurface::SupportsSharing;
221 dispatchUpdate(bind(&CoordinatedGraphicsScene::createCanvas, m_scene.get(), id, canvasSize, GraphicsSurface::create(canvasSize, surfaceFlags, token)));
224 void CoordinatedLayerTreeHostProxy::syncCanvas(CoordinatedLayerID id, uint32_t frontBuffer)
226 dispatchUpdate(bind(&CoordinatedGraphicsScene::syncCanvas, m_scene.get(), id, frontBuffer));
229 void CoordinatedLayerTreeHostProxy::destroyCanvas(CoordinatedLayerID id)
231 dispatchUpdate(bind(&CoordinatedGraphicsScene::destroyCanvas, m_scene.get(), id));
235 void CoordinatedLayerTreeHostProxy::setLayerRepaintCount(CoordinatedLayerID id, int value)
237 dispatchUpdate(bind(&CoordinatedGraphicsScene::setLayerRepaintCount, m_scene.get(), id, value));
240 void CoordinatedLayerTreeHostProxy::purgeBackingStores()
242 m_drawingAreaProxy->page()->process()->send(Messages::CoordinatedLayerTreeHost::PurgeBackingStores(), m_drawingAreaProxy->page()->pageID());
245 void CoordinatedLayerTreeHostProxy::setBackgroundColor(const Color& color)
247 dispatchUpdate(bind(&CoordinatedGraphicsScene::setBackgroundColor, m_scene.get(), color));
251 #endif // USE(COORDINATED_GRAPHICS)