OLD | NEW |
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "config.h" | 5 #include "config.h" |
6 #include "platform/graphics/GraphicsContextState.h" | 6 #include "platform/graphics/GraphicsContextState.h" |
7 | 7 |
8 namespace blink { | 8 namespace blink { |
9 | 9 |
10 GraphicsContextState::GraphicsContextState() | 10 GraphicsContextState::GraphicsContextState() |
11 : m_strokeColor(Color::black) | 11 : m_strokeColor(Color::black) |
12 , m_fillColor(Color::black) | 12 , m_fillColor(Color::black) |
13 , m_textDrawingMode(TextModeFill) | 13 , m_textDrawingMode(TextModeFill) |
14 , m_alpha(256) | |
15 , m_compositeOperation(SkXfermode::kSrcOver_Mode) | |
16 , m_interpolationQuality(InterpolationDefault) | 14 , m_interpolationQuality(InterpolationDefault) |
17 , m_saveCount(0) | 15 , m_saveCount(0) |
18 , m_shouldAntialias(true) | 16 , m_shouldAntialias(true) |
19 , m_shouldClampToSourceRect(true) | |
20 { | 17 { |
21 m_strokePaint.setStyle(SkPaint::kStroke_Style); | 18 m_strokePaint.setStyle(SkPaint::kStroke_Style); |
22 m_strokePaint.setStrokeWidth(SkFloatToScalar(m_strokeData.thickness())); | 19 m_strokePaint.setStrokeWidth(SkFloatToScalar(m_strokeData.thickness())); |
23 m_strokePaint.setColor(applyAlpha(m_strokeColor.rgb())); | 20 m_strokePaint.setColor(m_strokeColor.rgb()); |
24 m_strokePaint.setStrokeCap(SkPaint::kDefault_Cap); | 21 m_strokePaint.setStrokeCap(SkPaint::kDefault_Cap); |
25 m_strokePaint.setStrokeJoin(SkPaint::kDefault_Join); | 22 m_strokePaint.setStrokeJoin(SkPaint::kDefault_Join); |
26 m_strokePaint.setStrokeMiter(SkFloatToScalar(m_strokeData.miterLimit())); | 23 m_strokePaint.setStrokeMiter(SkFloatToScalar(m_strokeData.miterLimit())); |
27 m_strokePaint.setFilterQuality(WebCoreInterpolationQualityToSkFilterQuality(
m_interpolationQuality)); | 24 m_strokePaint.setFilterQuality(WebCoreInterpolationQualityToSkFilterQuality(
m_interpolationQuality)); |
28 m_strokePaint.setAntiAlias(m_shouldAntialias); | 25 m_strokePaint.setAntiAlias(m_shouldAntialias); |
29 m_fillPaint.setColor(applyAlpha(m_fillColor.rgb())); | 26 m_fillPaint.setColor(m_fillColor.rgb()); |
30 m_fillPaint.setFilterQuality(WebCoreInterpolationQualityToSkFilterQuality(m_
interpolationQuality)); | 27 m_fillPaint.setFilterQuality(WebCoreInterpolationQualityToSkFilterQuality(m_
interpolationQuality)); |
31 m_fillPaint.setAntiAlias(m_shouldAntialias); | 28 m_fillPaint.setAntiAlias(m_shouldAntialias); |
32 } | 29 } |
33 | 30 |
34 GraphicsContextState::GraphicsContextState(const GraphicsContextState& other) | 31 GraphicsContextState::GraphicsContextState(const GraphicsContextState& other) |
35 : m_strokePaint(other.m_strokePaint) | 32 : m_strokePaint(other.m_strokePaint) |
36 , m_fillPaint(other.m_fillPaint) | 33 , m_fillPaint(other.m_fillPaint) |
37 , m_strokeData(other.m_strokeData) | 34 , m_strokeData(other.m_strokeData) |
38 , m_strokeColor(other.m_strokeColor) | 35 , m_strokeColor(other.m_strokeColor) |
39 , m_strokeGradient(other.m_strokeGradient) | 36 , m_strokeGradient(other.m_strokeGradient) |
40 , m_strokePattern(other.m_strokePattern) | 37 , m_strokePattern(other.m_strokePattern) |
41 , m_fillColor(other.m_fillColor) | 38 , m_fillColor(other.m_fillColor) |
42 , m_fillGradient(other.m_fillGradient) | 39 , m_fillGradient(other.m_fillGradient) |
43 , m_fillPattern(other.m_fillPattern) | 40 , m_fillPattern(other.m_fillPattern) |
44 , m_looper(other.m_looper) | 41 , m_looper(other.m_looper) |
45 , m_dropShadowImageFilter(other.m_dropShadowImageFilter) | |
46 , m_textDrawingMode(other.m_textDrawingMode) | 42 , m_textDrawingMode(other.m_textDrawingMode) |
47 , m_alpha(other.m_alpha) | |
48 , m_colorFilter(other.m_colorFilter) | 43 , m_colorFilter(other.m_colorFilter) |
49 , m_compositeOperation(other.m_compositeOperation) | |
50 , m_interpolationQuality(other.m_interpolationQuality) | 44 , m_interpolationQuality(other.m_interpolationQuality) |
51 , m_saveCount(0) | 45 , m_saveCount(0) |
52 , m_shouldAntialias(other.m_shouldAntialias) | 46 , m_shouldAntialias(other.m_shouldAntialias) { } |
53 , m_shouldClampToSourceRect(other.m_shouldClampToSourceRect) { } | |
54 | 47 |
55 void GraphicsContextState::copy(const GraphicsContextState& source) | 48 void GraphicsContextState::copy(const GraphicsContextState& source) |
56 { | 49 { |
57 this->~GraphicsContextState(); | 50 this->~GraphicsContextState(); |
58 new (this) GraphicsContextState(source); | 51 new (this) GraphicsContextState(source); |
59 } | 52 } |
60 | 53 |
61 const SkPaint& GraphicsContextState::strokePaint(int strokedPathLength) const | 54 const SkPaint& GraphicsContextState::strokePaint(int strokedPathLength) const |
62 { | 55 { |
63 if (m_strokeGradient && m_strokeGradient->shaderChanged()) | 56 if (m_strokeGradient && m_strokeGradient->shaderChanged()) |
(...skipping 18 matching lines...) Expand all Loading... |
82 { | 75 { |
83 m_strokeData.setThickness(thickness); | 76 m_strokeData.setThickness(thickness); |
84 m_strokePaint.setStrokeWidth(SkFloatToScalar(thickness)); | 77 m_strokePaint.setStrokeWidth(SkFloatToScalar(thickness)); |
85 } | 78 } |
86 | 79 |
87 void GraphicsContextState::setStrokeColor(const Color& color) | 80 void GraphicsContextState::setStrokeColor(const Color& color) |
88 { | 81 { |
89 m_strokeGradient.clear(); | 82 m_strokeGradient.clear(); |
90 m_strokePattern.clear(); | 83 m_strokePattern.clear(); |
91 m_strokeColor = color; | 84 m_strokeColor = color; |
92 m_strokePaint.setColor(applyAlpha(color.rgb())); | 85 m_strokePaint.setColor(color.rgb()); |
93 m_strokePaint.setShader(0); | 86 m_strokePaint.setShader(0); |
94 } | 87 } |
95 | 88 |
96 void GraphicsContextState::setStrokeGradient(const PassRefPtr<Gradient> gradient
, float alpha) | 89 void GraphicsContextState::setStrokeGradient(const PassRefPtr<Gradient> gradient
, float alpha) |
97 { | 90 { |
98 m_strokeColor = Color::black; | 91 m_strokeColor = Color::black; |
99 m_strokePattern.clear(); | 92 m_strokePattern.clear(); |
100 m_strokeGradient = gradient; | 93 m_strokeGradient = gradient; |
101 m_strokePaint.setColor(scaleAlpha(applyAlpha(SK_ColorBLACK), alpha)); | 94 m_strokePaint.setColor(scaleAlpha(SK_ColorBLACK, alpha)); |
102 m_strokePaint.setShader(m_strokeGradient->shader()); | 95 m_strokePaint.setShader(m_strokeGradient->shader()); |
103 } | 96 } |
104 | 97 |
105 void GraphicsContextState::setStrokePattern(const PassRefPtr<Pattern> pattern, f
loat alpha) | 98 void GraphicsContextState::setStrokePattern(const PassRefPtr<Pattern> pattern, f
loat alpha) |
106 { | 99 { |
107 m_strokeColor = Color::black; | 100 m_strokeColor = Color::black; |
108 m_strokeGradient.clear(); | 101 m_strokeGradient.clear(); |
109 m_strokePattern = pattern; | 102 m_strokePattern = pattern; |
110 m_strokePaint.setColor(scaleAlpha(applyAlpha(SK_ColorBLACK), alpha)); | 103 m_strokePaint.setColor(scaleAlpha(SK_ColorBLACK, alpha)); |
111 m_strokePaint.setShader(m_strokePattern->shader()); | 104 m_strokePaint.setShader(m_strokePattern->shader()); |
112 } | 105 } |
113 | 106 |
114 void GraphicsContextState::setLineCap(LineCap cap) | 107 void GraphicsContextState::setLineCap(LineCap cap) |
115 { | 108 { |
116 m_strokeData.setLineCap(cap); | 109 m_strokeData.setLineCap(cap); |
117 m_strokePaint.setStrokeCap((SkPaint::Cap)cap); | 110 m_strokePaint.setStrokeCap((SkPaint::Cap)cap); |
118 } | 111 } |
119 | 112 |
120 void GraphicsContextState::setLineJoin(LineJoin join) | 113 void GraphicsContextState::setLineJoin(LineJoin join) |
121 { | 114 { |
122 m_strokeData.setLineJoin(join); | 115 m_strokeData.setLineJoin(join); |
123 m_strokePaint.setStrokeJoin((SkPaint::Join)join); | 116 m_strokePaint.setStrokeJoin((SkPaint::Join)join); |
124 } | 117 } |
125 | 118 |
126 void GraphicsContextState::setMiterLimit(float miterLimit) | 119 void GraphicsContextState::setMiterLimit(float miterLimit) |
127 { | 120 { |
128 m_strokeData.setMiterLimit(miterLimit); | 121 m_strokeData.setMiterLimit(miterLimit); |
129 m_strokePaint.setStrokeMiter(SkFloatToScalar(miterLimit)); | 122 m_strokePaint.setStrokeMiter(SkFloatToScalar(miterLimit)); |
130 } | 123 } |
131 | 124 |
132 void GraphicsContextState::setFillColor(const Color& color) | 125 void GraphicsContextState::setFillColor(const Color& color) |
133 { | 126 { |
134 m_fillColor = color; | 127 m_fillColor = color; |
135 m_fillGradient.clear(); | 128 m_fillGradient.clear(); |
136 m_fillPattern.clear(); | 129 m_fillPattern.clear(); |
137 m_fillPaint.setColor(applyAlpha(color.rgb())); | 130 m_fillPaint.setColor(color.rgb()); |
138 m_fillPaint.setShader(0); | 131 m_fillPaint.setShader(0); |
139 } | 132 } |
140 | 133 |
141 void GraphicsContextState::setFillGradient(const PassRefPtr<Gradient> gradient,
float alpha) | 134 void GraphicsContextState::setFillGradient(const PassRefPtr<Gradient> gradient,
float alpha) |
142 { | 135 { |
143 m_fillColor = Color::black; | 136 m_fillColor = Color::black; |
144 m_fillPattern.clear(); | 137 m_fillPattern.clear(); |
145 m_fillGradient = gradient; | 138 m_fillGradient = gradient; |
146 m_fillPaint.setColor(scaleAlpha(applyAlpha(SK_ColorBLACK), alpha)); | 139 m_fillPaint.setColor(scaleAlpha(SK_ColorBLACK, alpha)); |
147 m_fillPaint.setShader(m_fillGradient->shader()); | 140 m_fillPaint.setShader(m_fillGradient->shader()); |
148 } | 141 } |
149 | 142 |
150 void GraphicsContextState::setFillPattern(const PassRefPtr<Pattern> pattern, flo
at alpha) | 143 void GraphicsContextState::setFillPattern(const PassRefPtr<Pattern> pattern, flo
at alpha) |
151 { | 144 { |
152 m_fillColor = Color::black; | 145 m_fillColor = Color::black; |
153 m_fillGradient.clear(); | 146 m_fillGradient.clear(); |
154 m_fillPattern = pattern; | 147 m_fillPattern = pattern; |
155 m_fillPaint.setColor(scaleAlpha(applyAlpha(SK_ColorBLACK), alpha)); | 148 m_fillPaint.setColor(scaleAlpha(SK_ColorBLACK, alpha)); |
156 m_fillPaint.setShader(m_fillPattern->shader()); | 149 m_fillPaint.setShader(m_fillPattern->shader()); |
157 } | 150 } |
158 | 151 |
159 // Shadow. (This will need tweaking if we use draw loopers for other things.) | 152 // Shadow. (This will need tweaking if we use draw loopers for other things.) |
160 void GraphicsContextState::setDrawLooper(PassRefPtr<SkDrawLooper> drawLooper) | 153 void GraphicsContextState::setDrawLooper(PassRefPtr<SkDrawLooper> drawLooper) |
161 { | 154 { |
162 m_looper = drawLooper; | 155 m_looper = drawLooper; |
163 m_strokePaint.setLooper(m_looper.get()); | 156 m_strokePaint.setLooper(m_looper.get()); |
164 m_fillPaint.setLooper(m_looper.get()); | 157 m_fillPaint.setLooper(m_looper.get()); |
165 } | 158 } |
166 | 159 |
167 void GraphicsContextState::clearDrawLooper() | 160 void GraphicsContextState::clearDrawLooper() |
168 { | 161 { |
169 m_looper.clear(); | 162 m_looper.clear(); |
170 m_strokePaint.setLooper(0); | 163 m_strokePaint.setLooper(0); |
171 m_fillPaint.setLooper(0); | 164 m_fillPaint.setLooper(0); |
172 } | 165 } |
173 | 166 |
174 void GraphicsContextState::setDropShadowImageFilter(PassRefPtr<SkImageFilter> dr
opShadowImageFilter) | |
175 { | |
176 m_dropShadowImageFilter = dropShadowImageFilter; | |
177 } | |
178 | |
179 void GraphicsContextState::clearDropShadowImageFilter() | |
180 { | |
181 m_dropShadowImageFilter.clear(); | |
182 } | |
183 | |
184 void GraphicsContextState::setAlphaAsFloat(float alpha) | |
185 { | |
186 m_alpha = clampedAlphaForBlending(alpha); | |
187 m_strokePaint.setColor(applyAlpha(m_strokeColor.rgb())); | |
188 m_fillPaint.setColor(applyAlpha(m_fillColor.rgb())); | |
189 } | |
190 | |
191 void GraphicsContextState::setLineDash(const DashArray& dashes, float dashOffset
) | 167 void GraphicsContextState::setLineDash(const DashArray& dashes, float dashOffset
) |
192 { | 168 { |
193 m_strokeData.setLineDash(dashes, dashOffset); | 169 m_strokeData.setLineDash(dashes, dashOffset); |
194 } | 170 } |
195 | 171 |
196 void GraphicsContextState::setColorFilter(PassRefPtr<SkColorFilter> colorFilter) | 172 void GraphicsContextState::setColorFilter(PassRefPtr<SkColorFilter> colorFilter) |
197 { | 173 { |
198 m_colorFilter = colorFilter; | 174 m_colorFilter = colorFilter; |
199 m_strokePaint.setColorFilter(m_colorFilter.get()); | 175 m_strokePaint.setColorFilter(m_colorFilter.get()); |
200 m_fillPaint.setColorFilter(m_colorFilter.get()); | 176 m_fillPaint.setColorFilter(m_colorFilter.get()); |
201 } | 177 } |
202 | 178 |
203 void GraphicsContextState::setCompositeOperation(SkXfermode::Mode xferMode) | |
204 { | |
205 m_compositeOperation = xferMode; | |
206 m_strokePaint.setXfermodeMode(xferMode); | |
207 m_fillPaint.setXfermodeMode(xferMode); | |
208 } | |
209 | |
210 void GraphicsContextState::setInterpolationQuality(InterpolationQuality quality) | 179 void GraphicsContextState::setInterpolationQuality(InterpolationQuality quality) |
211 { | 180 { |
212 m_interpolationQuality = quality; | 181 m_interpolationQuality = quality; |
213 m_strokePaint.setFilterQuality(WebCoreInterpolationQualityToSkFilterQuality(
quality)); | 182 m_strokePaint.setFilterQuality(WebCoreInterpolationQualityToSkFilterQuality(
quality)); |
214 m_fillPaint.setFilterQuality(WebCoreInterpolationQualityToSkFilterQuality(qu
ality)); | 183 m_fillPaint.setFilterQuality(WebCoreInterpolationQualityToSkFilterQuality(qu
ality)); |
215 } | 184 } |
216 | 185 |
217 void GraphicsContextState::setShouldAntialias(bool shouldAntialias) | 186 void GraphicsContextState::setShouldAntialias(bool shouldAntialias) |
218 { | 187 { |
219 m_shouldAntialias = shouldAntialias; | 188 m_shouldAntialias = shouldAntialias; |
220 m_strokePaint.setAntiAlias(shouldAntialias); | 189 m_strokePaint.setAntiAlias(shouldAntialias); |
221 m_fillPaint.setAntiAlias(shouldAntialias); | 190 m_fillPaint.setAntiAlias(shouldAntialias); |
222 } | 191 } |
223 | 192 |
224 } // namespace blink | 193 } // namespace blink |
OLD | NEW |