| 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 "GrGpu.h" | 9 #include "GrGpu.h" |
| 10 #include "gl/builders/GrGLProgramBuilder.h" | 10 #include "gl/builders/GrGLFullProgramBuilder.h" |
| 11 #include "gl/GrGLProcessor.h" | 11 #include "gl/GrGLProcessor.h" |
| 12 #include "gl/GrGLGeometryProcessor.h" | 12 #include "gl/GrGLGeometryProcessor.h" |
| 13 #include "GrTBackendProcessorFactory.h" | 13 #include "GrTBackendProcessorFactory.h" |
| 14 #include "SkColorPriv.h" | 14 #include "SkColorPriv.h" |
| 15 #include "GrGeometryProcessor.h" | 15 #include "GrGeometryProcessor.h" |
| 16 | 16 |
| 17 /////////////////////////////////////////////////////////////////////////////// | 17 /////////////////////////////////////////////////////////////////////////////// |
| 18 class GrGLAlignedRectEffect; | 18 class GrGLAlignedRectEffect; |
| 19 | 19 |
| 20 // Axis Aligned special case | 20 // Axis Aligned special case |
| (...skipping 13 matching lines...) Expand all Loading... |
| 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(GrGLFullProgramBuilder* builder, |
| 45 const GrGeometryProcessor& geometryProcessor, | 45 const GrGeometryProcessor& geometryProcessor, |
| 46 const GrProcessorKey& key, | 46 const GrProcessorKey& key, |
| 47 const char* outputColor, | 47 const char* outputColor, |
| 48 const char* inputColor, | 48 const char* inputColor, |
| 49 const TransformedCoordsArray&, | 49 const TransformedCoordsArray&, |
| 50 const TextureSamplerArray& samplers) SK_OVERRIDE { | 50 const TextureSamplerArray& samplers) SK_OVERRIDE { |
| 51 // setup the varying for the Axis aligned rect effect | 51 // setup the varying for the Axis aligned rect effect |
| 52 // xy -> interpolated offset | 52 // xy -> interpolated offset |
| 53 // zw -> w/2+0.5, h/2+0.5 | 53 // zw -> w/2+0.5, h/2+0.5 |
| 54 const char *vsRectName, *fsRectName; | 54 const char *vsRectName, *fsRectName; |
| 55 builder->addVarying(kVec4f_GrSLType, "Rect", &vsRectName, &fsRectNam
e); | 55 builder->addVarying(kVec4f_GrSLType, "Rect", &vsRectName, &fsRectNam
e); |
| 56 | 56 |
| 57 const GrShaderVar& inRect = geometryProcessor.cast<GrAlignedRectEffe
ct>().inRect(); | 57 const GrShaderVar& inRect = geometryProcessor.cast<GrAlignedRectEffe
ct>().inRect(); |
| 58 GrGLVertexBuilder* vsBuilder = builder->getVertexShaderBuilder(); | 58 GrGLVertexShaderBuilder* vsBuilder = builder->getVertexShaderBuilder
(); |
| 59 vsBuilder->codeAppendf("\t%s = %s;\n", vsRectName, inRect.c_str()); | 59 vsBuilder->codeAppendf("\t%s = %s;\n", vsRectName, inRect.c_str()); |
| 60 | 60 |
| 61 GrGLGPFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder
(); | 61 GrGLProcessorFragmentShaderBuilder* fsBuilder = builder->getFragment
ShaderBuilder(); |
| 62 // TODO: compute all these offsets, spans, and scales in the VS | 62 // 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); | 63 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); | 64 fsBuilder->codeAppendf("\tfloat insetH = min(1.0, %s.w) - 0.5;\n", f
sRectName); |
| 65 fsBuilder->codeAppend("\tfloat outset = 0.5;\n"); | 65 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 | 66 // 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. | 67 // < 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"); | 68 fsBuilder->codeAppend("\tfloat spanW = insetW + outset;\n"); |
| 69 fsBuilder->codeAppend("\tfloat spanH = insetH + outset;\n"); | 69 fsBuilder->codeAppend("\tfloat spanH = insetH + outset;\n"); |
| 70 // For rects < 1 pixel wide or tall, these scale factors are used to
cap the maximum | 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 | 71 // value of coverage that is used. In other words it is the coverage
that is |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 | 160 |
| 161 virtual const GrBackendGeometryProcessorFactory& getFactory() const SK_OVERR
IDE { | 161 virtual const GrBackendGeometryProcessorFactory& getFactory() const SK_OVERR
IDE { |
| 162 return GrTBackendGeometryProcessorFactory<GrRectEffect>::getInstance(); | 162 return GrTBackendGeometryProcessorFactory<GrRectEffect>::getInstance(); |
| 163 } | 163 } |
| 164 | 164 |
| 165 class GLProcessor : public GrGLGeometryProcessor { | 165 class GLProcessor : public GrGLGeometryProcessor { |
| 166 public: | 166 public: |
| 167 GLProcessor(const GrBackendProcessorFactory& factory, const GrProcessor&
) | 167 GLProcessor(const GrBackendProcessorFactory& factory, const GrProcessor&
) |
| 168 : INHERITED (factory) {} | 168 : INHERITED (factory) {} |
| 169 | 169 |
| 170 virtual void emitCode(GrGLGPBuilder* builder, | 170 virtual void emitCode(GrGLFullProgramBuilder* builder, |
| 171 const GrGeometryProcessor& geometryProcessor, | 171 const GrGeometryProcessor& geometryProcessor, |
| 172 const GrProcessorKey& key, | 172 const GrProcessorKey& key, |
| 173 const char* outputColor, | 173 const char* outputColor, |
| 174 const char* inputColor, | 174 const char* inputColor, |
| 175 const TransformedCoordsArray&, | 175 const TransformedCoordsArray&, |
| 176 const TextureSamplerArray& samplers) SK_OVERRIDE { | 176 const TextureSamplerArray& samplers) SK_OVERRIDE { |
| 177 // setup the varying for the center point and the unit vector | 177 // setup the varying for the center point and the unit vector |
| 178 // that points down the height of the rect | 178 // that points down the height of the rect |
| 179 const char *vsRectEdgeName, *fsRectEdgeName; | 179 const char *vsRectEdgeName, *fsRectEdgeName; |
| 180 builder->addVarying(kVec4f_GrSLType, "RectEdge", | 180 builder->addVarying(kVec4f_GrSLType, "RectEdge", |
| 181 &vsRectEdgeName, &fsRectEdgeName); | 181 &vsRectEdgeName, &fsRectEdgeName); |
| 182 | 182 |
| 183 const GrRectEffect& rectEffect = geometryProcessor.cast<GrRectEffect
>(); | 183 const GrRectEffect& rectEffect = geometryProcessor.cast<GrRectEffect
>(); |
| 184 GrGLVertexBuilder* vsBuilder = builder->getVertexShaderBuilder(); | 184 GrGLVertexShaderBuilder* vsBuilder = builder->getVertexShaderBuilder
(); |
| 185 vsBuilder->codeAppendf("%s = %s;", vsRectEdgeName, rectEffect.inRect
Edge().c_str()); | 185 vsBuilder->codeAppendf("%s = %s;", vsRectEdgeName, rectEffect.inRect
Edge().c_str()); |
| 186 | 186 |
| 187 // setup the varying for width/2+.5 and height/2+.5 | 187 // setup the varying for width/2+.5 and height/2+.5 |
| 188 const char *vsWidthHeightName, *fsWidthHeightName; | 188 const char *vsWidthHeightName, *fsWidthHeightName; |
| 189 builder->addVarying(kVec2f_GrSLType, "WidthHeight", | 189 builder->addVarying(kVec2f_GrSLType, "WidthHeight", |
| 190 &vsWidthHeightName, &fsWidthHeightName); | 190 &vsWidthHeightName, &fsWidthHeightName); |
| 191 vsBuilder->codeAppendf("%s = %s;", | 191 vsBuilder->codeAppendf("%s = %s;", |
| 192 vsWidthHeightName, | 192 vsWidthHeightName, |
| 193 rectEffect.inWidthHeight().c_str()); | 193 rectEffect.inWidthHeight().c_str()); |
| 194 | 194 |
| 195 GrGLGPFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder
(); | 195 GrGLProcessorFragmentShaderBuilder* fsBuilder = builder->getFragment
ShaderBuilder(); |
| 196 // TODO: compute all these offsets, spans, and scales in the VS | 196 // TODO: compute all these offsets, spans, and scales in the VS |
| 197 fsBuilder->codeAppendf("\tfloat insetW = min(1.0, %s.x) - 0.5;\n", f
sWidthHeightName); | 197 fsBuilder->codeAppendf("\tfloat insetW = min(1.0, %s.x) - 0.5;\n", f
sWidthHeightName); |
| 198 fsBuilder->codeAppendf("\tfloat insetH = min(1.0, %s.y) - 0.5;\n", f
sWidthHeightName); | 198 fsBuilder->codeAppendf("\tfloat insetH = min(1.0, %s.y) - 0.5;\n", f
sWidthHeightName); |
| 199 fsBuilder->codeAppend("\tfloat outset = 0.5;\n"); | 199 fsBuilder->codeAppend("\tfloat outset = 0.5;\n"); |
| 200 // For rects > 1 pixel wide and tall the span's are noops (i.e., 1.0
). For rects | 200 // For rects > 1 pixel wide and tall the span's are noops (i.e., 1.0
). For rects |
| 201 // < 1 pixel wide or tall they serve to normalize the < 1 ramp to a
0 .. 1 range. | 201 // < 1 pixel wide or tall they serve to normalize the < 1 ramp to a
0 .. 1 range. |
| 202 fsBuilder->codeAppend("\tfloat spanW = insetW + outset;\n"); | 202 fsBuilder->codeAppend("\tfloat spanW = insetW + outset;\n"); |
| 203 fsBuilder->codeAppend("\tfloat spanH = insetH + outset;\n"); | 203 fsBuilder->codeAppend("\tfloat spanH = insetH + outset;\n"); |
| 204 // For rects < 1 pixel wide or tall, these scale factors are used to
cap the maximum | 204 // For rects < 1 pixel wide or tall, these scale factors are used to
cap the maximum |
| 205 // value of coverage that is used. In other words it is the coverage
that is | 205 // value of coverage that is used. In other words it is the coverage
that is |
| (...skipping 757 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 |