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

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

Issue 666693012: GP Emit Code takes a struct (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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 23 matching lines...) Expand all
34 34
35 virtual const GrBackendGeometryProcessorFactory& getFactory() const SK_OVERR IDE { 35 virtual const GrBackendGeometryProcessorFactory& getFactory() const SK_OVERR IDE {
36 return GrTBackendGeometryProcessorFactory<GrAlignedRectEffect>::getInsta nce(); 36 return GrTBackendGeometryProcessorFactory<GrAlignedRectEffect>::getInsta nce();
37 } 37 }
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(GrGLGPBuilder* builder, 44 virtual void emitCode(const EmitArgs& args) SK_OVERRIDE {
45 const GrGeometryProcessor& geometryProcessor,
46 const GrProcessorKey& key,
47 const char* outputColor,
48 const char* inputColor,
49 const TransformedCoordsArray&,
50 const TextureSamplerArray& samplers) SK_OVERRIDE {
51 // setup the varying for the Axis aligned rect effect 45 // setup the varying for the Axis aligned rect effect
52 // xy -> interpolated offset 46 // xy -> interpolated offset
53 // zw -> w/2+0.5, h/2+0.5 47 // zw -> w/2+0.5, h/2+0.5
54 const char *vsRectName, *fsRectName; 48 const char *vsRectName, *fsRectName;
55 builder->addVarying(kVec4f_GrSLType, "Rect", &vsRectName, &fsRectNam e); 49 args.fPB->addVarying(kVec4f_GrSLType, "Rect", &vsRectName, &fsRectNa me);
56 50
57 const GrShaderVar& inRect = geometryProcessor.cast<GrAlignedRectEffe ct>().inRect(); 51 const GrShaderVar& inRect = args.fGP.cast<GrAlignedRectEffect>().inR ect();
58 GrGLVertexBuilder* vsBuilder = builder->getVertexShaderBuilder(); 52 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder();
59 vsBuilder->codeAppendf("\t%s = %s;\n", vsRectName, inRect.c_str()); 53 vsBuilder->codeAppendf("\t%s = %s;\n", vsRectName, inRect.c_str());
60 54
61 GrGLGPFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder (); 55 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilde r();
62 // TODO: compute all these offsets, spans, and scales in the VS 56 // TODO: compute all these offsets, spans, and scales in the VS
63 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", f sRectName);
64 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", f sRectName);
65 fsBuilder->codeAppend("\tfloat outset = 0.5;\n"); 59 fsBuilder->codeAppend("\tfloat outset = 0.5;\n");
66 // 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
67 // < 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.
68 fsBuilder->codeAppend("\tfloat spanW = insetW + outset;\n"); 62 fsBuilder->codeAppend("\tfloat spanW = insetW + outset;\n");
69 fsBuilder->codeAppend("\tfloat spanH = insetH + outset;\n"); 63 fsBuilder->codeAppend("\tfloat spanH = insetH + outset;\n");
70 // 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
71 // 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
72 // used in the interior of the rect after the ramp. 66 // used in the interior of the rect after the ramp.
73 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");
74 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");
75 69
76 // Compute the coverage for the rect's width 70 // Compute the coverage for the rect's width
77 fsBuilder->codeAppendf( 71 fsBuilder->codeAppendf(
78 "\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", fsRectName,
79 fsRectName); 73 fsRectName);
80 // 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
81 fsBuilder->codeAppendf( 75 fsBuilder->codeAppendf(
82 "\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",
83 fsRectName, fsRectName); 77 fsRectName, fsRectName);
84 78
85 79
86 fsBuilder->codeAppendf("\t%s = %s;\n", outputColor, 80 fsBuilder->codeAppendf("\t%s = %s;\n", args.fOutput,
87 (GrGLSLExpr4(inputColor) * GrGLSLExpr1("cover age")).c_str()); 81 (GrGLSLExpr4(args.fInput) * GrGLSLExpr1("cove rage")).c_str());
88 } 82 }
89 83
90 static void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKeyBu ilder*) {} 84 static void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKeyBu ilder*) {}
91 85
92 virtual void setData(const GrGLProgramDataManager& pdman, const GrProces sor&) SK_OVERRIDE {} 86 virtual void setData(const GrGLProgramDataManager& pdman, const GrProces sor&) SK_OVERRIDE {}
93 87
94 private: 88 private:
95 typedef GrGLGeometryProcessor INHERITED; 89 typedef GrGLGeometryProcessor INHERITED;
96 }; 90 };
97 91
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 153
160 virtual const GrBackendGeometryProcessorFactory& getFactory() const SK_OVERR IDE { 154 virtual const GrBackendGeometryProcessorFactory& getFactory() const SK_OVERR IDE {
161 return GrTBackendGeometryProcessorFactory<GrRectEffect>::getInstance(); 155 return GrTBackendGeometryProcessorFactory<GrRectEffect>::getInstance();
162 } 156 }
163 157
164 class GLProcessor : public GrGLGeometryProcessor { 158 class GLProcessor : public GrGLGeometryProcessor {
165 public: 159 public:
166 GLProcessor(const GrBackendProcessorFactory& factory, const GrProcessor& ) 160 GLProcessor(const GrBackendProcessorFactory& factory, const GrProcessor& )
167 : INHERITED (factory) {} 161 : INHERITED (factory) {}
168 162
169 virtual void emitCode(GrGLGPBuilder* builder, 163 virtual void emitCode(const EmitArgs& args) SK_OVERRIDE {
170 const GrGeometryProcessor& geometryProcessor,
171 const GrProcessorKey& key,
172 const char* outputColor,
173 const char* inputColor,
174 const TransformedCoordsArray&,
175 const TextureSamplerArray& samplers) SK_OVERRIDE {
176 // setup the varying for the center point and the unit vector 164 // setup the varying for the center point and the unit vector
177 // that points down the height of the rect 165 // that points down the height of the rect
178 const char *vsRectEdgeName, *fsRectEdgeName; 166 const char *vsRectEdgeName, *fsRectEdgeName;
179 builder->addVarying(kVec4f_GrSLType, "RectEdge", 167 args.fPB->addVarying(kVec4f_GrSLType, "RectEdge",
180 &vsRectEdgeName, &fsRectEdgeName); 168 &vsRectEdgeName, &fsRectEdgeName);
181 169
182 const GrRectEffect& rectEffect = geometryProcessor.cast<GrRectEffect >(); 170 const GrRectEffect& rectEffect = args.fGP.cast<GrRectEffect>();
183 GrGLVertexBuilder* vsBuilder = builder->getVertexShaderBuilder(); 171 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder();
184 vsBuilder->codeAppendf("%s = %s;", vsRectEdgeName, rectEffect.inRect Edge().c_str()); 172 vsBuilder->codeAppendf("%s = %s;", vsRectEdgeName, rectEffect.inRect Edge().c_str());
185 173
186 // setup the varying for width/2+.5 and height/2+.5 174 // setup the varying for width/2+.5 and height/2+.5
187 const char *vsWidthHeightName, *fsWidthHeightName; 175 const char *vsWidthHeightName, *fsWidthHeightName;
188 builder->addVarying(kVec2f_GrSLType, "WidthHeight", 176 args.fPB->addVarying(kVec2f_GrSLType, "WidthHeight",
189 &vsWidthHeightName, &fsWidthHeightName); 177 &vsWidthHeightName, &fsWidthHeightName);
190 vsBuilder->codeAppendf("%s = %s;", 178 vsBuilder->codeAppendf("%s = %s;",
191 vsWidthHeightName, 179 vsWidthHeightName,
192 rectEffect.inWidthHeight().c_str()); 180 rectEffect.inWidthHeight().c_str());
193 181
194 GrGLGPFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder (); 182 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilde r();
195 // TODO: compute all these offsets, spans, and scales in the VS 183 // TODO: compute all these offsets, spans, and scales in the VS
196 fsBuilder->codeAppendf("\tfloat insetW = min(1.0, %s.x) - 0.5;\n", f sWidthHeightName); 184 fsBuilder->codeAppendf("\tfloat insetW = min(1.0, %s.x) - 0.5;\n", f sWidthHeightName);
197 fsBuilder->codeAppendf("\tfloat insetH = min(1.0, %s.y) - 0.5;\n", f sWidthHeightName); 185 fsBuilder->codeAppendf("\tfloat insetH = min(1.0, %s.y) - 0.5;\n", f sWidthHeightName);
198 fsBuilder->codeAppend("\tfloat outset = 0.5;\n"); 186 fsBuilder->codeAppend("\tfloat outset = 0.5;\n");
199 // 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
200 // < 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.
201 fsBuilder->codeAppend("\tfloat spanW = insetW + outset;\n"); 189 fsBuilder->codeAppend("\tfloat spanW = insetW + outset;\n");
202 fsBuilder->codeAppend("\tfloat spanH = insetH + outset;\n"); 190 fsBuilder->codeAppend("\tfloat spanH = insetH + outset;\n");
203 // 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
204 // 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
(...skipping 11 matching lines...) Expand all
216 fsWidthHeightName); 204 fsWidthHeightName);
217 205
218 // 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
219 fsBuilder->codeAppendf("\tperpDot = abs(dot(offset, %s.zw));\n", 207 fsBuilder->codeAppendf("\tperpDot = abs(dot(offset, %s.zw));\n",
220 fsRectEdgeName); 208 fsRectEdgeName);
221 fsBuilder->codeAppendf( 209 fsBuilder->codeAppendf(
222 "\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",
223 fsWidthHeightName); 211 fsWidthHeightName);
224 212
225 213
226 fsBuilder->codeAppendf("\t%s = %s;\n", outputColor, 214 fsBuilder->codeAppendf("\t%s = %s;\n", args.fOutput,
227 (GrGLSLExpr4(inputColor) * GrGLSLExpr1("cover age")).c_str()); 215 (GrGLSLExpr4(args.fInput) * GrGLSLExpr1("cove rage")).c_str());
228 } 216 }
229 217
230 static void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKeyBu ilder*) {} 218 static void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKeyBu ilder*) {}
231 219
232 virtual void setData(const GrGLProgramDataManager& pdman, const GrProces sor&) SK_OVERRIDE {} 220 virtual void setData(const GrGLProgramDataManager& pdman, const GrProces sor&) SK_OVERRIDE {}
233 221
234 private: 222 private:
235 typedef GrGLGeometryProcessor INHERITED; 223 typedef GrGLGeometryProcessor INHERITED;
236 }; 224 };
237 225
(...skipping 723 matching lines...) Expand 10 before | Expand all | Expand 10 after
961 // can't call mapRect for devInside since it calls sort 949 // can't call mapRect for devInside since it calls sort
962 combinedMatrix.mapPoints((SkPoint*)&devInside, (const SkPoint*)&rects[1], 2) ; 950 combinedMatrix.mapPoints((SkPoint*)&devInside, (const SkPoint*)&rects[1], 2) ;
963 951
964 if (devInside.isEmpty()) { 952 if (devInside.isEmpty()) {
965 this->fillAARect(gpu, target, devOutside, SkMatrix::I(), devOutside); 953 this->fillAARect(gpu, target, devOutside, SkMatrix::I(), devOutside);
966 return; 954 return;
967 } 955 }
968 956
969 this->geometryStrokeAARect(gpu, target, devOutside, devOutsideAssist, devIns ide, true); 957 this->geometryStrokeAARect(gpu, target, devOutside, devOutsideAssist, devIns ide, true);
970 } 958 }
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