2 * Copyright (C) 2010 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #ifndef GraphicsLayerChromium_h
32 #define GraphicsLayerChromium_h
34 #if USE(ACCELERATED_COMPOSITING)
36 #include "GraphicsContext.h"
37 #include "GraphicsLayer.h"
38 #include "OpaqueRectTrackingContentLayerDelegate.h"
40 #include <public/WebAnimationDelegate.h>
41 #include <public/WebContentLayer.h>
42 #include <public/WebImageLayer.h>
43 #include <public/WebLayer.h>
44 #include <wtf/HashMap.h>
51 class LinkHighlightClient {
53 virtual void invalidate() = 0;
54 virtual void clearCurrentGraphicsLayer() = 0;
55 virtual WebKit::WebLayer* layer() = 0;
58 virtual ~LinkHighlightClient() { }
61 class GraphicsLayerChromium : public GraphicsLayer, public GraphicsContextPainter, public WebKit::WebAnimationDelegate {
63 GraphicsLayerChromium(GraphicsLayerClient*);
64 virtual ~GraphicsLayerChromium();
66 virtual void willBeDestroyed() OVERRIDE;
68 virtual void setName(const String&);
70 virtual bool setChildren(const Vector<GraphicsLayer*>&);
71 virtual void addChild(GraphicsLayer*);
72 virtual void addChildAtIndex(GraphicsLayer*, int index);
73 virtual void addChildAbove(GraphicsLayer*, GraphicsLayer* sibling);
74 virtual void addChildBelow(GraphicsLayer*, GraphicsLayer* sibling);
75 virtual bool replaceChild(GraphicsLayer* oldChild, GraphicsLayer* newChild);
77 virtual void removeFromParent();
79 virtual void setPosition(const FloatPoint&);
80 virtual void setAnchorPoint(const FloatPoint3D&);
81 virtual void setSize(const FloatSize&);
83 virtual void setTransform(const TransformationMatrix&);
85 virtual void setChildrenTransform(const TransformationMatrix&);
87 virtual void setPreserves3D(bool);
88 virtual void setMasksToBounds(bool);
89 virtual void setDrawsContent(bool);
90 virtual void setContentsVisible(bool);
91 virtual void setMaskLayer(GraphicsLayer*);
93 virtual void setBackgroundColor(const Color&);
94 virtual void clearBackgroundColor();
96 virtual void setContentsOpaque(bool);
97 virtual void setBackfaceVisibility(bool);
99 virtual void setReplicatedByLayer(GraphicsLayer*);
101 virtual void setOpacity(float);
103 // Returns true if filter can be rendered by the compositor
104 virtual bool setFilters(const FilterOperations&);
105 void setBackgroundFilters(const FilterOperations&);
107 virtual void setNeedsDisplay();
108 virtual void setNeedsDisplayInRect(const FloatRect&);
109 virtual void setContentsNeedsDisplay();
111 virtual void setContentsRect(const IntRect&);
113 virtual void setContentsToImage(Image*);
114 virtual void setContentsToMedia(PlatformLayer*);
115 virtual void setContentsToCanvas(PlatformLayer*);
116 virtual bool hasContentsLayer() const { return m_contentsLayer; }
118 virtual bool addAnimation(const KeyframeValueList&, const IntSize& boxSize, const Animation*, const String&, double timeOffset);
119 virtual void pauseAnimation(const String& animationName, double timeOffset);
120 virtual void removeAnimation(const String& animationName);
121 virtual void suspendAnimations(double wallClockTime);
122 virtual void resumeAnimations();
124 void setLinkHighlight(LinkHighlightClient*);
125 // Next function for testing purposes.
126 LinkHighlightClient* linkHighlight() { return m_linkHighlight; }
128 virtual PlatformLayer* platformLayer() const;
130 virtual void setDebugBackgroundColor(const Color&);
131 virtual void setDebugBorder(const Color&, float borderWidth);
132 virtual void deviceOrPageScaleFactorChanged();
134 // GraphicsContextPainter implementation.
135 virtual void paint(GraphicsContext&, const IntRect& clip) OVERRIDE;
137 // WebAnimationDelegate implementation.
138 virtual void notifyAnimationStarted(double startTime) OVERRIDE;
139 virtual void notifyAnimationFinished(double finishTime) OVERRIDE;
141 WebKit::WebContentLayer* contentLayer() const { return m_layer.get(); }
143 // Exposed for tests.
144 WebKit::WebLayer* contentsLayer() const { return m_contentsLayer; }
145 float contentsScale() const;
149 void updateChildList();
150 void updateLayerPosition();
151 void updateLayerSize();
152 void updateAnchorPoint();
153 void updateTransform();
154 void updateChildrenTransform();
155 void updateMasksToBounds();
156 void updateLayerPreserves3D();
157 void updateLayerIsDrawable();
158 void updateLayerBackgroundColor();
160 void updateContentsImage();
161 void updateContentsVideo();
162 void updateContentsRect();
163 void updateContentsScale();
165 enum ContentsLayerPurpose {
167 ContentsLayerForImage,
168 ContentsLayerForVideo,
169 ContentsLayerForCanvas,
172 void setContentsTo(ContentsLayerPurpose, WebKit::WebLayer*);
173 void setupContentsLayer(WebKit::WebLayer*);
175 int mapAnimationNameToId(const String& animationName);
179 OwnPtr<WebKit::WebContentLayer> m_layer;
180 OwnPtr<WebKit::WebLayer> m_transformLayer;
181 OwnPtr<WebKit::WebImageLayer> m_imageLayer;
182 WebKit::WebLayer* m_contentsLayer;
183 // We don't have ownership of m_contentsLayer, but we do want to know if a given layer is the
184 // same as our current layer in setContentsTo(). Since m_contentsLayer may be deleted at this point,
185 // we stash an ID away when we know m_contentsLayer is alive and use that for comparisons from that point
187 int m_contentsLayerId;
189 LinkHighlightClient* m_linkHighlight;
191 OwnPtr<OpaqueRectTrackingContentLayerDelegate> m_opaqueRectTrackingContentLayerDelegate;
193 ContentsLayerPurpose m_contentsLayerPurpose;
194 bool m_contentsLayerHasBackgroundColor : 1;
195 bool m_inSetChildren;
196 bool m_pageScaleChanged;
198 typedef HashMap<String, int> AnimationIdMap;
199 AnimationIdMap m_animationIdMap;
202 } // namespace WebCore
204 #endif // USE(ACCELERATED_COMPOSITING)