| 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 #include "GrInvariantOutput.h" | 9 #include "GrInvariantOutput.h" |
| 10 #include "SkPath.h" | 10 #include "SkPath.h" |
| 11 #include "gl/GrGLProcessor.h" | 11 #include "gl/GrGLProcessor.h" |
| 12 #include "gl/GrGLSL.h" | 12 #include "gl/GrGLSL.h" |
| 13 #include "gl/builders/GrGLProgramBuilder.h" | 13 #include "gl/builders/GrGLProgramBuilder.h" |
| 14 | 14 |
| 15 ////////////////////////////////////////////////////////////////////////////// | 15 ////////////////////////////////////////////////////////////////////////////// |
| 16 class AARectEffect : public GrFragmentProcessor { | 16 class AARectEffect : public GrFragmentProcessor { |
| 17 public: | 17 public: |
| 18 const SkRect& getRect() const { return fRect; } | 18 const SkRect& getRect() const { return fRect; } |
| 19 | 19 |
| 20 static GrFragmentProcessor* Create(GrPrimitiveEdgeType edgeType, const SkRec
t& rect) { | 20 static GrFragmentProcessor* Create(GrPrimitiveEdgeType edgeType, const SkRec
t& rect) { |
| 21 return SkNEW_ARGS(AARectEffect, (edgeType, rect)); | 21 return SkNEW_ARGS(AARectEffect, (edgeType, rect)); |
| 22 } | 22 } |
| 23 | 23 |
| 24 GrPrimitiveEdgeType getEdgeType() const { return fEdgeType; } | 24 GrPrimitiveEdgeType getEdgeType() const { return fEdgeType; } |
| 25 | 25 |
| 26 const char* name() const override { return "AARect"; } | 26 const char* name() const override { return "AARect"; } |
| 27 | 27 |
| 28 void getGLProcessorKey(const GrGLCaps&, GrProcessorKeyBuilder*) const overri
de; | 28 void getGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const over
ride; |
| 29 | 29 |
| 30 GrGLFragmentProcessor* createGLInstance() const override; | 30 GrGLFragmentProcessor* createGLInstance() const override; |
| 31 | 31 |
| 32 private: | 32 private: |
| 33 AARectEffect(GrPrimitiveEdgeType edgeType, const SkRect& rect) | 33 AARectEffect(GrPrimitiveEdgeType edgeType, const SkRect& rect) |
| 34 : fRect(rect), fEdgeType(edgeType) { | 34 : fRect(rect), fEdgeType(edgeType) { |
| 35 this->initClassID<AARectEffect>(); | 35 this->initClassID<AARectEffect>(); |
| 36 this->setWillReadFragmentPosition(); | 36 this->setWillReadFragmentPosition(); |
| 37 } | 37 } |
| 38 | 38 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 public: | 85 public: |
| 86 GLAARectEffect(const GrProcessor&); | 86 GLAARectEffect(const GrProcessor&); |
| 87 | 87 |
| 88 virtual void emitCode(GrGLFPBuilder* builder, | 88 virtual void emitCode(GrGLFPBuilder* builder, |
| 89 const GrFragmentProcessor& fp, | 89 const GrFragmentProcessor& fp, |
| 90 const char* outputColor, | 90 const char* outputColor, |
| 91 const char* inputColor, | 91 const char* inputColor, |
| 92 const TransformedCoordsArray&, | 92 const TransformedCoordsArray&, |
| 93 const TextureSamplerArray&) override; | 93 const TextureSamplerArray&) override; |
| 94 | 94 |
| 95 static inline void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKe
yBuilder*); | 95 static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessor
KeyBuilder*); |
| 96 | 96 |
| 97 void setData(const GrGLProgramDataManager&, const GrProcessor&) override; | 97 void setData(const GrGLProgramDataManager&, const GrProcessor&) override; |
| 98 | 98 |
| 99 private: | 99 private: |
| 100 GrGLProgramDataManager::UniformHandle fRectUniform; | 100 GrGLProgramDataManager::UniformHandle fRectUniform; |
| 101 SkRect fPrevRect; | 101 SkRect fPrevRect; |
| 102 typedef GrGLFragmentProcessor INHERITED; | 102 typedef GrGLFragmentProcessor INHERITED; |
| 103 }; | 103 }; |
| 104 | 104 |
| 105 GLAARectEffect::GLAARectEffect(const GrProcessor& effect) { | 105 GLAARectEffect::GLAARectEffect(const GrProcessor& effect) { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 void GLAARectEffect::setData(const GrGLProgramDataManager& pdman, const GrProces
sor& processor) { | 153 void GLAARectEffect::setData(const GrGLProgramDataManager& pdman, const GrProces
sor& processor) { |
| 154 const AARectEffect& aare = processor.cast<AARectEffect>(); | 154 const AARectEffect& aare = processor.cast<AARectEffect>(); |
| 155 const SkRect& rect = aare.getRect(); | 155 const SkRect& rect = aare.getRect(); |
| 156 if (rect != fPrevRect) { | 156 if (rect != fPrevRect) { |
| 157 pdman.set4f(fRectUniform, rect.fLeft + 0.5f, rect.fTop + 0.5f, | 157 pdman.set4f(fRectUniform, rect.fLeft + 0.5f, rect.fTop + 0.5f, |
| 158 rect.fRight - 0.5f, rect.fBottom - 0.5f); | 158 rect.fRight - 0.5f, rect.fBottom - 0.5f); |
| 159 fPrevRect = rect; | 159 fPrevRect = rect; |
| 160 } | 160 } |
| 161 } | 161 } |
| 162 | 162 |
| 163 void GLAARectEffect::GenKey(const GrProcessor& processor, const GrGLCaps&, | 163 void GLAARectEffect::GenKey(const GrProcessor& processor, const GrGLSLCaps&, |
| 164 GrProcessorKeyBuilder* b) { | 164 GrProcessorKeyBuilder* b) { |
| 165 const AARectEffect& aare = processor.cast<AARectEffect>(); | 165 const AARectEffect& aare = processor.cast<AARectEffect>(); |
| 166 b->add32(aare.getEdgeType()); | 166 b->add32(aare.getEdgeType()); |
| 167 } | 167 } |
| 168 | 168 |
| 169 void AARectEffect::getGLProcessorKey(const GrGLCaps& caps, GrProcessorKeyBuilder
* b) const { | 169 void AARectEffect::getGLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuild
er* b) const { |
| 170 GLAARectEffect::GenKey(*this, caps, b); | 170 GLAARectEffect::GenKey(*this, caps, b); |
| 171 } | 171 } |
| 172 | 172 |
| 173 GrGLFragmentProcessor* AARectEffect::createGLInstance() const { | 173 GrGLFragmentProcessor* AARectEffect::createGLInstance() const { |
| 174 return SkNEW_ARGS(GLAARectEffect, (*this)); | 174 return SkNEW_ARGS(GLAARectEffect, (*this)); |
| 175 } | 175 } |
| 176 | 176 |
| 177 ////////////////////////////////////////////////////////////////////////////// | 177 ////////////////////////////////////////////////////////////////////////////// |
| 178 | 178 |
| 179 class GrGLConvexPolyEffect : public GrGLFragmentProcessor { | 179 class GrGLConvexPolyEffect : public GrGLFragmentProcessor { |
| 180 public: | 180 public: |
| 181 GrGLConvexPolyEffect(const GrProcessor&); | 181 GrGLConvexPolyEffect(const GrProcessor&); |
| 182 | 182 |
| 183 virtual void emitCode(GrGLFPBuilder* builder, | 183 virtual void emitCode(GrGLFPBuilder* builder, |
| 184 const GrFragmentProcessor& fp, | 184 const GrFragmentProcessor& fp, |
| 185 const char* outputColor, | 185 const char* outputColor, |
| 186 const char* inputColor, | 186 const char* inputColor, |
| 187 const TransformedCoordsArray&, | 187 const TransformedCoordsArray&, |
| 188 const TextureSamplerArray&) override; | 188 const TextureSamplerArray&) override; |
| 189 | 189 |
| 190 static inline void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKe
yBuilder*); | 190 static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessor
KeyBuilder*); |
| 191 | 191 |
| 192 void setData(const GrGLProgramDataManager&, const GrProcessor&) override; | 192 void setData(const GrGLProgramDataManager&, const GrProcessor&) override; |
| 193 | 193 |
| 194 private: | 194 private: |
| 195 GrGLProgramDataManager::UniformHandle fEdgeUniform; | 195 GrGLProgramDataManager::UniformHandle fEdgeUniform; |
| 196 SkScalar fPrevEdges[3 * GrConvexPolyEffect::kMa
xEdges]; | 196 SkScalar fPrevEdges[3 * GrConvexPolyEffect::kMa
xEdges]; |
| 197 typedef GrGLFragmentProcessor INHERITED; | 197 typedef GrGLFragmentProcessor INHERITED; |
| 198 }; | 198 }; |
| 199 | 199 |
| 200 GrGLConvexPolyEffect::GrGLConvexPolyEffect(const GrProcessor&) { | 200 GrGLConvexPolyEffect::GrGLConvexPolyEffect(const GrProcessor&) { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 | 245 |
| 246 void GrGLConvexPolyEffect::setData(const GrGLProgramDataManager& pdman, const Gr
Processor& effect) { | 246 void GrGLConvexPolyEffect::setData(const GrGLProgramDataManager& pdman, const Gr
Processor& effect) { |
| 247 const GrConvexPolyEffect& cpe = effect.cast<GrConvexPolyEffect>(); | 247 const GrConvexPolyEffect& cpe = effect.cast<GrConvexPolyEffect>(); |
| 248 size_t byteSize = 3 * cpe.getEdgeCount() * sizeof(SkScalar); | 248 size_t byteSize = 3 * cpe.getEdgeCount() * sizeof(SkScalar); |
| 249 if (0 != memcmp(fPrevEdges, cpe.getEdges(), byteSize)) { | 249 if (0 != memcmp(fPrevEdges, cpe.getEdges(), byteSize)) { |
| 250 pdman.set3fv(fEdgeUniform, cpe.getEdgeCount(), cpe.getEdges()); | 250 pdman.set3fv(fEdgeUniform, cpe.getEdgeCount(), cpe.getEdges()); |
| 251 memcpy(fPrevEdges, cpe.getEdges(), byteSize); | 251 memcpy(fPrevEdges, cpe.getEdges(), byteSize); |
| 252 } | 252 } |
| 253 } | 253 } |
| 254 | 254 |
| 255 void GrGLConvexPolyEffect::GenKey(const GrProcessor& processor, const GrGLCaps&, | 255 void GrGLConvexPolyEffect::GenKey(const GrProcessor& processor, const GrGLSLCaps
&, |
| 256 GrProcessorKeyBuilder* b) { | 256 GrProcessorKeyBuilder* b) { |
| 257 const GrConvexPolyEffect& cpe = processor.cast<GrConvexPolyEffect>(); | 257 const GrConvexPolyEffect& cpe = processor.cast<GrConvexPolyEffect>(); |
| 258 GR_STATIC_ASSERT(kGrProcessorEdgeTypeCnt <= 8); | 258 GR_STATIC_ASSERT(kGrProcessorEdgeTypeCnt <= 8); |
| 259 uint32_t key = (cpe.getEdgeCount() << 3) | cpe.getEdgeType(); | 259 uint32_t key = (cpe.getEdgeCount() << 3) | cpe.getEdgeType(); |
| 260 b->add32(key); | 260 b->add32(key); |
| 261 } | 261 } |
| 262 | 262 |
| 263 ////////////////////////////////////////////////////////////////////////////// | 263 ////////////////////////////////////////////////////////////////////////////// |
| 264 | 264 |
| 265 GrFragmentProcessor* GrConvexPolyEffect::Create(GrPrimitiveEdgeType type, const
SkPath& path, | 265 GrFragmentProcessor* GrConvexPolyEffect::Create(GrPrimitiveEdgeType type, const
SkPath& path, |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 } | 319 } |
| 320 return AARectEffect::Create(edgeType, rect); | 320 return AARectEffect::Create(edgeType, rect); |
| 321 } | 321 } |
| 322 | 322 |
| 323 GrConvexPolyEffect::~GrConvexPolyEffect() {} | 323 GrConvexPolyEffect::~GrConvexPolyEffect() {} |
| 324 | 324 |
| 325 void GrConvexPolyEffect::onComputeInvariantOutput(GrInvariantOutput* inout) cons
t { | 325 void GrConvexPolyEffect::onComputeInvariantOutput(GrInvariantOutput* inout) cons
t { |
| 326 inout->mulByUnknownSingleComponent(); | 326 inout->mulByUnknownSingleComponent(); |
| 327 } | 327 } |
| 328 | 328 |
| 329 void GrConvexPolyEffect::getGLProcessorKey(const GrGLCaps& caps, | 329 void GrConvexPolyEffect::getGLProcessorKey(const GrGLSLCaps& caps, |
| 330 GrProcessorKeyBuilder* b) const { | 330 GrProcessorKeyBuilder* b) const { |
| 331 GrGLConvexPolyEffect::GenKey(*this, caps, b); | 331 GrGLConvexPolyEffect::GenKey(*this, caps, b); |
| 332 } | 332 } |
| 333 | 333 |
| 334 GrGLFragmentProcessor* GrConvexPolyEffect::createGLInstance() const { | 334 GrGLFragmentProcessor* GrConvexPolyEffect::createGLInstance() const { |
| 335 return SkNEW_ARGS(GrGLConvexPolyEffect, (*this)); | 335 return SkNEW_ARGS(GrGLConvexPolyEffect, (*this)); |
| 336 } | 336 } |
| 337 | 337 |
| 338 GrConvexPolyEffect::GrConvexPolyEffect(GrPrimitiveEdgeType edgeType, int n, cons
t SkScalar edges[]) | 338 GrConvexPolyEffect::GrConvexPolyEffect(GrPrimitiveEdgeType edgeType, int n, cons
t SkScalar edges[]) |
| 339 : fEdgeType(edgeType) | 339 : fEdgeType(edgeType) |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 } | 372 } |
| 373 | 373 |
| 374 GrFragmentProcessor* fp; | 374 GrFragmentProcessor* fp; |
| 375 do { | 375 do { |
| 376 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>( | 376 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>( |
| 377 random->nextULessThan(kGrProcessorEdgeTy
peCnt)); | 377 random->nextULessThan(kGrProcessorEdgeTy
peCnt)); |
| 378 fp = GrConvexPolyEffect::Create(edgeType, count, edges); | 378 fp = GrConvexPolyEffect::Create(edgeType, count, edges); |
| 379 } while (NULL == fp); | 379 } while (NULL == fp); |
| 380 return fp; | 380 return fp; |
| 381 } | 381 } |
| OLD | NEW |