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 "GrRefCnt.h" | 9 #include "GrRefCnt.h" |
10 #include "GrGpu.h" | 10 #include "GrGpu.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
51 const char* inputColor, | 51 const char* inputColor, |
52 const TextureSamplerArray& samplers) SK_OVERRIDE { | 52 const TextureSamplerArray& samplers) SK_OVERRIDE { |
53 // setup the varying for the Axis aligned rect effect | 53 // setup the varying for the Axis aligned rect effect |
54 // xy -> interpolated offset | 54 // xy -> interpolated offset |
55 // zw -> w/2+0.5, h/2+0.5 | 55 // zw -> w/2+0.5, h/2+0.5 |
56 const char *vsRectName, *fsRectName; | 56 const char *vsRectName, *fsRectName; |
57 builder->addVarying(kVec4f_GrSLType, "Rect", &vsRectName, &fsRectNam e); | 57 builder->addVarying(kVec4f_GrSLType, "Rect", &vsRectName, &fsRectNam e); |
58 const SkString* attr0Name = | 58 const SkString* attr0Name = |
59 builder->getEffectAttributeName(drawEffect.getVertexAttribIndice s()[0]); | 59 builder->getEffectAttributeName(drawEffect.getVertexAttribIndice s()[0]); |
60 builder->vsCodeAppendf("\t%s = %s;\n", vsRectName, attr0Name->c_str( )); | 60 builder->vsCodeAppendf("\t%s = %s;\n", vsRectName, attr0Name->c_str( )); |
61 | 61 |
robertphillips
2013/06/13 17:45:52
This comment is now orphaned
egdaniel
2013/06/13 19:17:46
What do you mean by orphaned? Both the TODO and th
robertphillips
2013/06/13 19:55:24
It isn't as relevant in this iteration but in an e
| |
62 // TODO: compute these scale factors in the VS | 62 // TODO: compute these scale factors in the VS |
63 // These scale factors adjust the coverage for < 1 pixel wide/high r ects | 63 // These scale factors adjust the coverage for < 1 pixel wide/high r ects |
64 builder->fsCodeAppendf("\tfloat wScale = max(1.0, 2.0/(0.5+%s.z));\n ", | 64 builder->fsCodeAppendf("\tfloat insetW = min(1.0, %s.z) - 0.5;\n", f sRectName); |
65 fsRectName); | 65 builder->fsCodeAppendf("\tfloat insetH = min(1.0, %s.w) - 0.5;\n", f sRectName); |
66 builder->fsCodeAppendf("\tfloat hScale = max(1.0, 2.0/(0.5+%s.w));\n ", | 66 builder->fsCodeAppend("\tfloat outset = 0.5;\n"); |
bsalomon
2013/06/13 14:27:51
static const?
I'm not sure, but I think windows m
egdaniel
2013/06/13 14:52:18
On 2013/06/13 14:27:51, bsalomon wrote:
I will mak
bsalomon
2013/06/13 14:55:45
I'm a moron... I was reading this as c code. ignor
| |
67 fsRectName); | 67 builder->fsCodeAppend("\tfloat spanW = insetW + outset;\n"); |
68 builder->fsCodeAppend("\tfloat spanH = insetH + outset;\n"); | |
69 builder->fsCodeAppend("\tfloat scaleW = min(1.0, 2*insetW/(spanW));\ n"); | |
bsalomon
2013/06/13 14:27:51
need the parens in the divisor?
| |
70 builder->fsCodeAppend("\tfloat scaleH = min(1.0, 2*insetH/(spanH));\ n"); | |
68 | 71 |
69 // Compute the coverage for the rect's width | 72 // Compute the coverage for the rect's width |
70 builder->fsCodeAppendf("\tfloat coverage = clamp(wScale*(%s.z-abs(%s .x)), 0.0, 1.0);\n", | 73 builder->fsCodeAppendf( |
71 fsRectName, | 74 "\tfloat coverage = scaleW*clamp((%s.z-abs(%s.x))/spanW, 0.0, 1. 0);\n", fsRectName, |
72 fsRectName); | 75 fsRectName); |
73 | |
74 // Compute the coverage for the rect's height and merge with the wid th | 76 // Compute the coverage for the rect's height and merge with the wid th |
75 builder->fsCodeAppendf( | 77 builder->fsCodeAppendf( |
76 "\tcoverage = min(coverage, clamp(hScale*(%s.w-abs(%s.y)), 0 .0, 1.0));\n", | 78 "\tcoverage = coverage*scaleH*clamp((%s.w-abs(%s.y))/spanH, 0.0, 1.0);\n",fsRectName, |
77 fsRectName, | 79 fsRectName); |
78 fsRectName); | |
79 | 80 |
80 SkString modulate; | 81 SkString modulate; |
81 GrGLSLModulatef<4>(&modulate, inputColor, "coverage"); | 82 GrGLSLModulatef<4>(&modulate, inputColor, "coverage"); |
82 builder->fsCodeAppendf("\t%s = %s;\n", outputColor, modulate.c_str() ); | 83 builder->fsCodeAppendf("\t%s = %s;\n", outputColor, modulate.c_str() ); |
83 } | 84 } |
84 | 85 |
85 static inline EffectKey GenKey(const GrDrawEffect& drawEffect, const GrG LCaps&) { | 86 static inline EffectKey GenKey(const GrDrawEffect& drawEffect, const GrG LCaps&) { |
86 return 0; | 87 return 0; |
87 } | 88 } |
88 | 89 |
(...skipping 689 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
778 // can't call mapRect for devInside since it calls sort | 779 // can't call mapRect for devInside since it calls sort |
779 combinedMatrix.mapPoints((SkPoint*)&devInside, (const SkPoint*)&rects[1], 2) ; | 780 combinedMatrix.mapPoints((SkPoint*)&devInside, (const SkPoint*)&rects[1], 2) ; |
780 | 781 |
781 if (devInside.isEmpty()) { | 782 if (devInside.isEmpty()) { |
782 this->fillAARect(gpu, target, devOutside, SkMatrix::I(), devOutside, use VertexCoverage); | 783 this->fillAARect(gpu, target, devOutside, SkMatrix::I(), devOutside, use VertexCoverage); |
783 return; | 784 return; |
784 } | 785 } |
785 | 786 |
786 this->geometryStrokeAARect(gpu, target, devOutside, devInside, useVertexCove rage); | 787 this->geometryStrokeAARect(gpu, target, devOutside, devInside, useVertexCove rage); |
787 } | 788 } |
OLD | NEW |