| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2006, 2007, 2008, 2011 Apple Inc. All rights reserved. | |
| 3 * Copyright (C) 2007 Alp Toker <alp@atoker.com> | |
| 4 * Copyright (C) 2008 Torch Mobile, Inc. | |
| 5 * Copyright (C) 2013 Google Inc. All rights reserved. | |
| 6 * | |
| 7 * Redistribution and use in source and binary forms, with or without | |
| 8 * modification, are permitted provided that the following conditions | |
| 9 * are met: | |
| 10 * 1. Redistributions of source code must retain the above copyright | |
| 11 * notice, this list of conditions and the following disclaimer. | |
| 12 * 2. Redistributions in binary form must reproduce the above copyright | |
| 13 * notice, this list of conditions and the following disclaimer in the | |
| 14 * documentation and/or other materials provided with the distribution. | |
| 15 * | |
| 16 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY | |
| 17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
| 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
| 19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | |
| 20 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
| 21 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
| 22 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
| 23 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | |
| 24 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 27 */ | |
| 28 | |
| 29 #ifndef Gradient_h | |
| 30 #define Gradient_h | |
| 31 | |
| 32 #include "platform/geometry/FloatPoint.h" | |
| 33 #include "platform/graphics/GraphicsTypes.h" | |
| 34 #include "platform/transforms/AffineTransform.h" | |
| 35 #include "wtf/PassRefPtr.h" | |
| 36 #include "wtf/RefCounted.h" | |
| 37 #include "wtf/RefPtr.h" | |
| 38 #include "wtf/Vector.h" | |
| 39 | |
| 40 class SkShader; | |
| 41 | |
| 42 namespace WebCore { | |
| 43 | |
| 44 class Color; | |
| 45 class FloatRect; | |
| 46 class IntSize; | |
| 47 | |
| 48 class Gradient : public RefCounted<Gradient> { | |
| 49 public: | |
| 50 static PassRefPtr<Gradient> create(const FloatPoint& p0, const FloatPoint& p
1) | |
| 51 { | |
| 52 return adoptRef(new Gradient(p0, p1)); | |
| 53 } | |
| 54 static PassRefPtr<Gradient> create(const FloatPoint& p0, float r0, const Flo
atPoint& p1, float r1, float aspectRatio = 1) | |
| 55 { | |
| 56 return adoptRef(new Gradient(p0, r0, p1, r1, aspectRatio)); | |
| 57 } | |
| 58 ~Gradient(); | |
| 59 | |
| 60 struct ColorStop { | |
| 61 float stop; | |
| 62 float red; | |
| 63 float green; | |
| 64 float blue; | |
| 65 float alpha; | |
| 66 | |
| 67 ColorStop() : stop(0), red(0), green(0), blue(0), alpha(0) { } | |
| 68 ColorStop(float s, float r, float g, float b, float a) : stop(s), red(r)
, green(g), blue(b), alpha(a) { } | |
| 69 }; | |
| 70 void addColorStop(const ColorStop&); | |
| 71 void addColorStop(float, const Color&); | |
| 72 | |
| 73 bool hasAlpha() const; | |
| 74 | |
| 75 bool isRadial() const { return m_radial; } | |
| 76 bool isZeroSize() const { return m_p0.x() == m_p1.x() && m_p0.y() == m_p1.y(
) && (!m_radial || m_r0 == m_r1); } | |
| 77 | |
| 78 const FloatPoint& p0() const { return m_p0; } | |
| 79 const FloatPoint& p1() const { return m_p1; } | |
| 80 | |
| 81 void setP0(const FloatPoint& p) | |
| 82 { | |
| 83 if (m_p0 == p) | |
| 84 return; | |
| 85 | |
| 86 m_p0 = p; | |
| 87 } | |
| 88 | |
| 89 void setP1(const FloatPoint& p) | |
| 90 { | |
| 91 if (m_p1 == p) | |
| 92 return; | |
| 93 | |
| 94 m_p1 = p; | |
| 95 } | |
| 96 | |
| 97 float startRadius() const { return m_r0; } | |
| 98 float endRadius() const { return m_r1; } | |
| 99 | |
| 100 void setStartRadius(float r) | |
| 101 { | |
| 102 if (m_r0 == r) | |
| 103 return; | |
| 104 | |
| 105 m_r0 = r; | |
| 106 } | |
| 107 | |
| 108 void setEndRadius(float r) | |
| 109 { | |
| 110 if (m_r1 == r) | |
| 111 return; | |
| 112 | |
| 113 m_r1 = r; | |
| 114 } | |
| 115 | |
| 116 float aspectRatio() const { return m_aspectRatio; } | |
| 117 | |
| 118 SkShader* shader(); | |
| 119 | |
| 120 void setStopsSorted(bool s) { m_stopsSorted = s; } | |
| 121 | |
| 122 void setDrawsInPMColorSpace(bool drawInPMColorSpace); | |
| 123 | |
| 124 void setSpreadMethod(GradientSpreadMethod); | |
| 125 GradientSpreadMethod spreadMethod() { return m_spreadMethod; } | |
| 126 void setGradientSpaceTransform(const AffineTransform& gradientSpaceTransform
ation); | |
| 127 AffineTransform gradientSpaceTransform() { return m_gradientSpaceTransformat
ion; } | |
| 128 | |
| 129 private: | |
| 130 Gradient(const FloatPoint& p0, const FloatPoint& p1); | |
| 131 Gradient(const FloatPoint& p0, float r0, const FloatPoint& p1, float r1, flo
at aspectRatio); | |
| 132 | |
| 133 void destroyShader(); | |
| 134 | |
| 135 void sortStopsIfNecessary(); | |
| 136 | |
| 137 // Keep any parameters relevant to rendering in sync with the structure in G
radient::hash(). | |
| 138 bool m_radial; | |
| 139 FloatPoint m_p0; | |
| 140 FloatPoint m_p1; | |
| 141 float m_r0; | |
| 142 float m_r1; | |
| 143 float m_aspectRatio; // For elliptical gradient, width / height. | |
| 144 mutable Vector<ColorStop, 2> m_stops; | |
| 145 mutable bool m_stopsSorted; | |
| 146 GradientSpreadMethod m_spreadMethod; | |
| 147 AffineTransform m_gradientSpaceTransformation; | |
| 148 | |
| 149 bool m_drawInPMColorSpace; | |
| 150 | |
| 151 RefPtr<SkShader> m_gradient; | |
| 152 }; | |
| 153 | |
| 154 } // namespace WebCore | |
| 155 | |
| 156 #endif | |
| OLD | NEW |