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.
20 #ifndef CoordinatedLayerTreeHost_h
21 #define CoordinatedLayerTreeHost_h
23 #if USE(COORDINATED_GRAPHICS)
25 #include "LayerTreeContext.h"
26 #include "LayerTreeHost.h"
28 #include <WebCore/CoordinatedGraphicsLayer.h>
29 #include <WebCore/CoordinatedImageBacking.h>
30 #include <WebCore/GraphicsLayerClient.h>
31 #include <WebCore/GraphicsLayerFactory.h>
32 #include <WebCore/UpdateAtlas.h>
33 #include <wtf/OwnPtr.h>
35 #if ENABLE(CSS_SHADERS)
36 #include "WebCustomFilterProgramProxy.h"
40 class CoordinatedSurface;
47 class CoordinatedLayerTreeHost : public LayerTreeHost, WebCore::GraphicsLayerClient
48 , public WebCore::CoordinatedGraphicsLayerClient
49 , public WebCore::CoordinatedImageBacking::Coordinator
50 , public WebCore::UpdateAtlasClient
51 , public WebCore::GraphicsLayerFactory
52 #if ENABLE(CSS_SHADERS)
53 , WebCustomFilterProgramProxyClient
57 static PassRefPtr<CoordinatedLayerTreeHost> create(WebPage*);
58 virtual ~CoordinatedLayerTreeHost();
60 virtual const LayerTreeContext& layerTreeContext() { return m_layerTreeContext; }
61 virtual void setLayerFlushSchedulingEnabled(bool);
62 virtual void scheduleLayerFlush();
63 virtual void setShouldNotifyAfterNextScheduledLayerFlush(bool);
64 virtual void setRootCompositingLayer(WebCore::GraphicsLayer*);
65 virtual void invalidate();
67 virtual void setNonCompositedContentsNeedDisplay(const WebCore::IntRect&);
68 virtual void scrollNonCompositedContents(const WebCore::IntRect& scrollRect, const WebCore::IntSize& scrollOffset);
69 virtual void forceRepaint();
70 virtual bool forceRepaintAsync(uint64_t callbackID);
71 virtual void sizeDidChange(const WebCore::IntSize& newSize);
73 virtual void didInstallPageOverlay();
74 virtual void didUninstallPageOverlay();
75 virtual void setPageOverlayNeedsDisplay(const WebCore::IntRect&);
76 virtual void setPageOverlayOpacity(float);
77 virtual bool pageOverlayShouldApplyFadeWhenPainting() const { return false; }
79 virtual void pauseRendering() { m_isSuspended = true; }
80 virtual void resumeRendering() { m_isSuspended = false; scheduleLayerFlush(); }
81 virtual void deviceOrPageScaleFactorChanged() OVERRIDE;
82 virtual PassRefPtr<WebCore::CoordinatedImageBacking> createImageBackingIfNeeded(WebCore::Image*) OVERRIDE;
84 virtual bool isFlushingLayerChanges() const OVERRIDE { return m_isFlushingLayerChanges; }
85 virtual void createTile(WebCore::CoordinatedLayerID, uint32_t tileID, const WebCore::SurfaceUpdateInfo&, const WebCore::IntRect&);
86 virtual void updateTile(WebCore::CoordinatedLayerID, uint32_t tileID, const WebCore::SurfaceUpdateInfo&, const WebCore::IntRect&);
87 virtual void removeTile(WebCore::CoordinatedLayerID, uint32_t tileID);
88 virtual WebCore::FloatRect visibleContentsRect() const;
89 virtual void renderNextFrame();
90 virtual void purgeBackingStores();
91 virtual void setVisibleContentsRect(const WebCore::FloatRect&, const WebCore::FloatPoint&);
92 virtual void didReceiveCoordinatedLayerTreeHostMessage(CoreIPC::Connection*, CoreIPC::MessageDecoder&);
93 virtual WebCore::GraphicsLayerFactory* graphicsLayerFactory() OVERRIDE;
95 virtual void syncLayerState(WebCore::CoordinatedLayerID, const WebCore::CoordinatedLayerInfo&);
96 virtual void syncLayerChildren(WebCore::CoordinatedLayerID, const Vector<WebCore::CoordinatedLayerID>&);
97 virtual void setLayerAnimations(WebCore::CoordinatedLayerID, const WebCore::GraphicsLayerAnimations&);
98 #if ENABLE(CSS_FILTERS)
99 virtual void syncLayerFilters(WebCore::CoordinatedLayerID, const WebCore::FilterOperations&);
101 #if USE(GRAPHICS_SURFACE)
102 virtual void createCanvas(WebCore::CoordinatedLayerID, WebCore::PlatformLayer*) OVERRIDE;
103 virtual void syncCanvas(WebCore::CoordinatedLayerID, WebCore::PlatformLayer*) OVERRIDE;
104 virtual void destroyCanvas(WebCore::CoordinatedLayerID) OVERRIDE;
106 virtual void setLayerRepaintCount(WebCore::CoordinatedLayerID, int) OVERRIDE;
107 virtual void detachLayer(WebCore::CoordinatedGraphicsLayer*);
109 virtual PassOwnPtr<WebCore::GraphicsContext> beginContentUpdate(const WebCore::IntSize&, WebCore::CoordinatedSurface::Flags, uint32_t& atlasID, WebCore::IntPoint&);
112 virtual bool createUpdateAtlas(uint32_t atlasID, PassRefPtr<WebCore::CoordinatedSurface>) OVERRIDE;
113 virtual void removeUpdateAtlas(uint32_t atlasID);
115 #if ENABLE(REQUEST_ANIMATION_FRAME)
116 virtual void scheduleAnimation() OVERRIDE;
118 virtual void setBackgroundColor(const WebCore::Color&) OVERRIDE;
120 static PassRefPtr<WebCore::CoordinatedSurface> createCoordinatedSurface(const WebCore::IntSize&, WebCore::CoordinatedSurface::Flags);
123 explicit CoordinatedLayerTreeHost(WebPage*);
126 // GraphicsLayerClient
127 virtual void notifyAnimationStarted(const WebCore::GraphicsLayer*, double time);
128 virtual void notifyFlushRequired(const WebCore::GraphicsLayer*);
129 virtual void paintContents(const WebCore::GraphicsLayer*, WebCore::GraphicsContext&, WebCore::GraphicsLayerPaintingPhase, const WebCore::IntRect& clipRect);
130 virtual float deviceScaleFactor() const OVERRIDE;
131 virtual float pageScaleFactor() const OVERRIDE;
133 // CoordinatedImageBacking::Coordinator
134 virtual void createImageBacking(WebCore::CoordinatedImageBackingID) OVERRIDE;
135 virtual bool updateImageBacking(WebCore::CoordinatedImageBackingID, PassRefPtr<WebCore::CoordinatedSurface>) OVERRIDE;
136 virtual void clearImageBackingContents(WebCore::CoordinatedImageBackingID) OVERRIDE;
137 virtual void removeImageBacking(WebCore::CoordinatedImageBackingID) OVERRIDE;
139 void flushPendingImageBackingChanges();
141 // GraphicsLayerFactory
142 virtual PassOwnPtr<WebCore::GraphicsLayer> createGraphicsLayer(WebCore::GraphicsLayerClient*) OVERRIDE;
144 // CoordinatedLayerTreeHost
145 void initializeRootCompositingLayerIfNeeded();
146 void createPageOverlayLayer();
147 void destroyPageOverlayLayer();
148 bool flushPendingLayerChanges();
149 void createCompositingLayers();
150 void deleteCompositingLayers();
151 void cancelPendingLayerFlush();
152 void performScheduledLayerFlush();
153 void didPerformScheduledLayerFlush();
154 void syncDisplayState();
155 void lockAnimations();
156 void unlockAnimations();
158 void layerFlushTimerFired(WebCore::Timer<CoordinatedLayerTreeHost>*);
160 void scheduleReleaseInactiveAtlases();
161 #if ENABLE(REQUEST_ANIMATION_FRAME)
162 void animationFrameReady();
165 void releaseInactiveAtlasesTimerFired(WebCore::Timer<CoordinatedLayerTreeHost>*);
167 #if ENABLE(CSS_SHADERS)
168 // WebCustomFilterProgramProxyClient
169 void removeCustomFilterProgramProxy(WebCustomFilterProgramProxy*);
171 void checkCustomFilterProgramProxies(const WebCore::FilterOperations&);
172 void disconnectCustomFilterPrograms();
175 OwnPtr<WebCore::GraphicsLayer> m_rootLayer;
177 // The layer which contains all non-composited content.
178 OwnPtr<WebCore::GraphicsLayer> m_nonCompositedContentLayer;
180 // The page overlay layer. Will be null if there's no page overlay.
181 OwnPtr<WebCore::GraphicsLayer> m_pageOverlayLayer;
183 HashSet<WebCore::CoordinatedGraphicsLayer*> m_registeredLayers;
184 Vector<WebCore::CoordinatedLayerID> m_layersToCreate;
185 Vector<WebCore::CoordinatedLayerID> m_layersToDelete;
186 typedef HashMap<WebCore::CoordinatedImageBackingID, RefPtr<WebCore::CoordinatedImageBacking> > ImageBackingMap;
187 ImageBackingMap m_imageBackings;
188 Vector<OwnPtr<WebCore::UpdateAtlas> > m_updateAtlases;
190 #if ENABLE(CSS_SHADERS)
191 HashSet<WebCustomFilterProgramProxy*> m_customFilterPrograms;
194 bool m_notifyAfterScheduledLayerFlush;
196 // We don't send the messages related to releasing resources to UI Process during purging, because UI Process already had removed all resources.
198 bool m_isFlushingLayerChanges;
200 bool m_waitingForUIProcess;
202 WebCore::FloatRect m_visibleContentsRect;
203 bool m_shouldSendScrollPositionUpdate;
205 LayerTreeContext m_layerTreeContext;
206 bool m_shouldSyncFrame;
207 bool m_didInitializeRootCompositingLayer;
208 WebCore::Timer<CoordinatedLayerTreeHost> m_layerFlushTimer;
209 WebCore::Timer<CoordinatedLayerTreeHost> m_releaseInactiveAtlasesTimer;
210 bool m_layerFlushSchedulingEnabled;
211 uint64_t m_forceRepaintAsyncCallbackID;
212 bool m_animationsLocked;
215 } // namespace WebKit
217 #endif // USE(COORDINATED_GRAPHICS)
219 #endif // CoordinatedLayerTreeHost_h