OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2006, 2007, 2008, 2010 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007, 2008, 2010 Apple Inc. All rights reserved. |
3 * Copyright (C) 2007 Alp Toker <alp@atoker.com> | 3 * Copyright (C) 2007 Alp Toker <alp@atoker.com> |
4 * Copyright (C) 2013 Google Inc. All rights reserved. | 4 * Copyright (C) 2013 Google Inc. All rights reserved. |
5 * | 5 * |
6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
7 * modification, are permitted provided that the following conditions | 7 * modification, are permitted provided that the following conditions |
8 * are met: | 8 * are met: |
9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 } | 182 } |
183 | 183 |
184 // Copy the last stop to 1.0 if needed. See comment above about this float | 184 // Copy the last stop to 1.0 if needed. See comment above about this float |
185 // comparison. | 185 // comparison. |
186 if (count < 1 || (--stop)->stop < 1.0) { | 186 if (count < 1 || (--stop)->stop < 1.0) { |
187 pos[start + count] = WebCoreFloatToSkScalar(1.0); | 187 pos[start + count] = WebCoreFloatToSkScalar(1.0); |
188 colors[start + count] = colors[start + count - 1]; | 188 colors[start + count] = colors[start + count - 1]; |
189 } | 189 } |
190 } | 190 } |
191 | 191 |
192 PassRefPtr<SkShader> Gradient::refShader() | 192 SkShader* Gradient::shader() |
193 { | 193 { |
194 if (m_gradient) | 194 if (m_gradient) |
195 return m_gradient; | 195 return m_gradient.get(); |
196 | 196 |
197 sortStopsIfNecessary(); | 197 sortStopsIfNecessary(); |
198 ASSERT(m_stopsSorted); | 198 ASSERT(m_stopsSorted); |
199 | 199 |
200 size_t countUsed = totalStopsNeeded(m_stops.data(), m_stops.size()); | 200 size_t countUsed = totalStopsNeeded(m_stops.data(), m_stops.size()); |
201 ASSERT(countUsed >= 2); | 201 ASSERT(countUsed >= 2); |
202 ASSERT(countUsed >= m_stops.size()); | 202 ASSERT(countUsed >= m_stops.size()); |
203 | 203 |
204 ColorStopOffsetVector pos(countUsed); | 204 ColorStopOffsetVector pos(countUsed); |
205 ColorStopColorVector colors(countUsed); | 205 ColorStopColorVector colors(countUsed); |
(...skipping 20 matching lines...) Expand all Loading... |
226 m_gradientSpaceTransformation.translate(m_p0.x(), m_p0.y()); | 226 m_gradientSpaceTransformation.translate(m_p0.x(), m_p0.y()); |
227 m_gradientSpaceTransformation.scale(1, 1 / aspectRatio()); | 227 m_gradientSpaceTransformation.scale(1, 1 / aspectRatio()); |
228 m_gradientSpaceTransformation.translate(-m_p0.x(), -m_p0.y()); | 228 m_gradientSpaceTransformation.translate(-m_p0.x(), -m_p0.y()); |
229 ASSERT(m_p0 == m_p1); | 229 ASSERT(m_p0 == m_p1); |
230 } | 230 } |
231 SkMatrix localMatrix = affineTransformToSkMatrix(m_gradientSpaceTransfor
mation); | 231 SkMatrix localMatrix = affineTransformToSkMatrix(m_gradientSpaceTransfor
mation); |
232 | 232 |
233 // Since the two-point radial gradient is slower than the plain radial, | 233 // Since the two-point radial gradient is slower than the plain radial, |
234 // only use it if we have to. | 234 // only use it if we have to. |
235 if (m_p0 == m_p1 && m_r0 <= 0.0f) { | 235 if (m_p0 == m_p1 && m_r0 <= 0.0f) { |
236 m_gradient = adoptRef(SkGradientShader::MakeRadial(m_p1.data(), m_r1
, colors.data(), pos.data(), static_cast<int>(countUsed), tile, shouldDrawInPMCo
lorSpace, &localMatrix)); | 236 m_gradient = adoptRef(SkGradientShader::CreateRadial(m_p1.data(), m_
r1, colors.data(), pos.data(), static_cast<int>(countUsed), tile, shouldDrawInPM
ColorSpace, &localMatrix)); |
237 } else { | 237 } else { |
238 // The radii we give to Skia must be positive. If we're given a | 238 // The radii we give to Skia must be positive. If we're given a |
239 // negative radius, ask for zero instead. | 239 // negative radius, ask for zero instead. |
240 SkScalar radius0 = m_r0 >= 0.0f ? WebCoreFloatToSkScalar(m_r0) : 0; | 240 SkScalar radius0 = m_r0 >= 0.0f ? WebCoreFloatToSkScalar(m_r0) : 0; |
241 SkScalar radius1 = m_r1 >= 0.0f ? WebCoreFloatToSkScalar(m_r1) : 0; | 241 SkScalar radius1 = m_r1 >= 0.0f ? WebCoreFloatToSkScalar(m_r1) : 0; |
242 m_gradient = adoptRef(SkGradientShader::MakeTwoPointConical(m_p0.dat
a(), radius0, m_p1.data(), radius1, colors.data(), pos.data(), static_cast<int>(
countUsed), tile, shouldDrawInPMColorSpace, &localMatrix)); | 242 m_gradient = adoptRef(SkGradientShader::CreateTwoPointConical(m_p0.d
ata(), radius0, m_p1.data(), radius1, colors.data(), pos.data(), static_cast<int
>(countUsed), tile, shouldDrawInPMColorSpace, &localMatrix)); |
243 } | 243 } |
244 } else { | 244 } else { |
245 SkPoint pts[2] = { m_p0.data(), m_p1.data() }; | 245 SkPoint pts[2] = { m_p0.data(), m_p1.data() }; |
246 SkMatrix localMatrix = affineTransformToSkMatrix(m_gradientSpaceTransfor
mation); | 246 SkMatrix localMatrix = affineTransformToSkMatrix(m_gradientSpaceTransfor
mation); |
247 m_gradient = adoptRef(SkGradientShader::MakeLinear(pts, colors.data(), p
os.data(), static_cast<int>(countUsed), tile, shouldDrawInPMColorSpace, &localMa
trix)); | 247 m_gradient = adoptRef(SkGradientShader::CreateLinear(pts, colors.data(),
pos.data(), static_cast<int>(countUsed), tile, shouldDrawInPMColorSpace, &local
Matrix)); |
248 } | 248 } |
249 | 249 |
250 if (!m_gradient) { | 250 if (!m_gradient) { |
251 // use last color, since our "geometry" was degenerate (e.g. radius==0) | 251 // use last color, since our "geometry" was degenerate (e.g. radius==0) |
252 m_gradient = adoptRef(SkShader::MakeColorShader(colors[countUsed - 1])); | 252 m_gradient = adoptRef(SkShader::CreateColorShader(colors[countUsed - 1])
); |
253 } | 253 } |
254 return m_gradient; | 254 return m_gradient.get(); |
255 } | 255 } |
256 | 256 |
257 void Gradient::applyToPaint(SkPaint& paint) | 257 void Gradient::applyToPaint(SkPaint& paint) |
258 { | 258 { |
259 paint.setShader(adoptSkSp(refShader())); | 259 paint.setShader(shader()); |
260 | 260 |
261 // Legacy behavior: gradients are always dithered. | 261 // Legacy behavior: gradients are always dithered. |
262 paint.setDither(true); | 262 paint.setDither(true); |
263 } | 263 } |
264 | |
265 } // namespace blink | 264 } // namespace blink |
OLD | NEW |