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

Side by Side Diff: src/gpu/GrOvalRenderer.cpp

Issue 2275423002: Fix for fat stroked roundrects. (Closed)
Patch Set: Created 4 years, 3 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 | « no previous file | 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 2013 Google Inc. 2 * Copyright 2013 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "GrOvalRenderer.h" 8 #include "GrOvalRenderer.h"
9 9
10 #include "GrBatchFlushState.h" 10 #include "GrBatchFlushState.h"
(...skipping 1332 matching lines...) Expand 10 before | Expand all | Expand 10 after
1343 // | | | | 1343 // | | | |
1344 // | | | | 1344 // | | | |
1345 // | | | | 1345 // | | | |
1346 // |_|________|_| 1346 // |_|________|_|
1347 // |_|________|_| 1347 // |_|________|_|
1348 // 1348 //
1349 // For strokes, we don't draw the center quad. 1349 // For strokes, we don't draw the center quad.
1350 // 1350 //
1351 // For circular roundrects, in the case where the stroke width is greater than t wice 1351 // For circular roundrects, in the case where the stroke width is greater than t wice
1352 // the corner radius (overstroke), we add additional geometry to mark out the re ctangle 1352 // the corner radius (overstroke), we add additional geometry to mark out the re ctangle
1353 // in the center: 1353 // in the center. The shared vertices are duplicated so we can set a different o uter radius
1354 // for the fill calculation.
1354 // ____________ 1355 // ____________
1355 // |_|________|_| 1356 // |_|________|_|
1356 // | |\ ____ /| | 1357 // | |\ ____ /| |
1357 // | | | | | | 1358 // | | | | | |
1358 // | | |____| | | 1359 // | | |____| | |
1359 // |_|/______\|_| 1360 // |_|/______\|_|
1360 // |_|________|_| 1361 // |_|________|_|
1361 // 1362 //
1362 // We don't draw the center quad from the fill rect in this case. 1363 // We don't draw the center quad from the fill rect in this case.
1363 1364
1364 static const uint16_t gRRectOverstrokeIndices[] = { 1365 static const uint16_t gRRectOverstrokeIndices[] = {
1365 // overstroke quads 1366 // overstroke quads
1366 // we place this at the beginning so that we can skip these indices when ren dering normally 1367 // we place this at the beginning so that we can skip these indices when ren dering normally
1367 5, 6, 17, 5, 17, 16, 1368 16, 17, 19, 16, 19, 18,
1368 17, 6, 10, 17, 10, 19, 1369 19, 17, 23, 19, 23, 21,
1369 10, 9, 18, 10, 18, 19, 1370 21, 23, 22, 21, 22, 20,
1370 18, 9, 5, 18, 5, 16, 1371 22, 16, 18, 22, 18, 20,
1371 1372
1372 // corners 1373 // corners
1373 0, 1, 5, 0, 5, 4, 1374 0, 1, 5, 0, 5, 4,
1374 2, 3, 7, 2, 7, 6, 1375 2, 3, 7, 2, 7, 6,
1375 8, 9, 13, 8, 13, 12, 1376 8, 9, 13, 8, 13, 12,
1376 10, 11, 15, 10, 15, 14, 1377 10, 11, 15, 10, 15, 14,
1377 1378
1378 // edges 1379 // edges
1379 1, 2, 6, 1, 6, 5, 1380 1, 2, 6, 1, 6, 5,
1380 4, 5, 9, 4, 9, 8, 1381 4, 5, 9, 4, 9, 8,
1381 6, 7, 11, 6, 11, 10, 1382 6, 7, 11, 6, 11, 10,
1382 9, 10, 14, 9, 14, 13, 1383 9, 10, 14, 9, 14, 13,
1383 1384
1384 // center 1385 // center
1385 // we place this at the end so that we can ignore these indices when not ren dering as filled 1386 // we place this at the end so that we can ignore these indices when not ren dering as filled
1386 5, 6, 10, 5, 10, 9, 1387 5, 6, 10, 5, 10, 9,
1387 }; 1388 };
1388 1389
1389 static const uint16_t* gRRectIndices = gRRectOverstrokeIndices + 6*4; 1390 static const uint16_t* gRRectIndices = gRRectOverstrokeIndices + 6*4;
1390 1391
1391 // overstroke count is arraysize 1392 // overstroke count is arraysize
1392 static const int kIndicesPerOverstrokeRRect = SK_ARRAY_COUNT(gRRectOverstrokeInd ices) - 6; 1393 static const int kIndicesPerOverstrokeRRect = SK_ARRAY_COUNT(gRRectOverstrokeInd ices) - 6;
1393 static const int kIndicesPerFillRRect = kIndicesPerOverstrokeRRect - 6*4 + 6; 1394 static const int kIndicesPerFillRRect = kIndicesPerOverstrokeRRect - 6*4 + 6;
1394 static const int kIndicesPerStrokeRRect = kIndicesPerFillRRect - 6; 1395 static const int kIndicesPerStrokeRRect = kIndicesPerFillRRect - 6;
1395 static const int kVertsPerStandardRRect = 16; 1396 static const int kVertsPerStandardRRect = 16;
1396 static const int kVertsPerOverstrokeRRect = 20; 1397 static const int kVertsPerOverstrokeRRect = 24;
1397 static const int kNumRRectsInIndexBuffer = 256; 1398 static const int kNumRRectsInIndexBuffer = 256;
1398 1399
1399 enum RRectType { 1400 enum RRectType {
1400 kFill_RRectType, 1401 kFill_RRectType,
1401 kStroke_RRectType, 1402 kStroke_RRectType,
1402 kOverstroke_RRectType 1403 kOverstroke_RRectType
1403 }; 1404 };
1404 1405
1405 GR_DECLARE_STATIC_UNIQUE_KEY(gStrokeRRectOnlyIndexBufferKey); 1406 GR_DECLARE_STATIC_UNIQUE_KEY(gStrokeRRectOnlyIndexBufferKey);
1406 GR_DECLARE_STATIC_UNIQUE_KEY(gRRectOnlyIndexBufferKey); 1407 GR_DECLARE_STATIC_UNIQUE_KEY(gRRectOnlyIndexBufferKey);
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
1604 verts++; 1605 verts++;
1605 1606
1606 verts->fPos = SkPoint::Make(bounds.fRight, yCoords[i]); 1607 verts->fPos = SkPoint::Make(bounds.fRight, yCoords[i]);
1607 verts->fColor = color; 1608 verts->fColor = color;
1608 verts->fOffset = SkPoint::Make(1, yOuterRadii[i]); 1609 verts->fOffset = SkPoint::Make(1, yOuterRadii[i]);
1609 verts->fOuterRadius = outerRadius; 1610 verts->fOuterRadius = outerRadius;
1610 verts->fInnerRadius = innerRadius; 1611 verts->fInnerRadius = innerRadius;
1611 verts++; 1612 verts++;
1612 } 1613 }
1613 // Add the additional vertices for overstroked rrects. 1614 // Add the additional vertices for overstroked rrects.
1615 // Effectively this is an additional rrect, drawn inside out,
1616 // with outerRadius == -innerRadius. This will give us correct AA in the center.
1614 // 1617 //
1615 // Note that args.fInnerRadius is negative in this case. 1618 // Note that args.fInnerRadius is negative in this case.
1616 // Also, the offset is a constant vector pointing to the right, whic h guarantees 1619 // Also, the offset is a constant vector pointing to the right, whic h guarantees
1617 // that the distance value along the inner rectangle is constant, wh ich 1620 // that the distance value along the inner rectangle is constant, wh ich
1618 // is what we want to get nice anti-aliasing. 1621 // is what we want to get nice anti-aliasing.
1619 if (kOverstroke_RRectType == fType) { 1622 if (kOverstroke_RRectType == fType) {
1620 // outerRadius = originalOuter + 0.5, and innerRadius = original Inner - 0.5. 1623 verts->fPos = SkPoint::Make(bounds.fLeft + outerRadius, yCoords[ 1]);
1621 // What we want is originalOuter - originalInner + 0.5, so we su btract 0.5. 1624 verts->fColor = color;
1622 SkScalar inset = outerRadius - args.fInnerRadius - SK_ScalarHalf ; 1625 verts->fOffset = SkPoint::Make(0, 0);
1626 verts->fOuterRadius = -args.fInnerRadius;
1627 verts->fInnerRadius = innerRadius;
1628 verts++;
1629
1630 verts->fPos = SkPoint::Make(bounds.fRight - outerRadius, yCoords [1]);
1631 verts->fColor = color;
1632 verts->fOffset = SkPoint::Make(0, 0);
1633 verts->fOuterRadius = -args.fInnerRadius;
1634 verts->fInnerRadius = innerRadius;
1635 verts++;
1636
1637 SkScalar inset = outerRadius - args.fInnerRadius;
1623 verts->fPos = SkPoint::Make(bounds.fLeft + inset, 1638 verts->fPos = SkPoint::Make(bounds.fLeft + inset,
1624 bounds.fTop + inset); 1639 bounds.fTop + inset);
1625 verts->fColor = color; 1640 verts->fColor = color;
1626 verts->fOffset = SkPoint::Make(1, 0); 1641 verts->fOffset = SkPoint::Make(1, 0);
1627 verts->fOuterRadius = outerRadius; 1642 verts->fOuterRadius = -args.fInnerRadius;
egdaniel 2016/08/25 20:24:27 does this need to be normalized? If so just use -i
jvanverth1 2016/08/26 14:35:20 No, the math is a little weird. We pass in normali
1628 verts->fInnerRadius = innerRadius; 1643 verts->fInnerRadius = innerRadius;
1629 verts++; 1644 verts++;
1630 1645
1631 verts->fPos = SkPoint::Make(bounds.fRight - inset, 1646 verts->fPos = SkPoint::Make(bounds.fRight - inset,
1632 bounds.fTop + inset); 1647 bounds.fTop + inset);
1633 verts->fColor = color; 1648 verts->fColor = color;
1634 verts->fOffset = SkPoint::Make(1, 0); 1649 verts->fOffset = SkPoint::Make(1, 0);
1635 verts->fOuterRadius = outerRadius; 1650 verts->fOuterRadius = -args.fInnerRadius;
1636 verts->fInnerRadius = innerRadius; 1651 verts->fInnerRadius = innerRadius;
1637 verts++; 1652 verts++;
1638 1653
1639 verts->fPos = SkPoint::Make(bounds.fLeft + inset, 1654 verts->fPos = SkPoint::Make(bounds.fLeft + inset,
1640 bounds.fBottom - inset); 1655 bounds.fBottom - inset);
1641 verts->fColor = color; 1656 verts->fColor = color;
1642 verts->fOffset = SkPoint::Make(1, 0); 1657 verts->fOffset = SkPoint::Make(1, 0);
1643 verts->fOuterRadius = outerRadius; 1658 verts->fOuterRadius = -args.fInnerRadius;
1644 verts->fInnerRadius = innerRadius; 1659 verts->fInnerRadius = innerRadius;
1645 verts++; 1660 verts++;
1646 1661
1647 verts->fPos = SkPoint::Make(bounds.fRight - inset, 1662 verts->fPos = SkPoint::Make(bounds.fRight - inset,
1648 bounds.fBottom - inset); 1663 bounds.fBottom - inset);
1649 verts->fColor = color; 1664 verts->fColor = color;
1650 verts->fOffset = SkPoint::Make(1, 0); 1665 verts->fOffset = SkPoint::Make(1, 0);
1651 verts->fOuterRadius = outerRadius; 1666 verts->fOuterRadius = -args.fInnerRadius;
1667 verts->fInnerRadius = innerRadius;
1668 verts++;
1669
1670 verts->fPos = SkPoint::Make(bounds.fLeft + outerRadius, yCoords[ 2]);
1671 verts->fColor = color;
1672 verts->fOffset = SkPoint::Make(0, 0);
1673 verts->fOuterRadius = -args.fInnerRadius;
1674 verts->fInnerRadius = innerRadius;
1675 verts++;
1676
1677 verts->fPos = SkPoint::Make(bounds.fRight - outerRadius, yCoords [2]);
1678 verts->fColor = color;
1679 verts->fOffset = SkPoint::Make(0, 0);
1680 verts->fOuterRadius = -args.fInnerRadius;
1652 verts->fInnerRadius = innerRadius; 1681 verts->fInnerRadius = innerRadius;
1653 verts++; 1682 verts++;
1654 } 1683 }
1655 } 1684 }
1656 1685
1657 helper.recordDraw(target, gp); 1686 helper.recordDraw(target, gp);
1658 } 1687 }
1659 1688
1660 bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { 1689 bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override {
1661 RRectCircleRendererBatch* that = t->cast<RRectCircleRendererBatch>(); 1690 RRectCircleRendererBatch* that = t->cast<RRectCircleRendererBatch>();
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after
2090 } 2119 }
2091 2120
2092 DRAW_BATCH_TEST_DEFINE(RRectBatch) { 2121 DRAW_BATCH_TEST_DEFINE(RRectBatch) {
2093 SkMatrix viewMatrix = GrTest::TestMatrixRectStaysRect(random); 2122 SkMatrix viewMatrix = GrTest::TestMatrixRectStaysRect(random);
2094 GrColor color = GrRandomColor(random); 2123 GrColor color = GrRandomColor(random);
2095 const SkRRect& rrect = GrTest::TestRRectSimple(random); 2124 const SkRRect& rrect = GrTest::TestRRectSimple(random);
2096 return create_rrect_batch(color, viewMatrix, rrect, GrTest::TestStrokeRec(ra ndom)); 2125 return create_rrect_batch(color, viewMatrix, rrect, GrTest::TestStrokeRec(ra ndom));
2097 } 2126 }
2098 2127
2099 #endif 2128 #endif
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698