| 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 "SkPathPriv.h" | 10 #include "SkPathPriv.h" |
| 11 #include "gl/GrGLContext.h" | 11 #include "glsl/GrGLSLFragmentProcessor.h" |
| 12 #include "gl/GrGLFragmentProcessor.h" | |
| 13 #include "glsl/GrGLSLFragmentShaderBuilder.h" | 12 #include "glsl/GrGLSLFragmentShaderBuilder.h" |
| 14 #include "glsl/GrGLSLProgramBuilder.h" | 13 #include "glsl/GrGLSLProgramBuilder.h" |
| 15 #include "glsl/GrGLSLProgramDataManager.h" | 14 #include "glsl/GrGLSLProgramDataManager.h" |
| 16 | 15 |
| 17 ////////////////////////////////////////////////////////////////////////////// | 16 ////////////////////////////////////////////////////////////////////////////// |
| 18 class AARectEffect : public GrFragmentProcessor { | 17 class AARectEffect : public GrFragmentProcessor { |
| 19 public: | 18 public: |
| 20 const SkRect& getRect() const { return fRect; } | 19 const SkRect& getRect() const { return fRect; } |
| 21 | 20 |
| 22 static GrFragmentProcessor* Create(GrPrimitiveEdgeType edgeType, const SkRec
t& rect) { | 21 static GrFragmentProcessor* Create(GrPrimitiveEdgeType edgeType, const SkRec
t& rect) { |
| 23 return new AARectEffect(edgeType, rect); | 22 return new AARectEffect(edgeType, rect); |
| 24 } | 23 } |
| 25 | 24 |
| 26 GrPrimitiveEdgeType getEdgeType() const { return fEdgeType; } | 25 GrPrimitiveEdgeType getEdgeType() const { return fEdgeType; } |
| 27 | 26 |
| 28 const char* name() const override { return "AARect"; } | 27 const char* name() const override { return "AARect"; } |
| 29 | 28 |
| 30 void onGetGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const ov
erride; | 29 void onGetGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const ov
erride; |
| 31 | 30 |
| 32 private: | 31 private: |
| 33 AARectEffect(GrPrimitiveEdgeType edgeType, const SkRect& rect) | 32 AARectEffect(GrPrimitiveEdgeType edgeType, const SkRect& rect) |
| 34 : fRect(rect), fEdgeType(edgeType) { | 33 : fRect(rect), fEdgeType(edgeType) { |
| 35 this->initClassID<AARectEffect>(); | 34 this->initClassID<AARectEffect>(); |
| 36 this->setWillReadFragmentPosition(); | 35 this->setWillReadFragmentPosition(); |
| 37 } | 36 } |
| 38 | 37 |
| 39 GrGLFragmentProcessor* onCreateGLInstance() const override; | 38 GrGLSLFragmentProcessor* onCreateGLInstance() const override; |
| 40 | 39 |
| 41 bool onIsEqual(const GrFragmentProcessor& other) const override { | 40 bool onIsEqual(const GrFragmentProcessor& other) const override { |
| 42 const AARectEffect& aare = other.cast<AARectEffect>(); | 41 const AARectEffect& aare = other.cast<AARectEffect>(); |
| 43 return fRect == aare.fRect; | 42 return fRect == aare.fRect; |
| 44 } | 43 } |
| 45 | 44 |
| 46 void onComputeInvariantOutput(GrInvariantOutput* inout) const override { | 45 void onComputeInvariantOutput(GrInvariantOutput* inout) const override { |
| 47 if (fRect.isEmpty()) { | 46 if (fRect.isEmpty()) { |
| 48 // An empty rect will have no coverage anywhere. | 47 // An empty rect will have no coverage anywhere. |
| 49 inout->mulByKnownSingleComponent(0); | 48 inout->mulByKnownSingleComponent(0); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 73 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>( | 72 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>( |
| 74 d->fRandom->nextULessThan(kGrProcessorEdgeTypeCnt)); | 73 d->fRandom->nextULessThan(kGrProcessorEdgeTypeCnt)); |
| 75 | 74 |
| 76 fp = AARectEffect::Create(edgeType, rect); | 75 fp = AARectEffect::Create(edgeType, rect); |
| 77 } while (nullptr == fp); | 76 } while (nullptr == fp); |
| 78 return fp; | 77 return fp; |
| 79 } | 78 } |
| 80 | 79 |
| 81 ////////////////////////////////////////////////////////////////////////////// | 80 ////////////////////////////////////////////////////////////////////////////// |
| 82 | 81 |
| 83 class GLAARectEffect : public GrGLFragmentProcessor { | 82 class GLAARectEffect : public GrGLSLFragmentProcessor { |
| 84 public: | 83 public: |
| 85 GLAARectEffect(const GrProcessor&); | 84 GLAARectEffect(const GrProcessor&); |
| 86 | 85 |
| 87 virtual void emitCode(EmitArgs&) override; | 86 virtual void emitCode(EmitArgs&) override; |
| 88 | 87 |
| 89 static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessor
KeyBuilder*); | 88 static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessor
KeyBuilder*); |
| 90 | 89 |
| 91 protected: | 90 protected: |
| 92 void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override
; | 91 void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override
; |
| 93 | 92 |
| 94 private: | 93 private: |
| 95 GrGLSLProgramDataManager::UniformHandle fRectUniform; | 94 GrGLSLProgramDataManager::UniformHandle fRectUniform; |
| 96 SkRect fPrevRect; | 95 SkRect fPrevRect; |
| 97 typedef GrGLFragmentProcessor INHERITED; | 96 typedef GrGLSLFragmentProcessor INHERITED; |
| 98 }; | 97 }; |
| 99 | 98 |
| 100 GLAARectEffect::GLAARectEffect(const GrProcessor& effect) { | 99 GLAARectEffect::GLAARectEffect(const GrProcessor& effect) { |
| 101 fPrevRect.fLeft = SK_ScalarNaN; | 100 fPrevRect.fLeft = SK_ScalarNaN; |
| 102 } | 101 } |
| 103 | 102 |
| 104 void GLAARectEffect::emitCode(EmitArgs& args) { | 103 void GLAARectEffect::emitCode(EmitArgs& args) { |
| 105 const AARectEffect& aare = args.fFp.cast<AARectEffect>(); | 104 const AARectEffect& aare = args.fFp.cast<AARectEffect>(); |
| 106 const char *rectName; | 105 const char *rectName; |
| 107 // The rect uniform's xyzw refer to (left + 0.5, top + 0.5, right - 0.5, bot
tom - 0.5), | 106 // The rect uniform's xyzw refer to (left + 0.5, top + 0.5, right - 0.5, bot
tom - 0.5), |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 void GLAARectEffect::GenKey(const GrProcessor& processor, const GrGLSLCaps&, | 153 void GLAARectEffect::GenKey(const GrProcessor& processor, const GrGLSLCaps&, |
| 155 GrProcessorKeyBuilder* b) { | 154 GrProcessorKeyBuilder* b) { |
| 156 const AARectEffect& aare = processor.cast<AARectEffect>(); | 155 const AARectEffect& aare = processor.cast<AARectEffect>(); |
| 157 b->add32(aare.getEdgeType()); | 156 b->add32(aare.getEdgeType()); |
| 158 } | 157 } |
| 159 | 158 |
| 160 void AARectEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBui
lder* b) const { | 159 void AARectEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBui
lder* b) const { |
| 161 GLAARectEffect::GenKey(*this, caps, b); | 160 GLAARectEffect::GenKey(*this, caps, b); |
| 162 } | 161 } |
| 163 | 162 |
| 164 GrGLFragmentProcessor* AARectEffect::onCreateGLInstance() const { | 163 GrGLSLFragmentProcessor* AARectEffect::onCreateGLInstance() const { |
| 165 return new GLAARectEffect(*this); | 164 return new GLAARectEffect(*this); |
| 166 } | 165 } |
| 167 | 166 |
| 168 ////////////////////////////////////////////////////////////////////////////// | 167 ////////////////////////////////////////////////////////////////////////////// |
| 169 | 168 |
| 170 class GrGLConvexPolyEffect : public GrGLFragmentProcessor { | 169 class GrGLConvexPolyEffect : public GrGLSLFragmentProcessor { |
| 171 public: | 170 public: |
| 172 GrGLConvexPolyEffect(const GrProcessor&); | 171 GrGLConvexPolyEffect(const GrProcessor&); |
| 173 | 172 |
| 174 virtual void emitCode(EmitArgs&) override; | 173 virtual void emitCode(EmitArgs&) override; |
| 175 | 174 |
| 176 static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessor
KeyBuilder*); | 175 static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessor
KeyBuilder*); |
| 177 | 176 |
| 178 protected: | 177 protected: |
| 179 void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override
; | 178 void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override
; |
| 180 | 179 |
| 181 private: | 180 private: |
| 182 GrGLSLProgramDataManager::UniformHandle fEdgeUniform; | 181 GrGLSLProgramDataManager::UniformHandle fEdgeUniform; |
| 183 SkScalar fPrevEdges[3 * GrConvexPolyEffect::kMa
xEdges]; | 182 SkScalar fPrevEdges[3 * GrConvexPolyEffect::kMa
xEdges]; |
| 184 typedef GrGLFragmentProcessor INHERITED; | 183 typedef GrGLSLFragmentProcessor INHERITED; |
| 185 }; | 184 }; |
| 186 | 185 |
| 187 GrGLConvexPolyEffect::GrGLConvexPolyEffect(const GrProcessor&) { | 186 GrGLConvexPolyEffect::GrGLConvexPolyEffect(const GrProcessor&) { |
| 188 fPrevEdges[0] = SK_ScalarNaN; | 187 fPrevEdges[0] = SK_ScalarNaN; |
| 189 } | 188 } |
| 190 | 189 |
| 191 void GrGLConvexPolyEffect::emitCode(EmitArgs& args) { | 190 void GrGLConvexPolyEffect::emitCode(EmitArgs& args) { |
| 192 const GrConvexPolyEffect& cpe = args.fFp.cast<GrConvexPolyEffect>(); | 191 const GrConvexPolyEffect& cpe = args.fFp.cast<GrConvexPolyEffect>(); |
| 193 | 192 |
| 194 const char *edgeArrayName; | 193 const char *edgeArrayName; |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 | 301 |
| 303 void GrConvexPolyEffect::onComputeInvariantOutput(GrInvariantOutput* inout) cons
t { | 302 void GrConvexPolyEffect::onComputeInvariantOutput(GrInvariantOutput* inout) cons
t { |
| 304 inout->mulByUnknownSingleComponent(); | 303 inout->mulByUnknownSingleComponent(); |
| 305 } | 304 } |
| 306 | 305 |
| 307 void GrConvexPolyEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, | 306 void GrConvexPolyEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, |
| 308 GrProcessorKeyBuilder* b) const { | 307 GrProcessorKeyBuilder* b) const { |
| 309 GrGLConvexPolyEffect::GenKey(*this, caps, b); | 308 GrGLConvexPolyEffect::GenKey(*this, caps, b); |
| 310 } | 309 } |
| 311 | 310 |
| 312 GrGLFragmentProcessor* GrConvexPolyEffect::onCreateGLInstance() const { | 311 GrGLSLFragmentProcessor* GrConvexPolyEffect::onCreateGLInstance() const { |
| 313 return new GrGLConvexPolyEffect(*this); | 312 return new GrGLConvexPolyEffect(*this); |
| 314 } | 313 } |
| 315 | 314 |
| 316 GrConvexPolyEffect::GrConvexPolyEffect(GrPrimitiveEdgeType edgeType, int n, cons
t SkScalar edges[]) | 315 GrConvexPolyEffect::GrConvexPolyEffect(GrPrimitiveEdgeType edgeType, int n, cons
t SkScalar edges[]) |
| 317 : fEdgeType(edgeType) | 316 : fEdgeType(edgeType) |
| 318 , fEdgeCount(n) { | 317 , fEdgeCount(n) { |
| 319 this->initClassID<GrConvexPolyEffect>(); | 318 this->initClassID<GrConvexPolyEffect>(); |
| 320 // Factory function should have already ensured this. | 319 // Factory function should have already ensured this. |
| 321 SkASSERT(n <= kMaxEdges); | 320 SkASSERT(n <= kMaxEdges); |
| 322 memcpy(fEdges, edges, 3 * n * sizeof(SkScalar)); | 321 memcpy(fEdges, edges, 3 * n * sizeof(SkScalar)); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 347 } | 346 } |
| 348 | 347 |
| 349 GrFragmentProcessor* fp; | 348 GrFragmentProcessor* fp; |
| 350 do { | 349 do { |
| 351 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>( | 350 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>( |
| 352 d->fRandom->nextULessThan(kGrProcessorEdgeTypeCnt)); | 351 d->fRandom->nextULessThan(kGrProcessorEdgeTypeCnt)); |
| 353 fp = GrConvexPolyEffect::Create(edgeType, count, edges); | 352 fp = GrConvexPolyEffect::Create(edgeType, count, edges); |
| 354 } while (nullptr == fp); | 353 } while (nullptr == fp); |
| 355 return fp; | 354 return fp; |
| 356 } | 355 } |
| OLD | NEW |