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

Side by Side Diff: gm/gradients.cpp

Issue 1620423002: add GM to exercise duplicate color-stops (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 11 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 | « no previous file | no next file » | 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 2011 Google Inc. 2 * Copyright 2011 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 "gm.h" 8 #include "gm.h"
9 #include "SkGradientShader.h" 9 #include "SkGradientShader.h"
10 10
(...skipping 628 matching lines...) Expand 10 before | Expand all | Expand 10 after
639 canvas->drawRect(SkRect::MakeWH(kRectSize, kRectSize), paint); 639 canvas->drawRect(SkRect::MakeWH(kRectSize, kRectSize), paint);
640 } 640 }
641 } 641 }
642 642
643 private: 643 private:
644 typedef GM INHERITED; 644 typedef GM INHERITED;
645 }; 645 };
646 DEF_GM( return new LinearGradientTinyGM(); ) 646 DEF_GM( return new LinearGradientTinyGM(); )
647 647
648 } 648 }
649
650 //////////////////////////////////////////////////////////////////////////////// ///////////////////
651
652 struct GradRun {
653 SkColor fColors[4];
654 SkScalar fPos[4];
655 int fCount;
656 };
657
658 #define SIZE 121
659
660 static SkShader* make_linear(const GradRun& run, SkShader::TileMode mode) {
661 const SkPoint pts[] { { 30, 30 }, { SIZE - 30, SIZE - 30 } };
662 return SkGradientShader::CreateLinear(pts, run.fColors, run.fPos, run.fCount , mode);
663 }
664
665 static SkShader* make_radial(const GradRun& run, SkShader::TileMode mode) {
666 const SkScalar half = SIZE * 0.5f;
667 return SkGradientShader::CreateRadial({half,half}, half - 10,
668 run.fColors, run.fPos, run.fCount, mod e);
669 }
670
671 static SkShader* make_conical(const GradRun& run, SkShader::TileMode mode) {
672 const SkScalar half = SIZE * 0.5f;
673 const SkPoint center { half, half };
674 return SkGradientShader::CreateTwoPointConical(center, 20, center, half - 10 ,
675 run.fColors, run.fPos, run.fCount, mod e);
676 }
677
678 static SkShader* make_sweep(const GradRun& run, SkShader::TileMode) {
679 const SkScalar half = SIZE * 0.5f;
680 return SkGradientShader::CreateSweep(half, half, run.fColors, run.fPos, run. fCount);
681 }
682
683 /*
684 * Exercise duplicate color-stops, at the ends, and in the middle
685 *
686 * At the time of this writing, only Linear correctly deals with duplicates at the ends,
687 * and then only correctly on CPU backend.
688 */
689 DEF_SIMPLE_GM(gradients_dup_color_stops, canvas, 704, 564) {
690 const SkColor preColor = 0xFFFF0000; // clamp color before start
691 const SkColor postColor = 0xFF0000FF; // clamp color after end
692 const SkColor color0 = 0xFF000000;
693 const SkColor color1 = 0xFF00FF00;
694 const SkColor badColor = 0xFF3388BB; // should never be seen, fills out f ixed-size array
695
696 const GradRun runs[] = {
697 { { color0, color1, badColor, badColor },
698 { 0, 1, -1, -1 },
699 2,
700 },
701 { { preColor, color0, color1, badColor },
702 { 0, 0, 1, -1 },
703 3,
704 },
705 { { color0, color1, postColor, badColor },
706 { 0, 1, 1, -1 },
707 3,
708 },
709 { { preColor, color0, color1, postColor },
710 { 0, 0, 1, 1 },
711 4,
712 },
713 { { color0, color0, color1, color1 },
714 { 0, 0.5f, 0.5f, 1 },
715 4,
716 },
717 };
718 SkShader* (*factories[])(const GradRun&, SkShader::TileMode) {
719 make_linear, make_radial, make_conical, make_sweep
720 };
721
722 const SkRect rect = SkRect::MakeWH(SIZE, SIZE);
723 const SkScalar dx = SIZE + 20;
724 const SkScalar dy = SIZE + 20;
725 const SkShader::TileMode mode = SkShader::kClamp_TileMode;
726
727 SkPaint paint;
728 canvas->translate(10, 10 - dy);
729 for (auto factory : factories) {
730 canvas->translate(0, dy);
731 SkAutoCanvasRestore acr(canvas, true);
732 for (const auto& run : runs) {
733 paint.setShader(factory(run, mode))->unref();
734 canvas->drawRect(rect, paint);
735 canvas->translate(dx, 0);
736 }
737 }
738 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698