OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (c) 2010, Google 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 are |
| 6 * met: |
| 7 * |
| 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 |
| 13 * distribution. |
| 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. |
| 17 * |
| 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. |
| 29 */ |
| 30 |
| 31 |
| 32 #ifndef LayerSkia_h |
| 33 #define LayerSkia_h |
| 34 |
| 35 #if USE(ACCELERATED_COMPOSITING) |
| 36 |
| 37 #include "StringHash.h" |
| 38 |
| 39 #include <wtf/RefCounted.h> |
| 40 |
| 41 #include <wtf/PassRefPtr.h> |
| 42 #include <wtf/Vector.h> |
| 43 |
| 44 #include "GraphicsContext.h" |
| 45 #include "GraphicsLayerSkia.h" |
| 46 #include "PlatformString.h" |
| 47 #include "TransformationMatrix.h" |
| 48 |
| 49 #include "SkPoint.h" |
| 50 #include "SkColor.h" |
| 51 |
| 52 namespace skia { |
| 53 class PlatformCanvas; |
| 54 } |
| 55 |
| 56 namespace WebCore { |
| 57 |
| 58 class LayerSkia : public RefCounted<LayerSkia> { |
| 59 public: |
| 60 enum LayerType { Layer, TransformLayer }; |
| 61 enum FilterType { Linear, Nearest, Trilinear, Lanczos }; |
| 62 enum ContentsGravityType { Center, Top, Bottom, Left, Right, TopLeft, TopRig
ht, |
| 63 BottomLeft, BottomRight, Resize, ResizeAspect, Re
sizeAspectFill }; |
| 64 |
| 65 static PassRefPtr<LayerSkia> create(LayerType, GraphicsLayerSkia* owner = 0)
; |
| 66 |
| 67 ~LayerSkia(); |
| 68 |
| 69 void display(PlatformGraphicsContext*); |
| 70 |
| 71 void addSublayer(PassRefPtr<LayerSkia> sublayer); |
| 72 void insertSublayer(PassRefPtr<LayerSkia>, size_t index); |
| 73 void replaceSublayer(LayerSkia* reference, PassRefPtr<LayerSkia>); |
| 74 void removeFromSuperlayer(); |
| 75 |
| 76 LayerSkia* ancestorOrSelfWithSuperlayer(LayerSkia*) const; |
| 77 |
| 78 void setAnchorPoint(const SkPoint& anchorPoint) { m_anchorPoint = anchorPoin
t; setNeedsCommit(); } |
| 79 SkPoint anchorPoint() const { return m_anchorPoint; } |
| 80 |
| 81 void setAnchorPointZ(float anchorPointZ) { m_anchorPointZ = anchorPointZ; se
tNeedsCommit(); } |
| 82 float anchorPointZ() const { return m_anchorPointZ; } |
| 83 |
| 84 void setBackgroundColor(Color color) { m_backgroundColor = color; setNeedsCo
mmit(); } |
| 85 Color backgroundColor() const { return m_backgroundColor; } |
| 86 |
| 87 void setBorderColor(const Color& color) { m_borderColor = color; } |
| 88 Color borderColor() const { return m_borderColor; } |
| 89 |
| 90 void setBorderWidth(float width) { m_borderWidth = width; } |
| 91 SkScalar borderWidth() const { return m_borderWidth; } |
| 92 |
| 93 void setBounds(const SkIRect&); |
| 94 SkIRect bounds() const { return m_bounds; } |
| 95 |
| 96 void setClearsContext(bool clears) { m_clearsContext = clears; setNeedsCommi
t(); } |
| 97 bool clearsContext() const { return m_clearsContext; } |
| 98 |
| 99 void setContentsGravity(ContentsGravityType gravityType) { m_contentsGravity
= gravityType; setNeedsCommit(); } |
| 100 ContentsGravityType contentsGravity() const { return m_contentsGravity; } |
| 101 |
| 102 void setDoubleSided(bool doubleSided) { m_doubleSided = doubleSided; setNeed
sCommit(); } |
| 103 bool doubleSided() const { return m_doubleSided; } |
| 104 |
| 105 void setEdgeAntialiasingMask(uint32_t mask) { m_edgeAntialiasingMask = mask;
setNeedsCommit(); } |
| 106 uint32_t edgeAntialiasingMask() const { return m_edgeAntialiasingMask; } |
| 107 |
| 108 void setFrame(const SkRect&); |
| 109 SkRect frame() const { return m_frame; } |
| 110 |
| 111 void setHidden(bool hidden) { m_hidden = hidden; setNeedsCommit(); } |
| 112 bool isHidden() const { return m_hidden; } |
| 113 |
| 114 void setMasksToBounds(bool masksToBounds) { m_masksToBounds = masksToBounds;
} |
| 115 bool masksToBounds() const { return m_masksToBounds; } |
| 116 |
| 117 void setName(const String& name) { m_name = name; } |
| 118 String name() const { return m_name; } |
| 119 |
| 120 void setNeedsDisplay(const SkRect& dirtyRect); |
| 121 void setNeedsDisplay(); |
| 122 |
| 123 void setNeedsDisplayOnBoundsChange(bool needsDisplay) { m_needsDisplayOnBoun
dsChange = needsDisplay; } |
| 124 |
| 125 void setOpacity(float opacity) { m_opacity = opacity; setNeedsCommit(); } |
| 126 float opacity() const { return m_opacity; } |
| 127 |
| 128 void setOpaque(bool opaque) { m_opaque = opaque; setNeedsCommit(); } |
| 129 bool opaque() const { return m_opaque; } |
| 130 |
| 131 void setPosition(const SkPoint& position) { |
| 132 m_position = position; setNeedsCommit(); } |
| 133 |
| 134 SkPoint position() const { return m_position; } |
| 135 |
| 136 void setZPosition(float zPosition) { m_zPosition = zPosition; setNeedsCommit
(); } |
| 137 SkScalar zPosition() const { return m_zPosition; } |
| 138 |
| 139 LayerSkia* rootLayer() const; |
| 140 |
| 141 void removeAllSublayers(); |
| 142 |
| 143 void setSublayers(const Vector<RefPtr<LayerSkia> >&); |
| 144 |
| 145 const Vector<RefPtr<LayerSkia>>& getSublayers() const { return m_sublayers;
} |
| 146 |
| 147 void setSublayerTransform(const SkMatrix& transform) { m_sublayerTransform =
transform; setNeedsCommit(); } |
| 148 SkMatrix sublayerTransform() const { return m_sublayerTransform; } |
| 149 |
| 150 void setSuperlayer(LayerSkia* superlayer); |
| 151 LayerSkia* superlayer() const; |
| 152 |
| 153 |
| 154 void setTransform(const SkMatrix& transform) { m_transform = transform; setN
eedsCommit(); } |
| 155 SkMatrix transform() const { return m_transform; } |
| 156 |
| 157 void setGeometryFlipped(bool flipped) { m_geometryFlipped = flipped; setNeed
sCommit(); } |
| 158 bool geometryFlipped() const { return m_geometryFlipped; } |
| 159 |
| 160 void updateContents(); |
| 161 |
| 162 skia::PlatformCanvas* platformCanvas() { return m_canvas; } |
| 163 GraphicsContext* graphicsContext() { return m_graphicsContext; } |
| 164 |
| 165 void setBackingStoreRect(const SkIRect& rect); |
| 166 |
| 167 private: |
| 168 LayerSkia(LayerType, GraphicsLayerSkia* owner); |
| 169 |
| 170 void setNeedsCommit(); |
| 171 |
| 172 void paintMe(); |
| 173 |
| 174 size_t numSublayers() const |
| 175 { |
| 176 return m_sublayers.size(); |
| 177 } |
| 178 |
| 179 // Returns the index of the passed layer in this layer's sublayers list |
| 180 // or -1 if not found |
| 181 int indexOfSublayer(const LayerSkia*); |
| 182 |
| 183 // This should only be called from removeFromSuperlayer. |
| 184 void removeSublayer(LayerSkia*); |
| 185 |
| 186 // Re-created the canvas and graphics context. This method |
| 187 // must be called every time the layer is resized. |
| 188 void updateGraphicsContext(const SkIRect& rect); |
| 189 |
| 190 Vector< RefPtr<LayerSkia> > m_sublayers; |
| 191 LayerSkia* m_superlayer; |
| 192 |
| 193 bool m_needsDisplayOnBoundsChange; |
| 194 GraphicsLayerSkia* m_owner; |
| 195 |
| 196 skia::PlatformCanvas* m_canvas; |
| 197 PlatformContextSkia* m_skiaContext; |
| 198 GraphicsContext* m_graphicsContext; |
| 199 Color m_borderColor; |
| 200 float m_borderWidth; |
| 201 |
| 202 LayerType m_layerType; |
| 203 |
| 204 SkIRect m_bounds; |
| 205 SkIRect m_backingStoreRect; |
| 206 SkPoint m_position; |
| 207 SkPoint m_anchorPoint; |
| 208 float m_anchorPointZ; |
| 209 Color m_backgroundColor; |
| 210 bool m_clearsContext; |
| 211 bool m_doubleSided; |
| 212 uint32_t m_edgeAntialiasingMask; |
| 213 SkRect m_frame; |
| 214 bool m_hidden; |
| 215 bool m_masksToBounds; |
| 216 ContentsGravityType m_contentsGravity; |
| 217 float m_opacity; |
| 218 bool m_opaque; |
| 219 float m_zPosition; |
| 220 bool m_geometryFlipped; |
| 221 String m_name; |
| 222 |
| 223 SkMatrix m_transform; |
| 224 SkMatrix m_sublayerTransform; |
| 225 }; |
| 226 |
| 227 } |
| 228 |
| 229 #endif // USE(ACCELERATED_COMPOSITING) |
| 230 |
| 231 #endif // WKCACFLayer_h |
OLD | NEW |