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

Side by Side Diff: src/gpu/GrAARectRenderer.cpp

Issue 671023002: Added varying struct (Closed) Base URL: https://skia.googlesource.com/skia.git@gp_emit_struct
Patch Set: cleanup Created 6 years, 1 month 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 | « src/gpu/GrAAConvexPathRenderer.cpp ('k') | src/gpu/GrOvalRenderer.cpp » ('j') | 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 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
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 const char *vsRectName, *fsRectName; 48 GrGLVertToFrag v(kVec4f_GrSLType);
49 args.fPB->addVarying(kVec4f_GrSLType, "Rect", &vsRectName, &fsRectNa me); 49 args.fPB->addVarying("Rect", &v);
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", vsRectName, inRect.c_str()); 53 vsBuilder->codeAppendf("\t%s = %s;\n", v.fsIn(), 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", f sRectName); 57 fsBuilder->codeAppendf("\tfloat insetW = min(1.0, %s.z) - 0.5;\n", v .fsIn());
58 fsBuilder->codeAppendf("\tfloat insetH = min(1.0, %s.w) - 0.5;\n", f sRectName); 58 fsBuilder->codeAppendf("\tfloat insetH = min(1.0, %s.w) - 0.5;\n", v .fsIn());
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", fsRectName, 72 "\tfloat coverage = scaleW*clamp((%s.z-abs(%s.x))/spanW, 0.0, 1. 0);\n", v.fsIn(),
73 fsRectName); 73 v.fsIn());
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 fsRectName, fsRectName); 77 v.fsIn(), v.fsIn());
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
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 const char *vsRectEdgeName, *fsRectEdgeName; 166 GrGLVertToFrag rectEdge(kVec4f_GrSLType);
167 args.fPB->addVarying(kVec4f_GrSLType, "RectEdge", 167 args.fPB->addVarying("RectEdge", &rectEdge);
168 &vsRectEdgeName, &fsRectEdgeName);
169 168
170 const GrRectEffect& rectEffect = args.fGP.cast<GrRectEffect>(); 169 const GrRectEffect& rectEffect = args.fGP.cast<GrRectEffect>();
171 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); 170 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder();
172 vsBuilder->codeAppendf("%s = %s;", vsRectEdgeName, rectEffect.inRect Edge().c_str()); 171 vsBuilder->codeAppendf("%s = %s;", rectEdge.vsOut(), rectEffect.inRe ctEdge().c_str());
173 172
174 // setup the varying for width/2+.5 and height/2+.5 173 // setup the varying for width/2+.5 and height/2+.5
175 const char *vsWidthHeightName, *fsWidthHeightName; 174 GrGLVertToFrag widthHeight(kVec2f_GrSLType);
176 args.fPB->addVarying(kVec2f_GrSLType, "WidthHeight", 175 args.fPB->addVarying("WidthHeight", &widthHeight);
177 &vsWidthHeightName, &fsWidthHeightName);
178 vsBuilder->codeAppendf("%s = %s;", 176 vsBuilder->codeAppendf("%s = %s;",
179 vsWidthHeightName, 177 widthHeight.vsOut(),
180 rectEffect.inWidthHeight().c_str()); 178 rectEffect.inWidthHeight().c_str());
181 179
182 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilde r(); 180 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilde r();
183 // TODO: compute all these offsets, spans, and scales in the VS 181 // TODO: compute all these offsets, spans, and scales in the VS
184 fsBuilder->codeAppendf("\tfloat insetW = min(1.0, %s.x) - 0.5;\n", f sWidthHeightName); 182 fsBuilder->codeAppendf("\tfloat insetW = min(1.0, %s.x) - 0.5;\n", w idthHeight.fsIn());
185 fsBuilder->codeAppendf("\tfloat insetH = min(1.0, %s.y) - 0.5;\n", f sWidthHeightName); 183 fsBuilder->codeAppendf("\tfloat insetH = min(1.0, %s.y) - 0.5;\n", w idthHeight.fsIn());
186 fsBuilder->codeAppend("\tfloat outset = 0.5;\n"); 184 fsBuilder->codeAppend("\tfloat outset = 0.5;\n");
187 // For rects > 1 pixel wide and tall the span's are noops (i.e., 1.0 ). For rects 185 // For rects > 1 pixel wide and tall the span's are noops (i.e., 1.0 ). For rects
188 // < 1 pixel wide or tall they serve to normalize the < 1 ramp to a 0 .. 1 range. 186 // < 1 pixel wide or tall they serve to normalize the < 1 ramp to a 0 .. 1 range.
189 fsBuilder->codeAppend("\tfloat spanW = insetW + outset;\n"); 187 fsBuilder->codeAppend("\tfloat spanW = insetW + outset;\n");
190 fsBuilder->codeAppend("\tfloat spanH = insetH + outset;\n"); 188 fsBuilder->codeAppend("\tfloat spanH = insetH + outset;\n");
191 // For rects < 1 pixel wide or tall, these scale factors are used to cap the maximum 189 // For rects < 1 pixel wide or tall, these scale factors are used to cap the maximum
192 // value of coverage that is used. In other words it is the coverage that is 190 // value of coverage that is used. In other words it is the coverage that is
193 // used in the interior of the rect after the ramp. 191 // used in the interior of the rect after the ramp.
194 fsBuilder->codeAppend("\tfloat scaleW = min(1.0, 2.0*insetW/spanW);\ n"); 192 fsBuilder->codeAppend("\tfloat scaleW = min(1.0, 2.0*insetW/spanW);\ n");
195 fsBuilder->codeAppend("\tfloat scaleH = min(1.0, 2.0*insetH/spanH);\ n"); 193 fsBuilder->codeAppend("\tfloat scaleH = min(1.0, 2.0*insetH/spanH);\ n");
196 194
197 // Compute the coverage for the rect's width 195 // Compute the coverage for the rect's width
198 fsBuilder->codeAppendf("\tvec2 offset = %s.xy - %s.xy;\n", 196 fsBuilder->codeAppendf("\tvec2 offset = %s.xy - %s.xy;\n",
199 fsBuilder->fragmentPosition(), fsRectEdgeName ); 197 fsBuilder->fragmentPosition(), rectEdge.fsIn( ));
200 fsBuilder->codeAppendf("\tfloat perpDot = abs(offset.x * %s.w - offs et.y * %s.z);\n", 198 fsBuilder->codeAppendf("\tfloat perpDot = abs(offset.x * %s.w - offs et.y * %s.z);\n",
201 fsRectEdgeName, fsRectEdgeName); 199 rectEdge.fsIn(), rectEdge.fsIn());
202 fsBuilder->codeAppendf( 200 fsBuilder->codeAppendf(
203 "\tfloat coverage = scaleW*clamp((%s.x-perpDot)/spanW, 0.0, 1.0) ;\n", 201 "\tfloat coverage = scaleW*clamp((%s.x-perpDot)/spanW, 0.0, 1.0) ;\n",
204 fsWidthHeightName); 202 widthHeight.fsIn());
205 203
206 // Compute the coverage for the rect's height and merge with the wid th 204 // Compute the coverage for the rect's height and merge with the wid th
207 fsBuilder->codeAppendf("\tperpDot = abs(dot(offset, %s.zw));\n", 205 fsBuilder->codeAppendf("\tperpDot = abs(dot(offset, %s.zw));\n",
208 fsRectEdgeName); 206 rectEdge.fsIn());
209 fsBuilder->codeAppendf( 207 fsBuilder->codeAppendf(
210 "\tcoverage = coverage*scaleH*clamp((%s.y-perpDot)/spanH, 0. 0, 1.0);\n", 208 "\tcoverage = coverage*scaleH*clamp((%s.y-perpDot)/spanH, 0. 0, 1.0);\n",
211 fsWidthHeightName); 209 widthHeight.fsIn());
212 210
213 211
214 fsBuilder->codeAppendf("\t%s = %s;\n", args.fOutput, 212 fsBuilder->codeAppendf("\t%s = %s;\n", args.fOutput,
215 (GrGLSLExpr4(args.fInput) * GrGLSLExpr1("cove rage")).c_str()); 213 (GrGLSLExpr4(args.fInput) * GrGLSLExpr1("cove rage")).c_str());
216 } 214 }
217 215
218 static void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKeyBu ilder*) {} 216 static void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKeyBu ilder*) {}
219 217
220 virtual void setData(const GrGLProgramDataManager& pdman, const GrProces sor&) SK_OVERRIDE {} 218 virtual void setData(const GrGLProgramDataManager& pdman, const GrProces sor&) SK_OVERRIDE {}
221 219
(...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after
918 // can't call mapRect for devInside since it calls sort 916 // can't call mapRect for devInside since it calls sort
919 combinedMatrix.mapPoints((SkPoint*)&devInside, (const SkPoint*)&rects[1], 2) ; 917 combinedMatrix.mapPoints((SkPoint*)&devInside, (const SkPoint*)&rects[1], 2) ;
920 918
921 if (devInside.isEmpty()) { 919 if (devInside.isEmpty()) {
922 this->fillAARect(gpu, target, devOutside, SkMatrix::I(), devOutside); 920 this->fillAARect(gpu, target, devOutside, SkMatrix::I(), devOutside);
923 return; 921 return;
924 } 922 }
925 923
926 this->geometryStrokeAARect(gpu, target, devOutside, devOutsideAssist, devIns ide, true); 924 this->geometryStrokeAARect(gpu, target, devOutside, devOutsideAssist, devIns ide, true);
927 } 925 }
OLDNEW
« no previous file with comments | « src/gpu/GrAAConvexPathRenderer.cpp ('k') | src/gpu/GrOvalRenderer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698