Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(297)

Side by Side Diff: include/gpu/GrTestUtils.h

Issue 1957363002: Replace GrStrokeInfo with GrStyle. (Closed) Base URL: https://chromium.googlesource.com/skia.git@resscale
Patch Set: Remove dependency on SkDashPathEffect from GrDashingEffect.cpp Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #ifndef GrTestUtils_DEFINED 8 #ifndef GrTestUtils_DEFINED
9 #define GrTestUtils_DEFINED 9 #define GrTestUtils_DEFINED
10 10
11 #include "SkTypes.h" 11 #include "SkTypes.h"
12 12
13 #ifdef GR_TEST_UTILS 13 #ifdef GR_TEST_UTILS
14 14
15 #include "GrColor.h" 15 #include "GrColor.h"
16 #include "SkDashPathPriv.h"
17 #include "SkPathEffect.h"
16 #include "SkRandom.h" 18 #include "SkRandom.h"
17 #include "SkStrokeRec.h" 19 #include "SkStrokeRec.h"
20 #include "SkTemplates.h"
18 21
19 class GrStrokeInfo; 22 class GrStyle;
20 class SkMatrix; 23 class SkMatrix;
21 class SkPath; 24 class SkPath;
22 class SkRRect; 25 class SkRRect;
23 struct SkRect; 26 struct SkRect;
24 27
25 namespace GrTest { 28 namespace GrTest {
26 /** 29 /**
27 * A helper for use in Test functions. 30 * Helpers for use in Test functions.
28 */ 31 */
29 const SkMatrix& TestMatrix(SkRandom*); 32 const SkMatrix& TestMatrix(SkRandom*);
30 const SkMatrix& TestMatrixPreservesRightAngles(SkRandom*); 33 const SkMatrix& TestMatrixPreservesRightAngles(SkRandom*);
31 const SkMatrix& TestMatrixRectStaysRect(SkRandom*); 34 const SkMatrix& TestMatrixRectStaysRect(SkRandom*);
32 const SkMatrix& TestMatrixInvertible(SkRandom*); 35 const SkMatrix& TestMatrixInvertible(SkRandom*);
33 const SkRect& TestRect(SkRandom*); 36 const SkRect& TestRect(SkRandom*);
34 const SkRect& TestSquare(SkRandom*); 37 const SkRect& TestSquare(SkRandom*);
35 const SkRRect& TestRRectSimple(SkRandom*); 38 const SkRRect& TestRRectSimple(SkRandom*);
36 const SkPath& TestPath(SkRandom*); 39 const SkPath& TestPath(SkRandom*);
37 const SkPath& TestPathConvex(SkRandom*); 40 const SkPath& TestPathConvex(SkRandom*);
38 SkStrokeRec TestStrokeRec(SkRandom*); 41 SkStrokeRec TestStrokeRec(SkRandom*);
39 GrStrokeInfo TestStrokeInfo(SkRandom*); 42 /** Creates styles with dash path effects and null path effects */
43 void TestStyle(SkRandom*, GrStyle*);
40 44
robertphillips 2016/05/09 20:05:28 Can this class go in the .cpp file ?
bsalomon 2016/05/09 20:38:55 It's also used by GrDashingEffect's test function.
41 } 45 // We have a simplified dash path effect here to avoid relying on SkDashPathEffe ct which
46 // is in the optional build target effects.
47 class TestDashPathEffect : public SkPathEffect {
48 public:
49 static sk_sp<SkPathEffect> Make(const SkScalar* intervals, int count, SkScal ar phase) {
50 return sk_sp<SkPathEffect>(new TestDashPathEffect(intervals, count, phas e));
51 }
52
53 bool filterPath(SkPath* dst, const SkPath& src, SkStrokeRec* rec,
54 const SkRect* cullRect) const override {
55 return SkDashPath::InternalFilter(dst, src, rec, cullRect, fIntervals.ge t(), fCount,
56 fInitialDashLength, fInitialDashIndex, fIntervalLength);
57 }
58
59 DashType asADash(DashInfo* info) const override {
60 if (info) {
61 if (info->fCount >= fCount && info->fIntervals) {
62 memcpy(info->fIntervals, fIntervals.get(), fCount * sizeof(SkSca lar));
63 }
64 info->fCount = fCount;
65 info->fPhase = fPhase;
66 }
67 return kDash_DashType;
68 }
69
70 Factory getFactory() const override { return nullptr; }
71 void toString(SkString*) const override {}
72
73 private:
74 TestDashPathEffect(const SkScalar* intervals, int count, SkScalar phase) {
75 fCount = count;
76 fIntervals.reset(count);
77 memcpy(fIntervals.get(), intervals, count * sizeof(SkScalar));
78 SkDashPath::CalcDashParameters(phase, intervals, count, &fInitialDashLen gth,
79 &fInitialDashIndex, &fIntervalLength, &fP hase);
80 }
81
82 int fCount;
83 SkAutoTArray<SkScalar> fIntervals;
84 SkScalar fPhase;
85 SkScalar fInitialDashLength;
86 int fInitialDashIndex;
87 SkScalar fIntervalLength;
88 };
89
90 } // namespace GrTest
42 91
43 static inline GrColor GrRandomColor(SkRandom* random) { 92 static inline GrColor GrRandomColor(SkRandom* random) {
44 // There are only a few cases of random colors which interest us 93 // There are only a few cases of random colors which interest us
45 enum ColorMode { 94 enum ColorMode {
46 kAllOnes_ColorMode, 95 kAllOnes_ColorMode,
47 kAllZeros_ColorMode, 96 kAllZeros_ColorMode,
48 kAlphaOne_ColorMode, 97 kAlphaOne_ColorMode,
49 kRandom_ColorMode, 98 kRandom_ColorMode,
50 kLast_ColorMode = kRandom_ColorMode 99 kLast_ColorMode = kRandom_ColorMode
51 }; 100 };
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 break; 146 break;
98 case kRandom_CoverageMode: 147 case kRandom_CoverageMode:
99 coverage = random->nextULessThan(256); 148 coverage = random->nextULessThan(256);
100 break; 149 break;
101 } 150 }
102 return coverage; 151 return coverage;
103 } 152 }
104 153
105 #endif 154 #endif
106 #endif 155 #endif
OLDNEW
« no previous file with comments | « include/gpu/GrDrawContext.h ('k') | src/gpu/GrBlurUtils.h » ('j') | src/gpu/GrBlurUtils.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698