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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 |
62 // TODO: compute these scale factors in the VS | 62 // TODO: compute all these offsets, spans, and scales in the VS |
63 // These scale factors adjust the coverage for < 1 pixel wide/high r
ects | 63 builder->fsCodeAppendf("\tfloat insetW = min(1.0, %s.z) - 0.5;\n", f
sRectName); |
64 builder->fsCodeAppendf("\tfloat wScale = max(1.0, 2.0/(0.5+%s.z));\n
", | 64 builder->fsCodeAppendf("\tfloat insetH = min(1.0, %s.w) - 0.5;\n", f
sRectName); |
65 fsRectName); | 65 builder->fsCodeAppend("\tfloat outset = 0.5;\n"); |
66 builder->fsCodeAppendf("\tfloat hScale = max(1.0, 2.0/(0.5+%s.w));\n
", | 66 // For rects > 1 pixel wide and tall the span's are noops (i.e., 1.0
). For rects |
67 fsRectName); | 67 // < 1 pixel wide or tall they serve to normalize the < 1 ramp to a
0 .. 1 range. |
| 68 builder->fsCodeAppend("\tfloat spanW = insetW + outset;\n"); |
| 69 builder->fsCodeAppend("\tfloat spanH = insetH + outset;\n"); |
| 70 // 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 |
| 72 // used in the interior of the rect after the ramp. |
| 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"); |
68 | 75 |
69 // Compute the coverage for the rect's width | 76 // 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", | 77 builder->fsCodeAppendf( |
71 fsRectName, | 78 "\tfloat coverage = scaleW*clamp((%s.z-abs(%s.x))/spanW, 0.0, 1.
0);\n", fsRectName, |
72 fsRectName); | 79 fsRectName); |
73 | |
74 // 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 |
75 builder->fsCodeAppendf( | 81 builder->fsCodeAppendf( |
76 "\tcoverage = min(coverage, clamp(hScale*(%s.w-abs(%s.y)), 0
.0, 1.0));\n", | 82 "\tcoverage = coverage*scaleH*clamp((%s.w-abs(%s.y))/spanH, 0.0,
1.0);\n", |
77 fsRectName, | 83 fsRectName, fsRectName); |
78 fsRectName); | |
79 | 84 |
80 SkString modulate; | 85 SkString modulate; |
81 GrGLSLModulatef<4>(&modulate, inputColor, "coverage"); | 86 GrGLSLModulatef<4>(&modulate, inputColor, "coverage"); |
82 builder->fsCodeAppendf("\t%s = %s;\n", outputColor, modulate.c_str()
); | 87 builder->fsCodeAppendf("\t%s = %s;\n", outputColor, modulate.c_str()
); |
83 } | 88 } |
84 | 89 |
85 static inline EffectKey GenKey(const GrDrawEffect& drawEffect, const GrG
LCaps&) { | 90 static inline EffectKey GenKey(const GrDrawEffect& drawEffect, const GrG
LCaps&) { |
86 return 0; | 91 return 0; |
87 } | 92 } |
88 | 93 |
(...skipping 689 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
778 // can't call mapRect for devInside since it calls sort | 783 // can't call mapRect for devInside since it calls sort |
779 combinedMatrix.mapPoints((SkPoint*)&devInside, (const SkPoint*)&rects[1], 2)
; | 784 combinedMatrix.mapPoints((SkPoint*)&devInside, (const SkPoint*)&rects[1], 2)
; |
780 | 785 |
781 if (devInside.isEmpty()) { | 786 if (devInside.isEmpty()) { |
782 this->fillAARect(gpu, target, devOutside, SkMatrix::I(), devOutside, use
VertexCoverage); | 787 this->fillAARect(gpu, target, devOutside, SkMatrix::I(), devOutside, use
VertexCoverage); |
783 return; | 788 return; |
784 } | 789 } |
785 | 790 |
786 this->geometryStrokeAARect(gpu, target, devOutside, devInside, useVertexCove
rage); | 791 this->geometryStrokeAARect(gpu, target, devOutside, devInside, useVertexCove
rage); |
787 } | 792 } |
OLD | NEW |