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