Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(140)

Side by Side Diff: src/effects/gradients/SkSweepGradient.cpp

Issue 318923005: SkShader::asNewEffect Refactoring (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: SkColorShader refactor and fix Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 SkPoint center = {random->nextUScalar1(), random->nextUScalar1()}; 240 SkPoint center = {random->nextUScalar1(), random->nextUScalar1()};
241 241
242 SkColor colors[kMaxRandomGradientColors]; 242 SkColor colors[kMaxRandomGradientColors];
243 SkScalar stopsArray[kMaxRandomGradientColors]; 243 SkScalar stopsArray[kMaxRandomGradientColors];
244 SkScalar* stops = stopsArray; 244 SkScalar* stops = stopsArray;
245 SkShader::TileMode tmIgnored; 245 SkShader::TileMode tmIgnored;
246 int colorCount = RandomGradientParams(random, colors, &stops, &tmIgnored); 246 int colorCount = RandomGradientParams(random, colors, &stops, &tmIgnored);
247 SkAutoTUnref<SkShader> shader(SkGradientShader::CreateSweep(center.fX, cente r.fY, 247 SkAutoTUnref<SkShader> shader(SkGradientShader::CreateSweep(center.fX, cente r.fY,
248 colors, stops, c olorCount)); 248 colors, stops, c olorCount));
249 SkPaint paint; 249 SkPaint paint;
250 return shader->asNewEffect(context, paint, NULL); 250 GrEffectRef* effect;
251 GrColor grColor;
252 shader->asNewEffect(context, paint, NULL, &grColor, &effect);
253 return effect;
251 } 254 }
252 255
253 ///////////////////////////////////////////////////////////////////// 256 /////////////////////////////////////////////////////////////////////
254 257
255 void GrGLSweepGradient::emitCode(GrGLShaderBuilder* builder, 258 void GrGLSweepGradient::emitCode(GrGLShaderBuilder* builder,
256 const GrDrawEffect&, 259 const GrDrawEffect&,
257 EffectKey key, 260 EffectKey key,
258 const char* outputColor, 261 const char* outputColor,
259 const char* inputColor, 262 const char* inputColor,
260 const TransformedCoordsArray& coords, 263 const TransformedCoordsArray& coords,
(...skipping 11 matching lines...) Expand all
272 } else { 275 } else {
273 t.printf("atan(- %s.y, -1.0 * %s.x) * 0.1591549430918 + 0.5", 276 t.printf("atan(- %s.y, -1.0 * %s.x) * 0.1591549430918 + 0.5",
274 coords2D.c_str(), coords2D.c_str()); 277 coords2D.c_str(), coords2D.c_str());
275 } 278 }
276 this->emitColor(builder, t.c_str(), key, 279 this->emitColor(builder, t.c_str(), key,
277 outputColor, inputColor, samplers); 280 outputColor, inputColor, samplers);
278 } 281 }
279 282
280 ///////////////////////////////////////////////////////////////////// 283 /////////////////////////////////////////////////////////////////////
281 284
282 GrEffectRef* SkSweepGradient::asNewEffect(GrContext* context, const SkPaint&, 285 bool SkSweepGradient::asNewEffect(GrContext* context, const SkPaint& paint,
283 const SkMatrix* localMatrix) const { 286 const SkMatrix* localMatrix, GrColor* grColor,
287 GrEffectRef** grEffect) const {
288 *grColor = this->getColorAsAlpha(paint);
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 *grEffect = GrSweepGradient::Create(context, *this, matrix);
303 return NULL != *grEffect;
297 } 304 }
298 305
299 #else 306 #else
300 307
301 GrEffectRef* SkSweepGradient::asNewEffect(GrContext*, const SkPaint&, const SkMa trix*) const { 308 bool SkSweepGradient::asNewEffect(GrContext* context, const SkPaint& paint,
309 const SkMatrix* localMatrix, GrColor* grColor,
310 GrEffectRef** grEffect) const {
302 SkDEBUGFAIL("Should not call in GPU-less build"); 311 SkDEBUGFAIL("Should not call in GPU-less build");
303 return NULL; 312 return false;
304 } 313 }
305 314
306 #endif 315 #endif
307 316
308 #ifndef SK_IGNORE_TO_STRING 317 #ifndef SK_IGNORE_TO_STRING
309 void SkSweepGradient::toString(SkString* str) const { 318 void SkSweepGradient::toString(SkString* str) const {
310 str->append("SkSweepGradient: ("); 319 str->append("SkSweepGradient: (");
311 320
312 str->append("center: ("); 321 str->append("center: (");
313 str->appendScalar(fCenter.fX); 322 str->appendScalar(fCenter.fX);
314 str->append(", "); 323 str->append(", ");
315 str->appendScalar(fCenter.fY); 324 str->appendScalar(fCenter.fY);
316 str->append(") "); 325 str->append(") ");
317 326
318 this->INHERITED::toString(str); 327 this->INHERITED::toString(str);
319 328
320 str->append(")"); 329 str->append(")");
321 } 330 }
322 #endif 331 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698