| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2012 Google Inc. | 3 * Copyright 2012 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 #include "SkSweepGradient.h" | 9 #include "SkSweepGradient.h" |
| 10 | 10 |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 private: | 198 private: |
| 199 | 199 |
| 200 typedef GrGLGradientEffect INHERITED; | 200 typedef GrGLGradientEffect INHERITED; |
| 201 | 201 |
| 202 }; | 202 }; |
| 203 | 203 |
| 204 ///////////////////////////////////////////////////////////////////// | 204 ///////////////////////////////////////////////////////////////////// |
| 205 | 205 |
| 206 class GrSweepGradient : public GrGradientEffect { | 206 class GrSweepGradient : public GrGradientEffect { |
| 207 public: | 207 public: |
| 208 static GrEffectRef* Create(GrContext* ctx, | 208 static GrEffect* Create(GrContext* ctx, const SkSweepGradient& shader, const
SkMatrix& m) { |
| 209 const SkSweepGradient& shader, | 209 return SkNEW_ARGS(GrSweepGradient, (ctx, shader, m)); |
| 210 const SkMatrix& matrix) { | |
| 211 return SkNEW_ARGS(GrSweepGradient, (ctx, shader, matrix)); | |
| 212 } | 210 } |
| 213 virtual ~GrSweepGradient() { } | 211 virtual ~GrSweepGradient() { } |
| 214 | 212 |
| 215 static const char* Name() { return "Sweep Gradient"; } | 213 static const char* Name() { return "Sweep Gradient"; } |
| 216 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE { | 214 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE { |
| 217 return GrTBackendEffectFactory<GrSweepGradient>::getInstance(); | 215 return GrTBackendEffectFactory<GrSweepGradient>::getInstance(); |
| 218 } | 216 } |
| 219 | 217 |
| 220 typedef GrGLSweepGradient GLEffect; | 218 typedef GrGLSweepGradient GLEffect; |
| 221 | 219 |
| 222 private: | 220 private: |
| 223 GrSweepGradient(GrContext* ctx, | 221 GrSweepGradient(GrContext* ctx, |
| 224 const SkSweepGradient& shader, | 222 const SkSweepGradient& shader, |
| 225 const SkMatrix& matrix) | 223 const SkMatrix& matrix) |
| 226 : INHERITED(ctx, shader, matrix, SkShader::kClamp_TileMode) { } | 224 : INHERITED(ctx, shader, matrix, SkShader::kClamp_TileMode) { } |
| 227 GR_DECLARE_EFFECT_TEST; | 225 GR_DECLARE_EFFECT_TEST; |
| 228 | 226 |
| 229 typedef GrGradientEffect INHERITED; | 227 typedef GrGradientEffect INHERITED; |
| 230 }; | 228 }; |
| 231 | 229 |
| 232 ///////////////////////////////////////////////////////////////////// | 230 ///////////////////////////////////////////////////////////////////// |
| 233 | 231 |
| 234 GR_DEFINE_EFFECT_TEST(GrSweepGradient); | 232 GR_DEFINE_EFFECT_TEST(GrSweepGradient); |
| 235 | 233 |
| 236 GrEffectRef* GrSweepGradient::TestCreate(SkRandom* random, | 234 GrEffect* GrSweepGradient::TestCreate(SkRandom* random, |
| 237 GrContext* context, | 235 GrContext* context, |
| 238 const GrDrawTargetCaps&, | 236 const GrDrawTargetCaps&, |
| 239 GrTexture**) { | 237 GrTexture**) { |
| 240 SkPoint center = {random->nextUScalar1(), random->nextUScalar1()}; | 238 SkPoint center = {random->nextUScalar1(), random->nextUScalar1()}; |
| 241 | 239 |
| 242 SkColor colors[kMaxRandomGradientColors]; | 240 SkColor colors[kMaxRandomGradientColors]; |
| 243 SkScalar stopsArray[kMaxRandomGradientColors]; | 241 SkScalar stopsArray[kMaxRandomGradientColors]; |
| 244 SkScalar* stops = stopsArray; | 242 SkScalar* stops = stopsArray; |
| 245 SkShader::TileMode tmIgnored; | 243 SkShader::TileMode tmIgnored; |
| 246 int colorCount = RandomGradientParams(random, colors, &stops, &tmIgnored); | 244 int colorCount = RandomGradientParams(random, colors, &stops, &tmIgnored); |
| 247 SkAutoTUnref<SkShader> shader(SkGradientShader::CreateSweep(center.fX, cente
r.fY, | 245 SkAutoTUnref<SkShader> shader(SkGradientShader::CreateSweep(center.fX, cente
r.fY, |
| 248 colors, stops, c
olorCount)); | 246 colors, stops, c
olorCount)); |
| 249 SkPaint paint; | 247 SkPaint paint; |
| 250 GrEffectRef* effect; | 248 GrEffect* effect; |
| 251 GrColor grColor; | 249 GrColor paintColor; |
| 252 shader->asNewEffect(context, paint, NULL, &grColor, &effect); | 250 SkAssertResult(shader->asNewEffect(context, paint, NULL, &paintColor, &effec
t)); |
| 253 return effect; | 251 return effect; |
| 254 } | 252 } |
| 255 | 253 |
| 256 ///////////////////////////////////////////////////////////////////// | 254 ///////////////////////////////////////////////////////////////////// |
| 257 | 255 |
| 258 void GrGLSweepGradient::emitCode(GrGLShaderBuilder* builder, | 256 void GrGLSweepGradient::emitCode(GrGLShaderBuilder* builder, |
| 259 const GrDrawEffect&, | 257 const GrDrawEffect&, |
| 260 EffectKey key, | 258 EffectKey key, |
| 261 const char* outputColor, | 259 const char* outputColor, |
| 262 const char* inputColor, | 260 const char* inputColor, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 276 t.printf("atan(- %s.y, -1.0 * %s.x) * 0.1591549430918 + 0.5", | 274 t.printf("atan(- %s.y, -1.0 * %s.x) * 0.1591549430918 + 0.5", |
| 277 coords2D.c_str(), coords2D.c_str()); | 275 coords2D.c_str(), coords2D.c_str()); |
| 278 } | 276 } |
| 279 this->emitColor(builder, t.c_str(), key, | 277 this->emitColor(builder, t.c_str(), key, |
| 280 outputColor, inputColor, samplers); | 278 outputColor, inputColor, samplers); |
| 281 } | 279 } |
| 282 | 280 |
| 283 ///////////////////////////////////////////////////////////////////// | 281 ///////////////////////////////////////////////////////////////////// |
| 284 | 282 |
| 285 bool SkSweepGradient::asNewEffect(GrContext* context, const SkPaint& paint, | 283 bool SkSweepGradient::asNewEffect(GrContext* context, const SkPaint& paint, |
| 286 const SkMatrix* localMatrix, GrColor* grColor, | 284 const SkMatrix* localMatrix, GrColor* paintCol
or, |
| 287 GrEffectRef** grEffect) const { | 285 GrEffect** effect) const { |
| 288 | 286 |
| 289 SkMatrix matrix; | 287 SkMatrix matrix; |
| 290 if (!this->getLocalMatrix().invert(&matrix)) { | 288 if (!this->getLocalMatrix().invert(&matrix)) { |
| 291 return false; | 289 return false; |
| 292 } | 290 } |
| 293 if (localMatrix) { | 291 if (localMatrix) { |
| 294 SkMatrix inv; | 292 SkMatrix inv; |
| 295 if (!localMatrix->invert(&inv)) { | 293 if (!localMatrix->invert(&inv)) { |
| 296 return false; | 294 return false; |
| 297 } | 295 } |
| 298 matrix.postConcat(inv); | 296 matrix.postConcat(inv); |
| 299 } | 297 } |
| 300 matrix.postConcat(fPtsToUnit); | 298 matrix.postConcat(fPtsToUnit); |
| 301 | 299 |
| 302 *grEffect = GrSweepGradient::Create(context, *this, matrix); | 300 *effect = GrSweepGradient::Create(context, *this, matrix); |
| 303 *grColor = SkColor2GrColorJustAlpha(paint.getColor()); | 301 *paintColor = SkColor2GrColorJustAlpha(paint.getColor()); |
| 304 | 302 |
| 305 return true; | 303 return true; |
| 306 } | 304 } |
| 307 | 305 |
| 308 #else | 306 #else |
| 309 | 307 |
| 310 bool SkSweepGradient::asNewEffect(GrContext* context, const SkPaint& paint, | 308 bool SkSweepGradient::asNewEffect(GrContext* context, const SkPaint& paint, |
| 311 const SkMatrix* localMatrix, GrColor* grColor, | 309 const SkMatrix* localMatrix, GrColor* paintCol
or, |
| 312 GrEffect** grEffect) const { | 310 GrEffect** effect) const { |
| 313 SkDEBUGFAIL("Should not call in GPU-less build"); | 311 SkDEBUGFAIL("Should not call in GPU-less build"); |
| 314 return false; | 312 return false; |
| 315 } | 313 } |
| 316 | 314 |
| 317 #endif | 315 #endif |
| 318 | 316 |
| 319 #ifndef SK_IGNORE_TO_STRING | 317 #ifndef SK_IGNORE_TO_STRING |
| 320 void SkSweepGradient::toString(SkString* str) const { | 318 void SkSweepGradient::toString(SkString* str) const { |
| 321 str->append("SkSweepGradient: ("); | 319 str->append("SkSweepGradient: ("); |
| 322 | 320 |
| 323 str->append("center: ("); | 321 str->append("center: ("); |
| 324 str->appendScalar(fCenter.fX); | 322 str->appendScalar(fCenter.fX); |
| 325 str->append(", "); | 323 str->append(", "); |
| 326 str->appendScalar(fCenter.fY); | 324 str->appendScalar(fCenter.fY); |
| 327 str->append(") "); | 325 str->append(") "); |
| 328 | 326 |
| 329 this->INHERITED::toString(str); | 327 this->INHERITED::toString(str); |
| 330 | 328 |
| 331 str->append(")"); | 329 str->append(")"); |
| 332 } | 330 } |
| 333 #endif | 331 #endif |
| OLD | NEW |