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 #include "platform/graphics/skia/SkiaUtils.h" | 8 #include "platform/graphics/skia/SkiaUtils.h" |
9 | 9 |
10 namespace blink { | 10 namespace blink { |
11 | 11 |
12 GraphicsContextState::GraphicsContextState() | 12 GraphicsContextState::GraphicsContextState() |
13 : m_fillColor(Color::black) | 13 : m_strokeColor(Color::black) |
| 14 , m_fillColor(Color::black) |
14 , m_fillRule(RULE_NONZERO) | 15 , m_fillRule(RULE_NONZERO) |
15 , m_textDrawingMode(TextModeFill) | 16 , m_textDrawingMode(TextModeFill) |
16 , m_alpha(256) | 17 , m_alpha(256) |
17 , m_compositeOperator(CompositeSourceOver) | 18 , m_compositeOperator(CompositeSourceOver) |
18 , m_blendMode(WebBlendModeNormal) | 19 , m_blendMode(WebBlendModeNormal) |
19 , m_interpolationQuality(InterpolationDefault) | 20 , m_interpolationQuality(InterpolationDefault) |
20 , m_saveCount(0) | 21 , m_saveCount(0) |
21 , m_shouldAntialias(true) | 22 , m_shouldAntialias(true) |
22 , m_shouldClampToSourceRect(true) | 23 , m_shouldClampToSourceRect(true) |
23 { | 24 { |
24 m_strokePaint.setStyle(SkPaint::kStroke_Style); | 25 m_strokePaint.setStyle(SkPaint::kStroke_Style); |
25 m_strokePaint.setStrokeWidth(SkFloatToScalar(m_strokeData.thickness())); | 26 m_strokePaint.setStrokeWidth(SkFloatToScalar(m_strokeData.thickness())); |
26 m_strokePaint.setColor(applyAlpha(m_strokeData.color().rgb())); | 27 m_strokePaint.setColor(applyAlpha(m_strokeColor.rgb())); |
27 m_strokePaint.setStrokeCap(SkPaint::kDefault_Cap); | 28 m_strokePaint.setStrokeCap(SkPaint::kDefault_Cap); |
28 m_strokePaint.setStrokeJoin(SkPaint::kDefault_Join); | 29 m_strokePaint.setStrokeJoin(SkPaint::kDefault_Join); |
29 m_strokePaint.setStrokeMiter(SkFloatToScalar(m_strokeData.miterLimit())); | 30 m_strokePaint.setStrokeMiter(SkFloatToScalar(m_strokeData.miterLimit())); |
30 m_strokePaint.setFilterLevel(WebCoreInterpolationQualityToSkFilterLevel(m_in
terpolationQuality)); | 31 m_strokePaint.setFilterLevel(WebCoreInterpolationQualityToSkFilterLevel(m_in
terpolationQuality)); |
31 m_strokePaint.setAntiAlias(m_shouldAntialias); | 32 m_strokePaint.setAntiAlias(m_shouldAntialias); |
32 m_fillPaint.setColor(applyAlpha(m_fillColor.rgb())); | 33 m_fillPaint.setColor(applyAlpha(m_fillColor.rgb())); |
33 m_fillPaint.setFilterLevel(WebCoreInterpolationQualityToSkFilterLevel(m_inte
rpolationQuality)); | 34 m_fillPaint.setFilterLevel(WebCoreInterpolationQualityToSkFilterLevel(m_inte
rpolationQuality)); |
34 m_fillPaint.setAntiAlias(m_shouldAntialias); | 35 m_fillPaint.setAntiAlias(m_shouldAntialias); |
35 } | 36 } |
36 | 37 |
37 GraphicsContextState::GraphicsContextState(const GraphicsContextState& other) | 38 GraphicsContextState::GraphicsContextState(const GraphicsContextState& other) |
38 : m_strokePaint(other.m_strokePaint) | 39 : m_strokePaint(other.m_strokePaint) |
39 , m_fillPaint(other.m_fillPaint) | 40 , m_fillPaint(other.m_fillPaint) |
40 , m_strokeData(other.m_strokeData) | 41 , m_strokeData(other.m_strokeData) |
| 42 , m_strokeColor(other.m_strokeColor) |
| 43 , m_strokeGradient(other.m_strokeGradient) |
| 44 , m_strokePattern(other.m_strokePattern) |
41 , m_fillColor(other.m_fillColor) | 45 , m_fillColor(other.m_fillColor) |
42 , m_fillRule(other.m_fillRule) | 46 , m_fillRule(other.m_fillRule) |
43 , m_fillGradient(other.m_fillGradient) | 47 , m_fillGradient(other.m_fillGradient) |
44 , m_fillPattern(other.m_fillPattern) | 48 , m_fillPattern(other.m_fillPattern) |
45 , m_looper(other.m_looper) | 49 , m_looper(other.m_looper) |
46 , m_textDrawingMode(other.m_textDrawingMode) | 50 , m_textDrawingMode(other.m_textDrawingMode) |
47 , m_alpha(other.m_alpha) | 51 , m_alpha(other.m_alpha) |
48 , m_colorFilter(other.m_colorFilter) | 52 , m_colorFilter(other.m_colorFilter) |
49 , m_compositeOperator(other.m_compositeOperator) | 53 , m_compositeOperator(other.m_compositeOperator) |
50 , m_blendMode(other.m_blendMode) | 54 , m_blendMode(other.m_blendMode) |
51 , m_interpolationQuality(other.m_interpolationQuality) | 55 , m_interpolationQuality(other.m_interpolationQuality) |
52 , m_saveCount(0) | 56 , m_saveCount(0) |
53 , m_shouldAntialias(other.m_shouldAntialias) | 57 , m_shouldAntialias(other.m_shouldAntialias) |
54 , m_shouldClampToSourceRect(other.m_shouldClampToSourceRect) { } | 58 , m_shouldClampToSourceRect(other.m_shouldClampToSourceRect) { } |
55 | 59 |
56 void GraphicsContextState::copy(const GraphicsContextState& source) | 60 void GraphicsContextState::copy(const GraphicsContextState& source) |
57 { | 61 { |
58 this->~GraphicsContextState(); | 62 this->~GraphicsContextState(); |
59 new (this) GraphicsContextState(source); | 63 new (this) GraphicsContextState(source); |
60 } | 64 } |
61 | 65 |
62 const SkPaint& GraphicsContextState::strokePaint(int strokedPathLength) const | 66 const SkPaint& GraphicsContextState::strokePaint(int strokedPathLength) const |
63 { | 67 { |
64 if (m_strokeData.gradient() && m_strokeData.gradient()->shaderChanged()) | 68 if (m_strokeGradient && m_strokeGradient->shaderChanged()) |
65 m_strokePaint.setShader(m_strokeData.gradient()->shader()); | 69 m_strokePaint.setShader(m_strokeGradient->shader()); |
66 m_strokeData.setupPaintDashPathEffect(&m_strokePaint, strokedPathLength); | 70 m_strokeData.setupPaintDashPathEffect(&m_strokePaint, strokedPathLength); |
67 return m_strokePaint; | 71 return m_strokePaint; |
68 } | 72 } |
69 | 73 |
70 const SkPaint& GraphicsContextState::fillPaint() const | 74 const SkPaint& GraphicsContextState::fillPaint() const |
71 { | 75 { |
72 if (m_fillGradient && m_fillGradient->shaderChanged()) | 76 if (m_fillGradient && m_fillGradient->shaderChanged()) |
73 m_fillPaint.setShader(m_fillGradient->shader()); | 77 m_fillPaint.setShader(m_fillGradient->shader()); |
74 return m_fillPaint; | 78 return m_fillPaint; |
75 } | 79 } |
76 | 80 |
77 void GraphicsContextState::setStrokeStyle(StrokeStyle style) | 81 void GraphicsContextState::setStrokeStyle(StrokeStyle style) |
78 { | 82 { |
79 m_strokeData.setStyle(style); | 83 m_strokeData.setStyle(style); |
80 } | 84 } |
81 | 85 |
82 void GraphicsContextState::setStrokeThickness(float thickness) | 86 void GraphicsContextState::setStrokeThickness(float thickness) |
83 { | 87 { |
84 m_strokeData.setThickness(thickness); | 88 m_strokeData.setThickness(thickness); |
85 m_strokePaint.setStrokeWidth(SkFloatToScalar(thickness)); | 89 m_strokePaint.setStrokeWidth(SkFloatToScalar(thickness)); |
86 } | 90 } |
87 | 91 |
88 void GraphicsContextState::setStrokeColor(const Color& color) | 92 void GraphicsContextState::setStrokeColor(const Color& color) |
89 { | 93 { |
90 m_strokeData.clearGradient(); | 94 m_strokeGradient.clear(); |
91 m_strokeData.clearPattern(); | 95 m_strokePattern.clear(); |
92 m_strokeData.setColor(color); | 96 m_strokeColor = color; |
93 m_strokePaint.setColor(applyAlpha(color.rgb())); | 97 m_strokePaint.setColor(applyAlpha(color.rgb())); |
94 m_strokePaint.setShader(0); | 98 m_strokePaint.setShader(0); |
95 } | 99 } |
96 | 100 |
97 void GraphicsContextState::setStrokeGradient(const PassRefPtr<Gradient> gradient
) | 101 void GraphicsContextState::setStrokeGradient(const PassRefPtr<Gradient> gradient
) |
98 { | 102 { |
99 m_strokeData.setColor(Color::black); | 103 m_strokeColor = Color::black; |
100 m_strokeData.clearPattern(); | 104 m_strokePattern.clear(); |
101 m_strokeData.setGradient(gradient); | 105 m_strokeGradient = gradient; |
102 m_strokePaint.setColor(applyAlpha(SK_ColorBLACK)); | 106 m_strokePaint.setColor(applyAlpha(SK_ColorBLACK)); |
103 m_strokePaint.setShader(m_strokeData.gradient()->shader()); | 107 m_strokePaint.setShader(m_strokeGradient->shader()); |
104 } | 108 } |
105 | 109 |
106 void GraphicsContextState::clearStrokeGradient() | 110 void GraphicsContextState::clearStrokeGradient() |
107 { | 111 { |
108 m_strokeData.clearGradient(); | 112 m_strokeGradient.clear(); |
109 ASSERT(!m_strokeData.pattern()); | 113 ASSERT(!m_strokePattern); |
110 m_strokePaint.setColor(applyAlpha(m_strokeData.color().rgb())); | 114 m_strokePaint.setColor(applyAlpha(m_strokeColor.rgb())); |
111 } | 115 } |
112 | 116 |
113 void GraphicsContextState::setStrokePattern(const PassRefPtr<Pattern> pattern) | 117 void GraphicsContextState::setStrokePattern(const PassRefPtr<Pattern> pattern) |
114 { | 118 { |
115 m_strokeData.setColor(Color::black); | 119 m_strokeColor = Color::black; |
116 m_strokeData.clearGradient(); | 120 m_strokeGradient.clear(); |
117 m_strokeData.setPattern(pattern); | 121 m_strokePattern = pattern; |
118 m_strokePaint.setColor(applyAlpha(SK_ColorBLACK)); | 122 m_strokePaint.setColor(applyAlpha(SK_ColorBLACK)); |
119 m_strokePaint.setShader(m_strokeData.pattern()->shader()); | 123 m_strokePaint.setShader(m_strokePattern->shader()); |
120 } | 124 } |
121 | 125 |
122 void GraphicsContextState::clearStrokePattern() | 126 void GraphicsContextState::clearStrokePattern() |
123 { | 127 { |
124 m_strokeData.clearPattern(); | 128 m_strokePattern.clear(); |
125 ASSERT(!m_strokeData.gradient()); | 129 ASSERT(!m_strokeGradient); |
126 m_strokePaint.setColor(applyAlpha(m_strokeData.color().rgb())); | 130 m_strokePaint.setColor(applyAlpha(m_strokeColor.rgb())); |
127 } | 131 } |
128 | 132 |
129 void GraphicsContextState::setLineCap(LineCap cap) | 133 void GraphicsContextState::setLineCap(LineCap cap) |
130 { | 134 { |
131 m_strokeData.setLineCap(cap); | 135 m_strokeData.setLineCap(cap); |
132 m_strokePaint.setStrokeCap((SkPaint::Cap)cap); | 136 m_strokePaint.setStrokeCap((SkPaint::Cap)cap); |
133 } | 137 } |
134 | 138 |
135 void GraphicsContextState::setLineJoin(LineJoin join) | 139 void GraphicsContextState::setLineJoin(LineJoin join) |
136 { | 140 { |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 | 206 |
203 void GraphicsContextState::setAlphaAsFloat(float alpha) | 207 void GraphicsContextState::setAlphaAsFloat(float alpha) |
204 { | 208 { |
205 if (alpha < 0) { | 209 if (alpha < 0) { |
206 m_alpha = 0; | 210 m_alpha = 0; |
207 } else { | 211 } else { |
208 m_alpha = roundf(alpha * 256); | 212 m_alpha = roundf(alpha * 256); |
209 if (m_alpha > 256) | 213 if (m_alpha > 256) |
210 m_alpha = 256; | 214 m_alpha = 256; |
211 } | 215 } |
212 m_strokePaint.setColor(applyAlpha(m_strokeData.color().rgb())); | 216 m_strokePaint.setColor(applyAlpha(m_strokeColor.rgb())); |
213 m_fillPaint.setColor(applyAlpha(m_fillColor.rgb())); | 217 m_fillPaint.setColor(applyAlpha(m_fillColor.rgb())); |
214 } | 218 } |
215 | 219 |
216 void GraphicsContextState::setLineDash(const DashArray& dashes, float dashOffset
) | 220 void GraphicsContextState::setLineDash(const DashArray& dashes, float dashOffset
) |
217 { | 221 { |
218 m_strokeData.setLineDash(dashes, dashOffset); | 222 m_strokeData.setLineDash(dashes, dashOffset); |
219 } | 223 } |
220 | 224 |
221 void GraphicsContextState::setColorFilter(PassRefPtr<SkColorFilter> colorFilter) | 225 void GraphicsContextState::setColorFilter(PassRefPtr<SkColorFilter> colorFilter) |
222 { | 226 { |
(...skipping 20 matching lines...) Expand all Loading... |
243 | 247 |
244 void GraphicsContextState::setShouldAntialias(bool shouldAntialias) | 248 void GraphicsContextState::setShouldAntialias(bool shouldAntialias) |
245 { | 249 { |
246 m_shouldAntialias = shouldAntialias; | 250 m_shouldAntialias = shouldAntialias; |
247 m_strokePaint.setAntiAlias(shouldAntialias); | 251 m_strokePaint.setAntiAlias(shouldAntialias); |
248 m_fillPaint.setAntiAlias(shouldAntialias); | 252 m_fillPaint.setAntiAlias(shouldAntialias); |
249 } | 253 } |
250 | 254 |
251 | 255 |
252 } // namespace blink | 256 } // namespace blink |
OLD | NEW |