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

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 5 years, 12 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 | 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 12 matching lines...) Expand all
23 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 23 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
24 * THE POSSIBILITY OF SUCH DAMAGE. 24 * THE POSSIBILITY OF SUCH DAMAGE.
25 */ 25 */
26 26
27 #include "config.h" 27 #include "config.h"
28 #include "platform/graphics/GraphicsContext.h" 28 #include "platform/graphics/GraphicsContext.h"
29 29
30 #include "platform/RuntimeEnabledFeatures.h" 30 #include "platform/RuntimeEnabledFeatures.h"
31 #include "platform/TraceEvent.h" 31 #include "platform/TraceEvent.h"
32 #include "platform/geometry/IntRect.h" 32 #include "platform/geometry/IntRect.h"
33 #include "platform/geometry/RoundedRect.h"
34 #include "platform/graphics/BitmapImage.h" 33 #include "platform/graphics/BitmapImage.h"
35 #include "platform/graphics/Gradient.h" 34 #include "platform/graphics/Gradient.h"
36 #include "platform/graphics/ImageBuffer.h" 35 #include "platform/graphics/ImageBuffer.h"
37 #include "platform/graphics/UnacceleratedImageBufferSurface.h" 36 #include "platform/graphics/UnacceleratedImageBufferSurface.h"
38 #include "platform/graphics/skia/SkiaUtils.h" 37 #include "platform/graphics/skia/SkiaUtils.h"
39 #include "platform/text/BidiResolver.h" 38 #include "platform/text/BidiResolver.h"
40 #include "platform/text/TextRunIterator.h" 39 #include "platform/text/TextRunIterator.h"
41 #include "platform/weborigin/KURL.h" 40 #include "platform/weborigin/KURL.h"
42 #include "third_party/skia/include/core/SkAnnotation.h" 41 #include "third_party/skia/include/core/SkAnnotation.h"
43 #include "third_party/skia/include/core/SkClipStack.h" 42 #include "third_party/skia/include/core/SkClipStack.h"
(...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after
698 697
699 if (focusRingRegion.isRect()) { 698 if (focusRingRegion.isRect()) {
700 drawFocusRingRect(SkRect::MakeFromIRect(focusRingRegion.getBounds()), co lor, width); 699 drawFocusRingRect(SkRect::MakeFromIRect(focusRingRegion.getBounds()), co lor, width);
701 } else { 700 } else {
702 SkPath path; 701 SkPath path;
703 if (focusRingRegion.getBoundaryPath(&path)) 702 if (focusRingRegion.getBoundaryPath(&path))
704 drawFocusRingPath(path, color, width); 703 drawFocusRingPath(path, color, width);
705 } 704 }
706 } 705 }
707 706
708 static inline IntRect areaCastingShadowInHole(const IntRect& holeRect, int shado wBlur, int shadowSpread, const IntSize& shadowOffset) 707 static inline FloatRect areaCastingShadowInHole(const FloatRect& holeRect, int s hadowBlur, int shadowSpread, const IntSize& shadowOffset)
709 { 708 {
710 IntRect bounds(holeRect); 709 IntRect bounds(holeRect);
711 710
712 bounds.inflate(shadowBlur); 711 bounds.inflate(shadowBlur);
713 712
714 if (shadowSpread < 0) 713 if (shadowSpread < 0)
715 bounds.inflate(-shadowSpread); 714 bounds.inflate(-shadowSpread);
716 715
717 IntRect offsetBounds = bounds; 716 IntRect offsetBounds = bounds;
718 offsetBounds.move(-shadowOffset); 717 offsetBounds.move(-shadowOffset);
719 return unionRect(bounds, offsetBounds); 718 return unionRect(bounds, offsetBounds);
720 } 719 }
721 720
722 void GraphicsContext::drawInnerShadow(const RoundedRect& rect, const Color& shad owColor, const IntSize shadowOffset, int shadowBlur, int shadowSpread, Edges cli ppedEdges) 721 void GraphicsContext::drawInnerShadow(const FloatRoundedRect& rect, const Color& shadowColor, const IntSize shadowOffset, int shadowBlur, int shadowSpread, Edge s clippedEdges)
723 { 722 {
724 if (contextDisabled()) 723 if (contextDisabled())
725 return; 724 return;
726 725
727 IntRect holeRect(rect.rect()); 726 FloatRect holeRect(rect.rect());
728 holeRect.inflate(-shadowSpread); 727 holeRect.inflate(-shadowSpread);
729 728
730 if (holeRect.isEmpty()) { 729 if (holeRect.isEmpty()) {
731 if (rect.isRounded()) 730 if (rect.isRounded())
732 fillRoundedRect(rect, shadowColor); 731 fillRoundedRect(rect, shadowColor);
733 else 732 else
734 fillRect(rect.rect(), shadowColor); 733 fillRect(rect.rect(), shadowColor);
735 return; 734 return;
736 } 735 }
737 736
738 if (clippedEdges & LeftEdge) { 737 if (clippedEdges & LeftEdge) {
739 holeRect.move(-std::max(shadowOffset.width(), 0) - shadowBlur, 0); 738 holeRect.move(-std::max(shadowOffset.width(), 0) - shadowBlur, 0);
740 holeRect.setWidth(holeRect.width() + std::max(shadowOffset.width(), 0) + shadowBlur); 739 holeRect.setWidth(holeRect.width() + std::max(shadowOffset.width(), 0) + shadowBlur);
741 } 740 }
742 if (clippedEdges & TopEdge) { 741 if (clippedEdges & TopEdge) {
743 holeRect.move(0, -std::max(shadowOffset.height(), 0) - shadowBlur); 742 holeRect.move(0, -std::max(shadowOffset.height(), 0) - shadowBlur);
744 holeRect.setHeight(holeRect.height() + std::max(shadowOffset.height(), 0 ) + shadowBlur); 743 holeRect.setHeight(holeRect.height() + std::max(shadowOffset.height(), 0 ) + shadowBlur);
745 } 744 }
746 if (clippedEdges & RightEdge) 745 if (clippedEdges & RightEdge)
747 holeRect.setWidth(holeRect.width() - std::min(shadowOffset.width(), 0) + shadowBlur); 746 holeRect.setWidth(holeRect.width() - std::min(shadowOffset.width(), 0) + shadowBlur);
748 if (clippedEdges & BottomEdge) 747 if (clippedEdges & BottomEdge)
749 holeRect.setHeight(holeRect.height() - std::min(shadowOffset.height(), 0 ) + shadowBlur); 748 holeRect.setHeight(holeRect.height() - std::min(shadowOffset.height(), 0 ) + shadowBlur);
750 749
751 Color fillColor(shadowColor.red(), shadowColor.green(), shadowColor.blue(), 255); 750 Color fillColor(shadowColor.red(), shadowColor.green(), shadowColor.blue(), 255);
752 751
753 IntRect outerRect = areaCastingShadowInHole(rect.rect(), shadowBlur, shadowS pread, shadowOffset); 752 FloatRect outerRect = areaCastingShadowInHole(rect.rect(), shadowBlur, shado wSpread, shadowOffset);
754 RoundedRect roundedHole(holeRect, rect.radii()); 753 FloatRoundedRect roundedHole(holeRect, rect.radii());
755 754
756 save(); 755 save();
757 if (rect.isRounded()) { 756 if (rect.isRounded()) {
758 Path path; 757 Path path;
759 path.addRoundedRect(rect); 758 path.addRoundedRect(rect);
760 clipPath(path); 759 clipPath(path);
761 roundedHole.shrinkRadii(shadowSpread); 760 roundedHole.shrinkRadii(shadowSpread);
762 } else { 761 } else {
763 clip(rect.rect()); 762 clip(rect.rect());
764 } 763 }
(...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after
1332 { 1331 {
1333 if (contextDisabled()) 1332 if (contextDisabled())
1334 return; 1333 return;
1335 1334
1336 SkRect r = rect; 1335 SkRect r = rect;
1337 SkPaint paint = immutableState()->fillPaint(); 1336 SkPaint paint = immutableState()->fillPaint();
1338 paint.setColor(color.rgb()); 1337 paint.setColor(color.rgb());
1339 drawRect(r, paint); 1338 drawRect(r, paint);
1340 } 1339 }
1341 1340
1342 void GraphicsContext::fillBetweenRoundedRects(const IntRect& outer, const IntSiz e& outerTopLeft, const IntSize& outerTopRight, const IntSize& outerBottomLeft, c onst IntSize& outerBottomRight, 1341 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) 1342 const FloatRect& inner, const FloatSize& innerTopLeft, const FloatSize& inne rTopRight, const FloatSize& innerBottomLeft, const FloatSize& innerBottomRight, const Color& color)
1344 { 1343 {
1345 ASSERT(m_canvas); 1344 ASSERT(m_canvas);
1346 if (contextDisabled()) 1345 if (contextDisabled())
1347 return; 1346 return;
1348 1347
1349 SkVector outerRadii[4]; 1348 SkVector outerRadii[4];
1350 SkVector innerRadii[4]; 1349 SkVector innerRadii[4];
1351 setRadii(outerRadii, outerTopLeft, outerTopRight, outerBottomRight, outerBot tomLeft); 1350 setRadii(outerRadii, outerTopLeft, outerTopRight, outerBottomRight, outerBot tomLeft);
1352 setRadii(innerRadii, innerTopLeft, innerTopRight, innerBottomRight, innerBot tomLeft); 1351 setRadii(innerRadii, innerTopLeft, innerTopRight, innerBottomRight, innerBot tomLeft);
1353 1352
1354 SkRRect rrOuter; 1353 SkRRect rrOuter;
1355 SkRRect rrInner; 1354 SkRRect rrInner;
1356 rrOuter.setRectRadii(outer, outerRadii); 1355 rrOuter.setRectRadii(outer, outerRadii);
1357 rrInner.setRectRadii(inner, innerRadii); 1356 rrInner.setRectRadii(inner, innerRadii);
1358 1357
1359 SkPaint paint(immutableState()->fillPaint()); 1358 SkPaint paint(immutableState()->fillPaint());
1360 paint.setColor(color.rgb()); 1359 paint.setColor(color.rgb());
1361 1360
1362 m_canvas->drawDRRect(rrOuter, rrInner, paint); 1361 m_canvas->drawDRRect(rrOuter, rrInner, paint);
1363 1362
1364 if (regionTrackingEnabled()) 1363 if (regionTrackingEnabled())
1365 m_trackedRegion.didDrawBounded(this, rrOuter.getBounds(), paint); 1364 m_trackedRegion.didDrawBounded(this, rrOuter.getBounds(), paint);
1366 } 1365 }
1367 1366
1368 void GraphicsContext::fillBetweenRoundedRects(const RoundedRect& outer, const Ro undedRect& inner, const Color& color) 1367 void GraphicsContext::fillBetweenRoundedRects(const FloatRoundedRect& outer, con st FloatRoundedRect& inner, const Color& color)
1369 { 1368 {
1370 fillBetweenRoundedRects(outer.rect(), outer.radii().topLeft(), outer.radii() .topRight(), outer.radii().bottomLeft(), outer.radii().bottomRight(), 1369 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); 1370 inner.rect(), inner.radii().topLeft(), inner.radii().topRight(), inner.r adii().bottomLeft(), inner.radii().bottomRight(), color);
1372 } 1371 }
1373 1372
1374 void GraphicsContext::fillRoundedRect(const IntRect& rect, const IntSize& topLef t, const IntSize& topRight, 1373 void GraphicsContext::fillRoundedRect(const FloatRect& rect, const FloatSize& to pLeft, const FloatSize& topRight,
1375 const IntSize& bottomLeft, const IntSize& bottomRight, const Color& color) 1374 const FloatSize& bottomLeft, const FloatSize& bottomRight, const Color& colo r)
1376 { 1375 {
1377 ASSERT(m_canvas); 1376 ASSERT(m_canvas);
1378 if (contextDisabled()) 1377 if (contextDisabled())
1379 return; 1378 return;
1380 1379
1381 if (topLeft.width() + topRight.width() > rect.width() 1380 if (topLeft.width() + topRight.width() > rect.width()
1382 || bottomLeft.width() + bottomRight.width() > rect.width() 1381 || bottomLeft.width() + bottomRight.width() > rect.width()
1383 || topLeft.height() + bottomLeft.height() > rect.height() 1382 || topLeft.height() + bottomLeft.height() > rect.height()
1384 || topRight.height() + bottomRight.height() > rect.height()) { 1383 || topRight.height() + bottomRight.height() > rect.height()) {
1385 // Not all the radii fit, return a rect. This matches the behavior of 1384 // 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 } 1455 }
1457 1456
1458 void GraphicsContext::strokeEllipse(const FloatRect& ellipse) 1457 void GraphicsContext::strokeEllipse(const FloatRect& ellipse)
1459 { 1458 {
1460 if (contextDisabled()) 1459 if (contextDisabled())
1461 return; 1460 return;
1462 1461
1463 drawOval(ellipse, immutableState()->strokePaint()); 1462 drawOval(ellipse, immutableState()->strokePaint());
1464 } 1463 }
1465 1464
1466 void GraphicsContext::clipRoundedRect(const RoundedRect& rect, SkRegion::Op regi onOp) 1465 void GraphicsContext::clipRoundedRect(const FloatRoundedRect& rect, SkRegion::Op regionOp)
1467 { 1466 {
1468 if (contextDisabled()) 1467 if (contextDisabled())
1469 return; 1468 return;
1470 1469
1471 if (!rect.isRounded()) { 1470 if (!rect.isRounded()) {
1472 clipRect(rect.rect(), NotAntiAliased, regionOp); 1471 clipRect(rect.rect(), NotAntiAliased, regionOp);
1473 return; 1472 return;
1474 } 1473 }
1475 1474
1476 SkVector radii[4]; 1475 SkVector radii[4];
1477 RoundedRect::Radii wkRadii = rect.radii(); 1476 FloatRoundedRect::Radii wkRadii = rect.radii();
1478 setRadii(radii, wkRadii.topLeft(), wkRadii.topRight(), wkRadii.bottomRight() , wkRadii.bottomLeft()); 1477 setRadii(radii, wkRadii.topLeft(), wkRadii.topRight(), wkRadii.bottomRight() , wkRadii.bottomLeft());
1479 1478
1480 SkRRect r; 1479 SkRRect r;
1481 r.setRectRadii(rect.rect(), radii); 1480 r.setRectRadii(rect.rect(), radii);
1482 1481
1483 clipRRect(r, AntiAliased, regionOp); 1482 clipRRect(r, AntiAliased, regionOp);
1484 } 1483 }
1485 1484
1486 void GraphicsContext::clipOut(const Path& pathToClip) 1485 void GraphicsContext::clipOut(const Path& pathToClip)
1487 { 1486 {
(...skipping 28 matching lines...) Expand all
1516 if (contextDisabled()) 1515 if (contextDisabled())
1517 return; 1516 return;
1518 1517
1519 ASSERT(numPoints > 2); 1518 ASSERT(numPoints > 2);
1520 1519
1521 SkPath path; 1520 SkPath path;
1522 setPathFromPoints(&path, numPoints, points); 1521 setPathFromPoints(&path, numPoints, points);
1523 clipPath(path, antialiased ? AntiAliased : NotAntiAliased); 1522 clipPath(path, antialiased ? AntiAliased : NotAntiAliased);
1524 } 1523 }
1525 1524
1526 void GraphicsContext::clipOutRoundedRect(const RoundedRect& rect) 1525 void GraphicsContext::clipOutRoundedRect(const FloatRoundedRect& rect)
1527 { 1526 {
1528 if (contextDisabled()) 1527 if (contextDisabled())
1529 return; 1528 return;
1530 1529
1531 clipRoundedRect(rect, SkRegion::kDifference_Op); 1530 clipRoundedRect(rect, SkRegion::kDifference_Op);
1532 } 1531 }
1533 1532
1534 void GraphicsContext::clipRect(const SkRect& rect, AntiAliasingMode aa, SkRegion ::Op op) 1533 void GraphicsContext::clipRect(const SkRect& rect, AntiAliasingMode aa, SkRegion ::Op op)
1535 { 1534 {
1536 ASSERT(m_canvas); 1535 ASSERT(m_canvas);
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
1639 { 1638 {
1640 if (contextDisabled()) 1639 if (contextDisabled())
1641 return; 1640 return;
1642 1641
1643 CompositeOperator previousOperator = compositeOperation(); 1642 CompositeOperator previousOperator = compositeOperation();
1644 setCompositeOperation(op); 1643 setCompositeOperation(op);
1645 fillRect(rect, color); 1644 fillRect(rect, color);
1646 setCompositeOperation(previousOperator); 1645 setCompositeOperation(previousOperator);
1647 } 1646 }
1648 1647
1649 void GraphicsContext::fillRoundedRect(const RoundedRect& rect, const Color& colo r) 1648 void GraphicsContext::fillRoundedRect(const FloatRoundedRect& rect, const Color& color)
1650 { 1649 {
1651 if (contextDisabled()) 1650 if (contextDisabled())
1652 return; 1651 return;
1653 1652
1654 if (rect.isRounded()) 1653 if (rect.isRounded())
1655 fillRoundedRect(rect.rect(), rect.radii().topLeft(), rect.radii().topRig ht(), rect.radii().bottomLeft(), rect.radii().bottomRight(), color); 1654 fillRoundedRect(rect.rect(), rect.radii().topLeft(), rect.radii().topRig ht(), rect.radii().bottomLeft(), rect.radii().bottomRight(), color);
1656 else 1655 else
1657 fillRect(rect.rect(), color); 1656 fillRect(rect.rect(), color);
1658 } 1657 }
1659 1658
1660 void GraphicsContext::fillRectWithRoundedHole(const IntRect& rect, const Rounded Rect& roundedHoleRect, const Color& color) 1659 void GraphicsContext::fillRectWithRoundedHole(const FloatRect& rect, const Float RoundedRect& roundedHoleRect, const Color& color)
1661 { 1660 {
1662 if (contextDisabled()) 1661 if (contextDisabled())
1663 return; 1662 return;
1664 1663
1665 Path path; 1664 Path path;
1666 path.addRect(rect); 1665 path.addRect(rect);
1667 1666
1668 if (!roundedHoleRect.radii().isZero()) 1667 if (!roundedHoleRect.radii().isZero())
1669 path.addRoundedRect(roundedHoleRect); 1668 path.addRoundedRect(roundedHoleRect);
1670 else 1669 else
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
1746 { 1745 {
1747 path->incReserve(numPoints); 1746 path->incReserve(numPoints);
1748 path->moveTo(WebCoreFloatToSkScalar(points[0].x()), 1747 path->moveTo(WebCoreFloatToSkScalar(points[0].x()),
1749 WebCoreFloatToSkScalar(points[0].y())); 1748 WebCoreFloatToSkScalar(points[0].y()));
1750 for (size_t i = 1; i < numPoints; ++i) { 1749 for (size_t i = 1; i < numPoints; ++i) {
1751 path->lineTo(WebCoreFloatToSkScalar(points[i].x()), 1750 path->lineTo(WebCoreFloatToSkScalar(points[i].x()),
1752 WebCoreFloatToSkScalar(points[i].y())); 1751 WebCoreFloatToSkScalar(points[i].y()));
1753 } 1752 }
1754 } 1753 }
1755 1754
1756 void GraphicsContext::setRadii(SkVector* radii, IntSize topLeft, IntSize topRigh t, IntSize bottomRight, IntSize bottomLeft) 1755 void GraphicsContext::setRadii(SkVector* radii, FloatSize topLeft, FloatSize top Right, FloatSize bottomRight, FloatSize bottomLeft)
1757 { 1756 {
1758 radii[SkRRect::kUpperLeft_Corner].set(SkIntToScalar(topLeft.width()), 1757 radii[SkRRect::kUpperLeft_Corner].set(SkIntToScalar(topLeft.width()),
1759 SkIntToScalar(topLeft.height())); 1758 SkIntToScalar(topLeft.height()));
1760 radii[SkRRect::kUpperRight_Corner].set(SkIntToScalar(topRight.width()), 1759 radii[SkRRect::kUpperRight_Corner].set(SkIntToScalar(topRight.width()),
1761 SkIntToScalar(topRight.height())); 1760 SkIntToScalar(topRight.height()));
1762 radii[SkRRect::kLowerRight_Corner].set(SkIntToScalar(bottomRight.width()), 1761 radii[SkRRect::kLowerRight_Corner].set(SkIntToScalar(bottomRight.width()),
1763 SkIntToScalar(bottomRight.height())); 1762 SkIntToScalar(bottomRight.height()));
1764 radii[SkRRect::kLowerLeft_Corner].set(SkIntToScalar(bottomLeft.width()), 1763 radii[SkRRect::kLowerLeft_Corner].set(SkIntToScalar(bottomLeft.width()),
1765 SkIntToScalar(bottomLeft.height())); 1764 SkIntToScalar(bottomLeft.height()));
1766 } 1765 }
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
1965 GraphicsContext::AutoCanvasRestorer::~AutoCanvasRestorer() 1964 GraphicsContext::AutoCanvasRestorer::~AutoCanvasRestorer()
1966 { 1965 {
1967 while (m_restoreCount) { 1966 while (m_restoreCount) {
1968 m_canvas->restore(); 1967 m_canvas->restore();
1969 m_restoreCount--; 1968 m_restoreCount--;
1970 } 1969 }
1971 1970
1972 } 1971 }
1973 1972
1974 } // namespace blink 1973 } // namespace blink
OLDNEW
« no previous file with comments | « Source/platform/graphics/GraphicsContext.h ('k') | Source/platform/graphics/GraphicsContextTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698