aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/ShadowUtilsTest.cpp
blob: adcb5031f4d22f516f9ff2309c1ad6181d53965c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
 * Copyright 2017 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "SkCanvas.h"
#include "SkPath.h"
#include "SkShadowTessellator.h"
#include "SkShadowUtils.h"
#include "Test.h"

void tessellate_shadow(skiatest::Reporter* reporter, const SkPath& path, bool expectSuccess) {
    static constexpr SkScalar kRadius = 2.f;
    static constexpr SkColor kUmbraColor = 0xFFFFFFFF;
    static constexpr SkColor kPenumbraColor = 0x20202020;
    auto verts = SkShadowVertices::MakeAmbient(path, kRadius, kUmbraColor, kPenumbraColor, true);
    if (expectSuccess != SkToBool(verts)) {
        ERRORF(reporter, "Expected shadow tessellation to % but it did not.",
               expectSuccess ? "succeed" : "fail");
    }
    verts = SkShadowVertices::MakeAmbient(path, kRadius, kUmbraColor, kPenumbraColor, false);
    if (expectSuccess != SkToBool(verts)) {
        ERRORF(reporter, "Expected shadow tessellation to % but it did not.",
               expectSuccess ? "succeed" : "fail");
    }
    verts = SkShadowVertices::MakeSpot(path, 1.5f, {0, 0}, kRadius, kUmbraColor, kPenumbraColor,
                                       false);
    if (expectSuccess != SkToBool(verts)) {
        ERRORF(reporter, "Expected shadow tessellation to % but it did not.",
               expectSuccess ? "succeed" : "fail");
    }
    verts = SkShadowVertices::MakeSpot(path, 1.5f, {0, 0}, kRadius, kUmbraColor, kPenumbraColor,
                                       true);
    if (expectSuccess != SkToBool(verts)) {
        ERRORF(reporter, "Expected shadow tessellation to % but it did not.",
               expectSuccess ? "succeed" : "fail");
    }
}

DEF_TEST(ShadowUtils, reporter) {
    SkCanvas canvas(100, 100);
    // Currently SkShadowUtils doesn't really stupport cubics when compiled without SK_SUPPORT_GPU.
    // However, this should now crash.
    SkPath path;
    path.cubicTo(100, 50, 20, 100, 0, 0);
    tessellate_shadow(reporter, path, (bool)SK_SUPPORT_GPU);

    // This line segment has no area and no shadow.
    path.reset();
    path.lineTo(10.f, 10.f);
    tessellate_shadow(reporter, path, false);

    // A series of colinear line segments
    path.reset();
    for (int i = 0; i < 10; ++i) {
        path.lineTo((SkScalar)i, (SkScalar)i);
    }
    tessellate_shadow(reporter, path, false);
}