| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006, 2007, 2008, 2011 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007, 2008, 2011 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2007 Alp Toker <alp@atoker.com> | 3 * Copyright (C) 2007 Alp Toker <alp@atoker.com> |
| 4 * Copyright (C) 2008 Torch Mobile, Inc. | 4 * Copyright (C) 2008 Torch Mobile, Inc. |
| 5 * Copyright (C) 2013 Google Inc. All rights reserved. | 5 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 6 * | 6 * |
| 7 * Redistribution and use in source and binary forms, with or without | 7 * Redistribution and use in source and binary forms, with or without |
| 8 * modification, are permitted provided that the following conditions | 8 * modification, are permitted provided that the following conditions |
| 9 * are met: | 9 * are met: |
| 10 * 1. Redistributions of source code must retain the above copyright | 10 * 1. Redistributions of source code must retain the above copyright |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 #include "wtf/Vector.h" | 42 #include "wtf/Vector.h" |
| 43 | 43 |
| 44 class SkMatrix; | 44 class SkMatrix; |
| 45 | 45 |
| 46 namespace blink { | 46 namespace blink { |
| 47 | 47 |
| 48 class PLATFORM_EXPORT Gradient : public RefCounted<Gradient> { | 48 class PLATFORM_EXPORT Gradient : public RefCounted<Gradient> { |
| 49 WTF_MAKE_NONCOPYABLE(Gradient); | 49 WTF_MAKE_NONCOPYABLE(Gradient); |
| 50 | 50 |
| 51 public: | 51 public: |
| 52 static PassRefPtr<Gradient> create(const FloatPoint& p0, | 52 enum class ColorInterpolation { |
| 53 const FloatPoint& p1) { | 53 Premultiplied, |
| 54 return adoptRef(new Gradient(p0, p1)); | 54 Unpremultiplied, |
| 55 }; |
| 56 |
| 57 static PassRefPtr<Gradient> create( |
| 58 const FloatPoint& p0, |
| 59 const FloatPoint& p1, |
| 60 GradientSpreadMethod spreadMethod = SpreadMethodPad, |
| 61 ColorInterpolation interpolation = ColorInterpolation::Unpremultiplied) { |
| 62 return adoptRef(new Gradient(p0, p1, spreadMethod, interpolation)); |
| 55 } | 63 } |
| 56 static PassRefPtr<Gradient> create(const FloatPoint& p0, | 64 static PassRefPtr<Gradient> create( |
| 57 float r0, | 65 const FloatPoint& p0, |
| 58 const FloatPoint& p1, | 66 float r0, |
| 59 float r1, | 67 const FloatPoint& p1, |
| 60 float aspectRatio = 1) { | 68 float r1, |
| 61 return adoptRef(new Gradient(p0, r0, p1, r1, aspectRatio)); | 69 float aspectRatio = 1, |
| 70 GradientSpreadMethod spreadMethod = SpreadMethodPad, |
| 71 ColorInterpolation interpolation = ColorInterpolation::Unpremultiplied) { |
| 72 return adoptRef( |
| 73 new Gradient(p0, r0, p1, r1, aspectRatio, spreadMethod, interpolation)); |
| 62 } | 74 } |
| 63 ~Gradient(); | 75 ~Gradient(); |
| 64 | 76 |
| 65 struct ColorStop { | 77 struct ColorStop { |
| 66 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); | 78 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); |
| 67 float stop; | 79 float stop; |
| 68 Color color; | 80 Color color; |
| 69 | 81 |
| 70 ColorStop(float s, const Color& c) : stop(s), color(c) {} | 82 ColorStop(float s, const Color& c) : stop(s), color(c) {} |
| 71 }; | 83 }; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 | 122 |
| 111 void setEndRadius(float r) { | 123 void setEndRadius(float r) { |
| 112 if (m_r1 == r) | 124 if (m_r1 == r) |
| 113 return; | 125 return; |
| 114 | 126 |
| 115 m_r1 = r; | 127 m_r1 = r; |
| 116 } | 128 } |
| 117 | 129 |
| 118 void applyToFlags(PaintFlags&, const SkMatrix& localMatrix); | 130 void applyToFlags(PaintFlags&, const SkMatrix& localMatrix); |
| 119 | 131 |
| 120 void setDrawsInPMColorSpace(bool drawInPMColorSpace); | |
| 121 | |
| 122 void setSpreadMethod(GradientSpreadMethod); | |
| 123 GradientSpreadMethod spreadMethod() const { return m_spreadMethod; } | 132 GradientSpreadMethod spreadMethod() const { return m_spreadMethod; } |
| 124 | 133 |
| 125 private: | 134 private: |
| 126 Gradient(const FloatPoint& p0, const FloatPoint& p1); | 135 Gradient(const FloatPoint& p0, |
| 136 const FloatPoint& p1, |
| 137 GradientSpreadMethod, |
| 138 ColorInterpolation); |
| 127 Gradient(const FloatPoint& p0, | 139 Gradient(const FloatPoint& p0, |
| 128 float r0, | 140 float r0, |
| 129 const FloatPoint& p1, | 141 const FloatPoint& p1, |
| 130 float r1, | 142 float r1, |
| 131 float aspectRatio); | 143 float aspectRatio, |
| 144 GradientSpreadMethod, |
| 145 ColorInterpolation); |
| 132 | 146 |
| 133 sk_sp<PaintShader> createShader(const SkMatrix& localMatrix); | 147 sk_sp<PaintShader> createShader(const SkMatrix& localMatrix); |
| 134 | 148 |
| 135 void sortStopsIfNecessary(); | 149 void sortStopsIfNecessary(); |
| 136 | 150 |
| 137 FloatPoint m_p0; | 151 FloatPoint m_p0; |
| 138 FloatPoint m_p1; | 152 FloatPoint m_p1; |
| 139 float m_r0; | 153 float m_r0; |
| 140 float m_r1; | 154 float m_r1; |
| 141 float m_aspectRatio; // For elliptical gradient, width / height. | 155 float m_aspectRatio; // For elliptical gradient, width / height. |
| 142 Vector<ColorStop, 2> m_stops; | 156 Vector<ColorStop, 2> m_stops; |
| 143 bool m_radial; | 157 bool m_radial; |
| 144 bool m_stopsSorted; | 158 bool m_stopsSorted; |
| 145 bool m_drawInPMColorSpace; | |
| 146 GradientSpreadMethod m_spreadMethod; | 159 GradientSpreadMethod m_spreadMethod; |
| 160 ColorInterpolation m_colorInterpolation; |
| 147 | 161 |
| 148 mutable sk_sp<PaintShader> m_cachedShader; | 162 mutable sk_sp<PaintShader> m_cachedShader; |
| 149 }; | 163 }; |
| 150 | 164 |
| 151 } // namespace blink | 165 } // namespace blink |
| 152 | 166 |
| 153 #endif | 167 #endif |
| OLD | NEW |