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

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

Issue 815933006: Change all uses of the RoundedRect class to use FloatRoundedRect instead. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years 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 /* 1 /*
2 * Copyright (C) 2003, 2004, 2005, 2006, 2009 Apple Inc. All rights reserved. 2 * Copyright (C) 2003, 2004, 2005, 2006, 2009 Apple Inc. All rights reserved.
3 * Copyright (C) 2013 Google Inc. All rights reserved. 3 * Copyright (C) 2013 Google Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 687 matching lines...) Expand 10 before | Expand all | Expand 10 after
698 698
699 if (focusRingRegion.isRect()) { 699 if (focusRingRegion.isRect()) {
700 drawFocusRingRect(SkRect::MakeFromIRect(focusRingRegion.getBounds()), co lor, width); 700 drawFocusRingRect(SkRect::MakeFromIRect(focusRingRegion.getBounds()), co lor, width);
701 } else { 701 } else {
702 SkPath path; 702 SkPath path;
703 if (focusRingRegion.getBoundaryPath(&path)) 703 if (focusRingRegion.getBoundaryPath(&path))
704 drawFocusRingPath(path, color, width); 704 drawFocusRingPath(path, color, width);
705 } 705 }
706 } 706 }
707 707
708 static inline IntRect areaCastingShadowInHole(const IntRect& holeRect, int shado wBlur, int shadowSpread, const IntSize& shadowOffset) 708 static inline FloatRect areaCastingShadowInHole(const FloatRect& holeRect, int s hadowBlur, int shadowSpread, const IntSize& shadowOffset)
709 { 709 {
710 IntRect bounds(holeRect); 710 IntRect bounds(holeRect);
711 711
712 bounds.inflate(shadowBlur); 712 bounds.inflate(shadowBlur);
713 713
714 if (shadowSpread < 0) 714 if (shadowSpread < 0)
715 bounds.inflate(-shadowSpread); 715 bounds.inflate(-shadowSpread);
716 716
717 IntRect offsetBounds = bounds; 717 IntRect offsetBounds = bounds;
718 offsetBounds.move(-shadowOffset); 718 offsetBounds.move(-shadowOffset);
719 return unionRect(bounds, offsetBounds); 719 return unionRect(bounds, offsetBounds);
720 } 720 }
721 721
722 void GraphicsContext::drawInnerShadow(const RoundedRect& rect, const Color& shad owColor, const IntSize shadowOffset, int shadowBlur, int shadowSpread, Edges cli ppedEdges) 722 void GraphicsContext::drawInnerShadow(const FloatRoundedRect& rect, const Color& shadowColor, const IntSize shadowOffset, int shadowBlur, int shadowSpread, Edge s clippedEdges)
723 { 723 {
724 if (contextDisabled()) 724 if (contextDisabled())
725 return; 725 return;
726 726
727 IntRect holeRect(rect.rect()); 727 FloatRect holeRect(rect.rect());
728 holeRect.inflate(-shadowSpread); 728 holeRect.inflate(-shadowSpread);
729 729
730 if (holeRect.isEmpty()) { 730 if (holeRect.isEmpty()) {
731 if (rect.isRounded()) 731 if (rect.isRounded())
732 fillRoundedRect(rect, shadowColor); 732 fillRoundedRect(rect, shadowColor);
733 else 733 else
734 fillRect(rect.rect(), shadowColor); 734 fillRect(rect.rect(), shadowColor);
735 return; 735 return;
736 } 736 }
737 737
738 if (clippedEdges & LeftEdge) { 738 if (clippedEdges & LeftEdge) {
739 holeRect.move(-std::max(shadowOffset.width(), 0) - shadowBlur, 0); 739 holeRect.move(-std::max(shadowOffset.width(), 0) - shadowBlur, 0);
740 holeRect.setWidth(holeRect.width() + std::max(shadowOffset.width(), 0) + shadowBlur); 740 holeRect.setWidth(holeRect.width() + std::max(shadowOffset.width(), 0) + shadowBlur);
741 } 741 }
742 if (clippedEdges & TopEdge) { 742 if (clippedEdges & TopEdge) {
743 holeRect.move(0, -std::max(shadowOffset.height(), 0) - shadowBlur); 743 holeRect.move(0, -std::max(shadowOffset.height(), 0) - shadowBlur);
744 holeRect.setHeight(holeRect.height() + std::max(shadowOffset.height(), 0 ) + shadowBlur); 744 holeRect.setHeight(holeRect.height() + std::max(shadowOffset.height(), 0 ) + shadowBlur);
745 } 745 }
746 if (clippedEdges & RightEdge) 746 if (clippedEdges & RightEdge)
747 holeRect.setWidth(holeRect.width() - std::min(shadowOffset.width(), 0) + shadowBlur); 747 holeRect.setWidth(holeRect.width() - std::min(shadowOffset.width(), 0) + shadowBlur);
748 if (clippedEdges & BottomEdge) 748 if (clippedEdges & BottomEdge)
749 holeRect.setHeight(holeRect.height() - std::min(shadowOffset.height(), 0 ) + shadowBlur); 749 holeRect.setHeight(holeRect.height() - std::min(shadowOffset.height(), 0 ) + shadowBlur);
750 750
751 Color fillColor(shadowColor.red(), shadowColor.green(), shadowColor.blue(), 255); 751 Color fillColor(shadowColor.red(), shadowColor.green(), shadowColor.blue(), 255);
752 752
753 IntRect outerRect = areaCastingShadowInHole(rect.rect(), shadowBlur, shadowS pread, shadowOffset); 753 FloatRect outerRect = areaCastingShadowInHole(rect.rect(), shadowBlur, shado wSpread, shadowOffset);
754 RoundedRect roundedHole(holeRect, rect.radii()); 754 FloatRoundedRect roundedHole(holeRect, rect.radii());
755 755
756 save(); 756 save();
757 if (rect.isRounded()) { 757 if (rect.isRounded()) {
758 Path path; 758 Path path;
759 path.addRoundedRect(rect); 759 path.addRoundedRect(rect);
760 clipPath(path); 760 clipPath(path);
761 roundedHole.shrinkRadii(shadowSpread); 761 roundedHole.shrinkRadii(shadowSpread);
762 } else { 762 } else {
763 clip(rect.rect()); 763 clip(rect.rect());
764 } 764 }
(...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after
1332 { 1332 {
1333 if (contextDisabled()) 1333 if (contextDisabled())
1334 return; 1334 return;
1335 1335
1336 SkRect r = rect; 1336 SkRect r = rect;
1337 SkPaint paint = immutableState()->fillPaint(); 1337 SkPaint paint = immutableState()->fillPaint();
1338 paint.setColor(color.rgb()); 1338 paint.setColor(color.rgb());
1339 drawRect(r, paint); 1339 drawRect(r, paint);
1340 } 1340 }
1341 1341
1342 void GraphicsContext::fillBetweenRoundedRects(const IntRect& outer, const IntSiz e& outerTopLeft, const IntSize& outerTopRight, const IntSize& outerBottomLeft, c onst IntSize& outerBottomRight, 1342 void GraphicsContext::fillBetweenRoundedRects(const FloatRect& outer, const Floa tSize& outerTopLeft, const FloatSize& outerTopRight, const FloatSize& outerBotto mLeft, const FloatSize& outerBottomRight,
1343 const IntRect& inner, const IntSize& innerTopLeft, const IntSize& innerTopRi ght, const IntSize& innerBottomLeft, const IntSize& innerBottomRight, const Colo r& color) 1343 const FloatRect& inner, const FloatSize& innerTopLeft, const FloatSize& inne rTopRight, const FloatSize& innerBottomLeft, const FloatSize& innerBottomRight, const Color& color)
1344 { 1344 {
1345 ASSERT(m_canvas); 1345 ASSERT(m_canvas);
1346 if (contextDisabled()) 1346 if (contextDisabled())
1347 return; 1347 return;
1348 1348
1349 SkVector outerRadii[4]; 1349 SkVector outerRadii[4];
1350 SkVector innerRadii[4]; 1350 SkVector innerRadii[4];
1351 setRadii(outerRadii, outerTopLeft, outerTopRight, outerBottomRight, outerBot tomLeft); 1351 setRadii(outerRadii, outerTopLeft, outerTopRight, outerBottomRight, outerBot tomLeft);
1352 setRadii(innerRadii, innerTopLeft, innerTopRight, innerBottomRight, innerBot tomLeft); 1352 setRadii(innerRadii, innerTopLeft, innerTopRight, innerBottomRight, innerBot tomLeft);
1353 1353
1354 SkRRect rrOuter; 1354 SkRRect rrOuter;
1355 SkRRect rrInner; 1355 SkRRect rrInner;
1356 rrOuter.setRectRadii(outer, outerRadii); 1356 rrOuter.setRectRadii(outer, outerRadii);
1357 rrInner.setRectRadii(inner, innerRadii); 1357 rrInner.setRectRadii(inner, innerRadii);
1358 1358
1359 SkPaint paint(immutableState()->fillPaint()); 1359 SkPaint paint(immutableState()->fillPaint());
1360 paint.setColor(color.rgb()); 1360 paint.setColor(color.rgb());
1361 1361
1362 m_canvas->drawDRRect(rrOuter, rrInner, paint); 1362 m_canvas->drawDRRect(rrOuter, rrInner, paint);
1363 1363
1364 if (regionTrackingEnabled()) 1364 if (regionTrackingEnabled())
1365 m_trackedRegion.didDrawBounded(this, rrOuter.getBounds(), paint); 1365 m_trackedRegion.didDrawBounded(this, rrOuter.getBounds(), paint);
1366 } 1366 }
1367 1367
1368 void GraphicsContext::fillBetweenRoundedRects(const RoundedRect& outer, const Ro undedRect& inner, const Color& color) 1368 void GraphicsContext::fillBetweenRoundedRects(const FloatRoundedRect& outer, con st FloatRoundedRect& inner, const Color& color)
1369 { 1369 {
1370 fillBetweenRoundedRects(outer.rect(), outer.radii().topLeft(), outer.radii() .topRight(), outer.radii().bottomLeft(), outer.radii().bottomRight(), 1370 fillBetweenRoundedRects(outer.rect(), outer.radii().topLeft(), outer.radii() .topRight(), outer.radii().bottomLeft(), outer.radii().bottomRight(),
1371 inner.rect(), inner.radii().topLeft(), inner.radii().topRight(), inner.r adii().bottomLeft(), inner.radii().bottomRight(), color); 1371 inner.rect(), inner.radii().topLeft(), inner.radii().topRight(), inner.r adii().bottomLeft(), inner.radii().bottomRight(), color);
1372 } 1372 }
1373 1373
1374 void GraphicsContext::fillRoundedRect(const IntRect& rect, const IntSize& topLef t, const IntSize& topRight, 1374 void GraphicsContext::fillRoundedRect(const FloatRect& rect, const FloatSize& to pLeft, const FloatSize& topRight,
1375 const IntSize& bottomLeft, const IntSize& bottomRight, const Color& color) 1375 const FloatSize& bottomLeft, const FloatSize& bottomRight, const Color& colo r)
1376 { 1376 {
1377 ASSERT(m_canvas); 1377 ASSERT(m_canvas);
1378 if (contextDisabled()) 1378 if (contextDisabled())
1379 return; 1379 return;
1380 1380
1381 if (topLeft.width() + topRight.width() > rect.width() 1381 if (topLeft.width() + topRight.width() > rect.width()
1382 || bottomLeft.width() + bottomRight.width() > rect.width() 1382 || bottomLeft.width() + bottomRight.width() > rect.width()
1383 || topLeft.height() + bottomLeft.height() > rect.height() 1383 || topLeft.height() + bottomLeft.height() > rect.height()
1384 || topRight.height() + bottomRight.height() > rect.height()) { 1384 || topRight.height() + bottomRight.height() > rect.height()) {
1385 // Not all the radii fit, return a rect. This matches the behavior of 1385 // Not all the radii fit, return a rect. This matches the behavior of
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
1456 } 1456 }
1457 1457
1458 void GraphicsContext::strokeEllipse(const FloatRect& ellipse) 1458 void GraphicsContext::strokeEllipse(const FloatRect& ellipse)
1459 { 1459 {
1460 if (contextDisabled()) 1460 if (contextDisabled())
1461 return; 1461 return;
1462 1462
1463 drawOval(ellipse, immutableState()->strokePaint()); 1463 drawOval(ellipse, immutableState()->strokePaint());
1464 } 1464 }
1465 1465
1466 void GraphicsContext::clipRoundedRect(const RoundedRect& rect, SkRegion::Op regi onOp) 1466 void GraphicsContext::clipRoundedRect(const FloatRoundedRect& rect, SkRegion::Op regionOp)
1467 { 1467 {
1468 if (contextDisabled()) 1468 if (contextDisabled())
1469 return; 1469 return;
1470 1470
1471 if (!rect.isRounded()) { 1471 if (!rect.isRounded()) {
1472 clipRect(rect.rect(), NotAntiAliased, regionOp); 1472 clipRect(rect.rect(), NotAntiAliased, regionOp);
1473 return; 1473 return;
1474 } 1474 }
1475 1475
1476 SkVector radii[4]; 1476 SkVector radii[4];
1477 RoundedRect::Radii wkRadii = rect.radii(); 1477 FloatRoundedRect::Radii wkRadii = rect.radii();
1478 setRadii(radii, wkRadii.topLeft(), wkRadii.topRight(), wkRadii.bottomRight() , wkRadii.bottomLeft()); 1478 setRadii(radii, wkRadii.topLeft(), wkRadii.topRight(), wkRadii.bottomRight() , wkRadii.bottomLeft());
1479 1479
1480 SkRRect r; 1480 SkRRect r;
1481 r.setRectRadii(rect.rect(), radii); 1481 r.setRectRadii(rect.rect(), radii);
1482 1482
1483 clipRRect(r, AntiAliased, regionOp); 1483 clipRRect(r, AntiAliased, regionOp);
1484 } 1484 }
1485 1485
1486 void GraphicsContext::clipOut(const Path& pathToClip) 1486 void GraphicsContext::clipOut(const Path& pathToClip)
1487 { 1487 {
(...skipping 28 matching lines...) Expand all
1516 if (contextDisabled()) 1516 if (contextDisabled())
1517 return; 1517 return;
1518 1518
1519 ASSERT(numPoints > 2); 1519 ASSERT(numPoints > 2);
1520 1520
1521 SkPath path; 1521 SkPath path;
1522 setPathFromPoints(&path, numPoints, points); 1522 setPathFromPoints(&path, numPoints, points);
1523 clipPath(path, antialiased ? AntiAliased : NotAntiAliased); 1523 clipPath(path, antialiased ? AntiAliased : NotAntiAliased);
1524 } 1524 }
1525 1525
1526 void GraphicsContext::clipOutRoundedRect(const RoundedRect& rect) 1526 void GraphicsContext::clipOutRoundedRect(const FloatRoundedRect& rect)
1527 { 1527 {
1528 if (contextDisabled()) 1528 if (contextDisabled())
1529 return; 1529 return;
1530 1530
1531 clipRoundedRect(rect, SkRegion::kDifference_Op); 1531 clipRoundedRect(rect, SkRegion::kDifference_Op);
1532 } 1532 }
1533 1533
1534 void GraphicsContext::clipRect(const SkRect& rect, AntiAliasingMode aa, SkRegion ::Op op) 1534 void GraphicsContext::clipRect(const SkRect& rect, AntiAliasingMode aa, SkRegion ::Op op)
1535 { 1535 {
1536 ASSERT(m_canvas); 1536 ASSERT(m_canvas);
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
1639 { 1639 {
1640 if (contextDisabled()) 1640 if (contextDisabled())
1641 return; 1641 return;
1642 1642
1643 CompositeOperator previousOperator = compositeOperation(); 1643 CompositeOperator previousOperator = compositeOperation();
1644 setCompositeOperation(op); 1644 setCompositeOperation(op);
1645 fillRect(rect, color); 1645 fillRect(rect, color);
1646 setCompositeOperation(previousOperator); 1646 setCompositeOperation(previousOperator);
1647 } 1647 }
1648 1648
1649 void GraphicsContext::fillRoundedRect(const RoundedRect& rect, const Color& colo r) 1649 void GraphicsContext::fillRoundedRect(const FloatRoundedRect& rect, const Color& color)
1650 { 1650 {
1651 if (contextDisabled()) 1651 if (contextDisabled())
1652 return; 1652 return;
1653 1653
1654 if (rect.isRounded()) 1654 if (rect.isRounded())
1655 fillRoundedRect(rect.rect(), rect.radii().topLeft(), rect.radii().topRig ht(), rect.radii().bottomLeft(), rect.radii().bottomRight(), color); 1655 fillRoundedRect(rect.rect(), rect.radii().topLeft(), rect.radii().topRig ht(), rect.radii().bottomLeft(), rect.radii().bottomRight(), color);
1656 else 1656 else
1657 fillRect(rect.rect(), color); 1657 fillRect(rect.rect(), color);
1658 } 1658 }
1659 1659
1660 void GraphicsContext::fillRectWithRoundedHole(const IntRect& rect, const Rounded Rect& roundedHoleRect, const Color& color) 1660 void GraphicsContext::fillRectWithRoundedHole(const FloatRect& rect, const Float RoundedRect& roundedHoleRect, const Color& color)
1661 { 1661 {
1662 if (contextDisabled()) 1662 if (contextDisabled())
1663 return; 1663 return;
1664 1664
1665 Path path; 1665 Path path;
1666 path.addRect(rect); 1666 path.addRect(rect);
1667 1667
1668 if (!roundedHoleRect.radii().isZero()) 1668 if (!roundedHoleRect.radii().isZero())
1669 path.addRoundedRect(roundedHoleRect); 1669 path.addRoundedRect(roundedHoleRect);
1670 else 1670 else
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
1746 { 1746 {
1747 path->incReserve(numPoints); 1747 path->incReserve(numPoints);
1748 path->moveTo(WebCoreFloatToSkScalar(points[0].x()), 1748 path->moveTo(WebCoreFloatToSkScalar(points[0].x()),
1749 WebCoreFloatToSkScalar(points[0].y())); 1749 WebCoreFloatToSkScalar(points[0].y()));
1750 for (size_t i = 1; i < numPoints; ++i) { 1750 for (size_t i = 1; i < numPoints; ++i) {
1751 path->lineTo(WebCoreFloatToSkScalar(points[i].x()), 1751 path->lineTo(WebCoreFloatToSkScalar(points[i].x()),
1752 WebCoreFloatToSkScalar(points[i].y())); 1752 WebCoreFloatToSkScalar(points[i].y()));
1753 } 1753 }
1754 } 1754 }
1755 1755
1756 void GraphicsContext::setRadii(SkVector* radii, IntSize topLeft, IntSize topRigh t, IntSize bottomRight, IntSize bottomLeft) 1756 void GraphicsContext::setRadii(SkVector* radii, FloatSize topLeft, FloatSize top Right, FloatSize bottomRight, FloatSize bottomLeft)
1757 { 1757 {
1758 radii[SkRRect::kUpperLeft_Corner].set(SkIntToScalar(topLeft.width()), 1758 radii[SkRRect::kUpperLeft_Corner].set(SkIntToScalar(topLeft.width()),
1759 SkIntToScalar(topLeft.height())); 1759 SkIntToScalar(topLeft.height()));
1760 radii[SkRRect::kUpperRight_Corner].set(SkIntToScalar(topRight.width()), 1760 radii[SkRRect::kUpperRight_Corner].set(SkIntToScalar(topRight.width()),
1761 SkIntToScalar(topRight.height())); 1761 SkIntToScalar(topRight.height()));
1762 radii[SkRRect::kLowerRight_Corner].set(SkIntToScalar(bottomRight.width()), 1762 radii[SkRRect::kLowerRight_Corner].set(SkIntToScalar(bottomRight.width()),
1763 SkIntToScalar(bottomRight.height())); 1763 SkIntToScalar(bottomRight.height()));
1764 radii[SkRRect::kLowerLeft_Corner].set(SkIntToScalar(bottomLeft.width()), 1764 radii[SkRRect::kLowerLeft_Corner].set(SkIntToScalar(bottomLeft.width()),
1765 SkIntToScalar(bottomLeft.height())); 1765 SkIntToScalar(bottomLeft.height()));
1766 } 1766 }
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
1965 GraphicsContext::AutoCanvasRestorer::~AutoCanvasRestorer() 1965 GraphicsContext::AutoCanvasRestorer::~AutoCanvasRestorer()
1966 { 1966 {
1967 while (m_restoreCount) { 1967 while (m_restoreCount) {
1968 m_canvas->restore(); 1968 m_canvas->restore();
1969 m_restoreCount--; 1969 m_restoreCount--;
1970 } 1970 }
1971 1971
1972 } 1972 }
1973 1973
1974 } // namespace blink 1974 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698