Unreviewed, rolling out r142112.
[WebKit-https.git] / Source / WebKit2 / WebProcess / WebPage / CoordinatedGraphics / CoordinatedLayerTreeHost.h
1 /*
2     Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies)
3
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.
8
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.
13
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.
18 */
19
20 #ifndef CoordinatedLayerTreeHost_h
21 #define CoordinatedLayerTreeHost_h
22
23 #if USE(COORDINATED_GRAPHICS)
24
25 #include "LayerTreeContext.h"
26 #include "LayerTreeHost.h"
27 #include "Timer.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>
34
35 #if ENABLE(CSS_SHADERS)
36 #include "WebCustomFilterProgramProxy.h"
37 #endif
38
39 namespace WebCore {
40 class CoordinatedSurface;
41 }
42
43 namespace WebKit {
44
45 class WebPage;
46
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
54 #endif
55 {
56 public:
57     static PassRefPtr<CoordinatedLayerTreeHost> create(WebPage*);
58     virtual ~CoordinatedLayerTreeHost();
59
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();
66
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);
72
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; }
78
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;
83
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;
94
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&);
100 #endif
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;
105 #endif
106     virtual void setLayerRepaintCount(WebCore::CoordinatedLayerID, int) OVERRIDE;
107     virtual void detachLayer(WebCore::CoordinatedGraphicsLayer*);
108     virtual void syncFixedLayers();
109
110     virtual PassOwnPtr<WebCore::GraphicsContext> beginContentUpdate(const WebCore::IntSize&, WebCore::CoordinatedSurface::Flags, uint32_t& atlasID, WebCore::IntPoint&);
111
112     // UpdateAtlasClient
113     virtual bool createUpdateAtlas(uint32_t atlasID, PassRefPtr<WebCore::CoordinatedSurface>) OVERRIDE;
114     virtual void removeUpdateAtlas(uint32_t atlasID);
115
116 #if ENABLE(REQUEST_ANIMATION_FRAME)
117     virtual void scheduleAnimation() OVERRIDE;
118 #endif
119     virtual void setBackgroundColor(const WebCore::Color&) OVERRIDE;
120
121     static PassRefPtr<WebCore::CoordinatedSurface> createCoordinatedSurface(const WebCore::IntSize&, WebCore::CoordinatedSurface::Flags);
122
123 protected:
124     explicit CoordinatedLayerTreeHost(WebPage*);
125
126 private:
127     // GraphicsLayerClient
128     virtual void notifyAnimationStarted(const WebCore::GraphicsLayer*, double time);
129     virtual void notifyFlushRequired(const WebCore::GraphicsLayer*);
130     virtual void paintContents(const WebCore::GraphicsLayer*, WebCore::GraphicsContext&, WebCore::GraphicsLayerPaintingPhase, const WebCore::IntRect& clipRect);
131     virtual float deviceScaleFactor() const OVERRIDE;
132     virtual float pageScaleFactor() const OVERRIDE;
133
134     // CoordinatedImageBacking::Coordinator
135     virtual void createImageBacking(WebCore::CoordinatedImageBackingID) OVERRIDE;
136     virtual bool updateImageBacking(WebCore::CoordinatedImageBackingID, PassRefPtr<WebCore::CoordinatedSurface>) OVERRIDE;
137     virtual void clearImageBackingContents(WebCore::CoordinatedImageBackingID) OVERRIDE;
138     virtual void removeImageBacking(WebCore::CoordinatedImageBackingID) OVERRIDE;
139
140     void flushPendingImageBackingChanges();
141
142     // GraphicsLayerFactory
143     virtual PassOwnPtr<WebCore::GraphicsLayer> createGraphicsLayer(WebCore::GraphicsLayerClient*) OVERRIDE;
144
145     // CoordinatedLayerTreeHost
146     void initializeRootCompositingLayerIfNeeded();
147     void createPageOverlayLayer();
148     void destroyPageOverlayLayer();
149     bool flushPendingLayerChanges();
150     void createCompositingLayers();
151     void deleteCompositingLayers();
152     void cancelPendingLayerFlush();
153     void performScheduledLayerFlush();
154     void didPerformScheduledLayerFlush();
155     void syncDisplayState();
156     void lockAnimations();
157     void unlockAnimations();
158
159     void layerFlushTimerFired(WebCore::Timer<CoordinatedLayerTreeHost>*);
160
161     void scheduleReleaseInactiveAtlases();
162 #if ENABLE(REQUEST_ANIMATION_FRAME)
163     void animationFrameReady();
164 #endif
165
166     void releaseInactiveAtlasesTimerFired(WebCore::Timer<CoordinatedLayerTreeHost>*);
167
168 #if ENABLE(CSS_SHADERS)
169     // WebCustomFilterProgramProxyClient
170     void removeCustomFilterProgramProxy(WebCustomFilterProgramProxy*);
171
172     void checkCustomFilterProgramProxies(const WebCore::FilterOperations&);
173     void disconnectCustomFilterPrograms();
174 #endif
175
176     OwnPtr<WebCore::GraphicsLayer> m_rootLayer;
177
178     // The layer which contains all non-composited content.
179     OwnPtr<WebCore::GraphicsLayer> m_nonCompositedContentLayer;
180
181     // The page overlay layer. Will be null if there's no page overlay.
182     OwnPtr<WebCore::GraphicsLayer> m_pageOverlayLayer;
183
184     HashSet<WebCore::CoordinatedGraphicsLayer*> m_registeredLayers;
185     Vector<WebCore::CoordinatedLayerID> m_layersToCreate;
186     Vector<WebCore::CoordinatedLayerID> m_layersToDelete;
187     typedef HashMap<WebCore::CoordinatedImageBackingID, RefPtr<WebCore::CoordinatedImageBacking> > ImageBackingMap;
188     ImageBackingMap m_imageBackings;
189     Vector<OwnPtr<WebCore::UpdateAtlas> > m_updateAtlases;
190
191 #if ENABLE(CSS_SHADERS)
192     HashSet<WebCustomFilterProgramProxy*> m_customFilterPrograms;
193 #endif
194
195     bool m_notifyAfterScheduledLayerFlush;
196     bool m_isValid;
197     // 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_isPurging;
199     bool m_isFlushingLayerChanges;
200
201     bool m_waitingForUIProcess;
202     bool m_isSuspended;
203     WebCore::FloatRect m_visibleContentsRect;
204     bool m_shouldSendScrollPositionUpdate;
205
206     LayerTreeContext m_layerTreeContext;
207     bool m_shouldSyncFrame;
208     bool m_didInitializeRootCompositingLayer;
209     WebCore::Timer<CoordinatedLayerTreeHost> m_layerFlushTimer;
210     WebCore::Timer<CoordinatedLayerTreeHost> m_releaseInactiveAtlasesTimer;
211     bool m_layerFlushSchedulingEnabled;
212     uint64_t m_forceRepaintAsyncCallbackID;
213     bool m_animationsLocked;
214 };
215
216 } // namespace WebKit
217
218 #endif // USE(COORDINATED_GRAPHICS)
219
220 #endif // CoordinatedLayerTreeHost_h