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