1 /* 2 * Copyright (C) 2009 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 GraphicsLayerCACF_h 27 #define GraphicsLayerCACF_h 28 29 #if USE(ACCELERATED_COMPOSITING) 30 31 #include "GraphicsLayer.h" 32 #include "GraphicsContext.h" 33 #include <wtf/RetainPtr.h> 34 35 namespace WebCore { 36 37 class WKCACFLayer; 38 39 class GraphicsLayerCACF : public GraphicsLayer { 40 public: 41 42 GraphicsLayerCACF(GraphicsLayerClient*); 43 virtual ~GraphicsLayerCACF(); 44 45 virtual void setName(const String& inName); 46 47 virtual bool setChildren(const Vector<GraphicsLayer*>&); 48 virtual void addChild(GraphicsLayer *layer); 49 virtual void addChildAtIndex(GraphicsLayer *layer, 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 54 virtual void removeFromParent(); 55 56 virtual void setPosition(const FloatPoint& inPoint); 57 virtual void setAnchorPoint(const FloatPoint3D& inPoint); 58 virtual void setSize(const FloatSize& inSize); 59 60 virtual void setTransform(const TransformationMatrix&); 61 62 virtual void setChildrenTransform(const TransformationMatrix&); 63 64 virtual void setPreserves3D(bool); 65 virtual void setMasksToBounds(bool); 66 virtual void setDrawsContent(bool); 67 68 virtual void setBackgroundColor(const Color&); 69 virtual void clearBackgroundColor(); 70 71 virtual void setContentsOpaque(bool); 72 virtual void setBackfaceVisibility(bool); 73 74 virtual void setOpacity(float opacity); 75 76 virtual void setNeedsDisplay(); 77 virtual void setNeedsDisplayInRect(const FloatRect&); 78 79 virtual void setContentsRect(const IntRect&); 80 81 virtual void setContentsToImage(Image*); 82 virtual void setContentsToMedia(PlatformLayer*); 83 84 virtual PlatformLayer* platformLayer() const; 85 86 virtual void setDebugBackgroundColor(const Color&); 87 virtual void setDebugBorder(const Color&, float borderWidth); 88 89 private: 90 void updateOpacityOnLayer(); 91 92 WKCACFLayer* primaryLayer() const { return m_transformLayer.get() ? m_transformLayer.get() : m_layer.get(); } 93 WKCACFLayer* hostLayerForSublayers() const; 94 WKCACFLayer* layerForSuperlayer() const; 95 96 bool requiresTiledLayer(const FloatSize&) const; 97 void swapFromOrToTiledLayer(bool useTiledLayer); 98 99 CompositingCoordinatesOrientation defaultContentsOrientation() const; 100 void updateSublayerList(); 101 void updateLayerPosition(); 102 void updateLayerSize(); 103 void updateAnchorPoint(); 104 void updateTransform(); 105 void updateChildrenTransform(); 106 void updateMasksToBounds(); 107 void updateContentsOpaque(); 108 void updateBackfaceVisibility(); 109 void updateLayerPreserves3D(); 110 void updateLayerDrawsContent(); 111 void updateLayerBackgroundColor(); 112 113 void updateContentsImage(); 114 void updateContentsMedia(); 115 void updateContentsRect(); 116 117 void setupContentsLayer(WKCACFLayer*); 118 WKCACFLayer* contentsLayer() const { return m_contentsLayer.get(); } 119 120 RefPtr<WKCACFLayer> m_layer; 121 RefPtr<WKCACFLayer> m_transformLayer; 122 RefPtr<WKCACFLayer> m_contentsLayer; 123 124 enum ContentsLayerPurpose { 125 NoContentsLayer = 0, 126 ContentsLayerForImage, 127 ContentsLayerForMedia 128 }; 129 130 ContentsLayerPurpose m_contentsLayerPurpose; 131 bool m_contentsLayerHasBackgroundColor : 1; 132 RetainPtr<CGImageRef> m_pendingContentsImage; 133 }; 134 135 } // namespace WebCore 136 137 #endif // USE(ACCELERATED_COMPOSITING) 138 139 #endif // GraphicsLayerCACF_h 140