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

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

Issue 2787113002: Initial conic-gradient() implementation (Closed)
Patch Set: baselines Created 3 years, 8 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
« no previous file with comments | « third_party/WebKit/Source/platform/graphics/Gradient.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 SkShader::TileMode tileMode, 187 SkShader::TileMode tileMode,
188 uint32_t flags, 188 uint32_t flags,
189 const SkMatrix& localMatrix) const override { 189 const SkMatrix& localMatrix) const override {
190 SkPoint pts[2] = {m_p0.data(), m_p1.data()}; 190 SkPoint pts[2] = {m_p0.data(), m_p1.data()};
191 return SkGradientShader::MakeLinear(pts, colors.data(), pos.data(), 191 return SkGradientShader::MakeLinear(pts, colors.data(), pos.data(),
192 static_cast<int>(colors.size()), 192 static_cast<int>(colors.size()),
193 tileMode, flags, &localMatrix); 193 tileMode, flags, &localMatrix);
194 } 194 }
195 195
196 private: 196 private:
197 FloatPoint m_p0; 197 const FloatPoint m_p0;
198 FloatPoint m_p1; 198 const FloatPoint m_p1;
199 }; 199 };
200 200
201 class RadialGradient final : public Gradient { 201 class RadialGradient final : public Gradient {
202 public: 202 public:
203 RadialGradient(const FloatPoint& p0, 203 RadialGradient(const FloatPoint& p0,
204 float r0, 204 float r0,
205 const FloatPoint& p1, 205 const FloatPoint& p1,
206 float r1, 206 float r1,
207 float aspectRatio, 207 float aspectRatio,
208 GradientSpreadMethod spreadMethod, 208 GradientSpreadMethod spreadMethod,
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 // The radii we give to Skia must be positive. If we're given a 241 // The radii we give to Skia must be positive. If we're given a
242 // negative radius, ask for zero instead. 242 // negative radius, ask for zero instead.
243 const SkScalar radius0 = std::max(WebCoreFloatToSkScalar(m_r0), 0.0f); 243 const SkScalar radius0 = std::max(WebCoreFloatToSkScalar(m_r0), 0.0f);
244 const SkScalar radius1 = std::max(WebCoreFloatToSkScalar(m_r1), 0.0f); 244 const SkScalar radius1 = std::max(WebCoreFloatToSkScalar(m_r1), 0.0f);
245 return SkGradientShader::MakeTwoPointConical( 245 return SkGradientShader::MakeTwoPointConical(
246 m_p0.data(), radius0, m_p1.data(), radius1, colors.data(), pos.data(), 246 m_p0.data(), radius0, m_p1.data(), radius1, colors.data(), pos.data(),
247 static_cast<int>(colors.size()), tileMode, flags, adjustedLocalMatrix); 247 static_cast<int>(colors.size()), tileMode, flags, adjustedLocalMatrix);
248 } 248 }
249 249
250 private: 250 private:
251 FloatPoint m_p0; 251 const FloatPoint m_p0;
252 FloatPoint m_p1; 252 const FloatPoint m_p1;
253 float m_r0; 253 const float m_r0;
254 float m_r1; 254 const float m_r1;
255 float m_aspectRatio; // For elliptical gradient, width / height. 255 const float m_aspectRatio; // For elliptical gradient, width / height.
256 };
257
258 class ConicGradient final : public Gradient {
259 public:
260 ConicGradient(const FloatPoint& position,
261 float angle,
262 GradientSpreadMethod spreadMethod,
263 ColorInterpolation interpolation)
264 : Gradient(Type::Conic, spreadMethod, interpolation),
265 m_position(position),
266 m_angle(angle) {}
267
268 protected:
269 sk_sp<SkShader> createShader(const ColorBuffer& colors,
270 const OffsetBuffer& pos,
271 SkShader::TileMode tileMode,
272 uint32_t flags,
273 const SkMatrix& localMatrix) const override {
274 if (tileMode != SkShader::kClamp_TileMode) {
275 // TODO(fmalita): kRepeat support
276 return nullptr;
277 }
278
279 // Skia's sweep gradient angles are relative to the x-axis, not the y-axis.
280 const float skiaAngle = m_angle - 90;
281 SkTCopyOnFirstWrite<SkMatrix> adjustedLocalMatrix(localMatrix);
282 if (skiaAngle) {
283 adjustedLocalMatrix.writable()->preRotate(skiaAngle, m_position.x(),
284 m_position.y());
285 }
286
287 return SkGradientShader::MakeSweep(
288 m_position.x(), m_position.y(), colors.data(), pos.data(),
289 static_cast<int>(colors.size()), flags, adjustedLocalMatrix);
290 }
291
292 private:
293 const FloatPoint m_position;
294 const float m_angle;
256 }; 295 };
257 296
258 } // anonymous ns 297 } // anonymous ns
259 298
260 PassRefPtr<Gradient> Gradient::createLinear(const FloatPoint& p0, 299 PassRefPtr<Gradient> Gradient::createLinear(const FloatPoint& p0,
261 const FloatPoint& p1, 300 const FloatPoint& p1,
262 GradientSpreadMethod spreadMethod, 301 GradientSpreadMethod spreadMethod,
263 ColorInterpolation interpolation) { 302 ColorInterpolation interpolation) {
264 return adoptRef(new LinearGradient(p0, p1, spreadMethod, interpolation)); 303 return adoptRef(new LinearGradient(p0, p1, spreadMethod, interpolation));
265 } 304 }
266 305
267 PassRefPtr<Gradient> Gradient::createRadial(const FloatPoint& p0, 306 PassRefPtr<Gradient> Gradient::createRadial(const FloatPoint& p0,
268 float r0, 307 float r0,
269 const FloatPoint& p1, 308 const FloatPoint& p1,
270 float r1, 309 float r1,
271 float aspectRatio, 310 float aspectRatio,
272 GradientSpreadMethod spreadMethod, 311 GradientSpreadMethod spreadMethod,
273 ColorInterpolation interpolation) { 312 ColorInterpolation interpolation) {
274 return adoptRef(new RadialGradient(p0, r0, p1, r1, aspectRatio, spreadMethod, 313 return adoptRef(new RadialGradient(p0, r0, p1, r1, aspectRatio, spreadMethod,
275 interpolation)); 314 interpolation));
276 } 315 }
277 316
317 PassRefPtr<Gradient> Gradient::createConic(const FloatPoint& position,
318 float angle,
319 GradientSpreadMethod spreadMethod,
320 ColorInterpolation interpolation) {
321 return adoptRef(
322 new ConicGradient(position, angle, spreadMethod, interpolation));
323 }
324
278 } // namespace blink 325 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/graphics/Gradient.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698