Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(194)

Side by Side Diff: Source/platform/graphics/GraphicsContextState.cpp

Issue 1093673002: Removing the dependency on GraphicsContext for drawing images in 2D canvas (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: rebase Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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)
16 , m_compositeOperation(SkXfermode::kSrcOver_Mode)
17 , m_interpolationQuality(InterpolationDefault) 15 , m_interpolationQuality(InterpolationDefault)
18 , m_saveCount(0) 16 , m_saveCount(0)
19 , m_shouldAntialias(true) 17 , m_shouldAntialias(true)
20 , m_shouldClampToSourceRect(true)
21 { 18 {
22 m_strokePaint.setStyle(SkPaint::kStroke_Style); 19 m_strokePaint.setStyle(SkPaint::kStroke_Style);
23 m_strokePaint.setStrokeWidth(SkFloatToScalar(m_strokeData.thickness())); 20 m_strokePaint.setStrokeWidth(SkFloatToScalar(m_strokeData.thickness()));
24 m_strokePaint.setColor(applyAlpha(m_strokeColor.rgb())); 21 m_strokePaint.setColor(m_strokeColor.rgb());
25 m_strokePaint.setStrokeCap(SkPaint::kDefault_Cap); 22 m_strokePaint.setStrokeCap(SkPaint::kDefault_Cap);
26 m_strokePaint.setStrokeJoin(SkPaint::kDefault_Join); 23 m_strokePaint.setStrokeJoin(SkPaint::kDefault_Join);
27 m_strokePaint.setStrokeMiter(SkFloatToScalar(m_strokeData.miterLimit())); 24 m_strokePaint.setStrokeMiter(SkFloatToScalar(m_strokeData.miterLimit()));
28 m_strokePaint.setFilterQuality(WebCoreInterpolationQualityToSkFilterQuality( m_interpolationQuality)); 25 m_strokePaint.setFilterQuality(WebCoreInterpolationQualityToSkFilterQuality( m_interpolationQuality));
29 m_strokePaint.setAntiAlias(m_shouldAntialias); 26 m_strokePaint.setAntiAlias(m_shouldAntialias);
30 m_fillPaint.setColor(applyAlpha(m_fillColor.rgb())); 27 m_fillPaint.setColor(m_fillColor.rgb());
31 m_fillPaint.setFilterQuality(WebCoreInterpolationQualityToSkFilterQuality(m_ interpolationQuality)); 28 m_fillPaint.setFilterQuality(WebCoreInterpolationQualityToSkFilterQuality(m_ interpolationQuality));
32 m_fillPaint.setAntiAlias(m_shouldAntialias); 29 m_fillPaint.setAntiAlias(m_shouldAntialias);
33 } 30 }
34 31
35 GraphicsContextState::GraphicsContextState(const GraphicsContextState& other) 32 GraphicsContextState::GraphicsContextState(const GraphicsContextState& other)
36 : m_strokePaint(other.m_strokePaint) 33 : m_strokePaint(other.m_strokePaint)
37 , m_fillPaint(other.m_fillPaint) 34 , m_fillPaint(other.m_fillPaint)
38 , m_strokeData(other.m_strokeData) 35 , m_strokeData(other.m_strokeData)
39 , m_strokeColor(other.m_strokeColor) 36 , m_strokeColor(other.m_strokeColor)
40 , m_strokeGradient(other.m_strokeGradient) 37 , m_strokeGradient(other.m_strokeGradient)
41 , m_strokePattern(other.m_strokePattern) 38 , m_strokePattern(other.m_strokePattern)
42 , m_fillColor(other.m_fillColor) 39 , m_fillColor(other.m_fillColor)
43 , m_fillRule(other.m_fillRule) 40 , m_fillRule(other.m_fillRule)
44 , m_fillGradient(other.m_fillGradient) 41 , m_fillGradient(other.m_fillGradient)
45 , m_fillPattern(other.m_fillPattern) 42 , m_fillPattern(other.m_fillPattern)
46 , m_looper(other.m_looper) 43 , m_looper(other.m_looper)
47 , m_dropShadowImageFilter(other.m_dropShadowImageFilter)
48 , m_textDrawingMode(other.m_textDrawingMode) 44 , m_textDrawingMode(other.m_textDrawingMode)
49 , m_alpha(other.m_alpha)
50 , m_colorFilter(other.m_colorFilter) 45 , m_colorFilter(other.m_colorFilter)
51 , m_compositeOperation(other.m_compositeOperation)
52 , m_interpolationQuality(other.m_interpolationQuality) 46 , m_interpolationQuality(other.m_interpolationQuality)
53 , m_saveCount(0) 47 , m_saveCount(0)
54 , m_shouldAntialias(other.m_shouldAntialias) 48 , m_shouldAntialias(other.m_shouldAntialias) { }
55 , m_shouldClampToSourceRect(other.m_shouldClampToSourceRect) { }
56 49
57 void GraphicsContextState::copy(const GraphicsContextState& source) 50 void GraphicsContextState::copy(const GraphicsContextState& source)
58 { 51 {
59 this->~GraphicsContextState(); 52 this->~GraphicsContextState();
60 new (this) GraphicsContextState(source); 53 new (this) GraphicsContextState(source);
61 } 54 }
62 55
63 const SkPaint& GraphicsContextState::strokePaint(int strokedPathLength) const 56 const SkPaint& GraphicsContextState::strokePaint(int strokedPathLength) const
64 { 57 {
65 if (m_strokeGradient && m_strokeGradient->shaderChanged()) 58 if (m_strokeGradient && m_strokeGradient->shaderChanged())
(...skipping 18 matching lines...) Expand all
84 { 77 {
85 m_strokeData.setThickness(thickness); 78 m_strokeData.setThickness(thickness);
86 m_strokePaint.setStrokeWidth(SkFloatToScalar(thickness)); 79 m_strokePaint.setStrokeWidth(SkFloatToScalar(thickness));
87 } 80 }
88 81
89 void GraphicsContextState::setStrokeColor(const Color& color) 82 void GraphicsContextState::setStrokeColor(const Color& color)
90 { 83 {
91 m_strokeGradient.clear(); 84 m_strokeGradient.clear();
92 m_strokePattern.clear(); 85 m_strokePattern.clear();
93 m_strokeColor = color; 86 m_strokeColor = color;
94 m_strokePaint.setColor(applyAlpha(color.rgb())); 87 m_strokePaint.setColor(color.rgb());
95 m_strokePaint.setShader(0); 88 m_strokePaint.setShader(0);
96 } 89 }
97 90
98 void GraphicsContextState::setStrokeGradient(const PassRefPtr<Gradient> gradient , float alpha) 91 void GraphicsContextState::setStrokeGradient(const PassRefPtr<Gradient> gradient , float alpha)
99 { 92 {
100 m_strokeColor = Color::black; 93 m_strokeColor = Color::black;
101 m_strokePattern.clear(); 94 m_strokePattern.clear();
102 m_strokeGradient = gradient; 95 m_strokeGradient = gradient;
103 m_strokePaint.setColor(scaleAlpha(applyAlpha(SK_ColorBLACK), alpha)); 96 m_strokePaint.setColor(scaleAlpha(SK_ColorBLACK, alpha));
104 m_strokePaint.setShader(m_strokeGradient->shader()); 97 m_strokePaint.setShader(m_strokeGradient->shader());
105 } 98 }
106 99
107 void GraphicsContextState::setStrokePattern(const PassRefPtr<Pattern> pattern, f loat alpha) 100 void GraphicsContextState::setStrokePattern(const PassRefPtr<Pattern> pattern, f loat alpha)
108 { 101 {
109 m_strokeColor = Color::black; 102 m_strokeColor = Color::black;
110 m_strokeGradient.clear(); 103 m_strokeGradient.clear();
111 m_strokePattern = pattern; 104 m_strokePattern = pattern;
112 m_strokePaint.setColor(scaleAlpha(applyAlpha(SK_ColorBLACK), alpha)); 105 m_strokePaint.setColor(scaleAlpha(SK_ColorBLACK, alpha));
113 m_strokePaint.setShader(m_strokePattern->shader()); 106 m_strokePaint.setShader(m_strokePattern->shader());
114 } 107 }
115 108
116 void GraphicsContextState::setLineCap(LineCap cap) 109 void GraphicsContextState::setLineCap(LineCap cap)
117 { 110 {
118 m_strokeData.setLineCap(cap); 111 m_strokeData.setLineCap(cap);
119 m_strokePaint.setStrokeCap((SkPaint::Cap)cap); 112 m_strokePaint.setStrokeCap((SkPaint::Cap)cap);
120 } 113 }
121 114
122 void GraphicsContextState::setLineJoin(LineJoin join) 115 void GraphicsContextState::setLineJoin(LineJoin join)
123 { 116 {
124 m_strokeData.setLineJoin(join); 117 m_strokeData.setLineJoin(join);
125 m_strokePaint.setStrokeJoin((SkPaint::Join)join); 118 m_strokePaint.setStrokeJoin((SkPaint::Join)join);
126 } 119 }
127 120
128 void GraphicsContextState::setMiterLimit(float miterLimit) 121 void GraphicsContextState::setMiterLimit(float miterLimit)
129 { 122 {
130 m_strokeData.setMiterLimit(miterLimit); 123 m_strokeData.setMiterLimit(miterLimit);
131 m_strokePaint.setStrokeMiter(SkFloatToScalar(miterLimit)); 124 m_strokePaint.setStrokeMiter(SkFloatToScalar(miterLimit));
132 } 125 }
133 126
134 void GraphicsContextState::setFillColor(const Color& color) 127 void GraphicsContextState::setFillColor(const Color& color)
135 { 128 {
136 m_fillColor = color; 129 m_fillColor = color;
137 m_fillGradient.clear(); 130 m_fillGradient.clear();
138 m_fillPattern.clear(); 131 m_fillPattern.clear();
139 m_fillPaint.setColor(applyAlpha(color.rgb())); 132 m_fillPaint.setColor(color.rgb());
140 m_fillPaint.setShader(0); 133 m_fillPaint.setShader(0);
141 } 134 }
142 135
143 void GraphicsContextState::setFillGradient(const PassRefPtr<Gradient> gradient, float alpha) 136 void GraphicsContextState::setFillGradient(const PassRefPtr<Gradient> gradient, float alpha)
144 { 137 {
145 m_fillColor = Color::black; 138 m_fillColor = Color::black;
146 m_fillPattern.clear(); 139 m_fillPattern.clear();
147 m_fillGradient = gradient; 140 m_fillGradient = gradient;
148 m_fillPaint.setColor(scaleAlpha(applyAlpha(SK_ColorBLACK), alpha)); 141 m_fillPaint.setColor(scaleAlpha(SK_ColorBLACK, alpha));
149 m_fillPaint.setShader(m_fillGradient->shader()); 142 m_fillPaint.setShader(m_fillGradient->shader());
150 } 143 }
151 144
152 void GraphicsContextState::setFillPattern(const PassRefPtr<Pattern> pattern, flo at alpha) 145 void GraphicsContextState::setFillPattern(const PassRefPtr<Pattern> pattern, flo at alpha)
153 { 146 {
154 m_fillColor = Color::black; 147 m_fillColor = Color::black;
155 m_fillGradient.clear(); 148 m_fillGradient.clear();
156 m_fillPattern = pattern; 149 m_fillPattern = pattern;
157 m_fillPaint.setColor(scaleAlpha(applyAlpha(SK_ColorBLACK), alpha)); 150 m_fillPaint.setColor(scaleAlpha(SK_ColorBLACK, alpha));
158 m_fillPaint.setShader(m_fillPattern->shader()); 151 m_fillPaint.setShader(m_fillPattern->shader());
159 } 152 }
160 153
161 // Shadow. (This will need tweaking if we use draw loopers for other things.) 154 // Shadow. (This will need tweaking if we use draw loopers for other things.)
162 void GraphicsContextState::setDrawLooper(PassRefPtr<SkDrawLooper> drawLooper) 155 void GraphicsContextState::setDrawLooper(PassRefPtr<SkDrawLooper> drawLooper)
163 { 156 {
164 m_looper = drawLooper; 157 m_looper = drawLooper;
165 m_strokePaint.setLooper(m_looper.get()); 158 m_strokePaint.setLooper(m_looper.get());
166 m_fillPaint.setLooper(m_looper.get()); 159 m_fillPaint.setLooper(m_looper.get());
167 } 160 }
168 161
169 void GraphicsContextState::clearDrawLooper() 162 void GraphicsContextState::clearDrawLooper()
170 { 163 {
171 m_looper.clear(); 164 m_looper.clear();
172 m_strokePaint.setLooper(0); 165 m_strokePaint.setLooper(0);
173 m_fillPaint.setLooper(0); 166 m_fillPaint.setLooper(0);
174 } 167 }
175 168
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 ) 169 void GraphicsContextState::setLineDash(const DashArray& dashes, float dashOffset )
194 { 170 {
195 m_strokeData.setLineDash(dashes, dashOffset); 171 m_strokeData.setLineDash(dashes, dashOffset);
196 } 172 }
197 173
198 void GraphicsContextState::setColorFilter(PassRefPtr<SkColorFilter> colorFilter) 174 void GraphicsContextState::setColorFilter(PassRefPtr<SkColorFilter> colorFilter)
199 { 175 {
200 m_colorFilter = colorFilter; 176 m_colorFilter = colorFilter;
201 m_strokePaint.setColorFilter(m_colorFilter.get()); 177 m_strokePaint.setColorFilter(m_colorFilter.get());
202 m_fillPaint.setColorFilter(m_colorFilter.get()); 178 m_fillPaint.setColorFilter(m_colorFilter.get());
203 } 179 }
204 180
205 void GraphicsContextState::setCompositeOperation(SkXfermode::Mode xferMode)
206 {
207 m_compositeOperation = xferMode;
208 m_strokePaint.setXfermodeMode(xferMode);
209 m_fillPaint.setXfermodeMode(xferMode);
210 }
211
212 void GraphicsContextState::setInterpolationQuality(InterpolationQuality quality) 181 void GraphicsContextState::setInterpolationQuality(InterpolationQuality quality)
213 { 182 {
214 m_interpolationQuality = quality; 183 m_interpolationQuality = quality;
215 m_strokePaint.setFilterQuality(WebCoreInterpolationQualityToSkFilterQuality( quality)); 184 m_strokePaint.setFilterQuality(WebCoreInterpolationQualityToSkFilterQuality( quality));
216 m_fillPaint.setFilterQuality(WebCoreInterpolationQualityToSkFilterQuality(qu ality)); 185 m_fillPaint.setFilterQuality(WebCoreInterpolationQualityToSkFilterQuality(qu ality));
217 } 186 }
218 187
219 void GraphicsContextState::setShouldAntialias(bool shouldAntialias) 188 void GraphicsContextState::setShouldAntialias(bool shouldAntialias)
220 { 189 {
221 m_shouldAntialias = shouldAntialias; 190 m_shouldAntialias = shouldAntialias;
222 m_strokePaint.setAntiAlias(shouldAntialias); 191 m_strokePaint.setAntiAlias(shouldAntialias);
223 m_fillPaint.setAntiAlias(shouldAntialias); 192 m_fillPaint.setAntiAlias(shouldAntialias);
224 } 193 }
225 194
226 } // namespace blink 195 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698