aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/GpuDrawPathTest.cpp
diff options
context:
space:
mode:
authorGravatar fmalita <fmalita@chromium.org>2015-11-18 14:07:13 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2015-11-18 14:07:13 -0800
commitf9b1577d763988ebc043ddabf80674f71571ecff (patch)
treebee79110fb74f9b061794a1892f3eb6a82b6af3d /tests/GpuDrawPathTest.cpp
parentc8e8fc6e98e9272293fcf24d53428ddd6129b011 (diff)
Fix NVPR assert for equivalent ovals
For oval paths, GrPath ignores the point order and only uses the bounds when building its key. This is problematic because 1) point order is important when dashing 2) GrStencilAndCoverPathRenderer asserts that the lookup SkPath is equal to the cached SkPath - which is not the case for ovals with different directions/different point order. With this CL we no longer use the reduced oval key when dashing, and instead fall through to the more general path cases. The assert is adjusted to accommodate "equivalent" ovals (when not dashing). Also re-enabled & updated the GpuDrawPath unit test (disabled in https://codereview.chromium.org/1456463003/, presumably due to the use of uninitialized SkRects). R=bsalomon@google.com,robertphillips@google.com,cdalton@nvidia.com Review URL: https://codereview.chromium.org/1457073002
Diffstat (limited to 'tests/GpuDrawPathTest.cpp')
-rw-r--r--tests/GpuDrawPathTest.cpp50
1 files changed, 40 insertions, 10 deletions
diff --git a/tests/GpuDrawPathTest.cpp b/tests/GpuDrawPathTest.cpp
index f23f5ef8dc..c89e125be9 100644
--- a/tests/GpuDrawPathTest.cpp
+++ b/tests/GpuDrawPathTest.cpp
@@ -15,6 +15,8 @@
#include "SkCanvas.h"
#include "SkColor.h"
#include "SkPaint.h"
+#include "SkPath.h"
+#include "SkDashPathEffect.h"
#include "SkRRect.h"
#include "SkRect.h"
#include "SkSurface.h"
@@ -23,11 +25,12 @@
static void test_drawPathEmpty(skiatest::Reporter*, SkCanvas* canvas) {
// Filling an empty path should not crash.
SkPaint paint;
- canvas->drawRect(SkRect(), paint);
+ SkRect emptyRect = SkRect::MakeEmpty();
+ canvas->drawRect(emptyRect, paint);
canvas->drawPath(SkPath(), paint);
- canvas->drawOval(SkRect(), paint);
- canvas->drawRect(SkRect(), paint);
- canvas->drawRRect(SkRRect(), paint);
+ canvas->drawOval(emptyRect, paint);
+ canvas->drawRect(emptyRect, paint);
+ canvas->drawRRect(SkRRect::MakeRect(emptyRect), paint);
// Stroking an empty path should not crash.
paint.setAntiAlias(true);
@@ -35,17 +38,43 @@ static void test_drawPathEmpty(skiatest::Reporter*, SkCanvas* canvas) {
paint.setColor(SK_ColorGRAY);
paint.setStrokeWidth(SkIntToScalar(20));
paint.setStrokeJoin(SkPaint::kRound_Join);
- canvas->drawRect(SkRect(), paint);
+ canvas->drawRect(emptyRect, paint);
canvas->drawPath(SkPath(), paint);
- canvas->drawOval(SkRect(), paint);
- canvas->drawRect(SkRect(), paint);
- canvas->drawRRect(SkRRect(), paint);
+ canvas->drawOval(emptyRect, paint);
+ canvas->drawRect(emptyRect, paint);
+ canvas->drawRRect(SkRRect::MakeRect(emptyRect), paint);
}
+static void fill_and_stroke(SkCanvas* canvas, const SkPath& p1, const SkPath& p2,
+ SkPathEffect* effect) {
+ SkPaint paint;
+ paint.setAntiAlias(true);
+ paint.setPathEffect(effect);
-DEF_GPUTEST(GpuDrawPath, reporter, factory) {
- return;
+ canvas->drawPath(p1, paint);
+ canvas->drawPath(p2, paint);
+
+ paint.setStyle(SkPaint::kStroke_Style);
+ canvas->drawPath(p1, paint);
+ canvas->drawPath(p2, paint);
+}
+static void test_drawSameRectOvals(skiatest::Reporter*, SkCanvas* canvas) {
+ // Drawing ovals with similar bounds but different points order should not crash.
+
+ SkPath oval1, oval2;
+ const SkRect rect = SkRect::MakeWH(100, 50);
+ oval1.addOval(rect, SkPath::kCW_Direction);
+ oval2.addOval(rect, SkPath::kCCW_Direction);
+
+ fill_and_stroke(canvas, oval1, oval2, nullptr);
+
+ const SkScalar intervals[] = { 1, 1 };
+ SkAutoTUnref<SkPathEffect> dashEffect(SkDashPathEffect::Create(intervals, 2, 0));
+ fill_and_stroke(canvas, oval1, oval2, dashEffect);
+}
+
+DEF_GPUTEST(GpuDrawPath, reporter, factory) {
for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) {
GrContextFactory::GLContextType glType = static_cast<GrContextFactory::GLContextType>(type);
@@ -62,6 +91,7 @@ DEF_GPUTEST(GpuDrawPath, reporter, factory) {
SkSurface::NewRenderTarget(grContext, SkSurface::kNo_Budgeted, info,
sampleCounts[i], nullptr));
test_drawPathEmpty(reporter, surface->getCanvas());
+ test_drawSameRectOvals(reporter, surface->getCanvas());
}
}
}