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

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

Issue 2041113004: sk_sp for gpu. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Reserve correctly. Created 4 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
« no previous file with comments | « src/effects/gradients/SkLinearGradient.h ('k') | src/effects/gradients/SkRadialGradient.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 "Sk4fLinearGradient.h" 8 #include "Sk4fLinearGradient.h"
9 #include "SkLinearGradient.h" 9 #include "SkLinearGradient.h"
10 #include "SkRefCnt.h"
10 11
11 // define to test the 4f gradient path 12 // define to test the 4f gradient path
12 // #define FORCE_4F_CONTEXT 13 // #define FORCE_4F_CONTEXT
13 14
14 static const float kInv255Float = 1.0f / 255; 15 static const float kInv255Float = 1.0f / 255;
15 16
16 static inline int repeat_8bits(int x) { 17 static inline int repeat_8bits(int x) {
17 return x & 0xFF; 18 return x & 0xFF;
18 } 19 }
19 20
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 private: 363 private:
363 364
364 typedef GrGLGradientEffect INHERITED; 365 typedef GrGLGradientEffect INHERITED;
365 }; 366 };
366 367
367 ///////////////////////////////////////////////////////////////////// 368 /////////////////////////////////////////////////////////////////////
368 369
369 class GrLinearGradient : public GrGradientEffect { 370 class GrLinearGradient : public GrGradientEffect {
370 public: 371 public:
371 372
372 static GrFragmentProcessor* Create(GrContext* ctx, 373 static sk_sp<GrFragmentProcessor> Make(GrContext* ctx,
373 const SkLinearGradient& shader, 374 const SkLinearGradient& shader,
374 const SkMatrix& matrix, 375 const SkMatrix& matrix,
375 SkShader::TileMode tm) { 376 SkShader::TileMode tm) {
376 return new GrLinearGradient(ctx, shader, matrix, tm); 377 return sk_sp<GrFragmentProcessor>(new GrLinearGradient(ctx, shader, matr ix, tm));
377 } 378 }
378 379
379 virtual ~GrLinearGradient() { } 380 virtual ~GrLinearGradient() { }
380 381
381 const char* name() const override { return "Linear Gradient"; } 382 const char* name() const override { return "Linear Gradient"; }
382 383
383 private: 384 private:
384 GrLinearGradient(GrContext* ctx, 385 GrLinearGradient(GrContext* ctx,
385 const SkLinearGradient& shader, 386 const SkLinearGradient& shader,
386 const SkMatrix& matrix, 387 const SkMatrix& matrix,
(...skipping 13 matching lines...) Expand all
400 401
401 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; 402 GR_DECLARE_FRAGMENT_PROCESSOR_TEST;
402 403
403 typedef GrGradientEffect INHERITED; 404 typedef GrGradientEffect INHERITED;
404 }; 405 };
405 406
406 ///////////////////////////////////////////////////////////////////// 407 /////////////////////////////////////////////////////////////////////
407 408
408 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrLinearGradient); 409 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrLinearGradient);
409 410
410 const GrFragmentProcessor* GrLinearGradient::TestCreate(GrProcessorTestData* d) { 411 sk_sp<GrFragmentProcessor> GrLinearGradient::TestCreate(GrProcessorTestData* d) {
411 SkPoint points[] = {{d->fRandom->nextUScalar1(), d->fRandom->nextUScalar1()} , 412 SkPoint points[] = {{d->fRandom->nextUScalar1(), d->fRandom->nextUScalar1()} ,
412 {d->fRandom->nextUScalar1(), d->fRandom->nextUScalar1()} }; 413 {d->fRandom->nextUScalar1(), d->fRandom->nextUScalar1()} };
413 414
414 SkColor colors[kMaxRandomGradientColors]; 415 SkColor colors[kMaxRandomGradientColors];
415 SkScalar stopsArray[kMaxRandomGradientColors]; 416 SkScalar stopsArray[kMaxRandomGradientColors];
416 SkScalar* stops = stopsArray; 417 SkScalar* stops = stopsArray;
417 SkShader::TileMode tm; 418 SkShader::TileMode tm;
418 int colorCount = RandomGradientParams(d->fRandom, colors, &stops, &tm); 419 int colorCount = RandomGradientParams(d->fRandom, colors, &stops, &tm);
419 auto shader = SkGradientShader::MakeLinear(points, colors, stops, colorCount , tm); 420 auto shader = SkGradientShader::MakeLinear(points, colors, stops, colorCount , tm);
420 const GrFragmentProcessor* fp = shader->asFragmentProcessor(d->fContext, 421 sk_sp<GrFragmentProcessor> fp = shader->asFragmentProcessor(d->fContext,
421 GrTest::TestMatrix(d->fRandom), NULL, kNone_SkFilterQuality, 422 GrTest::TestMatrix(d->fRandom), NULL, kNone_SkFilterQuality,
422 SkSourceGammaTreatment::kRespect); 423 SkSourceGammaTreatment::kRespect);
423 GrAlwaysAssert(fp); 424 GrAlwaysAssert(fp);
424 return fp; 425 return fp;
425 } 426 }
426 427
427 ///////////////////////////////////////////////////////////////////// 428 /////////////////////////////////////////////////////////////////////
428 429
429 void GrGLLinearGradient::emitCode(EmitArgs& args) { 430 void GrGLLinearGradient::emitCode(EmitArgs& args) {
430 const GrLinearGradient& ge = args.fFp.cast<GrLinearGradient>(); 431 const GrLinearGradient& ge = args.fFp.cast<GrLinearGradient>();
431 this->emitUniforms(args.fUniformHandler, ge); 432 this->emitUniforms(args.fUniformHandler, ge);
432 SkString t = args.fFragBuilder->ensureFSCoords2D(args.fCoords, 0); 433 SkString t = args.fFragBuilder->ensureFSCoords2D(args.fCoords, 0);
433 t.append(".x"); 434 t.append(".x");
434 this->emitColor(args.fFragBuilder, 435 this->emitColor(args.fFragBuilder,
435 args.fUniformHandler, 436 args.fUniformHandler,
436 args.fGLSLCaps, 437 args.fGLSLCaps,
437 ge, t.c_str(), 438 ge, t.c_str(),
438 args.fOutputColor, 439 args.fOutputColor,
439 args.fInputColor, 440 args.fInputColor,
440 args.fTexSamplers); 441 args.fTexSamplers);
441 } 442 }
442 443
443 ///////////////////////////////////////////////////////////////////// 444 /////////////////////////////////////////////////////////////////////
444 445
445 const GrFragmentProcessor* SkLinearGradient::asFragmentProcessor( 446 sk_sp<GrFragmentProcessor> SkLinearGradient::asFragmentProcessor(
446 GrContext* context, 447 GrContext* context,
447 const SkMatrix& viewm, 448 const SkMatrix& viewm,
448 const SkMatrix* localMatrix, 449 const SkMatrix* localMatrix,
449 SkFilterQuality, 450 SkFilterQuality,
450 SkSourceGammaTreatment) const { 451 SkSourceGammaTreatment) const {
451 SkASSERT(context); 452 SkASSERT(context);
452 453
453 SkMatrix matrix; 454 SkMatrix matrix;
454 if (!this->getLocalMatrix().invert(&matrix)) { 455 if (!this->getLocalMatrix().invert(&matrix)) {
455 return nullptr; 456 return nullptr;
456 } 457 }
457 if (localMatrix) { 458 if (localMatrix) {
458 SkMatrix inv; 459 SkMatrix inv;
459 if (!localMatrix->invert(&inv)) { 460 if (!localMatrix->invert(&inv)) {
460 return nullptr; 461 return nullptr;
461 } 462 }
462 matrix.postConcat(inv); 463 matrix.postConcat(inv);
463 } 464 }
464 matrix.postConcat(fPtsToUnit); 465 matrix.postConcat(fPtsToUnit);
465 466
466 SkAutoTUnref<const GrFragmentProcessor> inner( 467 sk_sp<GrFragmentProcessor> inner(GrLinearGradient::Make(context, *this, matr ix, fTileMode));
467 GrLinearGradient::Create(context, *this, matrix, fTileMode)); 468 return GrFragmentProcessor::MulOutputByInputAlpha(std::move(inner));
468 return GrFragmentProcessor::MulOutputByInputAlpha(inner);
469 } 469 }
470 470
471 471
472 #endif 472 #endif
473 473
474 #ifndef SK_IGNORE_TO_STRING 474 #ifndef SK_IGNORE_TO_STRING
475 void SkLinearGradient::toString(SkString* str) const { 475 void SkLinearGradient::toString(SkString* str) const {
476 str->append("SkLinearGradient ("); 476 str->append("SkLinearGradient (");
477 477
478 str->appendf("start: (%f, %f)", fStart.fX, fStart.fY); 478 str->appendf("start: (%f, %f)", fStart.fX, fStart.fY);
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
756 this->shade4_dx_clamp<false, true>(dstC, count, fx, dx, invDx, dithe r); 756 this->shade4_dx_clamp<false, true>(dstC, count, fx, dx, invDx, dithe r);
757 } 757 }
758 } else { 758 } else {
759 if (fApplyAlphaAfterInterp) { 759 if (fApplyAlphaAfterInterp) {
760 this->shade4_dx_clamp<true, false>(dstC, count, fx, dx, invDx, dithe r); 760 this->shade4_dx_clamp<true, false>(dstC, count, fx, dx, invDx, dithe r);
761 } else { 761 } else {
762 this->shade4_dx_clamp<false, false>(dstC, count, fx, dx, invDx, dith er); 762 this->shade4_dx_clamp<false, false>(dstC, count, fx, dx, invDx, dith er);
763 } 763 }
764 } 764 }
765 } 765 }
OLDNEW
« no previous file with comments | « src/effects/gradients/SkLinearGradient.h ('k') | src/effects/gradients/SkRadialGradient.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698