| 1 |
/* |
| 2 |
* Copyright 2015 Google Inc. |
| 3 |
* |
| 4 |
* Use of this source code is governed by a BSD-style license that can be |
| 5 |
* found in the LICENSE file. |
| 6 |
*/ |
| 7 |
|
| 8 |
#ifndef GrTestUtils_DEFINED |
| 9 |
#define GrTestUtils_DEFINED |
| 10 |
|
| 11 |
#include "include/core/SkTypes.h" |
| 12 |
|
| 13 |
#if defined(GPU_TEST_UTILS) |
| 14 |
|
| 15 |
#include "include/core/SkPathEffect.h" |
| 16 |
#include "include/core/SkRefCnt.h" |
| 17 |
#include "include/core/SkScalar.h" |
| 18 |
#include "include/core/SkSpan.h" |
| 19 |
#include "include/core/SkStrokeRec.h" |
| 20 |
#include "include/core/SkSurfaceProps.h" |
| 21 |
#include "include/core/SkTypes.h" |
| 22 |
#include "include/private/base/SkTemplates.h" |
| 23 |
#include "src/core/SkPathEffectBase.h" |
| 24 |
#include "src/gpu/ganesh/GrColor.h" |
| 25 |
#include "src/gpu/ganesh/GrFPArgs.h" |
| 26 |
#include "src/gpu/ganesh/GrSamplerState.h" |
| 27 |
|
| 28 |
#include <cstddef> |
| 29 |
#include <cstdint> |
| 30 |
#include <memory> |
| 31 |
#include <optional> |
| 32 |
|
| 33 |
class GrColorInfo; |
| 34 |
class GrColorSpaceXform; |
| 35 |
class GrProcessorTestData; |
| 36 |
class GrStyle; |
| 37 |
class SkColorSpace; |
| 38 |
class SkMatrix; |
| 39 |
class SkPath; |
| 40 |
class SkPathBuilder; |
| 41 |
class SkRRect; |
| 42 |
class SkRandom; |
| 43 |
struct SkRect; |
| 44 |
|
| 45 |
namespace GrTest { |
| 46 |
/** |
| 47 |
* Helpers for use in Test functions. |
| 48 |
*/ |
| 49 |
const SkMatrix& TestMatrix(SkRandom*); |
| 50 |
const SkMatrix& TestMatrixPreservesRightAngles(SkRandom*); |
| 51 |
const SkMatrix& TestMatrixRectStaysRect(SkRandom*); |
| 52 |
const SkMatrix& TestMatrixInvertible(SkRandom*); |
| 53 |
const SkMatrix& TestMatrixPerspective(SkRandom*); |
| 54 |
void TestWrapModes(SkRandom*, GrSamplerState::WrapMode[2]); |
| 55 |
const SkRect& TestRect(SkRandom*); |
| 56 |
const SkRect& TestSquare(SkRandom*); |
| 57 |
const SkRRect& TestRRectSimple(SkRandom*); |
| 58 |
const SkPath& TestPath(SkRandom*); |
| 59 |
const SkPath& TestPathConvex(SkRandom*); |
| 60 |
SkStrokeRec TestStrokeRec(SkRandom*); |
| 61 |
/** Creates styles with dash path effects and null path effects */ |
| 62 |
void TestStyle(SkRandom*, GrStyle*); |
| 63 |
sk_sp<SkColorSpace> TestColorSpace(SkRandom*); |
| 64 |
sk_sp<GrColorSpaceXform> TestColorXform(SkRandom*); |
| 65 |
|
| 66 |
GrColor RandomColor(SkRandom* random); |
| 67 |
uint8_t RandomCoverage(SkRandom* random); |
| 68 |
|
| 69 |
class TestAsFPArgs { |
| 70 |
public: |
| 71 |
TestAsFPArgs(GrProcessorTestData*); |
| 72 |
~TestAsFPArgs(); |
| 73 |
const GrFPArgs& args() const { return fArgs; } |
| 74 |
|
| 75 |
private: |
| 76 |
std::unique_ptr<GrColorInfo> fColorInfoStorage; |
| 77 |
SkSurfaceProps fSurfaceProps; |
| 78 |
GrFPArgs fArgs; |
| 79 |
}; |
| 80 |
|
| 81 |
// We have a simplified dash path effect here to avoid relying on SkDashPathEffect which |
| 82 |
// is in the optional build target effects. |
| 83 |
class TestDashPathEffect : public SkPathEffectBase { |
| 84 |
public: |
| 85 |
static sk_sp<SkPathEffect> Make(SkSpan<const SkScalar> intervals, SkScalar phase) { |
| 86 |
return sk_sp<SkPathEffect>(new TestDashPathEffect(intervals, phase)); |
| 87 |
} |
| 88 |
|
| 89 |
Factory getFactory() const override { return nullptr; } |
| 90 |
const char* getTypeName() const override { return nullptr; } |
| 91 |
|
| 92 |
protected: |
| 93 |
bool onFilterPath(SkPathBuilder* dst, const SkPath&, SkStrokeRec* , const SkRect*, |
| 94 |
const SkMatrix&) const override; |
| 95 |
std::optional<DashInfo> asADash() const override; |
| 96 |
|
| 97 |
private: |
| 98 |
TestDashPathEffect(SkSpan<const SkScalar> intervals, SkScalar phase); |
| 99 |
|
| 100 |
bool computeFastBounds(SkRect* bounds) const override { return true; } |
| 101 |
|
| 102 |
skia_private::AutoTArray<SkScalar> fIntervals; |
| 103 |
SkScalar fPhase; |
| 104 |
SkScalar fInitialDashLength; |
| 105 |
size_t fInitialDashIndex; |
| 106 |
SkScalar fIntervalLength; |
| 107 |
}; |
| 108 |
|
| 109 |
} // namespace GrTest |
| 110 |
|
| 111 |
#endif |
| 112 |
#endif |