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

Side by Side Diff: tests/GpuDrawPathTest.cpp

Issue 2342873002: Fix key computation for GrPaths (Closed)
Patch Set: more MSVS warnings 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 | « src/gpu/batches/GrStencilAndCoverPathRenderer.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 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 "SkTypes.h" 8 #include "SkTypes.h"
9 9
10 #if SK_SUPPORT_GPU 10 #if SK_SUPPORT_GPU
11 11
12 #include "GrContext.h" 12 #include "GrContext.h"
13 #include "GrPath.h" 13 #include "GrPath.h"
14 #include "GrStyle.h" 14 #include "GrShape.h"
15 #include "SkBitmap.h" 15 #include "SkBitmap.h"
16 #include "SkCanvas.h" 16 #include "SkCanvas.h"
17 #include "SkColor.h" 17 #include "SkColor.h"
18 #include "SkPaint.h" 18 #include "SkPaint.h"
19 #include "SkPath.h" 19 #include "SkPath.h"
20 #include "SkDashPathEffect.h" 20 #include "SkDashPathEffect.h"
21 #include "SkRRect.h" 21 #include "SkRRect.h"
22 #include "SkRect.h" 22 #include "SkRect.h"
23 #include "SkSurface.h" 23 #include "SkSurface.h"
24 #include "Test.h" 24 #include "Test.h"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 sampleCount, nullptr)); 85 sampleCount, nullptr));
86 if (!surface) { 86 if (!surface) {
87 continue; 87 continue;
88 } 88 }
89 test_func(reporter, surface->getCanvas()); 89 test_func(reporter, surface->getCanvas());
90 } 90 }
91 } 91 }
92 } 92 }
93 93
94 DEF_GPUTEST(GrPathKeys, reporter, /*factory*/) { 94 DEF_GPUTEST(GrPathKeys, reporter, /*factory*/) {
95 // Keys should not ignore conic weights. 95 SkPaint strokePaint;
96 SkPath path1, path2; 96 strokePaint.setStyle(SkPaint::kStroke_Style);
97 path1.setIsVolatile(true); 97 strokePaint.setStrokeWidth(10.f);
98 path2.setIsVolatile(true); 98 GrStyle styles[] = {
99 SkPoint p0 = SkPoint::Make(100, 0); 99 GrStyle::SimpleFill(),
100 SkPoint p1 = SkPoint::Make(100, 100); 100 GrStyle::SimpleHairline(),
101 GrStyle(strokePaint)
102 };
101 103
102 path1.conicTo(p0, p1, .5f); 104 for (const GrStyle& style : styles) {
103 path2.conicTo(p0, p1, .7f); 105 // Keys should not ignore conic weights.
106 SkPath path1, path2;
107 path1.setIsVolatile(true);
108 path2.setIsVolatile(true);
109 SkPoint p0 = SkPoint::Make(100, 0);
110 SkPoint p1 = SkPoint::Make(100, 100);
104 111
105 bool isVolatile; 112 path1.conicTo(p0, p1, .5f);
106 GrUniqueKey key1, key2; 113 path2.conicTo(p0, p1, .7f);
107 GrPath::ComputeKey(path1, GrStyle::SimpleFill(), &key1, &isVolatile); 114
108 GrPath::ComputeKey(path2, GrStyle::SimpleFill(), &key2, &isVolatile); 115 bool isVolatile;
109 REPORTER_ASSERT(reporter, key1 != key2); 116 GrUniqueKey key1, key2;
117 // Even though the paths are marked volatile, they should have keys base d on the path data
118 // because they have a small amount of data.
119 GrPath::ComputeKey(GrShape(path1, GrStyle::SimpleFill()), &key1, &isVola tile);
120 REPORTER_ASSERT(reporter, !isVolatile);
121 REPORTER_ASSERT(reporter, key1.isValid());
122 GrPath::ComputeKey(GrShape(path2, GrStyle::SimpleFill()), &key2, &isVola tile);
123 REPORTER_ASSERT(reporter, !isVolatile);
124 REPORTER_ASSERT(reporter, key1.isValid());
125 REPORTER_ASSERT(reporter, key1 != key2);
126
127 // Ensure that recreating the GrShape doesn't change the key.
128 {
129 GrUniqueKey tempKey;
130 GrPath::ComputeKey(GrShape(path1, GrStyle::SimpleFill()), &tempKey, &isVolatile);
131 REPORTER_ASSERT(reporter, key1 == tempKey);
132 }
133
134 // Try a large path that is too big to be keyed off its data.
135 SkPath path3;
136 SkPath path4;
137 for (int i = 0; i < 1000; ++i) {
138 SkScalar s = SkIntToScalar(i);
139 path3.conicTo(s, 3.f * s / 4, s + 1.f, s, 0.5f + s / 2000.f);
140 path4.conicTo(s, 3.f * s / 4, s + 1.f, s, 0.3f + s / 2000.f);
141 }
142
143 GrUniqueKey key3, key4;
144 // These aren't marked volatile and so should have keys
145 GrPath::ComputeKey(GrShape(path3, style), &key3, &isVolatile);
146 REPORTER_ASSERT(reporter, !isVolatile);
147 REPORTER_ASSERT(reporter, key3.isValid());
148 GrPath::ComputeKey(GrShape(path4, style), &key4, &isVolatile);
149 REPORTER_ASSERT(reporter, !isVolatile);
150 REPORTER_ASSERT(reporter, key4.isValid());
151 REPORTER_ASSERT(reporter, key3 != key4);
152
153 {
154 GrUniqueKey tempKey;
155 path3.setIsVolatile(true);
156 GrPath::ComputeKey(GrShape(path3, style), &key1, &isVolatile);
157 REPORTER_ASSERT(reporter, isVolatile);
158 REPORTER_ASSERT(reporter, !tempKey.isValid());
159 }
160 }
110 } 161 }
111 162
112 #endif 163 #endif
OLDNEW
« no previous file with comments | « src/gpu/batches/GrStencilAndCoverPathRenderer.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698