From 63227ca63b09ad534b52b1b1957202ab18aa53f7 Mon Sep 17 00:00:00 2001 From: Mike Reed Date: Tue, 30 Jan 2018 10:12:22 -0500 Subject: handle clipping large triangles originally found by fuzzer. Bug: skia: Change-Id: I45007a619f13936153c0db8a60b3631a2c9db20c Reviewed-on: https://skia-review.googlesource.com/101741 Reviewed-by: Cary Clark Commit-Queue: Mike Reed --- tests/VerticesTest.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'tests/VerticesTest.cpp') diff --git a/tests/VerticesTest.cpp b/tests/VerticesTest.cpp index 399aba2f21..f55adb0ed3 100644 --- a/tests/VerticesTest.cpp +++ b/tests/VerticesTest.cpp @@ -5,7 +5,10 @@ * found in the LICENSE file. */ +#include "SkCanvas.h" +#include "SkSurface.h" #include "SkVertices.h" +#include "sk_pixel_iter.h" #include "Test.h" static bool equal(const SkVertices* v0, const SkVertices* v1) { @@ -86,3 +89,30 @@ DEF_TEST(Vertices, reporter) { } } } + +static void fill_triangle(SkCanvas* canvas, const SkPoint pts[], SkColor c) { + SkColor colors[] = { c, c, c }; + auto verts = SkVertices::MakeCopy(SkVertices::kTriangles_VertexMode, 3, pts, nullptr, colors); + canvas->drawVertices(verts, SkBlendMode::kSrc, SkPaint()); +} + +DEF_TEST(Vertices_clipping, reporter) { + // A very large triangle has to be geometrically clipped (since its "fast" clipping is + // normally done in after building SkFixed coordinates). Check that we handle this. + // (and don't assert). + auto surf = SkSurface::MakeRasterN32Premul(3, 3); + + SkPoint pts[] = { { -10, 1 }, { -10, 2 }, { 1e9f, 1.5f } }; + fill_triangle(surf->getCanvas(), pts, SK_ColorBLACK); + + sk_tool_utils::PixelIter iter(surf.get()); + SkIPoint loc; + while (void* addr = iter.next(&loc)) { + SkPMColor c = *(SkPMColor*)addr; + if (loc.fY == 1) { + REPORTER_ASSERT(reporter, c == 0xFF000000); + } else { + REPORTER_ASSERT(reporter, c == 0); + } + } +} -- cgit v1.2.3