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

Side by Side Diff: Source/core/platform/graphics/Path.cpp

Issue 14298022: Add support for new canvas ellipse method. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Patch to discuss about degenerate ellipse. Created 7 years, 5 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) 2003, 2006 Apple Computer, Inc. All rights reserved. 2 * Copyright (C) 2003, 2006 Apple Computer, Inc. All rights reserved.
3 * 2006 Rob Buis <buis@kde.org> 3 * 2006 Rob Buis <buis@kde.org>
4 * Copyright (C) 2007 Eric Seidel <eric@webkit.org> 4 * Copyright (C) 2007 Eric Seidel <eric@webkit.org>
5 * Copyright (C) 2013 Google Inc. All rights reserved. 5 * Copyright (C) 2013 Google Inc. All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 void Path::addArcTo(const FloatPoint& p1, const FloatPoint& p2, float radius) 256 void Path::addArcTo(const FloatPoint& p1, const FloatPoint& p2, float radius)
257 { 257 {
258 m_path.arcTo(p1, p2, WebCoreFloatToSkScalar(radius)); 258 m_path.arcTo(p1, p2, WebCoreFloatToSkScalar(radius));
259 } 259 }
260 260
261 void Path::closeSubpath() 261 void Path::closeSubpath()
262 { 262 {
263 m_path.close(); 263 m_path.close();
264 } 264 }
265 265
266 void Path::addArc(const FloatPoint& p, float r, float sa, float ea, bool anticlo ckwise) 266 void Path::addArc(const FloatPoint& p, float radius, float startAngle, float ea, bool anticlockwise)
267 { 267 {
268 SkScalar cx = WebCoreFloatToSkScalar(p.x()); 268 SkScalar cx = WebCoreFloatToSkScalar(p.x());
269 SkScalar cy = WebCoreFloatToSkScalar(p.y()); 269 SkScalar cy = WebCoreFloatToSkScalar(p.y());
270 SkScalar radius = WebCoreFloatToSkScalar(r); 270 SkScalar radiusScalar = WebCoreFloatToSkScalar(radius);
271 SkScalar s360 = SkIntToScalar(360); 271 SkScalar s360 = SkIntToScalar(360);
272 272
273 SkRect oval; 273 SkRect oval;
274 oval.set(cx - radius, cy - radius, cx + radius, cy + radius); 274 oval.set(cx - radiusScalar, cy - radiusScalar, cx + radiusScalar, cy + radiu sScalar);
275 275
276 float sweep = ea - sa; 276 float sweep = ea - startAngle;
277 SkScalar startDegrees = WebCoreFloatToSkScalar(sa * 180 / piFloat); 277 SkScalar startDegrees = WebCoreFloatToSkScalar(startAngle * 180 / piFloat);
278 SkScalar sweepDegrees = WebCoreFloatToSkScalar(sweep * 180 / piFloat); 278 SkScalar sweepDegrees = WebCoreFloatToSkScalar(sweep * 180 / piFloat);
279 // Check for a circle. 279 // Check for a circle.
280 if (sweepDegrees >= s360 || sweepDegrees <= -s360) { 280 if (sweepDegrees >= s360 || sweepDegrees <= -s360) {
281 // Move to the start position (0 sweep means we add a single point). 281 // Move to the start position (0 sweep means we add a single point).
282 m_path.arcTo(oval, startDegrees, 0, false); 282 m_path.arcTo(oval, startDegrees, 0, false);
283 // Draw the circle. 283 // Draw the circle.
284 m_path.addOval(oval, anticlockwise ? 284 m_path.addOval(oval, anticlockwise ?
285 SkPath::kCCW_Direction : SkPath::kCW_Direction); 285 SkPath::kCCW_Direction : SkPath::kCW_Direction);
286 // Force a moveTo the end position. 286 // Force a moveTo the end position.
287 m_path.arcTo(oval, startDegrees + sweepDegrees, 0, true); 287 m_path.arcTo(oval, startDegrees + sweepDegrees, 0, true);
(...skipping 10 matching lines...) Expand all
298 sweepDegrees += s360; 298 sweepDegrees += s360;
299 299
300 m_path.arcTo(oval, startDegrees, sweepDegrees, false); 300 m_path.arcTo(oval, startDegrees, sweepDegrees, false);
301 } 301 }
302 302
303 void Path::addRect(const FloatRect& rect) 303 void Path::addRect(const FloatRect& rect)
304 { 304 {
305 m_path.addRect(rect); 305 m_path.addRect(rect);
306 } 306 }
307 307
308 void Path::addEllipse(const FloatPoint& p, float radiusX, float radiusY, float r otation, float startAngle, float endAngle, bool anticlockwise)
309 {
310 // Optimize the common case of an entire ellipse.
311 SkScalar twoPiScalar = WebCoreFloatToSkScalar(2 * piFloat);
312 SkScalar endAngleScalar = WebCoreFloatToSkScalar(endAngle);
313 if (!rotation && !startAngle && SkScalarNearlyEqual(twoPiScalar, SkScalarAbs (endAngleScalar))) {
314 FloatRect boundingRect(p - FloatSize(radiusX, radiusY), FloatSize(2 * ra diusX, 2 * radiusY));
315 if (anticlockwise && SkScalarNearlyEqual(twoPiScalar, -endAngleScalar)) {
316 m_path.addOval(boundingRect, SkPath::kCCW_Direction);
317 return;
318 }
319 if (!anticlockwise && SkScalarNearlyEqual(twoPiScalar, endAngleScalar)) {
320 m_path.addOval(boundingRect);
321 return;
322 }
323 }
324
325 // Add an arc after the relevant transform.
326 AffineTransform ellipseTransform = AffineTransform::translation(p.x(), p.y() ).rotate(rad2deg(rotation)).scale(radiusX, radiusY);
327 ASSERT(ellipseTransform.isInvertible());
328 AffineTransform inverseEllipseTransform = ellipseTransform.inverse();
329 transform(inverseEllipseTransform);
330 addArc(FloatPoint::zero(), 1 /* unit circle */, startAngle, endAngle, anticl ockwise);
331 transform(ellipseTransform);
332 }
333
308 void Path::addEllipse(const FloatRect& rect) 334 void Path::addEllipse(const FloatRect& rect)
309 { 335 {
310 m_path.addOval(rect); 336 m_path.addOval(rect);
311 } 337 }
312 338
313 void Path::addRoundedRect(const RoundedRect& r) 339 void Path::addRoundedRect(const RoundedRect& r)
314 { 340 {
315 addRoundedRect(r.rect(), r.radii().topLeft(), r.radii().topRight(), r.radii( ).bottomLeft(), r.radii().bottomRight()); 341 addRoundedRect(r.rect(), r.radii().topLeft(), r.radii().topRight(), r.radii( ).bottomLeft(), r.radii().bottomRight());
316 } 342 }
317 343
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 427
402 closeSubpath(); 428 closeSubpath();
403 } 429 }
404 430
405 void Path::translate(const FloatSize& size) 431 void Path::translate(const FloatSize& size)
406 { 432 {
407 m_path.offset(WebCoreFloatToSkScalar(size.width()), WebCoreFloatToSkScalar(s ize.height())); 433 m_path.offset(WebCoreFloatToSkScalar(size.width()), WebCoreFloatToSkScalar(s ize.height()));
408 } 434 }
409 435
410 } 436 }
OLDNEW
« Source/core/html/canvas/CanvasPathMethods.cpp ('K') | « Source/core/platform/graphics/Path.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698