Revert "Remove TIZEN_RECORDING_SURFACE_SET and TIZEN_RECORDING_SURFACE_PAINT_THREAD"
[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 #else
213     void markCanvasPlatformLayerNeedsUpdate() { m_canvasNeedsDisplay = true; }
214 #endif
215 #if ENABLE(TIZEN_ACCELERATED_2D_CANVAS_EFL)
216     void flushPlatformSurfaces();
217 #endif
218     int contentType() { return m_layerInfo.contentType; }
219 #endif
220
221 #if ENABLE(TIZEN_WEBKIT2_DEBUG_BORDERS)
222     virtual bool drawTileInfo() const;
223 #endif
224
225 #if ENABLE(TIZEN_RECORDING_SURFACE_SET)
226     virtual IntRect dirtyUnionRect();
227     void setNonCompositedLayer(bool);
228 #endif
229
230 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION)
231     void setVisibleRect(const IntRect& rect) { m_visibleRect = rect; }
232     void setIsOverflow(const bool b);
233     bool isOverflow() const { return m_isOverflow; }
234 #endif
235
236 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_SCROLLBAR)
237     void startAnimation();
238     void animationTimerFired(WebCore::Timer<WebGraphicsLayer>*);
239 #endif
240
241 #if ENABLE(TIZEN_CUTOFF_TILES_OVER_MEMORY_LIMIT)
242     Vector<TileCutOffInfo> getCutOffInfoList();
243     void setCutOffDistance(double distance);
244 #endif
245 #if ENABLE(TIZEN_WEBKIT2_MEMORY_SAVING_MODE)
246     bool memorySavingModeEnabled();
247 #endif
248 #if ENABLE(TIZEN_CSS_OVERFLOW_CLIPPING_BACKING_STORE)
249     FloatRect clippingBounds();
250 #endif
251
252 private:
253     virtual void willBeDestroyed();
254     WebKit::WebLayerID m_id;
255     WebKit::WebLayerInfo m_layerInfo;
256     RefPtr<Image> m_image;
257     GraphicsLayer* m_maskTarget;
258     FloatRect m_needsDisplayRect;
259     GraphicsLayerTransform m_layerTransform;
260     GraphicsLayerTransform m_layerSettledTransform;
261     bool m_inUpdateMode : 1;
262     bool m_shouldUpdateVisibleRect: 1;
263     bool m_shouldSyncLayerState: 1;
264     bool m_shouldSyncChildren: 1;
265     bool m_shouldSyncFilters: 1;
266     bool m_shouldSyncAnimations: 1;
267     bool m_fixedToViewport : 1;
268     bool m_movingVisibleRect : 1;
269 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION)
270     bool m_isOverflow : 1;
271 #endif
272     bool m_canvasNeedsDisplay : 1;
273 #if ENABLE(TIZEN_DONT_PURGE_PLATFORM_SURFACE_BACKINGSTORE_ON_NODE_DETACH_FROM_WEBLAYER_TREE)
274     bool m_shouldSyncBackingStore : 1;
275 #endif
276
277     void notifyChange();
278     void didChangeAnimations();
279     void didChangeGeometry();
280     void didChangeLayerState();
281     void didChangeChildren();
282 #if ENABLE(CSS_FILTERS)
283     void didChangeFilters();
284 #endif
285
286     float m_effectiveOpacity;
287     TransformationMatrix m_effectiveTransform;
288
289     void createBackingStore();
290
291     bool selfOrAncestorHasActiveTransformAnimation();
292     bool selfOrAncestorHaveNonAffineTransforms();
293     void adjustContentsScale();
294     void computeTransformedVisibleRect();
295     void syncLayerParameters();
296     void syncAnimations();
297     void setShouldUpdateVisibleRect();
298     float effectiveContentsScale();
299
300     void animationStartedTimerFired(WebCore::Timer<WebGraphicsLayer>*);
301 #if ENABLE(TIZEN_DONT_PURGE_PLATFORM_SURFACE_BACKINGSTORE_ON_NODE_DETACH_FROM_WEBLAYER_TREE)
302     void syncBackingStoreIfNeeded();
303 #endif
304
305     WebKit::WebGraphicsLayerClient* m_webGraphicsLayerClient;
306     OwnPtr<WebCore::TiledBackingStore> m_mainBackingStore;
307     OwnPtr<WebCore::TiledBackingStore> m_previousBackingStore;
308     float m_contentsScale;
309
310 #if ENABLE(TIZEN_RECORDING_SURFACE_SET)
311     bool recordingSurfaceSetEnableGet();
312     bool recordingSurfaceSetLoadStartGet();
313     bool recordingSurfaceSetLoadFinishedGet();
314     void recordingSurfaceSetRecord();
315     void recordingSurfaceSetReplay(WebCore::GraphicsContext&, const WebCore::IntRect&);
316     void recordingSurfaceSetRebuild(WebKit::RecordingSurfaceSet*, float scale);
317     void setDirtyUnionRect(const IntRect& rect);
318     void uniteDirtyUnionRect(const IntRect& rect);
319     void setDirtyRect(const IntRect& rect);
320     void dirtyRectInvalidate();
321
322     enum RecordingSurfaceSetStatus {
323         RecordingSurfaceSetInit,
324         RecordingSurfaceSetComplete
325     };
326
327     bool m_nonCompositedLayer;
328     IntRect m_dirtyUnionRect;
329     bool m_changedZoomSet;
330     bool m_recordingSurfaceSetIsReplaying;
331     RecordingSurfaceSetStatus m_recordingSurfaceSetStatus;
332     WebKit::RecordingSurfaceSet* m_recordingSurfaceSet;
333     Vector<WebCore::IntRect> m_dirtyRects;
334
335 #if ENABLE(TIZEN_RECORDING_SURFACE_PAINT_THREAD)
336     void updateTileBuffers();
337     void scheduleUpdateTileBuffersAsync();
338     WTF::BinarySemaphore m_waitForSyncSemaphore;
339 #endif
340 #endif
341 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION)
342     IntRect m_visibleRect;
343 #endif
344     PlatformLayer* m_canvasPlatformLayer;
345     Timer<WebGraphicsLayer> m_animationStartedTimer;
346     GraphicsLayerAnimations m_animations;
347
348 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_SCROLLBAR)
349     WebCore::Timer<WebGraphicsLayer> m_animationTimer;
350 #endif
351 };
352
353 WebGraphicsLayer* toWebGraphicsLayer(GraphicsLayer*);
354
355 }
356 #endif
357
358 #endif // WebGraphicsLayer_H