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_fillRule(RULE_NONZERO) | 13 , m_fillRule(RULE_NONZERO) |
14 , m_textDrawingMode(TextModeFill) | 14 , m_textDrawingMode(TextModeFill) |
15 , m_alpha(256) | 15 , m_alpha(256) |
16 , m_compositeOperation(SkXfermode::kSrcOver_Mode) | 16 , m_compositeOperation(SkXfermode::kSrcOver_Mode) |
17 , m_interpolationQuality(InterpolationDefault) | 17 , m_interpolationQuality(InterpolationDefault) |
18 , m_saveCount(0) | 18 , m_saveCount(0) |
19 , m_shouldAntialias(true) | 19 , m_shouldAntialias(true) |
20 , m_shouldClampToSourceRect(true) | |
21 { | 20 { |
22 m_strokePaint.setStyle(SkPaint::kStroke_Style); | 21 m_strokePaint.setStyle(SkPaint::kStroke_Style); |
23 m_strokePaint.setStrokeWidth(SkFloatToScalar(m_strokeData.thickness())); | 22 m_strokePaint.setStrokeWidth(SkFloatToScalar(m_strokeData.thickness())); |
24 m_strokePaint.setColor(applyAlpha(m_strokeColor.rgb())); | 23 m_strokePaint.setColor(applyAlpha(m_strokeColor.rgb())); |
25 m_strokePaint.setStrokeCap(SkPaint::kDefault_Cap); | 24 m_strokePaint.setStrokeCap(SkPaint::kDefault_Cap); |
26 m_strokePaint.setStrokeJoin(SkPaint::kDefault_Join); | 25 m_strokePaint.setStrokeJoin(SkPaint::kDefault_Join); |
27 m_strokePaint.setStrokeMiter(SkFloatToScalar(m_strokeData.miterLimit())); | 26 m_strokePaint.setStrokeMiter(SkFloatToScalar(m_strokeData.miterLimit())); |
28 m_strokePaint.setFilterQuality(WebCoreInterpolationQualityToSkFilterQuality(
m_interpolationQuality)); | 27 m_strokePaint.setFilterQuality(WebCoreInterpolationQualityToSkFilterQuality(
m_interpolationQuality)); |
29 m_strokePaint.setAntiAlias(m_shouldAntialias); | 28 m_strokePaint.setAntiAlias(m_shouldAntialias); |
30 m_fillPaint.setColor(applyAlpha(m_fillColor.rgb())); | 29 m_fillPaint.setColor(applyAlpha(m_fillColor.rgb())); |
31 m_fillPaint.setFilterQuality(WebCoreInterpolationQualityToSkFilterQuality(m_
interpolationQuality)); | 30 m_fillPaint.setFilterQuality(WebCoreInterpolationQualityToSkFilterQuality(m_
interpolationQuality)); |
32 m_fillPaint.setAntiAlias(m_shouldAntialias); | 31 m_fillPaint.setAntiAlias(m_shouldAntialias); |
33 } | 32 } |
34 | 33 |
35 GraphicsContextState::GraphicsContextState(const GraphicsContextState& other) | 34 GraphicsContextState::GraphicsContextState(const GraphicsContextState& other) |
36 : m_strokePaint(other.m_strokePaint) | 35 : m_strokePaint(other.m_strokePaint) |
37 , m_fillPaint(other.m_fillPaint) | 36 , m_fillPaint(other.m_fillPaint) |
38 , m_strokeData(other.m_strokeData) | 37 , m_strokeData(other.m_strokeData) |
39 , m_strokeColor(other.m_strokeColor) | 38 , m_strokeColor(other.m_strokeColor) |
40 , m_strokeGradient(other.m_strokeGradient) | 39 , m_strokeGradient(other.m_strokeGradient) |
41 , m_strokePattern(other.m_strokePattern) | 40 , m_strokePattern(other.m_strokePattern) |
42 , m_fillColor(other.m_fillColor) | 41 , m_fillColor(other.m_fillColor) |
43 , m_fillRule(other.m_fillRule) | 42 , m_fillRule(other.m_fillRule) |
44 , m_fillGradient(other.m_fillGradient) | 43 , m_fillGradient(other.m_fillGradient) |
45 , m_fillPattern(other.m_fillPattern) | 44 , m_fillPattern(other.m_fillPattern) |
46 , m_looper(other.m_looper) | 45 , m_looper(other.m_looper) |
47 , m_dropShadowImageFilter(other.m_dropShadowImageFilter) | |
48 , m_textDrawingMode(other.m_textDrawingMode) | 46 , m_textDrawingMode(other.m_textDrawingMode) |
49 , m_alpha(other.m_alpha) | 47 , m_alpha(other.m_alpha) |
50 , m_colorFilter(other.m_colorFilter) | 48 , m_colorFilter(other.m_colorFilter) |
51 , m_compositeOperation(other.m_compositeOperation) | 49 , m_compositeOperation(other.m_compositeOperation) |
52 , m_interpolationQuality(other.m_interpolationQuality) | 50 , m_interpolationQuality(other.m_interpolationQuality) |
53 , m_saveCount(0) | 51 , m_saveCount(0) |
54 , m_shouldAntialias(other.m_shouldAntialias) | 52 , m_shouldAntialias(other.m_shouldAntialias) { } |
55 , m_shouldClampToSourceRect(other.m_shouldClampToSourceRect) { } | |
56 | 53 |
57 void GraphicsContextState::copy(const GraphicsContextState& source) | 54 void GraphicsContextState::copy(const GraphicsContextState& source) |
58 { | 55 { |
59 this->~GraphicsContextState(); | 56 this->~GraphicsContextState(); |
60 new (this) GraphicsContextState(source); | 57 new (this) GraphicsContextState(source); |
61 } | 58 } |
62 | 59 |
63 const SkPaint& GraphicsContextState::strokePaint(int strokedPathLength) const | 60 const SkPaint& GraphicsContextState::strokePaint(int strokedPathLength) const |
64 { | 61 { |
65 if (m_strokeGradient && m_strokeGradient->shaderChanged()) | 62 if (m_strokeGradient && m_strokeGradient->shaderChanged()) |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 m_fillPaint.setLooper(m_looper.get()); | 163 m_fillPaint.setLooper(m_looper.get()); |
167 } | 164 } |
168 | 165 |
169 void GraphicsContextState::clearDrawLooper() | 166 void GraphicsContextState::clearDrawLooper() |
170 { | 167 { |
171 m_looper.clear(); | 168 m_looper.clear(); |
172 m_strokePaint.setLooper(0); | 169 m_strokePaint.setLooper(0); |
173 m_fillPaint.setLooper(0); | 170 m_fillPaint.setLooper(0); |
174 } | 171 } |
175 | 172 |
176 void GraphicsContextState::setDropShadowImageFilter(PassRefPtr<SkImageFilter> dr
opShadowImageFilter) | |
177 { | |
178 m_dropShadowImageFilter = dropShadowImageFilter; | |
179 } | |
180 | |
181 void GraphicsContextState::clearDropShadowImageFilter() | |
182 { | |
183 m_dropShadowImageFilter.clear(); | |
184 } | |
185 | |
186 void GraphicsContextState::setAlphaAsFloat(float alpha) | |
187 { | |
188 m_alpha = clampedAlphaForBlending(alpha); | |
189 m_strokePaint.setColor(applyAlpha(m_strokeColor.rgb())); | |
190 m_fillPaint.setColor(applyAlpha(m_fillColor.rgb())); | |
191 } | |
192 | |
193 void GraphicsContextState::setLineDash(const DashArray& dashes, float dashOffset
) | 173 void GraphicsContextState::setLineDash(const DashArray& dashes, float dashOffset
) |
194 { | 174 { |
195 m_strokeData.setLineDash(dashes, dashOffset); | 175 m_strokeData.setLineDash(dashes, dashOffset); |
196 } | 176 } |
197 | 177 |
198 void GraphicsContextState::setColorFilter(PassRefPtr<SkColorFilter> colorFilter) | 178 void GraphicsContextState::setColorFilter(PassRefPtr<SkColorFilter> colorFilter) |
199 { | 179 { |
200 m_colorFilter = colorFilter; | 180 m_colorFilter = colorFilter; |
201 m_strokePaint.setColorFilter(m_colorFilter.get()); | 181 m_strokePaint.setColorFilter(m_colorFilter.get()); |
202 m_fillPaint.setColorFilter(m_colorFilter.get()); | 182 m_fillPaint.setColorFilter(m_colorFilter.get()); |
(...skipping 14 matching lines...) Expand all Loading... |
217 } | 197 } |
218 | 198 |
219 void GraphicsContextState::setShouldAntialias(bool shouldAntialias) | 199 void GraphicsContextState::setShouldAntialias(bool shouldAntialias) |
220 { | 200 { |
221 m_shouldAntialias = shouldAntialias; | 201 m_shouldAntialias = shouldAntialias; |
222 m_strokePaint.setAntiAlias(shouldAntialias); | 202 m_strokePaint.setAntiAlias(shouldAntialias); |
223 m_fillPaint.setAntiAlias(shouldAntialias); | 203 m_fillPaint.setAntiAlias(shouldAntialias); |
224 } | 204 } |
225 | 205 |
226 } // namespace blink | 206 } // namespace blink |
OLD | NEW |