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

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

Issue 320573002: Revert of Fix Assert for gpu ConicalTwoPointGradient edgecase to be correct bounds. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 6 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 | « no previous file | no next file » | 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 /* 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 "GrTBackendEffectFactory.h" 14 #include "GrTBackendEffectFactory.h"
15 // For brevity 15 // For brevity
16 typedef GrGLUniformManager::UniformHandle UniformHandle; 16 typedef GrGLUniformManager::UniformHandle UniformHandle;
17 17
18 static const SkScalar kErrorTol = 0.00001f; 18 static const SkScalar kErrorTol = 0.00001f;
19 static const SkScalar kEdgeErrorTol = 5.f * kErrorTol;
20 19
21 /** 20 /**
22 * We have three general cases for 2pt conical gradients. First we always assume that 21 * 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 22 * the start radius <= end radius. Our first case (kInside_) is when the start c ircle
24 * is completely enclosed by the end circle. The second case (kOutside_) is the case 23 * is completely enclosed by the end circle. The second case (kOutside_) is the case
25 * when the start circle is either completely outside the end circle or the circ les 24 * when the start circle is either completely outside the end circle or the circ les
26 * overlap. The final case (kEdge_) is when the start circle is inside the end o ne, 25 * overlap. The final case (kEdge_) is when the start circle is inside the end o ne,
27 * but the two are just barely touching at 1 point along their edges. 26 * but the two are just barely touching at 1 point along their edges.
28 */ 27 */
29 enum ConicalType { 28 enum ConicalType {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 89
91 Edge2PtConicalEffect(GrContext* ctx, 90 Edge2PtConicalEffect(GrContext* ctx,
92 const SkTwoPointConicalGradient& shader, 91 const SkTwoPointConicalGradient& shader,
93 const SkMatrix& matrix, 92 const SkMatrix& matrix,
94 SkShader::TileMode tm) 93 SkShader::TileMode tm)
95 : INHERITED(ctx, shader, matrix, tm), 94 : INHERITED(ctx, shader, matrix, tm),
96 fCenterX1(shader.getCenterX1()), 95 fCenterX1(shader.getCenterX1()),
97 fRadius0(shader.getStartRadius()), 96 fRadius0(shader.getStartRadius()),
98 fDiffRadius(shader.getDiffRadius()){ 97 fDiffRadius(shader.getDiffRadius()){
99 // We should only be calling this shader if we are degenerate case with touching circles 98 // We should only be calling this shader if we are degenerate case with touching circles
100 SkASSERT(SkScalarAbs(SkScalarAbs(fDiffRadius) - SkScalarAbs(fCenterX1)) < 99 SkASSERT(SkScalarAbs(fDiffRadius) - SkScalarAbs(fCenterX1) < kErrorTol) ;
101 fRadius0 * kEdgeErrorTol);
102 100
103 // We pass the linear part of the quadratic as a varying. 101 // We pass the linear part of the quadratic as a varying.
104 // float b = -2.0 * (fCenterX1 * x + fRadius0 * fDiffRadius * z) 102 // float b = -2.0 * (fCenterX1 * x + fRadius0 * fDiffRadius * z)
105 fBTransform = this->getCoordTransform(); 103 fBTransform = this->getCoordTransform();
106 SkMatrix& bMatrix = *fBTransform.accessMatrix(); 104 SkMatrix& bMatrix = *fBTransform.accessMatrix();
107 SkScalar r0dr = SkScalarMul(fRadius0, fDiffRadius); 105 SkScalar r0dr = SkScalarMul(fRadius0, fDiffRadius);
108 bMatrix[SkMatrix::kMScaleX] = -2 * (SkScalarMul(fCenterX1, bMatrix[SkMat rix::kMScaleX]) + 106 bMatrix[SkMatrix::kMScaleX] = -2 * (SkScalarMul(fCenterX1, bMatrix[SkMat rix::kMScaleX]) +
109 SkScalarMul(r0dr, bMatrix[SkMatrix:: kMPersp0])); 107 SkScalarMul(r0dr, bMatrix[SkMatrix:: kMPersp0]));
110 bMatrix[SkMatrix::kMSkewX] = -2 * (SkScalarMul(fCenterX1, bMatrix[SkMatr ix::kMSkewX]) + 108 bMatrix[SkMatrix::kMSkewX] = -2 * (SkScalarMul(fCenterX1, bMatrix[SkMatr ix::kMSkewX]) +
111 SkScalarMul(r0dr, bMatrix[SkMatrix::k MPersp1])); 109 SkScalarMul(r0dr, bMatrix[SkMatrix::k MPersp1]));
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 SkMatrix rot; 321 SkMatrix rot;
324 rot.setSinCos(-SkScalarMul(invFocalX, focalTrans.fY), 322 rot.setSinCos(-SkScalarMul(invFocalX, focalTrans.fY),
325 SkScalarMul(invFocalX, focalTrans.fX)); 323 SkScalarMul(invFocalX, focalTrans.fX));
326 matrix.postConcat(rot); 324 matrix.postConcat(rot);
327 } 325 }
328 326
329 matrix.postTranslate(-(*focalX), 0.f); 327 matrix.postTranslate(-(*focalX), 0.f);
330 328
331 // If the focal point is touching the edge of the circle it will 329 // If the focal point is touching the edge of the circle it will
332 // cause a degenerate case that must be handled separately 330 // cause a degenerate case that must be handled separately
333 // kEdgeErrorTol = 5 * kErrorTol was picked after manual testing the 331 // 5 * kErrorTol was picked after manual testing the stability trade off
334 // stability trade off versus the linear approx used in the Edge Shader 332 // versus the linear approx used in the Edge Shader
335 if (SkScalarAbs(1.f - (*focalX)) < kEdgeErrorTol) { 333 if (SkScalarAbs(1.f - (*focalX)) < 5 * kErrorTol) {
336 return kEdge_ConicalType; 334 return kEdge_ConicalType;
337 } 335 }
338 336
339 // Scale factor 1 / (1 - focalX * focalX) 337 // Scale factor 1 / (1 - focalX * focalX)
340 SkScalar oneMinusF2 = 1.f - SkScalarMul(*focalX, *focalX); 338 SkScalar oneMinusF2 = 1.f - SkScalarMul(*focalX, *focalX);
341 SkScalar s = SkScalarDiv(1.f, oneMinusF2); 339 SkScalar s = SkScalarDiv(1.f, oneMinusF2);
342 340
343 341
344 if (s >= 0.f) { 342 if (s >= 0.f) {
345 conicalType = kInside_ConicalType; 343 conicalType = kInside_ConicalType;
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after
766 radiusEnd /= radiusStart; 764 radiusEnd /= radiusStart;
767 765
768 SkPoint centerEndTrans; 766 SkPoint centerEndTrans;
769 matrix.mapPoints(&centerEndTrans, &centerEnd, 1); 767 matrix.mapPoints(&centerEndTrans, &centerEnd, 1);
770 768
771 SkScalar A = centerEndTrans.fX * centerEndTrans.fX + centerEndTrans.fY * cen terEndTrans.fY 769 SkScalar A = centerEndTrans.fX * centerEndTrans.fX + centerEndTrans.fY * cen terEndTrans.fY
772 - radiusEnd * radiusEnd + 2 * radiusEnd - 1; 770 - radiusEnd * radiusEnd + 2 * radiusEnd - 1;
773 771
774 // Check to see if start circle is inside end circle with edges touching. 772 // Check to see if start circle is inside end circle with edges touching.
775 // If touching we return that it is of kEdge_ConicalType, and leave the matr ix setting 773 // If touching we return that it is of kEdge_ConicalType, and leave the matr ix setting
776 // to the edge shader. kEdgeErrorTol = 5 * kErrorTol was picked after manual testing 774 // to the edge shader. 5 * kErrorTol was picked after manual testing so that C = 1 / A
777 // so that C = 1 / A is stable, and the linear approximation used in the Edg e shader is 775 // is stable, and the linear approximation used in the Edge shader is still accurate.
778 // still accurate. 776 if (SkScalarAbs(A) < 5 * kErrorTol) {
779 if (SkScalarAbs(A) < kEdgeErrorTol) {
780 return kEdge_ConicalType; 777 return kEdge_ConicalType;
781 } 778 }
782 779
783 SkScalar C = 1.f / A; 780 SkScalar C = 1.f / A;
784 SkScalar B = (radiusEnd - 1.f) * C; 781 SkScalar B = (radiusEnd - 1.f) * C;
785 782
786 matrix.postScale(C, C); 783 matrix.postScale(C, C);
787 784
788 invLMatrix->postConcat(matrix); 785 invLMatrix->postConcat(matrix);
789 786
(...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after
1304 return CircleInside2PtConicalEffect::Create(ctx, shader, matrix, tm, inf o); 1301 return CircleInside2PtConicalEffect::Create(ctx, shader, matrix, tm, inf o);
1305 } else if (type == kEdge_ConicalType) { 1302 } else if (type == kEdge_ConicalType) {
1306 set_matrix_edge_conical(shader, &matrix); 1303 set_matrix_edge_conical(shader, &matrix);
1307 return Edge2PtConicalEffect::Create(ctx, shader, matrix, tm); 1304 return Edge2PtConicalEffect::Create(ctx, shader, matrix, tm);
1308 } else { 1305 } else {
1309 return CircleOutside2PtConicalEffect::Create(ctx, shader, matrix, tm, in fo); 1306 return CircleOutside2PtConicalEffect::Create(ctx, shader, matrix, tm, in fo);
1310 } 1307 }
1311 } 1308 }
1312 1309
1313 #endif 1310 #endif
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698