rileya@google.com | 589708b | 2012-07-26 20:04:23 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2012 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
| 8 | |
| 9 | #include "SkSweepGradient.h" |
| 10 | |
reed | addf2ed | 2014-08-11 08:28:24 -0700 | [diff] [blame] | 11 | SkSweepGradient::SkSweepGradient(SkScalar cx, SkScalar cy, const Descriptor& desc) |
| 12 | : SkGradientShaderBase(desc) |
reed@google.com | 3d3a860 | 2013-05-24 14:58:44 +0000 | [diff] [blame] | 13 | , fCenter(SkPoint::Make(cx, cy)) |
rileya@google.com | 589708b | 2012-07-26 20:04:23 +0000 | [diff] [blame] | 14 | { |
| 15 | fPtsToUnit.setTranslate(-cx, -cy); |
reed@google.com | 437d6eb | 2013-05-23 19:03:05 +0000 | [diff] [blame] | 16 | |
| 17 | // overwrite the tilemode to a canonical value (since sweep ignores it) |
| 18 | fTileMode = SkShader::kClamp_TileMode; |
rileya@google.com | 589708b | 2012-07-26 20:04:23 +0000 | [diff] [blame] | 19 | } |
| 20 | |
| 21 | SkShader::BitmapType SkSweepGradient::asABitmap(SkBitmap* bitmap, |
| 22 | SkMatrix* matrix, SkShader::TileMode* xy) const { |
| 23 | if (bitmap) { |
rileya@google.com | 1c6d64b | 2012-07-27 15:49:05 +0000 | [diff] [blame] | 24 | this->getGradientTableBitmap(bitmap); |
rileya@google.com | 589708b | 2012-07-26 20:04:23 +0000 | [diff] [blame] | 25 | } |
| 26 | if (matrix) { |
| 27 | *matrix = fPtsToUnit; |
| 28 | } |
| 29 | if (xy) { |
| 30 | xy[0] = fTileMode; |
| 31 | xy[1] = kClamp_TileMode; |
| 32 | } |
| 33 | return kSweep_BitmapType; |
| 34 | } |
| 35 | |
| 36 | SkShader::GradientType SkSweepGradient::asAGradient(GradientInfo* info) const { |
| 37 | if (info) { |
| 38 | commonAsAGradient(info); |
| 39 | info->fPoint[0] = fCenter; |
| 40 | } |
| 41 | return kSweep_GradientType; |
| 42 | } |
| 43 | |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 44 | SkSweepGradient::SkSweepGradient(SkReadBuffer& buffer) |
rileya@google.com | 589708b | 2012-07-26 20:04:23 +0000 | [diff] [blame] | 45 | : INHERITED(buffer), |
| 46 | fCenter(buffer.readPoint()) { |
| 47 | } |
| 48 | |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 49 | void SkSweepGradient::flatten(SkWriteBuffer& buffer) const { |
rileya@google.com | 589708b | 2012-07-26 20:04:23 +0000 | [diff] [blame] | 50 | this->INHERITED::flatten(buffer); |
| 51 | buffer.writePoint(fCenter); |
| 52 | } |
| 53 | |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 54 | size_t SkSweepGradient::contextSize() const { |
| 55 | return sizeof(SweepGradientContext); |
| 56 | } |
| 57 | |
commit-bot@chromium.org | ce56d96 | 2014-05-05 18:39:18 +0000 | [diff] [blame] | 58 | SkShader::Context* SkSweepGradient::onCreateContext(const ContextRec& rec, void* storage) const { |
commit-bot@chromium.org | e901b6d | 2014-05-01 19:31:31 +0000 | [diff] [blame] | 59 | return SkNEW_PLACEMENT_ARGS(storage, SweepGradientContext, (*this, rec)); |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | SkSweepGradient::SweepGradientContext::SweepGradientContext( |
commit-bot@chromium.org | e901b6d | 2014-05-01 19:31:31 +0000 | [diff] [blame] | 63 | const SkSweepGradient& shader, const ContextRec& rec) |
| 64 | : INHERITED(shader, rec) {} |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 65 | |
rileya@google.com | 589708b | 2012-07-26 20:04:23 +0000 | [diff] [blame] | 66 | // returns angle in a circle [0..2PI) -> [0..255] |
rileya@google.com | 589708b | 2012-07-26 20:04:23 +0000 | [diff] [blame] | 67 | static unsigned SkATan2_255(float y, float x) { |
| 68 | // static const float g255Over2PI = 255 / (2 * SK_ScalarPI); |
| 69 | static const float g255Over2PI = 40.584510488433314f; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 70 | |
rileya@google.com | 589708b | 2012-07-26 20:04:23 +0000 | [diff] [blame] | 71 | float result = sk_float_atan2(y, x); |
| 72 | if (result < 0) { |
| 73 | result += 2 * SK_ScalarPI; |
| 74 | } |
| 75 | SkASSERT(result >= 0); |
| 76 | // since our value is always >= 0, we can cast to int, which is faster than |
| 77 | // calling floorf() |
| 78 | int ir = (int)(result * g255Over2PI); |
| 79 | SkASSERT(ir >= 0 && ir <= 255); |
| 80 | return ir; |
| 81 | } |
rileya@google.com | 589708b | 2012-07-26 20:04:23 +0000 | [diff] [blame] | 82 | |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 83 | void SkSweepGradient::SweepGradientContext::shadeSpan(int x, int y, SkPMColor* SK_RESTRICT dstC, |
| 84 | int count) { |
rileya@google.com | 589708b | 2012-07-26 20:04:23 +0000 | [diff] [blame] | 85 | SkMatrix::MapXYProc proc = fDstToIndexProc; |
| 86 | const SkMatrix& matrix = fDstToIndex; |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 87 | const SkPMColor* SK_RESTRICT cache = fCache->getCache32(); |
reed@google.com | 6004029 | 2013-02-04 18:21:23 +0000 | [diff] [blame] | 88 | int toggle = init_dither_toggle(x, y); |
rileya@google.com | 589708b | 2012-07-26 20:04:23 +0000 | [diff] [blame] | 89 | SkPoint srcPt; |
| 90 | |
| 91 | if (fDstToIndexClass != kPerspective_MatrixClass) { |
| 92 | proc(matrix, SkIntToScalar(x) + SK_ScalarHalf, |
| 93 | SkIntToScalar(y) + SK_ScalarHalf, &srcPt); |
| 94 | SkScalar dx, fx = srcPt.fX; |
| 95 | SkScalar dy, fy = srcPt.fY; |
| 96 | |
| 97 | if (fDstToIndexClass == kFixedStepInX_MatrixClass) { |
| 98 | SkFixed storage[2]; |
| 99 | (void)matrix.fixedStepInX(SkIntToScalar(y) + SK_ScalarHalf, |
| 100 | &storage[0], &storage[1]); |
| 101 | dx = SkFixedToScalar(storage[0]); |
| 102 | dy = SkFixedToScalar(storage[1]); |
| 103 | } else { |
| 104 | SkASSERT(fDstToIndexClass == kLinear_MatrixClass); |
| 105 | dx = matrix.getScaleX(); |
| 106 | dy = matrix.getSkewY(); |
| 107 | } |
| 108 | |
| 109 | for (; count > 0; --count) { |
reed@google.com | 6004029 | 2013-02-04 18:21:23 +0000 | [diff] [blame] | 110 | *dstC++ = cache[toggle + SkATan2_255(fy, fx)]; |
rileya@google.com | 589708b | 2012-07-26 20:04:23 +0000 | [diff] [blame] | 111 | fx += dx; |
| 112 | fy += dy; |
reed@google.com | 6004029 | 2013-02-04 18:21:23 +0000 | [diff] [blame] | 113 | toggle = next_dither_toggle(toggle); |
rileya@google.com | 589708b | 2012-07-26 20:04:23 +0000 | [diff] [blame] | 114 | } |
| 115 | } else { // perspective case |
| 116 | for (int stop = x + count; x < stop; x++) { |
| 117 | proc(matrix, SkIntToScalar(x) + SK_ScalarHalf, |
| 118 | SkIntToScalar(y) + SK_ScalarHalf, &srcPt); |
reed@google.com | 6004029 | 2013-02-04 18:21:23 +0000 | [diff] [blame] | 119 | *dstC++ = cache[toggle + SkATan2_255(srcPt.fY, srcPt.fX)]; |
reed@google.com | 6004029 | 2013-02-04 18:21:23 +0000 | [diff] [blame] | 120 | toggle = next_dither_toggle(toggle); |
rileya@google.com | 589708b | 2012-07-26 20:04:23 +0000 | [diff] [blame] | 121 | } |
| 122 | } |
| 123 | } |
| 124 | |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 125 | void SkSweepGradient::SweepGradientContext::shadeSpan16(int x, int y, uint16_t* SK_RESTRICT dstC, |
| 126 | int count) { |
rileya@google.com | 589708b | 2012-07-26 20:04:23 +0000 | [diff] [blame] | 127 | SkMatrix::MapXYProc proc = fDstToIndexProc; |
| 128 | const SkMatrix& matrix = fDstToIndex; |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 129 | const uint16_t* SK_RESTRICT cache = fCache->getCache16(); |
reed@google.com | 55853db | 2013-02-01 19:34:59 +0000 | [diff] [blame] | 130 | int toggle = init_dither_toggle16(x, y); |
rileya@google.com | 589708b | 2012-07-26 20:04:23 +0000 | [diff] [blame] | 131 | SkPoint srcPt; |
| 132 | |
| 133 | if (fDstToIndexClass != kPerspective_MatrixClass) { |
| 134 | proc(matrix, SkIntToScalar(x) + SK_ScalarHalf, |
| 135 | SkIntToScalar(y) + SK_ScalarHalf, &srcPt); |
| 136 | SkScalar dx, fx = srcPt.fX; |
| 137 | SkScalar dy, fy = srcPt.fY; |
| 138 | |
| 139 | if (fDstToIndexClass == kFixedStepInX_MatrixClass) { |
| 140 | SkFixed storage[2]; |
| 141 | (void)matrix.fixedStepInX(SkIntToScalar(y) + SK_ScalarHalf, |
| 142 | &storage[0], &storage[1]); |
| 143 | dx = SkFixedToScalar(storage[0]); |
| 144 | dy = SkFixedToScalar(storage[1]); |
| 145 | } else { |
| 146 | SkASSERT(fDstToIndexClass == kLinear_MatrixClass); |
| 147 | dx = matrix.getScaleX(); |
| 148 | dy = matrix.getSkewY(); |
| 149 | } |
| 150 | |
| 151 | for (; count > 0; --count) { |
| 152 | int index = SkATan2_255(fy, fx) >> (8 - kCache16Bits); |
| 153 | *dstC++ = cache[toggle + index]; |
reed@google.com | 55853db | 2013-02-01 19:34:59 +0000 | [diff] [blame] | 154 | toggle = next_dither_toggle16(toggle); |
rileya@google.com | 589708b | 2012-07-26 20:04:23 +0000 | [diff] [blame] | 155 | fx += dx; |
| 156 | fy += dy; |
| 157 | } |
| 158 | } else { // perspective case |
| 159 | for (int stop = x + count; x < stop; x++) { |
| 160 | proc(matrix, SkIntToScalar(x) + SK_ScalarHalf, |
| 161 | SkIntToScalar(y) + SK_ScalarHalf, &srcPt); |
| 162 | |
| 163 | int index = SkATan2_255(srcPt.fY, srcPt.fX); |
| 164 | index >>= (8 - kCache16Bits); |
| 165 | *dstC++ = cache[toggle + index]; |
reed@google.com | 55853db | 2013-02-01 19:34:59 +0000 | [diff] [blame] | 166 | toggle = next_dither_toggle16(toggle); |
rileya@google.com | 589708b | 2012-07-26 20:04:23 +0000 | [diff] [blame] | 167 | } |
| 168 | } |
| 169 | } |
| 170 | |
rileya@google.com | d7cc651 | 2012-07-27 14:00:39 +0000 | [diff] [blame] | 171 | ///////////////////////////////////////////////////////////////////// |
| 172 | |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 173 | #if SK_SUPPORT_GPU |
| 174 | |
bsalomon@google.com | 2eaaefd | 2012-10-29 19:51:22 +0000 | [diff] [blame] | 175 | #include "GrTBackendEffectFactory.h" |
bsalomon | 848faf0 | 2014-07-11 10:01:02 -0700 | [diff] [blame] | 176 | #include "gl/GrGLShaderBuilder.h" |
dandov | 9de5b51 | 2014-06-10 14:38:28 -0700 | [diff] [blame] | 177 | #include "SkGr.h" |
bsalomon@google.com | 2eaaefd | 2012-10-29 19:51:22 +0000 | [diff] [blame] | 178 | |
bsalomon@google.com | 0707c29 | 2012-10-25 21:45:42 +0000 | [diff] [blame] | 179 | class GrGLSweepGradient : public GrGLGradientEffect { |
rileya@google.com | d7cc651 | 2012-07-27 14:00:39 +0000 | [diff] [blame] | 180 | public: |
| 181 | |
bsalomon@google.com | 396e61f | 2012-10-25 19:00:29 +0000 | [diff] [blame] | 182 | GrGLSweepGradient(const GrBackendEffectFactory& factory, |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 183 | const GrDrawEffect&) : INHERITED (factory) { } |
rileya@google.com | d7cc651 | 2012-07-27 14:00:39 +0000 | [diff] [blame] | 184 | virtual ~GrGLSweepGradient() { } |
| 185 | |
bsalomon@google.com | f78df33 | 2012-10-29 12:43:38 +0000 | [diff] [blame] | 186 | virtual void emitCode(GrGLShaderBuilder*, |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 187 | const GrDrawEffect&, |
bsalomon | 63e99f7 | 2014-07-21 08:03:14 -0700 | [diff] [blame] | 188 | const GrEffectKey&, |
bsalomon@google.com | f78df33 | 2012-10-29 12:43:38 +0000 | [diff] [blame] | 189 | const char* outputColor, |
| 190 | const char* inputColor, |
bsalomon@google.com | 77af680 | 2013-10-02 13:04:56 +0000 | [diff] [blame] | 191 | const TransformedCoordsArray&, |
bsalomon@google.com | f78df33 | 2012-10-29 12:43:38 +0000 | [diff] [blame] | 192 | const TextureSamplerArray&) SK_OVERRIDE; |
rileya@google.com | d7cc651 | 2012-07-27 14:00:39 +0000 | [diff] [blame] | 193 | |
bsalomon | 63e99f7 | 2014-07-21 08:03:14 -0700 | [diff] [blame] | 194 | static void GenKey(const GrDrawEffect& drawEffect, const GrGLCaps&, GrEffectKeyBuilder* b) { |
| 195 | b->add32(GenBaseGradientKey(drawEffect)); |
bsalomon@google.com | d8b5fac | 2012-11-01 17:02:46 +0000 | [diff] [blame] | 196 | } |
rileya@google.com | d7cc651 | 2012-07-27 14:00:39 +0000 | [diff] [blame] | 197 | |
| 198 | private: |
| 199 | |
bsalomon@google.com | 0707c29 | 2012-10-25 21:45:42 +0000 | [diff] [blame] | 200 | typedef GrGLGradientEffect INHERITED; |
rileya@google.com | d7cc651 | 2012-07-27 14:00:39 +0000 | [diff] [blame] | 201 | |
| 202 | }; |
| 203 | |
rileya@google.com | 98e8b6d | 2012-07-31 20:38:06 +0000 | [diff] [blame] | 204 | ///////////////////////////////////////////////////////////////////// |
| 205 | |
| 206 | class GrSweepGradient : public GrGradientEffect { |
| 207 | public: |
bsalomon | 83d081a | 2014-07-08 09:56:10 -0700 | [diff] [blame] | 208 | static GrEffect* Create(GrContext* ctx, const SkSweepGradient& shader, const SkMatrix& m) { |
| 209 | return SkNEW_ARGS(GrSweepGradient, (ctx, shader, m)); |
bsalomon@google.com | 0ac6af4 | 2013-01-16 15:16:18 +0000 | [diff] [blame] | 210 | } |
rileya@google.com | 98e8b6d | 2012-07-31 20:38:06 +0000 | [diff] [blame] | 211 | virtual ~GrSweepGradient() { } |
| 212 | |
| 213 | static const char* Name() { return "Sweep Gradient"; } |
bsalomon@google.com | 396e61f | 2012-10-25 19:00:29 +0000 | [diff] [blame] | 214 | virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE { |
| 215 | return GrTBackendEffectFactory<GrSweepGradient>::getInstance(); |
rileya@google.com | 98e8b6d | 2012-07-31 20:38:06 +0000 | [diff] [blame] | 216 | } |
| 217 | |
bsalomon@google.com | 422e81a | 2012-10-25 14:11:03 +0000 | [diff] [blame] | 218 | typedef GrGLSweepGradient GLEffect; |
rileya@google.com | 98e8b6d | 2012-07-31 20:38:06 +0000 | [diff] [blame] | 219 | |
bsalomon@google.com | d472620 | 2012-08-03 14:34:46 +0000 | [diff] [blame] | 220 | private: |
bsalomon@google.com | 0ac6af4 | 2013-01-16 15:16:18 +0000 | [diff] [blame] | 221 | GrSweepGradient(GrContext* ctx, |
| 222 | const SkSweepGradient& shader, |
| 223 | const SkMatrix& matrix) |
| 224 | : INHERITED(ctx, shader, matrix, SkShader::kClamp_TileMode) { } |
bsalomon@google.com | f271cc7 | 2012-10-24 19:35:13 +0000 | [diff] [blame] | 225 | GR_DECLARE_EFFECT_TEST; |
rileya@google.com | 98e8b6d | 2012-07-31 20:38:06 +0000 | [diff] [blame] | 226 | |
| 227 | typedef GrGradientEffect INHERITED; |
| 228 | }; |
| 229 | |
| 230 | ///////////////////////////////////////////////////////////////////// |
| 231 | |
bsalomon@google.com | f271cc7 | 2012-10-24 19:35:13 +0000 | [diff] [blame] | 232 | GR_DEFINE_EFFECT_TEST(GrSweepGradient); |
bsalomon@google.com | d472620 | 2012-08-03 14:34:46 +0000 | [diff] [blame] | 233 | |
bsalomon | 83d081a | 2014-07-08 09:56:10 -0700 | [diff] [blame] | 234 | GrEffect* GrSweepGradient::TestCreate(SkRandom* random, |
bsalomon@google.com | 0ac6af4 | 2013-01-16 15:16:18 +0000 | [diff] [blame] | 235 | GrContext* context, |
bsalomon@google.com | c26d94f | 2013-03-25 18:19:00 +0000 | [diff] [blame] | 236 | const GrDrawTargetCaps&, |
bsalomon@google.com | 0ac6af4 | 2013-01-16 15:16:18 +0000 | [diff] [blame] | 237 | GrTexture**) { |
bsalomon@google.com | d472620 | 2012-08-03 14:34:46 +0000 | [diff] [blame] | 238 | SkPoint center = {random->nextUScalar1(), random->nextUScalar1()}; |
| 239 | |
| 240 | SkColor colors[kMaxRandomGradientColors]; |
| 241 | SkScalar stopsArray[kMaxRandomGradientColors]; |
| 242 | SkScalar* stops = stopsArray; |
| 243 | SkShader::TileMode tmIgnored; |
| 244 | int colorCount = RandomGradientParams(random, colors, &stops, &tmIgnored); |
| 245 | SkAutoTUnref<SkShader> shader(SkGradientShader::CreateSweep(center.fX, center.fY, |
| 246 | colors, stops, colorCount)); |
bsalomon@google.com | e197cbf | 2013-01-14 16:46:26 +0000 | [diff] [blame] | 247 | SkPaint paint; |
bsalomon | 83d081a | 2014-07-08 09:56:10 -0700 | [diff] [blame] | 248 | GrEffect* effect; |
| 249 | GrColor paintColor; |
| 250 | SkAssertResult(shader->asNewEffect(context, paint, NULL, &paintColor, &effect)); |
dandov | 9de5b51 | 2014-06-10 14:38:28 -0700 | [diff] [blame] | 251 | return effect; |
bsalomon@google.com | d472620 | 2012-08-03 14:34:46 +0000 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | ///////////////////////////////////////////////////////////////////// |
| 255 | |
bsalomon@google.com | f78df33 | 2012-10-29 12:43:38 +0000 | [diff] [blame] | 256 | void GrGLSweepGradient::emitCode(GrGLShaderBuilder* builder, |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 257 | const GrDrawEffect&, |
bsalomon | 63e99f7 | 2014-07-21 08:03:14 -0700 | [diff] [blame] | 258 | const GrEffectKey& key, |
bsalomon@google.com | f78df33 | 2012-10-29 12:43:38 +0000 | [diff] [blame] | 259 | const char* outputColor, |
| 260 | const char* inputColor, |
bsalomon@google.com | 77af680 | 2013-10-02 13:04:56 +0000 | [diff] [blame] | 261 | const TransformedCoordsArray& coords, |
bsalomon@google.com | f78df33 | 2012-10-29 12:43:38 +0000 | [diff] [blame] | 262 | const TextureSamplerArray& samplers) { |
bsalomon | 63e99f7 | 2014-07-21 08:03:14 -0700 | [diff] [blame] | 263 | uint32_t baseKey = key.get32(0); |
| 264 | this->emitUniforms(builder, baseKey); |
bsalomon@google.com | 77af680 | 2013-10-02 13:04:56 +0000 | [diff] [blame] | 265 | SkString coords2D = builder->ensureFSCoords2D(coords, 0); |
commit-bot@chromium.org | 54318d3 | 2014-02-14 17:27:04 +0000 | [diff] [blame] | 266 | const GrGLContextInfo ctxInfo = builder->ctxInfo(); |
rileya@google.com | d7cc651 | 2012-07-27 14:00:39 +0000 | [diff] [blame] | 267 | SkString t; |
commit-bot@chromium.org | 54318d3 | 2014-02-14 17:27:04 +0000 | [diff] [blame] | 268 | // 0.1591549430918 is 1/(2*pi), used since atan returns values [-pi, pi] |
| 269 | // On Intel GPU there is an issue where it reads the second arguement to atan "- %s.x" as an int |
| 270 | // thus must us -1.0 * %s.x to work correctly |
| 271 | if (kIntel_GrGLVendor != ctxInfo.vendor()){ |
| 272 | t.printf("atan(- %s.y, - %s.x) * 0.1591549430918 + 0.5", |
| 273 | coords2D.c_str(), coords2D.c_str()); |
| 274 | } else { |
| 275 | t.printf("atan(- %s.y, -1.0 * %s.x) * 0.1591549430918 + 0.5", |
| 276 | coords2D.c_str(), coords2D.c_str()); |
| 277 | } |
bsalomon | 63e99f7 | 2014-07-21 08:03:14 -0700 | [diff] [blame] | 278 | this->emitColor(builder, t.c_str(), baseKey, outputColor, inputColor, samplers); |
rileya@google.com | d7cc651 | 2012-07-27 14:00:39 +0000 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | ///////////////////////////////////////////////////////////////////// |
| 282 | |
dandov | 9de5b51 | 2014-06-10 14:38:28 -0700 | [diff] [blame] | 283 | bool SkSweepGradient::asNewEffect(GrContext* context, const SkPaint& paint, |
bsalomon | 83d081a | 2014-07-08 09:56:10 -0700 | [diff] [blame] | 284 | const SkMatrix* localMatrix, GrColor* paintColor, |
| 285 | GrEffect** effect) const { |
dandov | 9de5b51 | 2014-06-10 14:38:28 -0700 | [diff] [blame] | 286 | |
bsalomon@google.com | dfdb7e5 | 2012-10-16 15:19:45 +0000 | [diff] [blame] | 287 | SkMatrix matrix; |
bsalomon@google.com | f94b3a4 | 2012-10-31 18:09:01 +0000 | [diff] [blame] | 288 | if (!this->getLocalMatrix().invert(&matrix)) { |
dandov | 9de5b51 | 2014-06-10 14:38:28 -0700 | [diff] [blame] | 289 | return false; |
bsalomon@google.com | dfdb7e5 | 2012-10-16 15:19:45 +0000 | [diff] [blame] | 290 | } |
commit-bot@chromium.org | 96fb748 | 2014-05-09 20:28:11 +0000 | [diff] [blame] | 291 | if (localMatrix) { |
| 292 | SkMatrix inv; |
| 293 | if (!localMatrix->invert(&inv)) { |
dandov | 9de5b51 | 2014-06-10 14:38:28 -0700 | [diff] [blame] | 294 | return false; |
commit-bot@chromium.org | 96fb748 | 2014-05-09 20:28:11 +0000 | [diff] [blame] | 295 | } |
| 296 | matrix.postConcat(inv); |
| 297 | } |
bsalomon@google.com | f94b3a4 | 2012-10-31 18:09:01 +0000 | [diff] [blame] | 298 | matrix.postConcat(fPtsToUnit); |
dandov | 9de5b51 | 2014-06-10 14:38:28 -0700 | [diff] [blame] | 299 | |
bsalomon | 83d081a | 2014-07-08 09:56:10 -0700 | [diff] [blame] | 300 | *effect = GrSweepGradient::Create(context, *this, matrix); |
| 301 | *paintColor = SkColor2GrColorJustAlpha(paint.getColor()); |
dandov | 9de5b51 | 2014-06-10 14:38:28 -0700 | [diff] [blame] | 302 | |
| 303 | return true; |
rileya@google.com | d7cc651 | 2012-07-27 14:00:39 +0000 | [diff] [blame] | 304 | } |
| 305 | |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 306 | #else |
| 307 | |
dandov | 9de5b51 | 2014-06-10 14:38:28 -0700 | [diff] [blame] | 308 | bool SkSweepGradient::asNewEffect(GrContext* context, const SkPaint& paint, |
bsalomon | 83d081a | 2014-07-08 09:56:10 -0700 | [diff] [blame] | 309 | const SkMatrix* localMatrix, GrColor* paintColor, |
| 310 | GrEffect** effect) const { |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 311 | SkDEBUGFAIL("Should not call in GPU-less build"); |
dandov | 9de5b51 | 2014-06-10 14:38:28 -0700 | [diff] [blame] | 312 | return false; |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | #endif |
robertphillips@google.com | 76f9e93 | 2013-01-15 20:17:47 +0000 | [diff] [blame] | 316 | |
commit-bot@chromium.org | 0f10f7b | 2014-03-13 18:02:17 +0000 | [diff] [blame] | 317 | #ifndef SK_IGNORE_TO_STRING |
robertphillips@google.com | 76f9e93 | 2013-01-15 20:17:47 +0000 | [diff] [blame] | 318 | void SkSweepGradient::toString(SkString* str) const { |
| 319 | str->append("SkSweepGradient: ("); |
| 320 | |
| 321 | str->append("center: ("); |
| 322 | str->appendScalar(fCenter.fX); |
| 323 | str->append(", "); |
| 324 | str->appendScalar(fCenter.fY); |
| 325 | str->append(") "); |
| 326 | |
| 327 | this->INHERITED::toString(str); |
| 328 | |
| 329 | str->append(")"); |
| 330 | } |
| 331 | #endif |