| 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 |
| 11 #include "SkTwoPointConicalGradient.h" | 11 #include "SkTwoPointConicalGradient.h" |
| 12 | 12 |
| 13 #if SK_SUPPORT_GPU | 13 #if SK_SUPPORT_GPU |
| 14 #include "GrPaint.h" |
| 14 #include "gl/builders/GrGLProgramBuilder.h" | 15 #include "gl/builders/GrGLProgramBuilder.h" |
| 15 // For brevity | 16 // For brevity |
| 16 typedef GrGLProgramDataManager::UniformHandle UniformHandle; | 17 typedef GrGLProgramDataManager::UniformHandle UniformHandle; |
| 17 | 18 |
| 18 static const SkScalar kErrorTol = 0.00001f; | 19 static const SkScalar kErrorTol = 0.00001f; |
| 19 static const SkScalar kEdgeErrorTol = 5.f * kErrorTol; | 20 static const SkScalar kEdgeErrorTol = 5.f * kErrorTol; |
| 20 | 21 |
| 21 /** | 22 /** |
| 22 * We have three general cases for 2pt conical gradients. First we always assume
that | 23 * We have three general cases for 2pt conical gradients. First we always assume
that |
| 23 * the start radius <= end radius. Our first case (kInside_) is when the start c
ircle | 24 * the start radius <= end radius. Our first case (kInside_) is when the start c
ircle |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 SkScalar* stops = stopsArray; | 210 SkScalar* stops = stopsArray; |
| 210 SkShader::TileMode tm; | 211 SkShader::TileMode tm; |
| 211 int colorCount = RandomGradientParams(random, colors, &stops, &tm); | 212 int colorCount = RandomGradientParams(random, colors, &stops, &tm); |
| 212 SkAutoTUnref<SkShader> shader(SkGradientShader::CreateTwoPointConical(center
1, radius1, | 213 SkAutoTUnref<SkShader> shader(SkGradientShader::CreateTwoPointConical(center
1, radius1, |
| 213 center
2, radius2, | 214 center
2, radius2, |
| 214 colors
, stops, colorCount, | 215 colors
, stops, colorCount, |
| 215 tm)); | 216 tm)); |
| 216 SkPaint paint; | 217 SkPaint paint; |
| 217 GrFragmentProcessor* fp; | 218 GrFragmentProcessor* fp; |
| 218 GrColor paintColor; | 219 GrColor paintColor; |
| 220 GrPaint grPaint; |
| 219 SkAssertResult(shader->asFragmentProcessor(context, paint, | 221 SkAssertResult(shader->asFragmentProcessor(context, paint, |
| 220 GrTest::TestMatrix(random), NULL, | 222 GrTest::TestMatrix(random), NULL, |
| 221 &paintColor, &fp)); | 223 &paintColor, grPaint.getShaderDat
aManager(), &fp)); |
| 222 return fp; | 224 return fp; |
| 223 } | 225 } |
| 224 | 226 |
| 225 GLEdge2PtConicalEffect::GLEdge2PtConicalEffect(const GrProcessor&) | 227 GLEdge2PtConicalEffect::GLEdge2PtConicalEffect(const GrProcessor&) |
| 226 : fVSVaryingName(NULL) | 228 : fVSVaryingName(NULL) |
| 227 , fFSVaryingName(NULL) | 229 , fFSVaryingName(NULL) |
| 228 , fCachedRadius(-SK_ScalarMax) | 230 , fCachedRadius(-SK_ScalarMax) |
| 229 , fCachedDiffRadius(-SK_ScalarMax) {} | 231 , fCachedDiffRadius(-SK_ScalarMax) {} |
| 230 | 232 |
| 231 void GLEdge2PtConicalEffect::emitCode(GrGLFPBuilder* builder, | 233 void GLEdge2PtConicalEffect::emitCode(GrGLFPBuilder* builder, |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 495 SkScalar* stops = stopsArray; | 497 SkScalar* stops = stopsArray; |
| 496 SkShader::TileMode tm; | 498 SkShader::TileMode tm; |
| 497 int colorCount = RandomGradientParams(random, colors, &stops, &tm); | 499 int colorCount = RandomGradientParams(random, colors, &stops, &tm); |
| 498 SkAutoTUnref<SkShader> shader(SkGradientShader::CreateTwoPointConical(center
1, radius1, | 500 SkAutoTUnref<SkShader> shader(SkGradientShader::CreateTwoPointConical(center
1, radius1, |
| 499 center
2, radius2, | 501 center
2, radius2, |
| 500 colors
, stops, colorCount, | 502 colors
, stops, colorCount, |
| 501 tm)); | 503 tm)); |
| 502 SkPaint paint; | 504 SkPaint paint; |
| 503 GrFragmentProcessor* effect; | 505 GrFragmentProcessor* effect; |
| 504 GrColor paintColor; | 506 GrColor paintColor; |
| 505 | 507 GrPaint grPaint; |
| 506 SkAssertResult(shader->asFragmentProcessor(context, paint, | 508 SkAssertResult(shader->asFragmentProcessor(context, paint, |
| 507 GrTest::TestMatrix(random), NULL, | 509 GrTest::TestMatrix(random), NULL, |
| 508 &paintColor, &effect)); | 510 &paintColor, grPaint.getShaderDat
aManager(), |
| 511 &effect)); |
| 509 return effect; | 512 return effect; |
| 510 } | 513 } |
| 511 | 514 |
| 512 GLFocalOutside2PtConicalEffect::GLFocalOutside2PtConicalEffect(const GrProcessor
& processor) | 515 GLFocalOutside2PtConicalEffect::GLFocalOutside2PtConicalEffect(const GrProcessor
& processor) |
| 513 : fVSVaryingName(NULL) | 516 : fVSVaryingName(NULL) |
| 514 , fFSVaryingName(NULL) | 517 , fFSVaryingName(NULL) |
| 515 , fCachedFocal(SK_ScalarMax) { | 518 , fCachedFocal(SK_ScalarMax) { |
| 516 const FocalOutside2PtConicalEffect& data = processor.cast<FocalOutside2PtCon
icalEffect>(); | 519 const FocalOutside2PtConicalEffect& data = processor.cast<FocalOutside2PtCon
icalEffect>(); |
| 517 fIsFlipped = data.isFlipped(); | 520 fIsFlipped = data.isFlipped(); |
| 518 } | 521 } |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 716 SkScalar* stops = stopsArray; | 719 SkScalar* stops = stopsArray; |
| 717 SkShader::TileMode tm; | 720 SkShader::TileMode tm; |
| 718 int colorCount = RandomGradientParams(random, colors, &stops, &tm); | 721 int colorCount = RandomGradientParams(random, colors, &stops, &tm); |
| 719 SkAutoTUnref<SkShader> shader(SkGradientShader::CreateTwoPointConical(center
1, radius1, | 722 SkAutoTUnref<SkShader> shader(SkGradientShader::CreateTwoPointConical(center
1, radius1, |
| 720 center
2, radius2, | 723 center
2, radius2, |
| 721 colors
, stops, colorCount, | 724 colors
, stops, colorCount, |
| 722 tm)); | 725 tm)); |
| 723 SkPaint paint; | 726 SkPaint paint; |
| 724 GrColor paintColor; | 727 GrColor paintColor; |
| 725 GrFragmentProcessor* fp; | 728 GrFragmentProcessor* fp; |
| 729 GrPaint grPaint; |
| 726 SkAssertResult(shader->asFragmentProcessor(context, paint, | 730 SkAssertResult(shader->asFragmentProcessor(context, paint, |
| 727 GrTest::TestMatrix(random), NULL, | 731 GrTest::TestMatrix(random), NULL, |
| 728 &paintColor, &fp)); | 732 &paintColor, grPaint.getShaderDat
aManager(), &fp)); |
| 729 return fp; | 733 return fp; |
| 730 } | 734 } |
| 731 | 735 |
| 732 GLFocalInside2PtConicalEffect::GLFocalInside2PtConicalEffect(const GrProcessor&) | 736 GLFocalInside2PtConicalEffect::GLFocalInside2PtConicalEffect(const GrProcessor&) |
| 733 : fVSVaryingName(NULL) | 737 : fVSVaryingName(NULL) |
| 734 , fFSVaryingName(NULL) | 738 , fFSVaryingName(NULL) |
| 735 , fCachedFocal(SK_ScalarMax) {} | 739 , fCachedFocal(SK_ScalarMax) {} |
| 736 | 740 |
| 737 void GLFocalInside2PtConicalEffect::emitCode(GrGLFPBuilder* builder, | 741 void GLFocalInside2PtConicalEffect::emitCode(GrGLFPBuilder* builder, |
| 738 const GrFragmentProcessor& fp, | 742 const GrFragmentProcessor& fp, |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 970 SkScalar stopsArray[kMaxRandomGradientColors]; | 974 SkScalar stopsArray[kMaxRandomGradientColors]; |
| 971 SkScalar* stops = stopsArray; | 975 SkScalar* stops = stopsArray; |
| 972 SkShader::TileMode tm; | 976 SkShader::TileMode tm; |
| 973 int colorCount = RandomGradientParams(random, colors, &stops, &tm); | 977 int colorCount = RandomGradientParams(random, colors, &stops, &tm); |
| 974 SkAutoTUnref<SkShader> shader(SkGradientShader::CreateTwoPointConical(center
1, radius1, | 978 SkAutoTUnref<SkShader> shader(SkGradientShader::CreateTwoPointConical(center
1, radius1, |
| 975 center
2, radius2, | 979 center
2, radius2, |
| 976 colors
, stops, colorCount, | 980 colors
, stops, colorCount, |
| 977 tm)); | 981 tm)); |
| 978 SkPaint paint; | 982 SkPaint paint; |
| 979 GrColor paintColor; | 983 GrColor paintColor; |
| 980 GrFragmentProcessor* processor; | 984 GrFragmentProcessor* fp; |
| 985 GrPaint grPaint; |
| 981 SkAssertResult(shader->asFragmentProcessor(context, paint, | 986 SkAssertResult(shader->asFragmentProcessor(context, paint, |
| 982 GrTest::TestMatrix(random), NULL, | 987 GrTest::TestMatrix(random), NULL, |
| 983 &paintColor, &processor)); | 988 &paintColor, grPaint.getShaderDat
aManager(), &fp)); |
| 984 return processor; | 989 return fp; |
| 985 } | 990 } |
| 986 | 991 |
| 987 GLCircleInside2PtConicalEffect::GLCircleInside2PtConicalEffect(const GrProcessor
& processor) | 992 GLCircleInside2PtConicalEffect::GLCircleInside2PtConicalEffect(const GrProcessor
& processor) |
| 988 : fVSVaryingName(NULL) | 993 : fVSVaryingName(NULL) |
| 989 , fFSVaryingName(NULL) | 994 , fFSVaryingName(NULL) |
| 990 , fCachedCenterX(SK_ScalarMax) | 995 , fCachedCenterX(SK_ScalarMax) |
| 991 , fCachedCenterY(SK_ScalarMax) | 996 , fCachedCenterY(SK_ScalarMax) |
| 992 , fCachedA(SK_ScalarMax) | 997 , fCachedA(SK_ScalarMax) |
| 993 , fCachedB(SK_ScalarMax) | 998 , fCachedB(SK_ScalarMax) |
| 994 , fCachedC(SK_ScalarMax) {} | 999 , fCachedC(SK_ScalarMax) {} |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1210 SkScalar stopsArray[kMaxRandomGradientColors]; | 1215 SkScalar stopsArray[kMaxRandomGradientColors]; |
| 1211 SkScalar* stops = stopsArray; | 1216 SkScalar* stops = stopsArray; |
| 1212 SkShader::TileMode tm; | 1217 SkShader::TileMode tm; |
| 1213 int colorCount = RandomGradientParams(random, colors, &stops, &tm); | 1218 int colorCount = RandomGradientParams(random, colors, &stops, &tm); |
| 1214 SkAutoTUnref<SkShader> shader(SkGradientShader::CreateTwoPointConical(center
1, radius1, | 1219 SkAutoTUnref<SkShader> shader(SkGradientShader::CreateTwoPointConical(center
1, radius1, |
| 1215 center
2, radius2, | 1220 center
2, radius2, |
| 1216 colors
, stops, colorCount, | 1221 colors
, stops, colorCount, |
| 1217 tm)); | 1222 tm)); |
| 1218 SkPaint paint; | 1223 SkPaint paint; |
| 1219 GrColor paintColor; | 1224 GrColor paintColor; |
| 1220 GrFragmentProcessor* processor; | 1225 GrFragmentProcessor* fp; |
| 1221 | 1226 GrPaint grPaint; |
| 1222 SkAssertResult(shader->asFragmentProcessor(context, paint, | 1227 SkAssertResult(shader->asFragmentProcessor(context, paint, |
| 1223 GrTest::TestMatrix(random), NULL, | 1228 GrTest::TestMatrix(random), NULL, |
| 1224 &paintColor, &processor)); | 1229 &paintColor, grPaint.getShaderDat
aManager(), &fp)); |
| 1225 return processor; | 1230 return fp; |
| 1226 } | 1231 } |
| 1227 | 1232 |
| 1228 GLCircleOutside2PtConicalEffect::GLCircleOutside2PtConicalEffect(const GrProcess
or& processor) | 1233 GLCircleOutside2PtConicalEffect::GLCircleOutside2PtConicalEffect(const GrProcess
or& processor) |
| 1229 : fVSVaryingName(NULL) | 1234 : fVSVaryingName(NULL) |
| 1230 , fFSVaryingName(NULL) | 1235 , fFSVaryingName(NULL) |
| 1231 , fCachedCenterX(SK_ScalarMax) | 1236 , fCachedCenterX(SK_ScalarMax) |
| 1232 , fCachedCenterY(SK_ScalarMax) | 1237 , fCachedCenterY(SK_ScalarMax) |
| 1233 , fCachedA(SK_ScalarMax) | 1238 , fCachedA(SK_ScalarMax) |
| 1234 , fCachedB(SK_ScalarMax) | 1239 , fCachedB(SK_ScalarMax) |
| 1235 , fCachedC(SK_ScalarMax) | 1240 , fCachedC(SK_ScalarMax) |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1371 return CircleInside2PtConicalEffect::Create(ctx, shader, matrix, tm, inf
o); | 1376 return CircleInside2PtConicalEffect::Create(ctx, shader, matrix, tm, inf
o); |
| 1372 } else if (type == kEdge_ConicalType) { | 1377 } else if (type == kEdge_ConicalType) { |
| 1373 set_matrix_edge_conical(shader, &matrix); | 1378 set_matrix_edge_conical(shader, &matrix); |
| 1374 return Edge2PtConicalEffect::Create(ctx, shader, matrix, tm); | 1379 return Edge2PtConicalEffect::Create(ctx, shader, matrix, tm); |
| 1375 } else { | 1380 } else { |
| 1376 return CircleOutside2PtConicalEffect::Create(ctx, shader, matrix, tm, in
fo); | 1381 return CircleOutside2PtConicalEffect::Create(ctx, shader, matrix, tm, in
fo); |
| 1377 } | 1382 } |
| 1378 } | 1383 } |
| 1379 | 1384 |
| 1380 #endif | 1385 #endif |
| OLD | NEW |