| 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 "gl/builders/GrGLProgramBuilder.h" | 8 #include "gl/builders/GrGLProgramBuilder.h" |
| 9 #include "GrAARectRenderer.h" | 9 #include "GrAARectRenderer.h" |
| 10 #include "GrGpu.h" | 10 #include "GrGpu.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 } | 36 } |
| 37 | 37 |
| 38 const GrShaderVar& inRect() const { return fInRect; } | 38 const GrShaderVar& inRect() const { return fInRect; } |
| 39 | 39 |
| 40 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE { | 40 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE { |
| 41 return GrTBackendEffectFactory<GrAlignedRectEffect>::getInstance(); | 41 return GrTBackendEffectFactory<GrAlignedRectEffect>::getInstance(); |
| 42 } | 42 } |
| 43 | 43 |
| 44 class GLEffect : public GrGLGeometryProcessor { | 44 class GLEffect : public GrGLGeometryProcessor { |
| 45 public: | 45 public: |
| 46 GLEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&) | 46 GLEffect(const GrBackendEffectFactory& factory, const GrEffect&) |
| 47 : INHERITED (factory) {} | 47 : INHERITED (factory) {} |
| 48 | 48 |
| 49 virtual void emitCode(GrGLFullProgramBuilder* builder, | 49 virtual void emitCode(GrGLFullProgramBuilder* builder, |
| 50 const GrDrawEffect& drawEffect, | 50 const GrEffect& effect, |
| 51 const GrEffectKey& key, | 51 const GrEffectKey& key, |
| 52 const char* outputColor, | 52 const char* outputColor, |
| 53 const char* inputColor, | 53 const char* inputColor, |
| 54 const TransformedCoordsArray&, | 54 const TransformedCoordsArray&, |
| 55 const TextureSamplerArray& samplers) SK_OVERRIDE { | 55 const TextureSamplerArray& samplers) SK_OVERRIDE { |
| 56 // setup the varying for the Axis aligned rect effect | 56 // setup the varying for the Axis aligned rect effect |
| 57 // xy -> interpolated offset | 57 // xy -> interpolated offset |
| 58 // zw -> w/2+0.5, h/2+0.5 | 58 // zw -> w/2+0.5, h/2+0.5 |
| 59 const char *vsRectName, *fsRectName; | 59 const char *vsRectName, *fsRectName; |
| 60 builder->addVarying(kVec4f_GrSLType, "Rect", &vsRectName, &fsRectNam
e); | 60 builder->addVarying(kVec4f_GrSLType, "Rect", &vsRectName, &fsRectNam
e); |
| 61 | 61 |
| 62 const GrShaderVar& inRect = drawEffect.castEffect<GrAlignedRectEffec
t>().inRect(); | 62 const GrShaderVar& inRect = effect.cast<GrAlignedRectEffect>().inRec
t(); |
| 63 GrGLVertexShaderBuilder* vsBuilder = builder->getVertexShaderBuilder
(); | 63 GrGLVertexShaderBuilder* vsBuilder = builder->getVertexShaderBuilder
(); |
| 64 vsBuilder->codeAppendf("\t%s = %s;\n", vsRectName, inRect.c_str()); | 64 vsBuilder->codeAppendf("\t%s = %s;\n", vsRectName, inRect.c_str()); |
| 65 | 65 |
| 66 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBui
lder(); | 66 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBui
lder(); |
| 67 // TODO: compute all these offsets, spans, and scales in the VS | 67 // TODO: compute all these offsets, spans, and scales in the VS |
| 68 fsBuilder->codeAppendf("\tfloat insetW = min(1.0, %s.z) - 0.5;\n", f
sRectName); | 68 fsBuilder->codeAppendf("\tfloat insetW = min(1.0, %s.z) - 0.5;\n", f
sRectName); |
| 69 fsBuilder->codeAppendf("\tfloat insetH = min(1.0, %s.w) - 0.5;\n", f
sRectName); | 69 fsBuilder->codeAppendf("\tfloat insetH = min(1.0, %s.w) - 0.5;\n", f
sRectName); |
| 70 fsBuilder->codeAppend("\tfloat outset = 0.5;\n"); | 70 fsBuilder->codeAppend("\tfloat outset = 0.5;\n"); |
| 71 // For rects > 1 pixel wide and tall the span's are noops (i.e., 1.0
). For rects | 71 // For rects > 1 pixel wide and tall the span's are noops (i.e., 1.0
). For rects |
| 72 // < 1 pixel wide or tall they serve to normalize the < 1 ramp to a
0 .. 1 range. | 72 // < 1 pixel wide or tall they serve to normalize the < 1 ramp to a
0 .. 1 range. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 85 // Compute the coverage for the rect's height and merge with the wid
th | 85 // Compute the coverage for the rect's height and merge with the wid
th |
| 86 fsBuilder->codeAppendf( | 86 fsBuilder->codeAppendf( |
| 87 "\tcoverage = coverage*scaleH*clamp((%s.w-abs(%s.y))/spanH, 0.0,
1.0);\n", | 87 "\tcoverage = coverage*scaleH*clamp((%s.w-abs(%s.y))/spanH, 0.0,
1.0);\n", |
| 88 fsRectName, fsRectName); | 88 fsRectName, fsRectName); |
| 89 | 89 |
| 90 | 90 |
| 91 fsBuilder->codeAppendf("\t%s = %s;\n", outputColor, | 91 fsBuilder->codeAppendf("\t%s = %s;\n", outputColor, |
| 92 (GrGLSLExpr4(inputColor) * GrGLSLExpr1("cover
age")).c_str()); | 92 (GrGLSLExpr4(inputColor) * GrGLSLExpr1("cover
age")).c_str()); |
| 93 } | 93 } |
| 94 | 94 |
| 95 static void GenKey(const GrDrawEffect&, const GrGLCaps&, GrEffectKeyBuil
der*) {} | 95 static void GenKey(const GrEffect&, const GrGLCaps&, GrEffectKeyBuilder*
) {} |
| 96 | 96 |
| 97 virtual void setData(const GrGLProgramDataManager& pdman, const GrDrawEf
fect&) SK_OVERRIDE {} | 97 virtual void setData(const GrGLProgramDataManager& pdman, const GrEffect
&) SK_OVERRIDE {} |
| 98 | 98 |
| 99 private: | 99 private: |
| 100 typedef GrGLGeometryProcessor INHERITED; | 100 typedef GrGLGeometryProcessor INHERITED; |
| 101 }; | 101 }; |
| 102 | 102 |
| 103 | 103 |
| 104 private: | 104 private: |
| 105 GrAlignedRectEffect() | 105 GrAlignedRectEffect() |
| 106 : fInRect(this->addVertexAttrib(GrShaderVar("inRect", | 106 : fInRect(this->addVertexAttrib(GrShaderVar("inRect", |
| 107 kVec4f_GrSLType, | 107 kVec4f_GrSLType, |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 | 162 |
| 163 const GrShaderVar& inRectEdge() const { return fInRectEdge; } | 163 const GrShaderVar& inRectEdge() const { return fInRectEdge; } |
| 164 const GrShaderVar& inWidthHeight() const { return fInWidthHeight; } | 164 const GrShaderVar& inWidthHeight() const { return fInWidthHeight; } |
| 165 | 165 |
| 166 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE { | 166 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE { |
| 167 return GrTBackendEffectFactory<GrRectEffect>::getInstance(); | 167 return GrTBackendEffectFactory<GrRectEffect>::getInstance(); |
| 168 } | 168 } |
| 169 | 169 |
| 170 class GLEffect : public GrGLGeometryProcessor { | 170 class GLEffect : public GrGLGeometryProcessor { |
| 171 public: | 171 public: |
| 172 GLEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&) | 172 GLEffect(const GrBackendEffectFactory& factory, const GrEffect&) |
| 173 : INHERITED (factory) {} | 173 : INHERITED (factory) {} |
| 174 | 174 |
| 175 virtual void emitCode(GrGLFullProgramBuilder* builder, | 175 virtual void emitCode(GrGLFullProgramBuilder* builder, |
| 176 const GrDrawEffect& drawEffect, | 176 const GrEffect& effect, |
| 177 const GrEffectKey& key, | 177 const GrEffectKey& key, |
| 178 const char* outputColor, | 178 const char* outputColor, |
| 179 const char* inputColor, | 179 const char* inputColor, |
| 180 const TransformedCoordsArray&, | 180 const TransformedCoordsArray&, |
| 181 const TextureSamplerArray& samplers) SK_OVERRIDE { | 181 const TextureSamplerArray& samplers) SK_OVERRIDE { |
| 182 // setup the varying for the center point and the unit vector | 182 // setup the varying for the center point and the unit vector |
| 183 // that points down the height of the rect | 183 // that points down the height of the rect |
| 184 const char *vsRectEdgeName, *fsRectEdgeName; | 184 const char *vsRectEdgeName, *fsRectEdgeName; |
| 185 builder->addVarying(kVec4f_GrSLType, "RectEdge", | 185 builder->addVarying(kVec4f_GrSLType, "RectEdge", |
| 186 &vsRectEdgeName, &fsRectEdgeName); | 186 &vsRectEdgeName, &fsRectEdgeName); |
| 187 | 187 |
| 188 const GrRectEffect& rectEffect = drawEffect.castEffect<GrRectEffect>
(); | 188 const GrRectEffect& rectEffect = effect.cast<GrRectEffect>(); |
| 189 GrGLVertexShaderBuilder* vsBuilder = builder->getVertexShaderBuilder
(); | 189 GrGLVertexShaderBuilder* vsBuilder = builder->getVertexShaderBuilder
(); |
| 190 vsBuilder->codeAppendf("%s = %s;", vsRectEdgeName, rectEffect.inRect
Edge().c_str()); | 190 vsBuilder->codeAppendf("%s = %s;", vsRectEdgeName, rectEffect.inRect
Edge().c_str()); |
| 191 | 191 |
| 192 // setup the varying for width/2+.5 and height/2+.5 | 192 // setup the varying for width/2+.5 and height/2+.5 |
| 193 const char *vsWidthHeightName, *fsWidthHeightName; | 193 const char *vsWidthHeightName, *fsWidthHeightName; |
| 194 builder->addVarying(kVec2f_GrSLType, "WidthHeight", | 194 builder->addVarying(kVec2f_GrSLType, "WidthHeight", |
| 195 &vsWidthHeightName, &fsWidthHeightName); | 195 &vsWidthHeightName, &fsWidthHeightName); |
| 196 vsBuilder->codeAppendf("%s = %s;", | 196 vsBuilder->codeAppendf("%s = %s;", |
| 197 vsWidthHeightName, | 197 vsWidthHeightName, |
| 198 rectEffect.inWidthHeight().c_str()); | 198 rectEffect.inWidthHeight().c_str()); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 226 fsRectEdgeName); | 226 fsRectEdgeName); |
| 227 fsBuilder->codeAppendf( | 227 fsBuilder->codeAppendf( |
| 228 "\tcoverage = coverage*scaleH*clamp((%s.y-perpDot)/spanH, 0.
0, 1.0);\n", | 228 "\tcoverage = coverage*scaleH*clamp((%s.y-perpDot)/spanH, 0.
0, 1.0);\n", |
| 229 fsWidthHeightName); | 229 fsWidthHeightName); |
| 230 | 230 |
| 231 | 231 |
| 232 fsBuilder->codeAppendf("\t%s = %s;\n", outputColor, | 232 fsBuilder->codeAppendf("\t%s = %s;\n", outputColor, |
| 233 (GrGLSLExpr4(inputColor) * GrGLSLExpr1("cover
age")).c_str()); | 233 (GrGLSLExpr4(inputColor) * GrGLSLExpr1("cover
age")).c_str()); |
| 234 } | 234 } |
| 235 | 235 |
| 236 static void GenKey(const GrDrawEffect&, const GrGLCaps&, GrEffectKeyBuil
der*) {} | 236 static void GenKey(const GrEffect&, const GrGLCaps&, GrEffectKeyBuilder*
) {} |
| 237 | 237 |
| 238 virtual void setData(const GrGLProgramDataManager& pdman, const GrDrawEf
fect&) SK_OVERRIDE {} | 238 virtual void setData(const GrGLProgramDataManager& pdman, const GrEffect
&) SK_OVERRIDE {} |
| 239 | 239 |
| 240 private: | 240 private: |
| 241 typedef GrGLGeometryProcessor INHERITED; | 241 typedef GrGLGeometryProcessor INHERITED; |
| 242 }; | 242 }; |
| 243 | 243 |
| 244 | 244 |
| 245 | 245 |
| 246 private: | 246 private: |
| 247 GrRectEffect() | 247 GrRectEffect() |
| 248 : fInRectEdge(this->addVertexAttrib(GrShaderVar("inRectEdge", | 248 : fInRectEdge(this->addVertexAttrib(GrShaderVar("inRectEdge", |
| (...skipping 714 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 963 // can't call mapRect for devInside since it calls sort | 963 // can't call mapRect for devInside since it calls sort |
| 964 combinedMatrix.mapPoints((SkPoint*)&devInside, (const SkPoint*)&rects[1], 2)
; | 964 combinedMatrix.mapPoints((SkPoint*)&devInside, (const SkPoint*)&rects[1], 2)
; |
| 965 | 965 |
| 966 if (devInside.isEmpty()) { | 966 if (devInside.isEmpty()) { |
| 967 this->fillAARect(gpu, target, devOutside, SkMatrix::I(), devOutside); | 967 this->fillAARect(gpu, target, devOutside, SkMatrix::I(), devOutside); |
| 968 return; | 968 return; |
| 969 } | 969 } |
| 970 | 970 |
| 971 this->geometryStrokeAARect(gpu, target, devOutside, devOutsideAssist, devIns
ide, true); | 971 this->geometryStrokeAARect(gpu, target, devOutside, devOutsideAssist, devIns
ide, true); |
| 972 } | 972 } |
| OLD | NEW |