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

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

Issue 1117443002: create GrTestUtils.h, move some common functions into it (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 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 | « include/gpu/GrProcessorUnitTest.h ('k') | src/effects/SkPerlinNoiseShader.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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 "GrColor.h"
12 #include "SkRandom.h"
13
14 class SkMatrix;
15
16 namespace GrTest {
17 /**
18 * A helper for use in Test functions.
19 */
20 const SkMatrix& TestMatrix(SkRandom*);
21
22 }
23
24 static inline GrColor GrRandomColor(SkRandom* random) {
25 // There are only a few cases of random colors which interest us
26 enum ColorMode {
27 kAllOnes_ColorMode,
28 kAllZeros_ColorMode,
29 kAlphaOne_ColorMode,
30 kRandom_ColorMode,
31 kLast_ColorMode = kRandom_ColorMode
32 };
33
34 ColorMode colorMode = ColorMode(random->nextULessThan(kLast_ColorMode + 1));
35 GrColor color;
36 switch (colorMode) {
37 case kAllOnes_ColorMode:
38 color = GrColorPackRGBA(0xFF, 0xFF, 0xFF, 0xFF);
39 break;
40 case kAllZeros_ColorMode:
41 color = GrColorPackRGBA(0, 0, 0, 0);
42 break;
43 case kAlphaOne_ColorMode:
44 color = GrColorPackRGBA(random->nextULessThan(256),
45 random->nextULessThan(256),
46 random->nextULessThan(256),
47 0xFF);
48 break;
49 case kRandom_ColorMode:
50 uint8_t alpha = random->nextULessThan(256);
51 color = GrColorPackRGBA(random->nextRangeU(0, alpha),
52 random->nextRangeU(0, alpha),
53 random->nextRangeU(0, alpha),
54 alpha);
55 break;
56 }
57 GrColorIsPMAssert(color);
58 return color;
59 }
60
61 static inline uint8_t GrRandomCoverage(SkRandom* random) {
62 enum CoverageMode {
63 kZero_CoverageMode,
64 kAllOnes_CoverageMode,
65 kRandom_CoverageMode,
66 kLast_CoverageMode = kRandom_CoverageMode
67 };
68
69 CoverageMode colorMode = CoverageMode(random->nextULessThan(kLast_CoverageMo de + 1));
70 uint8_t coverage;
71 switch (colorMode) {
72 case kZero_CoverageMode:
73 coverage = 0;
74 case kAllOnes_CoverageMode:
75 coverage = 0xff;
76 break;
77 case kRandom_CoverageMode:
78 coverage = random->nextULessThan(256);
79 break;
80 }
81 return coverage;
82 }
83
84 #endif
OLDNEW
« no previous file with comments | « include/gpu/GrProcessorUnitTest.h ('k') | src/effects/SkPerlinNoiseShader.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698