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

Side by Side Diff: tests/GrShapeTest.cpp

Issue 2369513002: Don't compute path keys for volatile paths in GrShape. (Closed)
Patch Set: fix test 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 | « tests/GpuDrawPathTest.cpp ('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 2016 Google Inc. 2 * Copyright 2016 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 <initializer_list> 8 #include <initializer_list>
9 #include <functional> 9 #include <functional>
10 #include "Test.h" 10 #include "Test.h"
(...skipping 1143 matching lines...) Expand 10 before | Expand all | Expand 10 after
1154 // The base shape cannot perform canonicalization on the path's fill typ e because of an 1154 // The base shape cannot perform canonicalization on the path's fill typ e because of an
1155 // unknown path effect. However, after the path effect is applied the re sulting hairline 1155 // unknown path effect. However, after the path effect is applied the re sulting hairline
1156 // shape will canonicalize the path fill type since hairlines (and strok ing in general) 1156 // shape will canonicalize the path fill type since hairlines (and strok ing in general)
1157 // don't distinguish between even/odd and non-zero winding. 1157 // don't distinguish between even/odd and non-zero winding.
1158 a.setFillType(b.getFillType()); 1158 a.setFillType(b.getFillType());
1159 REPORTER_ASSERT(reporter, a == b); 1159 REPORTER_ASSERT(reporter, a == b);
1160 REPORTER_ASSERT(reporter, a == c); 1160 REPORTER_ASSERT(reporter, a == c);
1161 // If the resulting path is small enough then it will have a key. 1161 // If the resulting path is small enough then it will have a key.
1162 REPORTER_ASSERT(reporter, paths_fill_same(a, b)); 1162 REPORTER_ASSERT(reporter, paths_fill_same(a, b));
1163 REPORTER_ASSERT(reporter, paths_fill_same(a, c)); 1163 REPORTER_ASSERT(reporter, paths_fill_same(a, c));
1164 if (c.countVerbs() <= GrShape::kMaxKeyFromDataVerbCnt) { 1164 REPORTER_ASSERT(reporter, peCase.appliedPathEffectKey().empty());
1165 REPORTER_ASSERT(reporter, !peCase.appliedPathEffectKey().empty()); 1165 REPORTER_ASSERT(reporter, peCase.appliedFullStyleKey().empty());
1166 REPORTER_ASSERT(reporter, peCase.appliedPathEffectKey() ==
1167 peCase.appliedFullStyleKey());
1168 } else {
1169 REPORTER_ASSERT(reporter, peCase.appliedPathEffectKey().empty());
1170 REPORTER_ASSERT(reporter, peCase.appliedFullStyleKey().empty());
1171 }
1172 } 1166 }
1173 REPORTER_ASSERT(reporter, peCase.appliedPathEffectShape().style().isSimpleHa irline()); 1167 REPORTER_ASSERT(reporter, peCase.appliedPathEffectShape().style().isSimpleHa irline());
1174 REPORTER_ASSERT(reporter, peCase.appliedFullStyleShape().style().isSimpleHai rline()); 1168 REPORTER_ASSERT(reporter, peCase.appliedFullStyleShape().style().isSimpleHai rline());
1175 } 1169 }
1176 1170
1177 void test_volatile_path(skiatest::Reporter* reporter, const Geo& geo) { 1171 void test_volatile_path(skiatest::Reporter* reporter, const Geo& geo) {
1178 SkPath vPath = geo.path(); 1172 SkPath vPath = geo.path();
1179 vPath.setIsVolatile(true); 1173 vPath.setIsVolatile(true);
1180 1174
1181 SkPaint dashAndStroke; 1175 SkPaint dashAndStroke;
1182 dashAndStroke.setPathEffect(make_dash()); 1176 dashAndStroke.setPathEffect(make_dash());
1183 dashAndStroke.setStrokeWidth(2.f); 1177 dashAndStroke.setStrokeWidth(2.f);
1184 dashAndStroke.setStyle(SkPaint::kStroke_Style); 1178 dashAndStroke.setStyle(SkPaint::kStroke_Style);
1185 TestCase volatileCase(reporter, vPath, dashAndStroke); 1179 TestCase volatileCase(reporter, vPath, dashAndStroke);
1186 // We expect a shape made from a volatile path to have a key iff the shape i s recognized 1180 // We expect a shape made from a volatile path to have a key iff the shape i s recognized
1187 // as a specialized geometry or it has a small verb count. 1181 // as a specialized geometry.
1188 if (geo.isNonPath(dashAndStroke) || vPath.countVerbs() <= GrShape::kMaxKeyFr omDataVerbCnt) { 1182 if (geo.isNonPath(dashAndStroke)) {
1189 REPORTER_ASSERT(reporter, SkToBool(volatileCase.baseKey().count())); 1183 REPORTER_ASSERT(reporter, SkToBool(volatileCase.baseKey().count()));
1190 // In this case all the keys should be identical to the non-volatile cas e. 1184 // In this case all the keys should be identical to the non-volatile cas e.
1191 TestCase nonVolatileCase(reporter, geo.path(), dashAndStroke); 1185 TestCase nonVolatileCase(reporter, geo.path(), dashAndStroke);
1192 volatileCase.compare(reporter, nonVolatileCase, TestCase::kAllSame_Compa risonExpecation); 1186 volatileCase.compare(reporter, nonVolatileCase, TestCase::kAllSame_Compa risonExpecation);
1193 } else { 1187 } else {
1194 // None of the keys should be valid. 1188 // None of the keys should be valid.
1195 REPORTER_ASSERT(reporter, !SkToBool(volatileCase.baseKey().count())); 1189 REPORTER_ASSERT(reporter, !SkToBool(volatileCase.baseKey().count()));
1196 REPORTER_ASSERT(reporter, !SkToBool(volatileCase.appliedPathEffectKey(). count())); 1190 REPORTER_ASSERT(reporter, !SkToBool(volatileCase.appliedPathEffectKey(). count()));
1197 REPORTER_ASSERT(reporter, !SkToBool(volatileCase.appliedFullStyleKey().c ount())); 1191 REPORTER_ASSERT(reporter, !SkToBool(volatileCase.appliedFullStyleKey().c ount()));
1198 REPORTER_ASSERT(reporter, !SkToBool(volatileCase.appliedPathEffectThenSt rokeKey().count())); 1192 REPORTER_ASSERT(reporter, !SkToBool(volatileCase.appliedPathEffectThenSt rokeKey().count()));
(...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after
1781 1775
1782 static void test_short_path_keys(skiatest::Reporter* r) { 1776 static void test_short_path_keys(skiatest::Reporter* r) {
1783 SkPaint paints[4]; 1777 SkPaint paints[4];
1784 paints[1].setStyle(SkPaint::kStroke_Style); 1778 paints[1].setStyle(SkPaint::kStroke_Style);
1785 paints[1].setStrokeWidth(5.f); 1779 paints[1].setStrokeWidth(5.f);
1786 paints[2].setStyle(SkPaint::kStroke_Style); 1780 paints[2].setStyle(SkPaint::kStroke_Style);
1787 paints[2].setStrokeWidth(0.f); 1781 paints[2].setStrokeWidth(0.f);
1788 paints[3].setStyle(SkPaint::kStrokeAndFill_Style); 1782 paints[3].setStyle(SkPaint::kStrokeAndFill_Style);
1789 paints[3].setStrokeWidth(5.f); 1783 paints[3].setStrokeWidth(5.f);
1790 1784
1791 auto compare = [r, &paints] (SkPath* pathA, SkPath* pathB, 1785 auto compare = [r, &paints] (const SkPath& pathA, const SkPath& pathB,
1792 TestCase::ComparisonExpecation expectation) { 1786 TestCase::ComparisonExpecation expectation) {
1787 SkPath volatileA = pathA;
1788 SkPath volatileB = pathB;
1789 volatileA.setIsVolatile(true);
1790 volatileB.setIsVolatile(true);
1793 for (const SkPaint& paint : paints) { 1791 for (const SkPaint& paint : paints) {
1792 REPORTER_ASSERT(r, !GrShape(volatileA, paint).hasUnstyledKey());
1793 REPORTER_ASSERT(r, !GrShape(volatileB, paint).hasUnstyledKey());
1794 for (PathGeo::Invert invert : {PathGeo::Invert::kNo, PathGeo::Invert ::kYes}) { 1794 for (PathGeo::Invert invert : {PathGeo::Invert::kNo, PathGeo::Invert ::kYes}) {
1795 for (bool aIsVolatile : {false, true}) { 1795 TestCase caseA(PathGeo(pathA, invert), paint, r);
1796 for (bool bIsVolatile : {false, true}) { 1796 TestCase caseB(PathGeo(pathB, invert), paint, r);
1797 pathA->setIsVolatile(aIsVolatile); 1797 caseA.compare(r, caseB, expectation);
1798 pathB->setIsVolatile(bIsVolatile);
1799 TestCase caseA(PathGeo(*pathA, invert), paint, r);
1800 TestCase caseB(PathGeo(*pathB, invert), paint, r);
1801 caseA.compare(r, caseB, expectation);
1802 }
1803 }
1804 } 1798 }
1805 } 1799 }
1806 }; 1800 };
1807 1801
1808 SkPath pathA; 1802 SkPath pathA;
1809 SkPath pathB; 1803 SkPath pathB;
1810 1804
1811 // Two identical paths 1805 // Two identical paths
1812 pathA.lineTo(10.f, 10.f); 1806 pathA.lineTo(10.f, 10.f);
1813 pathA.conicTo(20.f, 20.f, 20.f, 30.f, 0.7f); 1807 pathA.conicTo(20.f, 20.f, 20.f, 30.f, 0.7f);
1814 1808
1815 pathB.lineTo(10.f, 10.f); 1809 pathB.lineTo(10.f, 10.f);
1816 pathB.conicTo(20.f, 20.f, 20.f, 30.f, 0.7f); 1810 pathB.conicTo(20.f, 20.f, 20.f, 30.f, 0.7f);
1817 compare(&pathA, &pathB, TestCase::kAllSame_ComparisonExpecation); 1811 compare(pathA, pathB, TestCase::kAllSame_ComparisonExpecation);
1818 1812
1819 // Give path b a different point 1813 // Give path b a different point
1820 pathB.reset(); 1814 pathB.reset();
1821 pathB.lineTo(10.f, 10.f); 1815 pathB.lineTo(10.f, 10.f);
1822 pathB.conicTo(21.f, 20.f, 20.f, 30.f, 0.7f); 1816 pathB.conicTo(21.f, 20.f, 20.f, 30.f, 0.7f);
1823 compare(&pathA, &pathB, TestCase::kAllDifferent_ComparisonExpecation); 1817 compare(pathA, pathB, TestCase::kAllDifferent_ComparisonExpecation);
1824 1818
1825 // Give path b a different conic weight 1819 // Give path b a different conic weight
1826 pathB.reset(); 1820 pathB.reset();
1827 pathB.lineTo(10.f, 10.f); 1821 pathB.lineTo(10.f, 10.f);
1828 pathB.conicTo(20.f, 20.f, 20.f, 30.f, 0.6f); 1822 pathB.conicTo(20.f, 20.f, 20.f, 30.f, 0.6f);
1829 compare(&pathA, &pathB, TestCase::kAllDifferent_ComparisonExpecation); 1823 compare(pathA, pathB, TestCase::kAllDifferent_ComparisonExpecation);
1830 1824
1831 // Give path b an extra lineTo verb 1825 // Give path b an extra lineTo verb
1832 pathB.reset(); 1826 pathB.reset();
1833 pathB.lineTo(10.f, 10.f); 1827 pathB.lineTo(10.f, 10.f);
1834 pathB.conicTo(20.f, 20.f, 20.f, 30.f, 0.6f); 1828 pathB.conicTo(20.f, 20.f, 20.f, 30.f, 0.6f);
1835 pathB.lineTo(50.f, 50.f); 1829 pathB.lineTo(50.f, 50.f);
1836 compare(&pathA, &pathB, TestCase::kAllDifferent_ComparisonExpecation); 1830 compare(pathA, pathB, TestCase::kAllDifferent_ComparisonExpecation);
1837 1831
1838 // Give path b a close 1832 // Give path b a close
1839 pathB.reset(); 1833 pathB.reset();
1840 pathB.lineTo(10.f, 10.f); 1834 pathB.lineTo(10.f, 10.f);
1841 pathB.conicTo(20.f, 20.f, 20.f, 30.f, 0.7f); 1835 pathB.conicTo(20.f, 20.f, 20.f, 30.f, 0.7f);
1842 pathB.close(); 1836 pathB.close();
1843 compare(&pathA, &pathB, TestCase::kAllDifferent_ComparisonExpecation); 1837 compare(pathA, pathB, TestCase::kAllDifferent_ComparisonExpecation);
1844 } 1838 }
1845 1839
1846 DEF_TEST(GrShape, reporter) { 1840 DEF_TEST(GrShape, reporter) {
1847 SkTArray<std::unique_ptr<Geo>> geos; 1841 SkTArray<std::unique_ptr<Geo>> geos;
1848 SkTArray<std::unique_ptr<RRectPathGeo>> rrectPathGeos; 1842 SkTArray<std::unique_ptr<RRectPathGeo>> rrectPathGeos;
1849 1843
1850 for (auto r : { SkRect::MakeWH(10, 20), 1844 for (auto r : { SkRect::MakeWH(10, 20),
1851 SkRect::MakeWH(-10, -20), 1845 SkRect::MakeWH(-10, -20),
1852 SkRect::MakeWH(-10, 20), 1846 SkRect::MakeWH(-10, 20),
1853 SkRect::MakeWH(10, -20)}) { 1847 SkRect::MakeWH(10, -20)}) {
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
1967 test_empty_shape(reporter); 1961 test_empty_shape(reporter);
1968 1962
1969 test_lines(reporter); 1963 test_lines(reporter);
1970 1964
1971 test_stroked_lines(reporter); 1965 test_stroked_lines(reporter);
1972 1966
1973 test_short_path_keys(reporter); 1967 test_short_path_keys(reporter);
1974 } 1968 }
1975 1969
1976 #endif 1970 #endif
OLDNEW
« no previous file with comments | « tests/GpuDrawPathTest.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698