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 // for hosting this GraphicsLayer in a native layer hierarchy 48 virtual NativeLayer nativeLayer() const; 49 50 virtual bool setChildren(const Vector<GraphicsLayer*>&); 51 virtual void addChild(GraphicsLayer *layer); 52 virtual void addChildAtIndex(GraphicsLayer *layer, int index); 53 virtual void addChildAbove(GraphicsLayer *layer, GraphicsLayer *sibling); 54 virtual void addChildBelow(GraphicsLayer *layer, GraphicsLayer *sibling); 55 virtual bool replaceChild(GraphicsLayer *oldChild, GraphicsLayer *newChild); 56 57 virtual void removeFromParent(); 58 59 virtual void setPosition(const FloatPoint& inPoint); 60 virtual void setAnchorPoint(const FloatPoint3D& inPoint); 61 virtual void setSize(const FloatSize& inSize); 62 63 virtual void setTransform(const TransformationMatrix&); 64 65 virtual void setChildrenTransform(const TransformationMatrix&); 66 67 virtual void setPreserves3D(bool); 68 virtual void setMasksToBounds(bool); 69 virtual void setDrawsContent(bool); 70 71 virtual void setBackgroundColor(const Color&); 72 virtual void clearBackgroundColor(); 73 74 virtual void setContentsOpaque(bool); 75 virtual void setBackfaceVisibility(bool); 76 77 virtual void setOpacity(float opacity); 78 79 virtual void setNeedsDisplay(); 80 virtual void setNeedsDisplayInRect(const FloatRect&); 81 82 virtual void setContentsRect(const IntRect&); 83 84 virtual void setContentsToImage(Image*); 85 virtual void setContentsToMedia(PlatformLayer*); 86 87 virtual PlatformLayer* platformLayer() const; 88 89 virtual void setDebugBackgroundColor(const Color&); 90 virtual void setDebugBorder(const Color&, float borderWidth); 91 92 virtual void setGeometryOrientation(CompositingCoordinatesOrientation); 93 94 void notifySyncRequired() { if (m_client) m_client->notifySyncRequired(this); } 95 96 private: 97 void updateOpacityOnLayer(); 98 99 WKCACFLayer* primaryLayer() const { return m_transformLayer.get() ? m_transformLayer.get() : m_layer.get(); } 100 WKCACFLayer* hostLayerForSublayers() const; 101 WKCACFLayer* layerForSuperlayer() const; 102 103 CompositingCoordinatesOrientation defaultContentsOrientation() const; 104 void updateSublayerList(); 105 void updateLayerPosition(); 106 void updateLayerSize(); 107 void updateAnchorPoint(); 108 void updateTransform(); 109 void updateChildrenTransform(); 110 void updateMasksToBounds(); 111 void updateContentsOpaque(); 112 void updateBackfaceVisibility(); 113 void updateLayerPreserves3D(); 114 void updateLayerDrawsContent(); 115 void updateLayerBackgroundColor(); 116 117 void updateContentsImage(); 118 void updateContentsMedia(); 119 void updateContentsRect(); 120 void updateGeometryOrientation(); 121 122 void setupContentsLayer(WKCACFLayer*); 123 WKCACFLayer* contentsLayer() const { return m_contentsLayer.get(); } 124 125 RefPtr<WKCACFLayer> m_layer; 126 RefPtr<WKCACFLayer> m_transformLayer; 127 RefPtr<WKCACFLayer> m_contentsLayer; 128 129 enum ContentsLayerPurpose { 130 NoContentsLayer = 0, 131 ContentsLayerForImage, 132 ContentsLayerForMedia 133 }; 134 135 ContentsLayerPurpose m_contentsLayerPurpose; 136 bool m_contentsLayerHasBackgroundColor : 1; 137 RetainPtr<CGImageRef> m_pendingContentsImage; 138 }; 139 140 } // namespace WebCore 141 142 #endif // USE(ACCELERATED_COMPOSITING) 143 144 #endif // GraphicsLayerCACF_h_ 145