| 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 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 toggle = next_dither_toggle16(toggle); | 167 toggle = next_dither_toggle16(toggle); |
| 168 } | 168 } |
| 169 } | 169 } |
| 170 } | 170 } |
| 171 | 171 |
| 172 ///////////////////////////////////////////////////////////////////// | 172 ///////////////////////////////////////////////////////////////////// |
| 173 | 173 |
| 174 #if SK_SUPPORT_GPU | 174 #if SK_SUPPORT_GPU |
| 175 | 175 |
| 176 #include "GrTBackendEffectFactory.h" | 176 #include "GrTBackendEffectFactory.h" |
| 177 #include "SkGr.h" |
| 177 | 178 |
| 178 class GrGLSweepGradient : public GrGLGradientEffect { | 179 class GrGLSweepGradient : public GrGLGradientEffect { |
| 179 public: | 180 public: |
| 180 | 181 |
| 181 GrGLSweepGradient(const GrBackendEffectFactory& factory, | 182 GrGLSweepGradient(const GrBackendEffectFactory& factory, |
| 182 const GrDrawEffect&) : INHERITED (factory) { } | 183 const GrDrawEffect&) : INHERITED (factory) { } |
| 183 virtual ~GrGLSweepGradient() { } | 184 virtual ~GrGLSweepGradient() { } |
| 184 | 185 |
| 185 virtual void emitCode(GrGLShaderBuilder*, | 186 virtual void emitCode(GrGLShaderBuilder*, |
| 186 const GrDrawEffect&, | 187 const GrDrawEffect&, |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 SkPoint center = {random->nextUScalar1(), random->nextUScalar1()}; | 241 SkPoint center = {random->nextUScalar1(), random->nextUScalar1()}; |
| 241 | 242 |
| 242 SkColor colors[kMaxRandomGradientColors]; | 243 SkColor colors[kMaxRandomGradientColors]; |
| 243 SkScalar stopsArray[kMaxRandomGradientColors]; | 244 SkScalar stopsArray[kMaxRandomGradientColors]; |
| 244 SkScalar* stops = stopsArray; | 245 SkScalar* stops = stopsArray; |
| 245 SkShader::TileMode tmIgnored; | 246 SkShader::TileMode tmIgnored; |
| 246 int colorCount = RandomGradientParams(random, colors, &stops, &tmIgnored); | 247 int colorCount = RandomGradientParams(random, colors, &stops, &tmIgnored); |
| 247 SkAutoTUnref<SkShader> shader(SkGradientShader::CreateSweep(center.fX, cente
r.fY, | 248 SkAutoTUnref<SkShader> shader(SkGradientShader::CreateSweep(center.fX, cente
r.fY, |
| 248 colors, stops, c
olorCount)); | 249 colors, stops, c
olorCount)); |
| 249 SkPaint paint; | 250 SkPaint paint; |
| 250 return shader->asNewEffect(context, paint, NULL); | 251 GrEffectRef* effect; |
| 252 GrColor grColor; |
| 253 shader->asNewEffect(context, paint, NULL, &grColor, &effect); |
| 254 return effect; |
| 251 } | 255 } |
| 252 | 256 |
| 253 ///////////////////////////////////////////////////////////////////// | 257 ///////////////////////////////////////////////////////////////////// |
| 254 | 258 |
| 255 void GrGLSweepGradient::emitCode(GrGLShaderBuilder* builder, | 259 void GrGLSweepGradient::emitCode(GrGLShaderBuilder* builder, |
| 256 const GrDrawEffect&, | 260 const GrDrawEffect&, |
| 257 EffectKey key, | 261 EffectKey key, |
| 258 const char* outputColor, | 262 const char* outputColor, |
| 259 const char* inputColor, | 263 const char* inputColor, |
| 260 const TransformedCoordsArray& coords, | 264 const TransformedCoordsArray& coords, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 272 } else { | 276 } else { |
| 273 t.printf("atan(- %s.y, -1.0 * %s.x) * 0.1591549430918 + 0.5", | 277 t.printf("atan(- %s.y, -1.0 * %s.x) * 0.1591549430918 + 0.5", |
| 274 coords2D.c_str(), coords2D.c_str()); | 278 coords2D.c_str(), coords2D.c_str()); |
| 275 } | 279 } |
| 276 this->emitColor(builder, t.c_str(), key, | 280 this->emitColor(builder, t.c_str(), key, |
| 277 outputColor, inputColor, samplers); | 281 outputColor, inputColor, samplers); |
| 278 } | 282 } |
| 279 | 283 |
| 280 ///////////////////////////////////////////////////////////////////// | 284 ///////////////////////////////////////////////////////////////////// |
| 281 | 285 |
| 282 GrEffectRef* SkSweepGradient::asNewEffect(GrContext* context, const SkPaint&, | 286 bool SkSweepGradient::asNewEffect(GrContext* context, const SkPaint& paint, |
| 283 const SkMatrix* localMatrix) const { | 287 const SkMatrix* localMatrix, GrColor* grColor, |
| 288 GrEffectRef** grEffect) const { |
| 289 |
| 284 SkMatrix matrix; | 290 SkMatrix matrix; |
| 285 if (!this->getLocalMatrix().invert(&matrix)) { | 291 if (!this->getLocalMatrix().invert(&matrix)) { |
| 286 return NULL; | 292 return false; |
| 287 } | 293 } |
| 288 if (localMatrix) { | 294 if (localMatrix) { |
| 289 SkMatrix inv; | 295 SkMatrix inv; |
| 290 if (!localMatrix->invert(&inv)) { | 296 if (!localMatrix->invert(&inv)) { |
| 291 return NULL; | 297 return false; |
| 292 } | 298 } |
| 293 matrix.postConcat(inv); | 299 matrix.postConcat(inv); |
| 294 } | 300 } |
| 295 matrix.postConcat(fPtsToUnit); | 301 matrix.postConcat(fPtsToUnit); |
| 296 return GrSweepGradient::Create(context, *this, matrix); | 302 |
| 303 *grEffect = GrSweepGradient::Create(context, *this, matrix); |
| 304 *grColor = SkColor2GrColorJustAlpha(paint.getColor()); |
| 305 |
| 306 return true; |
| 297 } | 307 } |
| 298 | 308 |
| 299 #else | 309 #else |
| 300 | 310 |
| 301 GrEffectRef* SkSweepGradient::asNewEffect(GrContext*, const SkPaint&, const SkMa
trix*) const { | 311 bool SkSweepGradient::asNewEffect(GrContext* context, const SkPaint& paint, |
| 312 const SkMatrix* localMatrix, GrColor* grColor, |
| 313 GrEffectRef** grEffect) const { |
| 302 SkDEBUGFAIL("Should not call in GPU-less build"); | 314 SkDEBUGFAIL("Should not call in GPU-less build"); |
| 303 return NULL; | 315 return false; |
| 304 } | 316 } |
| 305 | 317 |
| 306 #endif | 318 #endif |
| 307 | 319 |
| 308 #ifndef SK_IGNORE_TO_STRING | 320 #ifndef SK_IGNORE_TO_STRING |
| 309 void SkSweepGradient::toString(SkString* str) const { | 321 void SkSweepGradient::toString(SkString* str) const { |
| 310 str->append("SkSweepGradient: ("); | 322 str->append("SkSweepGradient: ("); |
| 311 | 323 |
| 312 str->append("center: ("); | 324 str->append("center: ("); |
| 313 str->appendScalar(fCenter.fX); | 325 str->appendScalar(fCenter.fX); |
| 314 str->append(", "); | 326 str->append(", "); |
| 315 str->appendScalar(fCenter.fY); | 327 str->appendScalar(fCenter.fY); |
| 316 str->append(") "); | 328 str->append(") "); |
| 317 | 329 |
| 318 this->INHERITED::toString(str); | 330 this->INHERITED::toString(str); |
| 319 | 331 |
| 320 str->append(")"); | 332 str->append(")"); |
| 321 } | 333 } |
| 322 #endif | 334 #endif |
| OLD | NEW |