1 /* 2 * Copyright (C) 2010 Apple Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 26 #ifndef PlatformCALayer_h 27 #define PlatformCALayer_h 28 29 #if USE(ACCELERATED_COMPOSITING) 30 31 #include "GraphicsContext.h" 32 #include "PlatformCAAnimation.h" 33 #include "PlatformCALayerClient.h" 34 #include "PlatformString.h" 35 #include <wtf/HashMap.h> 36 #include <wtf/PassRefPtr.h> 37 #include <wtf/RefCounted.h> 38 #include <wtf/RetainPtr.h> 39 #include <wtf/Vector.h> 40 #include <wtf/text/StringHash.h> 41 42 namespace WebCore { 43 44 class PlatformCALayer; 45 46 typedef Vector<RefPtr<PlatformCALayer> > PlatformCALayerList; 47 48 class PlatformCALayer : public RefCounted<PlatformCALayer> { 49 public: 50 // LayerTypeRootLayer is used on some platforms. It has no backing store, so setNeedsDisplay 51 // should not call CACFLayerSetNeedsDisplay, but rather just notify the renderer that it 52 // has changed and should be re-rendered. 53 enum LayerType { LayerTypeLayer, LayerTypeWebLayer, LayerTypeTransformLayer, LayerTypeWebTiledLayer, LayerTypeRootLayer, LayerTypeCustom }; 54 enum FilterType { Linear, Nearest, Trilinear }; 55 56 static PassRefPtr<PlatformCALayer> create(LayerType, PlatformCALayerClient*); 57 58 // This function passes the layer as a void* rather than a PlatformLayer because PlatformLayer 59 // is defined differently for Obj C and C++. This allows callers from both languages. 60 static PassRefPtr<PlatformCALayer> create(void* platformLayer, PlatformCALayerClient*); 61 62 ~PlatformCALayer(); 63 64 // This function passes the layer as a void* rather than a PlatformLayer because PlatformLayer 65 // is defined differently for Obj C and C++. This allows callers from both languages. 66 static PlatformCALayer* platformCALayer(void* platformLayer); 67 68 PlatformLayer* platformLayer() const; 69 70 PlatformCALayer* rootLayer() const; 71 72 static bool isValueFunctionSupported(); 73 owner()74 PlatformCALayerClient* owner() const { return m_owner; } 75 void setOwner(PlatformCALayerClient*); 76 animationStarted(CFTimeInterval beginTime)77 void animationStarted(CFTimeInterval beginTime) 78 { 79 if (m_owner) 80 m_owner->platformCALayerAnimationStarted(beginTime); 81 } 82 83 // Layout support 84 void setNeedsLayout(); 85 86 87 void setNeedsDisplay(const FloatRect* dirtyRect = 0); 88 89 // This tells the layer tree to commit changes and perform a render, without do a setNeedsDisplay on any layer. 90 void setNeedsCommit(); 91 92 void setContentsChanged(); 93 layerType()94 LayerType layerType() const { return m_layerType; } 95 96 PlatformCALayer* superlayer() const; 97 void removeFromSuperlayer(); 98 void setSublayers(const PlatformCALayerList&); 99 void removeAllSublayers(); 100 void appendSublayer(PlatformCALayer*); 101 void insertSublayer(PlatformCALayer*, size_t index); 102 void replaceSublayer(PlatformCALayer* reference, PlatformCALayer*); 103 size_t sublayerCount() const; 104 105 // This method removes the sublayers from the source and reparents them to the current layer. 106 // Any sublayers previously in the current layer are removed. 107 void adoptSublayers(PlatformCALayer* source); 108 109 void addAnimationForKey(const String& key, PlatformCAAnimation* animation); 110 void removeAnimationForKey(const String& key); 111 PassRefPtr<PlatformCAAnimation> animationForKey(const String& key); 112 113 PlatformCALayer* mask() const; 114 void setMask(PlatformCALayer*); 115 116 bool isOpaque() const; 117 void setOpaque(bool); 118 119 FloatRect bounds() const; 120 void setBounds(const FloatRect&); 121 122 FloatPoint3D position() const; 123 void setPosition(const FloatPoint3D&); setPosition(const FloatPoint & pos)124 void setPosition(const FloatPoint& pos) { setPosition(FloatPoint3D(pos.x(), pos.y(), 0)); } 125 126 FloatPoint3D anchorPoint() const; 127 void setAnchorPoint(const FloatPoint3D&); 128 129 TransformationMatrix transform() const; 130 void setTransform(const TransformationMatrix&); 131 132 TransformationMatrix sublayerTransform() const; 133 void setSublayerTransform(const TransformationMatrix&); 134 135 TransformationMatrix contentsTransform() const; 136 void setContentsTransform(const TransformationMatrix&); 137 138 bool isHidden() const; 139 void setHidden(bool); 140 141 bool isGeometryFlipped() const; 142 void setGeometryFlipped(bool); 143 144 bool isDoubleSided() const; 145 void setDoubleSided(bool); 146 147 bool masksToBounds() const; 148 void setMasksToBounds(bool); 149 150 bool acceleratesDrawing() const; 151 void setAcceleratesDrawing(bool); 152 153 CFTypeRef contents() const; 154 void setContents(CFTypeRef); 155 156 FloatRect contentsRect() const; 157 void setContentsRect(const FloatRect&); 158 159 void setMinificationFilter(FilterType); 160 void setMagnificationFilter(FilterType); 161 162 Color backgroundColor() const; 163 void setBackgroundColor(const Color&); 164 165 float borderWidth() const; 166 void setBorderWidth(float); 167 168 Color borderColor() const; 169 void setBorderColor(const Color&); 170 171 float opacity() const; 172 void setOpacity(float); 173 174 String name() const; 175 void setName(const String&); 176 177 FloatRect frame() const; 178 void setFrame(const FloatRect&); 179 180 float speed() const; 181 void setSpeed(float); 182 183 CFTimeInterval timeOffset() const; 184 void setTimeOffset(CFTimeInterval); 185 186 float contentsScale() const; 187 void setContentsScale(float); 188 189 #if PLATFORM(WIN) && !defined(NDEBUG) 190 void printTree() const; 191 #endif 192 193 protected: 194 PlatformCALayer(LayerType, PlatformLayer*, PlatformCALayerClient*); 195 196 private: 197 PlatformCALayerClient* m_owner; 198 LayerType m_layerType; 199 200 #if PLATFORM(MAC) || PLATFORM(WIN) 201 RetainPtr<PlatformLayer> m_layer; 202 #endif 203 204 #if PLATFORM(WIN) 205 HashMap<String, RefPtr<PlatformCAAnimation> > m_animations; 206 #endif 207 208 #if PLATFORM(MAC) 209 #ifdef __OBJC__ 210 RetainPtr<NSObject> m_delegate; 211 #else 212 RetainPtr<void> m_delegate; 213 #endif 214 #endif 215 }; 216 217 } 218 219 #endif // USE(ACCELERATED_COMPOSITING) 220 221 #endif // PlatformCALayer_h 222