| 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" | |
| 9 | |
| 10 namespace blink { | 8 namespace blink { |
| 11 | 9 |
| 12 GraphicsContextState::GraphicsContextState() | 10 GraphicsContextState::GraphicsContextState() |
| 13 : m_strokeColor(Color::black) | 11 : m_strokeColor(Color::black) |
| 14 , m_fillColor(Color::black) | 12 , m_fillColor(Color::black) |
| 15 , m_fillRule(RULE_NONZERO) | 13 , m_fillRule(RULE_NONZERO) |
| 16 , m_textDrawingMode(TextModeFill) | 14 , m_textDrawingMode(TextModeFill) |
| 17 , m_alpha(256) | 15 , m_alpha(256) |
| 18 , m_compositeOperation(SkXfermode::kSrcOver_Mode) | 16 , m_compositeOperation(SkXfermode::kSrcOver_Mode) |
| 19 , m_interpolationQuality(InterpolationDefault) | 17 , m_interpolationQuality(InterpolationDefault) |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 | 90 |
| 93 void GraphicsContextState::setStrokeColor(const Color& color) | 91 void GraphicsContextState::setStrokeColor(const Color& color) |
| 94 { | 92 { |
| 95 m_strokeGradient.clear(); | 93 m_strokeGradient.clear(); |
| 96 m_strokePattern.clear(); | 94 m_strokePattern.clear(); |
| 97 m_strokeColor = color; | 95 m_strokeColor = color; |
| 98 m_strokePaint.setColor(applyAlpha(color.rgb())); | 96 m_strokePaint.setColor(applyAlpha(color.rgb())); |
| 99 m_strokePaint.setShader(0); | 97 m_strokePaint.setShader(0); |
| 100 } | 98 } |
| 101 | 99 |
| 102 void GraphicsContextState::setStrokeGradient(const PassRefPtr<Gradient> gradient
) | 100 void GraphicsContextState::setStrokeGradient(const PassRefPtr<Gradient> gradient
, float alpha) |
| 103 { | 101 { |
| 104 m_strokeColor = Color::black; | 102 m_strokeColor = Color::black; |
| 105 m_strokePattern.clear(); | 103 m_strokePattern.clear(); |
| 106 m_strokeGradient = gradient; | 104 m_strokeGradient = gradient; |
| 107 m_strokePaint.setColor(applyAlpha(SK_ColorBLACK)); | 105 m_strokePaint.setColor(multiplyAlpha(applyAlpha(SK_ColorBLACK), alpha)); |
| 108 m_strokePaint.setShader(m_strokeGradient->shader()); | 106 m_strokePaint.setShader(m_strokeGradient->shader()); |
| 109 } | 107 } |
| 110 | 108 |
| 111 void GraphicsContextState::clearStrokeGradient() | 109 void GraphicsContextState::clearStrokeGradient() |
| 112 { | 110 { |
| 113 m_strokeGradient.clear(); | 111 m_strokeGradient.clear(); |
| 114 ASSERT(!m_strokePattern); | 112 ASSERT(!m_strokePattern); |
| 115 m_strokePaint.setColor(applyAlpha(m_strokeColor.rgb())); | 113 m_strokePaint.setColor(applyAlpha(m_strokeColor.rgb())); |
| 116 } | 114 } |
| 117 | 115 |
| 118 void GraphicsContextState::setStrokePattern(const PassRefPtr<Pattern> pattern) | 116 void GraphicsContextState::setStrokePattern(const PassRefPtr<Pattern> pattern, f
loat alpha) |
| 119 { | 117 { |
| 120 m_strokeColor = Color::black; | 118 m_strokeColor = Color::black; |
| 121 m_strokeGradient.clear(); | 119 m_strokeGradient.clear(); |
| 122 m_strokePattern = pattern; | 120 m_strokePattern = pattern; |
| 123 m_strokePaint.setColor(applyAlpha(SK_ColorBLACK)); | 121 m_strokePaint.setColor(multiplyAlpha(applyAlpha(SK_ColorBLACK), alpha)); |
| 124 m_strokePaint.setShader(m_strokePattern->shader()); | 122 m_strokePaint.setShader(m_strokePattern->shader()); |
| 125 } | 123 } |
| 126 | 124 |
| 127 void GraphicsContextState::clearStrokePattern() | 125 void GraphicsContextState::clearStrokePattern() |
| 128 { | 126 { |
| 129 m_strokePattern.clear(); | 127 m_strokePattern.clear(); |
| 130 ASSERT(!m_strokeGradient); | 128 ASSERT(!m_strokeGradient); |
| 131 m_strokePaint.setColor(applyAlpha(m_strokeColor.rgb())); | 129 m_strokePaint.setColor(applyAlpha(m_strokeColor.rgb())); |
| 132 } | 130 } |
| 133 | 131 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 151 | 149 |
| 152 void GraphicsContextState::setFillColor(const Color& color) | 150 void GraphicsContextState::setFillColor(const Color& color) |
| 153 { | 151 { |
| 154 m_fillColor = color; | 152 m_fillColor = color; |
| 155 m_fillGradient.clear(); | 153 m_fillGradient.clear(); |
| 156 m_fillPattern.clear(); | 154 m_fillPattern.clear(); |
| 157 m_fillPaint.setColor(applyAlpha(color.rgb())); | 155 m_fillPaint.setColor(applyAlpha(color.rgb())); |
| 158 m_fillPaint.setShader(0); | 156 m_fillPaint.setShader(0); |
| 159 } | 157 } |
| 160 | 158 |
| 161 void GraphicsContextState::setFillGradient(const PassRefPtr<Gradient> gradient) | 159 void GraphicsContextState::setFillGradient(const PassRefPtr<Gradient> gradient,
float alpha) |
| 162 { | 160 { |
| 163 m_fillColor = Color::black; | 161 m_fillColor = Color::black; |
| 164 m_fillPattern.clear(); | 162 m_fillPattern.clear(); |
| 165 m_fillGradient = gradient; | 163 m_fillGradient = gradient; |
| 166 m_fillPaint.setColor(applyAlpha(SK_ColorBLACK)); | 164 m_fillPaint.setColor(multiplyAlpha(applyAlpha(SK_ColorBLACK), alpha)); |
| 167 m_fillPaint.setShader(m_fillGradient->shader()); | 165 m_fillPaint.setShader(m_fillGradient->shader()); |
| 168 } | 166 } |
| 169 | 167 |
| 170 void GraphicsContextState::clearFillGradient() | 168 void GraphicsContextState::clearFillGradient() |
| 171 { | 169 { |
| 172 m_fillGradient.clear(); | 170 m_fillGradient.clear(); |
| 173 ASSERT(!m_fillPattern); | 171 ASSERT(!m_fillPattern); |
| 174 m_fillPaint.setColor(applyAlpha(m_fillColor.rgb())); | 172 m_fillPaint.setColor(applyAlpha(m_fillColor.rgb())); |
| 175 } | 173 } |
| 176 | 174 |
| 177 void GraphicsContextState::setFillPattern(const PassRefPtr<Pattern> pattern) | 175 void GraphicsContextState::setFillPattern(const PassRefPtr<Pattern> pattern, flo
at alpha) |
| 178 { | 176 { |
| 179 m_fillColor = Color::black; | 177 m_fillColor = Color::black; |
| 180 m_fillGradient.clear(); | 178 m_fillGradient.clear(); |
| 181 m_fillPattern = pattern; | 179 m_fillPattern = pattern; |
| 182 m_fillPaint.setColor(applyAlpha(SK_ColorBLACK)); | 180 m_fillPaint.setColor(multiplyAlpha(applyAlpha(SK_ColorBLACK), alpha)); |
| 183 m_fillPaint.setShader(m_fillPattern->shader()); | 181 m_fillPaint.setShader(m_fillPattern->shader()); |
| 184 } | 182 } |
| 185 | 183 |
| 186 void GraphicsContextState::clearFillPattern() | 184 void GraphicsContextState::clearFillPattern() |
| 187 { | 185 { |
| 188 m_fillPattern.clear(); | 186 m_fillPattern.clear(); |
| 189 ASSERT(!m_fillGradient); | 187 ASSERT(!m_fillGradient); |
| 190 m_fillPaint.setColor(applyAlpha(m_fillColor.rgb())); | 188 m_fillPaint.setColor(applyAlpha(m_fillColor.rgb())); |
| 191 } | 189 } |
| 192 | 190 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 210 m_dropShadowImageFilter = dropShadowImageFilter; | 208 m_dropShadowImageFilter = dropShadowImageFilter; |
| 211 } | 209 } |
| 212 | 210 |
| 213 void GraphicsContextState::clearDropShadowImageFilter() | 211 void GraphicsContextState::clearDropShadowImageFilter() |
| 214 { | 212 { |
| 215 m_dropShadowImageFilter.clear(); | 213 m_dropShadowImageFilter.clear(); |
| 216 } | 214 } |
| 217 | 215 |
| 218 void GraphicsContextState::setAlphaAsFloat(float alpha) | 216 void GraphicsContextState::setAlphaAsFloat(float alpha) |
| 219 { | 217 { |
| 220 if (alpha < 0) { | 218 m_alpha = clampedAlphaForBlending(alpha); |
| 221 m_alpha = 0; | |
| 222 } else { | |
| 223 m_alpha = roundf(alpha * 256); | |
| 224 if (m_alpha > 256) | |
| 225 m_alpha = 256; | |
| 226 } | |
| 227 m_strokePaint.setColor(applyAlpha(m_strokeColor.rgb())); | 219 m_strokePaint.setColor(applyAlpha(m_strokeColor.rgb())); |
| 228 m_fillPaint.setColor(applyAlpha(m_fillColor.rgb())); | 220 m_fillPaint.setColor(applyAlpha(m_fillColor.rgb())); |
| 229 } | 221 } |
| 230 | 222 |
| 231 void GraphicsContextState::setLineDash(const DashArray& dashes, float dashOffset
) | 223 void GraphicsContextState::setLineDash(const DashArray& dashes, float dashOffset
) |
| 232 { | 224 { |
| 233 m_strokeData.setLineDash(dashes, dashOffset); | 225 m_strokeData.setLineDash(dashes, dashOffset); |
| 234 } | 226 } |
| 235 | 227 |
| 236 void GraphicsContextState::setColorFilter(PassRefPtr<SkColorFilter> colorFilter) | 228 void GraphicsContextState::setColorFilter(PassRefPtr<SkColorFilter> colorFilter) |
| (...skipping 29 matching lines...) Expand all Loading... |
| 266 return m_hasComplexClip; | 258 return m_hasComplexClip; |
| 267 } | 259 } |
| 268 | 260 |
| 269 void GraphicsContextState::setHasComplexClip() | 261 void GraphicsContextState::setHasComplexClip() |
| 270 { | 262 { |
| 271 m_hasComplexClip = true; | 263 m_hasComplexClip = true; |
| 272 } | 264 } |
| 273 | 265 |
| 274 | 266 |
| 275 } // namespace blink | 267 } // namespace blink |
| OLD | NEW |