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

Side by Side Diff: src/gpu/effects/GrDistanceFieldGeoProc.cpp

Issue 1086183002: Fix LCD text and add path fix for Mali. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 8 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 * Copyright 2013 Google Inc. 2 * Copyright 2013 Google Inc.
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 "GrDistanceFieldGeoProc.h" 8 #include "GrDistanceFieldGeoProc.h"
9 #include "GrFontAtlasSizes.h" 9 #include "GrFontAtlasSizes.h"
10 #include "GrInvariantOutput.h" 10 #include "GrInvariantOutput.h"
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 fsBuilder->codeAppend(GrGLShaderVar::PrecisionString(kHigh_GrSLPrecision , 358 fsBuilder->codeAppend(GrGLShaderVar::PrecisionString(kHigh_GrSLPrecision ,
359 pb->ctxInfo().stand ard())); 359 pb->ctxInfo().stand ard()));
360 fsBuilder->codeAppendf("vec2 st = uv*%s;", textureSizeUniName); 360 fsBuilder->codeAppendf("vec2 st = uv*%s;", textureSizeUniName);
361 fsBuilder->codeAppend("float afwidth;"); 361 fsBuilder->codeAppend("float afwidth;");
362 if (dfTexEffect.getFlags() & kSimilarity_DistanceFieldEffectFlag) { 362 if (dfTexEffect.getFlags() & kSimilarity_DistanceFieldEffectFlag) {
363 // For uniform scale, we adjust for the effect of the transformation on the distance 363 // For uniform scale, we adjust for the effect of the transformation on the distance
364 // by using the length of the gradient of the texture coordinates. W e use st coordinates 364 // by using the length of the gradient of the texture coordinates. W e use st coordinates
365 // to ensure we're mapping 1:1 from texel space to pixel space. 365 // to ensure we're mapping 1:1 from texel space to pixel space.
366 366
367 // this gives us a smooth step across approximately one fragment 367 // this gives us a smooth step across approximately one fragment
368 fsBuilder->codeAppend("afwidth = abs(" SK_DistanceFieldAAFactor "*dF dx(st.x));"); 368 fsBuilder->codeAppend("afwidth = abs(" SK_DistanceFieldAAFactor "*dF dy(st.y));");
369 } else { 369 } else {
370 // For general transforms, to determine the amount of correction we multiply a unit 370 // For general transforms, to determine the amount of correction we multiply a unit
371 // vector pointing along the SDF gradient direction by the Jacobian of the st coords 371 // vector pointing along the SDF gradient direction by the Jacobian of the st coords
372 // (which is the inverse transform for this fragment) and take the l ength of the result. 372 // (which is the inverse transform for this fragment) and take the l ength of the result.
373 fsBuilder->codeAppend("vec2 dist_grad = vec2(dFdx(distance), dFdy(di stance));"); 373 fsBuilder->codeAppend("vec2 dist_grad = vec2(dFdx(distance), dFdy(di stance));");
374 // the length of the gradient may be 0, so we need to check for this 374 // the length of the gradient may be 0, so we need to check for this
375 // this also compensates for the Adreno, which likes to drop tiles o n division by 0 375 // this also compensates for the Adreno, which likes to drop tiles o n division by 0
376 fsBuilder->codeAppend("float dg_len2 = dot(dist_grad, dist_grad);"); 376 fsBuilder->codeAppend("float dg_len2 = dot(dist_grad, dist_grad);");
377 fsBuilder->codeAppend("if (dg_len2 < 0.0001) {"); 377 fsBuilder->codeAppend("if (dg_len2 < 0.0001) {");
378 fsBuilder->codeAppend("dist_grad = vec2(0.7071, 0.7071);"); 378 fsBuilder->codeAppend("dist_grad = vec2(0.7071, 0.7071);");
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
598 pb->ctxInfo().stand ard())); 598 pb->ctxInfo().stand ard()));
599 fsBuilder->codeAppendf("vec2 uv = %s;\n", uv.fsIn()); 599 fsBuilder->codeAppendf("vec2 uv = %s;\n", uv.fsIn());
600 fsBuilder->codeAppend(GrGLShaderVar::PrecisionString(kHigh_GrSLPrecision , 600 fsBuilder->codeAppend(GrGLShaderVar::PrecisionString(kHigh_GrSLPrecision ,
601 pb->ctxInfo().stand ard())); 601 pb->ctxInfo().stand ard()));
602 if (dfTexEffect.getFlags() & kBGR_DistanceFieldEffectFlag) { 602 if (dfTexEffect.getFlags() & kBGR_DistanceFieldEffectFlag) {
603 fsBuilder->codeAppend("float delta = -" GR_FONT_ATLAS_LCD_DELTA ";\n "); 603 fsBuilder->codeAppend("float delta = -" GR_FONT_ATLAS_LCD_DELTA ";\n ");
604 } else { 604 } else {
605 fsBuilder->codeAppend("float delta = " GR_FONT_ATLAS_LCD_DELTA ";\n" ); 605 fsBuilder->codeAppend("float delta = " GR_FONT_ATLAS_LCD_DELTA ";\n" );
606 } 606 }
607 if (isUniformScale) { 607 if (isUniformScale) {
608 fsBuilder->codeAppendf("float dy = dFdy(%s.y);", st.fsIn()); 608 fsBuilder->codeAppendf("float dy = abs(dFdy(%s.y));", st.fsIn());
609 fsBuilder->codeAppend("vec2 offset = vec2(dy*delta, 0.0);"); 609 fsBuilder->codeAppend("vec2 offset = vec2(dy*delta, 0.0);");
610 } else { 610 } else {
611 fsBuilder->codeAppendf("vec2 st = %s;\n", st.fsIn()); 611 fsBuilder->codeAppendf("vec2 st = %s;\n", st.fsIn());
612 612
613 fsBuilder->codeAppend("vec2 Jdx = dFdx(st);"); 613 fsBuilder->codeAppend("vec2 Jdx = dFdx(st);");
614 fsBuilder->codeAppend("vec2 Jdy = dFdy(st);"); 614 fsBuilder->codeAppend("vec2 Jdy = dFdy(st);");
615 fsBuilder->codeAppend("vec2 offset = delta*Jdx;"); 615 fsBuilder->codeAppend("vec2 offset = delta*Jdx;");
616 } 616 }
617 617
618 // green is distance to uv center 618 // green is distance to uv center
(...skipping 29 matching lines...) Expand all
648 // for each color component. However, this is only important when using perspective 648 // for each color component. However, this is only important when using perspective
649 // transformations, and even then using a single factor seems like a rea sonable 649 // transformations, and even then using a single factor seems like a rea sonable
650 // trade-off between quality and speed. 650 // trade-off between quality and speed.
651 fsBuilder->codeAppend("float afwidth;"); 651 fsBuilder->codeAppend("float afwidth;");
652 if (isUniformScale) { 652 if (isUniformScale) {
653 // For uniform scale, we adjust for the effect of the transformation on the distance 653 // For uniform scale, we adjust for the effect of the transformation on the distance
654 // by using the length of the gradient of the texture coordinates. W e use st coordinates 654 // by using the length of the gradient of the texture coordinates. W e use st coordinates
655 // to ensure we're mapping 1:1 from texel space to pixel space. 655 // to ensure we're mapping 1:1 from texel space to pixel space.
656 656
657 // this gives us a smooth step across approximately one fragment 657 // this gives us a smooth step across approximately one fragment
658 fsBuilder->codeAppend("afwidth = abs(" SK_DistanceFieldAAFactor "*dy );"); 658 fsBuilder->codeAppend("afwidth = " SK_DistanceFieldAAFactor "*dy;");
659 } else { 659 } else {
660 // For general transforms, to determine the amount of correction we multiply a unit 660 // For general transforms, to determine the amount of correction we multiply a unit
661 // vector pointing along the SDF gradient direction by the Jacobian of the st coords 661 // vector pointing along the SDF gradient direction by the Jacobian of the st coords
662 // (which is the inverse transform for this fragment) and take the l ength of the result. 662 // (which is the inverse transform for this fragment) and take the l ength of the result.
663 fsBuilder->codeAppend("vec2 dist_grad = vec2(dFdx(distance.r), dFdy( distance.r));"); 663 fsBuilder->codeAppend("vec2 dist_grad = vec2(dFdx(distance.r), dFdy( distance.r));");
664 // the length of the gradient may be 0, so we need to check for this 664 // the length of the gradient may be 0, so we need to check for this
665 // this also compensates for the Adreno, which likes to drop tiles o n division by 0 665 // this also compensates for the Adreno, which likes to drop tiles o n division by 0
666 fsBuilder->codeAppend("float dg_len2 = dot(dist_grad, dist_grad);"); 666 fsBuilder->codeAppend("float dg_len2 = dot(dist_grad, dist_grad);");
667 fsBuilder->codeAppend("if (dg_len2 < 0.0001) {"); 667 fsBuilder->codeAppend("if (dg_len2 < 0.0001) {");
668 fsBuilder->codeAppend("dist_grad = vec2(0.7071, 0.7071);"); 668 fsBuilder->codeAppend("dist_grad = vec2(0.7071, 0.7071);");
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
816 DistanceAdjust wa = { 0.0f, 0.1f, -0.1f }; 816 DistanceAdjust wa = { 0.0f, 0.1f, -0.1f };
817 uint32_t flags = kUseLCD_DistanceFieldEffectFlag; 817 uint32_t flags = kUseLCD_DistanceFieldEffectFlag;
818 flags |= random->nextBool() ? kUniformScale_DistanceFieldEffectMask : 0; 818 flags |= random->nextBool() ? kUniformScale_DistanceFieldEffectMask : 0;
819 flags |= random->nextBool() ? kBGR_DistanceFieldEffectFlag : 0; 819 flags |= random->nextBool() ? kBGR_DistanceFieldEffectFlag : 0;
820 return GrDistanceFieldLCDTextGeoProc::Create(GrRandomColor(random), 820 return GrDistanceFieldLCDTextGeoProc::Create(GrRandomColor(random),
821 GrProcessorUnitTest::TestMatrix (random), 821 GrProcessorUnitTest::TestMatrix (random),
822 textures[texIdx], params, 822 textures[texIdx], params,
823 wa, 823 wa,
824 flags); 824 flags);
825 } 825 }
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