Merge "Use EwkView's variables instead of drawingScaleFactor and drawingScrollPositio...
[framework/web/webkit-efl.git] / Source / WebKit2 / UIProcess / WebLayerTreeRenderer.h
1 /*
2     Copyright (C) 2012 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 #ifndef WebLayerTreeRenderer_h
21 #define WebLayerTreeRenderer_h
22
23 #if USE(UI_SIDE_COMPOSITING)
24 #include "BackingStore.h"
25 #include "GraphicsSurface.h"
26 #include "ShareableSurface.h"
27 #if ENABLE(TIZEN_RUNTIME_BACKEND_SELECTION)
28 #include "SurfaceUpdateInfo.h"
29 #endif
30 #include "TextureMapper.h"
31 #include "TextureMapperBackingStore.h"
32 #include "WebLayerTreeInfo.h"
33 #include "WebPageGroup.h"
34 #include "WebPageProxy.h"
35 #include "WebPreferences.h"
36 #include <WebCore/GraphicsContext.h>
37 #include <WebCore/GraphicsLayer.h>
38 #include <WebCore/GraphicsLayerAnimation.h>
39 #include <WebCore/IntRect.h>
40 #include <WebCore/IntSize.h>
41 #include <WebCore/RunLoop.h>
42 #include <WebCore/Timer.h>
43 #include <wtf/Functional.h>
44 #include <wtf/HashSet.h>
45 #include <wtf/ThreadingPrimitives.h>
46
47 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
48 #include "DrawingAreaProxy.h"
49 #endif
50
51 namespace WebKit {
52
53 class LayerBackingStore;
54 class LayerTreeCoordinatorProxy;
55 class WebLayerInfo;
56 class WebLayerUpdateInfo;
57
58 class WebLayerTreeRenderer : public ThreadSafeRefCounted<WebLayerTreeRenderer>, public WebCore::GraphicsLayerClient {
59 public:
60     struct TileUpdate {
61         WebCore::IntRect sourceRect;
62         WebCore::IntRect targetRect;
63         RefPtr<ShareableSurface> surface;
64         WebCore::IntPoint offset;
65 #if ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE)
66         int platformSurfaceID;
67         WebCore::IntSize platformSurfaceSize;
68         TileUpdate(const WebCore::IntRect& source, const WebCore::IntRect& target, PassRefPtr<ShareableSurface> newSurface, const WebCore::IntPoint& newOffset, int pmID, WebCore::IntSize pmSize)
69 #else
70         TileUpdate(const WebCore::IntRect& source, const WebCore::IntRect& target, PassRefPtr<ShareableSurface> newSurface, const WebCore::IntPoint& newOffset)
71 #endif
72             : sourceRect(source)
73             , targetRect(target)
74             , surface(newSurface)
75             , offset(newOffset)
76 #if ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE)
77             , platformSurfaceID(pmID)
78             , platformSurfaceSize(pmSize)
79 #endif
80         {
81         }
82     };
83     WebLayerTreeRenderer(LayerTreeCoordinatorProxy*);
84     virtual ~WebLayerTreeRenderer();
85
86     TIZEN_VIRTUAL void purgeGLResources();
87     void paintToCurrentGLContext(const WebCore::TransformationMatrix&, float, const WebCore::FloatRect&, const WebCore::Color&, WebCore::TextureMapper::PaintFlags = 0);
88     void paintToGraphicsContext(BackingStore::PlatformGraphicsContext, const WebCore::Color&);
89     void syncRemoteContent();
90     void setContentsSize(const WebCore::FloatSize&);
91     void setVisibleContentsRect(const WebCore::IntRect&, float scale, const WebCore::FloatPoint& accurateVisibleContentsPosition);
92     void didChangeScrollPosition(const WebCore::IntPoint& position);
93
94 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
95     TIZEN_VIRTUAL void syncCanvas(uint32_t id, const WebCore::IntSize& canvasSize, uint64_t graphicsSurfaceToken, uint32_t frontBuffer, int flags);
96 #else
97     void syncCanvas(uint32_t id, const WebCore::IntSize& canvasSize, uint64_t graphicsSurfaceToken, uint32_t frontBuffer);
98 #endif
99
100     TIZEN_VIRTUAL void detach();
101     TIZEN_VIRTUAL void appendUpdate(const Function<void()>&);
102     void updateViewport();
103     TIZEN_VIRTUAL void setActive(bool);
104     TIZEN_VIRTUAL void deleteLayer(WebLayerID);
105     void setRootLayerID(WebLayerID);
106     void setLayerChildren(WebLayerID, const Vector<WebLayerID>&);
107     TIZEN_VIRTUAL void setLayerState(WebLayerID, const WebLayerInfo&);
108
109 #if ENABLE(CSS_FILTERS)
110     void setLayerFilters(WebLayerID, const WebCore::FilterOperations&);
111 #endif
112
113     void createTile(WebLayerID, int, float scale);
114     TIZEN_VIRTUAL void removeTile(WebLayerID, int);
115
116     void updateTile(WebLayerID, int, const TileUpdate&);
117 #if ENABLE(TIZEN_RUNTIME_BACKEND_SELECTION)
118     virtual void updateTileWithUpdateInfo(WebLayerID, int, const TileUpdate&);
119     virtual bool isUsingPlatformSurface() { return false; }
120 #endif
121     TIZEN_VIRTUAL void flushLayerChanges();
122
123     void createImage(int64_t, PassRefPtr<ShareableBitmap>);
124     void destroyImage(int64_t);
125     void setLayerAnimations(WebLayerID, const WebCore::GraphicsLayerAnimations&);
126     void setAnimationsLocked(bool);
127
128 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
129     WebLayerTreeRenderer(LayerTreeCoordinatorProxy*, DrawingAreaProxy*, bool isGLMode = true);
130     TIZEN_VIRTUAL void clearBackingStores();
131
132 #if ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE)
133     virtual void freePlatformSurface() { }
134     virtual bool hasPlatformSurfaceToFree() { return false; }
135
136     virtual void updatePlatformSurfaceTile(WebLayerID, int tileID, const WebCore::IntRect& sourceRect, int platformSurfaceID, const WebCore::IntSize& pixplatformSurfaceSizemapSize) { }
137 #endif
138 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION)
139     int scrollingContentsLayerCounts() const { return m_scrollingContentsLayers.size(); }
140     virtual void platformLayerChanged(WebCore::GraphicsLayer*, WebCore::PlatformLayer* oldPlatformLayer, WebCore::PlatformLayer* newPlatformLayer);
141 #endif
142 #if ENABLE(TIZEN_WEBKIT2_DIRECT_RENDERING)
143     void setAngle(int angle) { m_angle = angle; }
144 #endif
145 #if ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE_BACKUP_IMAGE)
146     void paintToBackupTexture(const WebCore::TransformationMatrix&, float, const WebCore::FloatRect&, const WebCore::Color&);
147     void showBackupTexture(const WebCore::TransformationMatrix&, float, const WebCore::FloatRect&);
148 #endif
149 #endif
150
151 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION_ON_UI_SIDE)
152     WebLayerID focusedLayerID() { return m_focusedLayerID; }
153     void setFocusedLayerID(const WebLayerID id) { m_focusedLayerID = id; }
154     bool setOffset(const WebLayerID, const WebCore::FloatPoint&);
155     void setVisibleContentsRectForScrollingContentsLayers(const WebCore::IntRect&);
156 #endif
157 #if PLATFORM(EFL)
158     void updateViewportFired();
159 #endif
160
161 private:
162 #if ENABLE(TIZEN_RUNTIME_BACKEND_SELECTION)
163 protected:
164     virtual void createTextureMapper();
165 #endif
166     PassOwnPtr<WebCore::GraphicsLayer> createLayer(WebLayerID);
167
168     WebCore::GraphicsLayer* layerByID(WebLayerID id) { return (id == InvalidWebLayerID) ? 0 : m_layers.get(id); }
169     WebCore::GraphicsLayer* rootLayer() { return m_rootLayer.get(); }
170
171     // Reimplementations from WebCore::GraphicsLayerClient.
172     virtual void notifyAnimationStarted(const WebCore::GraphicsLayer*, double) { }
173     virtual void notifySyncRequired(const WebCore::GraphicsLayer*) { }
174     virtual bool showDebugBorders(const WebCore::GraphicsLayer*) const { return m_drawingAreaProxy->page()->pageGroup()->preferences()->compositingBordersVisible(); }
175     virtual bool showRepaintCounter(const WebCore::GraphicsLayer*) const { return false; }
176     void paintContents(const WebCore::GraphicsLayer*, WebCore::GraphicsContext&, WebCore::GraphicsLayerPaintingPhase, const WebCore::IntRect&) { }
177     void callOnMainThread(const Function<void()>&);
178     void adjustPositionForFixedLayers();
179 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION_ON_UI_SIDE)
180     void adjustPositionForOverflowLayers();
181 #endif
182
183     typedef HashMap<WebLayerID, WebCore::GraphicsLayer*> LayerMap;
184     WebCore::FloatSize m_contentsSize;
185     WebCore::IntRect m_visibleContentsRect;
186     WebCore::FloatPoint m_accurateVisibleContentsPosition;
187     float m_contentsScale;
188
189     // Render queue can be accessed ony from main thread or updatePaintNode call stack!
190     Vector<Function<void()> > m_renderQueue;
191
192 #if USE(TEXTURE_MAPPER)
193     OwnPtr<WebCore::TextureMapper> m_textureMapper;
194     TIZEN_VIRTUAL PassRefPtr<LayerBackingStore> getBackingStore(WebLayerID);
195     HashMap<int64_t, RefPtr<WebCore::TextureMapperBackingStore> > m_directlyCompositedImages;
196     HashSet<RefPtr<LayerBackingStore> > m_backingStoresWithPendingBuffers;
197 #endif
198 #if USE(GRAPHICS_SURFACE) || ENABLE(TIZEN_CANVAS_GRAPHICS_SURFACE)
199     typedef HashMap<WebLayerID, RefPtr<WebCore::TextureMapperSurfaceBackingStore> > SurfaceBackingStoreMap;
200     SurfaceBackingStoreMap m_surfaceBackingStores;
201 #endif
202
203     void removeBackingStoreIfNeeded(WebLayerID);
204     void scheduleWebViewUpdate();
205     void synchronizeViewport();
206     void assignImageToLayer(WebCore::GraphicsLayer*, int64_t imageID);
207     void ensureRootLayer();
208     void ensureLayer(WebLayerID);
209     void commitTileOperations();
210     void syncAnimations();
211     TIZEN_VIRTUAL void renderNextFrame();
212     TIZEN_VIRTUAL void purgeBackingStores();
213 #if ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE)
214     void clearPlatformLayerPlatformSurfaces();
215 #endif
216
217     LayerTreeCoordinatorProxy* m_layerTreeCoordinatorProxy;
218     OwnPtr<WebCore::GraphicsLayer> m_rootLayer;
219     Vector<WebLayerID> m_layersToDelete;
220
221     LayerMap m_layers;
222     LayerMap m_fixedLayers;
223     WebLayerID m_rootLayerID;
224 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION)
225     LayerMap m_scrollingContentsLayers;
226 #endif
227 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION_ON_UI_SIDE)
228     WebLayerID m_focusedLayerID;
229 #endif
230
231     WebCore::IntPoint m_renderedContentsScrollPosition;
232     WebCore::IntPoint m_pendingRenderedContentsScrollPosition;
233     bool m_isActive;
234     bool m_animationsLocked;
235
236 #if ENABLE(TIZEN_WEBKIT2_DIRECT_RENDERING)
237     int m_angle;
238 #endif
239
240 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
241     DrawingAreaProxy* m_drawingAreaProxy;
242
243 #if ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE_BACKUP_IMAGE)
244     RefPtr<BitmapTexture> m_backupTexture;
245 #endif
246
247     bool m_isGLMode;
248 #endif
249 #if PLATFORM(EFL)
250     WebCore::RunLoop::Timer<WebLayerTreeRenderer> m_updateViewportTimer;
251 #endif
252 };
253
254 };
255
256 #endif // USE(UI_SIDE_COMPOSITING)
257
258 #endif // WebLayerTreeRenderer_h