| 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/GrGLEffect.h" | 10 #include "gl/GrGLEffect.h" |
| 11 #include "gl/GrGLVertexEffect.h" |
| 11 #include "GrTBackendEffectFactory.h" | 12 #include "GrTBackendEffectFactory.h" |
| 12 #include "SkColorPriv.h" | 13 #include "SkColorPriv.h" |
| 13 #include "effects/GrVertexEffect.h" | 14 #include "effects/GrVertexEffect.h" |
| 14 | 15 |
| 15 SK_DEFINE_INST_COUNT(GrAARectRenderer) | 16 SK_DEFINE_INST_COUNT(GrAARectRenderer) |
| 16 | 17 |
| 17 /////////////////////////////////////////////////////////////////////////////// | 18 /////////////////////////////////////////////////////////////////////////////// |
| 18 class GrGLAlignedRectEffect; | 19 class GrGLAlignedRectEffect; |
| 19 | 20 |
| 20 // Axis Aligned special case | 21 // Axis Aligned special case |
| (...skipping 11 matching lines...) Expand all Loading... |
| 32 | 33 |
| 33 virtual void getConstantColorComponents(GrColor* color, | 34 virtual void getConstantColorComponents(GrColor* color, |
| 34 uint32_t* validFlags) const SK_OVERR
IDE { | 35 uint32_t* validFlags) const SK_OVERR
IDE { |
| 35 *validFlags = 0; | 36 *validFlags = 0; |
| 36 } | 37 } |
| 37 | 38 |
| 38 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE { | 39 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE { |
| 39 return GrTBackendEffectFactory<GrAlignedRectEffect>::getInstance(); | 40 return GrTBackendEffectFactory<GrAlignedRectEffect>::getInstance(); |
| 40 } | 41 } |
| 41 | 42 |
| 42 class GLEffect : public GrGLEffect { | 43 class GLEffect : public GrGLVertexEffect { |
| 43 public: | 44 public: |
| 44 GLEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&) | 45 GLEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&) |
| 45 : INHERITED (factory) {} | 46 : INHERITED (factory) {} |
| 46 | 47 |
| 47 virtual void emitCode(GrGLShaderBuilder* builder, | 48 virtual void emitCode(GrGLFullShaderBuilder* builder, |
| 48 const GrDrawEffect& drawEffect, | 49 const GrDrawEffect& drawEffect, |
| 49 EffectKey key, | 50 EffectKey key, |
| 50 const char* outputColor, | 51 const char* outputColor, |
| 51 const char* inputColor, | 52 const char* inputColor, |
| 52 const TransformedCoordsArray&, | 53 const TransformedCoordsArray&, |
| 53 const TextureSamplerArray& samplers) SK_OVERRIDE { | 54 const TextureSamplerArray& samplers) SK_OVERRIDE { |
| 54 GrGLShaderBuilder::VertexBuilder* vertexBuilder = builder->getVertex
Builder(); | |
| 55 SkASSERT(NULL != vertexBuilder); | |
| 56 | |
| 57 // setup the varying for the Axis aligned rect effect | 55 // setup the varying for the Axis aligned rect effect |
| 58 // xy -> interpolated offset | 56 // xy -> interpolated offset |
| 59 // zw -> w/2+0.5, h/2+0.5 | 57 // zw -> w/2+0.5, h/2+0.5 |
| 60 const char *vsRectName, *fsRectName; | 58 const char *vsRectName, *fsRectName; |
| 61 vertexBuilder->addVarying(kVec4f_GrSLType, "Rect", &vsRectName, &fsR
ectName); | 59 builder->addVarying(kVec4f_GrSLType, "Rect", &vsRectName, &fsRectNam
e); |
| 62 const SkString* attr0Name = | 60 const SkString* attr0Name = |
| 63 vertexBuilder->getEffectAttributeName(drawEffect.getVertexAttrib
Indices()[0]); | 61 builder->getEffectAttributeName(drawEffect.getVertexAttribIndice
s()[0]); |
| 64 vertexBuilder->vsCodeAppendf("\t%s = %s;\n", vsRectName, attr0Name->
c_str()); | 62 builder->vsCodeAppendf("\t%s = %s;\n", vsRectName, attr0Name->c_str(
)); |
| 65 | 63 |
| 66 // TODO: compute all these offsets, spans, and scales in the VS | 64 // TODO: compute all these offsets, spans, and scales in the VS |
| 67 builder->fsCodeAppendf("\tfloat insetW = min(1.0, %s.z) - 0.5;\n", f
sRectName); | 65 builder->fsCodeAppendf("\tfloat insetW = min(1.0, %s.z) - 0.5;\n", f
sRectName); |
| 68 builder->fsCodeAppendf("\tfloat insetH = min(1.0, %s.w) - 0.5;\n", f
sRectName); | 66 builder->fsCodeAppendf("\tfloat insetH = min(1.0, %s.w) - 0.5;\n", f
sRectName); |
| 69 builder->fsCodeAppend("\tfloat outset = 0.5;\n"); | 67 builder->fsCodeAppend("\tfloat outset = 0.5;\n"); |
| 70 // For rects > 1 pixel wide and tall the span's are noops (i.e., 1.0
). For rects | 68 // For rects > 1 pixel wide and tall the span's are noops (i.e., 1.0
). For rects |
| 71 // < 1 pixel wide or tall they serve to normalize the < 1 ramp to a
0 .. 1 range. | 69 // < 1 pixel wide or tall they serve to normalize the < 1 ramp to a
0 .. 1 range. |
| 72 builder->fsCodeAppend("\tfloat spanW = insetW + outset;\n"); | 70 builder->fsCodeAppend("\tfloat spanW = insetW + outset;\n"); |
| 73 builder->fsCodeAppend("\tfloat spanH = insetH + outset;\n"); | 71 builder->fsCodeAppend("\tfloat spanH = insetH + outset;\n"); |
| 74 // For rects < 1 pixel wide or tall, these scale factors are used to
cap the maximum | 72 // For rects < 1 pixel wide or tall, these scale factors are used to
cap the maximum |
| (...skipping 16 matching lines...) Expand all Loading... |
| 91 builder->fsCodeAppendf("\t%s = %s;\n", outputColor, modulate.c_str()
); | 89 builder->fsCodeAppendf("\t%s = %s;\n", outputColor, modulate.c_str()
); |
| 92 } | 90 } |
| 93 | 91 |
| 94 static inline EffectKey GenKey(const GrDrawEffect& drawEffect, const GrG
LCaps&) { | 92 static inline EffectKey GenKey(const GrDrawEffect& drawEffect, const GrG
LCaps&) { |
| 95 return 0; | 93 return 0; |
| 96 } | 94 } |
| 97 | 95 |
| 98 virtual void setData(const GrGLUniformManager& uman, const GrDrawEffect&
) SK_OVERRIDE {} | 96 virtual void setData(const GrGLUniformManager& uman, const GrDrawEffect&
) SK_OVERRIDE {} |
| 99 | 97 |
| 100 private: | 98 private: |
| 101 typedef GrGLEffect INHERITED; | 99 typedef GrGLVertexEffect INHERITED; |
| 102 }; | 100 }; |
| 103 | 101 |
| 104 | 102 |
| 105 private: | 103 private: |
| 106 GrAlignedRectEffect() : GrVertexEffect() { | 104 GrAlignedRectEffect() : GrVertexEffect() { |
| 107 this->addVertexAttrib(kVec4f_GrSLType); | 105 this->addVertexAttrib(kVec4f_GrSLType); |
| 108 } | 106 } |
| 109 | 107 |
| 110 virtual bool onIsEqual(const GrEffect&) const SK_OVERRIDE { return true; } | 108 virtual bool onIsEqual(const GrEffect&) const SK_OVERRIDE { return true; } |
| 111 | 109 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 | 151 |
| 154 virtual void getConstantColorComponents(GrColor* color, | 152 virtual void getConstantColorComponents(GrColor* color, |
| 155 uint32_t* validFlags) const SK_OVERR
IDE { | 153 uint32_t* validFlags) const SK_OVERR
IDE { |
| 156 *validFlags = 0; | 154 *validFlags = 0; |
| 157 } | 155 } |
| 158 | 156 |
| 159 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE { | 157 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE { |
| 160 return GrTBackendEffectFactory<GrRectEffect>::getInstance(); | 158 return GrTBackendEffectFactory<GrRectEffect>::getInstance(); |
| 161 } | 159 } |
| 162 | 160 |
| 163 class GLEffect : public GrGLEffect { | 161 class GLEffect : public GrGLVertexEffect { |
| 164 public: | 162 public: |
| 165 GLEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&) | 163 GLEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&) |
| 166 : INHERITED (factory) {} | 164 : INHERITED (factory) {} |
| 167 | 165 |
| 168 virtual void emitCode(GrGLShaderBuilder* builder, | 166 virtual void emitCode(GrGLFullShaderBuilder* builder, |
| 169 const GrDrawEffect& drawEffect, | 167 const GrDrawEffect& drawEffect, |
| 170 EffectKey key, | 168 EffectKey key, |
| 171 const char* outputColor, | 169 const char* outputColor, |
| 172 const char* inputColor, | 170 const char* inputColor, |
| 173 const TransformedCoordsArray&, | 171 const TransformedCoordsArray&, |
| 174 const TextureSamplerArray& samplers) SK_OVERRIDE { | 172 const TextureSamplerArray& samplers) SK_OVERRIDE { |
| 175 GrGLShaderBuilder::VertexBuilder* vertexBuilder = builder->getVertex
Builder(); | |
| 176 SkASSERT(NULL != vertexBuilder); | |
| 177 | |
| 178 // setup the varying for the center point and the unit vector | 173 // setup the varying for the center point and the unit vector |
| 179 // that points down the height of the rect | 174 // that points down the height of the rect |
| 180 const char *vsRectEdgeName, *fsRectEdgeName; | 175 const char *vsRectEdgeName, *fsRectEdgeName; |
| 181 vertexBuilder->addVarying(kVec4f_GrSLType, "RectEdge", | 176 builder->addVarying(kVec4f_GrSLType, "RectEdge", |
| 182 &vsRectEdgeName, &fsRectEdgeName); | 177 &vsRectEdgeName, &fsRectEdgeName); |
| 183 const SkString* attr0Name = | 178 const SkString* attr0Name = |
| 184 vertexBuilder->getEffectAttributeName(drawEffect.getVertexAttrib
Indices()[0]); | 179 builder->getEffectAttributeName(drawEffect.getVertexAttribIndice
s()[0]); |
| 185 vertexBuilder->vsCodeAppendf("\t%s = %s;\n", vsRectEdgeName, attr0Na
me->c_str()); | 180 builder->vsCodeAppendf("\t%s = %s;\n", vsRectEdgeName, attr0Name->c_
str()); |
| 186 | 181 |
| 187 // setup the varying for width/2+.5 and height/2+.5 | 182 // setup the varying for width/2+.5 and height/2+.5 |
| 188 const char *vsWidthHeightName, *fsWidthHeightName; | 183 const char *vsWidthHeightName, *fsWidthHeightName; |
| 189 vertexBuilder->addVarying(kVec2f_GrSLType, "WidthHeight", | 184 builder->addVarying(kVec2f_GrSLType, "WidthHeight", |
| 190 &vsWidthHeightName, &fsWidthHeightName); | 185 &vsWidthHeightName, &fsWidthHeightName); |
| 191 const SkString* attr1Name = | 186 const SkString* attr1Name = |
| 192 vertexBuilder->getEffectAttributeName(drawEffect.getVertexAttrib
Indices()[1]); | 187 builder->getEffectAttributeName(drawEffect.getVertexAttribIndice
s()[1]); |
| 193 vertexBuilder->vsCodeAppendf("\t%s = %s;\n", vsWidthHeightName, attr
1Name->c_str()); | 188 builder->vsCodeAppendf("\t%s = %s;\n", vsWidthHeightName, attr1Name-
>c_str()); |
| 194 | 189 |
| 195 // TODO: compute all these offsets, spans, and scales in the VS | 190 // TODO: compute all these offsets, spans, and scales in the VS |
| 196 builder->fsCodeAppendf("\tfloat insetW = min(1.0, %s.x) - 0.5;\n", f
sWidthHeightName); | 191 builder->fsCodeAppendf("\tfloat insetW = min(1.0, %s.x) - 0.5;\n", f
sWidthHeightName); |
| 197 builder->fsCodeAppendf("\tfloat insetH = min(1.0, %s.y) - 0.5;\n", f
sWidthHeightName); | 192 builder->fsCodeAppendf("\tfloat insetH = min(1.0, %s.y) - 0.5;\n", f
sWidthHeightName); |
| 198 builder->fsCodeAppend("\tfloat outset = 0.5;\n"); | 193 builder->fsCodeAppend("\tfloat outset = 0.5;\n"); |
| 199 // For rects > 1 pixel wide and tall the span's are noops (i.e., 1.0
). For rects | 194 // For rects > 1 pixel wide and tall the span's are noops (i.e., 1.0
). For rects |
| 200 // < 1 pixel wide or tall they serve to normalize the < 1 ramp to a
0 .. 1 range. | 195 // < 1 pixel wide or tall they serve to normalize the < 1 ramp to a
0 .. 1 range. |
| 201 builder->fsCodeAppend("\tfloat spanW = insetW + outset;\n"); | 196 builder->fsCodeAppend("\tfloat spanW = insetW + outset;\n"); |
| 202 builder->fsCodeAppend("\tfloat spanH = insetH + outset;\n"); | 197 builder->fsCodeAppend("\tfloat spanH = insetH + outset;\n"); |
| 203 // For rects < 1 pixel wide or tall, these scale factors are used to
cap the maximum | 198 // For rects < 1 pixel wide or tall, these scale factors are used to
cap the maximum |
| (...skipping 23 matching lines...) Expand all Loading... |
| 227 builder->fsCodeAppendf("\t%s = %s;\n", outputColor, modulate.c_str()
); | 222 builder->fsCodeAppendf("\t%s = %s;\n", outputColor, modulate.c_str()
); |
| 228 } | 223 } |
| 229 | 224 |
| 230 static inline EffectKey GenKey(const GrDrawEffect& drawEffect, const GrG
LCaps&) { | 225 static inline EffectKey GenKey(const GrDrawEffect& drawEffect, const GrG
LCaps&) { |
| 231 return 0; | 226 return 0; |
| 232 } | 227 } |
| 233 | 228 |
| 234 virtual void setData(const GrGLUniformManager& uman, const GrDrawEffect&
) SK_OVERRIDE {} | 229 virtual void setData(const GrGLUniformManager& uman, const GrDrawEffect&
) SK_OVERRIDE {} |
| 235 | 230 |
| 236 private: | 231 private: |
| 237 typedef GrGLEffect INHERITED; | 232 typedef GrGLVertexEffect INHERITED; |
| 238 }; | 233 }; |
| 239 | 234 |
| 240 | 235 |
| 241 private: | 236 private: |
| 242 GrRectEffect() : GrVertexEffect() { | 237 GrRectEffect() : GrVertexEffect() { |
| 243 this->addVertexAttrib(kVec4f_GrSLType); | 238 this->addVertexAttrib(kVec4f_GrSLType); |
| 244 this->addVertexAttrib(kVec2f_GrSLType); | 239 this->addVertexAttrib(kVec2f_GrSLType); |
| 245 this->setWillReadFragmentPosition(); | 240 this->setWillReadFragmentPosition(); |
| 246 } | 241 } |
| 247 | 242 |
| (...skipping 563 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 811 // can't call mapRect for devInside since it calls sort | 806 // can't call mapRect for devInside since it calls sort |
| 812 combinedMatrix.mapPoints((SkPoint*)&devInside, (const SkPoint*)&rects[1], 2)
; | 807 combinedMatrix.mapPoints((SkPoint*)&devInside, (const SkPoint*)&rects[1], 2)
; |
| 813 | 808 |
| 814 if (devInside.isEmpty()) { | 809 if (devInside.isEmpty()) { |
| 815 this->fillAARect(gpu, target, devOutside, SkMatrix::I(), devOutside, use
VertexCoverage); | 810 this->fillAARect(gpu, target, devOutside, SkMatrix::I(), devOutside, use
VertexCoverage); |
| 816 return; | 811 return; |
| 817 } | 812 } |
| 818 | 813 |
| 819 this->geometryStrokeAARect(gpu, target, devOutside, devInside, useVertexCove
rage); | 814 this->geometryStrokeAARect(gpu, target, devOutside, devInside, useVertexCove
rage); |
| 820 } | 815 } |
| OLD | NEW |