2017-02-03 15:33:25 +00:00
|
|
|
/*
|
|
|
|
* 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"
|
2017-02-06 20:47:44 +00:00
|
|
|
#include "SkVertices.h"
|
2017-02-03 15:33:25 +00:00
|
|
|
#include "Test.h"
|
|
|
|
|
2017-02-06 18:38:23 +00:00
|
|
|
void tessellate_shadow(skiatest::Reporter* reporter, const SkPath& path, const SkMatrix& ctm,
|
|
|
|
bool expectSuccess) {
|
2017-03-27 18:25:29 +00:00
|
|
|
static constexpr SkScalar kAmbientAlpha = 0.25f;
|
|
|
|
static constexpr SkScalar kSpotAlpha = 0.25f;
|
|
|
|
|
|
|
|
auto heightFunc = [] (SkScalar, SkScalar) { return 4; };
|
2017-04-13 16:20:21 +00:00
|
|
|
|
2017-03-27 18:25:29 +00:00
|
|
|
auto verts = SkShadowTessellator::MakeAmbient(path, ctm, heightFunc, kAmbientAlpha, true);
|
2017-02-03 15:33:25 +00:00
|
|
|
if (expectSuccess != SkToBool(verts)) {
|
2017-02-06 20:47:44 +00:00
|
|
|
ERRORF(reporter, "Expected shadow tessellation to %s but it did not.",
|
2017-02-03 15:33:25 +00:00
|
|
|
expectSuccess ? "succeed" : "fail");
|
|
|
|
}
|
2017-03-27 18:25:29 +00:00
|
|
|
verts = SkShadowTessellator::MakeAmbient(path, ctm, heightFunc, kAmbientAlpha, false);
|
2017-02-03 15:33:25 +00:00
|
|
|
if (expectSuccess != SkToBool(verts)) {
|
2017-02-06 20:47:44 +00:00
|
|
|
ERRORF(reporter, "Expected shadow tessellation to %s but it did not.",
|
2017-02-03 15:33:25 +00:00
|
|
|
expectSuccess ? "succeed" : "fail");
|
|
|
|
}
|
2017-03-27 18:25:29 +00:00
|
|
|
verts = SkShadowTessellator::MakeSpot(path, ctm, heightFunc, {0, 0, 128}, 128.f,
|
|
|
|
kSpotAlpha, false);
|
2017-02-03 15:33:25 +00:00
|
|
|
if (expectSuccess != SkToBool(verts)) {
|
2017-02-06 20:47:44 +00:00
|
|
|
ERRORF(reporter, "Expected shadow tessellation to %s but it did not.",
|
2017-02-03 15:33:25 +00:00
|
|
|
expectSuccess ? "succeed" : "fail");
|
|
|
|
}
|
2017-03-27 18:25:29 +00:00
|
|
|
verts = SkShadowTessellator::MakeSpot(path, ctm, heightFunc, {0, 0, 128}, 128.f,
|
|
|
|
kSpotAlpha, false);
|
2017-02-03 15:33:25 +00:00
|
|
|
if (expectSuccess != SkToBool(verts)) {
|
2017-02-06 20:47:44 +00:00
|
|
|
ERRORF(reporter, "Expected shadow tessellation to %s but it did not.",
|
2017-02-03 15:33:25 +00:00
|
|
|
expectSuccess ? "succeed" : "fail");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_TEST(ShadowUtils, reporter) {
|
|
|
|
SkCanvas canvas(100, 100);
|
2017-04-13 16:20:21 +00:00
|
|
|
|
2017-02-03 15:33:25 +00:00
|
|
|
SkPath path;
|
|
|
|
path.cubicTo(100, 50, 20, 100, 0, 0);
|
2017-04-13 16:20:21 +00:00
|
|
|
tessellate_shadow(reporter, path, canvas.getTotalMatrix(), true);
|
2017-02-03 15:33:25 +00:00
|
|
|
|
|
|
|
// This line segment has no area and no shadow.
|
|
|
|
path.reset();
|
|
|
|
path.lineTo(10.f, 10.f);
|
2017-02-06 18:38:23 +00:00
|
|
|
tessellate_shadow(reporter, path, canvas.getTotalMatrix(), false);
|
2017-02-03 15:33:25 +00:00
|
|
|
|
|
|
|
// A series of colinear line segments
|
|
|
|
path.reset();
|
|
|
|
for (int i = 0; i < 10; ++i) {
|
|
|
|
path.lineTo((SkScalar)i, (SkScalar)i);
|
|
|
|
}
|
2017-02-06 18:38:23 +00:00
|
|
|
tessellate_shadow(reporter, path, canvas.getTotalMatrix(), false);
|
2017-02-03 15:33:25 +00:00
|
|
|
}
|