Chromium Code Reviews| 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 767 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 778 matrix.mapPoints(¢erEndTrans, ¢erEnd, 1); | 778 matrix.mapPoints(¢erEndTrans, ¢erEnd, 1); |
| 779 | 779 |
| 780 SkScalar A = centerEndTrans.fX * centerEndTrans.fX + centerEndTrans.fY * cen terEndTrans.fY | 780 SkScalar A = centerEndTrans.fX * centerEndTrans.fX + centerEndTrans.fY * cen terEndTrans.fY |
| 781 - radiusEnd * radiusEnd + 2 * radiusEnd - 1; | 781 - radiusEnd * radiusEnd + 2 * radiusEnd - 1; |
| 782 | 782 |
| 783 // Check to see if start circle is inside end circle with edges touching. | 783 // Check to see if start circle is inside end circle with edges touching. |
| 784 // If touching we return that it is of kEdge_ConicalType, and leave the matr ix setting | 784 // If touching we return that it is of kEdge_ConicalType, and leave the matr ix setting |
| 785 // to the edge shader. kEdgeErrorTol = 5 * kErrorTol was picked after manual testing | 785 // to the edge shader. kEdgeErrorTol = 5 * kErrorTol was picked after manual testing |
| 786 // so that C = 1 / A is stable, and the linear approximation used in the Edg e shader is | 786 // so that C = 1 / A is stable, and the linear approximation used in the Edg e shader is |
| 787 // still accurate. | 787 // still accurate. |
| 788 if (SkScalarAbs(A) < kEdgeErrorTol) { | 788 if (SkScalarAbs(centerEndTrans.length() - (radiusEnd - 1)) < kEdgeErrorTol) { |
| 789 return kEdge_ConicalType; | 789 return kEdge_ConicalType; |
| 790 } | 790 } |
| 791 | 791 |
| 792 SkScalar C = 1.f / A; | 792 SkScalar C = 1.f / A; |
| 793 SkScalar B = (radiusEnd - 1.f) * C; | 793 SkScalar B = (radiusEnd - 1.f) * C; |
| 794 | 794 |
| 795 matrix.postScale(C, C); | 795 matrix.postScale(C, C); |
| 796 | 796 |
| 797 invLMatrix->postConcat(matrix); | 797 invLMatrix->postConcat(matrix); |
| 798 | 798 |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 910 SkPoint center1 = {random->nextUScalar1(), random->nextUScalar1()}; | 910 SkPoint center1 = {random->nextUScalar1(), random->nextUScalar1()}; |
| 911 SkScalar radius1 = random->nextUScalar1() + 0.0001f; // make sure radius1 != 0 | 911 SkScalar radius1 = random->nextUScalar1() + 0.0001f; // make sure radius1 != 0 |
| 912 SkPoint center2; | 912 SkPoint center2; |
| 913 SkScalar radius2; | 913 SkScalar radius2; |
| 914 do { | 914 do { |
| 915 center2.set(random->nextUScalar1(), random->nextUScalar1()); | 915 center2.set(random->nextUScalar1(), random->nextUScalar1()); |
| 916 // Below makes sure that circle one is contained within circle two | 916 // Below makes sure that circle one is contained within circle two |
| 917 SkScalar increase = random->nextUScalar1(); | 917 SkScalar increase = random->nextUScalar1(); |
| 918 SkPoint diff = center2 - center1; | 918 SkPoint diff = center2 - center1; |
| 919 SkScalar diffLen = diff.length(); | 919 SkScalar diffLen = diff.length(); |
| 920 radius2 = radius1 + diffLen + increase; | 920 radius2 = radius1 + diffLen + increase; |
|
egdaniel
2014/09/22 14:57:01
radius2 = radius1 + diffLen + increase + radius1 *
| |
| 921 // If the circles are identical the factory will give us an empty shader . | 921 // If the circles are identical the factory will give us an empty shader . |
| 922 } while (radius1 == radius2 && center1 == center2); | 922 } while (radius1 == radius2 && center1 == center2); |
| 923 | 923 |
| 924 SkColor colors[kMaxRandomGradientColors]; | 924 SkColor colors[kMaxRandomGradientColors]; |
| 925 SkScalar stopsArray[kMaxRandomGradientColors]; | 925 SkScalar stopsArray[kMaxRandomGradientColors]; |
| 926 SkScalar* stops = stopsArray; | 926 SkScalar* stops = stopsArray; |
| 927 SkShader::TileMode tm; | 927 SkShader::TileMode tm; |
| 928 int colorCount = RandomGradientParams(random, colors, &stops, &tm); | 928 int colorCount = RandomGradientParams(random, colors, &stops, &tm); |
| 929 SkAutoTUnref<SkShader> shader(SkGradientShader::CreateTwoPointConical(center 1, radius1, | 929 SkAutoTUnref<SkShader> shader(SkGradientShader::CreateTwoPointConical(center 1, radius1, |
| 930 center 2, radius2, | 930 center 2, radius2, |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1145 SkScalar radius2; | 1145 SkScalar radius2; |
| 1146 SkScalar diffLen; | 1146 SkScalar diffLen; |
| 1147 do { | 1147 do { |
| 1148 center2.set(random->nextUScalar1(), random->nextUScalar1()); | 1148 center2.set(random->nextUScalar1(), random->nextUScalar1()); |
| 1149 // If the circles share a center than we can't be in the outside case | 1149 // If the circles share a center than we can't be in the outside case |
| 1150 } while (center1 == center2); | 1150 } while (center1 == center2); |
| 1151 SkPoint diff = center2 - center1; | 1151 SkPoint diff = center2 - center1; |
| 1152 diffLen = diff.length(); | 1152 diffLen = diff.length(); |
| 1153 // Below makes sure that circle one is not contained within circle two | 1153 // Below makes sure that circle one is not contained within circle two |
| 1154 // and have radius2 >= radius to match sorting on cpu side | 1154 // and have radius2 >= radius to match sorting on cpu side |
| 1155 radius2 = radius1 + random->nextRangeF(0.f, diffLen); | 1155 radius2 = radius1 + random->nextRangeF(0.f, diffLen); |
|
egdaniel
2014/09/22 14:57:01
can we change this to:
radius2 = radius1 + random
| |
| 1156 | 1156 |
| 1157 SkColor colors[kMaxRandomGradientColors]; | 1157 SkColor colors[kMaxRandomGradientColors]; |
| 1158 SkScalar stopsArray[kMaxRandomGradientColors]; | 1158 SkScalar stopsArray[kMaxRandomGradientColors]; |
| 1159 SkScalar* stops = stopsArray; | 1159 SkScalar* stops = stopsArray; |
| 1160 SkShader::TileMode tm; | 1160 SkShader::TileMode tm; |
| 1161 int colorCount = RandomGradientParams(random, colors, &stops, &tm); | 1161 int colorCount = RandomGradientParams(random, colors, &stops, &tm); |
| 1162 SkAutoTUnref<SkShader> shader(SkGradientShader::CreateTwoPointConical(center 1, radius1, | 1162 SkAutoTUnref<SkShader> shader(SkGradientShader::CreateTwoPointConical(center 1, radius1, |
| 1163 center 2, radius2, | 1163 center 2, radius2, |
| 1164 colors , stops, colorCount, | 1164 colors , stops, colorCount, |
| 1165 tm)); | 1165 tm)); |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1317 return CircleInside2PtConicalEffect::Create(ctx, shader, matrix, tm, inf o); | 1317 return CircleInside2PtConicalEffect::Create(ctx, shader, matrix, tm, inf o); |
| 1318 } else if (type == kEdge_ConicalType) { | 1318 } else if (type == kEdge_ConicalType) { |
| 1319 set_matrix_edge_conical(shader, &matrix); | 1319 set_matrix_edge_conical(shader, &matrix); |
| 1320 return Edge2PtConicalEffect::Create(ctx, shader, matrix, tm); | 1320 return Edge2PtConicalEffect::Create(ctx, shader, matrix, tm); |
| 1321 } else { | 1321 } else { |
| 1322 return CircleOutside2PtConicalEffect::Create(ctx, shader, matrix, tm, in fo); | 1322 return CircleOutside2PtConicalEffect::Create(ctx, shader, matrix, tm, in fo); |
| 1323 } | 1323 } |
| 1324 } | 1324 } |
| 1325 | 1325 |
| 1326 #endif | 1326 #endif |
| OLD | NEW |