Merge "[WK2] calculate tiledBackingStoreVisibleRect including animation trajectory...
[framework/web/webkit-efl.git] / Source / WebKit2 / WebProcess / WebPage / LayerTreeCoordinator / WebGraphicsLayer.h
1     /*
2  Copyright (C) 2010 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
21 #ifndef WebGraphicsLayer_h
22 #define WebGraphicsLayer_h
23
24 #include "FloatPoint3D.h"
25 #include "GraphicsLayer.h"
26 #include "GraphicsLayerAnimation.h"
27 #include "GraphicsLayerTransform.h"
28 #include "Image.h"
29 #include "IntSize.h"
30 #include "ShareableBitmap.h"
31 #include "TiledBackingStore.h"
32 #include "TiledBackingStoreClient.h"
33 #include "TiledBackingStoreRemoteTile.h"
34 #include "TransformationMatrix.h"
35 #include "UpdateInfo.h"
36 #include "WebLayerTreeInfo.h"
37 #include "WebProcess.h"
38 #include <WebCore/RunLoop.h>
39 #include <wtf/text/StringHash.h>
40
41 #if ENABLE(TIZEN_RECORDING_SURFACE_SET)
42 #include "../WebPage/cairo/RecordingSurfaceSetCairo.h"
43 #endif
44
45 #if ENABLE(TIZEN_RECORDING_SURFACE_PAINT_THREAD)
46 #include <wtf/threads/BinarySemaphore.h>
47 #endif
48
49 #if ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE)
50 #include "efl/tizen/TiledBackingStoreRemoteTileTizen.h"
51 #endif
52
53 #if USE(UI_SIDE_COMPOSITING)
54 namespace WebCore {
55 class WebGraphicsLayer;
56 class GraphicsLayerAnimations;
57 #if ENABLE(TIZEN_CUTOFF_TILES_OVER_MEMORY_LIMIT)
58 class TileCutOffInfo;
59 #endif
60 }
61
62 namespace WebKit {
63 #if ENABLE(TIZEN_RECORDING_SURFACE_SET)
64 class RecordingSurfaceSet;
65 #endif
66
67 class WebGraphicsLayerClient {
68 public:
69     // TiledBackingStoreRemoteTileClient
70     virtual void createTile(WebLayerID, int tileID, const SurfaceUpdateInfo&, const WebCore::IntRect&) = 0;
71     virtual void updateTile(WebLayerID, int tileID, const SurfaceUpdateInfo&, const WebCore::IntRect&) = 0;
72     virtual void removeTile(WebLayerID, int tileID) = 0;
73
74     virtual WebCore::IntRect visibleContentsRect() const = 0;
75     virtual bool layerTreeTileUpdatesAllowed() const = 0;
76     virtual int64_t adoptImageBackingStore(WebCore::Image*) = 0;
77     virtual void releaseImageBackingStore(int64_t) = 0;
78     virtual void syncLayerState(WebLayerID, const WebLayerInfo&) = 0;
79     virtual void syncLayerChildren(WebLayerID, const Vector<WebLayerID>&) = 0;
80 #if ENABLE(CSS_FILTERS)
81     virtual void syncLayerFilters(WebLayerID, const WebCore::FilterOperations&) = 0;
82 #endif
83 #if PLATFORM(QT) || PLATFORM(EFL)
84 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
85     virtual void syncCanvas(WebLayerID, const WebCore::IntSize& canvasSize, uint64_t graphicsSurfaceToken, uint32_t frontBuffer, int flags) = 0;
86 #else
87     virtual void syncCanvas(WebLayerID, const WebCore::IntSize& canvasSize, uint64_t graphicsSurfaceToken, uint32_t frontBuffer) = 0;
88 #endif
89 #endif
90     virtual void setLayerAnimations(WebLayerID, const WebCore::GraphicsLayerAnimations&) = 0;
91
92     virtual void attachLayer(WebCore::WebGraphicsLayer*) = 0;
93     virtual void detachLayer(WebCore::WebGraphicsLayer*) = 0;
94     virtual void syncFixedLayers() = 0;
95     virtual PassOwnPtr<WebCore::GraphicsContext> beginContentUpdate(const WebCore::IntSize&, ShareableBitmap::Flags, ShareableSurface::Handle&, WebCore::IntPoint&) = 0;
96
97 #if ENABLE(TIZEN_RECORDING_SURFACE_SET)
98     virtual bool recordingSurfaceSetEnableGet() = 0;
99     virtual bool recordingSurfaceSetLoadStartGet() = 0;
100     virtual bool recordingSurfaceSetLoadFinishedGet() = 0;
101 #endif
102
103 #if ENABLE(TIZEN_RUNTIME_BACKEND_SELECTION)
104     virtual bool isGLAccelerationMode() const = 0;
105 #endif
106 };
107 }
108
109 namespace WebCore {
110
111 class WebGraphicsLayer : public WebCore::GraphicsLayer
112                        , public TiledBackingStoreClient
113                        , public WebKit::TiledBackingStoreRemoteTileClient {
114 public:
115     WebGraphicsLayer(GraphicsLayerClient*);
116     virtual ~WebGraphicsLayer();
117
118     // Reimplementations from GraphicsLayer.h.
119     bool setChildren(const Vector<GraphicsLayer*>&);
120     void addChild(GraphicsLayer*);
121     void addChildAtIndex(GraphicsLayer*, int);
122     void addChildAbove(GraphicsLayer*, GraphicsLayer*);
123     void addChildBelow(GraphicsLayer*, GraphicsLayer*);
124     bool replaceChild(GraphicsLayer*, GraphicsLayer*);
125     void removeFromParent();
126     void setPosition(const FloatPoint&);
127     void setAnchorPoint(const FloatPoint3D&);
128     void setSize(const FloatSize&);
129     void setTransform(const TransformationMatrix&);
130     void setChildrenTransform(const TransformationMatrix&);
131     void setPreserves3D(bool);
132     void setMasksToBounds(bool);
133     void setDrawsContent(bool);
134     void setContentsVisible(bool);
135     void setContentsOpaque(bool);
136     void setBackfaceVisibility(bool);
137     void setOpacity(float);
138     void setContentsRect(const IntRect&);
139     void setContentsToImage(Image*);
140     void setContentsToBackgroundColor(const Color&);
141     void setContentsToCanvas(PlatformLayer*);
142 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
143     void setContentsToMedia(PlatformLayer*);
144 #endif
145     void setMaskLayer(GraphicsLayer*);
146     void setReplicatedByLayer(GraphicsLayer*);
147     void setNeedsDisplay();
148     void setNeedsDisplayInRect(const FloatRect&);
149     void setContentsNeedsDisplay();
150     void setContentsScale(float);
151     void setVisibleContentRectTrajectoryVector(const FloatPoint&);
152     virtual void syncCompositingState(const FloatRect&);
153     virtual void syncCompositingStateForThisLayerOnly();
154 #if ENABLE(CSS_FILTERS)
155     bool setFilters(const FilterOperations&);
156 #endif
157
158     void setRootLayer(bool);
159
160     WebKit::WebLayerID id() const;
161     static WebGraphicsLayer* layerByID(WebKit::WebLayerID);
162     void didSynchronize();
163     Image* image() { return m_image.get(); }
164
165     bool fixedToViewport() const { return m_fixedToViewport; }
166     void setFixedToViewport(bool isFixed) { m_fixedToViewport = isFixed; }
167
168     GraphicsLayer* maskTarget() const { return m_maskTarget; }
169     void setMaskTarget(GraphicsLayer* layer) { m_maskTarget = layer; }
170
171     static void initFactory();
172
173     // TiledBackingStoreClient
174     virtual void tiledBackingStorePaintBegin();
175     virtual void tiledBackingStorePaint(GraphicsContext*, const IntRect&);
176     virtual void tiledBackingStorePaintEnd(const Vector<IntRect>& paintedArea);
177     virtual bool tiledBackingStoreUpdatesAllowed() const;
178     virtual IntRect tiledBackingStoreContentsRect();
179     virtual IntRect tiledBackingStoreVisibleRect();
180     virtual Color tiledBackingStoreBackgroundColor() const;
181
182     // TiledBackingStoreRemoteTileClient
183     virtual void createTile(int tileID, const WebKit::SurfaceUpdateInfo&, const WebCore::IntRect&);
184     virtual void updateTile(int tileID, const WebKit::SurfaceUpdateInfo&, const WebCore::IntRect&);
185     virtual void removeTile(int tileID);
186     virtual PassOwnPtr<WebCore::GraphicsContext> beginContentUpdate(const WebCore::IntSize&, WebKit::ShareableSurface::Handle&, WebCore::IntPoint&);
187
188     void setWebGraphicsLayerClient(WebKit::WebGraphicsLayerClient*);
189     void syncChildren();
190     void syncLayerState();
191 #if ENABLE(CSS_FILTERS)
192     void syncFilters();
193 #endif
194     void syncCanvas();
195     void ensureImageBackingStore();
196
197     void adjustVisibleRect();
198     bool isReadyForTileBufferSwap() const;
199     void updateContentBuffers();
200     void purgeBackingStores();
201     bool hasPendingVisibleChanges();
202
203     virtual bool addAnimation(const KeyframeValueList&, const IntSize&, const Animation*, const String&, double);
204     virtual void pauseAnimation(const String&, double);
205     virtual void removeAnimation(const String&);
206
207 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
208 #if ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE)
209     void freePlatformSurface(int platformSurfaceID);
210     void removePlatformSurface(int platformSurfaceID);
211     bool swapPlatformSurfaces();
212 #endif
213 #if ENABLE(TIZEN_ACCELERATED_2D_CANVAS_EFL)
214     void flushPlatformSurfaces();
215 #endif
216     int contentType() { return m_layerInfo.contentType; }
217 #endif
218
219 #if ENABLE(TIZEN_WEBKIT2_DEBUG_BORDERS)
220     virtual bool drawTileInfo() const;
221 #endif
222
223 #if ENABLE(TIZEN_RECORDING_SURFACE_SET)
224     virtual IntRect dirtyUnionRect();
225     void setNonCompositedLayer(bool);
226 #endif
227
228 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION)
229     void setVisibleRect(const IntRect& rect) { m_visibleRect = rect; }
230     void setIsOverflow(const bool b);
231     bool isOverflow() const { return m_isOverflow; }
232 #endif
233
234 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_SCROLLBAR)
235     void startAnimation();
236     void animationTimerFired(WebCore::Timer<WebGraphicsLayer>*);
237 #endif
238
239 #if ENABLE(TIZEN_CUTOFF_TILES_OVER_MEMORY_LIMIT)
240     Vector<TileCutOffInfo> getCutOffInfoList();
241     void setCutOffDistance(double distance);
242 #endif
243 #if ENABLE(TIZEN_WEBKIT2_MEMORY_SAVING_MODE)
244     bool memorySavingModeEnabled();
245 #endif
246 #if ENABLE(TIZEN_CSS_OVERFLOW_CLIPPING_BACKING_STORE)
247     FloatRect clippingBounds();
248 #endif
249
250 private:
251     virtual void willBeDestroyed();
252     WebKit::WebLayerID m_id;
253     WebKit::WebLayerInfo m_layerInfo;
254     RefPtr<Image> m_image;
255     GraphicsLayer* m_maskTarget;
256     FloatRect m_needsDisplayRect;
257     GraphicsLayerTransform m_layerTransform;
258     GraphicsLayerTransform m_layerSettledTransform;
259     bool m_inUpdateMode : 1;
260     bool m_shouldUpdateVisibleRect: 1;
261     bool m_shouldSyncLayerState: 1;
262     bool m_shouldSyncChildren: 1;
263     bool m_shouldSyncFilters: 1;
264     bool m_shouldSyncAnimations: 1;
265     bool m_fixedToViewport : 1;
266     bool m_movingVisibleRect : 1;
267 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION)
268     bool m_isOverflow : 1;
269 #endif
270     bool m_canvasNeedsDisplay : 1;
271 #if ENABLE(TIZEN_DONT_PURGE_PLATFORM_SURFACE_BACKINGSTORE_ON_NODE_DETACH_FROM_WEBLAYER_TREE)
272     bool m_shouldSyncBackingStore : 1;
273 #endif
274
275     void notifyChange();
276     void didChangeAnimations();
277     void didChangeGeometry();
278     void didChangeLayerState();
279     void didChangeChildren();
280 #if ENABLE(CSS_FILTERS)
281     void didChangeFilters();
282 #endif
283
284     float m_effectiveOpacity;
285     TransformationMatrix m_effectiveTransform;
286
287     void createBackingStore();
288
289     bool selfOrAncestorHasActiveTransformAnimation();
290     bool selfOrAncestorHaveNonAffineTransforms();
291     void adjustContentsScale();
292     void computeTransformedVisibleRect();
293     void syncLayerParameters();
294     void syncAnimations();
295     void setShouldUpdateVisibleRect();
296     float effectiveContentsScale();
297
298     void animationStartedTimerFired(WebCore::Timer<WebGraphicsLayer>*);
299 #if ENABLE(TIZEN_DONT_PURGE_PLATFORM_SURFACE_BACKINGSTORE_ON_NODE_DETACH_FROM_WEBLAYER_TREE)
300     void syncBackingStoreIfNeeded();
301 #endif
302
303     WebKit::WebGraphicsLayerClient* m_webGraphicsLayerClient;
304     OwnPtr<WebCore::TiledBackingStore> m_mainBackingStore;
305     OwnPtr<WebCore::TiledBackingStore> m_previousBackingStore;
306     float m_contentsScale;
307
308 #if ENABLE(TIZEN_RECORDING_SURFACE_SET)
309     bool recordingSurfaceSetEnableGet();
310     bool recordingSurfaceSetLoadStartGet();
311     bool recordingSurfaceSetLoadFinishedGet();
312     void recordingSurfaceSetRecord();
313     void recordingSurfaceSetReplay(WebCore::GraphicsContext&, const WebCore::IntRect&);
314     void recordingSurfaceSetRebuild(WebKit::RecordingSurfaceSet*, float scale);
315     void setDirtyUnionRect(const IntRect& rect);
316     void uniteDirtyUnionRect(const IntRect& rect);
317     void setDirtyRect(const IntRect& rect);
318     void dirtyRectInvalidate();
319
320     enum RecordingSurfaceSetStatus {
321         RecordingSurfaceSetInit,
322         RecordingSurfaceSetComplete
323     };
324
325     bool m_nonCompositedLayer;
326     IntRect m_dirtyUnionRect;
327     bool m_changedZoomSet;
328     bool m_recordingSurfaceSetIsReplaying;
329     RecordingSurfaceSetStatus m_recordingSurfaceSetStatus;
330     WebKit::RecordingSurfaceSet* m_recordingSurfaceSet;
331     Vector<WebCore::IntRect> m_dirtyRects;
332
333 #if ENABLE(TIZEN_RECORDING_SURFACE_PAINT_THREAD)
334     void updateTileBuffers();
335     void scheduleUpdateTileBuffersAsync();
336     WTF::BinarySemaphore m_waitForSyncSemaphore;
337 #endif
338 #endif
339 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION)
340     IntRect m_visibleRect;
341 #endif
342     PlatformLayer* m_canvasPlatformLayer;
343     Timer<WebGraphicsLayer> m_animationStartedTimer;
344     GraphicsLayerAnimations m_animations;
345
346 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_SCROLLBAR)
347     WebCore::Timer<WebGraphicsLayer> m_animationTimer;
348 #endif
349 };
350
351 WebGraphicsLayer* toWebGraphicsLayer(GraphicsLayer*);
352
353 }
354 #endif
355
356 #endif // WebGraphicsLayer_H