OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2014 Google Inc. | 3 * Copyright 2014 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 #include "SkTwoPointConicalGradient_gpu.h" | 9 #include "SkTwoPointConicalGradient_gpu.h" |
10 | 10 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 Edge2PtConicalEffect(GrContext* ctx, | 91 Edge2PtConicalEffect(GrContext* ctx, |
92 const SkTwoPointConicalGradient& shader, | 92 const SkTwoPointConicalGradient& shader, |
93 const SkMatrix& matrix, | 93 const SkMatrix& matrix, |
94 SkShader::TileMode tm) | 94 SkShader::TileMode tm) |
95 : INHERITED(ctx, shader, matrix, tm), | 95 : INHERITED(ctx, shader, matrix, tm), |
96 fCenterX1(shader.getCenterX1()), | 96 fCenterX1(shader.getCenterX1()), |
97 fRadius0(shader.getStartRadius()), | 97 fRadius0(shader.getStartRadius()), |
98 fDiffRadius(shader.getDiffRadius()){ | 98 fDiffRadius(shader.getDiffRadius()){ |
99 // We should only be calling this shader if we are degenerate case with
touching circles | 99 // We should only be calling this shader if we are degenerate case with
touching circles |
100 // When deciding if we are in edge case, we scaled by the end radius for
cases when the | 100 // When deciding if we are in edge case, we scaled by the end radius for
cases when the |
101 // start radius was close to zero, otherwise we scaled by the start radi
us | 101 // start radius was close to zero, otherwise we scaled by the start radi
us. In addition |
102 SkASSERT(SkScalarAbs(SkScalarAbs(fDiffRadius) - SkScalarAbs(fCenterX1))
< | 102 // Our test for the edge case in set_matrix_circle_conical has a higher
tolerance so we |
103 kEdgeErrorTol * (fRadius0 < kErrorTol ? shader.getEndRadius() :
fRadius0)); | 103 // need the sqrt value below |
| 104 SkASSERT(SkScalarAbs(SkScalarAbs(fDiffRadius) - fCenterX1) < |
| 105 (fRadius0 < kErrorTol ? shader.getEndRadius() * kEdgeErrorTol : |
| 106 fRadius0 * sqrt(kEdgeErrorTol))); |
104 | 107 |
105 // We pass the linear part of the quadratic as a varying. | 108 // We pass the linear part of the quadratic as a varying. |
106 // float b = -2.0 * (fCenterX1 * x + fRadius0 * fDiffRadius * z) | 109 // float b = -2.0 * (fCenterX1 * x + fRadius0 * fDiffRadius * z) |
107 fBTransform = this->getCoordTransform(); | 110 fBTransform = this->getCoordTransform(); |
108 SkMatrix& bMatrix = *fBTransform.accessMatrix(); | 111 SkMatrix& bMatrix = *fBTransform.accessMatrix(); |
109 SkScalar r0dr = SkScalarMul(fRadius0, fDiffRadius); | 112 SkScalar r0dr = SkScalarMul(fRadius0, fDiffRadius); |
110 bMatrix[SkMatrix::kMScaleX] = -2 * (SkScalarMul(fCenterX1, bMatrix[SkMat
rix::kMScaleX]) + | 113 bMatrix[SkMatrix::kMScaleX] = -2 * (SkScalarMul(fCenterX1, bMatrix[SkMat
rix::kMScaleX]) + |
111 SkScalarMul(r0dr, bMatrix[SkMatrix::
kMPersp0])); | 114 SkScalarMul(r0dr, bMatrix[SkMatrix::
kMPersp0])); |
112 bMatrix[SkMatrix::kMSkewX] = -2 * (SkScalarMul(fCenterX1, bMatrix[SkMatr
ix::kMSkewX]) + | 115 bMatrix[SkMatrix::kMSkewX] = -2 * (SkScalarMul(fCenterX1, bMatrix[SkMatr
ix::kMSkewX]) + |
113 SkScalarMul(r0dr, bMatrix[SkMatrix::k
MPersp1])); | 116 SkScalarMul(r0dr, bMatrix[SkMatrix::k
MPersp1])); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 typedef GrGLGradientEffect INHERITED; | 169 typedef GrGLGradientEffect INHERITED; |
167 | 170 |
168 }; | 171 }; |
169 | 172 |
170 const GrBackendEffectFactory& Edge2PtConicalEffect::getFactory() const { | 173 const GrBackendEffectFactory& Edge2PtConicalEffect::getFactory() const { |
171 return GrTBackendEffectFactory<Edge2PtConicalEffect>::getInstance(); | 174 return GrTBackendEffectFactory<Edge2PtConicalEffect>::getInstance(); |
172 } | 175 } |
173 | 176 |
174 GR_DEFINE_EFFECT_TEST(Edge2PtConicalEffect); | 177 GR_DEFINE_EFFECT_TEST(Edge2PtConicalEffect); |
175 | 178 |
| 179 /* |
| 180 * All Two point conical gradient test create functions may occasionally create
edge case shaders |
| 181 */ |
176 GrEffect* Edge2PtConicalEffect::TestCreate(SkRandom* random, | 182 GrEffect* Edge2PtConicalEffect::TestCreate(SkRandom* random, |
177 GrContext* context, | 183 GrContext* context, |
178 const GrDrawTargetCaps&, | 184 const GrDrawTargetCaps&, |
179 GrTexture**) { | 185 GrTexture**) { |
180 SkPoint center1 = {random->nextUScalar1(), random->nextUScalar1()}; | 186 SkPoint center1 = {random->nextUScalar1(), random->nextUScalar1()}; |
181 SkScalar radius1 = random->nextUScalar1(); | 187 SkScalar radius1 = random->nextUScalar1(); |
182 SkPoint center2; | 188 SkPoint center2; |
183 SkScalar radius2; | 189 SkScalar radius2; |
184 do { | 190 do { |
185 center2.set(random->nextUScalar1(), random->nextUScalar1()); | 191 center2.set(random->nextUScalar1(), random->nextUScalar1()); |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 typedef GrGLGradientEffect INHERITED; | 451 typedef GrGLGradientEffect INHERITED; |
446 | 452 |
447 }; | 453 }; |
448 | 454 |
449 const GrBackendEffectFactory& FocalOutside2PtConicalEffect::getFactory() const { | 455 const GrBackendEffectFactory& FocalOutside2PtConicalEffect::getFactory() const { |
450 return GrTBackendEffectFactory<FocalOutside2PtConicalEffect>::getInstance(); | 456 return GrTBackendEffectFactory<FocalOutside2PtConicalEffect>::getInstance(); |
451 } | 457 } |
452 | 458 |
453 GR_DEFINE_EFFECT_TEST(FocalOutside2PtConicalEffect); | 459 GR_DEFINE_EFFECT_TEST(FocalOutside2PtConicalEffect); |
454 | 460 |
| 461 /* |
| 462 * All Two point conical gradient test create functions may occasionally create
edge case shaders |
| 463 */ |
455 GrEffect* FocalOutside2PtConicalEffect::TestCreate(SkRandom* random, | 464 GrEffect* FocalOutside2PtConicalEffect::TestCreate(SkRandom* random, |
456 GrContext* context, | 465 GrContext* context, |
457 const GrDrawTargetCaps&, | 466 const GrDrawTargetCaps&, |
458 GrTexture**) { | 467 GrTexture**) { |
459 SkPoint center1 = {random->nextUScalar1(), random->nextUScalar1()}; | 468 SkPoint center1 = {random->nextUScalar1(), random->nextUScalar1()}; |
460 SkScalar radius1 = 0.f; | 469 SkScalar radius1 = 0.f; |
461 SkPoint center2; | 470 SkPoint center2; |
462 SkScalar radius2; | 471 SkScalar radius2; |
463 do { | 472 do { |
464 center2.set(random->nextUScalar1(), random->nextUScalar1()); | 473 center2.set(random->nextUScalar1(), random->nextUScalar1()); |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
649 typedef GrGLGradientEffect INHERITED; | 658 typedef GrGLGradientEffect INHERITED; |
650 | 659 |
651 }; | 660 }; |
652 | 661 |
653 const GrBackendEffectFactory& FocalInside2PtConicalEffect::getFactory() const { | 662 const GrBackendEffectFactory& FocalInside2PtConicalEffect::getFactory() const { |
654 return GrTBackendEffectFactory<FocalInside2PtConicalEffect>::getInstance(); | 663 return GrTBackendEffectFactory<FocalInside2PtConicalEffect>::getInstance(); |
655 } | 664 } |
656 | 665 |
657 GR_DEFINE_EFFECT_TEST(FocalInside2PtConicalEffect); | 666 GR_DEFINE_EFFECT_TEST(FocalInside2PtConicalEffect); |
658 | 667 |
| 668 /* |
| 669 * All Two point conical gradient test create functions may occasionally create
edge case shaders |
| 670 */ |
659 GrEffect* FocalInside2PtConicalEffect::TestCreate(SkRandom* random, | 671 GrEffect* FocalInside2PtConicalEffect::TestCreate(SkRandom* random, |
660 GrContext* context, | 672 GrContext* context, |
661 const GrDrawTargetCaps&, | 673 const GrDrawTargetCaps&, |
662 GrTexture**) { | 674 GrTexture**) { |
663 SkPoint center1 = {random->nextUScalar1(), random->nextUScalar1()}; | 675 SkPoint center1 = {random->nextUScalar1(), random->nextUScalar1()}; |
664 SkScalar radius1 = 0.f; | 676 SkScalar radius1 = 0.f; |
665 SkPoint center2; | 677 SkPoint center2; |
666 SkScalar radius2; | 678 SkScalar radius2; |
667 do { | 679 do { |
668 center2.set(random->nextUScalar1(), random->nextUScalar1()); | 680 center2.set(random->nextUScalar1(), random->nextUScalar1()); |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
896 typedef GrGLGradientEffect INHERITED; | 908 typedef GrGLGradientEffect INHERITED; |
897 | 909 |
898 }; | 910 }; |
899 | 911 |
900 const GrBackendEffectFactory& CircleInside2PtConicalEffect::getFactory() const { | 912 const GrBackendEffectFactory& CircleInside2PtConicalEffect::getFactory() const { |
901 return GrTBackendEffectFactory<CircleInside2PtConicalEffect>::getInstance(); | 913 return GrTBackendEffectFactory<CircleInside2PtConicalEffect>::getInstance(); |
902 } | 914 } |
903 | 915 |
904 GR_DEFINE_EFFECT_TEST(CircleInside2PtConicalEffect); | 916 GR_DEFINE_EFFECT_TEST(CircleInside2PtConicalEffect); |
905 | 917 |
| 918 /* |
| 919 * All Two point conical gradient test create functions may occasionally create
edge case shaders |
| 920 */ |
906 GrEffect* CircleInside2PtConicalEffect::TestCreate(SkRandom* random, | 921 GrEffect* CircleInside2PtConicalEffect::TestCreate(SkRandom* random, |
907 GrContext* context, | 922 GrContext* context, |
908 const GrDrawTargetCaps&, | 923 const GrDrawTargetCaps&, |
909 GrTexture**) { | 924 GrTexture**) { |
910 SkPoint center1 = {random->nextUScalar1(), random->nextUScalar1()}; | 925 SkPoint center1 = {random->nextUScalar1(), random->nextUScalar1()}; |
911 SkScalar radius1 = random->nextUScalar1() + 0.0001f; // make sure radius1 !=
0 | 926 SkScalar radius1 = random->nextUScalar1() + 0.0001f; // make sure radius1 !=
0 |
912 SkPoint center2; | 927 SkPoint center2; |
913 SkScalar radius2; | 928 SkScalar radius2; |
914 do { | 929 do { |
915 center2.set(random->nextUScalar1(), random->nextUScalar1()); | 930 center2.set(random->nextUScalar1(), random->nextUScalar1()); |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1128 typedef GrGLGradientEffect INHERITED; | 1143 typedef GrGLGradientEffect INHERITED; |
1129 | 1144 |
1130 }; | 1145 }; |
1131 | 1146 |
1132 const GrBackendEffectFactory& CircleOutside2PtConicalEffect::getFactory() const
{ | 1147 const GrBackendEffectFactory& CircleOutside2PtConicalEffect::getFactory() const
{ |
1133 return GrTBackendEffectFactory<CircleOutside2PtConicalEffect>::getInstance()
; | 1148 return GrTBackendEffectFactory<CircleOutside2PtConicalEffect>::getInstance()
; |
1134 } | 1149 } |
1135 | 1150 |
1136 GR_DEFINE_EFFECT_TEST(CircleOutside2PtConicalEffect); | 1151 GR_DEFINE_EFFECT_TEST(CircleOutside2PtConicalEffect); |
1137 | 1152 |
| 1153 /* |
| 1154 * All Two point conical gradient test create functions may occasionally create
edge case shaders |
| 1155 */ |
1138 GrEffect* CircleOutside2PtConicalEffect::TestCreate(SkRandom* random, | 1156 GrEffect* CircleOutside2PtConicalEffect::TestCreate(SkRandom* random, |
1139 GrContext* context, | 1157 GrContext* context, |
1140 const GrDrawTargetCaps&, | 1158 const GrDrawTargetCaps&, |
1141 GrTexture**) { | 1159 GrTexture**) { |
1142 SkPoint center1 = {random->nextUScalar1(), random->nextUScalar1()}; | 1160 SkPoint center1 = {random->nextUScalar1(), random->nextUScalar1()}; |
1143 SkScalar radius1 = random->nextUScalar1() + 0.0001f; // make sure radius1 !=
0 | 1161 SkScalar radius1 = random->nextUScalar1() + 0.0001f; // make sure radius1 !=
0 |
1144 SkPoint center2; | 1162 SkPoint center2; |
1145 SkScalar radius2; | 1163 SkScalar radius2; |
1146 SkScalar diffLen; | 1164 SkScalar diffLen; |
1147 do { | 1165 do { |
1148 center2.set(random->nextUScalar1(), random->nextUScalar1()); | 1166 center2.set(random->nextUScalar1(), random->nextUScalar1()); |
1149 // If the circles share a center than we can't be in the outside case | 1167 // If the circles share a center than we can't be in the outside case |
1150 } while (center1 == center2); | 1168 } while (center1 == center2); |
1151 SkPoint diff = center2 - center1; | 1169 SkPoint diff = center2 - center1; |
1152 diffLen = diff.length(); | 1170 diffLen = diff.length(); |
1153 // Below makes sure that circle one is not contained within circle two | 1171 // Below makes sure that circle one is not contained within circle two |
1154 // and have radius2 >= radius to match sorting on cpu side | 1172 // and have radius2 >= radius to match sorting on cpu side |
1155 radius2 = radius1 + random->nextRangeF(0.f, diffLen); | 1173 radius2 = radius1 + random->nextRangeF(0.f, diffLen); |
1156 | 1174 |
1157 SkColor colors[kMaxRandomGradientColors]; | 1175 SkColor colors[kMaxRandomGradientColors]; |
1158 SkScalar stopsArray[kMaxRandomGradientColors]; | 1176 SkScalar stopsArray[kMaxRandomGradientColors]; |
1159 SkScalar* stops = stopsArray; | 1177 SkScalar* stops = stopsArray; |
1160 SkShader::TileMode tm; | 1178 SkShader::TileMode tm; |
1161 int colorCount = RandomGradientParams(random, colors, &stops, &tm); | 1179 int colorCount = RandomGradientParams(random, colors, &stops, &tm); |
1162 SkAutoTUnref<SkShader> shader(SkGradientShader::CreateTwoPointConical(center
1, radius1, | 1180 SkAutoTUnref<SkShader> shader(SkGradientShader::CreateTwoPointConical(center
1, radius1, |
1163 center
2, radius2, | 1181 center
2, radius2, |
1164 colors
, stops, colorCount, | 1182 colors
, stops, colorCount, |
1165 tm)); | 1183 tm)); |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1317 return CircleInside2PtConicalEffect::Create(ctx, shader, matrix, tm, inf
o); | 1335 return CircleInside2PtConicalEffect::Create(ctx, shader, matrix, tm, inf
o); |
1318 } else if (type == kEdge_ConicalType) { | 1336 } else if (type == kEdge_ConicalType) { |
1319 set_matrix_edge_conical(shader, &matrix); | 1337 set_matrix_edge_conical(shader, &matrix); |
1320 return Edge2PtConicalEffect::Create(ctx, shader, matrix, tm); | 1338 return Edge2PtConicalEffect::Create(ctx, shader, matrix, tm); |
1321 } else { | 1339 } else { |
1322 return CircleOutside2PtConicalEffect::Create(ctx, shader, matrix, tm, in
fo); | 1340 return CircleOutside2PtConicalEffect::Create(ctx, shader, matrix, tm, in
fo); |
1323 } | 1341 } |
1324 } | 1342 } |
1325 | 1343 |
1326 #endif | 1344 #endif |
OLD | NEW |