OLD | NEW |
---|---|
1 // Copyright (C) 2013 Google Inc. All rights reserved. | 1 // Copyright (C) 2013 Google Inc. All rights reserved. |
2 // | 2 // |
3 // Redistribution and use in source and binary forms, with or without | 3 // Redistribution and use in source and binary forms, with or without |
4 // modification, are permitted provided that the following conditions are | 4 // modification, are permitted provided that the following conditions are |
5 // met: | 5 // met: |
6 // | 6 // |
7 // * Redistributions of source code must retain the above copyright | 7 // * Redistributions of source code must retain the above copyright |
8 // notice, this list of conditions and the following disclaimer. | 8 // notice, this list of conditions and the following disclaimer. |
9 // * Redistributions in binary form must reproduce the above | 9 // * Redistributions in binary form must reproduce the above |
10 // copyright notice, this list of conditions and the following disclaimer | 10 // copyright notice, this list of conditions and the following disclaimer |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
67 uint16_t saveCount() const { return m_saveCount; } | 67 uint16_t saveCount() const { return m_saveCount; } |
68 void incrementSaveCount() { ++m_saveCount; } | 68 void incrementSaveCount() { ++m_saveCount; } |
69 void decrementSaveCount() { --m_saveCount; } | 69 void decrementSaveCount() { --m_saveCount; } |
70 | 70 |
71 // Stroke data | 71 // Stroke data |
72 Color strokeColor() const { return m_strokeColor; } | 72 Color strokeColor() const { return m_strokeColor; } |
73 SkColor effectiveStrokeColor() const { return applyAlpha(m_strokeColor.rgb() ); } | 73 SkColor effectiveStrokeColor() const { return applyAlpha(m_strokeColor.rgb() ); } |
74 void setStrokeColor(const Color&); | 74 void setStrokeColor(const Color&); |
75 | 75 |
76 Gradient* strokeGradient() const { return m_strokeGradient.get(); } | 76 Gradient* strokeGradient() const { return m_strokeGradient.get(); } |
77 void setStrokeGradient(const PassRefPtr<Gradient>); | 77 void setStrokeGradient(const PassRefPtr<Gradient>, float); |
78 void clearStrokeGradient(); | 78 void clearStrokeGradient(); |
79 | 79 |
80 Pattern* strokePattern() const { return m_strokePattern.get(); } | 80 Pattern* strokePattern() const { return m_strokePattern.get(); } |
81 void setStrokePattern(const PassRefPtr<Pattern>); | 81 void setStrokePattern(const PassRefPtr<Pattern>, float); |
82 void clearStrokePattern(); | 82 void clearStrokePattern(); |
83 | 83 |
84 const StrokeData& strokeData() const { return m_strokeData; } | 84 const StrokeData& strokeData() const { return m_strokeData; } |
85 void setStrokeStyle(StrokeStyle); | 85 void setStrokeStyle(StrokeStyle); |
86 void setStrokeThickness(float); | 86 void setStrokeThickness(float); |
87 void setLineCap(LineCap); | 87 void setLineCap(LineCap); |
88 void setLineJoin(LineJoin); | 88 void setLineJoin(LineJoin); |
89 void setMiterLimit(float); | 89 void setMiterLimit(float); |
90 void setLineDash(const DashArray&, float); | 90 void setLineDash(const DashArray&, float); |
91 | 91 |
92 // Fill data | 92 // Fill data |
93 Color fillColor() const { return m_fillColor; } | 93 Color fillColor() const { return m_fillColor; } |
94 SkColor effectiveFillColor() const { return applyAlpha(m_fillColor.rgb()); } | 94 SkColor effectiveFillColor() const { return applyAlpha(m_fillColor.rgb()); } |
95 void setFillColor(const Color&); | 95 void setFillColor(const Color&); |
96 | 96 |
97 Gradient* fillGradient() const { return m_fillGradient.get(); } | 97 Gradient* fillGradient() const { return m_fillGradient.get(); } |
98 void setFillGradient(const PassRefPtr<Gradient>); | 98 void setFillGradient(const PassRefPtr<Gradient>, float); |
99 void clearFillGradient(); | 99 void clearFillGradient(); |
100 | 100 |
101 Pattern* fillPattern() const { return m_fillPattern.get(); } | 101 Pattern* fillPattern() const { return m_fillPattern.get(); } |
102 void setFillPattern(const PassRefPtr<Pattern>); | 102 void setFillPattern(const PassRefPtr<Pattern>, float); |
103 void clearFillPattern(); | 103 void clearFillPattern(); |
104 | 104 |
105 // Path fill rule | 105 // Path fill rule |
106 WindRule fillRule() const { return m_fillRule; } | 106 WindRule fillRule() const { return m_fillRule; } |
107 void setFillRule(WindRule rule) { m_fillRule = rule; } | 107 void setFillRule(WindRule rule) { m_fillRule = rule; } |
108 | 108 |
109 // Shadow. (This will need tweaking if we use draw loopers for other things. ) | 109 // Shadow. (This will need tweaking if we use draw loopers for other things. ) |
110 SkDrawLooper* drawLooper() const { return m_looper.get(); } | 110 SkDrawLooper* drawLooper() const { return m_looper.get(); } |
111 void setDrawLooper(PassRefPtr<SkDrawLooper>); | 111 void setDrawLooper(PassRefPtr<SkDrawLooper>); |
112 void clearDrawLooper(); | 112 void clearDrawLooper(); |
(...skipping 25 matching lines...) Expand all Loading... | |
138 void setShouldAntialias(bool); | 138 void setShouldAntialias(bool); |
139 | 139 |
140 bool shouldClampToSourceRect() const { return m_shouldClampToSourceRect; } | 140 bool shouldClampToSourceRect() const { return m_shouldClampToSourceRect; } |
141 void setShouldClampToSourceRect(bool shouldClampToSourceRect) { m_shouldClam pToSourceRect = shouldClampToSourceRect; } | 141 void setShouldClampToSourceRect(bool shouldClampToSourceRect) { m_shouldClam pToSourceRect = shouldClampToSourceRect; } |
142 | 142 |
143 // Returns true if clip is more than just a rectangle or intersection | 143 // Returns true if clip is more than just a rectangle or intersection |
144 // of rectangles. | 144 // of rectangles. |
145 bool hasComplexClip() const; | 145 bool hasComplexClip() const; |
146 void setHasComplexClip(); | 146 void setHasComplexClip(); |
147 | 147 |
148 // Multiply a color's alpha channel by an additional alpha factor where | |
149 // alpha is in the range [0, 1]. | |
150 static SkColor combineWithAlpha(SkColor color, float alpha) | |
f(malita)
2015/02/03 00:33:28
Is there any reason to keep these helpers in GC/GC
pdr.
2015/02/04 04:04:31
Moved to the other dumping ground, SkiaUtils :)
| |
151 { | |
152 return combineWithAlpha(color, clampedAlphaForBlending(alpha)); | |
f(malita)
2015/02/03 00:33:28
Naming nit: "combineWithAlpha" sounds pretty weird
pdr.
2015/02/04 04:04:31
After much fighting, I renamed this to multiplyAlp
| |
153 } | |
154 | |
148 private: | 155 private: |
149 GraphicsContextState(); | 156 GraphicsContextState(); |
150 explicit GraphicsContextState(const GraphicsContextState&); | 157 explicit GraphicsContextState(const GraphicsContextState&); |
151 GraphicsContextState& operator=(const GraphicsContextState&); | 158 GraphicsContextState& operator=(const GraphicsContextState&); |
152 | 159 |
160 // Multiply a color's alpha channel by an additional alpha factor where | |
161 // alpha is in the range [0, 256]. | |
162 static SkColor combineWithAlpha(SkColor color, int alpha) | |
163 { | |
164 int a = (SkColorGetA(color) * alpha) >> 8; | |
165 return (color & 0x00FFFFFF) | (a << 24); | |
166 } | |
167 | |
153 // Helper function for applying the state's alpha value to the given input | 168 // Helper function for applying the state's alpha value to the given input |
154 // color to produce a new output color. | 169 // color to produce a new output color. |
155 SkColor applyAlpha(SkColor c) const | 170 SkColor applyAlpha(SkColor color) const |
156 { | 171 { |
157 int a = SkAlphaMul(SkColorGetA(c), m_alpha); | 172 return combineWithAlpha(color, m_alpha); |
158 return (c & 0x00FFFFFF) | (a << 24); | 173 } |
174 | |
175 // Map alpha values from [0, 1] to [0, 256] for alpha blending. | |
176 static int clampedAlphaForBlending(float alpha) | |
177 { | |
178 if (alpha < 0) | |
179 return 0; | |
180 int roundedAlpha = roundf(alpha * 256); | |
181 if (roundedAlpha > 256) | |
182 roundedAlpha = 256; | |
183 return roundedAlpha; | |
159 } | 184 } |
160 | 185 |
161 // These are mutbale to enable gradient updates when the paints are fetched for use. | 186 // These are mutbale to enable gradient updates when the paints are fetched for use. |
162 mutable SkPaint m_strokePaint; | 187 mutable SkPaint m_strokePaint; |
163 mutable SkPaint m_fillPaint; | 188 mutable SkPaint m_fillPaint; |
164 | 189 |
165 StrokeData m_strokeData; | 190 StrokeData m_strokeData; |
166 | 191 |
167 Color m_strokeColor; | 192 Color m_strokeColor; |
168 RefPtr<Gradient> m_strokeGradient; | 193 RefPtr<Gradient> m_strokeGradient; |
(...skipping 19 matching lines...) Expand all Loading... | |
188 uint16_t m_saveCount; | 213 uint16_t m_saveCount; |
189 | 214 |
190 bool m_shouldAntialias : 1; | 215 bool m_shouldAntialias : 1; |
191 bool m_shouldClampToSourceRect : 1; | 216 bool m_shouldClampToSourceRect : 1; |
192 bool m_hasComplexClip : 1; | 217 bool m_hasComplexClip : 1; |
193 }; | 218 }; |
194 | 219 |
195 } // namespace blink | 220 } // namespace blink |
196 | 221 |
197 #endif // GraphicsContextState_h | 222 #endif // GraphicsContextState_h |
OLD | NEW |