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