Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "config.h" | |
| 6 #include "platform/graphics/GraphicsContextState.h" | |
| 7 | |
| 8 namespace WebCore { | |
| 9 | |
| 10 GraphicsContextState::GraphicsContextState() | |
| 11 : m_fillColor(Color::black) | |
| 12 , m_fillRule(RULE_NONZERO) | |
| 13 , m_textDrawingMode(TextModeFill) | |
| 14 , m_alpha(256) | |
| 15 , m_xferMode(nullptr) | |
| 16 , m_compositeOperator(CompositeSourceOver) | |
| 17 , m_blendMode(blink::WebBlendModeNormal) | |
| 18 #if USE(LOW_QUALITY_IMAGE_INTERPOLATION) | |
| 19 , m_interpolationQuality(InterpolationLow) | |
| 20 #else | |
| 21 , m_interpolationQuality(InterpolationHigh) | |
| 22 #endif | |
| 23 , m_saveCount(0) | |
| 24 , m_shouldAntialias(true) | |
| 25 , m_shouldSmoothFonts(true) | |
| 26 , m_shouldClampToSourceRect(true) | |
| 27 { | |
| 28 m_strokePaint.setStyle(SkPaint::kStroke_Style); | |
| 29 m_strokePaint.setStrokeWidth(SkFloatToScalar(m_strokeData.thickness())); | |
| 30 m_strokePaint.setColor(applyAlpha(m_strokeData.color().rgb())); | |
| 31 m_strokePaint.setStrokeCap(SkPaint::kDefault_Cap); | |
| 32 m_strokePaint.setStrokeJoin(SkPaint::kDefault_Join); | |
| 33 m_strokePaint.setStrokeMiter(SkFloatToScalar(m_strokeData.miterLimit())); | |
| 34 m_strokePaint.setFilterBitmap(m_interpolationQuality != InterpolationNone); | |
| 35 m_strokePaint.setAntiAlias(m_shouldAntialias); | |
| 36 m_fillPaint.setColor(applyAlpha(m_fillColor.rgb())); | |
| 37 m_fillPaint.setFilterBitmap(m_interpolationQuality != InterpolationNone); | |
| 38 m_fillPaint.setAntiAlias(m_shouldAntialias); | |
| 39 } | |
| 40 | |
| 41 void GraphicsContextState::copy(GraphicsContextState* source) | |
| 42 { | |
| 43 m_strokePaint = source->m_strokePaint; | |
| 44 m_fillPaint = source->m_fillPaint; | |
| 45 m_strokeData = source->m_strokeData; | |
| 46 m_fillColor = source->m_fillColor; | |
| 47 m_fillRule = source->m_fillRule; | |
| 48 m_fillGradient = source->m_fillGradient; | |
| 49 m_fillPattern = source->m_fillPattern; | |
| 50 m_looper = source->m_looper; | |
| 51 m_textDrawingMode = source->m_textDrawingMode; | |
| 52 m_alpha = source->m_alpha; | |
| 53 m_xferMode = source->m_xferMode; | |
| 54 m_colorFilter = source->m_colorFilter; | |
| 55 m_compositeOperator = source->m_compositeOperator; | |
| 56 m_blendMode = source->m_blendMode; | |
| 57 m_interpolationQuality = source->m_interpolationQuality; | |
| 58 m_saveCount = 0; | |
| 59 m_shouldAntialias = source->m_shouldAntialias; | |
| 60 m_shouldSmoothFonts = source->m_shouldSmoothFonts; | |
| 61 m_shouldClampToSourceRect = source->m_shouldClampToSourceRect; | |
| 62 } | |
| 63 | |
| 64 const SkPaint& GraphicsContextState::strokePaint() const | |
| 65 { | |
| 66 if (m_strokeData.gradient() && m_strokeData.gradient()->shaderChanged()) | |
| 67 m_strokePaint.setShader(m_strokeData.gradient()->shader()); | |
| 68 return m_strokePaint; | |
| 69 } | |
| 70 | |
| 71 const SkPaint& GraphicsContextState::fillPaint() const | |
| 72 { | |
| 73 if (m_fillGradient && m_fillGradient->shaderChanged()) | |
| 74 m_fillPaint.setShader(m_fillGradient->shader()); | |
|
Stephen White
2014/03/04 15:24:13
I'm surprised not to see patterns here. How are th
Stephen Chennney
2014/03/04 17:41:29
Patterns have no methods that change the shader po
| |
| 75 return m_fillPaint; | |
| 76 } | |
| 77 | |
| 78 void GraphicsContextState::setStrokeThickness(const float thickness) | |
| 79 { | |
| 80 m_strokeData.setThickness(thickness); | |
| 81 m_strokePaint.setStrokeWidth(SkFloatToScalar(thickness)); | |
| 82 } | |
| 83 | |
| 84 void GraphicsContextState::setStrokeColor(const Color& color) | |
| 85 { | |
| 86 m_strokeData.clearGradient(); | |
| 87 m_strokeData.clearPattern(); | |
| 88 m_strokeData.setColor(color); | |
| 89 m_strokePaint.setColor(applyAlpha(color.rgb())); | |
| 90 m_strokePaint.setShader(0); | |
| 91 } | |
| 92 | |
| 93 void GraphicsContextState::setStrokeGradient(const PassRefPtr<Gradient> gradient ) | |
| 94 { | |
| 95 m_strokeData.setColor(Color::black); | |
| 96 m_strokeData.clearPattern(); | |
| 97 m_strokeData.setGradient(gradient); | |
| 98 m_strokePaint.setColor(applyAlpha(SK_ColorBLACK)); | |
| 99 m_strokePaint.setShader(m_strokeData.gradient()->shader()); | |
| 100 } | |
| 101 | |
| 102 void GraphicsContextState::clearStrokeGradient() | |
| 103 { | |
| 104 m_strokeData.clearGradient(); | |
| 105 ASSERT(!m_strokeData.pattern()); | |
| 106 m_strokePaint.setColor(applyAlpha(m_strokeData.color().rgb())); | |
| 107 } | |
| 108 | |
| 109 void GraphicsContextState::setStrokePattern(const PassRefPtr<Pattern> pattern) | |
| 110 { | |
| 111 m_strokeData.setColor(Color::black); | |
| 112 m_strokeData.clearGradient(); | |
| 113 m_strokeData.setPattern(pattern); | |
| 114 m_strokePaint.setColor(applyAlpha(SK_ColorBLACK)); | |
| 115 m_strokePaint.setShader(m_strokeData.pattern()->shader()); | |
| 116 } | |
| 117 | |
| 118 void GraphicsContextState::clearStrokePattern() | |
| 119 { | |
| 120 m_strokeData.clearPattern(); | |
| 121 ASSERT(!m_strokeData.gradient()); | |
| 122 m_strokePaint.setColor(applyAlpha(m_strokeData.color().rgb())); | |
| 123 } | |
| 124 | |
| 125 void GraphicsContextState::setLineCap(const LineCap cap) | |
| 126 { | |
| 127 m_strokeData.setLineCap(cap); | |
| 128 m_strokePaint.setStrokeCap((SkPaint::Cap)cap); | |
| 129 } | |
| 130 | |
| 131 void GraphicsContextState::setLineJoin(const LineJoin join) | |
| 132 { | |
| 133 m_strokeData.setLineJoin(join); | |
| 134 m_strokePaint.setStrokeJoin((SkPaint::Join)join); | |
| 135 } | |
| 136 | |
| 137 void GraphicsContextState::setMiterLimit(const float miterLimit) | |
| 138 { | |
| 139 m_strokeData.setMiterLimit(miterLimit); | |
| 140 m_strokePaint.setStrokeMiter(SkFloatToScalar(miterLimit)); | |
| 141 } | |
| 142 | |
| 143 void GraphicsContextState::setFillColor(const Color& color) | |
| 144 { | |
| 145 m_fillColor = color; | |
| 146 m_fillGradient.clear(); | |
| 147 m_fillPattern.clear(); | |
| 148 m_fillPaint.setColor(applyAlpha(color.rgb())); | |
| 149 m_fillPaint.setShader(0); | |
| 150 } | |
| 151 | |
| 152 void GraphicsContextState::setFillGradient(const PassRefPtr<Gradient> gradient) | |
| 153 { | |
| 154 m_fillColor = Color::black; | |
| 155 m_fillPattern.clear(); | |
| 156 m_fillGradient = gradient; | |
| 157 m_fillPaint.setColor(applyAlpha(SK_ColorBLACK)); | |
| 158 m_fillPaint.setShader(m_fillGradient->shader()); | |
| 159 } | |
| 160 | |
| 161 void GraphicsContextState::clearFillGradient() | |
| 162 { | |
| 163 m_fillGradient.clear(); | |
| 164 ASSERT(!m_fillPattern); | |
| 165 m_fillPaint.setColor(applyAlpha(m_fillColor.rgb())); | |
| 166 } | |
| 167 | |
| 168 void GraphicsContextState::setFillPattern(const PassRefPtr<Pattern> pattern) | |
| 169 { | |
| 170 m_fillColor = Color::black; | |
| 171 m_fillGradient.clear(); | |
| 172 m_fillPattern = pattern; | |
| 173 m_fillPaint.setColor(applyAlpha(SK_ColorBLACK)); | |
| 174 m_fillPaint.setShader(m_fillPattern->shader()); | |
| 175 } | |
| 176 | |
| 177 void GraphicsContextState::clearFillPattern() | |
| 178 { | |
| 179 m_fillPattern.clear(); | |
| 180 ASSERT(!m_fillGradient); | |
| 181 m_fillPaint.setColor(applyAlpha(m_fillColor.rgb())); | |
| 182 } | |
| 183 | |
| 184 // Shadow. (This will need tweaking if we use draw loopers for other things.) | |
| 185 void GraphicsContextState::setDrawLooper(PassRefPtr<SkDrawLooper> drawLooper) | |
| 186 { | |
| 187 m_looper = drawLooper; | |
| 188 m_strokePaint.setLooper(m_looper.get()); | |
| 189 m_fillPaint.setLooper(m_looper.get()); | |
| 190 } | |
| 191 | |
| 192 void GraphicsContextState::clearDrawLooper() | |
| 193 { | |
| 194 m_looper.clear(); | |
| 195 m_strokePaint.setLooper(0); | |
| 196 m_fillPaint.setLooper(0); | |
| 197 } | |
| 198 | |
| 199 void GraphicsContextState::setAlpha(const float alpha) | |
| 200 { | |
| 201 if (alpha < 0) { | |
| 202 m_alpha = 0; | |
| 203 } else { | |
| 204 m_alpha = roundf(alpha * 256); | |
| 205 if (m_alpha > 256) | |
| 206 m_alpha = 256; | |
| 207 } | |
| 208 m_strokePaint.setColor(applyAlpha(m_strokeData.color().rgb())); | |
| 209 m_fillPaint.setColor(applyAlpha(m_fillColor.rgb())); | |
| 210 } | |
| 211 | |
| 212 void GraphicsContextState::setColorFilter(PassRefPtr<SkColorFilter> colorFilter) | |
| 213 { | |
| 214 m_colorFilter = colorFilter; | |
| 215 m_strokePaint.setColorFilter(m_colorFilter.get()); | |
| 216 m_fillPaint.setColorFilter(m_colorFilter.get()); | |
| 217 } | |
| 218 | |
| 219 void GraphicsContextState::setCompositeOperation(const CompositeOperator composi teOperation, const blink::WebBlendMode blendMode) | |
| 220 { | |
| 221 m_compositeOperator = compositeOperation; | |
| 222 m_blendMode = blendMode; | |
| 223 m_xferMode = WebCoreCompositeToSkiaComposite(compositeOperation, blendMode); | |
| 224 m_strokePaint.setXfermode(m_xferMode.get()); | |
| 225 m_fillPaint.setXfermode(m_xferMode.get()); | |
| 226 } | |
| 227 | |
| 228 void GraphicsContextState::setInterpolationQuality(const InterpolationQuality qu ality) | |
| 229 { | |
| 230 m_interpolationQuality = quality; | |
| 231 m_strokePaint.setFilterBitmap(quality != InterpolationNone); | |
| 232 m_fillPaint.setFilterBitmap(quality != InterpolationNone); | |
| 233 } | |
| 234 | |
| 235 void GraphicsContextState::setShouldAntialias(const bool shouldAntialias) | |
| 236 { | |
| 237 m_shouldAntialias = shouldAntialias; | |
| 238 m_strokePaint.setAntiAlias(shouldAntialias); | |
| 239 m_fillPaint.setAntiAlias(shouldAntialias); | |
| 240 } | |
| 241 | |
| 242 | |
| 243 } // namespace WebCore | |
| OLD | NEW |