OLD | NEW |
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 "GrDistanceFieldTextureEffect.h" | 8 #include "GrDistanceFieldTextureEffect.h" |
9 #include "gl/GrGLEffect.h" | 9 #include "gl/GrGLEffect.h" |
10 #include "gl/GrGLSL.h" | 10 #include "gl/GrGLSL.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 const char* textureSizeUniName = NULL; | 49 const char* textureSizeUniName = NULL; |
50 fTextureSizeUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visib
ility, | 50 fTextureSizeUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visib
ility, |
51 kVec2f_GrSLType, "TextureSize", | 51 kVec2f_GrSLType, "TextureSize", |
52 &textureSizeUniName); | 52 &textureSizeUniName); |
53 | 53 |
54 builder->fsCodeAppend("\tvec4 texColor = "); | 54 builder->fsCodeAppend("\tvec4 texColor = "); |
55 builder->fsAppendTextureLookup(samplers[0], | 55 builder->fsAppendTextureLookup(samplers[0], |
56 fsCoordName.c_str(), | 56 fsCoordName.c_str(), |
57 kVec2f_GrSLType); | 57 kVec2f_GrSLType); |
58 builder->fsCodeAppend(";\n"); | 58 builder->fsCodeAppend(";\n"); |
59 builder->fsCodeAppend("\tfloat distance = "MULTIPLIER"*(texColor.r - "TH
RESHOLD");\n"); | 59 builder->fsCodeAppend("\tfloat distance = " MULTIPLIER "*(texColor.r - "
THRESHOLD ");\n"); |
60 | 60 |
61 // we adjust for the effect of the transformation on the distance by usi
ng | 61 // we adjust for the effect of the transformation on the distance by usi
ng |
62 // the length of the gradient of the texture coordinates. We use st coor
dinates | 62 // the length of the gradient of the texture coordinates. We use st coor
dinates |
63 // to ensure we're mapping 1:1 from texel space to pixel space. | 63 // to ensure we're mapping 1:1 from texel space to pixel space. |
64 builder->fsCodeAppendf("\tvec2 st = %s*%s;\n", fsCoordName.c_str(), text
ureSizeUniName); | 64 builder->fsCodeAppendf("\tvec2 st = %s*%s;\n", fsCoordName.c_str(), text
ureSizeUniName); |
65 builder->fsCodeAppend("\tvec2 Jdx = dFdx(st);\n"); | 65 builder->fsCodeAppend("\tvec2 Jdx = dFdx(st);\n"); |
66 builder->fsCodeAppend("\tvec2 Jdy = dFdy(st);\n"); | 66 builder->fsCodeAppend("\tvec2 Jdy = dFdy(st);\n"); |
67 builder->fsCodeAppend("\tvec2 st_grad = normalize(st);\n"); | 67 builder->fsCodeAppend("\tvec2 st_grad = normalize(st);\n"); |
68 builder->fsCodeAppend("\tvec2 grad = vec2(st_grad.x*Jdx.x + st_grad.y*Jd
y.x,\n"); | 68 builder->fsCodeAppend("\tvec2 grad = vec2(st_grad.x*Jdx.x + st_grad.y*Jd
y.x,\n"); |
69 builder->fsCodeAppend("\t st_grad.x*Jdx.y + st_grad.y*Jd
y.y);\n"); | 69 builder->fsCodeAppend("\t st_grad.x*Jdx.y + st_grad.y*Jd
y.y);\n"); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 SkShader::TileMode tileModes[] = { | 146 SkShader::TileMode tileModes[] = { |
147 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], | 147 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], |
148 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], | 148 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], |
149 }; | 149 }; |
150 GrTextureParams params(tileModes, random->nextBool() ? GrTextureParams::kBil
erp_FilterMode : | 150 GrTextureParams params(tileModes, random->nextBool() ? GrTextureParams::kBil
erp_FilterMode : |
151 GrTextureParams::kNon
e_FilterMode); | 151 GrTextureParams::kNon
e_FilterMode); |
152 SkISize size = SkISize::Make(1024, 2048); | 152 SkISize size = SkISize::Make(1024, 2048); |
153 | 153 |
154 return GrDistanceFieldTextureEffect::Create(textures[texIdx], params, size); | 154 return GrDistanceFieldTextureEffect::Create(textures[texIdx], params, size); |
155 } | 155 } |
OLD | NEW |