diff options
author | Mike Reed <reed@google.com> | 2018-01-30 10:12:22 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2018-01-30 15:56:35 +0000 |
commit | 63227ca63b09ad534b52b1b1957202ab18aa53f7 (patch) | |
tree | d806fb6ce3fc95d4c08595943239455279f1ff57 /tests/VerticesTest.cpp | |
parent | ab2621d3e2d2055096b9fbebf16ee443e4ea90fb (diff) |
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 <caryclark@google.com>
Commit-Queue: Mike Reed <reed@google.com>
Diffstat (limited to 'tests/VerticesTest.cpp')
-rw-r--r-- | tests/VerticesTest.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
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); + } + } +} |