| 1 | /* |
| 2 | Copyright (C) 2009 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 GraphicsLayerTextureMapper_h |
| 21 | #define GraphicsLayerTextureMapper_h |
| 22 | |
| 23 | #if !USE(COORDINATED_GRAPHICS) |
| 24 | |
| 25 | #include "GraphicsLayer.h" |
| 26 | #include "GraphicsLayerClient.h" |
| 27 | #include "Image.h" |
| 28 | #include "TextureMapperLayer.h" |
| 29 | #include "TextureMapperPlatformLayer.h" |
| 30 | #include "TextureMapperTiledBackingStore.h" |
| 31 | |
| 32 | namespace WebCore { |
| 33 | |
| 34 | class GraphicsLayerTextureMapper final : public GraphicsLayer, TextureMapperPlatformLayer::Client { |
| 35 | public: |
| 36 | explicit GraphicsLayerTextureMapper(Type, GraphicsLayerClient&); |
| 37 | virtual ~GraphicsLayerTextureMapper(); |
| 38 | |
| 39 | void setID(uint32_t id) { m_layer.setID(id); } |
| 40 | |
| 41 | // GraphicsLayer |
| 42 | bool setChildren(Vector<Ref<GraphicsLayer>>&&) override; |
| 43 | void addChild(Ref<GraphicsLayer>&&) override; |
| 44 | void addChildAtIndex(Ref<GraphicsLayer>&&, int index) override; |
| 45 | void addChildAbove(Ref<GraphicsLayer>&&, GraphicsLayer* sibling) override; |
| 46 | void addChildBelow(Ref<GraphicsLayer>&&, GraphicsLayer* sibling) override; |
| 47 | bool replaceChild(GraphicsLayer* oldChild, Ref<GraphicsLayer>&& newChild) override; |
| 48 | |
| 49 | void setMaskLayer(RefPtr<GraphicsLayer>&&) override; |
| 50 | void setReplicatedByLayer(RefPtr<GraphicsLayer>&&) override; |
| 51 | void setPosition(const FloatPoint&) override; |
| 52 | void setAnchorPoint(const FloatPoint3D&) override; |
| 53 | void setSize(const FloatSize&) override; |
| 54 | void setTransform(const TransformationMatrix&) override; |
| 55 | void setChildrenTransform(const TransformationMatrix&) override; |
| 56 | void setPreserves3D(bool) override; |
| 57 | void setMasksToBounds(bool) override; |
| 58 | void setDrawsContent(bool) override; |
| 59 | void setContentsVisible(bool) override; |
| 60 | void setContentsOpaque(bool) override; |
| 61 | void setBackfaceVisibility(bool) override; |
| 62 | void setOpacity(float) override; |
| 63 | bool setFilters(const FilterOperations&) override; |
| 64 | |
| 65 | void setNeedsDisplay() override; |
| 66 | void setNeedsDisplayInRect(const FloatRect&, ShouldClipToLayer = ClipToLayer) override; |
| 67 | void setContentsNeedsDisplay() override; |
| 68 | void setContentsRect(const FloatRect&) override; |
| 69 | |
| 70 | bool addAnimation(const KeyframeValueList&, const FloatSize&, const Animation*, const String&, double) override; |
| 71 | void pauseAnimation(const String&, double) override; |
| 72 | void removeAnimation(const String&) override; |
| 73 | |
| 74 | void setContentsToImage(Image*) override; |
| 75 | void setContentsToSolidColor(const Color&) override; |
| 76 | void setContentsToPlatformLayer(PlatformLayer*, ContentsLayerPurpose) override; |
| 77 | bool usesContentsLayer() const override { return m_contentsLayer; } |
| 78 | PlatformLayer* platformLayer() const override { return m_contentsLayer; } |
| 79 | |
| 80 | void setShowDebugBorder(bool) override; |
| 81 | void setDebugBorder(const Color&, float width) override; |
| 82 | void setShowRepaintCounter(bool) override; |
| 83 | |
| 84 | void flushCompositingState(const FloatRect&) override; |
| 85 | void flushCompositingStateForThisLayerOnly() override; |
| 86 | |
| 87 | void updateBackingStoreIncludingSubLayers(); |
| 88 | |
| 89 | TextureMapperLayer& layer() { return m_layer; } |
| 90 | |
| 91 | Color debugBorderColor() const { return m_debugBorderColor; } |
| 92 | float debugBorderWidth() const { return m_debugBorderWidth; } |
| 93 | |
| 94 | private: |
| 95 | // GraphicsLayer |
| 96 | bool isGraphicsLayerTextureMapper() const override { return true; } |
| 97 | |
| 98 | // TextureMapperPlatformLayer::Client |
| 99 | void platformLayerWillBeDestroyed() override { setContentsToPlatformLayer(0, ContentsLayerPurpose::None); } |
| 100 | void setPlatformLayerNeedsDisplay() override { setContentsNeedsDisplay(); } |
| 101 | |
| 102 | void commitLayerChanges(); |
| 103 | void updateDebugBorderAndRepaintCount(); |
| 104 | void updateBackingStoreIfNeeded(); |
| 105 | void prepareBackingStoreIfNeeded(); |
| 106 | bool shouldHaveBackingStore() const; |
| 107 | |
| 108 | bool filtersCanBeComposited(const FilterOperations&) const; |
| 109 | |
| 110 | // This set of flags help us defer which properties of the layer have been |
| 111 | // modified by the compositor, so we can know what to look for in the next flush. |
| 112 | enum ChangeMask { |
| 113 | NoChanges = 0, |
| 114 | |
| 115 | ChildrenChange = (1L << 1), |
| 116 | MaskLayerChange = (1L << 2), |
| 117 | ReplicaLayerChange = (1L << 3), |
| 118 | |
| 119 | ContentChange = (1L << 4), |
| 120 | ContentsRectChange = (1L << 5), |
| 121 | ContentsVisibleChange = (1L << 6), |
| 122 | ContentsOpaqueChange = (1L << 7), |
| 123 | |
| 124 | PositionChange = (1L << 8), |
| 125 | AnchorPointChange = (1L << 9), |
| 126 | SizeChange = (1L << 10), |
| 127 | TransformChange = (1L << 11), |
| 128 | ChildrenTransformChange = (1L << 12), |
| 129 | Preserves3DChange = (1L << 13), |
| 130 | |
| 131 | MasksToBoundsChange = (1L << 14), |
| 132 | DrawsContentChange = (1L << 15), |
| 133 | OpacityChange = (1L << 16), |
| 134 | BackfaceVisibilityChange = (1L << 17), |
| 135 | |
| 136 | BackingStoreChange = (1L << 18), |
| 137 | DisplayChange = (1L << 19), |
| 138 | ContentsDisplayChange = (1L << 20), |
| 139 | BackgroundColorChange = (1L << 21), |
| 140 | |
| 141 | AnimationChange = (1L << 22), |
| 142 | FilterChange = (1L << 23), |
| 143 | |
| 144 | DebugVisualsChange = (1L << 24), |
| 145 | RepaintCountChange = (1L << 25), |
| 146 | |
| 147 | AnimationStarted = (1L << 26), |
| 148 | }; |
| 149 | void notifyChange(ChangeMask); |
| 150 | |
| 151 | TextureMapperLayer m_layer; |
| 152 | RefPtr<TextureMapperTiledBackingStore> m_compositedImage; |
| 153 | NativeImagePtr m_compositedNativeImagePtr; |
| 154 | RefPtr<TextureMapperTiledBackingStore> m_backingStore; |
| 155 | |
| 156 | int m_changeMask; |
| 157 | bool m_needsDisplay; |
| 158 | Color m_solidColor; |
| 159 | |
| 160 | Color m_debugBorderColor; |
| 161 | float m_debugBorderWidth; |
| 162 | |
| 163 | TextureMapperPlatformLayer* m_contentsLayer; |
| 164 | FloatRect m_needsDisplayRect; |
| 165 | TextureMapperAnimations m_animations; |
| 166 | MonotonicTime m_animationStartTime; |
| 167 | }; |
| 168 | |
| 169 | } // namespace WebCore |
| 170 | |
| 171 | SPECIALIZE_TYPE_TRAITS_GRAPHICSLAYER(WebCore::GraphicsLayerTextureMapper, isGraphicsLayerTextureMapper()) |
| 172 | |
| 173 | #endif |
| 174 | |
| 175 | #endif // GraphicsLayerTextureMapper_h |
| 176 | |