| 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 | #if USE(COORDINATED_GRAPHICS) |
| 25 | |
| 26 | #include "CoordinatedGraphicsState.h" |
| 27 | #include "FloatPoint3D.h" |
| 28 | #include "GraphicsLayer.h" |
| 29 | #include "GraphicsLayerTransform.h" |
| 30 | #include "Image.h" |
| 31 | #include "IntSize.h" |
| 32 | #include "NicosiaBuffer.h" |
| 33 | #include "NicosiaPlatformLayer.h" |
| 34 | #include "TextureMapperAnimation.h" |
| 35 | #include "TransformationMatrix.h" |
| 36 | #include <wtf/RunLoop.h> |
| 37 | #include <wtf/text/StringHash.h> |
| 38 | |
| 39 | namespace Nicosia { |
| 40 | class PaintingEngine; |
| 41 | } |
| 42 | |
| 43 | namespace WebCore { |
| 44 | class CoordinatedGraphicsLayer; |
| 45 | class TextureMapperAnimations; |
| 46 | |
| 47 | class CoordinatedGraphicsLayerClient { |
| 48 | public: |
| 49 | virtual bool isFlushingLayerChanges() const = 0; |
| 50 | virtual FloatRect visibleContentsRect() const = 0; |
| 51 | virtual void detachLayer(CoordinatedGraphicsLayer*) = 0; |
| 52 | virtual void attachLayer(CoordinatedGraphicsLayer*) = 0; |
| 53 | virtual Nicosia::PaintingEngine& paintingEngine() = 0; |
| 54 | virtual void syncLayerState() = 0; |
| 55 | }; |
| 56 | |
| 57 | class WEBCORE_EXPORT CoordinatedGraphicsLayer : public GraphicsLayer { |
| 58 | public: |
| 59 | explicit CoordinatedGraphicsLayer(Type, GraphicsLayerClient&); |
| 60 | virtual ~CoordinatedGraphicsLayer(); |
| 61 | |
| 62 | // FIXME: Merge these two methods. |
| 63 | Nicosia::PlatformLayer::LayerID id() const; |
| 64 | PlatformLayerID primaryLayerID() const override; |
| 65 | |
| 66 | // Reimplementations from GraphicsLayer.h. |
| 67 | bool setChildren(Vector<Ref<GraphicsLayer>>&&) override; |
| 68 | void addChild(Ref<GraphicsLayer>&&) override; |
| 69 | void addChildAtIndex(Ref<GraphicsLayer>&&, int) override; |
| 70 | void addChildAbove(Ref<GraphicsLayer>&&, GraphicsLayer*) override; |
| 71 | void addChildBelow(Ref<GraphicsLayer>&&, GraphicsLayer*) override; |
| 72 | bool replaceChild(GraphicsLayer*, Ref<GraphicsLayer>&&) override; |
| 73 | void removeFromParent() override; |
| 74 | void setPosition(const FloatPoint&) override; |
| 75 | void setAnchorPoint(const FloatPoint3D&) override; |
| 76 | void setSize(const FloatSize&) override; |
| 77 | void setTransform(const TransformationMatrix&) override; |
| 78 | void setChildrenTransform(const TransformationMatrix&) override; |
| 79 | void setPreserves3D(bool) override; |
| 80 | void setMasksToBounds(bool) override; |
| 81 | void setDrawsContent(bool) override; |
| 82 | void setContentsVisible(bool) override; |
| 83 | void setContentsOpaque(bool) override; |
| 84 | void setBackfaceVisibility(bool) override; |
| 85 | void setOpacity(float) override; |
| 86 | void setContentsRect(const FloatRect&) override; |
| 87 | void setContentsTilePhase(const FloatSize&) override; |
| 88 | void setContentsTileSize(const FloatSize&) override; |
| 89 | void setContentsToImage(Image*) override; |
| 90 | void setContentsToSolidColor(const Color&) override; |
| 91 | void setShowDebugBorder(bool) override; |
| 92 | void setShowRepaintCounter(bool) override; |
| 93 | bool shouldDirectlyCompositeImage(Image*) const override; |
| 94 | void setContentsToPlatformLayer(PlatformLayer*, ContentsLayerPurpose) override; |
| 95 | void setMaskLayer(RefPtr<GraphicsLayer>&&) override; |
| 96 | void setReplicatedByLayer(RefPtr<GraphicsLayer>&&) override; |
| 97 | void setNeedsDisplay() override; |
| 98 | void setNeedsDisplayInRect(const FloatRect&, ShouldClipToLayer = ClipToLayer) override; |
| 99 | void setContentsNeedsDisplay() override; |
| 100 | void deviceOrPageScaleFactorChanged() override; |
| 101 | void flushCompositingState(const FloatRect&) override; |
| 102 | void flushCompositingStateForThisLayerOnly() override; |
| 103 | bool setFilters(const FilterOperations&) override; |
| 104 | bool addAnimation(const KeyframeValueList&, const FloatSize&, const Animation*, const String&, double) override; |
| 105 | void pauseAnimation(const String&, double) override; |
| 106 | void removeAnimation(const String&) override; |
| 107 | void suspendAnimations(MonotonicTime) override; |
| 108 | void resumeAnimations() override; |
| 109 | bool usesContentsLayer() const override; |
| 110 | |
| 111 | void syncPendingStateChangesIncludingSubLayers(); |
| 112 | void updateContentBuffersIncludingSubLayers(); |
| 113 | |
| 114 | FloatPoint computePositionRelativeToBase(); |
| 115 | void computePixelAlignment(FloatPoint& position, FloatSize&, FloatPoint3D& anchorPoint, FloatSize& alignmentOffset); |
| 116 | |
| 117 | IntRect transformedVisibleRect(); |
| 118 | |
| 119 | void setCoordinator(CoordinatedGraphicsLayerClient*); |
| 120 | void setCoordinatorIncludingSubLayersIfNeeded(CoordinatedGraphicsLayerClient*); |
| 121 | |
| 122 | void setNeedsVisibleRectAdjustment(); |
| 123 | void purgeBackingStores(); |
| 124 | |
| 125 | const RefPtr<Nicosia::CompositionLayer>& compositionLayer() const; |
| 126 | |
| 127 | private: |
| 128 | bool isCoordinatedGraphicsLayer() const override; |
| 129 | |
| 130 | void updatePlatformLayer(); |
| 131 | |
| 132 | void setDebugBorder(const Color&, float width) override; |
| 133 | |
| 134 | void didChangeAnimations(); |
| 135 | void didChangeGeometry(); |
| 136 | void didChangeChildren(); |
| 137 | void didChangeFilters(); |
| 138 | void didUpdateTileBuffers(); |
| 139 | |
| 140 | void computeTransformedVisibleRect(); |
| 141 | void updateContentBuffers(); |
| 142 | |
| 143 | void notifyFlushRequired(); |
| 144 | |
| 145 | bool shouldHaveBackingStore() const; |
| 146 | bool selfOrAncestorHasActiveTransformAnimation() const; |
| 147 | bool selfOrAncestorHaveNonAffineTransforms(); |
| 148 | |
| 149 | void setShouldUpdateVisibleRect(); |
| 150 | float effectiveContentsScale(); |
| 151 | |
| 152 | void animationStartedTimerFired(); |
| 153 | void requestPendingTileCreationTimerFired(); |
| 154 | |
| 155 | bool filtersCanBeComposited(const FilterOperations&) const; |
| 156 | |
| 157 | Nicosia::PlatformLayer::LayerID m_id; |
| 158 | GraphicsLayerTransform m_layerTransform; |
| 159 | TransformationMatrix m_cachedInverseTransform; |
| 160 | FloatSize m_pixelAlignmentOffset; |
| 161 | FloatSize m_adjustedSize; |
| 162 | FloatPoint m_adjustedPosition; |
| 163 | FloatPoint3D m_adjustedAnchorPoint; |
| 164 | |
| 165 | Color m_solidColor; |
| 166 | |
| 167 | #ifndef NDEBUG |
| 168 | bool m_isPurging; |
| 169 | #endif |
| 170 | bool m_shouldUpdateVisibleRect: 1; |
| 171 | bool m_movingVisibleRect : 1; |
| 172 | bool m_pendingContentsScaleAdjustment : 1; |
| 173 | bool m_pendingVisibleRectAdjustment : 1; |
| 174 | bool m_shouldUpdatePlatformLayer : 1; |
| 175 | |
| 176 | CoordinatedGraphicsLayerClient* m_coordinator; |
| 177 | |
| 178 | struct { |
| 179 | bool completeLayer { false }; |
| 180 | Vector<FloatRect, 32> rects; |
| 181 | } m_needsDisplay; |
| 182 | |
| 183 | RefPtr<Image> m_compositedImage; |
| 184 | NativeImagePtr m_compositedNativeImagePtr; |
| 185 | |
| 186 | Timer m_animationStartedTimer; |
| 187 | RunLoop::Timer<CoordinatedGraphicsLayer> m_requestPendingTileCreationTimer; |
| 188 | TextureMapperAnimations m_animations; |
| 189 | MonotonicTime m_lastAnimationStartTime; |
| 190 | |
| 191 | struct { |
| 192 | RefPtr<Nicosia::CompositionLayer> layer; |
| 193 | Nicosia::CompositionLayer::LayerState::Delta delta; |
| 194 | Nicosia::CompositionLayer::LayerState::RepaintCounter repaintCounter; |
| 195 | Nicosia::CompositionLayer::LayerState::DebugBorder debugBorder; |
| 196 | bool performLayerSync { false }; |
| 197 | |
| 198 | RefPtr<Nicosia::BackingStore> backingStore; |
| 199 | RefPtr<Nicosia::ContentLayer> contentLayer; |
| 200 | RefPtr<Nicosia::ImageBacking> imageBacking; |
| 201 | } m_nicosia; |
| 202 | }; |
| 203 | |
| 204 | } // namespace WebCore |
| 205 | |
| 206 | SPECIALIZE_TYPE_TRAITS_GRAPHICSLAYER(WebCore::CoordinatedGraphicsLayer, isCoordinatedGraphicsLayer()) |
| 207 | |
| 208 | #endif // USE(COORDINATED_GRAPHICS) |
| 209 | |
| 210 | #endif // CoordinatedGraphicsLayer_h |
| 211 | |