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-02-03 15:33:25 +00:00
|
|
|
static constexpr SkScalar kRadius = 2.f;
|
|
|
|
static constexpr SkColor kUmbraColor = 0xFFFFFFFF;
|
|
|
|
static constexpr SkColor kPenumbraColor = 0x20202020;
|
2017-02-06 20:47:44 +00:00
|
|
|
auto verts =
|
|
|
|
SkShadowTessellator::MakeAmbient(path, ctm, kRadius, kUmbraColor, kPenumbraColor, 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-02-06 20:47:44 +00:00
|
|
|
verts = SkShadowTessellator::MakeAmbient(path, ctm, kRadius, kUmbraColor, kPenumbraColor,
|
|
|
|
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-02-06 20:47:44 +00:00
|
|
|
verts = SkShadowTessellator::MakeSpot(path, ctm, 1.5f, {0, 0}, kRadius, kUmbraColor,
|
|
|
|
kPenumbraColor, 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-02-06 20:47:44 +00:00
|
|
|
verts = SkShadowTessellator::MakeSpot(path, ctm, 1.5f, {0, 0}, kRadius, kUmbraColor,
|
|
|
|
kPenumbraColor, 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");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_TEST(ShadowUtils, reporter) {
|
|
|
|
SkCanvas canvas(100, 100);
|
2017-02-06 18:38:23 +00:00
|
|
|
// Currently SkShadowUtils doesn't really support cubics when compiled without SK_SUPPORT_GPU.
|
|
|
|
// However, this should now not crash.
|
2017-02-03 15:33:25 +00:00
|
|
|
SkPath path;
|
|
|
|
path.cubicTo(100, 50, 20, 100, 0, 0);
|
2017-02-06 18:38:23 +00:00
|
|
|
tessellate_shadow(reporter, path, canvas.getTotalMatrix(), (bool)SK_SUPPORT_GPU);
|
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
|
|
|
}
|