| 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 "gl/builders/GrGLProgramBuilder.h" | |
| 9 #include "GrConvexPolyEffect.h" | 8 #include "GrConvexPolyEffect.h" |
| 10 #include "GrInvariantOutput.h" | 9 #include "GrInvariantOutput.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 "GrTBackendProcessorFactory.h" | 13 #include "gl/builders/GrGLProgramBuilder.h" |
| 14 | |
| 15 #include "SkPath.h" | |
| 16 | 14 |
| 17 ////////////////////////////////////////////////////////////////////////////// | 15 ////////////////////////////////////////////////////////////////////////////// |
| 18 class GLAARectEffect; | |
| 19 | |
| 20 class AARectEffect : public GrFragmentProcessor { | 16 class AARectEffect : public GrFragmentProcessor { |
| 21 public: | 17 public: |
| 22 typedef GLAARectEffect GLProcessor; | |
| 23 | |
| 24 const SkRect& getRect() const { return fRect; } | 18 const SkRect& getRect() const { return fRect; } |
| 25 | 19 |
| 26 static const char* Name() { return "AARect"; } | |
| 27 | |
| 28 static GrFragmentProcessor* Create(GrPrimitiveEdgeType edgeType, const SkRec
t& rect) { | 20 static GrFragmentProcessor* Create(GrPrimitiveEdgeType edgeType, const SkRec
t& rect) { |
| 29 return SkNEW_ARGS(AARectEffect, (edgeType, rect)); | 21 return SkNEW_ARGS(AARectEffect, (edgeType, rect)); |
| 30 } | 22 } |
| 31 | 23 |
| 32 GrPrimitiveEdgeType getEdgeType() const { return fEdgeType; } | 24 GrPrimitiveEdgeType getEdgeType() const { return fEdgeType; } |
| 33 | 25 |
| 34 virtual const GrBackendFragmentProcessorFactory& getFactory() const SK_OVERR
IDE; | 26 virtual const char* name() const SK_OVERRIDE { return "AARect"; } |
| 27 |
| 28 virtual void getGLProcessorKey(const GrGLCaps&, GrProcessorKeyBuilder*) cons
t SK_OVERRIDE; |
| 29 |
| 30 virtual GrGLFragmentProcessor* createGLInstance() const SK_OVERRIDE; |
| 31 |
| 32 virtual uint32_t classID() const { |
| 33 static uint32_t id = GenClassID(); |
| 34 return id; |
| 35 } |
| 35 | 36 |
| 36 private: | 37 private: |
| 37 AARectEffect(GrPrimitiveEdgeType edgeType, const SkRect& rect) : fRect(rect)
, fEdgeType(edgeType) { | 38 AARectEffect(GrPrimitiveEdgeType edgeType, const SkRect& rect) : fRect(rect)
, fEdgeType(edgeType) { |
| 38 this->setWillReadFragmentPosition(); | 39 this->setWillReadFragmentPosition(); |
| 39 } | 40 } |
| 40 | 41 |
| 41 virtual bool onIsEqual(const GrFragmentProcessor& other) const SK_OVERRIDE { | 42 virtual bool onIsEqual(const GrFragmentProcessor& other) const SK_OVERRIDE { |
| 42 const AARectEffect& aare = other.cast<AARectEffect>(); | 43 const AARectEffect& aare = other.cast<AARectEffect>(); |
| 43 return fRect == aare.fRect; | 44 return fRect == aare.fRect; |
| 44 } | 45 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 | 79 |
| 79 fp = AARectEffect::Create(edgeType, rect); | 80 fp = AARectEffect::Create(edgeType, rect); |
| 80 } while (NULL == fp); | 81 } while (NULL == fp); |
| 81 return fp; | 82 return fp; |
| 82 } | 83 } |
| 83 | 84 |
| 84 ////////////////////////////////////////////////////////////////////////////// | 85 ////////////////////////////////////////////////////////////////////////////// |
| 85 | 86 |
| 86 class GLAARectEffect : public GrGLFragmentProcessor { | 87 class GLAARectEffect : public GrGLFragmentProcessor { |
| 87 public: | 88 public: |
| 88 GLAARectEffect(const GrBackendProcessorFactory&, const GrProcessor&); | 89 GLAARectEffect(const GrProcessor&); |
| 89 | 90 |
| 90 virtual void emitCode(GrGLFPBuilder* builder, | 91 virtual void emitCode(GrGLFPBuilder* builder, |
| 91 const GrFragmentProcessor& fp, | 92 const GrFragmentProcessor& fp, |
| 92 const char* outputColor, | 93 const char* outputColor, |
| 93 const char* inputColor, | 94 const char* inputColor, |
| 94 const TransformedCoordsArray&, | 95 const TransformedCoordsArray&, |
| 95 const TextureSamplerArray&) SK_OVERRIDE; | 96 const TextureSamplerArray&) SK_OVERRIDE; |
| 96 | 97 |
| 97 static inline void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKe
yBuilder*); | 98 static inline void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKe
yBuilder*); |
| 98 | 99 |
| 99 virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_O
VERRIDE; | 100 virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_O
VERRIDE; |
| 100 | 101 |
| 101 private: | 102 private: |
| 102 GrGLProgramDataManager::UniformHandle fRectUniform; | 103 GrGLProgramDataManager::UniformHandle fRectUniform; |
| 103 SkRect fPrevRect; | 104 SkRect fPrevRect; |
| 104 typedef GrGLFragmentProcessor INHERITED; | 105 typedef GrGLFragmentProcessor INHERITED; |
| 105 }; | 106 }; |
| 106 | 107 |
| 107 GLAARectEffect::GLAARectEffect(const GrBackendProcessorFactory& factory, | 108 GLAARectEffect::GLAARectEffect(const GrProcessor& effect) { |
| 108 const GrProcessor& effect) | |
| 109 : INHERITED (factory) { | |
| 110 fPrevRect.fLeft = SK_ScalarNaN; | 109 fPrevRect.fLeft = SK_ScalarNaN; |
| 111 } | 110 } |
| 112 | 111 |
| 113 void GLAARectEffect::emitCode(GrGLFPBuilder* builder, | 112 void GLAARectEffect::emitCode(GrGLFPBuilder* builder, |
| 114 const GrFragmentProcessor& fp, | 113 const GrFragmentProcessor& fp, |
| 115 const char* outputColor, | 114 const char* outputColor, |
| 116 const char* inputColor, | 115 const char* inputColor, |
| 117 const TransformedCoordsArray&, | 116 const TransformedCoordsArray&, |
| 118 const TextureSamplerArray& samplers) { | 117 const TextureSamplerArray& samplers) { |
| 119 const AARectEffect& aare = fp.cast<AARectEffect>(); | 118 const AARectEffect& aare = fp.cast<AARectEffect>(); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 fPrevRect = rect; | 161 fPrevRect = rect; |
| 163 } | 162 } |
| 164 } | 163 } |
| 165 | 164 |
| 166 void GLAARectEffect::GenKey(const GrProcessor& processor, const GrGLCaps&, | 165 void GLAARectEffect::GenKey(const GrProcessor& processor, const GrGLCaps&, |
| 167 GrProcessorKeyBuilder* b) { | 166 GrProcessorKeyBuilder* b) { |
| 168 const AARectEffect& aare = processor.cast<AARectEffect>(); | 167 const AARectEffect& aare = processor.cast<AARectEffect>(); |
| 169 b->add32(aare.getEdgeType()); | 168 b->add32(aare.getEdgeType()); |
| 170 } | 169 } |
| 171 | 170 |
| 172 const GrBackendFragmentProcessorFactory& AARectEffect::getFactory() const { | 171 void AARectEffect::getGLProcessorKey(const GrGLCaps& caps, GrProcessorKeyBuilder
* b) const { |
| 173 return GrTBackendFragmentProcessorFactory<AARectEffect>::getInstance(); | 172 GLAARectEffect::GenKey(*this, caps, b); |
| 173 } |
| 174 |
| 175 GrGLFragmentProcessor* AARectEffect::createGLInstance() const { |
| 176 return SkNEW_ARGS(GLAARectEffect, (*this)); |
| 174 } | 177 } |
| 175 | 178 |
| 176 ////////////////////////////////////////////////////////////////////////////// | 179 ////////////////////////////////////////////////////////////////////////////// |
| 177 | 180 |
| 178 class GrGLConvexPolyEffect : public GrGLFragmentProcessor { | 181 class GrGLConvexPolyEffect : public GrGLFragmentProcessor { |
| 179 public: | 182 public: |
| 180 GrGLConvexPolyEffect(const GrBackendProcessorFactory&, const GrProcessor&); | 183 GrGLConvexPolyEffect(const GrProcessor&); |
| 181 | 184 |
| 182 virtual void emitCode(GrGLFPBuilder* builder, | 185 virtual void emitCode(GrGLFPBuilder* builder, |
| 183 const GrFragmentProcessor& fp, | 186 const GrFragmentProcessor& fp, |
| 184 const char* outputColor, | 187 const char* outputColor, |
| 185 const char* inputColor, | 188 const char* inputColor, |
| 186 const TransformedCoordsArray&, | 189 const TransformedCoordsArray&, |
| 187 const TextureSamplerArray&) SK_OVERRIDE; | 190 const TextureSamplerArray&) SK_OVERRIDE; |
| 188 | 191 |
| 189 static inline void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKe
yBuilder*); | 192 static inline void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKe
yBuilder*); |
| 190 | 193 |
| 191 virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_O
VERRIDE; | 194 virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_O
VERRIDE; |
| 192 | 195 |
| 193 private: | 196 private: |
| 194 GrGLProgramDataManager::UniformHandle fEdgeUniform; | 197 GrGLProgramDataManager::UniformHandle fEdgeUniform; |
| 195 SkScalar fPrevEdges[3 * GrConvexPolyEffect::kMa
xEdges]; | 198 SkScalar fPrevEdges[3 * GrConvexPolyEffect::kMa
xEdges]; |
| 196 typedef GrGLFragmentProcessor INHERITED; | 199 typedef GrGLFragmentProcessor INHERITED; |
| 197 }; | 200 }; |
| 198 | 201 |
| 199 GrGLConvexPolyEffect::GrGLConvexPolyEffect(const GrBackendProcessorFactory& fact
ory, | 202 GrGLConvexPolyEffect::GrGLConvexPolyEffect(const GrProcessor&) { |
| 200 const GrProcessor&) | |
| 201 : INHERITED (factory) { | |
| 202 fPrevEdges[0] = SK_ScalarNaN; | 203 fPrevEdges[0] = SK_ScalarNaN; |
| 203 } | 204 } |
| 204 | 205 |
| 205 void GrGLConvexPolyEffect::emitCode(GrGLFPBuilder* builder, | 206 void GrGLConvexPolyEffect::emitCode(GrGLFPBuilder* builder, |
| 206 const GrFragmentProcessor& fp, | 207 const GrFragmentProcessor& fp, |
| 207 const char* outputColor, | 208 const char* outputColor, |
| 208 const char* inputColor, | 209 const char* inputColor, |
| 209 const TransformedCoordsArray&, | 210 const TransformedCoordsArray&, |
| 210 const TextureSamplerArray& samplers) { | 211 const TextureSamplerArray& samplers) { |
| 211 const GrConvexPolyEffect& cpe = fp.cast<GrConvexPolyEffect>(); | 212 const GrConvexPolyEffect& cpe = fp.cast<GrConvexPolyEffect>(); |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 } | 320 } |
| 320 return AARectEffect::Create(edgeType, rect); | 321 return AARectEffect::Create(edgeType, rect); |
| 321 } | 322 } |
| 322 | 323 |
| 323 GrConvexPolyEffect::~GrConvexPolyEffect() {} | 324 GrConvexPolyEffect::~GrConvexPolyEffect() {} |
| 324 | 325 |
| 325 void GrConvexPolyEffect::onComputeInvariantOutput(GrInvariantOutput* inout) cons
t { | 326 void GrConvexPolyEffect::onComputeInvariantOutput(GrInvariantOutput* inout) cons
t { |
| 326 inout->mulByUnknownAlpha(); | 327 inout->mulByUnknownAlpha(); |
| 327 } | 328 } |
| 328 | 329 |
| 329 const GrBackendFragmentProcessorFactory& GrConvexPolyEffect::getFactory() const
{ | 330 void GrConvexPolyEffect::getGLProcessorKey(const GrGLCaps& caps, |
| 330 return GrTBackendFragmentProcessorFactory<GrConvexPolyEffect>::getInstance()
; | 331 GrProcessorKeyBuilder* b) const { |
| 332 GrGLConvexPolyEffect::GenKey(*this, caps, b); |
| 333 } |
| 334 |
| 335 GrGLFragmentProcessor* GrConvexPolyEffect::createGLInstance() const { |
| 336 return SkNEW_ARGS(GrGLConvexPolyEffect, (*this)); |
| 331 } | 337 } |
| 332 | 338 |
| 333 GrConvexPolyEffect::GrConvexPolyEffect(GrPrimitiveEdgeType edgeType, int n, cons
t SkScalar edges[]) | 339 GrConvexPolyEffect::GrConvexPolyEffect(GrPrimitiveEdgeType edgeType, int n, cons
t SkScalar edges[]) |
| 334 : fEdgeType(edgeType) | 340 : fEdgeType(edgeType) |
| 335 , fEdgeCount(n) { | 341 , fEdgeCount(n) { |
| 336 // Factory function should have already ensured this. | 342 // Factory function should have already ensured this. |
| 337 SkASSERT(n <= kMaxEdges); | 343 SkASSERT(n <= kMaxEdges); |
| 338 memcpy(fEdges, edges, 3 * n * sizeof(SkScalar)); | 344 memcpy(fEdges, edges, 3 * n * sizeof(SkScalar)); |
| 339 // Outset the edges by 0.5 so that a pixel with center on an edge is 50% cov
ered in the AA case | 345 // Outset the edges by 0.5 so that a pixel with center on an edge is 50% cov
ered in the AA case |
| 340 // and 100% covered in the non-AA case. | 346 // and 100% covered in the non-AA case. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 366 } | 372 } |
| 367 | 373 |
| 368 GrFragmentProcessor* fp; | 374 GrFragmentProcessor* fp; |
| 369 do { | 375 do { |
| 370 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>( | 376 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>( |
| 371 random->nextULessThan(kGrProcessorEdgeTy
peCnt)); | 377 random->nextULessThan(kGrProcessorEdgeTy
peCnt)); |
| 372 fp = GrConvexPolyEffect::Create(edgeType, count, edges); | 378 fp = GrConvexPolyEffect::Create(edgeType, count, edges); |
| 373 } while (NULL == fp); | 379 } while (NULL == fp); |
| 374 return fp; | 380 return fp; |
| 375 } | 381 } |
| OLD | NEW |