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

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

Issue 17035012: Change general fill rect shader code to match geometry vers (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 6 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 | Annotate | Revision Log
« 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 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 "GrRefCnt.h" 9 #include "GrRefCnt.h"
10 #include "GrGpu.h" 10 #include "GrGpu.h"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 // value of coverage that is used. In other words it is the coverage that is 71 // 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. 72 // used in the interior of the rect after the ramp.
73 builder->fsCodeAppend("\tfloat scaleW = min(1.0, 2.0*insetW/spanW);\ n"); 73 builder->fsCodeAppend("\tfloat scaleW = min(1.0, 2.0*insetW/spanW);\ n");
74 builder->fsCodeAppend("\tfloat scaleH = min(1.0, 2.0*insetH/spanH);\ n"); 74 builder->fsCodeAppend("\tfloat scaleH = min(1.0, 2.0*insetH/spanH);\ n");
75 75
76 // Compute the coverage for the rect's width 76 // Compute the coverage for the rect's width
77 builder->fsCodeAppendf( 77 builder->fsCodeAppendf(
78 "\tfloat coverage = scaleW*clamp((%s.z-abs(%s.x))/spanW, 0.0, 1. 0);\n", fsRectName, 78 "\tfloat coverage = scaleW*clamp((%s.z-abs(%s.x))/spanW, 0.0, 1. 0);\n", fsRectName,
79 fsRectName); 79 fsRectName);
80 // Compute the coverage for the rect's height and merge with the wid th 80 // Compute the coverage for the rect's height and merge with the wid th
81 builder->fsCodeAppendf( 81 builder->fsCodeAppendf(
82 "\tcoverage = coverage*scaleH*clamp((%s.w-abs(%s.y))/spanH, 0.0 , 1.0);\n", 82 "\tcoverage = coverage*scaleH*clamp((%s.w-abs(%s.y))/spanH, 0.0, 1.0);\n",
83 fsRectName, fsRectName); 83 fsRectName, fsRectName);
84 84
85 SkString modulate; 85 SkString modulate;
86 GrGLSLModulatef<4>(&modulate, inputColor, "coverage"); 86 GrGLSLModulatef<4>(&modulate, inputColor, "coverage");
87 builder->fsCodeAppendf("\t%s = %s;\n", outputColor, modulate.c_str() ); 87 builder->fsCodeAppendf("\t%s = %s;\n", outputColor, modulate.c_str() );
88 } 88 }
89 89
90 static inline EffectKey GenKey(const GrDrawEffect& drawEffect, const GrG LCaps&) { 90 static inline EffectKey GenKey(const GrDrawEffect& drawEffect, const GrG LCaps&) {
91 return 0; 91 return 0;
92 } 92 }
93 93
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 builder->vsCodeAppendf("\t%s = %s;\n", vsRectEdgeName, attr0Name->c_ str()); 177 builder->vsCodeAppendf("\t%s = %s;\n", vsRectEdgeName, attr0Name->c_ str());
178 178
179 // setup the varying for width/2+.5 and height/2+.5 179 // setup the varying for width/2+.5 and height/2+.5
180 const char *vsWidthHeightName, *fsWidthHeightName; 180 const char *vsWidthHeightName, *fsWidthHeightName;
181 builder->addVarying(kVec2f_GrSLType, "WidthHeight", 181 builder->addVarying(kVec2f_GrSLType, "WidthHeight",
182 &vsWidthHeightName, &fsWidthHeightName); 182 &vsWidthHeightName, &fsWidthHeightName);
183 const SkString* attr1Name = 183 const SkString* attr1Name =
184 builder->getEffectAttributeName(drawEffect.getVertexAttribIndice s()[1]); 184 builder->getEffectAttributeName(drawEffect.getVertexAttribIndice s()[1]);
185 builder->vsCodeAppendf("\t%s = %s;\n", vsWidthHeightName, attr1Name- >c_str()); 185 builder->vsCodeAppendf("\t%s = %s;\n", vsWidthHeightName, attr1Name- >c_str());
186 186
187 // TODO: compute these scale factors in the VS 187 // TODO: compute all these offsets, spans, and scales in the VS
188 // These scale factors adjust the coverage for < 1 pixel wide/high r ects 188 builder->fsCodeAppendf("\tfloat insetW = min(1.0, %s.x) - 0.5;\n", f sWidthHeightName);
189 builder->fsCodeAppendf("\tfloat wScale = max(1.0, 2.0/(0.5+%s.x));\n ", 189 builder->fsCodeAppendf("\tfloat insetH = min(1.0, %s.y) - 0.5;\n", f sWidthHeightName);
190 fsWidthHeightName); 190 builder->fsCodeAppend("\tfloat outset = 0.5;\n");
191 builder->fsCodeAppendf("\tfloat hScale = max(1.0, 2.0/(0.5+%s.y));\n ", 191 // For rects > 1 pixel wide and tall the span's are noops (i.e., 1.0 ). For rects
192 fsWidthHeightName); 192 // < 1 pixel wide or tall they serve to normalize the < 1 ramp to a 0 .. 1 range.
193 builder->fsCodeAppend("\tfloat spanW = insetW + outset;\n");
194 builder->fsCodeAppend("\tfloat spanH = insetH + outset;\n");
195 // For rects < 1 pixel wide or tall, these scale factors are used to cap the maximum
196 // value of coverage that is used. In other words it is the coverage that is
197 // used in the interior of the rect after the ramp.
198 builder->fsCodeAppend("\tfloat scaleW = min(1.0, 2.0*insetW/spanW);\ n");
199 builder->fsCodeAppend("\tfloat scaleH = min(1.0, 2.0*insetH/spanH);\ n");
193 200
194 // Compute the coverage for the rect's width 201 // Compute the coverage for the rect's width
195 builder->fsCodeAppendf("\tvec2 offset = %s.xy - %s.xy;\n", 202 builder->fsCodeAppendf("\tvec2 offset = %s.xy - %s.xy;\n",
196 builder->fragmentPosition(), fsRectEdgeName); 203 builder->fragmentPosition(), fsRectEdgeName);
197 builder->fsCodeAppendf("\tfloat perpDot = abs(offset.x * %s.w - offs et.y * %s.z);\n", 204 builder->fsCodeAppendf("\tfloat perpDot = abs(offset.x * %s.w - offs et.y * %s.z);\n",
198 fsRectEdgeName, fsRectEdgeName); 205 fsRectEdgeName, fsRectEdgeName);
199 builder->fsCodeAppendf("\tfloat coverage = clamp(wScale*(%s.x-perpDo t), 0.0, 1.0);\n", 206 builder->fsCodeAppendf(
200 fsWidthHeightName); 207 "\tfloat coverage = scaleW*clamp((%s.x-perpDot)/spanW, 0.0, 1.0) ;\n",
208 fsWidthHeightName);
201 209
202 // Compute the coverage for the rect's height and merge with the wid th 210 // Compute the coverage for the rect's height and merge with the wid th
203 builder->fsCodeAppendf("\tperpDot = abs(dot(offset, %s.zw));\n", 211 builder->fsCodeAppendf("\tperpDot = abs(dot(offset, %s.zw));\n",
204 fsRectEdgeName); 212 fsRectEdgeName);
205 builder->fsCodeAppendf( 213 builder->fsCodeAppendf(
206 "\tcoverage = min(coverage, clamp(hScale*(%s.y-perpDot), 0.0 , 1.0));\n", 214 "\tcoverage = coverage*scaleH*clamp((%s.y-perpDot)/spanH, 0. 0, 1.0);\n",
207 fsWidthHeightName); 215 fsWidthHeightName);
208 216
209 SkString modulate; 217 SkString modulate;
210 GrGLSLModulatef<4>(&modulate, inputColor, "coverage"); 218 GrGLSLModulatef<4>(&modulate, inputColor, "coverage");
211 builder->fsCodeAppendf("\t%s = %s;\n", outputColor, modulate.c_str() ); 219 builder->fsCodeAppendf("\t%s = %s;\n", outputColor, modulate.c_str() );
212 } 220 }
213 221
214 static inline EffectKey GenKey(const GrDrawEffect& drawEffect, const GrG LCaps&) { 222 static inline EffectKey GenKey(const GrDrawEffect& drawEffect, const GrG LCaps&) {
215 return 0; 223 return 0;
216 } 224 }
(...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after
769 // can't call mapRect for devInside since it calls sort 777 // can't call mapRect for devInside since it calls sort
770 combinedMatrix.mapPoints((SkPoint*)&devInside, (const SkPoint*)&rects[1], 2) ; 778 combinedMatrix.mapPoints((SkPoint*)&devInside, (const SkPoint*)&rects[1], 2) ;
771 779
772 if (devInside.isEmpty()) { 780 if (devInside.isEmpty()) {
773 this->fillAARect(gpu, target, devOutside, SkMatrix::I(), devOutside, use VertexCoverage); 781 this->fillAARect(gpu, target, devOutside, SkMatrix::I(), devOutside, use VertexCoverage);
774 return; 782 return;
775 } 783 }
776 784
777 this->geometryStrokeAARect(gpu, target, devOutside, devInside, useVertexCove rage); 785 this->geometryStrokeAARect(gpu, target, devOutside, devInside, useVertexCove rage);
778 } 786 }
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