2 Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
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.
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.
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.
21 #ifndef WebGraphicsLayer_h
22 #define WebGraphicsLayer_h
24 #include "FloatPoint3D.h"
25 #include "GraphicsLayer.h"
26 #include "GraphicsLayerAnimation.h"
27 #include "GraphicsLayerTransform.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>
41 #if ENABLE(TIZEN_RECORDING_SURFACE_SET)
42 #include "../WebPage/cairo/RecordingSurfaceSetCairo.h"
45 #if ENABLE(TIZEN_RECORDING_SURFACE_PAINT_THREAD)
46 #include <wtf/threads/BinarySemaphore.h>
49 #if ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE)
50 #include "efl/tizen/TiledBackingStoreRemoteTileTizen.h"
53 #if USE(UI_SIDE_COMPOSITING)
55 class WebGraphicsLayer;
56 class GraphicsLayerAnimations;
57 #if ENABLE(TIZEN_CUTOFF_TILES_OVER_MEMORY_LIMIT)
63 #if ENABLE(TIZEN_RECORDING_SURFACE_SET)
64 class RecordingSurfaceSet;
67 class WebGraphicsLayerClient {
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;
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;
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;
87 virtual void syncCanvas(WebLayerID, const WebCore::IntSize& canvasSize, uint64_t graphicsSurfaceToken, uint32_t frontBuffer) = 0;
90 virtual void setLayerAnimations(WebLayerID, const WebCore::GraphicsLayerAnimations&) = 0;
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;
97 #if ENABLE(TIZEN_RECORDING_SURFACE_SET)
98 virtual bool recordingSurfaceSetEnableGet() = 0;
99 virtual bool recordingSurfaceSetLoadStartGet() = 0;
100 virtual bool recordingSurfaceSetLoadFinishedGet() = 0;
103 #if ENABLE(TIZEN_RUNTIME_BACKEND_SELECTION)
104 virtual bool isGLAccelerationMode() const = 0;
111 class WebGraphicsLayer : public WebCore::GraphicsLayer
112 , public TiledBackingStoreClient
113 , public WebKit::TiledBackingStoreRemoteTileClient {
115 WebGraphicsLayer(GraphicsLayerClient*);
116 virtual ~WebGraphicsLayer();
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*);
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&);
158 void setRootLayer(bool);
160 WebKit::WebLayerID id() const;
161 static WebGraphicsLayer* layerByID(WebKit::WebLayerID);
162 void didSynchronize();
163 Image* image() { return m_image.get(); }
165 bool fixedToViewport() const { return m_fixedToViewport; }
166 void setFixedToViewport(bool isFixed) { m_fixedToViewport = isFixed; }
168 GraphicsLayer* maskTarget() const { return m_maskTarget; }
169 void setMaskTarget(GraphicsLayer* layer) { m_maskTarget = layer; }
171 static void initFactory();
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;
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&);
188 void setWebGraphicsLayerClient(WebKit::WebGraphicsLayerClient*);
190 void syncLayerState();
191 #if ENABLE(CSS_FILTERS)
195 void ensureImageBackingStore();
197 void adjustVisibleRect();
198 bool isReadyForTileBufferSwap() const;
199 void updateContentBuffers();
200 void purgeBackingStores();
201 bool hasPendingVisibleChanges();
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&);
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();
213 #if ENABLE(TIZEN_ACCELERATED_2D_CANVAS_EFL)
214 void flushPlatformSurfaces();
216 int contentType() { return m_layerInfo.contentType; }
219 #if ENABLE(TIZEN_WEBKIT2_DEBUG_BORDERS)
220 virtual bool drawTileInfo() const;
223 #if ENABLE(TIZEN_RECORDING_SURFACE_SET)
224 virtual IntRect dirtyUnionRect();
225 void setNonCompositedLayer(bool);
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; }
234 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_SCROLLBAR)
235 void startAnimation();
236 void animationTimerFired(WebCore::Timer<WebGraphicsLayer>*);
239 #if ENABLE(TIZEN_CUTOFF_TILES_OVER_MEMORY_LIMIT)
240 Vector<TileCutOffInfo> getCutOffInfoList();
241 void setCutOffDistance(double distance);
243 #if ENABLE(TIZEN_WEBKIT2_MEMORY_SAVING_MODE)
244 bool memorySavingModeEnabled();
246 #if ENABLE(TIZEN_CSS_OVERFLOW_CLIPPING_BACKING_STORE)
247 FloatRect clippingBounds();
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 bool m_inUpdateMode : 1;
259 bool m_shouldUpdateVisibleRect: 1;
260 bool m_shouldSyncLayerState: 1;
261 bool m_shouldSyncChildren: 1;
262 bool m_shouldSyncFilters: 1;
263 bool m_shouldSyncAnimations: 1;
264 bool m_fixedToViewport : 1;
265 bool m_movingVisibleRect : 1;
266 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION)
267 bool m_isOverflow : 1;
269 bool m_canvasNeedsDisplay : 1;
270 #if ENABLE(TIZEN_DONT_PURGE_PLATFORM_SURFACE_BACKINGSTORE_ON_NODE_DETACH_FROM_WEBLAYER_TREE)
271 bool m_shouldSyncBackingStore : 1;
275 void didChangeAnimations();
276 void didChangeGeometry();
277 void didChangeLayerState();
278 void didChangeChildren();
279 #if ENABLE(CSS_FILTERS)
280 void didChangeFilters();
283 float m_effectiveOpacity;
284 TransformationMatrix m_effectiveTransform;
286 void createBackingStore();
288 bool selfOrAncestorHasActiveTransformAnimation();
289 bool selfOrAncestorHaveNonAffineTransforms();
290 void adjustContentsScale();
291 void computeTransformedVisibleRect();
292 void syncLayerParameters();
293 void syncAnimations();
294 void setShouldUpdateVisibleRect();
295 float effectiveContentsScale();
297 void animationStartedTimerFired(WebCore::Timer<WebGraphicsLayer>*);
298 #if ENABLE(TIZEN_DONT_PURGE_PLATFORM_SURFACE_BACKINGSTORE_ON_NODE_DETACH_FROM_WEBLAYER_TREE)
299 void syncBackingStoreIfNeeded();
302 WebKit::WebGraphicsLayerClient* m_webGraphicsLayerClient;
303 OwnPtr<WebCore::TiledBackingStore> m_mainBackingStore;
304 OwnPtr<WebCore::TiledBackingStore> m_previousBackingStore;
305 float m_contentsScale;
307 #if ENABLE(TIZEN_RECORDING_SURFACE_SET)
308 bool recordingSurfaceSetEnableGet();
309 bool recordingSurfaceSetLoadStartGet();
310 bool recordingSurfaceSetLoadFinishedGet();
311 void recordingSurfaceSetRecord();
312 void recordingSurfaceSetReplay(WebCore::GraphicsContext&, const WebCore::IntRect&);
313 void recordingSurfaceSetRebuild(WebKit::RecordingSurfaceSet*, float scale);
314 void setDirtyUnionRect(const IntRect& rect);
315 void uniteDirtyUnionRect(const IntRect& rect);
316 void setDirtyRect(const IntRect& rect);
317 void dirtyRectInvalidate();
319 enum RecordingSurfaceSetStatus {
320 RecordingSurfaceSetInit,
321 RecordingSurfaceSetComplete
324 bool m_nonCompositedLayer;
325 IntRect m_dirtyUnionRect;
326 bool m_changedZoomSet;
327 bool m_recordingSurfaceSetIsReplaying;
328 RecordingSurfaceSetStatus m_recordingSurfaceSetStatus;
329 WebKit::RecordingSurfaceSet* m_recordingSurfaceSet;
330 Vector<WebCore::IntRect> m_dirtyRects;
332 #if ENABLE(TIZEN_RECORDING_SURFACE_PAINT_THREAD)
333 void updateTileBuffers();
334 void scheduleUpdateTileBuffersAsync();
335 WTF::BinarySemaphore m_waitForSyncSemaphore;
338 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION)
339 IntRect m_visibleRect;
341 PlatformLayer* m_canvasPlatformLayer;
342 Timer<WebGraphicsLayer> m_animationStartedTimer;
343 GraphicsLayerAnimations m_animations;
345 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_SCROLLBAR)
346 WebCore::Timer<WebGraphicsLayer> m_animationTimer;
350 WebGraphicsLayer* toWebGraphicsLayer(GraphicsLayer*);
355 #endif // WebGraphicsLayer_H