| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "GrAARectRenderer.h" | 8 #include "GrAARectRenderer.h" |
| 9 #include "GrGpu.h" | 9 #include "GrGpu.h" |
| 10 #include "gl/builders/GrGLProgramBuilder.h" | 10 #include "gl/builders/GrGLProgramBuilder.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 | 38 |
| 39 class GLProcessor : public GrGLGeometryProcessor { | 39 class GLProcessor : public GrGLGeometryProcessor { |
| 40 public: | 40 public: |
| 41 GLProcessor(const GrBackendProcessorFactory& factory, const GrProcessor&
) | 41 GLProcessor(const GrBackendProcessorFactory& factory, const GrProcessor&
) |
| 42 : INHERITED (factory) {} | 42 : INHERITED (factory) {} |
| 43 | 43 |
| 44 virtual void emitCode(const EmitArgs& args) SK_OVERRIDE { | 44 virtual void emitCode(const EmitArgs& args) SK_OVERRIDE { |
| 45 // setup the varying for the Axis aligned rect effect | 45 // setup the varying for the Axis aligned rect effect |
| 46 // xy -> interpolated offset | 46 // xy -> interpolated offset |
| 47 // zw -> w/2+0.5, h/2+0.5 | 47 // zw -> w/2+0.5, h/2+0.5 |
| 48 GrGLVertToFrag v(kVec4f_GrSLType); | 48 const char *vsRectName, *fsRectName; |
| 49 args.fPB->addVarying("Rect", &v); | 49 args.fPB->addVarying(kVec4f_GrSLType, "Rect", &vsRectName, &fsRectNa
me); |
| 50 | 50 |
| 51 const GrShaderVar& inRect = args.fGP.cast<GrAlignedRectEffect>().inR
ect(); | 51 const GrShaderVar& inRect = args.fGP.cast<GrAlignedRectEffect>().inR
ect(); |
| 52 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); | 52 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); |
| 53 vsBuilder->codeAppendf("\t%s = %s;\n", v.fsIn(), inRect.c_str()); | 53 vsBuilder->codeAppendf("\t%s = %s;\n", vsRectName, inRect.c_str()); |
| 54 | 54 |
| 55 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilde
r(); | 55 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilde
r(); |
| 56 // TODO: compute all these offsets, spans, and scales in the VS | 56 // TODO: compute all these offsets, spans, and scales in the VS |
| 57 fsBuilder->codeAppendf("\tfloat insetW = min(1.0, %s.z) - 0.5;\n", v
.fsIn()); | 57 fsBuilder->codeAppendf("\tfloat insetW = min(1.0, %s.z) - 0.5;\n", f
sRectName); |
| 58 fsBuilder->codeAppendf("\tfloat insetH = min(1.0, %s.w) - 0.5;\n", v
.fsIn()); | 58 fsBuilder->codeAppendf("\tfloat insetH = min(1.0, %s.w) - 0.5;\n", f
sRectName); |
| 59 fsBuilder->codeAppend("\tfloat outset = 0.5;\n"); | 59 fsBuilder->codeAppend("\tfloat outset = 0.5;\n"); |
| 60 // For rects > 1 pixel wide and tall the span's are noops (i.e., 1.0
). For rects | 60 // For rects > 1 pixel wide and tall the span's are noops (i.e., 1.0
). For rects |
| 61 // < 1 pixel wide or tall they serve to normalize the < 1 ramp to a
0 .. 1 range. | 61 // < 1 pixel wide or tall they serve to normalize the < 1 ramp to a
0 .. 1 range. |
| 62 fsBuilder->codeAppend("\tfloat spanW = insetW + outset;\n"); | 62 fsBuilder->codeAppend("\tfloat spanW = insetW + outset;\n"); |
| 63 fsBuilder->codeAppend("\tfloat spanH = insetH + outset;\n"); | 63 fsBuilder->codeAppend("\tfloat spanH = insetH + outset;\n"); |
| 64 // For rects < 1 pixel wide or tall, these scale factors are used to
cap the maximum | 64 // For rects < 1 pixel wide or tall, these scale factors are used to
cap the maximum |
| 65 // value of coverage that is used. In other words it is the coverage
that is | 65 // value of coverage that is used. In other words it is the coverage
that is |
| 66 // used in the interior of the rect after the ramp. | 66 // used in the interior of the rect after the ramp. |
| 67 fsBuilder->codeAppend("\tfloat scaleW = min(1.0, 2.0*insetW/spanW);\
n"); | 67 fsBuilder->codeAppend("\tfloat scaleW = min(1.0, 2.0*insetW/spanW);\
n"); |
| 68 fsBuilder->codeAppend("\tfloat scaleH = min(1.0, 2.0*insetH/spanH);\
n"); | 68 fsBuilder->codeAppend("\tfloat scaleH = min(1.0, 2.0*insetH/spanH);\
n"); |
| 69 | 69 |
| 70 // Compute the coverage for the rect's width | 70 // Compute the coverage for the rect's width |
| 71 fsBuilder->codeAppendf( | 71 fsBuilder->codeAppendf( |
| 72 "\tfloat coverage = scaleW*clamp((%s.z-abs(%s.x))/spanW, 0.0, 1.
0);\n", v.fsIn(), | 72 "\tfloat coverage = scaleW*clamp((%s.z-abs(%s.x))/spanW, 0.0, 1.
0);\n", fsRectName, |
| 73 v.fsIn()); | 73 fsRectName); |
| 74 // Compute the coverage for the rect's height and merge with the wid
th | 74 // Compute the coverage for the rect's height and merge with the wid
th |
| 75 fsBuilder->codeAppendf( | 75 fsBuilder->codeAppendf( |
| 76 "\tcoverage = coverage*scaleH*clamp((%s.w-abs(%s.y))/spanH, 0.0,
1.0);\n", | 76 "\tcoverage = coverage*scaleH*clamp((%s.w-abs(%s.y))/spanH, 0.0,
1.0);\n", |
| 77 v.fsIn(), v.fsIn()); | 77 fsRectName, fsRectName); |
| 78 | 78 |
| 79 | 79 |
| 80 fsBuilder->codeAppendf("\t%s = %s;\n", args.fOutput, | 80 fsBuilder->codeAppendf("\t%s = %s;\n", args.fOutput, |
| 81 (GrGLSLExpr4(args.fInput) * GrGLSLExpr1("cove
rage")).c_str()); | 81 (GrGLSLExpr4(args.fInput) * GrGLSLExpr1("cove
rage")).c_str()); |
| 82 } | 82 } |
| 83 | 83 |
| 84 static void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKeyBu
ilder*) {} | 84 static void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKeyBu
ilder*) {} |
| 85 | 85 |
| 86 virtual void setData(const GrGLProgramDataManager& pdman, const GrProces
sor&) SK_OVERRIDE {} | 86 virtual void setData(const GrGLProgramDataManager& pdman, const GrProces
sor&) SK_OVERRIDE {} |
| 87 | 87 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 } | 156 } |
| 157 | 157 |
| 158 class GLProcessor : public GrGLGeometryProcessor { | 158 class GLProcessor : public GrGLGeometryProcessor { |
| 159 public: | 159 public: |
| 160 GLProcessor(const GrBackendProcessorFactory& factory, const GrProcessor&
) | 160 GLProcessor(const GrBackendProcessorFactory& factory, const GrProcessor&
) |
| 161 : INHERITED (factory) {} | 161 : INHERITED (factory) {} |
| 162 | 162 |
| 163 virtual void emitCode(const EmitArgs& args) SK_OVERRIDE { | 163 virtual void emitCode(const EmitArgs& args) SK_OVERRIDE { |
| 164 // setup the varying for the center point and the unit vector | 164 // setup the varying for the center point and the unit vector |
| 165 // that points down the height of the rect | 165 // that points down the height of the rect |
| 166 GrGLVertToFrag rectEdge(kVec4f_GrSLType); | 166 const char *vsRectEdgeName, *fsRectEdgeName; |
| 167 args.fPB->addVarying("RectEdge", &rectEdge); | 167 args.fPB->addVarying(kVec4f_GrSLType, "RectEdge", |
| 168 &vsRectEdgeName, &fsRectEdgeName); |
| 168 | 169 |
| 169 const GrRectEffect& rectEffect = args.fGP.cast<GrRectEffect>(); | 170 const GrRectEffect& rectEffect = args.fGP.cast<GrRectEffect>(); |
| 170 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); | 171 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); |
| 171 vsBuilder->codeAppendf("%s = %s;", rectEdge.vsOut(), rectEffect.inRe
ctEdge().c_str()); | 172 vsBuilder->codeAppendf("%s = %s;", vsRectEdgeName, rectEffect.inRect
Edge().c_str()); |
| 172 | 173 |
| 173 // setup the varying for width/2+.5 and height/2+.5 | 174 // setup the varying for width/2+.5 and height/2+.5 |
| 174 GrGLVertToFrag widthHeight(kVec2f_GrSLType); | 175 const char *vsWidthHeightName, *fsWidthHeightName; |
| 175 args.fPB->addVarying("WidthHeight", &widthHeight); | 176 args.fPB->addVarying(kVec2f_GrSLType, "WidthHeight", |
| 177 &vsWidthHeightName, &fsWidthHeightName); |
| 176 vsBuilder->codeAppendf("%s = %s;", | 178 vsBuilder->codeAppendf("%s = %s;", |
| 177 widthHeight.vsOut(), | 179 vsWidthHeightName, |
| 178 rectEffect.inWidthHeight().c_str()); | 180 rectEffect.inWidthHeight().c_str()); |
| 179 | 181 |
| 180 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilde
r(); | 182 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilde
r(); |
| 181 // TODO: compute all these offsets, spans, and scales in the VS | 183 // TODO: compute all these offsets, spans, and scales in the VS |
| 182 fsBuilder->codeAppendf("\tfloat insetW = min(1.0, %s.x) - 0.5;\n", w
idthHeight.fsIn()); | 184 fsBuilder->codeAppendf("\tfloat insetW = min(1.0, %s.x) - 0.5;\n", f
sWidthHeightName); |
| 183 fsBuilder->codeAppendf("\tfloat insetH = min(1.0, %s.y) - 0.5;\n", w
idthHeight.fsIn()); | 185 fsBuilder->codeAppendf("\tfloat insetH = min(1.0, %s.y) - 0.5;\n", f
sWidthHeightName); |
| 184 fsBuilder->codeAppend("\tfloat outset = 0.5;\n"); | 186 fsBuilder->codeAppend("\tfloat outset = 0.5;\n"); |
| 185 // For rects > 1 pixel wide and tall the span's are noops (i.e., 1.0
). For rects | 187 // For rects > 1 pixel wide and tall the span's are noops (i.e., 1.0
). For rects |
| 186 // < 1 pixel wide or tall they serve to normalize the < 1 ramp to a
0 .. 1 range. | 188 // < 1 pixel wide or tall they serve to normalize the < 1 ramp to a
0 .. 1 range. |
| 187 fsBuilder->codeAppend("\tfloat spanW = insetW + outset;\n"); | 189 fsBuilder->codeAppend("\tfloat spanW = insetW + outset;\n"); |
| 188 fsBuilder->codeAppend("\tfloat spanH = insetH + outset;\n"); | 190 fsBuilder->codeAppend("\tfloat spanH = insetH + outset;\n"); |
| 189 // For rects < 1 pixel wide or tall, these scale factors are used to
cap the maximum | 191 // For rects < 1 pixel wide or tall, these scale factors are used to
cap the maximum |
| 190 // value of coverage that is used. In other words it is the coverage
that is | 192 // value of coverage that is used. In other words it is the coverage
that is |
| 191 // used in the interior of the rect after the ramp. | 193 // used in the interior of the rect after the ramp. |
| 192 fsBuilder->codeAppend("\tfloat scaleW = min(1.0, 2.0*insetW/spanW);\
n"); | 194 fsBuilder->codeAppend("\tfloat scaleW = min(1.0, 2.0*insetW/spanW);\
n"); |
| 193 fsBuilder->codeAppend("\tfloat scaleH = min(1.0, 2.0*insetH/spanH);\
n"); | 195 fsBuilder->codeAppend("\tfloat scaleH = min(1.0, 2.0*insetH/spanH);\
n"); |
| 194 | 196 |
| 195 // Compute the coverage for the rect's width | 197 // Compute the coverage for the rect's width |
| 196 fsBuilder->codeAppendf("\tvec2 offset = %s.xy - %s.xy;\n", | 198 fsBuilder->codeAppendf("\tvec2 offset = %s.xy - %s.xy;\n", |
| 197 fsBuilder->fragmentPosition(), rectEdge.fsIn(
)); | 199 fsBuilder->fragmentPosition(), fsRectEdgeName
); |
| 198 fsBuilder->codeAppendf("\tfloat perpDot = abs(offset.x * %s.w - offs
et.y * %s.z);\n", | 200 fsBuilder->codeAppendf("\tfloat perpDot = abs(offset.x * %s.w - offs
et.y * %s.z);\n", |
| 199 rectEdge.fsIn(), rectEdge.fsIn()); | 201 fsRectEdgeName, fsRectEdgeName); |
| 200 fsBuilder->codeAppendf( | 202 fsBuilder->codeAppendf( |
| 201 "\tfloat coverage = scaleW*clamp((%s.x-perpDot)/spanW, 0.0, 1.0)
;\n", | 203 "\tfloat coverage = scaleW*clamp((%s.x-perpDot)/spanW, 0.0, 1.0)
;\n", |
| 202 widthHeight.fsIn()); | 204 fsWidthHeightName); |
| 203 | 205 |
| 204 // Compute the coverage for the rect's height and merge with the wid
th | 206 // Compute the coverage for the rect's height and merge with the wid
th |
| 205 fsBuilder->codeAppendf("\tperpDot = abs(dot(offset, %s.zw));\n", | 207 fsBuilder->codeAppendf("\tperpDot = abs(dot(offset, %s.zw));\n", |
| 206 rectEdge.fsIn()); | 208 fsRectEdgeName); |
| 207 fsBuilder->codeAppendf( | 209 fsBuilder->codeAppendf( |
| 208 "\tcoverage = coverage*scaleH*clamp((%s.y-perpDot)/spanH, 0.
0, 1.0);\n", | 210 "\tcoverage = coverage*scaleH*clamp((%s.y-perpDot)/spanH, 0.
0, 1.0);\n", |
| 209 widthHeight.fsIn()); | 211 fsWidthHeightName); |
| 210 | 212 |
| 211 | 213 |
| 212 fsBuilder->codeAppendf("\t%s = %s;\n", args.fOutput, | 214 fsBuilder->codeAppendf("\t%s = %s;\n", args.fOutput, |
| 213 (GrGLSLExpr4(args.fInput) * GrGLSLExpr1("cove
rage")).c_str()); | 215 (GrGLSLExpr4(args.fInput) * GrGLSLExpr1("cove
rage")).c_str()); |
| 214 } | 216 } |
| 215 | 217 |
| 216 static void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKeyBu
ilder*) {} | 218 static void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKeyBu
ilder*) {} |
| 217 | 219 |
| 218 virtual void setData(const GrGLProgramDataManager& pdman, const GrProces
sor&) SK_OVERRIDE {} | 220 virtual void setData(const GrGLProgramDataManager& pdman, const GrProces
sor&) SK_OVERRIDE {} |
| 219 | 221 |
| (...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 916 // can't call mapRect for devInside since it calls sort | 918 // can't call mapRect for devInside since it calls sort |
| 917 combinedMatrix.mapPoints((SkPoint*)&devInside, (const SkPoint*)&rects[1], 2)
; | 919 combinedMatrix.mapPoints((SkPoint*)&devInside, (const SkPoint*)&rects[1], 2)
; |
| 918 | 920 |
| 919 if (devInside.isEmpty()) { | 921 if (devInside.isEmpty()) { |
| 920 this->fillAARect(gpu, target, devOutside, SkMatrix::I(), devOutside); | 922 this->fillAARect(gpu, target, devOutside, SkMatrix::I(), devOutside); |
| 921 return; | 923 return; |
| 922 } | 924 } |
| 923 | 925 |
| 924 this->geometryStrokeAARect(gpu, target, devOutside, devOutsideAssist, devIns
ide, true); | 926 this->geometryStrokeAARect(gpu, target, devOutside, devOutsideAssist, devIns
ide, true); |
| 925 } | 927 } |
| OLD | NEW |