1 /* 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" 12 #include "SkVertices.h" 13 #include "Test.h" 14 15 void tessellate_shadow(skiatest::Reporter* reporter, const SkPath& path, const SkMatrix& ctm, 16 bool expectSuccess) { 17 18 auto heightParams = SkPoint3::Make(0, 0, 4); 19 20 auto verts = SkShadowTessellator::MakeAmbient(path, ctm, heightParams, true); 21 if (expectSuccess != SkToBool(verts)) { 22 ERRORF(reporter, "Expected shadow tessellation to %s but it did not.", 23 expectSuccess ? "succeed" : "fail"); 24 } 25 verts = SkShadowTessellator::MakeAmbient(path, ctm, heightParams, false); 26 if (expectSuccess != SkToBool(verts)) { 27 ERRORF(reporter, "Expected shadow tessellation to %s but it did not.", 28 expectSuccess ? "succeed" : "fail"); 29 } 30 verts = SkShadowTessellator::MakeSpot(path, ctm, heightParams, {0, 0, 128}, 128.f, false); 31 if (expectSuccess != SkToBool(verts)) { 32 ERRORF(reporter, "Expected shadow tessellation to %s but it did not.", 33 expectSuccess ? "succeed" : "fail"); 34 } 35 verts = SkShadowTessellator::MakeSpot(path, ctm, heightParams, {0, 0, 128}, 128.f, false); 36 if (expectSuccess != SkToBool(verts)) { 37 ERRORF(reporter, "Expected shadow tessellation to %s but it did not.", 38 expectSuccess ? "succeed" : "fail"); 39 } 40 } 41 42 DEF_TEST(ShadowUtils, reporter) { 43 SkCanvas canvas(100, 100); 44 45 SkPath path; 46 path.cubicTo(100, 50, 20, 100, 0, 0); 47 tessellate_shadow(reporter, path, canvas.getTotalMatrix(), true); 48 49 // This line segment has no area and no shadow. 50 path.reset(); 51 path.lineTo(10.f, 10.f); 52 tessellate_shadow(reporter, path, canvas.getTotalMatrix(), false); 53 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 } 59 tessellate_shadow(reporter, path, canvas.getTotalMatrix(), false); 60 } 61