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

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

Issue 2175563003: Bundle SkShader::asFragmentProcessor arguments in a struct (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix indentation to be less arbitrary Created 4 years, 5 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
« no previous file with comments | « src/effects/gradients/SkRadialGradient.h ('k') | src/effects/gradients/SkSweepGradient.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2012 Google Inc. 2 * Copyright 2012 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkRadialGradient.h" 8 #include "SkRadialGradient.h"
9 #include "SkNx.h" 9 #include "SkNx.h"
10 10
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 sk_sp<GrFragmentProcessor> GrRadialGradient::TestCreate(GrProcessorTestData* d) { 305 sk_sp<GrFragmentProcessor> GrRadialGradient::TestCreate(GrProcessorTestData* d) {
306 SkPoint center = {d->fRandom->nextUScalar1(), d->fRandom->nextUScalar1()}; 306 SkPoint center = {d->fRandom->nextUScalar1(), d->fRandom->nextUScalar1()};
307 SkScalar radius = d->fRandom->nextUScalar1(); 307 SkScalar radius = d->fRandom->nextUScalar1();
308 308
309 SkColor colors[kMaxRandomGradientColors]; 309 SkColor colors[kMaxRandomGradientColors];
310 SkScalar stopsArray[kMaxRandomGradientColors]; 310 SkScalar stopsArray[kMaxRandomGradientColors];
311 SkScalar* stops = stopsArray; 311 SkScalar* stops = stopsArray;
312 SkShader::TileMode tm; 312 SkShader::TileMode tm;
313 int colorCount = RandomGradientParams(d->fRandom, colors, &stops, &tm); 313 int colorCount = RandomGradientParams(d->fRandom, colors, &stops, &tm);
314 auto shader = SkGradientShader::MakeRadial(center, radius, colors, stops, co lorCount, tm); 314 auto shader = SkGradientShader::MakeRadial(center, radius, colors, stops, co lorCount, tm);
315 sk_sp<GrFragmentProcessor> fp = shader->asFragmentProcessor(d->fContext, 315 SkMatrix viewMatrix = GrTest::TestMatrix(d->fRandom);
316 GrTest::TestMatrix(d->fRandom), NULL, kNone_SkFilterQuality, 316 sk_sp<GrFragmentProcessor> fp = shader->asFragmentProcessor(SkShader::AsFPAr gs(
317 SkSourceGammaTreatment::kRespect); 317 d->fContext, &viewMatrix, NULL, kNone_SkFilterQuality, SkSourceGammaTrea tment::kRespect));
318 GrAlwaysAssert(fp); 318 GrAlwaysAssert(fp);
319 return fp; 319 return fp;
320 } 320 }
321 321
322 ///////////////////////////////////////////////////////////////////// 322 /////////////////////////////////////////////////////////////////////
323 323
324 void GrGLRadialGradient::emitCode(EmitArgs& args) { 324 void GrGLRadialGradient::emitCode(EmitArgs& args) {
325 const GrRadialGradient& ge = args.fFp.cast<GrRadialGradient>(); 325 const GrRadialGradient& ge = args.fFp.cast<GrRadialGradient>();
326 this->emitUniforms(args.fUniformHandler, ge); 326 this->emitUniforms(args.fUniformHandler, ge);
327 SkString t("length("); 327 SkString t("length(");
328 t.append(args.fFragBuilder->ensureFSCoords2D(args.fCoords, 0)); 328 t.append(args.fFragBuilder->ensureFSCoords2D(args.fCoords, 0));
329 t.append(")"); 329 t.append(")");
330 this->emitColor(args.fFragBuilder, 330 this->emitColor(args.fFragBuilder,
331 args.fUniformHandler, 331 args.fUniformHandler,
332 args.fGLSLCaps, 332 args.fGLSLCaps,
333 ge, t.c_str(), 333 ge, t.c_str(),
334 args.fOutputColor, 334 args.fOutputColor,
335 args.fInputColor, 335 args.fInputColor,
336 args.fTexSamplers); 336 args.fTexSamplers);
337 } 337 }
338 338
339 ///////////////////////////////////////////////////////////////////// 339 /////////////////////////////////////////////////////////////////////
340 340
341 sk_sp<GrFragmentProcessor> SkRadialGradient::asFragmentProcessor( 341 sk_sp<GrFragmentProcessor> SkRadialGradient::asFragmentProcessor(const AsFPArgs& args) const {
342 GrContext* context, 342 SkASSERT(args.fContext);
343 const SkMatrix& viewM,
344 const SkMatrix* localMatrix,
345 SkFilterQuality,
346 SkSourceGammaTreatment) const {
347 SkASSERT(context);
348 343
349 SkMatrix matrix; 344 SkMatrix matrix;
350 if (!this->getLocalMatrix().invert(&matrix)) { 345 if (!this->getLocalMatrix().invert(&matrix)) {
351 return nullptr; 346 return nullptr;
352 } 347 }
353 if (localMatrix) { 348 if (args.fLocalMatrix) {
354 SkMatrix inv; 349 SkMatrix inv;
355 if (!localMatrix->invert(&inv)) { 350 if (!args.fLocalMatrix->invert(&inv)) {
356 return nullptr; 351 return nullptr;
357 } 352 }
358 matrix.postConcat(inv); 353 matrix.postConcat(inv);
359 } 354 }
360 matrix.postConcat(fPtsToUnit); 355 matrix.postConcat(fPtsToUnit);
361 sk_sp<GrFragmentProcessor> inner(GrRadialGradient::Make(context, *this, matr ix, fTileMode)); 356 sk_sp<GrFragmentProcessor> inner(
357 GrRadialGradient::Make(args.fContext, *this, matrix, fTileMode));
362 return GrFragmentProcessor::MulOutputByInputAlpha(std::move(inner)); 358 return GrFragmentProcessor::MulOutputByInputAlpha(std::move(inner));
363 } 359 }
364 360
365 #endif 361 #endif
366 362
367 #ifndef SK_IGNORE_TO_STRING 363 #ifndef SK_IGNORE_TO_STRING
368 void SkRadialGradient::toString(SkString* str) const { 364 void SkRadialGradient::toString(SkString* str) const {
369 str->append("SkRadialGradient: ("); 365 str->append("SkRadialGradient: (");
370 366
371 str->append("center: ("); 367 str->append("center: (");
372 str->appendScalar(fCenter.fX); 368 str->appendScalar(fCenter.fX);
373 str->append(", "); 369 str->append(", ");
374 str->appendScalar(fCenter.fY); 370 str->appendScalar(fCenter.fY);
375 str->append(") radius: "); 371 str->append(") radius: ");
376 str->appendScalar(fRadius); 372 str->appendScalar(fRadius);
377 str->append(" "); 373 str->append(" ");
378 374
379 this->INHERITED::toString(str); 375 this->INHERITED::toString(str);
380 376
381 str->append(")"); 377 str->append(")");
382 } 378 }
383 #endif 379 #endif
OLDNEW
« no previous file with comments | « src/effects/gradients/SkRadialGradient.h ('k') | src/effects/gradients/SkSweepGradient.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698