Michael Ludwig | 4f94ef6 | 2018-09-12 15:22:16 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018 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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "src/gpu/gradients/GrGradientShader.h" |
Michael Ludwig | 4f94ef6 | 2018-09-12 15:22:16 -0400 | [diff] [blame] | 9 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 10 | #include "src/gpu/gradients/generated/GrClampedGradientEffect.h" |
| 11 | #include "src/gpu/gradients/generated/GrTiledGradientEffect.h" |
Michael Ludwig | 4f94ef6 | 2018-09-12 15:22:16 -0400 | [diff] [blame] | 12 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 13 | #include "src/gpu/gradients/generated/GrLinearGradientLayout.h" |
| 14 | #include "src/gpu/gradients/generated/GrRadialGradientLayout.h" |
| 15 | #include "src/gpu/gradients/generated/GrSweepGradientLayout.h" |
| 16 | #include "src/gpu/gradients/generated/GrTwoPointConicalGradientLayout.h" |
Michael Ludwig | 4089df8 | 2018-09-12 15:22:37 -0400 | [diff] [blame] | 17 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 18 | #include "src/gpu/gradients/GrGradientBitmapCache.h" |
| 19 | #include "src/gpu/gradients/generated/GrDualIntervalGradientColorizer.h" |
| 20 | #include "src/gpu/gradients/generated/GrSingleIntervalGradientColorizer.h" |
| 21 | #include "src/gpu/gradients/generated/GrTextureGradientColorizer.h" |
| 22 | #include "src/gpu/gradients/generated/GrUnrolledBinaryGradientColorizer.h" |
Michael Ludwig | 4f94ef6 | 2018-09-12 15:22:16 -0400 | [diff] [blame] | 23 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 24 | #include "include/private/GrRecordingContext.h" |
| 25 | #include "src/gpu/GrCaps.h" |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame^] | 26 | #include "src/gpu/GrColor.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 27 | #include "src/gpu/GrColorSpaceInfo.h" |
| 28 | #include "src/gpu/GrRecordingContextPriv.h" |
| 29 | #include "src/gpu/SkGr.h" |
Michael Ludwig | a7914d3 | 2018-09-14 09:47:21 -0400 | [diff] [blame] | 30 | |
Michael Ludwig | 72535fb | 2018-09-28 11:53:32 -0400 | [diff] [blame] | 31 | // Intervals smaller than this (that aren't hard stops) on low-precision-only devices force us to |
| 32 | // use the textured gradient |
| 33 | static const SkScalar kLowPrecisionIntervalLimit = 0.01f; |
| 34 | |
Michael Ludwig | a7914d3 | 2018-09-14 09:47:21 -0400 | [diff] [blame] | 35 | // Each cache entry costs 1K or 2K of RAM. Each bitmap will be 1x256 at either 32bpp or 64bpp. |
| 36 | static const int kMaxNumCachedGradientBitmaps = 32; |
| 37 | static const int kGradientTextureSize = 256; |
| 38 | |
| 39 | // NOTE: signature takes raw pointers to the color/pos arrays and a count to make it easy for |
| 40 | // MakeColorizer to transparently take care of hard stops at the end points of the gradient. |
Brian Osman | 021ed51 | 2018-10-16 15:19:44 -0400 | [diff] [blame] | 41 | static std::unique_ptr<GrFragmentProcessor> make_textured_colorizer(const SkPMColor4f* colors, |
Michael Ludwig | a7914d3 | 2018-09-14 09:47:21 -0400 | [diff] [blame] | 42 | const SkScalar* positions, int count, bool premul, const GrFPArgs& args) { |
| 43 | static GrGradientBitmapCache gCache(kMaxNumCachedGradientBitmaps, kGradientTextureSize); |
| 44 | |
| 45 | // Use 8888 or F16, depending on the destination config. |
| 46 | // TODO: Use 1010102 for opaque gradients, at least if destination is 1010102? |
| 47 | SkColorType colorType = kRGBA_8888_SkColorType; |
| 48 | if (kLow_GrSLPrecision != GrSLSamplerPrecision(args.fDstColorSpaceInfo->config()) && |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 49 | args.fContext->priv().caps()->isConfigTexturable(kRGBA_half_GrPixelConfig)) { |
Michael Ludwig | a7914d3 | 2018-09-14 09:47:21 -0400 | [diff] [blame] | 50 | colorType = kRGBA_F16_SkColorType; |
| 51 | } |
| 52 | SkAlphaType alphaType = premul ? kPremul_SkAlphaType : kUnpremul_SkAlphaType; |
| 53 | |
| 54 | SkBitmap bitmap; |
| 55 | gCache.getGradient(colors, positions, count, colorType, alphaType, &bitmap); |
| 56 | SkASSERT(1 == bitmap.height() && SkIsPow2(bitmap.width())); |
| 57 | SkASSERT(bitmap.isImmutable()); |
| 58 | |
| 59 | sk_sp<GrTextureProxy> proxy = GrMakeCachedBitmapProxy( |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 60 | args.fContext->priv().proxyProvider(), bitmap); |
Michael Ludwig | a7914d3 | 2018-09-14 09:47:21 -0400 | [diff] [blame] | 61 | if (proxy == nullptr) { |
| 62 | SkDebugf("Gradient won't draw. Could not create texture."); |
| 63 | return nullptr; |
| 64 | } |
| 65 | |
| 66 | return GrTextureGradientColorizer::Make(std::move(proxy)); |
| 67 | } |
Michael Ludwig | 4f94ef6 | 2018-09-12 15:22:16 -0400 | [diff] [blame] | 68 | |
| 69 | // Analyze the shader's color stops and positions and chooses an appropriate colorizer to represent |
| 70 | // the gradient. |
Brian Osman | 021ed51 | 2018-10-16 15:19:44 -0400 | [diff] [blame] | 71 | static std::unique_ptr<GrFragmentProcessor> make_colorizer(const SkPMColor4f* colors, |
Michael Ludwig | a7914d3 | 2018-09-14 09:47:21 -0400 | [diff] [blame] | 72 | const SkScalar* positions, int count, bool premul, const GrFPArgs& args) { |
Michael Ludwig | 4f94ef6 | 2018-09-12 15:22:16 -0400 | [diff] [blame] | 73 | // If there are hard stops at the beginning or end, the first and/or last color should be |
| 74 | // ignored by the colorizer since it should only be used in a clamped border color. By detecting |
| 75 | // and removing these stops at the beginning, it makes optimizing the remaining color stops |
| 76 | // simpler. |
| 77 | |
Michael Ludwig | 0495f7a | 2018-09-12 15:23:33 -0400 | [diff] [blame] | 78 | // SkGradientShaderBase guarantees that pos[0] == 0 by adding a dummy |
| 79 | bool bottomHardStop = SkScalarNearlyEqual(positions[0], positions[1]); |
| 80 | // The same is true for pos[end] == 1 |
Michael Ludwig | a7914d3 | 2018-09-14 09:47:21 -0400 | [diff] [blame] | 81 | bool topHardStop = SkScalarNearlyEqual(positions[count - 2], positions[count - 1]); |
Michael Ludwig | 4f94ef6 | 2018-09-12 15:22:16 -0400 | [diff] [blame] | 82 | |
| 83 | int offset = 0; |
Michael Ludwig | 4f94ef6 | 2018-09-12 15:22:16 -0400 | [diff] [blame] | 84 | if (bottomHardStop) { |
| 85 | offset += 1; |
| 86 | count--; |
| 87 | } |
| 88 | if (topHardStop) { |
| 89 | count--; |
| 90 | } |
| 91 | |
Michael Ludwig | 0495f7a | 2018-09-12 15:23:33 -0400 | [diff] [blame] | 92 | // Two remaining colors means a single interval from 0 to 1 |
| 93 | // (but it may have originally been a 3 or 4 color gradient with 1-2 hard stops at the ends) |
Michael Ludwig | 4f94ef6 | 2018-09-12 15:22:16 -0400 | [diff] [blame] | 94 | if (count == 2) { |
| 95 | return GrSingleIntervalGradientColorizer::Make(colors[offset], colors[offset + 1]); |
| 96 | } |
| 97 | |
Michael Ludwig | 72535fb | 2018-09-28 11:53:32 -0400 | [diff] [blame] | 98 | // Do an early test for the texture fallback to skip all of the other tests for specific |
| 99 | // analytic support of the gradient (and compatibility with the hardware), when it's definitely |
| 100 | // impossible to use an analytic solution. |
| 101 | bool tryAnalyticColorizer = count <= GrUnrolledBinaryGradientColorizer::kMaxColorCount; |
| 102 | |
| 103 | // The remaining analytic colorizers use scale*t+bias, and the scale/bias values can become |
| 104 | // quite large when thresholds are close (but still outside the hardstop limit). If float isn't |
| 105 | // 32-bit, output can be incorrect if the thresholds are too close together. However, the |
| 106 | // analytic shaders are higher quality, so they can be used with lower precision hardware when |
| 107 | // the thresholds are not ill-conditioned. |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 108 | const GrShaderCaps* caps = args.fContext->priv().caps()->shaderCaps(); |
Michael Ludwig | 72535fb | 2018-09-28 11:53:32 -0400 | [diff] [blame] | 109 | if (!caps->floatIs32Bits() && tryAnalyticColorizer) { |
| 110 | // Could run into problems, check if thresholds are close together (with a limit of .01, so |
| 111 | // that scales will be less than 100, which leaves 4 decimals of precision on 16-bit). |
| 112 | for (int i = offset; i < count - 1; i++) { |
| 113 | SkScalar dt = SkScalarAbs(positions[i] - positions[i + 1]); |
| 114 | if (dt <= kLowPrecisionIntervalLimit && dt > SK_ScalarNearlyZero) { |
| 115 | tryAnalyticColorizer = false; |
| 116 | break; |
| 117 | } |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | if (tryAnalyticColorizer) { |
| 122 | if (count == 3) { |
| 123 | // Must be a dual interval gradient, where the middle point is at offset+1 and the two |
| 124 | // intervals share the middle color stop. |
| 125 | return GrDualIntervalGradientColorizer::Make(colors[offset], colors[offset + 1], |
| 126 | colors[offset + 1], colors[offset + 2], |
| 127 | positions[offset + 1]); |
| 128 | } else if (count == 4 && SkScalarNearlyEqual(positions[offset + 1], |
| 129 | positions[offset + 2])) { |
| 130 | // Two separate intervals that join at the same threshold position |
| 131 | return GrDualIntervalGradientColorizer::Make(colors[offset], colors[offset + 1], |
| 132 | colors[offset + 2], colors[offset + 3], |
| 133 | positions[offset + 1]); |
| 134 | } |
| 135 | |
| 136 | // The single and dual intervals are a specialized case of the unrolled binary search |
| 137 | // colorizer which can analytically render gradients of up to 8 intervals (up to 9 or 16 |
| 138 | // colors depending on how many hard stops are inserted). |
| 139 | std::unique_ptr<GrFragmentProcessor> unrolled = GrUnrolledBinaryGradientColorizer::Make( |
| 140 | colors + offset, positions + offset, count); |
| 141 | if (unrolled) { |
| 142 | return unrolled; |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | // Otherwise fall back to a rasterized gradient sampled by a texture, which can handle |
| 147 | // arbitrary gradients (the only downside being sampling resolution). |
Michael Ludwig | a7914d3 | 2018-09-14 09:47:21 -0400 | [diff] [blame] | 148 | return make_textured_colorizer(colors + offset, positions + offset, count, premul, args); |
Michael Ludwig | 4f94ef6 | 2018-09-12 15:22:16 -0400 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | // Combines the colorizer and layout with an appropriately configured master effect based on the |
| 152 | // gradient's tile mode |
| 153 | static std::unique_ptr<GrFragmentProcessor> make_gradient(const SkGradientShaderBase& shader, |
| 154 | const GrFPArgs& args, std::unique_ptr<GrFragmentProcessor> layout) { |
| 155 | // No shader is possible if a layout couldn't be created, e.g. a layout-specific Make() returned |
| 156 | // null. |
| 157 | if (layout == nullptr) { |
| 158 | return nullptr; |
| 159 | } |
| 160 | |
Brian Osman | 021ed51 | 2018-10-16 15:19:44 -0400 | [diff] [blame] | 161 | // Convert all colors into destination space and into SkPMColor4fs, and handle |
Michael Ludwig | 4f94ef6 | 2018-09-12 15:22:16 -0400 | [diff] [blame] | 162 | // premul issues depending on the interpolation mode |
| 163 | bool inputPremul = shader.getGradFlags() & SkGradientShader::kInterpolateColorsInPremul_Flag; |
Michael Ludwig | b96cba3 | 2018-09-14 13:59:24 -0400 | [diff] [blame] | 164 | bool allOpaque = true; |
Brian Osman | 021ed51 | 2018-10-16 15:19:44 -0400 | [diff] [blame] | 165 | SkAutoSTMalloc<4, SkPMColor4f> colors(shader.fColorCount); |
Michael Ludwig | 4f94ef6 | 2018-09-12 15:22:16 -0400 | [diff] [blame] | 166 | SkColor4fXformer xformedColors(shader.fOrigColors4f, shader.fColorCount, |
| 167 | shader.fColorSpace.get(), args.fDstColorSpaceInfo->colorSpace()); |
| 168 | for (int i = 0; i < shader.fColorCount; i++) { |
Brian Osman | 021ed51 | 2018-10-16 15:19:44 -0400 | [diff] [blame] | 169 | const SkColor4f& upmColor = xformedColors.fColors[i]; |
| 170 | colors[i] = inputPremul ? upmColor.premul() |
| 171 | : SkPMColor4f{ upmColor.fR, upmColor.fG, upmColor.fB, upmColor.fA }; |
| 172 | if (allOpaque && !SkScalarNearlyEqual(colors[i].fA, 1.0)) { |
Michael Ludwig | b96cba3 | 2018-09-14 13:59:24 -0400 | [diff] [blame] | 173 | allOpaque = false; |
| 174 | } |
Michael Ludwig | 4f94ef6 | 2018-09-12 15:22:16 -0400 | [diff] [blame] | 175 | } |
| 176 | |
Michael Ludwig | 0495f7a | 2018-09-12 15:23:33 -0400 | [diff] [blame] | 177 | // SkGradientShader stores positions implicitly when they are evenly spaced, but the getPos() |
| 178 | // implementation performs a branch for every position index. Since the shader conversion |
| 179 | // requires lots of position tests, calculate all of the positions up front if needed. |
| 180 | SkTArray<SkScalar, true> implicitPos; |
| 181 | SkScalar* positions; |
| 182 | if (shader.fOrigPos) { |
| 183 | positions = shader.fOrigPos; |
| 184 | } else { |
| 185 | implicitPos.reserve(shader.fColorCount); |
Mike Klein | d3ed301 | 2018-11-06 19:23:08 -0500 | [diff] [blame] | 186 | SkScalar posScale = SK_Scalar1 / (shader.fColorCount - 1); |
Michael Ludwig | 0495f7a | 2018-09-12 15:23:33 -0400 | [diff] [blame] | 187 | for (int i = 0 ; i < shader.fColorCount; i++) { |
| 188 | implicitPos.push_back(SkIntToScalar(i) * posScale); |
| 189 | } |
| 190 | positions = implicitPos.begin(); |
| 191 | } |
| 192 | |
Michael Ludwig | 4f94ef6 | 2018-09-12 15:22:16 -0400 | [diff] [blame] | 193 | // All gradients are colorized the same way, regardless of layout |
Michael Ludwig | a7914d3 | 2018-09-14 09:47:21 -0400 | [diff] [blame] | 194 | std::unique_ptr<GrFragmentProcessor> colorizer = make_colorizer( |
| 195 | colors.get(), positions, shader.fColorCount, inputPremul, args); |
Michael Ludwig | 4f94ef6 | 2018-09-12 15:22:16 -0400 | [diff] [blame] | 196 | if (colorizer == nullptr) { |
| 197 | return nullptr; |
| 198 | } |
| 199 | |
Michael Ludwig | b96cba3 | 2018-09-14 13:59:24 -0400 | [diff] [blame] | 200 | // The master effect has to export premul colors, but under certain conditions it doesn't need |
| 201 | // to do anything to achieve that: i.e. its interpolating already premul colors (inputPremul) |
| 202 | // or all the colors have a = 1, in which case premul is a no op. Note that this allOpaque |
| 203 | // check is more permissive than SkGradientShaderBase's isOpaque(), since we can optimize away |
| 204 | // the make-premul op for two point conical gradients (which report false for isOpaque). |
| 205 | bool makePremul = !inputPremul && !allOpaque; |
| 206 | |
Michael Ludwig | 4f94ef6 | 2018-09-12 15:22:16 -0400 | [diff] [blame] | 207 | // All tile modes are supported (unless something was added to SkShader) |
| 208 | std::unique_ptr<GrFragmentProcessor> master; |
| 209 | switch(shader.getTileMode()) { |
Mike Reed | fae8fce | 2019-04-03 10:27:45 -0400 | [diff] [blame] | 210 | case SkTileMode::kRepeat: |
Michael Ludwig | 4f94ef6 | 2018-09-12 15:22:16 -0400 | [diff] [blame] | 211 | master = GrTiledGradientEffect::Make(std::move(colorizer), std::move(layout), |
Michael Ludwig | b96cba3 | 2018-09-14 13:59:24 -0400 | [diff] [blame] | 212 | /* mirror */ false, makePremul, allOpaque); |
Michael Ludwig | 4f94ef6 | 2018-09-12 15:22:16 -0400 | [diff] [blame] | 213 | break; |
Mike Reed | fae8fce | 2019-04-03 10:27:45 -0400 | [diff] [blame] | 214 | case SkTileMode::kMirror: |
Michael Ludwig | 4f94ef6 | 2018-09-12 15:22:16 -0400 | [diff] [blame] | 215 | master = GrTiledGradientEffect::Make(std::move(colorizer), std::move(layout), |
Michael Ludwig | b96cba3 | 2018-09-14 13:59:24 -0400 | [diff] [blame] | 216 | /* mirror */ true, makePremul, allOpaque); |
Michael Ludwig | 4f94ef6 | 2018-09-12 15:22:16 -0400 | [diff] [blame] | 217 | break; |
Mike Reed | fae8fce | 2019-04-03 10:27:45 -0400 | [diff] [blame] | 218 | case SkTileMode::kClamp: |
Michael Ludwig | 4f94ef6 | 2018-09-12 15:22:16 -0400 | [diff] [blame] | 219 | // For the clamped mode, the border colors are the first and last colors, corresponding |
| 220 | // to t=0 and t=1, because SkGradientShaderBase enforces that by adding color stops as |
| 221 | // appropriate. If there is a hard stop, this grabs the expected outer colors for the |
| 222 | // border. |
| 223 | master = GrClampedGradientEffect::Make(std::move(colorizer), std::move(layout), |
Michael Ludwig | b96cba3 | 2018-09-14 13:59:24 -0400 | [diff] [blame] | 224 | colors[0], colors[shader.fColorCount - 1], makePremul, allOpaque); |
Michael Ludwig | 4f94ef6 | 2018-09-12 15:22:16 -0400 | [diff] [blame] | 225 | break; |
Mike Reed | fae8fce | 2019-04-03 10:27:45 -0400 | [diff] [blame] | 226 | case SkTileMode::kDecal: |
Michael Ludwig | b96cba3 | 2018-09-14 13:59:24 -0400 | [diff] [blame] | 227 | // Even if the gradient colors are opaque, the decal borders are transparent so |
| 228 | // disable that optimization |
Michael Ludwig | 4f94ef6 | 2018-09-12 15:22:16 -0400 | [diff] [blame] | 229 | master = GrClampedGradientEffect::Make(std::move(colorizer), std::move(layout), |
Brian Osman | 021ed51 | 2018-10-16 15:19:44 -0400 | [diff] [blame] | 230 | SK_PMColor4fTRANSPARENT, SK_PMColor4fTRANSPARENT, |
Michael Ludwig | b96cba3 | 2018-09-14 13:59:24 -0400 | [diff] [blame] | 231 | makePremul, /* colorsAreOpaque */ false); |
Michael Ludwig | 4f94ef6 | 2018-09-12 15:22:16 -0400 | [diff] [blame] | 232 | break; |
| 233 | } |
| 234 | |
| 235 | if (master == nullptr) { |
| 236 | // Unexpected tile mode |
| 237 | return nullptr; |
| 238 | } |
Brian Salomon | c0d79e5 | 2019-04-10 15:02:11 -0400 | [diff] [blame] | 239 | if (args.fInputColorIsOpaque) { |
| 240 | return GrFragmentProcessor::OverrideInput(std::move(master), SK_PMColor4fWHITE, false); |
| 241 | } |
Michael Ludwig | 4f94ef6 | 2018-09-12 15:22:16 -0400 | [diff] [blame] | 242 | return GrFragmentProcessor::MulChildByInputAlpha(std::move(master)); |
| 243 | } |
| 244 | |
| 245 | namespace GrGradientShader { |
| 246 | |
| 247 | std::unique_ptr<GrFragmentProcessor> MakeLinear(const SkLinearGradient& shader, |
| 248 | const GrFPArgs& args) { |
| 249 | return make_gradient(shader, args, GrLinearGradientLayout::Make(shader, args)); |
| 250 | } |
| 251 | |
Michael Ludwig | 4089df8 | 2018-09-12 15:22:37 -0400 | [diff] [blame] | 252 | std::unique_ptr<GrFragmentProcessor> MakeRadial(const SkRadialGradient& shader, |
| 253 | const GrFPArgs& args) { |
| 254 | return make_gradient(shader,args, GrRadialGradientLayout::Make(shader, args)); |
| 255 | } |
| 256 | |
Michael Ludwig | 24d438b | 2018-09-12 15:22:50 -0400 | [diff] [blame] | 257 | std::unique_ptr<GrFragmentProcessor> MakeSweep(const SkSweepGradient& shader, |
| 258 | const GrFPArgs& args) { |
| 259 | return make_gradient(shader,args, GrSweepGradientLayout::Make(shader, args)); |
| 260 | } |
| 261 | |
Michael Ludwig | 8f68508 | 2018-09-12 15:23:01 -0400 | [diff] [blame] | 262 | std::unique_ptr<GrFragmentProcessor> MakeConical(const SkTwoPointConicalGradient& shader, |
| 263 | const GrFPArgs& args) { |
| 264 | return make_gradient(shader, args, GrTwoPointConicalGradientLayout::Make(shader, args)); |
| 265 | } |
| 266 | |
Michael Ludwig | 7f8c524 | 2018-09-14 15:07:55 -0400 | [diff] [blame] | 267 | #if GR_TEST_UTILS |
| 268 | RandomParams::RandomParams(SkRandom* random) { |
| 269 | // Set color count to min of 2 so that we don't trigger the const color optimization and make |
| 270 | // a non-gradient processor. |
| 271 | fColorCount = random->nextRangeU(2, kMaxRandomGradientColors); |
| 272 | fUseColors4f = random->nextBool(); |
| 273 | |
| 274 | // if one color, omit stops, otherwise randomly decide whether or not to |
| 275 | if (fColorCount == 1 || (fColorCount >= 2 && random->nextBool())) { |
| 276 | fStops = nullptr; |
| 277 | } else { |
| 278 | fStops = fStopStorage; |
| 279 | } |
| 280 | |
| 281 | // if using SkColor4f, attach a random (possibly null) color space (with linear gamma) |
| 282 | if (fUseColors4f) { |
| 283 | fColorSpace = GrTest::TestColorSpace(random); |
| 284 | } |
| 285 | |
| 286 | SkScalar stop = 0.f; |
| 287 | for (int i = 0; i < fColorCount; ++i) { |
| 288 | if (fUseColors4f) { |
| 289 | fColors4f[i].fR = random->nextUScalar1(); |
| 290 | fColors4f[i].fG = random->nextUScalar1(); |
| 291 | fColors4f[i].fB = random->nextUScalar1(); |
| 292 | fColors4f[i].fA = random->nextUScalar1(); |
| 293 | } else { |
| 294 | fColors[i] = random->nextU(); |
| 295 | } |
| 296 | if (fStops) { |
| 297 | fStops[i] = stop; |
| 298 | stop = i < fColorCount - 1 ? stop + random->nextUScalar1() * (1.f - stop) : 1.f; |
| 299 | } |
| 300 | } |
Mike Reed | fae8fce | 2019-04-03 10:27:45 -0400 | [diff] [blame] | 301 | fTileMode = static_cast<SkTileMode>(random->nextULessThan(kSkTileModeCount)); |
Michael Ludwig | 7f8c524 | 2018-09-14 15:07:55 -0400 | [diff] [blame] | 302 | } |
| 303 | #endif |
| 304 | |
Michael Ludwig | 4f94ef6 | 2018-09-12 15:22:16 -0400 | [diff] [blame] | 305 | } |