blob: c0e20d57e48c5bb09bc261f5d678c7e715cff5e8 [file] [log] [blame]
Brian Salomon0dda9cb2017-02-03 10:33:25 -05001/*
2 * Copyright 2017 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "SkCanvas.h"
9#include "SkPath.h"
10#include "SkShadowTessellator.h"
11#include "SkShadowUtils.h"
Brian Salomonaff27a22017-02-06 15:47:44 -050012#include "SkVertices.h"
Brian Salomon0dda9cb2017-02-03 10:33:25 -050013#include "Test.h"
14
Jim Van Vertha84898d2017-02-06 13:38:23 -050015void tessellate_shadow(skiatest::Reporter* reporter, const SkPath& path, const SkMatrix& ctm,
16 bool expectSuccess) {
Jim Van Verthb4366552017-03-27 14:25:29 -040017
Jim Van Verthe308a122017-05-08 14:19:30 -040018 auto heightParams = SkPoint3::Make(0, 0, 4);
Mike Klein98668172017-04-13 12:20:21 -040019
Jim Van Verthe308a122017-05-08 14:19:30 -040020 auto verts = SkShadowTessellator::MakeAmbient(path, ctm, heightParams, true);
Brian Salomon0dda9cb2017-02-03 10:33:25 -050021 if (expectSuccess != SkToBool(verts)) {
Brian Salomonaff27a22017-02-06 15:47:44 -050022 ERRORF(reporter, "Expected shadow tessellation to %s but it did not.",
Brian Salomon0dda9cb2017-02-03 10:33:25 -050023 expectSuccess ? "succeed" : "fail");
24 }
Jim Van Verthe308a122017-05-08 14:19:30 -040025 verts = SkShadowTessellator::MakeAmbient(path, ctm, heightParams, false);
Brian Salomon0dda9cb2017-02-03 10:33:25 -050026 if (expectSuccess != SkToBool(verts)) {
Brian Salomonaff27a22017-02-06 15:47:44 -050027 ERRORF(reporter, "Expected shadow tessellation to %s but it did not.",
Brian Salomon0dda9cb2017-02-03 10:33:25 -050028 expectSuccess ? "succeed" : "fail");
29 }
Jim Van Verthe308a122017-05-08 14:19:30 -040030 verts = SkShadowTessellator::MakeSpot(path, ctm, heightParams, {0, 0, 128}, 128.f, false);
Brian Salomon0dda9cb2017-02-03 10:33:25 -050031 if (expectSuccess != SkToBool(verts)) {
Brian Salomonaff27a22017-02-06 15:47:44 -050032 ERRORF(reporter, "Expected shadow tessellation to %s but it did not.",
Brian Salomon0dda9cb2017-02-03 10:33:25 -050033 expectSuccess ? "succeed" : "fail");
34 }
Jim Van Verthe308a122017-05-08 14:19:30 -040035 verts = SkShadowTessellator::MakeSpot(path, ctm, heightParams, {0, 0, 128}, 128.f, false);
Brian Salomon0dda9cb2017-02-03 10:33:25 -050036 if (expectSuccess != SkToBool(verts)) {
Brian Salomonaff27a22017-02-06 15:47:44 -050037 ERRORF(reporter, "Expected shadow tessellation to %s but it did not.",
Brian Salomon0dda9cb2017-02-03 10:33:25 -050038 expectSuccess ? "succeed" : "fail");
39 }
40}
41
42DEF_TEST(ShadowUtils, reporter) {
43 SkCanvas canvas(100, 100);
Mike Klein98668172017-04-13 12:20:21 -040044
Brian Salomon0dda9cb2017-02-03 10:33:25 -050045 SkPath path;
46 path.cubicTo(100, 50, 20, 100, 0, 0);
Mike Klein98668172017-04-13 12:20:21 -040047 tessellate_shadow(reporter, path, canvas.getTotalMatrix(), true);
Brian Salomon0dda9cb2017-02-03 10:33:25 -050048
49 // This line segment has no area and no shadow.
50 path.reset();
51 path.lineTo(10.f, 10.f);
Jim Van Vertha84898d2017-02-06 13:38:23 -050052 tessellate_shadow(reporter, path, canvas.getTotalMatrix(), false);
Brian Salomon0dda9cb2017-02-03 10:33:25 -050053
54 // A series of colinear line segments
55 path.reset();
56 for (int i = 0; i < 10; ++i) {
57 path.lineTo((SkScalar)i, (SkScalar)i);
58 }
Jim Van Vertha84898d2017-02-06 13:38:23 -050059 tessellate_shadow(reporter, path, canvas.getTotalMatrix(), false);
Brian Salomon0dda9cb2017-02-03 10:33:25 -050060}