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_PAINT_THREAD)
42 #include <wtf/threads/BinarySemaphore.h>
45 #if ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE)
46 #include "efl/tizen/TiledBackingStoreRemoteTileTizen.h"
49 #if USE(UI_SIDE_COMPOSITING)
51 class WebGraphicsLayer;
52 class GraphicsLayerAnimations;
53 #if ENABLE(TIZEN_CUTOFF_TILES_OVER_MEMORY_LIMIT)
60 class WebGraphicsLayerClient {
62 // TiledBackingStoreRemoteTileClient
63 virtual void createTile(WebLayerID, int tileID, const SurfaceUpdateInfo&, const WebCore::IntRect&) = 0;
64 virtual void updateTile(WebLayerID, int tileID, const SurfaceUpdateInfo&, const WebCore::IntRect&) = 0;
65 virtual void removeTile(WebLayerID, int tileID) = 0;
67 virtual WebCore::IntRect visibleContentsRect() const = 0;
68 virtual bool layerTreeTileUpdatesAllowed() const = 0;
69 virtual int64_t adoptImageBackingStore(WebCore::Image*) = 0;
70 virtual void releaseImageBackingStore(int64_t) = 0;
71 virtual void syncLayerState(WebLayerID, const WebLayerInfo&) = 0;
72 virtual void syncLayerChildren(WebLayerID, const Vector<WebLayerID>&) = 0;
73 #if ENABLE(CSS_FILTERS)
74 virtual void syncLayerFilters(WebLayerID, const WebCore::FilterOperations&) = 0;
76 #if PLATFORM(QT) || PLATFORM(EFL)
77 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
78 virtual void syncCanvas(WebLayerID, const WebCore::IntSize& canvasSize, uint64_t graphicsSurfaceToken, uint32_t frontBuffer, int flags) = 0;
80 virtual void syncCanvas(WebLayerID, const WebCore::IntSize& canvasSize, uint64_t graphicsSurfaceToken, uint32_t frontBuffer) = 0;
83 virtual void setLayerAnimations(WebLayerID, const WebCore::GraphicsLayerAnimations&) = 0;
85 virtual void attachLayer(WebCore::WebGraphicsLayer*) = 0;
86 virtual void detachLayer(WebCore::WebGraphicsLayer*) = 0;
87 virtual void syncFixedLayers() = 0;
88 virtual PassOwnPtr<WebCore::GraphicsContext> beginContentUpdate(const WebCore::IntSize&, ShareableBitmap::Flags, ShareableSurface::Handle&, WebCore::IntPoint&) = 0;
90 #if ENABLE(TIZEN_RUNTIME_BACKEND_SELECTION)
91 virtual bool isGLAccelerationMode() const = 0;
98 class WebGraphicsLayer : public WebCore::GraphicsLayer
99 , public TiledBackingStoreClient
100 , public WebKit::TiledBackingStoreRemoteTileClient {
102 WebGraphicsLayer(GraphicsLayerClient*);
103 virtual ~WebGraphicsLayer();
105 // Reimplementations from GraphicsLayer.h.
106 bool setChildren(const Vector<GraphicsLayer*>&);
107 void addChild(GraphicsLayer*);
108 void addChildAtIndex(GraphicsLayer*, int);
109 void addChildAbove(GraphicsLayer*, GraphicsLayer*);
110 void addChildBelow(GraphicsLayer*, GraphicsLayer*);
111 bool replaceChild(GraphicsLayer*, GraphicsLayer*);
112 void removeFromParent();
113 void setPosition(const FloatPoint&);
114 void setAnchorPoint(const FloatPoint3D&);
115 void setSize(const FloatSize&);
116 void setTransform(const TransformationMatrix&);
117 void setChildrenTransform(const TransformationMatrix&);
118 void setPreserves3D(bool);
119 void setMasksToBounds(bool);
120 void setDrawsContent(bool);
121 void setContentsVisible(bool);
122 void setContentsOpaque(bool);
123 void setBackfaceVisibility(bool);
124 void setOpacity(float);
125 void setContentsRect(const IntRect&);
126 void setContentsToImage(Image*);
127 void setContentsToBackgroundColor(const Color&);
128 void setContentsToCanvas(PlatformLayer*);
129 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
130 void setContentsToMedia(PlatformLayer*);
132 void setMaskLayer(GraphicsLayer*);
133 void setReplicatedByLayer(GraphicsLayer*);
134 void setNeedsDisplay();
135 void setNeedsDisplayInRect(const FloatRect&);
136 void setContentsNeedsDisplay();
137 void setContentsScale(float);
138 void setVisibleContentRectTrajectoryVector(const FloatPoint&);
139 virtual void syncCompositingState(const FloatRect&);
140 virtual void syncCompositingStateForThisLayerOnly();
141 #if ENABLE(CSS_FILTERS)
142 bool setFilters(const FilterOperations&);
145 void setRootLayer(bool);
147 WebKit::WebLayerID id() const;
148 static WebGraphicsLayer* layerByID(WebKit::WebLayerID);
149 void didSynchronize();
150 Image* image() { return m_image.get(); }
152 bool fixedToViewport() const { return m_fixedToViewport; }
153 void setFixedToViewport(bool isFixed) { m_fixedToViewport = isFixed; }
155 GraphicsLayer* maskTarget() const { return m_maskTarget; }
156 void setMaskTarget(GraphicsLayer* layer) { m_maskTarget = layer; }
158 static void initFactory();
160 // TiledBackingStoreClient
161 virtual void tiledBackingStorePaintBegin();
162 virtual void tiledBackingStorePaint(GraphicsContext*, const IntRect&);
163 virtual void tiledBackingStorePaintEnd(const Vector<IntRect>& paintedArea);
164 virtual bool tiledBackingStoreUpdatesAllowed() const;
165 virtual IntRect tiledBackingStoreContentsRect();
166 virtual IntRect tiledBackingStoreVisibleRect();
167 virtual Color tiledBackingStoreBackgroundColor() const;
169 // TiledBackingStoreRemoteTileClient
170 virtual void createTile(int tileID, const WebKit::SurfaceUpdateInfo&, const WebCore::IntRect&);
171 virtual void updateTile(int tileID, const WebKit::SurfaceUpdateInfo&, const WebCore::IntRect&);
172 virtual void removeTile(int tileID);
173 virtual PassOwnPtr<WebCore::GraphicsContext> beginContentUpdate(const WebCore::IntSize&, WebKit::ShareableSurface::Handle&, WebCore::IntPoint&);
175 void setWebGraphicsLayerClient(WebKit::WebGraphicsLayerClient*);
177 void syncLayerState();
178 #if ENABLE(CSS_FILTERS)
182 void ensureImageBackingStore();
184 void adjustVisibleRect();
185 bool isReadyForTileBufferSwap() const;
186 void updateContentBuffers();
187 void purgeBackingStores();
188 bool hasPendingVisibleChanges();
190 virtual bool addAnimation(const KeyframeValueList&, const IntSize&, const Animation*, const String&, double);
191 virtual void pauseAnimation(const String&, double);
192 virtual void removeAnimation(const String&);
194 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
195 #if ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE)
196 void freePlatformSurface(int platformSurfaceID);
197 void removePlatformSurface(int platformSurfaceID);
198 bool swapPlatformSurfaces();
200 void markCanvasPlatformLayerNeedsUpdate() { m_canvasNeedsDisplay = true; }
202 #if ENABLE(TIZEN_ACCELERATED_2D_CANVAS_EFL)
203 void flushPlatformSurfaces();
205 int contentType() { return m_layerInfo.contentType; }
208 #if ENABLE(TIZEN_WEBKIT2_DEBUG_BORDERS)
209 virtual bool drawTileInfo() const;
212 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION)
213 void setIsOverflow(const bool b);
214 bool isOverflow() const { return m_isOverflow; }
217 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_SCROLLBAR)
218 void startAnimation();
219 void animationTimerFired(WebCore::Timer<WebGraphicsLayer>*);
222 #if ENABLE(TIZEN_CUTOFF_TILES_OVER_MEMORY_LIMIT)
223 Vector<TileCutOffInfo> getCutOffInfoList();
224 void setCutOffDistance(double distance);
226 #if ENABLE(TIZEN_WEBKIT2_MEMORY_SAVING_MODE)
227 bool memorySavingModeEnabled();
229 #if ENABLE(TIZEN_CSS_OVERFLOW_CLIPPING_BACKING_STORE)
230 FloatRect clippingBounds();
234 virtual void willBeDestroyed();
235 WebKit::WebLayerID m_id;
236 WebKit::WebLayerInfo m_layerInfo;
237 RefPtr<Image> m_image;
238 GraphicsLayer* m_maskTarget;
239 FloatRect m_needsDisplayRect;
240 GraphicsLayerTransform m_layerTransform;
241 GraphicsLayerTransform m_layerSettledTransform;
242 bool m_inUpdateMode : 1;
243 bool m_shouldUpdateVisibleRect: 1;
244 bool m_shouldSyncLayerState: 1;
245 bool m_shouldSyncChildren: 1;
246 bool m_shouldSyncFilters: 1;
247 bool m_shouldSyncAnimations: 1;
248 bool m_fixedToViewport : 1;
249 bool m_movingVisibleRect : 1;
250 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION)
251 bool m_isOverflow : 1;
253 bool m_canvasNeedsDisplay : 1;
254 #if ENABLE(TIZEN_DONT_PURGE_PLATFORM_SURFACE_BACKINGSTORE_ON_NODE_DETACH_FROM_WEBLAYER_TREE)
255 bool m_shouldSyncBackingStore : 1;
259 void didChangeAnimations();
260 void didChangeGeometry();
261 void didChangeLayerState();
262 void didChangeChildren();
263 #if ENABLE(CSS_FILTERS)
264 void didChangeFilters();
267 float m_effectiveOpacity;
268 TransformationMatrix m_effectiveTransform;
270 void createBackingStore();
272 bool selfOrAncestorHasActiveTransformAnimation();
273 bool selfOrAncestorHaveNonAffineTransforms();
274 void adjustContentsScale();
275 void computeTransformedVisibleRect();
276 void syncLayerParameters();
277 void syncAnimations();
278 void setShouldUpdateVisibleRect();
279 float effectiveContentsScale();
281 void animationStartedTimerFired(WebCore::Timer<WebGraphicsLayer>*);
282 #if ENABLE(TIZEN_DONT_PURGE_PLATFORM_SURFACE_BACKINGSTORE_ON_NODE_DETACH_FROM_WEBLAYER_TREE)
283 void syncBackingStoreIfNeeded();
286 WebKit::WebGraphicsLayerClient* m_webGraphicsLayerClient;
287 OwnPtr<WebCore::TiledBackingStore> m_mainBackingStore;
288 OwnPtr<WebCore::TiledBackingStore> m_previousBackingStore;
289 float m_contentsScale;
290 #if ENABLE(TIZEN_USE_FIXED_SCALE_ANIMATION)
291 float m_fixedAnimationScale;
294 PlatformLayer* m_canvasPlatformLayer;
295 Timer<WebGraphicsLayer> m_animationStartedTimer;
296 GraphicsLayerAnimations m_animations;
298 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_SCROLLBAR)
299 WebCore::Timer<WebGraphicsLayer> m_animationTimer;
303 WebGraphicsLayer* toWebGraphicsLayer(GraphicsLayer*);
308 #endif // WebGraphicsLayer_H