2015-04-28 20:31:18 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2015 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef GrTestUtils_DEFINED
|
|
|
|
#define GrTestUtils_DEFINED
|
|
|
|
|
2015-04-29 17:01:22 +00:00
|
|
|
#include "SkTypes.h"
|
|
|
|
|
|
|
|
#ifdef GR_TEST_UTILS
|
|
|
|
|
2015-04-28 20:31:18 +00:00
|
|
|
#include "GrColor.h"
|
2016-05-10 16:14:17 +00:00
|
|
|
#include "SkPathEffect.h"
|
2015-04-28 20:31:18 +00:00
|
|
|
#include "SkRandom.h"
|
2015-05-11 14:21:37 +00:00
|
|
|
#include "SkStrokeRec.h"
|
2016-05-10 16:14:17 +00:00
|
|
|
#include "../private/SkTemplates.h"
|
2015-04-28 20:31:18 +00:00
|
|
|
|
2016-05-10 16:14:17 +00:00
|
|
|
class GrStyle;
|
2015-04-28 20:31:18 +00:00
|
|
|
class SkMatrix;
|
2015-05-02 14:07:17 +00:00
|
|
|
class SkPath;
|
2015-04-30 20:49:27 +00:00
|
|
|
class SkRRect;
|
2015-04-29 17:01:22 +00:00
|
|
|
struct SkRect;
|
2015-04-28 20:31:18 +00:00
|
|
|
|
|
|
|
namespace GrTest {
|
|
|
|
/**
|
2016-05-10 16:14:17 +00:00
|
|
|
* Helpers for use in Test functions.
|
2015-04-28 20:31:18 +00:00
|
|
|
*/
|
|
|
|
const SkMatrix& TestMatrix(SkRandom*);
|
2015-04-29 18:32:05 +00:00
|
|
|
const SkMatrix& TestMatrixPreservesRightAngles(SkRandom*);
|
2015-04-30 20:49:27 +00:00
|
|
|
const SkMatrix& TestMatrixRectStaysRect(SkRandom*);
|
2015-05-07 20:06:41 +00:00
|
|
|
const SkMatrix& TestMatrixInvertible(SkRandom*);
|
2015-04-29 17:01:22 +00:00
|
|
|
const SkRect& TestRect(SkRandom*);
|
2015-05-13 15:51:49 +00:00
|
|
|
const SkRect& TestSquare(SkRandom*);
|
2015-04-30 20:49:27 +00:00
|
|
|
const SkRRect& TestRRectSimple(SkRandom*);
|
2015-05-02 14:07:17 +00:00
|
|
|
const SkPath& TestPath(SkRandom*);
|
2015-05-11 15:58:52 +00:00
|
|
|
const SkPath& TestPathConvex(SkRandom*);
|
2015-05-11 14:21:37 +00:00
|
|
|
SkStrokeRec TestStrokeRec(SkRandom*);
|
2016-05-10 16:14:17 +00:00
|
|
|
/** Creates styles with dash path effects and null path effects */
|
|
|
|
void TestStyle(SkRandom*, GrStyle*);
|
2015-04-28 20:31:18 +00:00
|
|
|
|
2016-05-10 16:14:17 +00:00
|
|
|
// We have a simplified dash path effect here to avoid relying on SkDashPathEffect which
|
|
|
|
// is in the optional build target effects.
|
|
|
|
class TestDashPathEffect : public SkPathEffect {
|
|
|
|
public:
|
|
|
|
static sk_sp<SkPathEffect> Make(const SkScalar* intervals, int count, SkScalar phase) {
|
|
|
|
return sk_sp<SkPathEffect>(new TestDashPathEffect(intervals, count, phase));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool filterPath(SkPath* dst, const SkPath&, SkStrokeRec* , const SkRect*) const override;
|
|
|
|
DashType asADash(DashInfo* info) const override;
|
|
|
|
Factory getFactory() const override { return nullptr; }
|
|
|
|
void toString(SkString*) const override {}
|
|
|
|
|
|
|
|
private:
|
|
|
|
TestDashPathEffect(const SkScalar* intervals, int count, SkScalar phase);
|
|
|
|
|
|
|
|
int fCount;
|
|
|
|
SkAutoTArray<SkScalar> fIntervals;
|
|
|
|
SkScalar fPhase;
|
|
|
|
SkScalar fInitialDashLength;
|
|
|
|
int fInitialDashIndex;
|
|
|
|
SkScalar fIntervalLength;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace GrTest
|
2015-04-28 20:31:18 +00:00
|
|
|
|
|
|
|
static inline GrColor GrRandomColor(SkRandom* random) {
|
|
|
|
// There are only a few cases of random colors which interest us
|
|
|
|
enum ColorMode {
|
|
|
|
kAllOnes_ColorMode,
|
|
|
|
kAllZeros_ColorMode,
|
|
|
|
kAlphaOne_ColorMode,
|
|
|
|
kRandom_ColorMode,
|
|
|
|
kLast_ColorMode = kRandom_ColorMode
|
|
|
|
};
|
|
|
|
|
|
|
|
ColorMode colorMode = ColorMode(random->nextULessThan(kLast_ColorMode + 1));
|
2016-04-07 16:01:20 +00:00
|
|
|
GrColor color SK_INIT_TO_AVOID_WARNING;
|
2015-04-28 20:31:18 +00:00
|
|
|
switch (colorMode) {
|
|
|
|
case kAllOnes_ColorMode:
|
|
|
|
color = GrColorPackRGBA(0xFF, 0xFF, 0xFF, 0xFF);
|
|
|
|
break;
|
|
|
|
case kAllZeros_ColorMode:
|
|
|
|
color = GrColorPackRGBA(0, 0, 0, 0);
|
|
|
|
break;
|
|
|
|
case kAlphaOne_ColorMode:
|
|
|
|
color = GrColorPackRGBA(random->nextULessThan(256),
|
|
|
|
random->nextULessThan(256),
|
|
|
|
random->nextULessThan(256),
|
|
|
|
0xFF);
|
|
|
|
break;
|
2015-04-29 17:01:22 +00:00
|
|
|
case kRandom_ColorMode: {
|
|
|
|
uint8_t alpha = random->nextULessThan(256);
|
|
|
|
color = GrColorPackRGBA(random->nextRangeU(0, alpha),
|
|
|
|
random->nextRangeU(0, alpha),
|
|
|
|
random->nextRangeU(0, alpha),
|
|
|
|
alpha);
|
2015-04-28 20:31:18 +00:00
|
|
|
break;
|
2015-04-29 17:01:22 +00:00
|
|
|
}
|
2015-04-28 20:31:18 +00:00
|
|
|
}
|
|
|
|
GrColorIsPMAssert(color);
|
|
|
|
return color;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint8_t GrRandomCoverage(SkRandom* random) {
|
|
|
|
enum CoverageMode {
|
|
|
|
kZero_CoverageMode,
|
|
|
|
kAllOnes_CoverageMode,
|
|
|
|
kRandom_CoverageMode,
|
|
|
|
kLast_CoverageMode = kRandom_CoverageMode
|
|
|
|
};
|
|
|
|
|
|
|
|
CoverageMode colorMode = CoverageMode(random->nextULessThan(kLast_CoverageMode + 1));
|
2016-04-07 16:01:20 +00:00
|
|
|
uint8_t coverage SK_INIT_TO_AVOID_WARNING;
|
2015-04-28 20:31:18 +00:00
|
|
|
switch (colorMode) {
|
|
|
|
case kZero_CoverageMode:
|
|
|
|
coverage = 0;
|
2016-01-05 08:35:50 +00:00
|
|
|
break;
|
2015-04-28 20:31:18 +00:00
|
|
|
case kAllOnes_CoverageMode:
|
|
|
|
coverage = 0xff;
|
|
|
|
break;
|
|
|
|
case kRandom_CoverageMode:
|
|
|
|
coverage = random->nextULessThan(256);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return coverage;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
2015-04-29 17:01:22 +00:00
|
|
|
#endif
|