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

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

Issue 1109153004: Initial CL to create GrBatchTest infrastructure (Closed) Base URL: https://skia.googlesource.com/skia.git@rand-batch0
Patch Set: rebase onto master 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 | « gyp/gpu.gypi ('k') | src/gpu/GrAARectRenderer.h » ('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 class SkRect;
16
17 namespace GrTest {
18 /**
19 * A helper for use in Test functions.
20 */
21 const SkMatrix& TestMatrix(SkRandom*);
22 const SkRect& TestRect(SkRandom*);
23
24 }
25
26 static inline GrColor GrRandomColor(SkRandom* random) {
27 // There are only a few cases of random colors which interest us
28 enum ColorMode {
29 kAllOnes_ColorMode,
30 kAllZeros_ColorMode,
31 kAlphaOne_ColorMode,
32 kRandom_ColorMode,
33 kLast_ColorMode = kRandom_ColorMode
34 };
35
36 ColorMode colorMode = ColorMode(random->nextULessThan(kLast_ColorMode + 1));
37 GrColor color;
38 switch (colorMode) {
39 case kAllOnes_ColorMode:
40 color = GrColorPackRGBA(0xFF, 0xFF, 0xFF, 0xFF);
41 break;
42 case kAllZeros_ColorMode:
43 color = GrColorPackRGBA(0, 0, 0, 0);
44 break;
45 case kAlphaOne_ColorMode:
46 color = GrColorPackRGBA(random->nextULessThan(256),
47 random->nextULessThan(256),
48 random->nextULessThan(256),
49 0xFF);
50 break;
51 case kRandom_ColorMode:
robertphillips 2015/04/29 13:23:01 {}s around this (since it has a variable) ?
52 uint8_t alpha = random->nextULessThan(256);
53 color = GrColorPackRGBA(random->nextRangeU(0, alpha),
54 random->nextRangeU(0, alpha),
55 random->nextRangeU(0, alpha),
56 alpha);
57 break;
58 }
59 GrColorIsPMAssert(color);
60 return color;
61 }
62
63 static inline uint8_t GrRandomCoverage(SkRandom* random) {
64 enum CoverageMode {
65 kZero_CoverageMode,
66 kAllOnes_CoverageMode,
67 kRandom_CoverageMode,
68 kLast_CoverageMode = kRandom_CoverageMode
69 };
70
71 CoverageMode colorMode = CoverageMode(random->nextULessThan(kLast_CoverageMo de + 1));
72 uint8_t coverage;
73 switch (colorMode) {
74 case kZero_CoverageMode:
75 coverage = 0;
76 case kAllOnes_CoverageMode:
77 coverage = 0xff;
78 break;
79 case kRandom_CoverageMode:
80 coverage = random->nextULessThan(256);
81 break;
82 }
83 return coverage;
84 }
85
86 #endif
OLDNEW
« no previous file with comments | « gyp/gpu.gypi ('k') | src/gpu/GrAARectRenderer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698