| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 "GrConvexPolyEffect.h" | 8 #include "GrConvexPolyEffect.h" |
| 9 | 9 |
| 10 #include "gl/GrGLEffect.h" | 10 #include "gl/GrGLEffect.h" |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 } | 84 } |
| 85 | 85 |
| 86 ////////////////////////////////////////////////////////////////////////////// | 86 ////////////////////////////////////////////////////////////////////////////// |
| 87 | 87 |
| 88 class GLAARectEffect : public GrGLEffect { | 88 class GLAARectEffect : public GrGLEffect { |
| 89 public: | 89 public: |
| 90 GLAARectEffect(const GrBackendEffectFactory&, const GrDrawEffect&); | 90 GLAARectEffect(const GrBackendEffectFactory&, const GrDrawEffect&); |
| 91 | 91 |
| 92 virtual void emitCode(GrGLShaderBuilder* builder, | 92 virtual void emitCode(GrGLShaderBuilder* builder, |
| 93 const GrDrawEffect& drawEffect, | 93 const GrDrawEffect& drawEffect, |
| 94 EffectKey key, | 94 const GrEffectKey& key, |
| 95 const char* outputColor, | 95 const char* outputColor, |
| 96 const char* inputColor, | 96 const char* inputColor, |
| 97 const TransformedCoordsArray&, | 97 const TransformedCoordsArray&, |
| 98 const TextureSamplerArray&) SK_OVERRIDE; | 98 const TextureSamplerArray&) SK_OVERRIDE; |
| 99 | 99 |
| 100 static inline EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&); | 100 static inline void GenKey(const GrDrawEffect&, const GrGLCaps&, GrEffectKeyB
uilder*); |
| 101 | 101 |
| 102 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVER
RIDE; | 102 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVER
RIDE; |
| 103 | 103 |
| 104 private: | 104 private: |
| 105 GrGLUniformManager::UniformHandle fRectUniform; | 105 GrGLUniformManager::UniformHandle fRectUniform; |
| 106 SkRect fPrevRect; | 106 SkRect fPrevRect; |
| 107 typedef GrGLEffect INHERITED; | 107 typedef GrGLEffect INHERITED; |
| 108 }; | 108 }; |
| 109 | 109 |
| 110 GLAARectEffect::GLAARectEffect(const GrBackendEffectFactory& factory, | 110 GLAARectEffect::GLAARectEffect(const GrBackendEffectFactory& factory, |
| 111 const GrDrawEffect& drawEffect) | 111 const GrDrawEffect& drawEffect) |
| 112 : INHERITED (factory) { | 112 : INHERITED (factory) { |
| 113 fPrevRect.fLeft = SK_ScalarNaN; | 113 fPrevRect.fLeft = SK_ScalarNaN; |
| 114 } | 114 } |
| 115 | 115 |
| 116 void GLAARectEffect::emitCode(GrGLShaderBuilder* builder, | 116 void GLAARectEffect::emitCode(GrGLShaderBuilder* builder, |
| 117 const GrDrawEffect& drawEffect, | 117 const GrDrawEffect& drawEffect, |
| 118 EffectKey key, | 118 const GrEffectKey& key, |
| 119 const char* outputColor, | 119 const char* outputColor, |
| 120 const char* inputColor, | 120 const char* inputColor, |
| 121 const TransformedCoordsArray&, | 121 const TransformedCoordsArray&, |
| 122 const TextureSamplerArray& samplers) { | 122 const TextureSamplerArray& samplers) { |
| 123 const AARectEffect& aare = drawEffect.castEffect<AARectEffect>(); | 123 const AARectEffect& aare = drawEffect.castEffect<AARectEffect>(); |
| 124 const char *rectName; | 124 const char *rectName; |
| 125 // The rect uniform's xyzw refer to (left + 0.5, top + 0.5, right - 0.5, bot
tom - 0.5), | 125 // The rect uniform's xyzw refer to (left + 0.5, top + 0.5, right - 0.5, bot
tom - 0.5), |
| 126 // respectively. | 126 // respectively. |
| 127 fRectUniform = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility, | 127 fRectUniform = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility, |
| 128 kVec4f_GrSLType, | 128 kVec4f_GrSLType, |
| (...skipping 29 matching lines...) Expand all Loading... |
| 158 void GLAARectEffect::setData(const GrGLUniformManager& uman, const GrDrawEffect&
drawEffect) { | 158 void GLAARectEffect::setData(const GrGLUniformManager& uman, const GrDrawEffect&
drawEffect) { |
| 159 const AARectEffect& aare = drawEffect.castEffect<AARectEffect>(); | 159 const AARectEffect& aare = drawEffect.castEffect<AARectEffect>(); |
| 160 const SkRect& rect = aare.getRect(); | 160 const SkRect& rect = aare.getRect(); |
| 161 if (rect != fPrevRect) { | 161 if (rect != fPrevRect) { |
| 162 uman.set4f(fRectUniform, rect.fLeft + 0.5f, rect.fTop + 0.5f, | 162 uman.set4f(fRectUniform, rect.fLeft + 0.5f, rect.fTop + 0.5f, |
| 163 rect.fRight - 0.5f, rect.fBottom - 0.5f); | 163 rect.fRight - 0.5f, rect.fBottom - 0.5f); |
| 164 fPrevRect = rect; | 164 fPrevRect = rect; |
| 165 } | 165 } |
| 166 } | 166 } |
| 167 | 167 |
| 168 GrGLEffect::EffectKey GLAARectEffect::GenKey(const GrDrawEffect& drawEffect, con
st GrGLCaps&) { | 168 void GLAARectEffect::GenKey(const GrDrawEffect& drawEffect, const GrGLCaps&, |
| 169 GrEffectKeyBuilder* b) { |
| 169 const AARectEffect& aare = drawEffect.castEffect<AARectEffect>(); | 170 const AARectEffect& aare = drawEffect.castEffect<AARectEffect>(); |
| 170 return aare.getEdgeType(); | 171 b->add32(aare.getEdgeType()); |
| 171 } | 172 } |
| 172 | 173 |
| 173 const GrBackendEffectFactory& AARectEffect::getFactory() const { | 174 const GrBackendEffectFactory& AARectEffect::getFactory() const { |
| 174 return GrTBackendEffectFactory<AARectEffect>::getInstance(); | 175 return GrTBackendEffectFactory<AARectEffect>::getInstance(); |
| 175 } | 176 } |
| 176 | 177 |
| 177 ////////////////////////////////////////////////////////////////////////////// | 178 ////////////////////////////////////////////////////////////////////////////// |
| 178 | 179 |
| 179 class GrGLConvexPolyEffect : public GrGLEffect { | 180 class GrGLConvexPolyEffect : public GrGLEffect { |
| 180 public: | 181 public: |
| 181 GrGLConvexPolyEffect(const GrBackendEffectFactory&, const GrDrawEffect&); | 182 GrGLConvexPolyEffect(const GrBackendEffectFactory&, const GrDrawEffect&); |
| 182 | 183 |
| 183 virtual void emitCode(GrGLShaderBuilder* builder, | 184 virtual void emitCode(GrGLShaderBuilder* builder, |
| 184 const GrDrawEffect& drawEffect, | 185 const GrDrawEffect& drawEffect, |
| 185 EffectKey key, | 186 const GrEffectKey& key, |
| 186 const char* outputColor, | 187 const char* outputColor, |
| 187 const char* inputColor, | 188 const char* inputColor, |
| 188 const TransformedCoordsArray&, | 189 const TransformedCoordsArray&, |
| 189 const TextureSamplerArray&) SK_OVERRIDE; | 190 const TextureSamplerArray&) SK_OVERRIDE; |
| 190 | 191 |
| 191 static inline EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&); | 192 static inline void GenKey(const GrDrawEffect&, const GrGLCaps&, GrEffectKeyB
uilder*); |
| 192 | 193 |
| 193 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVER
RIDE; | 194 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVER
RIDE; |
| 194 | 195 |
| 195 private: | 196 private: |
| 196 GrGLUniformManager::UniformHandle fEdgeUniform; | 197 GrGLUniformManager::UniformHandle fEdgeUniform; |
| 197 SkScalar fPrevEdges[3 * GrConvexPolyEffect::kMaxE
dges]; | 198 SkScalar fPrevEdges[3 * GrConvexPolyEffect::kMaxE
dges]; |
| 198 typedef GrGLEffect INHERITED; | 199 typedef GrGLEffect INHERITED; |
| 199 }; | 200 }; |
| 200 | 201 |
| 201 GrGLConvexPolyEffect::GrGLConvexPolyEffect(const GrBackendEffectFactory& factory
, | 202 GrGLConvexPolyEffect::GrGLConvexPolyEffect(const GrBackendEffectFactory& factory
, |
| 202 const GrDrawEffect& drawEffect) | 203 const GrDrawEffect& drawEffect) |
| 203 : INHERITED (factory) { | 204 : INHERITED (factory) { |
| 204 fPrevEdges[0] = SK_ScalarNaN; | 205 fPrevEdges[0] = SK_ScalarNaN; |
| 205 } | 206 } |
| 206 | 207 |
| 207 void GrGLConvexPolyEffect::emitCode(GrGLShaderBuilder* builder, | 208 void GrGLConvexPolyEffect::emitCode(GrGLShaderBuilder* builder, |
| 208 const GrDrawEffect& drawEffect, | 209 const GrDrawEffect& drawEffect, |
| 209 EffectKey key, | 210 const GrEffectKey& key, |
| 210 const char* outputColor, | 211 const char* outputColor, |
| 211 const char* inputColor, | 212 const char* inputColor, |
| 212 const TransformedCoordsArray&, | 213 const TransformedCoordsArray&, |
| 213 const TextureSamplerArray& samplers) { | 214 const TextureSamplerArray& samplers) { |
| 214 const GrConvexPolyEffect& cpe = drawEffect.castEffect<GrConvexPolyEffect>(); | 215 const GrConvexPolyEffect& cpe = drawEffect.castEffect<GrConvexPolyEffect>(); |
| 215 | 216 |
| 216 const char *edgeArrayName; | 217 const char *edgeArrayName; |
| 217 fEdgeUniform = builder->addUniformArray(GrGLShaderBuilder::kFragment_Visibil
ity, | 218 fEdgeUniform = builder->addUniformArray(GrGLShaderBuilder::kFragment_Visibil
ity, |
| 218 kVec3f_GrSLType, | 219 kVec3f_GrSLType, |
| 219 "edges", | 220 "edges", |
| (...skipping 27 matching lines...) Expand all Loading... |
| 247 | 248 |
| 248 void GrGLConvexPolyEffect::setData(const GrGLUniformManager& uman, const GrDrawE
ffect& drawEffect) { | 249 void GrGLConvexPolyEffect::setData(const GrGLUniformManager& uman, const GrDrawE
ffect& drawEffect) { |
| 249 const GrConvexPolyEffect& cpe = drawEffect.castEffect<GrConvexPolyEffect>(); | 250 const GrConvexPolyEffect& cpe = drawEffect.castEffect<GrConvexPolyEffect>(); |
| 250 size_t byteSize = 3 * cpe.getEdgeCount() * sizeof(SkScalar); | 251 size_t byteSize = 3 * cpe.getEdgeCount() * sizeof(SkScalar); |
| 251 if (0 != memcmp(fPrevEdges, cpe.getEdges(), byteSize)) { | 252 if (0 != memcmp(fPrevEdges, cpe.getEdges(), byteSize)) { |
| 252 uman.set3fv(fEdgeUniform, cpe.getEdgeCount(), cpe.getEdges()); | 253 uman.set3fv(fEdgeUniform, cpe.getEdgeCount(), cpe.getEdges()); |
| 253 memcpy(fPrevEdges, cpe.getEdges(), byteSize); | 254 memcpy(fPrevEdges, cpe.getEdges(), byteSize); |
| 254 } | 255 } |
| 255 } | 256 } |
| 256 | 257 |
| 257 GrGLEffect::EffectKey GrGLConvexPolyEffect::GenKey(const GrDrawEffect& drawEffec
t, | 258 void GrGLConvexPolyEffect::GenKey(const GrDrawEffect& drawEffect, const GrGLCaps
&, |
| 258 const GrGLCaps&) { | 259 GrEffectKeyBuilder* b) { |
| 259 const GrConvexPolyEffect& cpe = drawEffect.castEffect<GrConvexPolyEffect>(); | 260 const GrConvexPolyEffect& cpe = drawEffect.castEffect<GrConvexPolyEffect>(); |
| 260 GR_STATIC_ASSERT(kGrEffectEdgeTypeCnt <= 8); | 261 GR_STATIC_ASSERT(kGrEffectEdgeTypeCnt <= 8); |
| 261 return (cpe.getEdgeCount() << 3) | cpe.getEdgeType(); | 262 uint32_t key = (cpe.getEdgeCount() << 3) | cpe.getEdgeType(); |
| 263 b->add32(key); |
| 262 } | 264 } |
| 263 | 265 |
| 264 ////////////////////////////////////////////////////////////////////////////// | 266 ////////////////////////////////////////////////////////////////////////////// |
| 265 | 267 |
| 266 GrEffect* GrConvexPolyEffect::Create(GrEffectEdgeType type, const SkPath& path, | 268 GrEffect* GrConvexPolyEffect::Create(GrEffectEdgeType type, const SkPath& path, |
| 267 const SkVector* offset) { | 269 const SkVector* offset) { |
| 268 if (kHairlineAA_GrEffectEdgeType == type) { | 270 if (kHairlineAA_GrEffectEdgeType == type) { |
| 269 return NULL; | 271 return NULL; |
| 270 } | 272 } |
| 271 if (path.getSegmentMasks() != SkPath::kLine_SegmentMask || | 273 if (path.getSegmentMasks() != SkPath::kLine_SegmentMask || |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 } | 369 } |
| 368 | 370 |
| 369 GrEffect* effect; | 371 GrEffect* effect; |
| 370 do { | 372 do { |
| 371 GrEffectEdgeType edgeType = static_cast<GrEffectEdgeType>( | 373 GrEffectEdgeType edgeType = static_cast<GrEffectEdgeType>( |
| 372 random->nextULessThan(kGrEffectEdgeTypeC
nt)); | 374 random->nextULessThan(kGrEffectEdgeTypeC
nt)); |
| 373 effect = GrConvexPolyEffect::Create(edgeType, count, edges); | 375 effect = GrConvexPolyEffect::Create(edgeType, count, edges); |
| 374 } while (NULL == effect); | 376 } while (NULL == effect); |
| 375 return effect; | 377 return effect; |
| 376 } | 378 } |
| OLD | NEW |