| OLD | NEW |
| 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" |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 if (fColorCount > 2) { | 196 if (fColorCount > 2) { |
| 197 Rec* recs = fRecs; | 197 Rec* recs = fRecs; |
| 198 for (int i = 1; i < fColorCount; i++) { | 198 for (int i = 1; i < fColorCount; i++) { |
| 199 buffer.writeInt(recs[i].fPos); | 199 buffer.writeInt(recs[i].fPos); |
| 200 buffer.writeUInt(recs[i].fScale); | 200 buffer.writeUInt(recs[i].fScale); |
| 201 } | 201 } |
| 202 } | 202 } |
| 203 buffer.writeMatrix(fPtsToUnit); | 203 buffer.writeMatrix(fPtsToUnit); |
| 204 } | 204 } |
| 205 | 205 |
| 206 void SkGradientShaderBase::getGradientDescriptorGpu(DescriptorGpu* desc) const { |
| 207 desc->fCount = fColorCount; |
| 208 if (fColorCount <= 3) { |
| 209 memcpy(desc->fColors, fOrigColors, fColorCount * sizeof(SkColor)); |
| 210 } |
| 211 if (3 == fColorCount){ |
| 212 desc->fMidPos = SkFixedToScalar(fRecs[1].fPos); |
| 213 } |
| 214 desc->fTileMode = fTileMode; |
| 215 desc->fFlags = fGradFlags; |
| 216 } |
| 217 |
| 206 bool SkGradientShaderBase::isOpaque() const { | 218 bool SkGradientShaderBase::isOpaque() const { |
| 207 return fColorsAreOpaque; | 219 return fColorsAreOpaque; |
| 208 } | 220 } |
| 209 | 221 |
| 210 SkGradientShaderBase::GradientShaderBaseContext::GradientShaderBaseContext( | 222 SkGradientShaderBase::GradientShaderBaseContext::GradientShaderBaseContext( |
| 211 const SkGradientShaderBase& shader, const SkBitmap& device, | 223 const SkGradientShaderBase& shader, const SkBitmap& device, |
| 212 const SkPaint& paint, const SkMatrix& matrix) | 224 const SkPaint& paint, const SkMatrix& matrix) |
| 213 : INHERITED(shader, device, paint, matrix) | 225 : INHERITED(shader, device, paint, matrix) |
| 214 , fCache(shader.refCache(getPaintAlpha())) | 226 , fCache(shader.refCache(getPaintAlpha())) |
| 215 { | 227 { |
| (...skipping 782 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 998 } | 1010 } |
| 999 | 1011 |
| 1000 ///////////////////////////////////////////////////////////////////// | 1012 ///////////////////////////////////////////////////////////////////// |
| 1001 | 1013 |
| 1002 GrGradientEffect::GrGradientEffect(GrContext* ctx, | 1014 GrGradientEffect::GrGradientEffect(GrContext* ctx, |
| 1003 const SkGradientShaderBase& shader, | 1015 const SkGradientShaderBase& shader, |
| 1004 const SkMatrix& matrix, | 1016 const SkMatrix& matrix, |
| 1005 SkShader::TileMode tileMode) { | 1017 SkShader::TileMode tileMode) { |
| 1006 | 1018 |
| 1007 fIsOpaque = shader.isOpaque(); | 1019 fIsOpaque = shader.isOpaque(); |
| 1020 SkGradientShaderBase::DescriptorGpu gradDesc; |
| 1008 | 1021 |
| 1009 SkShader::GradientInfo info; | 1022 gradDesc.fColors = &fColors[0]; |
| 1010 SkScalar pos[3] = {0}; | 1023 shader.getGradientDescriptorGpu(&gradDesc); |
| 1011 | |
| 1012 info.fColorCount = 3; | |
| 1013 info.fColors = &fColors[0]; | |
| 1014 info.fColorOffsets = &pos[0]; | |
| 1015 shader.asAGradient(&info); | |
| 1016 | 1024 |
| 1017 // The two and three color specializations do not currently support tiling. | 1025 // The two and three color specializations do not currently support tiling. |
| 1018 bool foundSpecialCase = false; | 1026 bool foundSpecialCase = false; |
| 1019 if (SkShader::kClamp_TileMode == info.fTileMode) { | 1027 if (SkShader::kClamp_TileMode == gradDesc.fTileMode) { |
| 1020 if (2 == info.fColorCount) { | 1028 if (2 == gradDesc.fCount) { |
| 1021 fRow = -1; // flag for no atlas | 1029 fRow = -1; // flag for no atlas |
| 1022 fColorType = kTwo_ColorType; | 1030 fColorType = kTwo_ColorType; |
| 1023 foundSpecialCase = true; | 1031 foundSpecialCase = true; |
| 1024 } else if (3 == info.fColorCount && | 1032 } else if (3 == gradDesc.fCount && |
| 1025 (SkScalarAbs(pos[1] - SK_ScalarHalf) < SK_Scalar1 / 1000)) {
// 3 color symmetric | 1033 (SkScalarAbs(gradDesc.fMidPos - SK_ScalarHalf) < SK_Scalar1 /
1000)) { // 3 color symmetric |
| 1026 fRow = -1; // flag for no atlas | 1034 fRow = -1; // flag for no atlas |
| 1027 fColorType = kThree_ColorType; | 1035 fColorType = kThree_ColorType; |
| 1028 foundSpecialCase = true; | 1036 foundSpecialCase = true; |
| 1029 } | 1037 } |
| 1030 } | 1038 } |
| 1031 if (foundSpecialCase) { | 1039 if (foundSpecialCase) { |
| 1032 if (SkGradientShader::kInterpolateColorsInPremul_Flag & info.fGradientFl
ags) { | 1040 if (SkGradientShader::kInterpolateColorsInPremul_Flag & gradDesc.fFlags)
{ |
| 1033 fPremulType = kBeforeInterp_PremulType; | 1041 fPremulType = kBeforeInterp_PremulType; |
| 1034 } else { | 1042 } else { |
| 1035 fPremulType = kAfterInterp_PremulType; | 1043 fPremulType = kAfterInterp_PremulType; |
| 1036 } | 1044 } |
| 1037 fCoordTransform.reset(kCoordSet, matrix); | 1045 fCoordTransform.reset(kCoordSet, matrix); |
| 1038 } else { | 1046 } else { |
| 1039 // doesn't matter how this is set, just be consistent because it is part
of the effect key. | 1047 // doesn't matter how this is set, just be consistent because it is part
of the effect key. |
| 1040 fPremulType = kBeforeInterp_PremulType; | 1048 fPremulType = kBeforeInterp_PremulType; |
| 1041 SkBitmap bitmap; | 1049 SkBitmap bitmap; |
| 1042 shader.getGradientTableBitmap(&bitmap); | 1050 shader.getGradientTableBitmap(&bitmap); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1142 (*stops)[i] = stop; | 1150 (*stops)[i] = stop; |
| 1143 stop = i < outColors - 1 ? stop + random->nextUScalar1() * (1.f - st
op) : 1.f; | 1151 stop = i < outColors - 1 ? stop + random->nextUScalar1() * (1.f - st
op) : 1.f; |
| 1144 } | 1152 } |
| 1145 } | 1153 } |
| 1146 *tm = static_cast<SkShader::TileMode>(random->nextULessThan(SkShader::kTileM
odeCount)); | 1154 *tm = static_cast<SkShader::TileMode>(random->nextULessThan(SkShader::kTileM
odeCount)); |
| 1147 | 1155 |
| 1148 return outColors; | 1156 return outColors; |
| 1149 } | 1157 } |
| 1150 | 1158 |
| 1151 #endif | 1159 #endif |
| OLD | NEW |