2016-04-26 19:56:00 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2016 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <initializer_list>
|
|
|
|
#include <functional>
|
|
|
|
#include "Test.h"
|
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
#include "GrShape.h"
|
2016-05-13 16:23:38 +00:00
|
|
|
#include "SkCanvas.h"
|
2016-04-26 19:56:00 +00:00
|
|
|
#include "SkDashPathEffect.h"
|
2016-05-13 16:23:38 +00:00
|
|
|
#include "SkPath.h"
|
2016-06-06 21:01:25 +00:00
|
|
|
#include "SkPathOps.h"
|
2016-05-13 16:23:38 +00:00
|
|
|
#include "SkSurface.h"
|
2016-04-26 19:56:00 +00:00
|
|
|
|
2016-04-27 13:46:23 +00:00
|
|
|
using Key = SkTArray<uint32_t>;
|
|
|
|
|
|
|
|
static bool make_key(Key* key, const GrShape& shape) {
|
|
|
|
int size = shape.unstyledKeySize();
|
|
|
|
if (size <= 0) {
|
|
|
|
key->reset(0);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
SkASSERT(size);
|
|
|
|
key->reset(size);
|
|
|
|
shape.writeUnstyledKey(key->begin());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-06-06 21:01:25 +00:00
|
|
|
static bool paths_fill_same(const SkPath& a, const SkPath& b) {
|
|
|
|
SkPath pathXor;
|
|
|
|
Op(a, b, SkPathOp::kXOR_SkPathOp, &pathXor);
|
|
|
|
return pathXor.isEmpty();
|
|
|
|
}
|
|
|
|
|
2016-05-13 16:23:38 +00:00
|
|
|
static bool test_bounds_by_rasterizing(const SkPath& path, const SkRect& bounds) {
|
|
|
|
static constexpr int kRes = 2000;
|
|
|
|
// This tolerance is in units of 1/kRes fractions of the bounds width/height.
|
|
|
|
static constexpr int kTol = 0;
|
|
|
|
GR_STATIC_ASSERT(kRes % 4 == 0);
|
|
|
|
SkImageInfo info = SkImageInfo::MakeA8(kRes, kRes);
|
|
|
|
sk_sp<SkSurface> surface = SkSurface::MakeRaster(info);
|
|
|
|
surface->getCanvas()->clear(0x0);
|
|
|
|
SkRect clip = SkRect::MakeXYWH(kRes/4, kRes/4, kRes/2, kRes/2);
|
|
|
|
SkMatrix matrix;
|
|
|
|
matrix.setRectToRect(bounds, clip, SkMatrix::kFill_ScaleToFit);
|
|
|
|
clip.outset(SkIntToScalar(kTol), SkIntToScalar(kTol));
|
|
|
|
surface->getCanvas()->clipRect(clip, SkRegion::kDifference_Op);
|
|
|
|
surface->getCanvas()->concat(matrix);
|
|
|
|
SkPaint whitePaint;
|
|
|
|
whitePaint.setColor(SK_ColorWHITE);
|
|
|
|
surface->getCanvas()->drawPath(path, whitePaint);
|
|
|
|
SkPixmap pixmap;
|
|
|
|
surface->getCanvas()->peekPixels(&pixmap);
|
|
|
|
#if defined(SK_BUILD_FOR_WIN)
|
|
|
|
// The static constexpr version in #else causes cl.exe to crash.
|
|
|
|
const uint8_t* kZeros = reinterpret_cast<uint8_t*>(calloc(kRes, 1));
|
|
|
|
#else
|
|
|
|
static constexpr uint8_t kZeros[kRes] = {0};
|
|
|
|
#endif
|
|
|
|
for (int y = 0; y < kRes/4; ++y) {
|
|
|
|
const uint8_t* row = pixmap.addr8(0, y);
|
|
|
|
if (0 != memcmp(kZeros, row, kRes)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#ifdef SK_BUILD_FOR_WIN
|
|
|
|
free(const_cast<uint8_t*>(kZeros));
|
|
|
|
#endif
|
|
|
|
return true;
|
|
|
|
}
|
2016-04-27 13:46:23 +00:00
|
|
|
|
2016-05-13 16:23:38 +00:00
|
|
|
namespace {
|
2016-04-26 19:56:00 +00:00
|
|
|
class TestCase {
|
|
|
|
public:
|
2016-04-27 13:46:23 +00:00
|
|
|
template <typename GEO>
|
2016-05-09 20:02:01 +00:00
|
|
|
TestCase(const GEO& geo, const SkPaint& paint, skiatest::Reporter* r,
|
|
|
|
SkScalar scale = SK_Scalar1) : fBase(geo, paint) {
|
|
|
|
this->init(r, scale);
|
2016-04-26 19:56:00 +00:00
|
|
|
}
|
|
|
|
|
2016-06-10 15:05:14 +00:00
|
|
|
TestCase(const GrShape& shape, skiatest::Reporter* r, SkScalar scale = SK_Scalar1)
|
|
|
|
: fBase(shape) {
|
|
|
|
this->init(r, scale);
|
|
|
|
}
|
|
|
|
|
2016-04-26 19:56:00 +00:00
|
|
|
struct SelfExpectations {
|
|
|
|
bool fPEHasEffect;
|
|
|
|
bool fPEHasValidKey;
|
|
|
|
bool fStrokeApplies;
|
|
|
|
};
|
|
|
|
|
|
|
|
void testExpectations(skiatest::Reporter* reporter, SelfExpectations expectations) const;
|
|
|
|
|
|
|
|
enum ComparisonExpecation {
|
|
|
|
kAllDifferent_ComparisonExpecation,
|
|
|
|
kSameUpToPE_ComparisonExpecation,
|
|
|
|
kSameUpToStroke_ComparisonExpecation,
|
|
|
|
kAllSame_ComparisonExpecation,
|
|
|
|
};
|
|
|
|
|
|
|
|
void compare(skiatest::Reporter*, const TestCase& that, ComparisonExpecation) const;
|
|
|
|
|
2016-04-27 13:46:23 +00:00
|
|
|
const GrShape& baseShape() const { return fBase; }
|
|
|
|
const GrShape& appliedPathEffectShape() const { return fAppliedPE; }
|
|
|
|
const GrShape& appliedFullStyleShape() const { return fAppliedFull; }
|
|
|
|
|
|
|
|
// The returned array's count will be 0 if the key shape has no key.
|
|
|
|
const Key& baseKey() const { return fBaseKey; }
|
|
|
|
const Key& appliedPathEffectKey() const { return fAppliedPEKey; }
|
|
|
|
const Key& appliedFullStyleKey() const { return fAppliedFullKey; }
|
2016-04-27 19:36:02 +00:00
|
|
|
const Key& appliedPathEffectThenStrokeKey() const { return fAppliedPEThenStrokeKey; }
|
2016-04-27 13:46:23 +00:00
|
|
|
|
2016-04-26 19:56:00 +00:00
|
|
|
private:
|
2016-05-13 16:23:38 +00:00
|
|
|
static void CheckBounds(skiatest::Reporter* r, const GrShape& shape, const SkRect& bounds) {
|
|
|
|
SkPath path;
|
|
|
|
shape.asPath(&path);
|
|
|
|
// If the bounds are empty, the path ought to be as well.
|
|
|
|
if (bounds.isEmpty()) {
|
|
|
|
REPORTER_ASSERT(r, path.isEmpty());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (path.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
2016-06-10 15:05:14 +00:00
|
|
|
// The bounds API explicitly calls out that it does not consider inverseness.
|
|
|
|
SkPath p = path;
|
|
|
|
p.setFillType(SkPath::ConvertToNonInverseFillType(path.getFillType()));
|
|
|
|
REPORTER_ASSERT(r, test_bounds_by_rasterizing(p, bounds));
|
2016-05-13 16:23:38 +00:00
|
|
|
}
|
|
|
|
|
2016-05-09 20:02:01 +00:00
|
|
|
void init(skiatest::Reporter* r, SkScalar scale) {
|
|
|
|
fAppliedPE = fBase.applyStyle(GrStyle::Apply::kPathEffectOnly, scale);
|
|
|
|
fAppliedPEThenStroke = fAppliedPE.applyStyle(GrStyle::Apply::kPathEffectAndStrokeRec,
|
|
|
|
scale);
|
|
|
|
fAppliedFull = fBase.applyStyle(GrStyle::Apply::kPathEffectAndStrokeRec, scale);
|
2016-04-26 19:56:00 +00:00
|
|
|
|
2016-04-27 13:46:23 +00:00
|
|
|
make_key(&fBaseKey, fBase);
|
|
|
|
make_key(&fAppliedPEKey, fAppliedPE);
|
|
|
|
make_key(&fAppliedPEThenStrokeKey, fAppliedPEThenStroke);
|
|
|
|
make_key(&fAppliedFullKey, fAppliedFull);
|
2016-05-04 15:27:41 +00:00
|
|
|
|
|
|
|
// Applying the path effect and then the stroke should always be the same as applying
|
|
|
|
// both in one go.
|
|
|
|
REPORTER_ASSERT(r, fAppliedPEThenStrokeKey == fAppliedFullKey);
|
|
|
|
SkPath a, b;
|
|
|
|
fAppliedPEThenStroke.asPath(&a);
|
|
|
|
fAppliedFull.asPath(&b);
|
2016-06-06 21:01:25 +00:00
|
|
|
// If the output of the path effect is a rrect then it is possible for a and b to be
|
|
|
|
// different paths that fill identically. The reason is that fAppliedFull will do this:
|
|
|
|
// base -> apply path effect -> rrect_as_path -> stroke -> stroked_rrect_as_path
|
|
|
|
// fAppliedPEThenStroke will have converted the rrect_as_path back to a rrect. However,
|
|
|
|
// now that there is no longer a path effect, the direction and starting index get
|
|
|
|
// canonicalized before the stroke.
|
2016-06-10 15:05:14 +00:00
|
|
|
if (fAppliedPE.asRRect(nullptr, nullptr, nullptr, nullptr)) {
|
2016-06-06 21:01:25 +00:00
|
|
|
REPORTER_ASSERT(r, paths_fill_same(a, b));
|
|
|
|
} else {
|
|
|
|
REPORTER_ASSERT(r, a == b);
|
|
|
|
}
|
2016-05-11 22:15:56 +00:00
|
|
|
REPORTER_ASSERT(r, fAppliedFull.isEmpty() == fAppliedPEThenStroke.isEmpty());
|
|
|
|
|
|
|
|
SkPath path;
|
|
|
|
fBase.asPath(&path);
|
|
|
|
REPORTER_ASSERT(r, path.isEmpty() == fBase.isEmpty());
|
2016-06-07 13:28:51 +00:00
|
|
|
REPORTER_ASSERT(r, path.getSegmentMasks() == fBase.segmentMask());
|
2016-05-11 22:15:56 +00:00
|
|
|
fAppliedPE.asPath(&path);
|
|
|
|
REPORTER_ASSERT(r, path.isEmpty() == fAppliedPE.isEmpty());
|
2016-06-07 13:28:51 +00:00
|
|
|
REPORTER_ASSERT(r, path.getSegmentMasks() == fAppliedPE.segmentMask());
|
2016-05-11 22:15:56 +00:00
|
|
|
fAppliedFull.asPath(&path);
|
|
|
|
REPORTER_ASSERT(r, path.isEmpty() == fAppliedFull.isEmpty());
|
2016-06-07 13:28:51 +00:00
|
|
|
REPORTER_ASSERT(r, path.getSegmentMasks() == fAppliedFull.segmentMask());
|
2016-05-04 15:27:41 +00:00
|
|
|
|
2016-05-13 16:23:38 +00:00
|
|
|
CheckBounds(r, fBase, fBase.bounds());
|
|
|
|
CheckBounds(r, fAppliedPE, fAppliedPE.bounds());
|
|
|
|
CheckBounds(r, fAppliedPEThenStroke, fAppliedPEThenStroke.bounds());
|
|
|
|
CheckBounds(r, fAppliedFull, fAppliedFull.bounds());
|
|
|
|
SkRect styledBounds;
|
|
|
|
fBase.styledBounds(&styledBounds);
|
|
|
|
CheckBounds(r, fAppliedFull, styledBounds);
|
|
|
|
fAppliedPE.styledBounds(&styledBounds);
|
|
|
|
CheckBounds(r, fAppliedFull, styledBounds);
|
|
|
|
|
2016-05-04 15:27:41 +00:00
|
|
|
// Check that the same path is produced when style is applied by GrShape and GrStyle.
|
|
|
|
SkPath preStyle;
|
|
|
|
SkPath postPathEffect;
|
|
|
|
SkPath postAllStyle;
|
|
|
|
|
|
|
|
fBase.asPath(&preStyle);
|
2016-05-06 18:07:03 +00:00
|
|
|
SkStrokeRec postPEStrokeRec(SkStrokeRec::kFill_InitStyle);
|
2016-05-09 20:02:01 +00:00
|
|
|
if (fBase.style().applyPathEffectToPath(&postPathEffect, &postPEStrokeRec, preStyle,
|
|
|
|
scale)) {
|
2016-05-06 18:07:03 +00:00
|
|
|
// run postPathEffect through GrShape to get any geometry reductions that would have
|
|
|
|
// occurred to fAppliedPE.
|
|
|
|
GrShape(postPathEffect, GrStyle(postPEStrokeRec, nullptr)).asPath(&postPathEffect);
|
|
|
|
|
2016-05-04 15:27:41 +00:00
|
|
|
SkPath testPath;
|
|
|
|
fAppliedPE.asPath(&testPath);
|
|
|
|
REPORTER_ASSERT(r, testPath == postPathEffect);
|
2016-05-06 18:07:03 +00:00
|
|
|
REPORTER_ASSERT(r, postPEStrokeRec.hasEqualEffect(fAppliedPE.style().strokeRec()));
|
2016-05-04 15:27:41 +00:00
|
|
|
}
|
|
|
|
SkStrokeRec::InitStyle fillOrHairline;
|
2016-05-09 20:02:01 +00:00
|
|
|
if (fBase.style().applyToPath(&postAllStyle, &fillOrHairline, preStyle, scale)) {
|
2016-05-04 15:27:41 +00:00
|
|
|
SkPath testPath;
|
|
|
|
fAppliedFull.asPath(&testPath);
|
2016-06-20 19:28:17 +00:00
|
|
|
if (fBase.style().hasPathEffect()) {
|
|
|
|
// Because GrShape always does two-stage application when there is a path effect
|
|
|
|
// there may be a reduction/canonicalization step between the path effect and
|
|
|
|
// strokerec not reflected in postAllStyle since it applied both the path effect
|
|
|
|
// and strokerec without analyzing the intermediate path.
|
|
|
|
REPORTER_ASSERT(r, paths_fill_same(postAllStyle, testPath));
|
|
|
|
} else {
|
|
|
|
// Make sure that postAllStyle sees any reductions/canonicalizations that GrShape
|
|
|
|
// would apply.
|
|
|
|
GrShape(postAllStyle, GrStyle(fillOrHairline)).asPath(&postAllStyle);
|
|
|
|
REPORTER_ASSERT(r, testPath == postAllStyle);
|
|
|
|
}
|
|
|
|
|
2016-05-04 15:27:41 +00:00
|
|
|
if (fillOrHairline == SkStrokeRec::kFill_InitStyle) {
|
|
|
|
REPORTER_ASSERT(r, fAppliedFull.style().isSimpleFill());
|
|
|
|
} else {
|
|
|
|
REPORTER_ASSERT(r, fAppliedFull.style().isSimpleHairline());
|
|
|
|
}
|
|
|
|
}
|
2016-04-26 19:56:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GrShape fBase;
|
|
|
|
GrShape fAppliedPE;
|
|
|
|
GrShape fAppliedPEThenStroke;
|
|
|
|
GrShape fAppliedFull;
|
|
|
|
|
|
|
|
Key fBaseKey;
|
|
|
|
Key fAppliedPEKey;
|
|
|
|
Key fAppliedPEThenStrokeKey;
|
|
|
|
Key fAppliedFullKey;
|
|
|
|
};
|
|
|
|
|
|
|
|
void TestCase::testExpectations(skiatest::Reporter* reporter, SelfExpectations expectations) const {
|
|
|
|
// The base's key should always be valid (unless the path is volatile)
|
2016-04-27 13:46:23 +00:00
|
|
|
REPORTER_ASSERT(reporter, fBaseKey.count());
|
2016-04-26 19:56:00 +00:00
|
|
|
if (expectations.fPEHasEffect) {
|
|
|
|
REPORTER_ASSERT(reporter, fBaseKey != fAppliedPEKey);
|
2016-04-27 13:46:23 +00:00
|
|
|
REPORTER_ASSERT(reporter, expectations.fPEHasValidKey == SkToBool(fAppliedPEKey.count()));
|
2016-04-26 19:56:00 +00:00
|
|
|
REPORTER_ASSERT(reporter, fBaseKey != fAppliedFullKey);
|
2016-04-27 13:46:23 +00:00
|
|
|
REPORTER_ASSERT(reporter, expectations.fPEHasValidKey == SkToBool(fAppliedFullKey.count()));
|
2016-04-26 19:56:00 +00:00
|
|
|
if (expectations.fStrokeApplies && expectations.fPEHasValidKey) {
|
|
|
|
REPORTER_ASSERT(reporter, fAppliedPEKey != fAppliedFullKey);
|
2016-04-27 13:46:23 +00:00
|
|
|
REPORTER_ASSERT(reporter, SkToBool(fAppliedFullKey.count()));
|
2016-04-26 19:56:00 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
REPORTER_ASSERT(reporter, fBaseKey == fAppliedPEKey);
|
2016-05-04 15:27:41 +00:00
|
|
|
SkPath a, b;
|
2016-04-27 13:46:23 +00:00
|
|
|
fBase.asPath(&a);
|
|
|
|
fAppliedPE.asPath(&b);
|
|
|
|
REPORTER_ASSERT(reporter, a == b);
|
2016-04-26 19:56:00 +00:00
|
|
|
if (expectations.fStrokeApplies) {
|
|
|
|
REPORTER_ASSERT(reporter, fBaseKey != fAppliedFullKey);
|
|
|
|
} else {
|
|
|
|
REPORTER_ASSERT(reporter, fBaseKey == fAppliedFullKey);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-06 21:01:25 +00:00
|
|
|
void check_equivalence(skiatest::Reporter* r, const GrShape& a, const GrShape& b,
|
|
|
|
const Key& keyA, const Key& keyB) {
|
|
|
|
// GrShape only respects the input winding direction and start point for rrect shapes
|
|
|
|
// when there is a path effect. Thus, if there are two GrShapes representing the same rrect
|
|
|
|
// but one has a path effect in its style and the other doesn't then asPath() and the unstyled
|
|
|
|
// key will differ. GrShape will have canonicalized the direction and start point for the shape
|
|
|
|
// without the path effect. If *both* have path effects then they should have both preserved
|
|
|
|
// the direction and starting point.
|
|
|
|
|
|
|
|
// The asRRect() output params are all initialized just to silence compiler warnings about
|
|
|
|
// uninitialized variables.
|
|
|
|
SkRRect rrectA = SkRRect::MakeEmpty(), rrectB = SkRRect::MakeEmpty();
|
|
|
|
SkPath::Direction dirA = SkPath::kCW_Direction, dirB = SkPath::kCW_Direction;
|
|
|
|
unsigned startA = ~0U, startB = ~0U;
|
2016-06-10 15:05:14 +00:00
|
|
|
bool invertedA = true, invertedB = true;
|
2016-06-06 21:01:25 +00:00
|
|
|
|
2016-06-10 15:05:14 +00:00
|
|
|
bool aIsRRect = a.asRRect(&rrectA, &dirA, &startA, &invertedA);
|
|
|
|
bool bIsRRect = b.asRRect(&rrectB, &dirB, &startB, &invertedB);
|
2016-06-06 21:01:25 +00:00
|
|
|
bool aHasPE = a.style().hasPathEffect();
|
|
|
|
bool bHasPE = b.style().hasPathEffect();
|
|
|
|
bool allowSameRRectButDiffStartAndDir = (aIsRRect && bIsRRect) && (aHasPE != bHasPE);
|
2016-06-10 15:05:14 +00:00
|
|
|
|
2016-06-06 21:01:25 +00:00
|
|
|
SkPath pathA, pathB;
|
|
|
|
a.asPath(&pathA);
|
|
|
|
b.asPath(&pathB);
|
2016-06-10 15:05:14 +00:00
|
|
|
|
2016-06-14 21:37:21 +00:00
|
|
|
// Having a dash path effect can allow 'a' but not 'b' to turn a inverse fill type into a
|
|
|
|
// non-inverse fill type (or vice versa).
|
2016-06-10 15:05:14 +00:00
|
|
|
bool ignoreInversenessDifference = false;
|
|
|
|
if (pathA.isInverseFillType() != pathB.isInverseFillType()) {
|
|
|
|
const GrShape* s1 = pathA.isInverseFillType() ? &a : &b;
|
|
|
|
const GrShape* s2 = pathA.isInverseFillType() ? &b : &a;
|
2016-06-14 21:37:21 +00:00
|
|
|
bool canDropInverse1 = s1->style().isDashed();
|
|
|
|
bool canDropInverse2 = s2->style().isDashed();
|
|
|
|
ignoreInversenessDifference = (canDropInverse1 != canDropInverse2);
|
2016-06-10 15:05:14 +00:00
|
|
|
}
|
|
|
|
|
2016-06-06 21:01:25 +00:00
|
|
|
if (allowSameRRectButDiffStartAndDir) {
|
|
|
|
REPORTER_ASSERT(r, rrectA == rrectB);
|
|
|
|
REPORTER_ASSERT(r, paths_fill_same(pathA, pathB));
|
2016-06-10 15:05:14 +00:00
|
|
|
REPORTER_ASSERT(r, ignoreInversenessDifference || invertedA == invertedB);
|
2016-06-06 21:01:25 +00:00
|
|
|
} else {
|
2016-06-10 15:05:14 +00:00
|
|
|
SkPath pA = pathA;
|
|
|
|
SkPath pB = pathB;
|
|
|
|
if (ignoreInversenessDifference) {
|
|
|
|
pA.setFillType(SkPath::ConvertToNonInverseFillType(pathA.getFillType()));
|
|
|
|
pB.setFillType(SkPath::ConvertToNonInverseFillType(pathB.getFillType()));
|
|
|
|
REPORTER_ASSERT(r, keyA != keyB);
|
|
|
|
} else {
|
|
|
|
REPORTER_ASSERT(r, keyA == keyB);
|
|
|
|
}
|
|
|
|
REPORTER_ASSERT(r, pA == pB);
|
2016-06-06 21:01:25 +00:00
|
|
|
REPORTER_ASSERT(r, aIsRRect == bIsRRect);
|
|
|
|
if (aIsRRect) {
|
|
|
|
REPORTER_ASSERT(r, rrectA == rrectB);
|
|
|
|
REPORTER_ASSERT(r, dirA == dirB);
|
|
|
|
REPORTER_ASSERT(r, startA == startB);
|
2016-06-10 15:05:14 +00:00
|
|
|
REPORTER_ASSERT(r, ignoreInversenessDifference || invertedA == invertedB);
|
2016-06-06 21:01:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
REPORTER_ASSERT(r, a.isEmpty() == b.isEmpty());
|
|
|
|
REPORTER_ASSERT(r, a.knownToBeClosed() == b.knownToBeClosed());
|
|
|
|
REPORTER_ASSERT(r, a.bounds() == b.bounds());
|
2016-06-07 13:28:51 +00:00
|
|
|
REPORTER_ASSERT(r, a.segmentMask() == b.segmentMask());
|
2016-06-13 17:22:48 +00:00
|
|
|
SkPoint pts[4];
|
|
|
|
REPORTER_ASSERT(r, a.asLine(pts) == b.asLine(pts + 2));
|
|
|
|
if (a.asLine(pts)) {
|
|
|
|
REPORTER_ASSERT(r, pts[2] == pts[0] && pts[3] == pts[1]);
|
|
|
|
}
|
2016-06-06 21:01:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestCase::compare(skiatest::Reporter* r, const TestCase& that,
|
2016-04-26 19:56:00 +00:00
|
|
|
ComparisonExpecation expectation) const {
|
2016-04-27 13:46:23 +00:00
|
|
|
SkPath a, b;
|
2016-04-26 19:56:00 +00:00
|
|
|
switch (expectation) {
|
|
|
|
case kAllDifferent_ComparisonExpecation:
|
2016-06-06 21:01:25 +00:00
|
|
|
REPORTER_ASSERT(r, fBaseKey != that.fBaseKey);
|
|
|
|
REPORTER_ASSERT(r, fAppliedPEKey != that.fAppliedPEKey);
|
|
|
|
REPORTER_ASSERT(r, fAppliedFullKey != that.fAppliedFullKey);
|
2016-04-26 19:56:00 +00:00
|
|
|
break;
|
|
|
|
case kSameUpToPE_ComparisonExpecation:
|
2016-06-06 21:01:25 +00:00
|
|
|
check_equivalence(r, fBase, that.fBase, fBaseKey, that.fBaseKey);
|
|
|
|
REPORTER_ASSERT(r, fAppliedPEKey != that.fAppliedPEKey);
|
|
|
|
REPORTER_ASSERT(r, fAppliedFullKey != that.fAppliedFullKey);
|
2016-04-26 19:56:00 +00:00
|
|
|
break;
|
|
|
|
case kSameUpToStroke_ComparisonExpecation:
|
2016-06-06 21:01:25 +00:00
|
|
|
check_equivalence(r, fBase, that.fBase, fBaseKey, that.fBaseKey);
|
|
|
|
check_equivalence(r, fAppliedPE, that.fAppliedPE, fAppliedPEKey, that.fAppliedPEKey);
|
|
|
|
REPORTER_ASSERT(r, fAppliedFullKey != that.fAppliedFullKey);
|
2016-04-26 19:56:00 +00:00
|
|
|
break;
|
|
|
|
case kAllSame_ComparisonExpecation:
|
2016-06-06 21:01:25 +00:00
|
|
|
check_equivalence(r, fBase, that.fBase, fBaseKey, that.fBaseKey);
|
|
|
|
check_equivalence(r, fAppliedPE, that.fAppliedPE, fAppliedPEKey, that.fAppliedPEKey);
|
|
|
|
check_equivalence(r, fAppliedFull, that.fAppliedFull, fAppliedFullKey,
|
|
|
|
that.fAppliedFullKey);
|
2016-04-26 19:56:00 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
static sk_sp<SkPathEffect> make_dash() {
|
|
|
|
static const SkScalar kIntervals[] = { 0.25, 3.f, 0.5, 2.f };
|
|
|
|
static const SkScalar kPhase = 0.75;
|
|
|
|
return SkDashPathEffect::Make(kIntervals, SK_ARRAY_COUNT(kIntervals), kPhase);
|
|
|
|
}
|
|
|
|
|
|
|
|
static sk_sp<SkPathEffect> make_null_dash() {
|
|
|
|
static const SkScalar kNullIntervals[] = {0, 0, 0, 0, 0, 0};
|
|
|
|
return SkDashPathEffect::Make(kNullIntervals, SK_ARRAY_COUNT(kNullIntervals), 0.f);
|
|
|
|
}
|
|
|
|
|
2016-04-27 13:46:23 +00:00
|
|
|
template<typename GEO>
|
|
|
|
static void test_basic(skiatest::Reporter* reporter, const GEO& geo) {
|
2016-04-26 19:56:00 +00:00
|
|
|
sk_sp<SkPathEffect> dashPE = make_dash();
|
|
|
|
|
|
|
|
TestCase::SelfExpectations expectations;
|
|
|
|
SkPaint fill;
|
|
|
|
|
2016-05-04 15:27:41 +00:00
|
|
|
TestCase fillCase(geo, fill, reporter);
|
2016-04-26 19:56:00 +00:00
|
|
|
expectations.fPEHasEffect = false;
|
|
|
|
expectations.fPEHasValidKey = false;
|
|
|
|
expectations.fStrokeApplies = false;
|
|
|
|
fillCase.testExpectations(reporter, expectations);
|
|
|
|
// Test that another GrShape instance built from the same primitive is the same.
|
2016-05-04 15:27:41 +00:00
|
|
|
TestCase(geo, fill, reporter).compare(reporter, fillCase,
|
|
|
|
TestCase::kAllSame_ComparisonExpecation);
|
2016-04-26 19:56:00 +00:00
|
|
|
|
|
|
|
SkPaint stroke2RoundBevel;
|
|
|
|
stroke2RoundBevel.setStyle(SkPaint::kStroke_Style);
|
|
|
|
stroke2RoundBevel.setStrokeCap(SkPaint::kRound_Cap);
|
|
|
|
stroke2RoundBevel.setStrokeJoin(SkPaint::kBevel_Join);
|
|
|
|
stroke2RoundBevel.setStrokeWidth(2.f);
|
2016-05-04 15:27:41 +00:00
|
|
|
TestCase stroke2RoundBevelCase(geo, stroke2RoundBevel, reporter);
|
2016-04-26 19:56:00 +00:00
|
|
|
expectations.fPEHasValidKey = true;
|
|
|
|
expectations.fPEHasEffect = false;
|
|
|
|
expectations.fStrokeApplies = true;
|
|
|
|
stroke2RoundBevelCase.testExpectations(reporter, expectations);
|
2016-05-04 15:27:41 +00:00
|
|
|
TestCase(geo, stroke2RoundBevel, reporter).compare(reporter, stroke2RoundBevelCase,
|
|
|
|
TestCase::kAllSame_ComparisonExpecation);
|
2016-04-26 19:56:00 +00:00
|
|
|
|
|
|
|
SkPaint stroke2RoundBevelDash = stroke2RoundBevel;
|
|
|
|
stroke2RoundBevelDash.setPathEffect(make_dash());
|
2016-05-04 15:27:41 +00:00
|
|
|
TestCase stroke2RoundBevelDashCase(geo, stroke2RoundBevelDash, reporter);
|
2016-04-26 19:56:00 +00:00
|
|
|
expectations.fPEHasValidKey = true;
|
|
|
|
expectations.fPEHasEffect = true;
|
|
|
|
expectations.fStrokeApplies = true;
|
|
|
|
stroke2RoundBevelDashCase.testExpectations(reporter, expectations);
|
2016-05-04 15:27:41 +00:00
|
|
|
TestCase(geo, stroke2RoundBevelDash, reporter).compare(reporter, stroke2RoundBevelDashCase,
|
|
|
|
TestCase::kAllSame_ComparisonExpecation);
|
2016-04-26 19:56:00 +00:00
|
|
|
|
|
|
|
fillCase.compare(reporter, stroke2RoundBevelCase,
|
|
|
|
TestCase::kSameUpToStroke_ComparisonExpecation);
|
|
|
|
fillCase.compare(reporter, stroke2RoundBevelDashCase,
|
|
|
|
TestCase::kSameUpToPE_ComparisonExpecation);
|
|
|
|
stroke2RoundBevelCase.compare(reporter, stroke2RoundBevelDashCase,
|
|
|
|
TestCase::kSameUpToPE_ComparisonExpecation);
|
2016-04-27 13:46:23 +00:00
|
|
|
|
2016-05-05 15:28:30 +00:00
|
|
|
// Stroke and fill cases
|
|
|
|
SkPaint stroke2RoundBevelAndFill = stroke2RoundBevel;
|
|
|
|
stroke2RoundBevelAndFill.setStyle(SkPaint::kStrokeAndFill_Style);
|
|
|
|
TestCase stroke2RoundBevelAndFillCase(geo, stroke2RoundBevelAndFill, reporter);
|
|
|
|
expectations.fPEHasValidKey = true;
|
|
|
|
expectations.fPEHasEffect = false;
|
|
|
|
expectations.fStrokeApplies = true;
|
|
|
|
stroke2RoundBevelAndFillCase.testExpectations(reporter, expectations);
|
|
|
|
TestCase(geo, stroke2RoundBevelAndFill, reporter).compare(reporter,
|
|
|
|
stroke2RoundBevelAndFillCase, TestCase::kAllSame_ComparisonExpecation);
|
|
|
|
|
|
|
|
SkPaint stroke2RoundBevelAndFillDash = stroke2RoundBevelDash;
|
|
|
|
stroke2RoundBevelAndFillDash.setStyle(SkPaint::kStrokeAndFill_Style);
|
|
|
|
TestCase stroke2RoundBevelAndFillDashCase(geo, stroke2RoundBevelAndFillDash, reporter);
|
|
|
|
expectations.fPEHasValidKey = true;
|
2016-06-09 13:03:38 +00:00
|
|
|
expectations.fPEHasEffect = false;
|
2016-05-05 15:28:30 +00:00
|
|
|
expectations.fStrokeApplies = true;
|
|
|
|
stroke2RoundBevelAndFillDashCase.testExpectations(reporter, expectations);
|
|
|
|
TestCase(geo, stroke2RoundBevelAndFillDash, reporter).compare(
|
|
|
|
reporter, stroke2RoundBevelAndFillDashCase, TestCase::kAllSame_ComparisonExpecation);
|
2016-06-09 13:03:38 +00:00
|
|
|
stroke2RoundBevelAndFillDashCase.compare(reporter, stroke2RoundBevelAndFillCase,
|
|
|
|
TestCase::kAllSame_ComparisonExpecation);
|
2016-05-05 15:28:30 +00:00
|
|
|
|
2016-04-27 13:46:23 +00:00
|
|
|
SkPaint hairline;
|
|
|
|
hairline.setStyle(SkPaint::kStroke_Style);
|
|
|
|
hairline.setStrokeWidth(0.f);
|
2016-05-04 15:27:41 +00:00
|
|
|
TestCase hairlineCase(geo, hairline, reporter);
|
2016-04-27 13:46:23 +00:00
|
|
|
// Since hairline style doesn't change the SkPath data, it is keyed identically to fill.
|
|
|
|
hairlineCase.compare(reporter, fillCase, TestCase::kAllSame_ComparisonExpecation);
|
2016-05-04 15:44:15 +00:00
|
|
|
REPORTER_ASSERT(reporter, hairlineCase.baseShape().style().isSimpleHairline());
|
|
|
|
REPORTER_ASSERT(reporter, hairlineCase.appliedFullStyleShape().style().isSimpleHairline());
|
|
|
|
REPORTER_ASSERT(reporter, hairlineCase.appliedPathEffectShape().style().isSimpleHairline());
|
2016-04-26 19:56:00 +00:00
|
|
|
}
|
|
|
|
|
2016-05-09 20:02:01 +00:00
|
|
|
template<typename GEO>
|
|
|
|
static void test_scale(skiatest::Reporter* reporter, const GEO& geo) {
|
|
|
|
sk_sp<SkPathEffect> dashPE = make_dash();
|
|
|
|
|
|
|
|
static const SkScalar kS1 = 1.f;
|
|
|
|
static const SkScalar kS2 = 2.f;
|
|
|
|
|
|
|
|
SkPaint fill;
|
|
|
|
TestCase fillCase1(geo, fill, reporter, kS1);
|
|
|
|
TestCase fillCase2(geo, fill, reporter, kS2);
|
|
|
|
// Scale doesn't affect fills.
|
|
|
|
fillCase1.compare(reporter, fillCase2, TestCase::kAllSame_ComparisonExpecation);
|
|
|
|
|
|
|
|
SkPaint hairline;
|
|
|
|
hairline.setStyle(SkPaint::kStroke_Style);
|
|
|
|
hairline.setStrokeWidth(0.f);
|
|
|
|
TestCase hairlineCase1(geo, hairline, reporter, kS1);
|
|
|
|
TestCase hairlineCase2(geo, hairline, reporter, kS2);
|
|
|
|
// Scale doesn't affect hairlines.
|
|
|
|
hairlineCase1.compare(reporter, hairlineCase2, TestCase::kAllSame_ComparisonExpecation);
|
|
|
|
|
|
|
|
SkPaint stroke;
|
|
|
|
stroke.setStyle(SkPaint::kStroke_Style);
|
|
|
|
stroke.setStrokeWidth(2.f);
|
|
|
|
TestCase strokeCase1(geo, stroke, reporter, kS1);
|
|
|
|
TestCase strokeCase2(geo, stroke, reporter, kS2);
|
|
|
|
// Scale affects the stroke.
|
|
|
|
strokeCase1.compare(reporter, strokeCase2, TestCase::kSameUpToStroke_ComparisonExpecation);
|
|
|
|
|
|
|
|
SkPaint strokeDash = stroke;
|
|
|
|
strokeDash.setPathEffect(make_dash());
|
|
|
|
TestCase strokeDashCase1(geo, strokeDash, reporter, kS1);
|
|
|
|
TestCase strokeDashCase2(geo, strokeDash, reporter, kS2);
|
|
|
|
// Scale affects the dash and the stroke.
|
|
|
|
strokeDashCase1.compare(reporter, strokeDashCase2, TestCase::kSameUpToPE_ComparisonExpecation);
|
|
|
|
|
|
|
|
// Stroke and fill cases
|
|
|
|
SkPaint strokeAndFill = stroke;
|
|
|
|
strokeAndFill.setStyle(SkPaint::kStrokeAndFill_Style);
|
|
|
|
TestCase strokeAndFillCase1(geo, strokeAndFill, reporter, kS1);
|
|
|
|
TestCase strokeAndFillCase2(geo, strokeAndFill, reporter, kS2);
|
2016-06-09 13:03:38 +00:00
|
|
|
SkPaint strokeAndFillDash = strokeDash;
|
|
|
|
strokeAndFillDash.setStyle(SkPaint::kStrokeAndFill_Style);
|
|
|
|
// Dash is ignored for stroke and fill
|
|
|
|
TestCase strokeAndFillDashCase1(geo, strokeAndFillDash, reporter, kS1);
|
|
|
|
TestCase strokeAndFillDashCase2(geo, strokeAndFillDash, reporter, kS2);
|
2016-05-09 20:02:01 +00:00
|
|
|
// Scale affects the stroke. Though, this can wind up creating a rect when the input is a rect.
|
|
|
|
// In that case we wind up with a pure geometry key and the geometries are the same.
|
|
|
|
SkRRect rrect;
|
2016-06-10 15:05:14 +00:00
|
|
|
if (strokeAndFillCase1.appliedFullStyleShape().asRRect(&rrect, nullptr, nullptr, nullptr)) {
|
2016-05-09 20:02:01 +00:00
|
|
|
// We currently only expect to get here in the rect->rect case.
|
|
|
|
REPORTER_ASSERT(reporter, rrect.isRect());
|
2016-06-06 21:01:25 +00:00
|
|
|
REPORTER_ASSERT(reporter,
|
2016-06-10 15:05:14 +00:00
|
|
|
strokeAndFillCase1.baseShape().asRRect(&rrect, nullptr, nullptr, nullptr) &&
|
2016-06-06 21:01:25 +00:00
|
|
|
rrect.isRect());
|
2016-05-09 20:02:01 +00:00
|
|
|
strokeAndFillCase1.compare(reporter, strokeAndFillCase2,
|
|
|
|
TestCase::kAllSame_ComparisonExpecation);
|
|
|
|
} else {
|
|
|
|
strokeAndFillCase1.compare(reporter, strokeAndFillCase2,
|
|
|
|
TestCase::kSameUpToStroke_ComparisonExpecation);
|
2016-06-09 13:03:38 +00:00
|
|
|
strokeAndFillDashCase1.compare(reporter, strokeAndFillDashCase2,
|
|
|
|
TestCase::kSameUpToStroke_ComparisonExpecation);
|
2016-05-09 20:02:01 +00:00
|
|
|
}
|
2016-06-09 13:03:38 +00:00
|
|
|
strokeAndFillDashCase1.compare(reporter, strokeAndFillCase1,
|
|
|
|
TestCase::kAllSame_ComparisonExpecation);
|
|
|
|
strokeAndFillDashCase2.compare(reporter, strokeAndFillCase2,
|
|
|
|
TestCase::kAllSame_ComparisonExpecation);
|
2016-05-09 20:02:01 +00:00
|
|
|
}
|
|
|
|
|
2016-04-27 13:46:23 +00:00
|
|
|
template <typename GEO, typename T>
|
2016-05-04 20:50:29 +00:00
|
|
|
static void test_stroke_param_impl(skiatest::Reporter* reporter, const GEO& geo,
|
|
|
|
std::function<void(SkPaint*, T)> setter, T a, T b,
|
|
|
|
bool paramAffectsStroke,
|
|
|
|
bool paramAffectsDashAndStroke) {
|
|
|
|
// Set the stroke width so that we don't get hairline. However, call the setter afterward so
|
|
|
|
// that it can override the stroke width.
|
2016-04-26 19:56:00 +00:00
|
|
|
SkPaint strokeA;
|
|
|
|
strokeA.setStyle(SkPaint::kStroke_Style);
|
|
|
|
strokeA.setStrokeWidth(2.f);
|
|
|
|
setter(&strokeA, a);
|
|
|
|
SkPaint strokeB;
|
|
|
|
strokeB.setStyle(SkPaint::kStroke_Style);
|
|
|
|
strokeB.setStrokeWidth(2.f);
|
|
|
|
setter(&strokeB, b);
|
|
|
|
|
2016-05-04 15:27:41 +00:00
|
|
|
TestCase strokeACase(geo, strokeA, reporter);
|
|
|
|
TestCase strokeBCase(geo, strokeB, reporter);
|
2016-05-04 20:50:29 +00:00
|
|
|
if (paramAffectsStroke) {
|
|
|
|
strokeACase.compare(reporter, strokeBCase, TestCase::kSameUpToStroke_ComparisonExpecation);
|
|
|
|
} else {
|
|
|
|
strokeACase.compare(reporter, strokeBCase, TestCase::kAllSame_ComparisonExpecation);
|
|
|
|
}
|
2016-04-26 19:56:00 +00:00
|
|
|
|
2016-05-05 15:28:30 +00:00
|
|
|
SkPaint strokeAndFillA = strokeA;
|
|
|
|
SkPaint strokeAndFillB = strokeB;
|
|
|
|
strokeAndFillA.setStyle(SkPaint::kStrokeAndFill_Style);
|
|
|
|
strokeAndFillB.setStyle(SkPaint::kStrokeAndFill_Style);
|
|
|
|
TestCase strokeAndFillACase(geo, strokeAndFillA, reporter);
|
|
|
|
TestCase strokeAndFillBCase(geo, strokeAndFillB, reporter);
|
|
|
|
if (paramAffectsStroke) {
|
|
|
|
strokeAndFillACase.compare(reporter, strokeAndFillBCase,
|
|
|
|
TestCase::kSameUpToStroke_ComparisonExpecation);
|
|
|
|
} else {
|
|
|
|
strokeAndFillACase.compare(reporter, strokeAndFillBCase,
|
|
|
|
TestCase::kAllSame_ComparisonExpecation);
|
|
|
|
}
|
|
|
|
|
2016-04-26 19:56:00 +00:00
|
|
|
// Make sure stroking params don't affect fill style.
|
|
|
|
SkPaint fillA = strokeA, fillB = strokeB;
|
|
|
|
fillA.setStyle(SkPaint::kFill_Style);
|
|
|
|
fillB.setStyle(SkPaint::kFill_Style);
|
2016-05-04 15:27:41 +00:00
|
|
|
TestCase fillACase(geo, fillA, reporter);
|
|
|
|
TestCase fillBCase(geo, fillB, reporter);
|
2016-04-26 19:56:00 +00:00
|
|
|
fillACase.compare(reporter, fillBCase, TestCase::kAllSame_ComparisonExpecation);
|
|
|
|
|
|
|
|
// Make sure just applying the dash but not stroke gives the same key for both stroking
|
|
|
|
// variations.
|
|
|
|
SkPaint dashA = strokeA, dashB = strokeB;
|
|
|
|
dashA.setPathEffect(make_dash());
|
|
|
|
dashB.setPathEffect(make_dash());
|
2016-05-04 15:27:41 +00:00
|
|
|
TestCase dashACase(geo, dashA, reporter);
|
|
|
|
TestCase dashBCase(geo, dashB, reporter);
|
2016-05-04 20:50:29 +00:00
|
|
|
if (paramAffectsDashAndStroke) {
|
|
|
|
dashACase.compare(reporter, dashBCase, TestCase::kSameUpToStroke_ComparisonExpecation);
|
|
|
|
} else {
|
|
|
|
dashACase.compare(reporter, dashBCase, TestCase::kAllSame_ComparisonExpecation);
|
|
|
|
}
|
2016-04-26 19:56:00 +00:00
|
|
|
}
|
|
|
|
|
2016-05-04 20:50:29 +00:00
|
|
|
template <typename GEO, typename T>
|
|
|
|
static void test_stroke_param(skiatest::Reporter* reporter, const GEO& geo,
|
|
|
|
std::function<void(SkPaint*, T)> setter, T a, T b) {
|
|
|
|
test_stroke_param_impl(reporter, geo, setter, a, b, true, true);
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename GEO>
|
|
|
|
static void test_stroke_cap(skiatest::Reporter* reporter, const GEO& geo) {
|
|
|
|
GrShape shape(geo, GrStyle(SkStrokeRec::kHairline_InitStyle));
|
|
|
|
// The cap should only affect shapes that may be open.
|
|
|
|
bool affectsStroke = !shape.knownToBeClosed();
|
|
|
|
// Dashing adds ends that need caps.
|
|
|
|
bool affectsDashAndStroke = true;
|
|
|
|
test_stroke_param_impl<GEO, SkPaint::Cap>(
|
|
|
|
reporter,
|
|
|
|
geo,
|
|
|
|
[](SkPaint* p, SkPaint::Cap c) { p->setStrokeCap(c);},
|
|
|
|
SkPaint::kButt_Cap, SkPaint::kRound_Cap,
|
|
|
|
affectsStroke,
|
|
|
|
affectsDashAndStroke);
|
|
|
|
};
|
|
|
|
|
2016-04-27 13:46:23 +00:00
|
|
|
template <typename GEO>
|
|
|
|
static void test_miter_limit(skiatest::Reporter* reporter, const GEO& geo) {
|
2016-05-04 20:50:29 +00:00
|
|
|
auto setMiterJoinAndLimit = [](SkPaint* p, SkScalar miter) {
|
|
|
|
p->setStrokeJoin(SkPaint::kMiter_Join);
|
|
|
|
p->setStrokeMiter(miter);
|
|
|
|
};
|
|
|
|
|
|
|
|
auto setOtherJoinAndLimit = [](SkPaint* p, SkScalar miter) {
|
|
|
|
p->setStrokeJoin(SkPaint::kRound_Join);
|
|
|
|
p->setStrokeMiter(miter);
|
|
|
|
};
|
|
|
|
|
|
|
|
// The miter limit should affect stroked and dashed-stroked cases when the join type is
|
|
|
|
// miter.
|
|
|
|
test_stroke_param_impl<GEO, SkScalar>(
|
|
|
|
reporter,
|
|
|
|
geo,
|
|
|
|
setMiterJoinAndLimit,
|
|
|
|
0.5f, 0.75f,
|
|
|
|
true,
|
|
|
|
true);
|
|
|
|
|
|
|
|
// The miter limit should not affect stroked and dashed-stroked cases when the join type is
|
|
|
|
// not miter.
|
|
|
|
test_stroke_param_impl<GEO, SkScalar>(
|
|
|
|
reporter,
|
|
|
|
geo,
|
|
|
|
setOtherJoinAndLimit,
|
|
|
|
0.5f, 0.75f,
|
|
|
|
false,
|
|
|
|
false);
|
2016-04-26 19:56:00 +00:00
|
|
|
}
|
|
|
|
|
2016-04-27 13:46:23 +00:00
|
|
|
template<typename GEO>
|
|
|
|
static void test_dash_fill(skiatest::Reporter* reporter, const GEO& geo) {
|
2016-04-26 19:56:00 +00:00
|
|
|
// A dash with no stroke should have no effect
|
|
|
|
using DashFactoryFn = sk_sp<SkPathEffect>(*)();
|
|
|
|
for (DashFactoryFn md : {&make_dash, &make_null_dash}) {
|
|
|
|
SkPaint dashFill;
|
|
|
|
dashFill.setPathEffect((*md)());
|
2016-05-04 15:27:41 +00:00
|
|
|
TestCase dashFillCase(geo, dashFill, reporter);
|
2016-04-26 19:56:00 +00:00
|
|
|
|
2016-05-04 15:27:41 +00:00
|
|
|
TestCase fillCase(geo, SkPaint(), reporter);
|
2016-04-26 19:56:00 +00:00
|
|
|
dashFillCase.compare(reporter, fillCase, TestCase::kAllSame_ComparisonExpecation);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-27 13:46:23 +00:00
|
|
|
template<typename GEO>
|
|
|
|
void test_null_dash(skiatest::Reporter* reporter, const GEO& geo) {
|
2016-04-26 19:56:00 +00:00
|
|
|
SkPaint fill;
|
|
|
|
SkPaint stroke;
|
|
|
|
stroke.setStyle(SkPaint::kStroke_Style);
|
|
|
|
stroke.setStrokeWidth(1.f);
|
|
|
|
SkPaint dash;
|
|
|
|
dash.setStyle(SkPaint::kStroke_Style);
|
|
|
|
dash.setStrokeWidth(1.f);
|
|
|
|
dash.setPathEffect(make_dash());
|
|
|
|
SkPaint nullDash;
|
|
|
|
nullDash.setStyle(SkPaint::kStroke_Style);
|
|
|
|
nullDash.setStrokeWidth(1.f);
|
|
|
|
nullDash.setPathEffect(make_null_dash());
|
|
|
|
|
2016-05-04 15:27:41 +00:00
|
|
|
TestCase fillCase(geo, fill, reporter);
|
|
|
|
TestCase strokeCase(geo, stroke, reporter);
|
|
|
|
TestCase dashCase(geo, dash, reporter);
|
|
|
|
TestCase nullDashCase(geo, nullDash, reporter);
|
2016-04-26 19:56:00 +00:00
|
|
|
|
|
|
|
nullDashCase.compare(reporter, fillCase, TestCase::kSameUpToStroke_ComparisonExpecation);
|
|
|
|
nullDashCase.compare(reporter, strokeCase, TestCase::kAllSame_ComparisonExpecation);
|
|
|
|
nullDashCase.compare(reporter, dashCase, TestCase::kSameUpToPE_ComparisonExpecation);
|
|
|
|
}
|
|
|
|
|
2016-04-27 13:46:23 +00:00
|
|
|
template <typename GEO>
|
|
|
|
void test_path_effect_makes_rrect(skiatest::Reporter* reporter, const GEO& geo) {
|
|
|
|
/**
|
|
|
|
* This path effect takes any input path and turns it into a rrect. It passes through stroke
|
|
|
|
* info.
|
|
|
|
*/
|
|
|
|
class RRectPathEffect : SkPathEffect {
|
|
|
|
public:
|
|
|
|
static const SkRRect& RRect() {
|
|
|
|
static const SkRRect kRRect = SkRRect::MakeRectXY(SkRect::MakeWH(12, 12), 3, 5);
|
|
|
|
return kRRect;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool filterPath(SkPath* dst, const SkPath& src, SkStrokeRec*,
|
|
|
|
const SkRect* cullR) const override {
|
|
|
|
dst->reset();
|
|
|
|
dst->addRRect(RRect());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
void computeFastBounds(SkRect* dst, const SkRect& src) const override {
|
|
|
|
*dst = RRect().getBounds();
|
|
|
|
}
|
|
|
|
static sk_sp<SkPathEffect> Make() { return sk_sp<SkPathEffect>(new RRectPathEffect); }
|
|
|
|
Factory getFactory() const override { return nullptr; }
|
|
|
|
void toString(SkString*) const override {}
|
|
|
|
private:
|
|
|
|
RRectPathEffect() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
SkPaint fill;
|
2016-05-04 15:27:41 +00:00
|
|
|
TestCase fillGeoCase(geo, fill, reporter);
|
2016-04-27 13:46:23 +00:00
|
|
|
|
|
|
|
SkPaint pe;
|
|
|
|
pe.setPathEffect(RRectPathEffect::Make());
|
2016-05-04 15:27:41 +00:00
|
|
|
TestCase geoPECase(geo, pe, reporter);
|
2016-04-27 13:46:23 +00:00
|
|
|
|
|
|
|
SkPaint peStroke;
|
|
|
|
peStroke.setPathEffect(RRectPathEffect::Make());
|
|
|
|
peStroke.setStrokeWidth(2.f);
|
|
|
|
peStroke.setStyle(SkPaint::kStroke_Style);
|
2016-05-04 15:27:41 +00:00
|
|
|
TestCase geoPEStrokeCase(geo, peStroke, reporter);
|
2016-04-27 13:46:23 +00:00
|
|
|
|
|
|
|
fillGeoCase.compare(reporter, geoPECase, TestCase::kSameUpToPE_ComparisonExpecation);
|
|
|
|
fillGeoCase.compare(reporter, geoPEStrokeCase, TestCase::kSameUpToPE_ComparisonExpecation);
|
|
|
|
geoPECase.compare(reporter, geoPEStrokeCase,
|
|
|
|
TestCase::kSameUpToStroke_ComparisonExpecation);
|
|
|
|
|
2016-05-04 15:27:41 +00:00
|
|
|
TestCase rrectFillCase(RRectPathEffect::RRect(), fill, reporter);
|
2016-04-27 13:46:23 +00:00
|
|
|
SkPaint stroke = peStroke;
|
|
|
|
stroke.setPathEffect(nullptr);
|
2016-05-04 15:27:41 +00:00
|
|
|
TestCase rrectStrokeCase(RRectPathEffect::RRect(), stroke, reporter);
|
2016-04-27 13:46:23 +00:00
|
|
|
|
|
|
|
SkRRect rrect;
|
|
|
|
// Applying the path effect should make a SkRRect shape. There is no further stroking in the
|
|
|
|
// geoPECase, so the full style should be the same as just the PE.
|
2016-06-10 15:05:14 +00:00
|
|
|
REPORTER_ASSERT(reporter, geoPECase.appliedPathEffectShape().asRRect(&rrect, nullptr, nullptr,
|
|
|
|
nullptr));
|
2016-04-27 13:46:23 +00:00
|
|
|
REPORTER_ASSERT(reporter, rrect == RRectPathEffect::RRect());
|
|
|
|
REPORTER_ASSERT(reporter, geoPECase.appliedPathEffectKey() == rrectFillCase.baseKey());
|
|
|
|
|
2016-06-10 15:05:14 +00:00
|
|
|
REPORTER_ASSERT(reporter, geoPECase.appliedFullStyleShape().asRRect(&rrect, nullptr, nullptr,
|
|
|
|
nullptr));
|
2016-04-27 13:46:23 +00:00
|
|
|
REPORTER_ASSERT(reporter, rrect == RRectPathEffect::RRect());
|
|
|
|
REPORTER_ASSERT(reporter, geoPECase.appliedFullStyleKey() == rrectFillCase.baseKey());
|
|
|
|
|
|
|
|
// In the PE+stroke case applying the full style should be the same as just stroking the rrect.
|
2016-06-10 15:05:14 +00:00
|
|
|
REPORTER_ASSERT(reporter, geoPEStrokeCase.appliedPathEffectShape().asRRect(&rrect, nullptr,
|
|
|
|
nullptr, nullptr));
|
2016-04-27 13:46:23 +00:00
|
|
|
REPORTER_ASSERT(reporter, rrect == RRectPathEffect::RRect());
|
|
|
|
REPORTER_ASSERT(reporter, geoPEStrokeCase.appliedPathEffectKey() == rrectFillCase.baseKey());
|
|
|
|
|
2016-06-10 15:05:14 +00:00
|
|
|
REPORTER_ASSERT(reporter, !geoPEStrokeCase.appliedFullStyleShape().asRRect(&rrect, nullptr,
|
|
|
|
nullptr, nullptr));
|
2016-04-27 13:46:23 +00:00
|
|
|
REPORTER_ASSERT(reporter, geoPEStrokeCase.appliedFullStyleKey() ==
|
|
|
|
rrectStrokeCase.appliedFullStyleKey());
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename GEO>
|
|
|
|
void test_unknown_path_effect(skiatest::Reporter* reporter, const GEO& geo) {
|
|
|
|
/**
|
|
|
|
* This path effect just adds two lineTos to the input path.
|
|
|
|
*/
|
|
|
|
class AddLineTosPathEffect : SkPathEffect {
|
|
|
|
public:
|
|
|
|
bool filterPath(SkPath* dst, const SkPath& src, SkStrokeRec*,
|
|
|
|
const SkRect* cullR) const override {
|
|
|
|
*dst = src;
|
|
|
|
dst->lineTo(0, 0);
|
|
|
|
dst->lineTo(10, 10);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
void computeFastBounds(SkRect* dst, const SkRect& src) const override {
|
|
|
|
*dst = src;
|
|
|
|
dst->growToInclude(0, 0);
|
|
|
|
dst->growToInclude(10, 10);
|
|
|
|
}
|
|
|
|
static sk_sp<SkPathEffect> Make() { return sk_sp<SkPathEffect>(new AddLineTosPathEffect); }
|
|
|
|
Factory getFactory() const override { return nullptr; }
|
|
|
|
void toString(SkString*) const override {}
|
|
|
|
private:
|
|
|
|
AddLineTosPathEffect() {}
|
|
|
|
};
|
|
|
|
|
2016-05-04 15:44:15 +00:00
|
|
|
// This path effect should make the keys invalid when it is applied. We only produce a path
|
2016-04-27 13:46:23 +00:00
|
|
|
// effect key for dash path effects. So the only way another arbitrary path effect can produce
|
|
|
|
// a styled result with a key is to produce a non-path shape that has a purely geometric key.
|
|
|
|
SkPaint peStroke;
|
|
|
|
peStroke.setPathEffect(AddLineTosPathEffect::Make());
|
|
|
|
peStroke.setStrokeWidth(2.f);
|
|
|
|
peStroke.setStyle(SkPaint::kStroke_Style);
|
2016-05-04 15:27:41 +00:00
|
|
|
TestCase geoPEStrokeCase(geo, peStroke, reporter);
|
2016-04-27 13:46:23 +00:00
|
|
|
TestCase::SelfExpectations expectations;
|
|
|
|
expectations.fPEHasEffect = true;
|
|
|
|
expectations.fPEHasValidKey = false;
|
|
|
|
expectations.fStrokeApplies = true;
|
|
|
|
geoPEStrokeCase.testExpectations(reporter, expectations);
|
|
|
|
}
|
|
|
|
|
2016-05-04 15:44:15 +00:00
|
|
|
template <typename GEO>
|
|
|
|
void test_make_hairline_path_effect(skiatest::Reporter* reporter, const GEO& geo, bool isNonPath) {
|
|
|
|
/**
|
|
|
|
* This path effect just changes the stroke rec to hairline.
|
|
|
|
*/
|
|
|
|
class MakeHairlinePathEffect : SkPathEffect {
|
|
|
|
public:
|
|
|
|
bool filterPath(SkPath* dst, const SkPath& src, SkStrokeRec* strokeRec,
|
|
|
|
const SkRect* cullR) const override {
|
|
|
|
*dst = src;
|
|
|
|
strokeRec->setHairlineStyle();
|
|
|
|
return true;
|
|
|
|
}
|
2016-06-10 15:05:14 +00:00
|
|
|
void computeFastBounds(SkRect* dst, const SkRect& src) const override { *dst = src; }
|
2016-05-04 15:44:15 +00:00
|
|
|
static sk_sp<SkPathEffect> Make() {
|
|
|
|
return sk_sp<SkPathEffect>(new MakeHairlinePathEffect);
|
|
|
|
}
|
|
|
|
Factory getFactory() const override { return nullptr; }
|
|
|
|
void toString(SkString*) const override {}
|
|
|
|
private:
|
|
|
|
MakeHairlinePathEffect() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
SkPaint fill;
|
|
|
|
SkPaint pe;
|
|
|
|
pe.setPathEffect(MakeHairlinePathEffect::Make());
|
|
|
|
|
|
|
|
TestCase peCase(geo, pe, reporter);
|
|
|
|
|
2016-06-06 21:01:25 +00:00
|
|
|
SkPath a, b, c;
|
2016-05-04 15:44:15 +00:00
|
|
|
peCase.baseShape().asPath(&a);
|
|
|
|
peCase.appliedPathEffectShape().asPath(&b);
|
2016-06-06 21:01:25 +00:00
|
|
|
peCase.appliedFullStyleShape().asPath(&c);
|
2016-05-04 15:44:15 +00:00
|
|
|
if (isNonPath) {
|
2016-06-06 21:01:25 +00:00
|
|
|
// RRect types can have a change in start index or direction after the PE is applied. This
|
|
|
|
// is because once the PE is applied, GrShape may canonicalize the dir and index since it
|
|
|
|
// is not germane to the styling any longer.
|
|
|
|
// Instead we just check that the paths would fill the same both before and after styling.
|
|
|
|
REPORTER_ASSERT(reporter, paths_fill_same(a, b));
|
|
|
|
REPORTER_ASSERT(reporter, paths_fill_same(a, c));
|
2016-05-04 15:44:15 +00:00
|
|
|
} else {
|
2016-06-06 21:01:25 +00:00
|
|
|
REPORTER_ASSERT(reporter, a == b);
|
|
|
|
REPORTER_ASSERT(reporter, a == c);
|
2016-05-04 15:44:15 +00:00
|
|
|
REPORTER_ASSERT(reporter, peCase.appliedPathEffectKey().empty());
|
|
|
|
REPORTER_ASSERT(reporter, peCase.appliedFullStyleKey().empty());
|
|
|
|
}
|
2016-06-06 21:01:25 +00:00
|
|
|
REPORTER_ASSERT(reporter, peCase.appliedPathEffectShape().style().isSimpleHairline());
|
|
|
|
REPORTER_ASSERT(reporter, peCase.appliedFullStyleShape().style().isSimpleHairline());
|
2016-05-04 15:44:15 +00:00
|
|
|
}
|
|
|
|
|
2016-04-27 20:30:25 +00:00
|
|
|
/**
|
|
|
|
* isNonPath indicates whether the initial shape made from the path is expected to be recognized
|
|
|
|
* as a simpler shape type (e.g. rrect)
|
|
|
|
*/
|
|
|
|
void test_volatile_path(skiatest::Reporter* reporter, const SkPath& path,
|
|
|
|
bool isNonPath) {
|
|
|
|
SkPath vPath(path);
|
|
|
|
vPath.setIsVolatile(true);
|
|
|
|
|
|
|
|
SkPaint dashAndStroke;
|
|
|
|
dashAndStroke.setPathEffect(make_dash());
|
|
|
|
dashAndStroke.setStrokeWidth(2.f);
|
|
|
|
dashAndStroke.setStyle(SkPaint::kStroke_Style);
|
2016-05-04 15:27:41 +00:00
|
|
|
TestCase volatileCase(vPath, dashAndStroke, reporter);
|
2016-04-27 20:30:25 +00:00
|
|
|
// We expect a shape made from a volatile path to have a key iff the shape is recognized
|
|
|
|
// as a specialized geometry.
|
|
|
|
if (isNonPath) {
|
|
|
|
REPORTER_ASSERT(reporter, SkToBool(volatileCase.baseKey().count()));
|
|
|
|
// In this case all the keys should be identical to the non-volatile case.
|
2016-05-04 15:27:41 +00:00
|
|
|
TestCase nonVolatileCase(path, dashAndStroke, reporter);
|
2016-04-27 20:30:25 +00:00
|
|
|
volatileCase.compare(reporter, nonVolatileCase, TestCase::kAllSame_ComparisonExpecation);
|
|
|
|
} else {
|
|
|
|
// None of the keys should be valid.
|
|
|
|
REPORTER_ASSERT(reporter, !SkToBool(volatileCase.baseKey().count()));
|
|
|
|
REPORTER_ASSERT(reporter, !SkToBool(volatileCase.appliedPathEffectKey().count()));
|
|
|
|
REPORTER_ASSERT(reporter, !SkToBool(volatileCase.appliedFullStyleKey().count()));
|
|
|
|
REPORTER_ASSERT(reporter, !SkToBool(volatileCase.appliedPathEffectThenStrokeKey().count()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-27 19:36:02 +00:00
|
|
|
template <typename GEO>
|
|
|
|
void test_path_effect_makes_empty_shape(skiatest::Reporter* reporter, const GEO& geo) {
|
|
|
|
/**
|
|
|
|
* This path effect returns an empty path.
|
|
|
|
*/
|
|
|
|
class EmptyPathEffect : SkPathEffect {
|
|
|
|
public:
|
|
|
|
bool filterPath(SkPath* dst, const SkPath& src, SkStrokeRec*,
|
|
|
|
const SkRect* cullR) const override {
|
|
|
|
dst->reset();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
void computeFastBounds(SkRect* dst, const SkRect& src) const override {
|
|
|
|
dst->setEmpty();
|
|
|
|
}
|
|
|
|
static sk_sp<SkPathEffect> Make() { return sk_sp<SkPathEffect>(new EmptyPathEffect); }
|
|
|
|
Factory getFactory() const override { return nullptr; }
|
|
|
|
void toString(SkString*) const override {}
|
|
|
|
private:
|
|
|
|
EmptyPathEffect() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
SkPath emptyPath;
|
|
|
|
GrShape emptyShape(emptyPath);
|
|
|
|
Key emptyKey;
|
|
|
|
make_key(&emptyKey, emptyShape);
|
2016-05-11 22:15:56 +00:00
|
|
|
REPORTER_ASSERT(reporter, emptyShape.isEmpty());
|
2016-04-27 19:36:02 +00:00
|
|
|
|
|
|
|
SkPaint pe;
|
|
|
|
pe.setPathEffect(EmptyPathEffect::Make());
|
2016-05-04 15:27:41 +00:00
|
|
|
TestCase geoCase(geo, pe, reporter);
|
2016-04-27 19:36:02 +00:00
|
|
|
REPORTER_ASSERT(reporter, geoCase.appliedFullStyleKey() == emptyKey);
|
|
|
|
REPORTER_ASSERT(reporter, geoCase.appliedPathEffectKey() == emptyKey);
|
|
|
|
REPORTER_ASSERT(reporter, geoCase.appliedPathEffectThenStrokeKey() == emptyKey);
|
2016-05-11 22:15:56 +00:00
|
|
|
REPORTER_ASSERT(reporter, geoCase.appliedPathEffectShape().isEmpty());
|
|
|
|
REPORTER_ASSERT(reporter, geoCase.appliedFullStyleShape().isEmpty());
|
2016-04-27 19:36:02 +00:00
|
|
|
|
|
|
|
SkPaint peStroke;
|
|
|
|
peStroke.setPathEffect(EmptyPathEffect::Make());
|
|
|
|
peStroke.setStrokeWidth(2.f);
|
|
|
|
peStroke.setStyle(SkPaint::kStroke_Style);
|
2016-05-04 15:27:41 +00:00
|
|
|
TestCase geoPEStrokeCase(geo, peStroke, reporter);
|
2016-04-27 19:36:02 +00:00
|
|
|
REPORTER_ASSERT(reporter, geoPEStrokeCase.appliedFullStyleKey() == emptyKey);
|
|
|
|
REPORTER_ASSERT(reporter, geoPEStrokeCase.appliedPathEffectKey() == emptyKey);
|
|
|
|
REPORTER_ASSERT(reporter, geoPEStrokeCase.appliedPathEffectThenStrokeKey() == emptyKey);
|
2016-05-11 22:15:56 +00:00
|
|
|
REPORTER_ASSERT(reporter, geoPEStrokeCase.appliedPathEffectShape().isEmpty());
|
|
|
|
REPORTER_ASSERT(reporter, geoPEStrokeCase.appliedFullStyleShape().isEmpty());
|
2016-04-27 19:36:02 +00:00
|
|
|
}
|
|
|
|
|
2016-06-07 19:20:15 +00:00
|
|
|
template <typename GEO>
|
|
|
|
void test_path_effect_fails(skiatest::Reporter* reporter, const GEO& geo) {
|
|
|
|
/**
|
|
|
|
* This path effect returns an empty path.
|
|
|
|
*/
|
|
|
|
class FailurePathEffect : SkPathEffect {
|
|
|
|
public:
|
|
|
|
bool filterPath(SkPath* dst, const SkPath& src, SkStrokeRec*,
|
|
|
|
const SkRect* cullR) const override {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
void computeFastBounds(SkRect* dst, const SkRect& src) const override {
|
|
|
|
*dst = src;
|
|
|
|
}
|
|
|
|
static sk_sp<SkPathEffect> Make() { return sk_sp<SkPathEffect>(new FailurePathEffect); }
|
|
|
|
Factory getFactory() const override { return nullptr; }
|
|
|
|
void toString(SkString*) const override {}
|
|
|
|
private:
|
|
|
|
FailurePathEffect() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
SkPaint fill;
|
|
|
|
TestCase fillCase(geo, fill, reporter);
|
|
|
|
|
|
|
|
SkPaint pe;
|
|
|
|
pe.setPathEffect(FailurePathEffect::Make());
|
|
|
|
TestCase peCase(geo, pe, reporter);
|
|
|
|
|
|
|
|
SkPaint stroke;
|
|
|
|
stroke.setStrokeWidth(2.f);
|
|
|
|
stroke.setStyle(SkPaint::kStroke_Style);
|
|
|
|
TestCase strokeCase(geo, stroke, reporter);
|
|
|
|
|
|
|
|
SkPaint peStroke = stroke;
|
|
|
|
peStroke.setPathEffect(FailurePathEffect::Make());
|
|
|
|
TestCase peStrokeCase(geo, peStroke, reporter);
|
|
|
|
|
|
|
|
// In general the path effect failure can cause some of the TestCase::compare() tests to fail
|
|
|
|
// for at least two reasons: 1) We will initially treat the shape as unkeyable because of the
|
|
|
|
// path effect, but then when the path effect fails we can key it. 2) GrShape will change its
|
|
|
|
// mind about whether a unclosed rect is actually rect. The path effect initially bars us from
|
|
|
|
// closing it but after the effect fails we can (for the fill+pe case). This causes different
|
|
|
|
// routes through GrShape to have equivalent but different representations of the path (closed
|
|
|
|
// or not) but that fill the same.
|
|
|
|
SkPath a;
|
|
|
|
SkPath b;
|
|
|
|
fillCase.appliedPathEffectShape().asPath(&a);
|
|
|
|
peCase.appliedPathEffectShape().asPath(&b);
|
|
|
|
REPORTER_ASSERT(reporter, paths_fill_same(a, b));
|
|
|
|
|
|
|
|
fillCase.appliedFullStyleShape().asPath(&a);
|
|
|
|
peCase.appliedFullStyleShape().asPath(&b);
|
|
|
|
REPORTER_ASSERT(reporter, paths_fill_same(a, b));
|
|
|
|
|
|
|
|
strokeCase.appliedPathEffectShape().asPath(&a);
|
|
|
|
peStrokeCase.appliedPathEffectShape().asPath(&b);
|
|
|
|
REPORTER_ASSERT(reporter, paths_fill_same(a, b));
|
|
|
|
|
|
|
|
strokeCase.appliedFullStyleShape().asPath(&a);
|
|
|
|
peStrokeCase.appliedFullStyleShape().asPath(&b);
|
|
|
|
REPORTER_ASSERT(reporter, paths_fill_same(a, b));
|
|
|
|
}
|
|
|
|
|
2016-04-27 19:36:02 +00:00
|
|
|
void test_empty_shape(skiatest::Reporter* reporter) {
|
|
|
|
SkPath emptyPath;
|
|
|
|
SkPaint fill;
|
2016-05-04 15:27:41 +00:00
|
|
|
TestCase fillEmptyCase(emptyPath, fill, reporter);
|
2016-05-11 22:15:56 +00:00
|
|
|
REPORTER_ASSERT(reporter, fillEmptyCase.baseShape().isEmpty());
|
|
|
|
REPORTER_ASSERT(reporter, fillEmptyCase.appliedPathEffectShape().isEmpty());
|
|
|
|
REPORTER_ASSERT(reporter, fillEmptyCase.appliedFullStyleShape().isEmpty());
|
2016-04-27 19:36:02 +00:00
|
|
|
|
|
|
|
Key emptyKey(fillEmptyCase.baseKey());
|
|
|
|
REPORTER_ASSERT(reporter, emptyKey.count());
|
|
|
|
TestCase::SelfExpectations expectations;
|
|
|
|
expectations.fStrokeApplies = false;
|
|
|
|
expectations.fPEHasEffect = false;
|
|
|
|
// This will test whether applying style preserves emptiness
|
|
|
|
fillEmptyCase.testExpectations(reporter, expectations);
|
|
|
|
|
|
|
|
// Stroking an empty path should have no effect
|
|
|
|
SkPath emptyPath2;
|
|
|
|
SkPaint stroke;
|
|
|
|
stroke.setStrokeWidth(2.f);
|
|
|
|
stroke.setStyle(SkPaint::kStroke_Style);
|
2016-05-04 15:27:41 +00:00
|
|
|
TestCase strokeEmptyCase(emptyPath2, stroke, reporter);
|
2016-04-27 19:36:02 +00:00
|
|
|
strokeEmptyCase.compare(reporter, fillEmptyCase, TestCase::kAllSame_ComparisonExpecation);
|
|
|
|
|
|
|
|
// Dashing and stroking an empty path should have no effect
|
|
|
|
SkPath emptyPath3;
|
|
|
|
SkPaint dashAndStroke;
|
|
|
|
dashAndStroke.setPathEffect(make_dash());
|
|
|
|
dashAndStroke.setStrokeWidth(2.f);
|
|
|
|
dashAndStroke.setStyle(SkPaint::kStroke_Style);
|
2016-05-04 15:27:41 +00:00
|
|
|
TestCase dashAndStrokeEmptyCase(emptyPath3, dashAndStroke, reporter);
|
2016-04-27 19:36:02 +00:00
|
|
|
dashAndStrokeEmptyCase.compare(reporter, fillEmptyCase,
|
|
|
|
TestCase::kAllSame_ComparisonExpecation);
|
2016-04-28 16:30:46 +00:00
|
|
|
|
|
|
|
// A shape made from an empty rrect should behave the same as an empty path.
|
|
|
|
SkRRect emptyRRect = SkRRect::MakeRect(SkRect::MakeEmpty());
|
|
|
|
REPORTER_ASSERT(reporter, emptyRRect.getType() == SkRRect::kEmpty_Type);
|
2016-05-04 15:27:41 +00:00
|
|
|
TestCase dashAndStrokeEmptyRRectCase(emptyRRect, dashAndStroke, reporter);
|
2016-04-28 16:30:46 +00:00
|
|
|
dashAndStrokeEmptyRRectCase.compare(reporter, fillEmptyCase,
|
|
|
|
TestCase::kAllSame_ComparisonExpecation);
|
|
|
|
|
|
|
|
// Same for a rect.
|
|
|
|
SkRect emptyRect = SkRect::MakeEmpty();
|
2016-05-04 15:27:41 +00:00
|
|
|
TestCase dashAndStrokeEmptyRectCase(emptyRect, dashAndStroke, reporter);
|
2016-04-28 16:30:46 +00:00
|
|
|
dashAndStrokeEmptyRectCase.compare(reporter, fillEmptyCase,
|
|
|
|
TestCase::kAllSame_ComparisonExpecation);
|
2016-04-27 19:36:02 +00:00
|
|
|
}
|
|
|
|
|
2016-06-10 15:05:14 +00:00
|
|
|
// rect and oval types have rrect start indices that collapse to the same point. Here we select the
|
|
|
|
// canonical point in these cases.
|
|
|
|
unsigned canonicalize_rrect_start(int s, const SkRRect& rrect) {
|
|
|
|
switch (rrect.getType()) {
|
|
|
|
case SkRRect::kRect_Type:
|
|
|
|
return (s + 1) & 0b110;
|
|
|
|
case SkRRect::kOval_Type:
|
|
|
|
return s & 0b110;
|
|
|
|
default:
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void test_rrect(skiatest::Reporter* r, const SkRRect& rrect) {
|
2016-06-11 01:28:06 +00:00
|
|
|
enum Style {
|
2016-06-10 15:05:14 +00:00
|
|
|
kFill,
|
|
|
|
kStroke,
|
|
|
|
kHairline,
|
|
|
|
kStrokeAndFill
|
|
|
|
};
|
|
|
|
|
|
|
|
// SkStrokeRec has no default cons., so init with kFill before calling the setters below.
|
|
|
|
SkStrokeRec strokeRecs[4] { SkStrokeRec::kFill_InitStyle, SkStrokeRec::kFill_InitStyle,
|
|
|
|
SkStrokeRec::kFill_InitStyle, SkStrokeRec::kFill_InitStyle};
|
|
|
|
strokeRecs[kFill].setFillStyle();
|
|
|
|
strokeRecs[kStroke].setStrokeStyle(2.f);
|
|
|
|
strokeRecs[kHairline].setHairlineStyle();
|
|
|
|
strokeRecs[kStrokeAndFill].setStrokeStyle(3.f, true);
|
|
|
|
sk_sp<SkPathEffect> dashEffect = make_dash();
|
|
|
|
|
2016-06-11 01:28:06 +00:00
|
|
|
static constexpr Style kStyleCnt = static_cast<Style>(SK_ARRAY_COUNT(strokeRecs));
|
|
|
|
|
|
|
|
auto index = [](bool inverted,
|
|
|
|
SkPath::Direction dir,
|
|
|
|
unsigned start,
|
|
|
|
Style style,
|
|
|
|
bool dash) -> int {
|
|
|
|
return inverted * (2 * 8 * kStyleCnt * 2) +
|
|
|
|
dir * ( 8 * kStyleCnt * 2) +
|
|
|
|
start * ( kStyleCnt * 2) +
|
|
|
|
style * ( 2) +
|
|
|
|
dash;
|
|
|
|
};
|
|
|
|
static const SkPath::Direction kSecondDirection = static_cast<SkPath::Direction>(1);
|
|
|
|
const int cnt = index(true, kSecondDirection, 7, static_cast<Style>(kStyleCnt - 1), true) + 1;
|
|
|
|
SkAutoTArray<GrShape> shapes(cnt);
|
|
|
|
for (bool inverted : {false, true}) {
|
|
|
|
for (SkPath::Direction dir : {SkPath::kCW_Direction, SkPath::kCCW_Direction}) {
|
|
|
|
for (unsigned start = 0; start < 8; ++start) {
|
|
|
|
for (Style style : {kFill, kStroke, kHairline, kStrokeAndFill}) {
|
|
|
|
for (bool dash : {false, true}) {
|
2016-06-10 15:05:14 +00:00
|
|
|
SkPathEffect* pe = dash ? dashEffect.get() : nullptr;
|
2016-06-11 01:28:06 +00:00
|
|
|
shapes[index(inverted, dir, start, style, dash)] =
|
|
|
|
GrShape(rrect, dir, start, SkToBool(inverted),
|
2016-06-10 15:05:14 +00:00
|
|
|
GrStyle(strokeRecs[style], pe));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-14 21:37:21 +00:00
|
|
|
// Get the keys for some example shape instances that we'll use for comparision against the
|
|
|
|
// rest.
|
|
|
|
static constexpr SkPath::Direction kExamplesDir = SkPath::kCW_Direction;
|
|
|
|
static constexpr unsigned kExamplesStart = 0;
|
|
|
|
const GrShape& exampleFillCase = shapes[index(false, kExamplesDir, kExamplesStart, kFill,
|
|
|
|
false)];
|
2016-06-10 15:05:14 +00:00
|
|
|
Key exampleFillCaseKey;
|
|
|
|
make_key(&exampleFillCaseKey, exampleFillCase);
|
|
|
|
|
2016-06-14 21:37:21 +00:00
|
|
|
const GrShape& exampleStrokeAndFillCase = shapes[index(false, kExamplesDir, kExamplesStart,
|
|
|
|
kStrokeAndFill, false)];
|
2016-06-10 15:05:14 +00:00
|
|
|
Key exampleStrokeAndFillCaseKey;
|
|
|
|
make_key(&exampleStrokeAndFillCaseKey, exampleStrokeAndFillCase);
|
|
|
|
|
2016-06-14 21:37:21 +00:00
|
|
|
const GrShape& exampleInvFillCase = shapes[index(true, kExamplesDir, kExamplesStart, kFill,
|
|
|
|
false)];
|
2016-06-10 15:05:14 +00:00
|
|
|
Key exampleInvFillCaseKey;
|
|
|
|
make_key(&exampleInvFillCaseKey, exampleInvFillCase);
|
|
|
|
|
2016-06-14 21:37:21 +00:00
|
|
|
const GrShape& exampleInvStrokeAndFillCase = shapes[index(true, kExamplesDir, kExamplesStart,
|
|
|
|
kStrokeAndFill, false)];
|
2016-06-10 15:05:14 +00:00
|
|
|
Key exampleInvStrokeAndFillCaseKey;
|
|
|
|
make_key(&exampleInvStrokeAndFillCaseKey, exampleInvStrokeAndFillCase);
|
|
|
|
|
2016-06-14 21:37:21 +00:00
|
|
|
const GrShape& exampleStrokeCase = shapes[index(false, kExamplesDir, kExamplesStart, kStroke,
|
|
|
|
false)];
|
2016-06-10 15:05:14 +00:00
|
|
|
Key exampleStrokeCaseKey;
|
|
|
|
make_key(&exampleStrokeCaseKey, exampleStrokeCase);
|
|
|
|
|
2016-06-14 21:37:21 +00:00
|
|
|
const GrShape& exampleInvStrokeCase = shapes[index(true, kExamplesDir, kExamplesStart, kStroke,
|
|
|
|
false)];
|
|
|
|
Key exampleInvStrokeCaseKey;
|
|
|
|
make_key(&exampleInvStrokeCaseKey, exampleInvStrokeCase);
|
|
|
|
|
|
|
|
const GrShape& exampleHairlineCase = shapes[index(false, kExamplesDir, kExamplesStart,
|
|
|
|
kHairline, false)];
|
2016-06-10 15:05:14 +00:00
|
|
|
Key exampleHairlineCaseKey;
|
|
|
|
make_key(&exampleHairlineCaseKey, exampleHairlineCase);
|
|
|
|
|
2016-06-14 21:37:21 +00:00
|
|
|
const GrShape& exampleInvHairlineCase = shapes[index(true, kExamplesDir, kExamplesStart,
|
|
|
|
kHairline, false)];
|
|
|
|
Key exampleInvHairlineCaseKey;
|
|
|
|
make_key(&exampleInvHairlineCaseKey, exampleInvHairlineCase);
|
|
|
|
|
2016-06-10 15:05:14 +00:00
|
|
|
// These are dummy initializations to suppress warnings.
|
2016-06-11 01:28:06 +00:00
|
|
|
SkRRect queryRR = SkRRect::MakeEmpty();
|
|
|
|
SkPath::Direction queryDir = SkPath::kCW_Direction;
|
|
|
|
unsigned queryStart = ~0U;
|
|
|
|
bool queryInverted = true;
|
|
|
|
|
|
|
|
REPORTER_ASSERT(r, exampleFillCase.asRRect(&queryRR, &queryDir, &queryStart, &queryInverted));
|
|
|
|
REPORTER_ASSERT(r, queryRR == rrect);
|
|
|
|
REPORTER_ASSERT(r, SkPath::kCW_Direction == queryDir);
|
|
|
|
REPORTER_ASSERT(r, 0 == queryStart);
|
|
|
|
REPORTER_ASSERT(r, !queryInverted);
|
|
|
|
|
|
|
|
REPORTER_ASSERT(r, exampleInvFillCase.asRRect(&queryRR, &queryDir, &queryStart,
|
|
|
|
&queryInverted));
|
|
|
|
REPORTER_ASSERT(r, queryRR == rrect);
|
|
|
|
REPORTER_ASSERT(r, SkPath::kCW_Direction == queryDir);
|
|
|
|
REPORTER_ASSERT(r, 0 == queryStart);
|
|
|
|
REPORTER_ASSERT(r, queryInverted);
|
|
|
|
|
|
|
|
REPORTER_ASSERT(r, exampleStrokeAndFillCase.asRRect(&queryRR, &queryDir, &queryStart,
|
|
|
|
&queryInverted));
|
|
|
|
REPORTER_ASSERT(r, queryRR == rrect);
|
|
|
|
REPORTER_ASSERT(r, SkPath::kCW_Direction == queryDir);
|
|
|
|
REPORTER_ASSERT(r, 0 == queryStart);
|
|
|
|
REPORTER_ASSERT(r, !queryInverted);
|
|
|
|
|
|
|
|
REPORTER_ASSERT(r, exampleInvStrokeAndFillCase.asRRect(&queryRR, &queryDir, &queryStart,
|
|
|
|
&queryInverted));
|
|
|
|
REPORTER_ASSERT(r, queryRR == rrect);
|
|
|
|
REPORTER_ASSERT(r, SkPath::kCW_Direction == queryDir);
|
|
|
|
REPORTER_ASSERT(r, 0 == queryStart);
|
|
|
|
REPORTER_ASSERT(r, queryInverted);
|
|
|
|
|
|
|
|
REPORTER_ASSERT(r, exampleHairlineCase.asRRect(&queryRR, &queryDir, &queryStart,
|
|
|
|
&queryInverted));
|
|
|
|
REPORTER_ASSERT(r, queryRR == rrect);
|
|
|
|
REPORTER_ASSERT(r, SkPath::kCW_Direction == queryDir);
|
|
|
|
REPORTER_ASSERT(r, 0 == queryStart);
|
|
|
|
REPORTER_ASSERT(r, !queryInverted);
|
|
|
|
|
2016-06-14 21:37:21 +00:00
|
|
|
REPORTER_ASSERT(r, exampleInvHairlineCase.asRRect(&queryRR, &queryDir, &queryStart,
|
|
|
|
&queryInverted));
|
|
|
|
REPORTER_ASSERT(r, queryRR == rrect);
|
|
|
|
REPORTER_ASSERT(r, SkPath::kCW_Direction == queryDir);
|
|
|
|
REPORTER_ASSERT(r, 0 == queryStart);
|
|
|
|
REPORTER_ASSERT(r, queryInverted);
|
|
|
|
|
2016-06-11 01:28:06 +00:00
|
|
|
REPORTER_ASSERT(r, exampleStrokeCase.asRRect(&queryRR, &queryDir, &queryStart, &queryInverted));
|
|
|
|
REPORTER_ASSERT(r, queryRR == rrect);
|
|
|
|
REPORTER_ASSERT(r, SkPath::kCW_Direction == queryDir);
|
|
|
|
REPORTER_ASSERT(r, 0 == queryStart);
|
|
|
|
REPORTER_ASSERT(r, !queryInverted);
|
2016-06-10 15:05:14 +00:00
|
|
|
|
2016-06-14 21:37:21 +00:00
|
|
|
REPORTER_ASSERT(r, exampleInvStrokeCase.asRRect(&queryRR, &queryDir, &queryStart,
|
|
|
|
&queryInverted));
|
|
|
|
REPORTER_ASSERT(r, queryRR == rrect);
|
|
|
|
REPORTER_ASSERT(r, SkPath::kCW_Direction == queryDir);
|
|
|
|
REPORTER_ASSERT(r, 0 == queryStart);
|
|
|
|
REPORTER_ASSERT(r, queryInverted);
|
|
|
|
|
2016-06-10 15:05:14 +00:00
|
|
|
// Remember that the key reflects the geometry before styling is applied.
|
|
|
|
REPORTER_ASSERT(r, exampleFillCaseKey != exampleInvFillCaseKey);
|
|
|
|
REPORTER_ASSERT(r, exampleFillCaseKey == exampleStrokeAndFillCaseKey);
|
|
|
|
REPORTER_ASSERT(r, exampleFillCaseKey != exampleInvStrokeAndFillCaseKey);
|
|
|
|
REPORTER_ASSERT(r, exampleFillCaseKey == exampleStrokeCaseKey);
|
2016-06-14 21:37:21 +00:00
|
|
|
REPORTER_ASSERT(r, exampleFillCaseKey != exampleInvStrokeCaseKey);
|
2016-06-10 15:05:14 +00:00
|
|
|
REPORTER_ASSERT(r, exampleFillCaseKey == exampleHairlineCaseKey);
|
2016-06-14 21:37:21 +00:00
|
|
|
REPORTER_ASSERT(r, exampleFillCaseKey != exampleInvHairlineCaseKey);
|
2016-06-10 15:05:14 +00:00
|
|
|
REPORTER_ASSERT(r, exampleInvStrokeAndFillCaseKey == exampleInvFillCaseKey);
|
2016-06-14 21:37:21 +00:00
|
|
|
REPORTER_ASSERT(r, exampleInvStrokeAndFillCaseKey == exampleInvStrokeCaseKey);
|
|
|
|
REPORTER_ASSERT(r, exampleInvStrokeAndFillCaseKey == exampleInvHairlineCaseKey);
|
2016-06-10 15:05:14 +00:00
|
|
|
|
2016-06-11 01:28:06 +00:00
|
|
|
for (bool inverted : {false, true}) {
|
|
|
|
for (SkPath::Direction dir : {SkPath::kCW_Direction, SkPath::kCCW_Direction}) {
|
|
|
|
for (unsigned start = 0; start < 8; ++start) {
|
|
|
|
for (bool dash : {false, true}) {
|
|
|
|
const GrShape& fillCase = shapes[index(inverted, dir, start, kFill, dash)];
|
2016-06-10 15:05:14 +00:00
|
|
|
Key fillCaseKey;
|
|
|
|
make_key(&fillCaseKey, fillCase);
|
|
|
|
|
2016-06-11 01:28:06 +00:00
|
|
|
const GrShape& strokeAndFillCase = shapes[index(inverted, dir, start,
|
|
|
|
kStrokeAndFill, dash)];
|
2016-06-10 15:05:14 +00:00
|
|
|
Key strokeAndFillCaseKey;
|
|
|
|
make_key(&strokeAndFillCaseKey, strokeAndFillCase);
|
|
|
|
|
|
|
|
// Both fill and stroke-and-fill shapes must respect the inverseness and both
|
|
|
|
// ignore dashing.
|
|
|
|
REPORTER_ASSERT(r, !fillCase.style().pathEffect());
|
|
|
|
REPORTER_ASSERT(r, !strokeAndFillCase.style().pathEffect());
|
|
|
|
TestCase a(fillCase, r);
|
|
|
|
TestCase b(inverted ? exampleInvFillCase : exampleFillCase, r);
|
|
|
|
TestCase c(strokeAndFillCase, r);
|
|
|
|
TestCase d(inverted ? exampleInvStrokeAndFillCase
|
|
|
|
: exampleStrokeAndFillCase, r);
|
|
|
|
a.compare(r, b, TestCase::kAllSame_ComparisonExpecation);
|
|
|
|
c.compare(r, d, TestCase::kAllSame_ComparisonExpecation);
|
|
|
|
|
2016-06-11 01:28:06 +00:00
|
|
|
const GrShape& strokeCase = shapes[index(inverted, dir, start, kStroke, dash)];
|
|
|
|
const GrShape& hairlineCase = shapes[index(inverted, dir, start, kHairline,
|
|
|
|
dash)];
|
2016-06-10 15:05:14 +00:00
|
|
|
|
|
|
|
TestCase e(strokeCase, r);
|
|
|
|
TestCase g(hairlineCase, r);
|
|
|
|
|
2016-06-14 21:37:21 +00:00
|
|
|
// Both hairline and stroke shapes must respect the dashing.
|
2016-06-10 15:05:14 +00:00
|
|
|
if (dash) {
|
2016-06-14 21:37:21 +00:00
|
|
|
// Dashing always ignores the inverseness. skbug.com/5421
|
|
|
|
TestCase f(exampleStrokeCase, r);
|
|
|
|
TestCase h(exampleHairlineCase, r);
|
2016-06-11 01:28:06 +00:00
|
|
|
unsigned expectedStart = canonicalize_rrect_start(start, rrect);
|
2016-06-10 15:05:14 +00:00
|
|
|
REPORTER_ASSERT(r, strokeCase.style().pathEffect());
|
|
|
|
REPORTER_ASSERT(r, hairlineCase.style().pathEffect());
|
|
|
|
|
2016-06-11 01:28:06 +00:00
|
|
|
REPORTER_ASSERT(r, strokeCase.asRRect(&queryRR, &queryDir, &queryStart,
|
|
|
|
&queryInverted));
|
|
|
|
REPORTER_ASSERT(r, queryRR == rrect);
|
|
|
|
REPORTER_ASSERT(r, queryDir == dir);
|
|
|
|
REPORTER_ASSERT(r, queryStart == expectedStart);
|
|
|
|
REPORTER_ASSERT(r, !queryInverted);
|
|
|
|
REPORTER_ASSERT(r, hairlineCase.asRRect(&queryRR, &queryDir, &queryStart,
|
|
|
|
&queryInverted));
|
|
|
|
REPORTER_ASSERT(r, queryRR == rrect);
|
|
|
|
REPORTER_ASSERT(r, queryDir == dir);
|
|
|
|
REPORTER_ASSERT(r, queryStart == expectedStart);
|
|
|
|
REPORTER_ASSERT(r, !queryInverted);
|
2016-06-10 15:05:14 +00:00
|
|
|
|
|
|
|
// The pre-style case for the dash will match the non-dash example iff the
|
|
|
|
// dir and start match (dir=cw, start=0).
|
2016-06-11 01:28:06 +00:00
|
|
|
if (0 == expectedStart && SkPath::kCW_Direction == dir) {
|
2016-06-10 15:05:14 +00:00
|
|
|
e.compare(r, f, TestCase::kSameUpToPE_ComparisonExpecation);
|
|
|
|
g.compare(r, h, TestCase::kSameUpToPE_ComparisonExpecation);
|
|
|
|
} else {
|
|
|
|
e.compare(r, f, TestCase::kAllDifferent_ComparisonExpecation);
|
|
|
|
g.compare(r, h, TestCase::kAllDifferent_ComparisonExpecation);
|
|
|
|
}
|
|
|
|
} else {
|
2016-06-14 21:37:21 +00:00
|
|
|
TestCase f(inverted ? exampleInvStrokeCase : exampleStrokeCase, r);
|
|
|
|
TestCase h(inverted ? exampleInvHairlineCase : exampleHairlineCase, r);
|
2016-06-10 15:05:14 +00:00
|
|
|
REPORTER_ASSERT(r, !strokeCase.style().pathEffect());
|
|
|
|
REPORTER_ASSERT(r, !hairlineCase.style().pathEffect());
|
|
|
|
e.compare(r, f, TestCase::kAllSame_ComparisonExpecation);
|
|
|
|
g.compare(r, h, TestCase::kAllSame_ComparisonExpecation);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-26 19:56:00 +00:00
|
|
|
DEF_TEST(GrShape, reporter) {
|
2016-06-06 21:01:25 +00:00
|
|
|
for (auto r : { SkRect::MakeWH(10, 20),
|
|
|
|
SkRect::MakeWH(-10, -20),
|
|
|
|
SkRect::MakeWH(-10, 20),
|
|
|
|
SkRect::MakeWH(10, -20)}) {
|
|
|
|
test_basic(reporter, r);
|
|
|
|
test_scale(reporter, r);
|
|
|
|
test_dash_fill(reporter, r);
|
|
|
|
test_null_dash(reporter, r);
|
|
|
|
// Test modifying various stroke params.
|
|
|
|
test_stroke_param<SkRect, SkScalar>(
|
|
|
|
reporter, r,
|
|
|
|
[](SkPaint* p, SkScalar w) { p->setStrokeWidth(w);},
|
|
|
|
SkIntToScalar(2), SkIntToScalar(4));
|
|
|
|
test_stroke_param<SkRect, SkPaint::Join>(
|
|
|
|
reporter, r,
|
|
|
|
[](SkPaint* p, SkPaint::Join j) { p->setStrokeJoin(j);},
|
|
|
|
SkPaint::kMiter_Join, SkPaint::kRound_Join);
|
|
|
|
test_stroke_cap(reporter, r);
|
|
|
|
test_miter_limit(reporter, r);
|
|
|
|
test_path_effect_makes_rrect(reporter, r);
|
|
|
|
test_unknown_path_effect(reporter, r);
|
|
|
|
test_path_effect_makes_empty_shape(reporter, r);
|
2016-06-07 19:20:15 +00:00
|
|
|
test_path_effect_fails(reporter, r);
|
2016-06-06 21:01:25 +00:00
|
|
|
test_make_hairline_path_effect(reporter, r, true);
|
2016-06-13 17:22:48 +00:00
|
|
|
GrShape shape(r);
|
|
|
|
REPORTER_ASSERT(reporter, !shape.asLine(nullptr));
|
2016-06-06 21:01:25 +00:00
|
|
|
}
|
2016-04-26 19:56:00 +00:00
|
|
|
|
|
|
|
for (auto rr : { SkRRect::MakeRect(SkRect::MakeWH(10, 10)),
|
2016-06-06 21:01:25 +00:00
|
|
|
SkRRect::MakeRectXY(SkRect::MakeWH(10, 10), 3, 4),
|
|
|
|
SkRRect::MakeOval(SkRect::MakeWH(20, 20))}) {
|
2016-04-26 19:56:00 +00:00
|
|
|
test_basic(reporter, rr);
|
2016-06-10 15:05:14 +00:00
|
|
|
test_rrect(reporter, rr);
|
2016-05-09 20:02:01 +00:00
|
|
|
test_scale(reporter, rr);
|
2016-04-26 19:56:00 +00:00
|
|
|
test_dash_fill(reporter, rr);
|
|
|
|
test_null_dash(reporter, rr);
|
|
|
|
// Test modifying various stroke params.
|
2016-04-27 13:46:23 +00:00
|
|
|
test_stroke_param<SkRRect, SkScalar>(
|
2016-04-26 19:56:00 +00:00
|
|
|
reporter, rr,
|
|
|
|
[](SkPaint* p, SkScalar w) { p->setStrokeWidth(w);},
|
|
|
|
SkIntToScalar(2), SkIntToScalar(4));
|
2016-04-27 13:46:23 +00:00
|
|
|
test_stroke_param<SkRRect, SkPaint::Join>(
|
2016-04-26 19:56:00 +00:00
|
|
|
reporter, rr,
|
|
|
|
[](SkPaint* p, SkPaint::Join j) { p->setStrokeJoin(j);},
|
|
|
|
SkPaint::kMiter_Join, SkPaint::kRound_Join);
|
2016-05-04 20:50:29 +00:00
|
|
|
test_stroke_cap(reporter, rr);
|
2016-04-26 19:56:00 +00:00
|
|
|
test_miter_limit(reporter, rr);
|
2016-04-27 13:46:23 +00:00
|
|
|
test_path_effect_makes_rrect(reporter, rr);
|
|
|
|
test_unknown_path_effect(reporter, rr);
|
2016-04-27 19:36:02 +00:00
|
|
|
test_path_effect_makes_empty_shape(reporter, rr);
|
2016-06-07 19:20:15 +00:00
|
|
|
test_path_effect_fails(reporter, rr);
|
2016-05-04 15:44:15 +00:00
|
|
|
test_make_hairline_path_effect(reporter, rr, true);
|
2016-06-13 17:22:48 +00:00
|
|
|
GrShape shape(rr);
|
|
|
|
REPORTER_ASSERT(reporter, !shape.asLine(nullptr));
|
2016-04-27 13:46:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct TestPath {
|
2016-06-13 17:22:48 +00:00
|
|
|
TestPath(const SkPath& path, bool isRRectFill, bool isRRectStroke, bool isLine, const SkRRect& rrect)
|
2016-04-27 13:46:23 +00:00
|
|
|
: fPath(path)
|
|
|
|
, fIsRRectForFill(isRRectFill)
|
|
|
|
, fIsRRectForStroke(isRRectStroke)
|
2016-06-13 17:22:48 +00:00
|
|
|
, fIsLine(isLine)
|
2016-04-27 13:46:23 +00:00
|
|
|
, fRRect(rrect) {}
|
|
|
|
SkPath fPath;
|
|
|
|
bool fIsRRectForFill;
|
|
|
|
bool fIsRRectForStroke;
|
2016-06-13 17:22:48 +00:00
|
|
|
bool fIsLine;
|
2016-04-27 13:46:23 +00:00
|
|
|
SkRRect fRRect;
|
|
|
|
};
|
|
|
|
SkTArray<TestPath> paths;
|
|
|
|
|
|
|
|
SkPath circlePath;
|
|
|
|
circlePath.addCircle(10, 10, 10);
|
2016-06-13 17:22:48 +00:00
|
|
|
paths.emplace_back(circlePath, true, true, false, SkRRect::MakeOval(SkRect::MakeWH(20,20)));
|
2016-04-27 13:46:23 +00:00
|
|
|
|
|
|
|
SkPath rectPath;
|
|
|
|
rectPath.addRect(SkRect::MakeWH(10, 10));
|
2016-06-13 17:22:48 +00:00
|
|
|
paths.emplace_back(rectPath, true, true, false, SkRRect::MakeRect(SkRect::MakeWH(10, 10)));
|
2016-04-27 13:46:23 +00:00
|
|
|
|
|
|
|
SkPath openRectPath;
|
|
|
|
openRectPath.moveTo(0, 0);
|
|
|
|
openRectPath.lineTo(10, 0);
|
|
|
|
openRectPath.lineTo(10, 10);
|
|
|
|
openRectPath.lineTo(0, 10);
|
2016-06-13 17:22:48 +00:00
|
|
|
paths.emplace_back(openRectPath, true, false, false, SkRRect::MakeRect(SkRect::MakeWH(10, 10)));
|
2016-04-27 13:46:23 +00:00
|
|
|
|
|
|
|
SkPath quadPath;
|
|
|
|
quadPath.quadTo(10, 10, 5, 8);
|
2016-06-13 17:22:48 +00:00
|
|
|
paths.emplace_back(quadPath, false, false, false, SkRRect());
|
|
|
|
|
|
|
|
SkPath linePath;
|
|
|
|
linePath.lineTo(10, 10);
|
|
|
|
paths.emplace_back(linePath, false, false, true, SkRRect());
|
2016-04-27 13:46:23 +00:00
|
|
|
|
|
|
|
for (auto testPath : paths) {
|
2016-06-10 15:05:14 +00:00
|
|
|
for (bool inverseFill : {false, true}) {
|
|
|
|
if (inverseFill) {
|
|
|
|
if (testPath.fPath.getFillType() == SkPath::kEvenOdd_FillType) {
|
|
|
|
testPath.fPath.setFillType(SkPath::kInverseEvenOdd_FillType);
|
|
|
|
} else {
|
|
|
|
SkASSERT(testPath.fPath.getFillType() == SkPath::kWinding_FillType);
|
|
|
|
testPath.fPath.setFillType(SkPath::kInverseWinding_FillType);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const SkPath& path = testPath.fPath;
|
|
|
|
// These tests all assume that the original GrShape for fill and stroke will be the
|
|
|
|
// same.
|
|
|
|
// However, that is not the case in special cases (e.g. an unclosed rect becomes a RRect
|
|
|
|
// GrShape with a fill style but becomes a Path GrShape when stroked).
|
|
|
|
if (testPath.fIsRRectForFill == testPath.fIsRRectForStroke) {
|
|
|
|
test_basic(reporter, path);
|
|
|
|
test_null_dash(reporter, path);
|
|
|
|
test_path_effect_makes_rrect(reporter, path);
|
|
|
|
}
|
|
|
|
test_scale(reporter, path);
|
|
|
|
// This test uses a stroking paint, hence use of fIsRRectForStroke
|
|
|
|
test_volatile_path(reporter, path, testPath.fIsRRectForStroke);
|
|
|
|
test_dash_fill(reporter, path);
|
|
|
|
// Test modifying various stroke params.
|
|
|
|
test_stroke_param<SkPath, SkScalar>(
|
|
|
|
reporter, path,
|
|
|
|
[](SkPaint* p, SkScalar w) { p->setStrokeWidth(w);},
|
|
|
|
SkIntToScalar(2), SkIntToScalar(4));
|
|
|
|
test_stroke_param<SkPath, SkPaint::Join>(
|
|
|
|
reporter, path,
|
|
|
|
[](SkPaint* p, SkPaint::Join j) { p->setStrokeJoin(j);},
|
|
|
|
SkPaint::kMiter_Join, SkPaint::kRound_Join);
|
|
|
|
test_stroke_cap(reporter, path);
|
|
|
|
test_miter_limit(reporter, path);
|
|
|
|
test_unknown_path_effect(reporter, path);
|
|
|
|
test_path_effect_makes_empty_shape(reporter, path);
|
|
|
|
test_path_effect_fails(reporter, path);
|
|
|
|
test_make_hairline_path_effect(reporter, path, testPath.fIsRRectForStroke);
|
2016-04-27 13:46:23 +00:00
|
|
|
}
|
2016-06-10 15:05:14 +00:00
|
|
|
}
|
2016-06-14 21:37:21 +00:00
|
|
|
|
2016-06-10 15:05:14 +00:00
|
|
|
for (auto testPath : paths) {
|
|
|
|
const SkPath& path = testPath.fPath;
|
2016-04-27 13:46:23 +00:00
|
|
|
|
|
|
|
SkPaint fillPaint;
|
2016-05-04 15:27:41 +00:00
|
|
|
TestCase fillPathCase(path, fillPaint, reporter);
|
2016-04-27 13:46:23 +00:00
|
|
|
SkRRect rrect;
|
|
|
|
REPORTER_ASSERT(reporter, testPath.fIsRRectForFill ==
|
2016-06-10 15:05:14 +00:00
|
|
|
fillPathCase.baseShape().asRRect(&rrect, nullptr, nullptr,
|
|
|
|
nullptr));
|
2016-04-27 13:46:23 +00:00
|
|
|
if (testPath.fIsRRectForFill) {
|
2016-06-10 15:05:14 +00:00
|
|
|
TestCase fillPathCase2(testPath.fPath, fillPaint, reporter);
|
2016-04-27 13:46:23 +00:00
|
|
|
REPORTER_ASSERT(reporter, rrect == testPath.fRRect);
|
2016-05-04 15:27:41 +00:00
|
|
|
TestCase fillRRectCase(rrect, fillPaint, reporter);
|
2016-06-10 15:05:14 +00:00
|
|
|
fillPathCase2.compare(reporter, fillRRectCase,
|
|
|
|
TestCase::kAllSame_ComparisonExpecation);
|
2016-04-27 13:46:23 +00:00
|
|
|
}
|
|
|
|
SkPaint strokePaint;
|
|
|
|
strokePaint.setStrokeWidth(3.f);
|
|
|
|
strokePaint.setStyle(SkPaint::kStroke_Style);
|
2016-05-04 15:27:41 +00:00
|
|
|
TestCase strokePathCase(path, strokePaint, reporter);
|
2016-04-27 13:46:23 +00:00
|
|
|
REPORTER_ASSERT(reporter, testPath.fIsRRectForStroke ==
|
2016-06-10 15:05:14 +00:00
|
|
|
strokePathCase.baseShape().asRRect(&rrect, nullptr, nullptr,
|
|
|
|
nullptr));
|
2016-04-27 13:46:23 +00:00
|
|
|
if (testPath.fIsRRectForStroke) {
|
|
|
|
REPORTER_ASSERT(reporter, rrect == testPath.fRRect);
|
2016-05-04 15:27:41 +00:00
|
|
|
TestCase strokeRRectCase(rrect, strokePaint, reporter);
|
2016-04-27 13:46:23 +00:00
|
|
|
strokePathCase.compare(reporter, strokeRRectCase,
|
2016-06-06 21:01:25 +00:00
|
|
|
TestCase::kAllSame_ComparisonExpecation);
|
2016-04-27 13:46:23 +00:00
|
|
|
}
|
2016-06-13 17:22:48 +00:00
|
|
|
REPORTER_ASSERT(reporter, testPath.fIsLine == fillPathCase.baseShape().asLine(nullptr));
|
|
|
|
REPORTER_ASSERT(reporter, testPath.fIsLine == strokePathCase.baseShape().asLine(nullptr));
|
2016-04-26 19:56:00 +00:00
|
|
|
}
|
2016-04-27 19:36:02 +00:00
|
|
|
|
2016-04-27 20:30:25 +00:00
|
|
|
// Test a volatile empty path.
|
|
|
|
test_volatile_path(reporter, SkPath(), true);
|
|
|
|
|
2016-04-27 19:36:02 +00:00
|
|
|
test_empty_shape(reporter);
|
2016-04-26 19:56:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|