dbebd386a5e57c89f29f213cd9ca05e93a663f29
[WebKit-https.git] / Source / WebKit2 / WebProcess / WebPage / CoordinatedGraphics / LayerTreeCoordinator.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 LayerTreeCoordinator_h
21 #define LayerTreeCoordinator_h
22
23 #if USE(COORDINATED_GRAPHICS)
24
25 #include "CoordinatedGraphicsLayer.h"
26 #include "LayerTreeContext.h"
27 #include "LayerTreeHost.h"
28 #include "Timer.h"
29 #include "UpdateAtlas.h"
30 #include <WebCore/GraphicsLayerClient.h>
31 #include <WebCore/GraphicsLayerFactory.h>
32 #include <WebCore/GraphicsSurface.h>
33 #include <wtf/OwnPtr.h>
34
35 namespace WebKit {
36
37 class UpdateInfo;
38 class WebPage;
39
40 class LayerTreeCoordinator : public LayerTreeHost, WebCore::GraphicsLayerClient
41                            , public CoordinatedGraphicsLayerClient
42                            , public WebCore::GraphicsLayerFactory {
43 public:
44     static PassRefPtr<LayerTreeCoordinator> create(WebPage*);
45     virtual ~LayerTreeCoordinator();
46
47     static bool supportsAcceleratedCompositing();
48
49     virtual const LayerTreeContext& layerTreeContext() { return m_layerTreeContext; }
50     virtual void setLayerFlushSchedulingEnabled(bool);
51     virtual void scheduleLayerFlush();
52     virtual void setShouldNotifyAfterNextScheduledLayerFlush(bool);
53     virtual void setRootCompositingLayer(WebCore::GraphicsLayer*);
54     virtual void invalidate();
55
56     virtual void setNonCompositedContentsNeedDisplay(const WebCore::IntRect&);
57     virtual void scrollNonCompositedContents(const WebCore::IntRect& scrollRect, const WebCore::IntSize& scrollOffset);
58     virtual void forceRepaint();
59     virtual bool forceRepaintAsync(uint64_t callbackID);
60     virtual void sizeDidChange(const WebCore::IntSize& newSize);
61
62     virtual void didInstallPageOverlay();
63     virtual void didUninstallPageOverlay();
64     virtual void setPageOverlayNeedsDisplay(const WebCore::IntRect&);
65     virtual void setPageOverlayOpacity(float);
66     virtual bool pageOverlayShouldApplyFadeWhenPainting() const { return false; }
67
68     virtual void pauseRendering() { m_isSuspended = true; }
69     virtual void resumeRendering() { m_isSuspended = false; scheduleLayerFlush(); }
70     virtual void deviceScaleFactorDidChange() { }
71     virtual int64_t adoptImageBackingStore(WebCore::Image*);
72     virtual void releaseImageBackingStore(int64_t);
73
74     virtual void createTile(WebLayerID, int tileID, const SurfaceUpdateInfo&, const WebCore::IntRect&);
75     virtual void updateTile(WebLayerID, int tileID, const SurfaceUpdateInfo&, const WebCore::IntRect&);
76     virtual void removeTile(WebLayerID, int tileID);
77     virtual WebCore::IntRect visibleContentsRect() const;
78     virtual void renderNextFrame();
79     virtual void purgeBackingStores();
80     virtual bool layerTreeTileUpdatesAllowed() const;
81     virtual void setVisibleContentsRect(const WebCore::IntRect&, float scale, const WebCore::FloatPoint&);
82     virtual void didReceiveLayerTreeCoordinatorMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*);
83     virtual WebCore::GraphicsLayerFactory* graphicsLayerFactory() OVERRIDE;
84
85     virtual void syncLayerState(WebLayerID, const WebLayerInfo&);
86     virtual void syncLayerChildren(WebLayerID, const Vector<WebLayerID>&);
87     virtual void setLayerAnimatedOpacity(WebLayerID, float);
88     virtual void setLayerAnimatedTransform(WebLayerID, const WebCore::TransformationMatrix&);
89 #if ENABLE(CSS_FILTERS)
90     virtual void syncLayerFilters(WebLayerID, const WebCore::FilterOperations&);
91 #endif
92 #if USE(GRAPHICS_SURFACE)
93     virtual void syncCanvas(WebLayerID, const WebCore::IntSize& canvasSize, const WebCore::GraphicsSurfaceToken&, uint32_t frontBuffer) OVERRIDE;
94 #endif
95     virtual void attachLayer(WebCore::CoordinatedGraphicsLayer*);
96     virtual void detachLayer(WebCore::CoordinatedGraphicsLayer*);
97     virtual void syncFixedLayers();
98
99     virtual PassOwnPtr<WebCore::GraphicsContext> beginContentUpdate(const WebCore::IntSize&, ShareableBitmap::Flags, ShareableSurface::Handle&, WebCore::IntPoint&);
100     virtual void scheduleAnimation() OVERRIDE;
101
102 protected:
103     explicit LayerTreeCoordinator(WebPage*);
104
105 private:
106     // GraphicsLayerClient
107     virtual void notifyAnimationStarted(const WebCore::GraphicsLayer*, double time);
108     virtual void notifyFlushRequired(const WebCore::GraphicsLayer*);
109     virtual void paintContents(const WebCore::GraphicsLayer*, WebCore::GraphicsContext&, WebCore::GraphicsLayerPaintingPhase, const WebCore::IntRect& clipRect);
110     virtual bool showDebugBorders(const WebCore::GraphicsLayer*) const;
111     virtual bool showRepaintCounter(const WebCore::GraphicsLayer*) const;
112
113     // GraphicsLayerFactory
114     virtual PassOwnPtr<WebCore::GraphicsLayer> createGraphicsLayer(WebCore::GraphicsLayerClient*) OVERRIDE;
115
116     // LayerTreeCoordinator
117     void createPageOverlayLayer();
118     void destroyPageOverlayLayer();
119     bool flushPendingLayerChanges();
120     void cancelPendingLayerFlush();
121     void performScheduledLayerFlush();
122     void didPerformScheduledLayerFlush();
123     void syncDisplayState();
124
125     void layerFlushTimerFired(WebCore::Timer<LayerTreeCoordinator>*);
126
127     void scheduleReleaseInactiveAtlases();
128     void releaseInactiveAtlasesTimerFired(WebCore::Timer<LayerTreeCoordinator>*);
129
130     OwnPtr<WebCore::GraphicsLayer> m_rootLayer;
131
132     // The layer which contains all non-composited content.
133     OwnPtr<WebCore::GraphicsLayer> m_nonCompositedContentLayer;
134
135     // The page overlay layer. Will be null if there's no page overlay.
136     OwnPtr<WebCore::GraphicsLayer> m_pageOverlayLayer;
137
138     HashSet<WebCore::CoordinatedGraphicsLayer*> m_registeredLayers;
139     Vector<WebLayerID> m_detachedLayers;
140     HashMap<int64_t, int> m_directlyCompositedImageRefCounts;
141     Vector<OwnPtr<UpdateAtlas> > m_updateAtlases;
142
143     bool m_notifyAfterScheduledLayerFlush;
144     bool m_isValid;
145
146     bool m_waitingForUIProcess;
147     bool m_isSuspended;
148     WebCore::IntRect m_visibleContentsRect;
149     float m_contentsScale;
150     bool m_shouldSendScrollPositionUpdate;
151
152     LayerTreeContext m_layerTreeContext;
153     bool m_shouldSyncFrame;
154     bool m_shouldSyncRootLayer;
155     WebCore::Timer<LayerTreeCoordinator> m_layerFlushTimer;
156     WebCore::Timer<LayerTreeCoordinator> m_releaseInactiveAtlasesTimer;
157     bool m_layerFlushSchedulingEnabled;
158     uint64_t m_forceRepaintAsyncCallbackID;
159 };
160
161 }
162
163 #endif
164
165 #endif // LayerTreeCoordinator_h