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

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

Issue 2221133002: Refactor various gradient effect classes (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Brian's suggestions Created 4 years, 4 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 * 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 #include "SkRefCnt.h"
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 } 340 }
341 341
342 #if SK_SUPPORT_GPU 342 #if SK_SUPPORT_GPU
343 343
344 #include "glsl/GrGLSLCaps.h" 344 #include "glsl/GrGLSLCaps.h"
345 #include "glsl/GrGLSLFragmentShaderBuilder.h" 345 #include "glsl/GrGLSLFragmentShaderBuilder.h"
346 #include "SkGr.h" 346 #include "SkGr.h"
347 347
348 ///////////////////////////////////////////////////////////////////// 348 /////////////////////////////////////////////////////////////////////
349 349
350 class GrGLLinearGradient : public GrGLGradientEffect {
351 public:
352
353 GrGLLinearGradient(const GrProcessor&) {}
354
355 virtual ~GrGLLinearGradient() { }
356
357 virtual void emitCode(EmitArgs&) override;
358
359 static void GenKey(const GrProcessor& processor, const GrGLSLCaps&, GrProces sorKeyBuilder* b) {
360 b->add32(GenBaseGradientKey(processor));
361 }
362
363 private:
364
365 typedef GrGLGradientEffect INHERITED;
366 };
367
368 /////////////////////////////////////////////////////////////////////
369
370 class GrLinearGradient : public GrGradientEffect { 350 class GrLinearGradient : public GrGradientEffect {
371 public: 351 public:
352 class GLSLLinearProcessor;
372 353
373 static sk_sp<GrFragmentProcessor> Make(GrContext* ctx, 354 static sk_sp<GrFragmentProcessor> Make(GrContext* ctx,
374 const SkLinearGradient& shader, 355 const SkLinearGradient& shader,
375 const SkMatrix& matrix, 356 const SkMatrix& matrix,
376 SkShader::TileMode tm) { 357 SkShader::TileMode tm) {
377 return sk_sp<GrFragmentProcessor>(new GrLinearGradient(ctx, shader, matr ix, tm)); 358 return sk_sp<GrFragmentProcessor>(new GrLinearGradient(ctx, shader, matr ix, tm));
378 } 359 }
379 360
380 virtual ~GrLinearGradient() { } 361 virtual ~GrLinearGradient() { }
381 362
382 const char* name() const override { return "Linear Gradient"; } 363 const char* name() const override { return "Linear Gradient"; }
383 364
384 private: 365 private:
385 GrLinearGradient(GrContext* ctx, 366 GrLinearGradient(GrContext* ctx,
386 const SkLinearGradient& shader, 367 const SkLinearGradient& shader,
387 const SkMatrix& matrix, 368 const SkMatrix& matrix,
388 SkShader::TileMode tm) 369 SkShader::TileMode tm)
389 : INHERITED(ctx, shader, matrix, tm) { 370 : INHERITED(ctx, shader, matrix, tm) {
390 this->initClassID<GrLinearGradient>(); 371 this->initClassID<GrLinearGradient>();
391 } 372 }
392 373
393 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override { 374 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
394 return new GrGLLinearGradient(*this);
395 }
396 375
397 virtual void onGetGLSLProcessorKey(const GrGLSLCaps& caps, 376 virtual void onGetGLSLProcessorKey(const GrGLSLCaps& caps,
398 GrProcessorKeyBuilder* b) const override { 377 GrProcessorKeyBuilder* b) const override;
399 GrGLLinearGradient::GenKey(*this, caps, b);
400 }
401 378
402 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; 379 GR_DECLARE_FRAGMENT_PROCESSOR_TEST;
403 380
404 typedef GrGradientEffect INHERITED; 381 typedef GrGradientEffect INHERITED;
405 }; 382 };
406 383
407 ///////////////////////////////////////////////////////////////////// 384 /////////////////////////////////////////////////////////////////////
408 385
386 class GrLinearGradient::GLSLLinearProcessor : public GrGradientEffect::GLSLProce ssor {
387 public:
388 GLSLLinearProcessor(const GrProcessor&) {}
389
390 virtual ~GLSLLinearProcessor() { }
391
392 virtual void emitCode(EmitArgs&) override;
393
394 static void GenKey(const GrProcessor& processor, const GrGLSLCaps&, GrProces sorKeyBuilder* b) {
395 b->add32(GenBaseGradientKey(processor));
396 }
397
398 private:
399 typedef GrGradientEffect::GLSLProcessor INHERITED;
400 };
401
402 /////////////////////////////////////////////////////////////////////
403
404 GrGLSLFragmentProcessor* GrLinearGradient::onCreateGLSLInstance() const {
405 return new GrLinearGradient::GLSLLinearProcessor(*this);
406 }
407
408 void GrLinearGradient::onGetGLSLProcessorKey(const GrGLSLCaps& caps,
409 GrProcessorKeyBuilder* b) const {
410 GrLinearGradient::GLSLLinearProcessor::GenKey(*this, caps, b);
411 }
412
413 /////////////////////////////////////////////////////////////////////
414
409 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrLinearGradient); 415 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrLinearGradient);
410 416
411 sk_sp<GrFragmentProcessor> GrLinearGradient::TestCreate(GrProcessorTestData* d) { 417 sk_sp<GrFragmentProcessor> GrLinearGradient::TestCreate(GrProcessorTestData* d) {
412 SkPoint points[] = {{d->fRandom->nextUScalar1(), d->fRandom->nextUScalar1()} , 418 SkPoint points[] = {{d->fRandom->nextUScalar1(), d->fRandom->nextUScalar1()} ,
413 {d->fRandom->nextUScalar1(), d->fRandom->nextUScalar1()} }; 419 {d->fRandom->nextUScalar1(), d->fRandom->nextUScalar1()} };
414 420
415 SkColor colors[kMaxRandomGradientColors]; 421 SkColor colors[kMaxRandomGradientColors];
416 SkScalar stopsArray[kMaxRandomGradientColors]; 422 SkScalar stopsArray[kMaxRandomGradientColors];
417 SkScalar* stops = stopsArray; 423 SkScalar* stops = stopsArray;
418 SkShader::TileMode tm; 424 SkShader::TileMode tm;
419 int colorCount = RandomGradientParams(d->fRandom, colors, &stops, &tm); 425 int colorCount = RandomGradientParams(d->fRandom, colors, &stops, &tm);
420 auto shader = SkGradientShader::MakeLinear(points, colors, stops, colorCount , tm); 426 auto shader = SkGradientShader::MakeLinear(points, colors, stops, colorCount , tm);
421 SkMatrix viewMatrix = GrTest::TestMatrix(d->fRandom); 427 SkMatrix viewMatrix = GrTest::TestMatrix(d->fRandom);
422 sk_sp<GrFragmentProcessor> fp = shader->asFragmentProcessor(SkShader::AsFPAr gs( 428 sk_sp<GrFragmentProcessor> fp = shader->asFragmentProcessor(SkShader::AsFPAr gs(
423 d->fContext, &viewMatrix, NULL, kNone_SkFilterQuality, nullptr, 429 d->fContext, &viewMatrix, NULL, kNone_SkFilterQuality, nullptr,
424 SkSourceGammaTreatment::kRespect)); 430 SkSourceGammaTreatment::kRespect));
425 GrAlwaysAssert(fp); 431 GrAlwaysAssert(fp);
426 return fp; 432 return fp;
427 } 433 }
428 434
429 ///////////////////////////////////////////////////////////////////// 435 /////////////////////////////////////////////////////////////////////
430 436
431 void GrGLLinearGradient::emitCode(EmitArgs& args) { 437 void GrLinearGradient::GLSLLinearProcessor::emitCode(EmitArgs& args) {
432 const GrLinearGradient& ge = args.fFp.cast<GrLinearGradient>(); 438 const GrLinearGradient& ge = args.fFp.cast<GrLinearGradient>();
433 this->emitUniforms(args.fUniformHandler, ge); 439 this->emitUniforms(args.fUniformHandler, ge);
434 SkString t = args.fFragBuilder->ensureFSCoords2D(args.fCoords, 0); 440 SkString t = args.fFragBuilder->ensureFSCoords2D(args.fCoords, 0);
435 t.append(".x"); 441 t.append(".x");
436 this->emitColor(args.fFragBuilder, 442 this->emitColor(args.fFragBuilder,
437 args.fUniformHandler, 443 args.fUniformHandler,
438 args.fGLSLCaps, 444 args.fGLSLCaps,
439 ge, t.c_str(), 445 ge,
446 t.c_str(),
440 args.fOutputColor, 447 args.fOutputColor,
441 args.fInputColor, 448 args.fInputColor,
442 args.fTexSamplers); 449 args.fTexSamplers);
443 } 450 }
444 451
445 ///////////////////////////////////////////////////////////////////// 452 /////////////////////////////////////////////////////////////////////
446 453
447 sk_sp<GrFragmentProcessor> SkLinearGradient::asFragmentProcessor(const AsFPArgs& args) const { 454 sk_sp<GrFragmentProcessor> SkLinearGradient::asFragmentProcessor(const AsFPArgs& args) const {
448 SkASSERT(args.fContext); 455 SkASSERT(args.fContext);
449 456
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
753 this->shade4_dx_clamp<false, true>(dstC, count, fx, dx, invDx, dithe r); 760 this->shade4_dx_clamp<false, true>(dstC, count, fx, dx, invDx, dithe r);
754 } 761 }
755 } else { 762 } else {
756 if (fApplyAlphaAfterInterp) { 763 if (fApplyAlphaAfterInterp) {
757 this->shade4_dx_clamp<true, false>(dstC, count, fx, dx, invDx, dithe r); 764 this->shade4_dx_clamp<true, false>(dstC, count, fx, dx, invDx, dithe r);
758 } else { 765 } else {
759 this->shade4_dx_clamp<false, false>(dstC, count, fx, dx, invDx, dith er); 766 this->shade4_dx_clamp<false, false>(dstC, count, fx, dx, invDx, dith er);
760 } 767 }
761 } 768 }
762 } 769 }
OLDNEW
« no previous file with comments | « src/effects/gradients/SkGradientShaderPriv.h ('k') | src/effects/gradients/SkRadialGradient.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698