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

Side by Side Diff: src/gpu/GrTestUtils.cpp

Issue 1967513002: Revert of Replace GrStrokeInfo with GrStyle. (Closed) Base URL: https://chromium.googlesource.com/skia.git@resscale
Patch Set: 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
« no previous file with comments | « src/gpu/GrStyle.h ('k') | src/gpu/SkGpuDevice.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "GrStrokeInfo.h"
8 #include "GrTestUtils.h" 9 #include "GrTestUtils.h"
9 #include "GrStyle.h"
10 #include "SkDashPathPriv.h"
11 #include "SkMatrix.h" 10 #include "SkMatrix.h"
11 #include "SkPathEffect.h"
12 #include "SkPath.h" 12 #include "SkPath.h"
13 #include "SkRRect.h" 13 #include "SkRRect.h"
14 14
15 #ifdef GR_TEST_UTILS 15 #ifdef GR_TEST_UTILS
16 16
17 static const SkMatrix& test_matrix(SkRandom* random, bool includePerspective) { 17 static const SkMatrix& test_matrix(SkRandom* random, bool includePerspective) {
18 static SkMatrix gMatrices[5]; 18 static SkMatrix gMatrices[5];
19 static const int kPerspectiveCount = 1; 19 static const int kPerspectiveCount = 1;
20 static bool gOnce; 20 static bool gOnce;
21 if (!gOnce) { 21 if (!gOnce) {
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 } 230 }
231 231
232 SkStrokeRec TestStrokeRec(SkRandom* random) { 232 SkStrokeRec TestStrokeRec(SkRandom* random) {
233 SkStrokeRec::InitStyle style = 233 SkStrokeRec::InitStyle style =
234 SkStrokeRec::InitStyle(random->nextULessThan(SkStrokeRec::kFill_Init Style + 1)); 234 SkStrokeRec::InitStyle(random->nextULessThan(SkStrokeRec::kFill_Init Style + 1));
235 SkStrokeRec rec(style); 235 SkStrokeRec rec(style);
236 randomize_stroke_rec(&rec, random); 236 randomize_stroke_rec(&rec, random);
237 return rec; 237 return rec;
238 } 238 }
239 239
240 void TestStyle(SkRandom* random, GrStyle* style) { 240 GrStrokeInfo TestStrokeInfo(SkRandom* random) {
241 SkStrokeRec::InitStyle initStyle = 241 SkStrokeRec::InitStyle style =
242 SkStrokeRec::InitStyle(random->nextULessThan(SkStrokeRec::kFill_Init Style + 1)); 242 SkStrokeRec::InitStyle(random->nextULessThan(SkStrokeRec::kFill_Init Style + 1));
243 SkStrokeRec stroke(initStyle); 243 GrStrokeInfo strokeInfo(style);
244 randomize_stroke_rec(&stroke, random); 244 randomize_stroke_rec(&strokeInfo, random);
245 sk_sp<SkPathEffect> pe; 245 SkPathEffect::DashInfo dashInfo;
246 if (random->nextBool()) { 246 dashInfo.fCount = random->nextRangeU(1, 50) * 2;
247 int cnt = random->nextRangeU(1, 50) * 2; 247 dashInfo.fIntervals = new SkScalar[dashInfo.fCount];
248 SkAutoTDeleteArray<SkScalar> intervals(new SkScalar[cnt]); 248 SkScalar sum = 0;
249 SkScalar sum = 0; 249 for (int i = 0; i < dashInfo.fCount; i++) {
250 for (int i = 0; i < cnt; i++) { 250 dashInfo.fIntervals[i] = random->nextRangeScalar(SkDoubleToScalar(0.01),
251 intervals[i] = random->nextRangeScalar(SkDoubleToScalar(0.01), 251 SkDoubleToScalar(10.0)) ;
252 SkDoubleToScalar(10.0)); 252 sum += dashInfo.fIntervals[i];
253 sum += intervals[i];
254 }
255 SkScalar phase = random->nextRangeScalar(0, sum);
256 pe = TestDashPathEffect::Make(intervals.get(), cnt, phase);
257 } 253 }
258 *style = GrStyle(stroke, pe.get()); 254 dashInfo.fPhase = random->nextRangeScalar(0, sum);
255 strokeInfo.setDashInfo(dashInfo);
256 delete[] dashInfo.fIntervals;
257 return strokeInfo;
259 } 258 }
260 259
261 TestDashPathEffect::TestDashPathEffect(const SkScalar* intervals, int count, SkS calar phase) { 260 };
262 fCount = count;
263 fIntervals.reset(count);
264 memcpy(fIntervals.get(), intervals, count * sizeof(SkScalar));
265 SkDashPath::CalcDashParameters(phase, intervals, count, &fInitialDashLength,
266 &fInitialDashIndex, &fIntervalLength, &fPhase );
267 }
268
269 bool TestDashPathEffect::filterPath(SkPath* dst, const SkPath& src, SkStroke Rec* rec,
270 const SkRect* cullRect) const {
271 return SkDashPath::InternalFilter(dst, src, rec, cullRect, fIntervals.get(), fCount,
272 fInitialDashLength, fInitialDashIndex, fIn tervalLength);
273 }
274
275 SkPathEffect::DashType TestDashPathEffect::asADash(DashInfo* info) const {
276 if (info) {
277 if (info->fCount >= fCount && info->fIntervals) {
278 memcpy(info->fIntervals, fIntervals.get(), fCount * sizeof(SkScalar) );
279 }
280 info->fCount = fCount;
281 info->fPhase = fPhase;
282 }
283 return kDash_DashType;
284 }
285
286
287 } // namespace GrTest
288 261
289 #endif 262 #endif
OLDNEW
« no previous file with comments | « src/gpu/GrStyle.h ('k') | src/gpu/SkGpuDevice.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698