Fix key computation for GrPaths
Improve tests to ensure paths are receiving valid keys
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2342873002
Review-Url: https://codereview.chromium.org/2342873002
diff --git a/tests/GpuDrawPathTest.cpp b/tests/GpuDrawPathTest.cpp
index c0b31f0..1a42a49 100644
--- a/tests/GpuDrawPathTest.cpp
+++ b/tests/GpuDrawPathTest.cpp
@@ -11,7 +11,7 @@
#include "GrContext.h"
#include "GrPath.h"
-#include "GrStyle.h"
+#include "GrShape.h"
#include "SkBitmap.h"
#include "SkCanvas.h"
#include "SkColor.h"
@@ -92,21 +92,72 @@
}
DEF_GPUTEST(GrPathKeys, reporter, /*factory*/) {
- // Keys should not ignore conic weights.
- SkPath path1, path2;
- path1.setIsVolatile(true);
- path2.setIsVolatile(true);
- SkPoint p0 = SkPoint::Make(100, 0);
- SkPoint p1 = SkPoint::Make(100, 100);
+ SkPaint strokePaint;
+ strokePaint.setStyle(SkPaint::kStroke_Style);
+ strokePaint.setStrokeWidth(10.f);
+ GrStyle styles[] = {
+ GrStyle::SimpleFill(),
+ GrStyle::SimpleHairline(),
+ GrStyle(strokePaint)
+ };
- path1.conicTo(p0, p1, .5f);
- path2.conicTo(p0, p1, .7f);
+ for (const GrStyle& style : styles) {
+ // Keys should not ignore conic weights.
+ SkPath path1, path2;
+ path1.setIsVolatile(true);
+ path2.setIsVolatile(true);
+ SkPoint p0 = SkPoint::Make(100, 0);
+ SkPoint p1 = SkPoint::Make(100, 100);
- bool isVolatile;
- GrUniqueKey key1, key2;
- GrPath::ComputeKey(path1, GrStyle::SimpleFill(), &key1, &isVolatile);
- GrPath::ComputeKey(path2, GrStyle::SimpleFill(), &key2, &isVolatile);
- REPORTER_ASSERT(reporter, key1 != key2);
+ path1.conicTo(p0, p1, .5f);
+ path2.conicTo(p0, p1, .7f);
+
+ bool isVolatile;
+ GrUniqueKey key1, key2;
+ // Even though the paths are marked volatile, they should have keys based on the path data
+ // because they have a small amount of data.
+ GrPath::ComputeKey(GrShape(path1, GrStyle::SimpleFill()), &key1, &isVolatile);
+ REPORTER_ASSERT(reporter, !isVolatile);
+ REPORTER_ASSERT(reporter, key1.isValid());
+ GrPath::ComputeKey(GrShape(path2, GrStyle::SimpleFill()), &key2, &isVolatile);
+ REPORTER_ASSERT(reporter, !isVolatile);
+ REPORTER_ASSERT(reporter, key1.isValid());
+ REPORTER_ASSERT(reporter, key1 != key2);
+
+ // Ensure that recreating the GrShape doesn't change the key.
+ {
+ GrUniqueKey tempKey;
+ GrPath::ComputeKey(GrShape(path1, GrStyle::SimpleFill()), &tempKey, &isVolatile);
+ REPORTER_ASSERT(reporter, key1 == tempKey);
+ }
+
+ // Try a large path that is too big to be keyed off its data.
+ SkPath path3;
+ SkPath path4;
+ for (int i = 0; i < 1000; ++i) {
+ SkScalar s = SkIntToScalar(i);
+ path3.conicTo(s, 3.f * s / 4, s + 1.f, s, 0.5f + s / 2000.f);
+ path4.conicTo(s, 3.f * s / 4, s + 1.f, s, 0.3f + s / 2000.f);
+ }
+
+ GrUniqueKey key3, key4;
+ // These aren't marked volatile and so should have keys
+ GrPath::ComputeKey(GrShape(path3, style), &key3, &isVolatile);
+ REPORTER_ASSERT(reporter, !isVolatile);
+ REPORTER_ASSERT(reporter, key3.isValid());
+ GrPath::ComputeKey(GrShape(path4, style), &key4, &isVolatile);
+ REPORTER_ASSERT(reporter, !isVolatile);
+ REPORTER_ASSERT(reporter, key4.isValid());
+ REPORTER_ASSERT(reporter, key3 != key4);
+
+ {
+ GrUniqueKey tempKey;
+ path3.setIsVolatile(true);
+ GrPath::ComputeKey(GrShape(path3, style), &key1, &isVolatile);
+ REPORTER_ASSERT(reporter, isVolatile);
+ REPORTER_ASSERT(reporter, !tempKey.isValid());
+ }
+ }
}
#endif