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

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

Issue 245963010: Move SkShader::fLocalMatrix into SkShader constructor. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: nit Created 6 years, 7 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/SkTileImageFilter.cpp ('k') | 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) { 15 SkGradientShaderBase::SkGradientShaderBase(const Descriptor& desc, const SkMatri x* localMatrix)
16 : INHERITED(localMatrix)
17 {
16 SkASSERT(desc.fCount > 1); 18 SkASSERT(desc.fCount > 1);
17 19
18 fMapper = desc.fMapper; 20 fMapper = desc.fMapper;
19 SkSafeRef(fMapper); 21 SkSafeRef(fMapper);
20 fGradFlags = SkToU8(desc.fGradFlags); 22 fGradFlags = SkToU8(desc.fGradFlags);
21 23
22 SkASSERT((unsigned)desc.fTileMode < SkShader::kTileModeCount); 24 SkASSERT((unsigned)desc.fTileMode < SkShader::kTileModeCount);
23 SkASSERT(SkShader::kTileModeCount == SK_ARRAY_COUNT(gTileProcs)); 25 SkASSERT(SkShader::kTileModeCount == SK_ARRAY_COUNT(gTileProcs));
24 fTileMode = desc.fTileMode; 26 fTileMode = desc.fTileMode;
25 fTileProc = gTileProcs[desc.fTileMode]; 27 fTileProc = gTileProcs[desc.fTileMode];
(...skipping 751 matching lines...) Expand 10 before | Expand all | Expand 10 after
777 desc->fTileMode = mode; 779 desc->fTileMode = mode;
778 desc->fMapper = mapper; 780 desc->fMapper = mapper;
779 desc->fGradFlags = flags; 781 desc->fGradFlags = flags;
780 } 782 }
781 783
782 SkShader* SkGradientShader::CreateLinear(const SkPoint pts[2], 784 SkShader* SkGradientShader::CreateLinear(const SkPoint pts[2],
783 const SkColor colors[], 785 const SkColor colors[],
784 const SkScalar pos[], int colorCount, 786 const SkScalar pos[], int colorCount,
785 SkShader::TileMode mode, 787 SkShader::TileMode mode,
786 SkUnitMapper* mapper, 788 SkUnitMapper* mapper,
787 uint32_t flags) { 789 uint32_t flags,
790 const SkMatrix* localMatrix) {
788 if (NULL == pts || NULL == colors || colorCount < 1) { 791 if (NULL == pts || NULL == colors || colorCount < 1) {
789 return NULL; 792 return NULL;
790 } 793 }
791 EXPAND_1_COLOR(colorCount); 794 EXPAND_1_COLOR(colorCount);
792 795
793 SkGradientShaderBase::Descriptor desc; 796 SkGradientShaderBase::Descriptor desc;
794 desc_init(&desc, colors, pos, colorCount, mode, mapper, flags); 797 desc_init(&desc, colors, pos, colorCount, mode, mapper, flags);
795 return SkNEW_ARGS(SkLinearGradient, (pts, desc)); 798 return SkNEW_ARGS(SkLinearGradient, (pts, desc, localMatrix));
796 } 799 }
797 800
798 SkShader* SkGradientShader::CreateRadial(const SkPoint& center, SkScalar radius, 801 SkShader* SkGradientShader::CreateRadial(const SkPoint& center, SkScalar radius,
799 const SkColor colors[], 802 const SkColor colors[],
800 const SkScalar pos[], int colorCount, 803 const SkScalar pos[], int colorCount,
801 SkShader::TileMode mode, 804 SkShader::TileMode mode,
802 SkUnitMapper* mapper, 805 SkUnitMapper* mapper,
803 uint32_t flags) { 806 uint32_t flags,
807 const SkMatrix* localMatrix) {
804 if (radius <= 0 || NULL == colors || colorCount < 1) { 808 if (radius <= 0 || NULL == colors || colorCount < 1) {
805 return NULL; 809 return NULL;
806 } 810 }
807 EXPAND_1_COLOR(colorCount); 811 EXPAND_1_COLOR(colorCount);
808 812
809 SkGradientShaderBase::Descriptor desc; 813 SkGradientShaderBase::Descriptor desc;
810 desc_init(&desc, colors, pos, colorCount, mode, mapper, flags); 814 desc_init(&desc, colors, pos, colorCount, mode, mapper, flags);
811 return SkNEW_ARGS(SkRadialGradient, (center, radius, desc)); 815 return SkNEW_ARGS(SkRadialGradient, (center, radius, desc, localMatrix));
812 } 816 }
813 817
814 SkShader* SkGradientShader::CreateTwoPointRadial(const SkPoint& start, 818 SkShader* SkGradientShader::CreateTwoPointRadial(const SkPoint& start,
815 SkScalar startRadius, 819 SkScalar startRadius,
816 const SkPoint& end, 820 const SkPoint& end,
817 SkScalar endRadius, 821 SkScalar endRadius,
818 const SkColor colors[], 822 const SkColor colors[],
819 const SkScalar pos[], 823 const SkScalar pos[],
820 int colorCount, 824 int colorCount,
821 SkShader::TileMode mode, 825 SkShader::TileMode mode,
822 SkUnitMapper* mapper, 826 SkUnitMapper* mapper,
823 uint32_t flags) { 827 uint32_t flags,
828 const SkMatrix* localMatrix) {
824 if (startRadius < 0 || endRadius < 0 || NULL == colors || colorCount < 1) { 829 if (startRadius < 0 || endRadius < 0 || NULL == colors || colorCount < 1) {
825 return NULL; 830 return NULL;
826 } 831 }
827 EXPAND_1_COLOR(colorCount); 832 EXPAND_1_COLOR(colorCount);
828 833
829 SkGradientShaderBase::Descriptor desc; 834 SkGradientShaderBase::Descriptor desc;
830 desc_init(&desc, colors, pos, colorCount, mode, mapper, flags); 835 desc_init(&desc, colors, pos, colorCount, mode, mapper, flags);
831 return SkNEW_ARGS(SkTwoPointRadialGradient, 836 return SkNEW_ARGS(SkTwoPointRadialGradient,
832 (start, startRadius, end, endRadius, desc)); 837 (start, startRadius, end, endRadius, desc, localMatrix));
833 } 838 }
834 839
835 SkShader* SkGradientShader::CreateTwoPointConical(const SkPoint& start, 840 SkShader* SkGradientShader::CreateTwoPointConical(const SkPoint& start,
836 SkScalar startRadius, 841 SkScalar startRadius,
837 const SkPoint& end, 842 const SkPoint& end,
838 SkScalar endRadius, 843 SkScalar endRadius,
839 const SkColor colors[], 844 const SkColor colors[],
840 const SkScalar pos[], 845 const SkScalar pos[],
841 int colorCount, 846 int colorCount,
842 SkShader::TileMode mode, 847 SkShader::TileMode mode,
843 SkUnitMapper* mapper, 848 SkUnitMapper* mapper,
844 uint32_t flags) { 849 uint32_t flags,
850 const SkMatrix* localMatrix) {
845 if (startRadius < 0 || endRadius < 0 || NULL == colors || colorCount < 1) { 851 if (startRadius < 0 || endRadius < 0 || NULL == colors || colorCount < 1) {
846 return NULL; 852 return NULL;
847 } 853 }
848 if (start == end && startRadius == endRadius) { 854 if (start == end && startRadius == endRadius) {
849 return SkNEW(SkEmptyShader); 855 return SkNEW(SkEmptyShader);
850 } 856 }
851 857
852 EXPAND_1_COLOR(colorCount); 858 EXPAND_1_COLOR(colorCount);
853 859
854 bool flipGradient = startRadius > endRadius; 860 bool flipGradient = startRadius > endRadius;
855 861
856 SkGradientShaderBase::Descriptor desc; 862 SkGradientShaderBase::Descriptor desc;
857 863
858 if (!flipGradient) { 864 if (!flipGradient) {
859 desc_init(&desc, colors, pos, colorCount, mode, mapper, flags); 865 desc_init(&desc, colors, pos, colorCount, mode, mapper, flags);
860 return SkNEW_ARGS(SkTwoPointConicalGradient, 866 return SkNEW_ARGS(SkTwoPointConicalGradient,
861 (start, startRadius, end, endRadius, flipGradient, des c)); 867 (start, startRadius, end, endRadius, flipGradient, des c, localMatrix));
862 } else { 868 } else {
863 SkAutoSTArray<8, SkColor> colorsNew(colorCount); 869 SkAutoSTArray<8, SkColor> colorsNew(colorCount);
864 SkAutoSTArray<8, SkScalar> posNew(colorCount); 870 SkAutoSTArray<8, SkScalar> posNew(colorCount);
865 for (int i = 0; i < colorCount; ++i) { 871 for (int i = 0; i < colorCount; ++i) {
866 colorsNew[i] = colors[colorCount - i - 1]; 872 colorsNew[i] = colors[colorCount - i - 1];
867 } 873 }
868 874
869 if (pos) { 875 if (pos) {
870 for (int i = 0; i < colorCount; ++i) { 876 for (int i = 0; i < colorCount; ++i) {
871 posNew[i] = 1 - pos[colorCount - i - 1]; 877 posNew[i] = 1 - pos[colorCount - i - 1];
872 } 878 }
873 desc_init(&desc, colorsNew.get(), posNew.get(), colorCount, mode, ma pper, flags); 879 desc_init(&desc, colorsNew.get(), posNew.get(), colorCount, mode, ma pper, flags);
874 } else { 880 } else {
875 desc_init(&desc, colorsNew.get(), NULL, colorCount, mode, mapper, fl ags); 881 desc_init(&desc, colorsNew.get(), NULL, colorCount, mode, mapper, fl ags);
876 } 882 }
877 883
878 return SkNEW_ARGS(SkTwoPointConicalGradient, 884 return SkNEW_ARGS(SkTwoPointConicalGradient,
879 (end, endRadius, start, startRadius, flipGradient, des c)); 885 (end, endRadius, start, startRadius, flipGradient, des c, localMatrix));
880 } 886 }
881 } 887 }
882 888
883 SkShader* SkGradientShader::CreateSweep(SkScalar cx, SkScalar cy, 889 SkShader* SkGradientShader::CreateSweep(SkScalar cx, SkScalar cy,
884 const SkColor colors[], 890 const SkColor colors[],
885 const SkScalar pos[], 891 const SkScalar pos[],
886 int colorCount, SkUnitMapper* mapper, 892 int colorCount, SkUnitMapper* mapper,
887 uint32_t flags) { 893 uint32_t flags,
894 const SkMatrix* localMatrix) {
888 if (NULL == colors || colorCount < 1) { 895 if (NULL == colors || colorCount < 1) {
889 return NULL; 896 return NULL;
890 } 897 }
891 EXPAND_1_COLOR(colorCount); 898 EXPAND_1_COLOR(colorCount);
892 899
893 SkGradientShaderBase::Descriptor desc; 900 SkGradientShaderBase::Descriptor desc;
894 desc_init(&desc, colors, pos, colorCount, SkShader::kClamp_TileMode, mapper, flags); 901 desc_init(&desc, colors, pos, colorCount, SkShader::kClamp_TileMode, mapper, flags);
895 return SkNEW_ARGS(SkSweepGradient, (cx, cy, desc)); 902 return SkNEW_ARGS(SkSweepGradient, (cx, cy, desc, localMatrix));
896 } 903 }
897 904
898 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkGradientShader) 905 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkGradientShader)
899 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkLinearGradient) 906 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkLinearGradient)
900 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkRadialGradient) 907 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkRadialGradient)
901 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSweepGradient) 908 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSweepGradient)
902 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkTwoPointRadialGradient) 909 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkTwoPointRadialGradient)
903 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkTwoPointConicalGradient) 910 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkTwoPointConicalGradient)
904 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END 911 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END
905 912
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
1204 (*stops)[i] = stop; 1211 (*stops)[i] = stop;
1205 stop = i < outColors - 1 ? stop + random->nextUScalar1() * (1.f - st op) : 1.f; 1212 stop = i < outColors - 1 ? stop + random->nextUScalar1() * (1.f - st op) : 1.f;
1206 } 1213 }
1207 } 1214 }
1208 *tm = static_cast<SkShader::TileMode>(random->nextULessThan(SkShader::kTileM odeCount)); 1215 *tm = static_cast<SkShader::TileMode>(random->nextULessThan(SkShader::kTileM odeCount));
1209 1216
1210 return outColors; 1217 return outColors;
1211 } 1218 }
1212 1219
1213 #endif 1220 #endif
OLDNEW
« no previous file with comments | « src/effects/SkTileImageFilter.cpp ('k') | src/effects/gradients/SkGradientShaderPriv.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698