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

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

Issue 461643002: add localMatrix to gradient Descriptor (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 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
« no previous file with comments | « no previous file | src/effects/gradients/SkGradientShaderPriv.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 2006 The Android Open Source Project 2 * Copyright 2006 The Android Open Source Project
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 "SkGradientShaderPriv.h" 8 #include "SkGradientShaderPriv.h"
9 #include "SkLinearGradient.h" 9 #include "SkLinearGradient.h"
10 #include "SkRadialGradient.h" 10 #include "SkRadialGradient.h"
11 #include "SkTwoPointRadialGradient.h" 11 #include "SkTwoPointRadialGradient.h"
12 #include "SkTwoPointConicalGradient.h" 12 #include "SkTwoPointConicalGradient.h"
13 #include "SkSweepGradient.h" 13 #include "SkSweepGradient.h"
14 14
15 SkGradientShaderBase::SkGradientShaderBase(const Descriptor& desc, const SkMatri x* localMatrix) 15 SkGradientShaderBase::SkGradientShaderBase(const Descriptor& desc)
16 : INHERITED(localMatrix) 16 : INHERITED(desc.fLocalMatrix)
17 { 17 {
18 SkASSERT(desc.fCount > 1); 18 SkASSERT(desc.fCount > 1);
19 19
20 fGradFlags = SkToU8(desc.fGradFlags); 20 fGradFlags = SkToU8(desc.fGradFlags);
21 21
22 SkASSERT((unsigned)desc.fTileMode < SkShader::kTileModeCount); 22 SkASSERT((unsigned)desc.fTileMode < SkShader::kTileModeCount);
23 SkASSERT(SkShader::kTileModeCount == SK_ARRAY_COUNT(gTileProcs)); 23 SkASSERT(SkShader::kTileModeCount == SK_ARRAY_COUNT(gTileProcs));
24 fTileMode = desc.fTileMode; 24 fTileMode = desc.fTileMode;
25 fTileProc = gTileProcs[desc.fTileMode]; 25 fTileProc = gTileProcs[desc.fTileMode];
26 26
(...skipping 677 matching lines...) Expand 10 before | Expand all | Expand 10 after
704 do { \ 704 do { \
705 if (1 == count) { \ 705 if (1 == count) { \
706 tmp[0] = tmp[1] = colors[0]; \ 706 tmp[0] = tmp[1] = colors[0]; \
707 colors = tmp; \ 707 colors = tmp; \
708 pos = NULL; \ 708 pos = NULL; \
709 count = 2; \ 709 count = 2; \
710 } \ 710 } \
711 } while (0) 711 } while (0)
712 712
713 static void desc_init(SkGradientShaderBase::Descriptor* desc, 713 static void desc_init(SkGradientShaderBase::Descriptor* desc,
714 const SkColor colors[], 714 const SkColor colors[], const SkScalar pos[], int colorCou nt,
715 const SkScalar pos[], int colorCount, 715 SkShader::TileMode mode, uint32_t flags, const SkMatrix* l ocalMatrix) {
716 SkShader::TileMode mode, uint32_t flags) {
717 desc->fColors = colors; 716 desc->fColors = colors;
718 desc->fPos = pos; 717 desc->fPos = pos;
719 desc->fCount = colorCount; 718 desc->fCount = colorCount;
720 desc->fTileMode = mode; 719 desc->fTileMode = mode;
721 desc->fGradFlags = flags; 720 desc->fGradFlags = flags;
721 desc->fLocalMatrix = localMatrix;
722 } 722 }
723 723
724 SkShader* SkGradientShader::CreateLinear(const SkPoint pts[2], 724 SkShader* SkGradientShader::CreateLinear(const SkPoint pts[2],
725 const SkColor colors[], 725 const SkColor colors[],
726 const SkScalar pos[], int colorCount, 726 const SkScalar pos[], int colorCount,
727 SkShader::TileMode mode, 727 SkShader::TileMode mode,
728 uint32_t flags, 728 uint32_t flags,
729 const SkMatrix* localMatrix) { 729 const SkMatrix* localMatrix) {
730 if (NULL == pts || NULL == colors || colorCount < 1) { 730 if (NULL == pts || NULL == colors || colorCount < 1) {
731 return NULL; 731 return NULL;
732 } 732 }
733 EXPAND_1_COLOR(colorCount); 733 EXPAND_1_COLOR(colorCount);
734 734
735 SkGradientShaderBase::Descriptor desc; 735 SkGradientShaderBase::Descriptor desc;
736 desc_init(&desc, colors, pos, colorCount, mode, flags); 736 desc_init(&desc, colors, pos, colorCount, mode, flags, localMatrix);
737 return SkNEW_ARGS(SkLinearGradient, (pts, desc, localMatrix)); 737 return SkNEW_ARGS(SkLinearGradient, (pts, desc));
738 } 738 }
739 739
740 SkShader* SkGradientShader::CreateRadial(const SkPoint& center, SkScalar radius, 740 SkShader* SkGradientShader::CreateRadial(const SkPoint& center, SkScalar radius,
741 const SkColor colors[], 741 const SkColor colors[],
742 const SkScalar pos[], int colorCount, 742 const SkScalar pos[], int colorCount,
743 SkShader::TileMode mode, 743 SkShader::TileMode mode,
744 uint32_t flags, 744 uint32_t flags,
745 const SkMatrix* localMatrix) { 745 const SkMatrix* localMatrix) {
746 if (radius <= 0 || NULL == colors || colorCount < 1) { 746 if (radius <= 0 || NULL == colors || colorCount < 1) {
747 return NULL; 747 return NULL;
748 } 748 }
749 EXPAND_1_COLOR(colorCount); 749 EXPAND_1_COLOR(colorCount);
750 750
751 SkGradientShaderBase::Descriptor desc; 751 SkGradientShaderBase::Descriptor desc;
752 desc_init(&desc, colors, pos, colorCount, mode, flags); 752 desc_init(&desc, colors, pos, colorCount, mode, flags, localMatrix);
753 return SkNEW_ARGS(SkRadialGradient, (center, radius, desc, localMatrix)); 753 return SkNEW_ARGS(SkRadialGradient, (center, radius, desc));
754 } 754 }
755 755
756 SkShader* SkGradientShader::CreateTwoPointRadial(const SkPoint& start, 756 SkShader* SkGradientShader::CreateTwoPointRadial(const SkPoint& start,
757 SkScalar startRadius, 757 SkScalar startRadius,
758 const SkPoint& end, 758 const SkPoint& end,
759 SkScalar endRadius, 759 SkScalar endRadius,
760 const SkColor colors[], 760 const SkColor colors[],
761 const SkScalar pos[], 761 const SkScalar pos[],
762 int colorCount, 762 int colorCount,
763 SkShader::TileMode mode, 763 SkShader::TileMode mode,
764 uint32_t flags, 764 uint32_t flags,
765 const SkMatrix* localMatrix) { 765 const SkMatrix* localMatrix) {
766 if (startRadius < 0 || endRadius < 0 || NULL == colors || colorCount < 1) { 766 if (startRadius < 0 || endRadius < 0 || NULL == colors || colorCount < 1) {
767 return NULL; 767 return NULL;
768 } 768 }
769 EXPAND_1_COLOR(colorCount); 769 EXPAND_1_COLOR(colorCount);
770 770
771 SkGradientShaderBase::Descriptor desc; 771 SkGradientShaderBase::Descriptor desc;
772 desc_init(&desc, colors, pos, colorCount, mode, flags); 772 desc_init(&desc, colors, pos, colorCount, mode, flags, localMatrix);
773 return SkNEW_ARGS(SkTwoPointRadialGradient, 773 return SkNEW_ARGS(SkTwoPointRadialGradient,
774 (start, startRadius, end, endRadius, desc, localMatrix)); 774 (start, startRadius, end, endRadius, desc));
775 } 775 }
776 776
777 SkShader* SkGradientShader::CreateTwoPointConical(const SkPoint& start, 777 SkShader* SkGradientShader::CreateTwoPointConical(const SkPoint& start,
778 SkScalar startRadius, 778 SkScalar startRadius,
779 const SkPoint& end, 779 const SkPoint& end,
780 SkScalar endRadius, 780 SkScalar endRadius,
781 const SkColor colors[], 781 const SkColor colors[],
782 const SkScalar pos[], 782 const SkScalar pos[],
783 int colorCount, 783 int colorCount,
784 SkShader::TileMode mode, 784 SkShader::TileMode mode,
785 uint32_t flags, 785 uint32_t flags,
786 const SkMatrix* localMatrix) { 786 const SkMatrix* localMatrix) {
787 if (startRadius < 0 || endRadius < 0 || NULL == colors || colorCount < 1) { 787 if (startRadius < 0 || endRadius < 0 || NULL == colors || colorCount < 1) {
788 return NULL; 788 return NULL;
789 } 789 }
790 if (start == end && startRadius == endRadius) { 790 if (start == end && startRadius == endRadius) {
791 return SkShader::CreateEmptyShader(); 791 return SkShader::CreateEmptyShader();
792 } 792 }
793 793
794 EXPAND_1_COLOR(colorCount); 794 EXPAND_1_COLOR(colorCount);
795 795
796 bool flipGradient = startRadius > endRadius; 796 bool flipGradient = startRadius > endRadius;
797 797
798 SkGradientShaderBase::Descriptor desc; 798 SkGradientShaderBase::Descriptor desc;
799 799
800 if (!flipGradient) { 800 if (!flipGradient) {
801 desc_init(&desc, colors, pos, colorCount, mode, flags); 801 desc_init(&desc, colors, pos, colorCount, mode, flags, localMatrix);
802 return SkNEW_ARGS(SkTwoPointConicalGradient, 802 return SkNEW_ARGS(SkTwoPointConicalGradient,
803 (start, startRadius, end, endRadius, flipGradient, des c, localMatrix)); 803 (start, startRadius, end, endRadius, flipGradient, des c));
804 } else { 804 } else {
805 SkAutoSTArray<8, SkColor> colorsNew(colorCount); 805 SkAutoSTArray<8, SkColor> colorsNew(colorCount);
806 SkAutoSTArray<8, SkScalar> posNew(colorCount); 806 SkAutoSTArray<8, SkScalar> posNew(colorCount);
807 for (int i = 0; i < colorCount; ++i) { 807 for (int i = 0; i < colorCount; ++i) {
808 colorsNew[i] = colors[colorCount - i - 1]; 808 colorsNew[i] = colors[colorCount - i - 1];
809 } 809 }
810 810
811 if (pos) { 811 if (pos) {
812 for (int i = 0; i < colorCount; ++i) { 812 for (int i = 0; i < colorCount; ++i) {
813 posNew[i] = 1 - pos[colorCount - i - 1]; 813 posNew[i] = 1 - pos[colorCount - i - 1];
814 } 814 }
815 desc_init(&desc, colorsNew.get(), posNew.get(), colorCount, mode, fl ags); 815 desc_init(&desc, colorsNew.get(), posNew.get(), colorCount, mode, fl ags, localMatrix);
816 } else { 816 } else {
817 desc_init(&desc, colorsNew.get(), NULL, colorCount, mode, flags); 817 desc_init(&desc, colorsNew.get(), NULL, colorCount, mode, flags, loc alMatrix);
818 } 818 }
819 819
820 return SkNEW_ARGS(SkTwoPointConicalGradient, 820 return SkNEW_ARGS(SkTwoPointConicalGradient,
821 (end, endRadius, start, startRadius, flipGradient, des c, localMatrix)); 821 (end, endRadius, start, startRadius, flipGradient, des c));
822 } 822 }
823 } 823 }
824 824
825 SkShader* SkGradientShader::CreateSweep(SkScalar cx, SkScalar cy, 825 SkShader* SkGradientShader::CreateSweep(SkScalar cx, SkScalar cy,
826 const SkColor colors[], 826 const SkColor colors[],
827 const SkScalar pos[], 827 const SkScalar pos[],
828 int colorCount, 828 int colorCount,
829 uint32_t flags, 829 uint32_t flags,
830 const SkMatrix* localMatrix) { 830 const SkMatrix* localMatrix) {
831 if (NULL == colors || colorCount < 1) { 831 if (NULL == colors || colorCount < 1) {
832 return NULL; 832 return NULL;
833 } 833 }
834 EXPAND_1_COLOR(colorCount); 834 EXPAND_1_COLOR(colorCount);
835 835
836 SkGradientShaderBase::Descriptor desc; 836 SkGradientShaderBase::Descriptor desc;
837 desc_init(&desc, colors, pos, colorCount, SkShader::kClamp_TileMode, flags); 837 desc_init(&desc, colors, pos, colorCount, SkShader::kClamp_TileMode, flags, localMatrix);
838 return SkNEW_ARGS(SkSweepGradient, (cx, cy, desc, localMatrix)); 838 return SkNEW_ARGS(SkSweepGradient, (cx, cy, desc));
839 } 839 }
840 840
841 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkGradientShader) 841 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkGradientShader)
842 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkLinearGradient) 842 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkLinearGradient)
843 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkRadialGradient) 843 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkRadialGradient)
844 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSweepGradient) 844 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSweepGradient)
845 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkTwoPointRadialGradient) 845 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkTwoPointRadialGradient)
846 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkTwoPointConicalGradient) 846 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkTwoPointConicalGradient)
847 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END 847 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END
848 848
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
1148 (*stops)[i] = stop; 1148 (*stops)[i] = stop;
1149 stop = i < outColors - 1 ? stop + random->nextUScalar1() * (1.f - st op) : 1.f; 1149 stop = i < outColors - 1 ? stop + random->nextUScalar1() * (1.f - st op) : 1.f;
1150 } 1150 }
1151 } 1151 }
1152 *tm = static_cast<SkShader::TileMode>(random->nextULessThan(SkShader::kTileM odeCount)); 1152 *tm = static_cast<SkShader::TileMode>(random->nextULessThan(SkShader::kTileM odeCount));
1153 1153
1154 return outColors; 1154 return outColors;
1155 } 1155 }
1156 1156
1157 #endif 1157 #endif
OLDNEW
« no previous file with comments | « no previous file | src/effects/gradients/SkGradientShaderPriv.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698