2 Copyright (C) 2012 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.
20 #ifndef WebLayerTreeRenderer_h
21 #define WebLayerTreeRenderer_h
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"
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>
47 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
48 #include "DrawingAreaProxy.h"
53 class LayerBackingStore;
54 class LayerTreeCoordinatorProxy;
56 class WebLayerUpdateInfo;
58 class WebLayerTreeRenderer : public ThreadSafeRefCounted<WebLayerTreeRenderer>, public WebCore::GraphicsLayerClient {
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)
70 TileUpdate(const WebCore::IntRect& source, const WebCore::IntRect& target, PassRefPtr<ShareableSurface> newSurface, const WebCore::IntPoint& newOffset)
76 #if ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE)
77 , platformSurfaceID(pmID)
78 , platformSurfaceSize(pmSize)
83 WebLayerTreeRenderer(LayerTreeCoordinatorProxy*);
84 virtual ~WebLayerTreeRenderer();
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);
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);
97 void syncCanvas(uint32_t id, const WebCore::IntSize& canvasSize, uint64_t graphicsSurfaceToken, uint32_t frontBuffer);
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&);
109 #if ENABLE(CSS_FILTERS)
110 void setLayerFilters(WebLayerID, const WebCore::FilterOperations&);
113 void createTile(WebLayerID, int, float scale);
114 TIZEN_VIRTUAL void removeTile(WebLayerID, int);
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; }
121 TIZEN_VIRTUAL void flushLayerChanges();
123 void createImage(int64_t, PassRefPtr<ShareableBitmap>);
124 void destroyImage(int64_t);
125 void setLayerAnimations(WebLayerID, const WebCore::GraphicsLayerAnimations&);
126 void setAnimationsLocked(bool);
128 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
129 WebLayerTreeRenderer(LayerTreeCoordinatorProxy*, DrawingAreaProxy*, bool isGLMode = true);
130 TIZEN_VIRTUAL void clearBackingStores();
132 #if ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE)
133 virtual void freePlatformSurface() { }
134 virtual bool hasPlatformSurfaceToFree() { return false; }
136 virtual void updatePlatformSurfaceTile(WebLayerID, int tileID, const WebCore::IntRect& sourceRect, int platformSurfaceID, const WebCore::IntSize& pixplatformSurfaceSizemapSize) { }
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);
142 #if ENABLE(TIZEN_WEBKIT2_DIRECT_RENDERING)
143 void setAngle(int angle) { m_angle = angle; }
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&);
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&);
158 void updateViewportFired();
162 #if ENABLE(TIZEN_RUNTIME_BACKEND_SELECTION)
164 virtual void createTextureMapper();
166 PassOwnPtr<WebCore::GraphicsLayer> createLayer(WebLayerID);
168 WebCore::GraphicsLayer* layerByID(WebLayerID id) { return (id == InvalidWebLayerID) ? 0 : m_layers.get(id); }
169 WebCore::GraphicsLayer* rootLayer() { return m_rootLayer.get(); }
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();
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;
189 // Render queue can be accessed ony from main thread or updatePaintNode call stack!
190 Vector<Function<void()> > m_renderQueue;
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;
198 #if USE(GRAPHICS_SURFACE) || ENABLE(TIZEN_CANVAS_GRAPHICS_SURFACE)
199 typedef HashMap<WebLayerID, RefPtr<WebCore::TextureMapperSurfaceBackingStore> > SurfaceBackingStoreMap;
200 SurfaceBackingStoreMap m_surfaceBackingStores;
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();
217 LayerTreeCoordinatorProxy* m_layerTreeCoordinatorProxy;
218 OwnPtr<WebCore::GraphicsLayer> m_rootLayer;
219 Vector<WebLayerID> m_layersToDelete;
222 LayerMap m_fixedLayers;
223 WebLayerID m_rootLayerID;
224 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION)
225 LayerMap m_scrollingContentsLayers;
227 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION_ON_UI_SIDE)
228 WebLayerID m_focusedLayerID;
231 WebCore::IntPoint m_renderedContentsScrollPosition;
232 WebCore::IntPoint m_pendingRenderedContentsScrollPosition;
234 bool m_animationsLocked;
236 #if ENABLE(TIZEN_WEBKIT2_DIRECT_RENDERING)
240 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
241 DrawingAreaProxy* m_drawingAreaProxy;
243 #if ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE_BACKUP_IMAGE)
244 RefPtr<BitmapTexture> m_backupTexture;
250 WebCore::RunLoop::Timer<WebLayerTreeRenderer> m_updateViewportTimer;
256 #endif // USE(UI_SIDE_COMPOSITING)
258 #endif // WebLayerTreeRenderer_h