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 #include "SkGr.h" |
10 | 11 |
11 SkSweepGradient::SkSweepGradient(SkScalar cx, SkScalar cy, | 12 SkSweepGradient::SkSweepGradient(SkScalar cx, SkScalar cy, |
12 const Descriptor& desc, const SkMatrix* localMa
trix) | 13 const Descriptor& desc, const SkMatrix* localMa
trix) |
13 : SkGradientShaderBase(desc, localMatrix) | 14 : SkGradientShaderBase(desc, localMatrix) |
14 , fCenter(SkPoint::Make(cx, cy)) | 15 , fCenter(SkPoint::Make(cx, cy)) |
15 { | 16 { |
16 fPtsToUnit.setTranslate(-cx, -cy); | 17 fPtsToUnit.setTranslate(-cx, -cy); |
17 | 18 |
18 // overwrite the tilemode to a canonical value (since sweep ignores it) | 19 // overwrite the tilemode to a canonical value (since sweep ignores it) |
19 fTileMode = SkShader::kClamp_TileMode; | 20 fTileMode = SkShader::kClamp_TileMode; |
(...skipping 220 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 |