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 CoordinatedGraphicsLayer_h 22#define CoordinatedGraphicsLayer_h 23 24#include "CoordinatedGraphicsState.h" 25#include "CoordinatedImageBacking.h" 26#include "CoordinatedTile.h" 27#include "FloatPoint3D.h" 28#include "GraphicsLayer.h" 29#include "GraphicsLayerAnimation.h" 30#include "GraphicsLayerTransform.h" 31#include "Image.h" 32#include "IntSize.h" 33#include "RunLoop.h" 34#include "TiledBackingStore.h" 35#include "TiledBackingStoreClient.h" 36#include "TransformationMatrix.h" 37#if USE(GRAPHICS_SURFACE) 38#include "GraphicsSurfaceToken.h" 39#endif 40#include <wtf/text/StringHash.h> 41 42#if USE(COORDINATED_GRAPHICS) 43 44namespace WebCore { 45class CoordinatedGraphicsLayer; 46class GraphicsLayerAnimations; 47class ScrollableArea; 48 49class CoordinatedGraphicsLayerClient { 50public: 51 virtual bool isFlushingLayerChanges() const = 0; 52 virtual FloatRect visibleContentsRect() const = 0; 53 virtual PassRefPtr<CoordinatedImageBacking> createImageBackingIfNeeded(Image*) = 0; 54 virtual void detachLayer(CoordinatedGraphicsLayer*) = 0; 55 virtual bool paintToSurface(const IntSize&, CoordinatedSurface::Flags, uint32_t& atlasID, IntPoint&, CoordinatedSurface::Client*) = 0; 56 57 virtual void syncLayerState(CoordinatedLayerID, CoordinatedGraphicsLayerState&) = 0; 58}; 59 60class CoordinatedGraphicsLayer : public GraphicsLayer 61 , public TiledBackingStoreClient 62 , public CoordinatedImageBacking::Host 63 , public CoordinatedTileClient { 64public: 65 explicit CoordinatedGraphicsLayer(GraphicsLayerClient*); 66 virtual ~CoordinatedGraphicsLayer(); 67 68 // Reimplementations from GraphicsLayer.h. 69 virtual bool setChildren(const Vector<GraphicsLayer*>&) OVERRIDE; 70 virtual void addChild(GraphicsLayer*) OVERRIDE; 71 virtual void addChildAtIndex(GraphicsLayer*, int) OVERRIDE; 72 virtual void addChildAbove(GraphicsLayer*, GraphicsLayer*) OVERRIDE; 73 virtual void addChildBelow(GraphicsLayer*, GraphicsLayer*) OVERRIDE; 74 virtual bool replaceChild(GraphicsLayer*, GraphicsLayer*) OVERRIDE; 75 virtual void removeFromParent() OVERRIDE; 76 virtual void setPosition(const FloatPoint&) OVERRIDE; 77 virtual void setAnchorPoint(const FloatPoint3D&) OVERRIDE; 78 virtual void setSize(const FloatSize&) OVERRIDE; 79 virtual void setTransform(const TransformationMatrix&) OVERRIDE; 80 virtual void setChildrenTransform(const TransformationMatrix&) OVERRIDE; 81 virtual void setPreserves3D(bool) OVERRIDE; 82 virtual void setMasksToBounds(bool) OVERRIDE; 83 virtual void setDrawsContent(bool) OVERRIDE; 84 virtual void setContentsVisible(bool) OVERRIDE; 85 virtual void setContentsOpaque(bool) OVERRIDE; 86 virtual void setBackfaceVisibility(bool) OVERRIDE; 87 virtual void setOpacity(float) OVERRIDE; 88 virtual void setContentsRect(const IntRect&) OVERRIDE; 89 virtual void setContentsTilePhase(const IntPoint&) OVERRIDE; 90 virtual void setContentsTileSize(const IntSize&) OVERRIDE; 91 virtual void setContentsToImage(Image*) OVERRIDE; 92 virtual void setContentsToSolidColor(const Color&) OVERRIDE; 93 virtual void setShowDebugBorder(bool) OVERRIDE; 94 virtual void setShowRepaintCounter(bool) OVERRIDE; 95 virtual bool shouldDirectlyCompositeImage(Image*) const OVERRIDE; 96 virtual void setContentsToCanvas(PlatformLayer*) OVERRIDE; 97 virtual void setMaskLayer(GraphicsLayer*) OVERRIDE; 98 virtual void setReplicatedByLayer(GraphicsLayer*) OVERRIDE; 99 virtual void setNeedsDisplay() OVERRIDE; 100 virtual void setNeedsDisplayInRect(const FloatRect&) OVERRIDE; 101 virtual void setContentsNeedsDisplay() OVERRIDE; 102 virtual void deviceOrPageScaleFactorChanged() OVERRIDE; 103 virtual void flushCompositingState(const FloatRect&) OVERRIDE; 104 virtual void flushCompositingStateForThisLayerOnly() OVERRIDE; 105#if ENABLE(CSS_FILTERS) 106 virtual bool setFilters(const FilterOperations&) OVERRIDE; 107#endif 108 virtual bool addAnimation(const KeyframeValueList&, const IntSize&, const Animation*, const String&, double) OVERRIDE; 109 virtual void pauseAnimation(const String&, double) OVERRIDE; 110 virtual void removeAnimation(const String&) OVERRIDE; 111 virtual void suspendAnimations(double time) OVERRIDE; 112 virtual void resumeAnimations() OVERRIDE; 113 114 void syncPendingStateChangesIncludingSubLayers(); 115 void updateContentBuffersIncludingSubLayers(); 116 117 FloatPoint computePositionRelativeToBase(); 118 void computePixelAlignment(FloatPoint& position, FloatSize&, FloatPoint3D& anchorPoint, FloatSize& alignmentOffset); 119 120 void setVisibleContentRectTrajectoryVector(const FloatPoint&); 121 122 void setScrollableArea(ScrollableArea*); 123 bool isScrollable() const { return !!m_scrollableArea; } 124 void commitScrollOffset(const IntSize&); 125 126 CoordinatedLayerID id() const; 127 128 void setFixedToViewport(bool isFixed); 129 130 IntRect coverRect() const { return m_mainBackingStore ? m_mainBackingStore->mapToContents(m_mainBackingStore->coverRect()) : IntRect(); } 131 132 // TiledBackingStoreClient 133 virtual void tiledBackingStorePaintBegin() OVERRIDE; 134 virtual void tiledBackingStorePaint(GraphicsContext*, const IntRect&) OVERRIDE; 135 virtual void tiledBackingStorePaintEnd(const Vector<IntRect>& paintedArea) OVERRIDE; 136 virtual void tiledBackingStoreHasPendingTileCreation() OVERRIDE; 137 virtual IntRect tiledBackingStoreContentsRect() OVERRIDE; 138 virtual IntRect tiledBackingStoreVisibleRect() OVERRIDE; 139 virtual Color tiledBackingStoreBackgroundColor() const OVERRIDE; 140 141 // CoordinatedTileClient 142 virtual void createTile(uint32_t tileID, const SurfaceUpdateInfo&, const IntRect&) OVERRIDE; 143 virtual void updateTile(uint32_t tileID, const SurfaceUpdateInfo&, const IntRect&) OVERRIDE; 144 virtual void removeTile(uint32_t tileID) OVERRIDE; 145 virtual bool paintToSurface(const IntSize&, uint32_t& /* atlasID */, IntPoint&, CoordinatedSurface::Client*) OVERRIDE; 146 147 void setCoordinator(CoordinatedGraphicsLayerClient*); 148 149 void setNeedsVisibleRectAdjustment(); 150 void purgeBackingStores(); 151 bool hasPendingVisibleChanges(); 152 153 static void setShouldSupportContentsTiling(bool); 154 CoordinatedGraphicsLayer* findFirstDescendantWithContentsRecursively(); 155 156private: 157#if USE(GRAPHICS_SURFACE) 158 enum PendingCanvasOperation { 159 None = 0x00, 160 CreateCanvas = 0x01, 161 DestroyCanvas = 0x02, 162 SyncCanvas = 0x04, 163 CreateAndSyncCanvas = CreateCanvas | SyncCanvas, 164 RecreateCanvas = CreateAndSyncCanvas | DestroyCanvas 165 }; 166 167 void syncCanvas(); 168 void destroyCanvasIfNeeded(); 169 void createCanvasIfNeeded(); 170#endif 171 172 virtual void setDebugBorder(const Color&, float width) OVERRIDE; 173 174 bool fixedToViewport() const { return m_fixedToViewport; } 175 176 void didChangeLayerState(); 177 void didChangeAnimations(); 178 void didChangeGeometry(); 179 void didChangeChildren(); 180#if ENABLE(CSS_FILTERS) 181 void didChangeFilters(); 182#endif 183 void didChangeImageBacking(); 184 185 void resetLayerState(); 186 void syncLayerState(); 187 void syncAnimations(); 188 void syncChildren(); 189#if ENABLE(CSS_FILTERS) 190 void syncFilters(); 191#endif 192 void syncImageBacking(); 193 void computeTransformedVisibleRect(); 194 void updateContentBuffers(); 195 196 void createBackingStore(); 197 void releaseImageBackingIfNeeded(); 198 199 // CoordinatedImageBacking::Host 200 virtual bool imageBackingVisible() OVERRIDE; 201 bool shouldHaveBackingStore() const; 202 bool selfOrAncestorHasActiveTransformAnimation() const; 203 bool selfOrAncestorHaveNonAffineTransforms(); 204 void adjustContentsScale(); 205 206 void setShouldUpdateVisibleRect(); 207 float effectiveContentsScale(); 208 209 void animationStartedTimerFired(Timer<CoordinatedGraphicsLayer>*); 210 211 CoordinatedLayerID m_id; 212 CoordinatedGraphicsLayerState m_layerState; 213 GraphicsLayerTransform m_layerTransform; 214 TransformationMatrix m_cachedInverseTransform; 215 FloatSize m_pixelAlignmentOffset; 216 FloatSize m_adjustedSize; 217 FloatPoint m_adjustedPosition; 218 FloatPoint3D m_adjustedAnchorPoint; 219 220#ifndef NDEBUG 221 bool m_isPurging; 222#endif 223 bool m_shouldUpdateVisibleRect: 1; 224 bool m_shouldSyncLayerState: 1; 225 bool m_shouldSyncChildren: 1; 226 bool m_shouldSyncFilters: 1; 227 bool m_shouldSyncImageBacking: 1; 228 bool m_shouldSyncAnimations: 1; 229 bool m_fixedToViewport : 1; 230 bool m_movingVisibleRect : 1; 231 bool m_pendingContentsScaleAdjustment : 1; 232 bool m_pendingVisibleRectAdjustment : 1; 233#if USE(GRAPHICS_SURFACE) 234 bool m_isValidCanvas : 1; 235 unsigned m_pendingCanvasOperation : 3; 236#endif 237 238 CoordinatedGraphicsLayerClient* m_coordinator; 239 OwnPtr<TiledBackingStore> m_mainBackingStore; 240 OwnPtr<TiledBackingStore> m_previousBackingStore; 241 242 RefPtr<Image> m_compositedImage; 243 NativeImagePtr m_compositedNativeImagePtr; 244 RefPtr<CoordinatedImageBacking> m_coordinatedImageBacking; 245 246 PlatformLayer* m_canvasPlatformLayer; 247#if USE(GRAPHICS_SURFACE) 248 IntSize m_canvasSize; 249 GraphicsSurfaceToken m_canvasToken; 250#endif 251 Timer<CoordinatedGraphicsLayer> m_animationStartedTimer; 252 GraphicsLayerAnimations m_animations; 253 double m_lastAnimationStartTime; 254 255 ScrollableArea* m_scrollableArea; 256}; 257 258CoordinatedGraphicsLayer* toCoordinatedGraphicsLayer(GraphicsLayer*); 259 260} // namespace WebCore 261#endif // USE(COORDINATED_GRAPHICS) 262 263#endif // CoordinatedGraphicsLayer_h 264