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

Side by Side Diff: third_party/WebKit/Source/platform/graphics/Gradient.cpp

Issue 1789063005: Add sk_sp helpers and switch Blink SkShader clients to the new APIs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fromSkSp, review comments Created 4 years, 9 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
OLDNEW
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 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
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::CreateRadial(m_p1.data(), m_ r1, colors.data(), pos.data(), static_cast<int>(countUsed), tile, shouldDrawInPM ColorSpace, &localMatrix)); 236 m_gradient = fromSkSp(SkGradientShader::MakeRadial(m_p1.data(), m_r1 , colors.data(), pos.data(), static_cast<int>(countUsed), tile, shouldDrawInPMCo lorSpace, &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::CreateTwoPointConical(m_p0.d ata(), radius0, m_p1.data(), radius1, colors.data(), pos.data(), static_cast<int >(countUsed), tile, shouldDrawInPMColorSpace, &localMatrix)); 242 m_gradient = fromSkSp(SkGradientShader::MakeTwoPointConical(m_p0.dat a(), 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::CreateLinear(pts, colors.data(), pos.data(), static_cast<int>(countUsed), tile, shouldDrawInPMColorSpace, &local Matrix)); 247 m_gradient = fromSkSp(SkGradientShader::MakeLinear(pts, colors.data(), p os.data(), static_cast<int>(countUsed), tile, shouldDrawInPMColorSpace, &localMa trix));
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::CreateColorShader(colors[countUsed - 1]) ); 252 m_gradient = fromSkSp(SkShader::MakeColorShader(colors[countUsed - 1]));
253 } 253 }
254 return m_gradient.get(); 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(shader()); 259 paint.setShader(sk_ref_sp(shader()));
Stephen White 2016/03/18 14:48:27 Perhaps m_gradient should be sk_sp<SkShader>, and
f(malita) 2016/03/18 15:11:53 I'm not sure what the right balance for Blink's sk
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
264 } // namespace blink 265 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698