| 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" | 8 #include "gl/builders/GrGLProgramBuilder.h" |
| 9 #include "GrRRectEffect.h" | 9 #include "GrRRectEffect.h" |
| 10 | 10 |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 } while (NULL == fp); | 130 } while (NULL == fp); |
| 131 return fp; | 131 return fp; |
| 132 } | 132 } |
| 133 | 133 |
| 134 ////////////////////////////////////////////////////////////////////////////// | 134 ////////////////////////////////////////////////////////////////////////////// |
| 135 | 135 |
| 136 class GLCircularRRectEffect : public GrGLFragmentProcessor { | 136 class GLCircularRRectEffect : public GrGLFragmentProcessor { |
| 137 public: | 137 public: |
| 138 GLCircularRRectEffect(const GrBackendProcessorFactory&, const GrProcessor&); | 138 GLCircularRRectEffect(const GrBackendProcessorFactory&, const GrProcessor&); |
| 139 | 139 |
| 140 virtual void emitCode(GrGLProgramBuilder* builder, | 140 virtual void emitCode(GrGLFPBuilder* builder, |
| 141 const GrFragmentProcessor& fp, | 141 const GrFragmentProcessor& fp, |
| 142 const GrProcessorKey& key, | 142 const GrProcessorKey& key, |
| 143 const char* outputColor, | 143 const char* outputColor, |
| 144 const char* inputColor, | 144 const char* inputColor, |
| 145 const TransformedCoordsArray&, | 145 const TransformedCoordsArray&, |
| 146 const TextureSamplerArray&) SK_OVERRIDE; | 146 const TextureSamplerArray&) SK_OVERRIDE; |
| 147 | 147 |
| 148 static inline void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKe
yBuilder*); | 148 static inline void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKe
yBuilder*); |
| 149 | 149 |
| 150 virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_O
VERRIDE; | 150 virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_O
VERRIDE; |
| 151 | 151 |
| 152 private: | 152 private: |
| 153 GrGLProgramDataManager::UniformHandle fInnerRectUniform; | 153 GrGLProgramDataManager::UniformHandle fInnerRectUniform; |
| 154 GrGLProgramDataManager::UniformHandle fRadiusPlusHalfUniform; | 154 GrGLProgramDataManager::UniformHandle fRadiusPlusHalfUniform; |
| 155 SkRRect fPrevRRect; | 155 SkRRect fPrevRRect; |
| 156 typedef GrGLFragmentProcessor INHERITED; | 156 typedef GrGLFragmentProcessor INHERITED; |
| 157 }; | 157 }; |
| 158 | 158 |
| 159 GLCircularRRectEffect::GLCircularRRectEffect(const GrBackendProcessorFactory& fa
ctory, | 159 GLCircularRRectEffect::GLCircularRRectEffect(const GrBackendProcessorFactory& fa
ctory, |
| 160 const GrProcessor& ) | 160 const GrProcessor& ) |
| 161 : INHERITED (factory) { | 161 : INHERITED (factory) { |
| 162 fPrevRRect.setEmpty(); | 162 fPrevRRect.setEmpty(); |
| 163 } | 163 } |
| 164 | 164 |
| 165 void GLCircularRRectEffect::emitCode(GrGLProgramBuilder* builder, | 165 void GLCircularRRectEffect::emitCode(GrGLFPBuilder* builder, |
| 166 const GrFragmentProcessor& fp, | 166 const GrFragmentProcessor& fp, |
| 167 const GrProcessorKey& key, | 167 const GrProcessorKey& key, |
| 168 const char* outputColor, | 168 const char* outputColor, |
| 169 const char* inputColor, | 169 const char* inputColor, |
| 170 const TransformedCoordsArray&, | 170 const TransformedCoordsArray&, |
| 171 const TextureSamplerArray& samplers) { | 171 const TextureSamplerArray& samplers) { |
| 172 const CircularRRectEffect& crre = fp.cast<CircularRRectEffect>(); | 172 const CircularRRectEffect& crre = fp.cast<CircularRRectEffect>(); |
| 173 const char *rectName; | 173 const char *rectName; |
| 174 const char *radiusPlusHalfName; | 174 const char *radiusPlusHalfName; |
| 175 // The inner rect is the rrect bounds inset by the radius. Its left, top, ri
ght, and bottom | 175 // The inner rect is the rrect bounds inset by the radius. Its left, top, ri
ght, and bottom |
| 176 // edges correspond to components x, y, z, and w, respectively. When a side
of the rrect has | 176 // edges correspond to components x, y, z, and w, respectively. When a side
of the rrect has |
| 177 // only rectangular corners, that side's value corresponds to the rect edge'
s value outset by | 177 // only rectangular corners, that side's value corresponds to the rect edge'
s value outset by |
| 178 // half a pixel. | 178 // half a pixel. |
| 179 fInnerRectUniform = builder->addUniform(GrGLProgramBuilder::kFragment_Visibi
lity, | 179 fInnerRectUniform = builder->addUniform(GrGLProgramBuilder::kFragment_Visibi
lity, |
| 180 kVec4f_GrSLType, | 180 kVec4f_GrSLType, |
| 181 "innerRect", | 181 "innerRect", |
| 182 &rectName); | 182 &rectName); |
| 183 fRadiusPlusHalfUniform = builder->addUniform(GrGLProgramBuilder::kFragment_V
isibility, | 183 fRadiusPlusHalfUniform = builder->addUniform(GrGLProgramBuilder::kFragment_V
isibility, |
| 184 kFloat_GrSLType, | 184 kFloat_GrSLType, |
| 185 "radiusPlusHalf", | 185 "radiusPlusHalf", |
| 186 &radiusPlusHalfName); | 186 &radiusPlusHalfName); |
| 187 | 187 |
| 188 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder(); | 188 GrGLFPFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder(); |
| 189 const char* fragmentPos = fsBuilder->fragmentPosition(); | 189 const char* fragmentPos = fsBuilder->fragmentPosition(); |
| 190 // At each quarter-circle corner we compute a vector that is the offset of t
he fragment position | 190 // At each quarter-circle corner we compute a vector that is the offset of t
he fragment position |
| 191 // from the circle center. The vector is pinned in x and y to be in the quar
ter-plane relevant | 191 // from the circle center. The vector is pinned in x and y to be in the quar
ter-plane relevant |
| 192 // to that corner. This means that points near the interior near the rrect t
op edge will have | 192 // to that corner. This means that points near the interior near the rrect t
op edge will have |
| 193 // a vector that points straight up for both the TL left and TR corners. Com
puting an | 193 // a vector that points straight up for both the TL left and TR corners. Com
puting an |
| 194 // alpha from this vector at either the TR or TL corner will give the correc
t result. Similarly, | 194 // alpha from this vector at either the TR or TL corner will give the correc
t result. Similarly, |
| 195 // fragments near the other three edges will get the correct AA. Fragments i
n the interior of | 195 // fragments near the other three edges will get the correct AA. Fragments i
n the interior of |
| 196 // the rrect will have a (0,0) vector at all four corners. So long as the ra
dius > 0.5 they will | 196 // the rrect will have a (0,0) vector at all four corners. So long as the ra
dius > 0.5 they will |
| 197 // correctly produce an alpha value of 1 at all four corners. We take the mi
n of all the alphas. | 197 // correctly produce an alpha value of 1 at all four corners. We take the mi
n of all the alphas. |
| 198 // The code below is a simplified version of the above that performs maxs on
the vector | 198 // The code below is a simplified version of the above that performs maxs on
the vector |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 486 } while (NULL == fp); | 486 } while (NULL == fp); |
| 487 return fp; | 487 return fp; |
| 488 } | 488 } |
| 489 | 489 |
| 490 ////////////////////////////////////////////////////////////////////////////// | 490 ////////////////////////////////////////////////////////////////////////////// |
| 491 | 491 |
| 492 class GLEllipticalRRectEffect : public GrGLFragmentProcessor { | 492 class GLEllipticalRRectEffect : public GrGLFragmentProcessor { |
| 493 public: | 493 public: |
| 494 GLEllipticalRRectEffect(const GrBackendProcessorFactory&, const GrProcessor&
); | 494 GLEllipticalRRectEffect(const GrBackendProcessorFactory&, const GrProcessor&
); |
| 495 | 495 |
| 496 virtual void emitCode(GrGLProgramBuilder* builder, | 496 virtual void emitCode(GrGLFPBuilder* builder, |
| 497 const GrFragmentProcessor& effect, | 497 const GrFragmentProcessor& effect, |
| 498 const GrProcessorKey& key, | 498 const GrProcessorKey& key, |
| 499 const char* outputColor, | 499 const char* outputColor, |
| 500 const char* inputColor, | 500 const char* inputColor, |
| 501 const TransformedCoordsArray&, | 501 const TransformedCoordsArray&, |
| 502 const TextureSamplerArray&) SK_OVERRIDE; | 502 const TextureSamplerArray&) SK_OVERRIDE; |
| 503 | 503 |
| 504 static inline void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKe
yBuilder*); | 504 static inline void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKe
yBuilder*); |
| 505 | 505 |
| 506 virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_O
VERRIDE; | 506 virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_O
VERRIDE; |
| 507 | 507 |
| 508 private: | 508 private: |
| 509 GrGLProgramDataManager::UniformHandle fInnerRectUniform; | 509 GrGLProgramDataManager::UniformHandle fInnerRectUniform; |
| 510 GrGLProgramDataManager::UniformHandle fInvRadiiSqdUniform; | 510 GrGLProgramDataManager::UniformHandle fInvRadiiSqdUniform; |
| 511 SkRRect fPrevRRect; | 511 SkRRect fPrevRRect; |
| 512 typedef GrGLFragmentProcessor INHERITED; | 512 typedef GrGLFragmentProcessor INHERITED; |
| 513 }; | 513 }; |
| 514 | 514 |
| 515 GLEllipticalRRectEffect::GLEllipticalRRectEffect(const GrBackendProcessorFactory
& factory, | 515 GLEllipticalRRectEffect::GLEllipticalRRectEffect(const GrBackendProcessorFactory
& factory, |
| 516 const GrProcessor& effect) | 516 const GrProcessor& effect) |
| 517 : INHERITED (factory) { | 517 : INHERITED (factory) { |
| 518 fPrevRRect.setEmpty(); | 518 fPrevRRect.setEmpty(); |
| 519 } | 519 } |
| 520 | 520 |
| 521 void GLEllipticalRRectEffect::emitCode(GrGLProgramBuilder* builder, | 521 void GLEllipticalRRectEffect::emitCode(GrGLFPBuilder* builder, |
| 522 const GrFragmentProcessor& effect, | 522 const GrFragmentProcessor& effect, |
| 523 const GrProcessorKey& key, | 523 const GrProcessorKey& key, |
| 524 const char* outputColor, | 524 const char* outputColor, |
| 525 const char* inputColor, | 525 const char* inputColor, |
| 526 const TransformedCoordsArray&, | 526 const TransformedCoordsArray&, |
| 527 const TextureSamplerArray& samplers) { | 527 const TextureSamplerArray& samplers) { |
| 528 const EllipticalRRectEffect& erre = effect.cast<EllipticalRRectEffect>(); | 528 const EllipticalRRectEffect& erre = effect.cast<EllipticalRRectEffect>(); |
| 529 const char *rectName; | 529 const char *rectName; |
| 530 // The inner rect is the rrect bounds inset by the x/y radii | 530 // The inner rect is the rrect bounds inset by the x/y radii |
| 531 fInnerRectUniform = builder->addUniform(GrGLProgramBuilder::kFragment_Visibi
lity, | 531 fInnerRectUniform = builder->addUniform(GrGLProgramBuilder::kFragment_Visibi
lity, |
| 532 kVec4f_GrSLType, | 532 kVec4f_GrSLType, |
| 533 "innerRect", | 533 "innerRect", |
| 534 &rectName); | 534 &rectName); |
| 535 | 535 |
| 536 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder(); | 536 GrGLFPFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder(); |
| 537 const char* fragmentPos = fsBuilder->fragmentPosition(); | 537 const char* fragmentPos = fsBuilder->fragmentPosition(); |
| 538 // At each quarter-ellipse corner we compute a vector that is the offset of
the fragment pos | 538 // At each quarter-ellipse corner we compute a vector that is the offset of
the fragment pos |
| 539 // to the ellipse center. The vector is pinned in x and y to be in the quart
er-plane relevant | 539 // to the ellipse center. The vector is pinned in x and y to be in the quart
er-plane relevant |
| 540 // to that corner. This means that points near the interior near the rrect t
op edge will have | 540 // to that corner. This means that points near the interior near the rrect t
op edge will have |
| 541 // a vector that points straight up for both the TL left and TR corners. Com
puting an | 541 // a vector that points straight up for both the TL left and TR corners. Com
puting an |
| 542 // alpha from this vector at either the TR or TL corner will give the correc
t result. Similarly, | 542 // alpha from this vector at either the TR or TL corner will give the correc
t result. Similarly, |
| 543 // fragments near the other three edges will get the correct AA. Fragments i
n the interior of | 543 // fragments near the other three edges will get the correct AA. Fragments i
n the interior of |
| 544 // the rrect will have a (0,0) vector at all four corners. So long as the ra
dii > 0.5 they will | 544 // the rrect will have a (0,0) vector at all four corners. So long as the ra
dii > 0.5 they will |
| 545 // correctly produce an alpha value of 1 at all four corners. We take the mi
n of all the alphas. | 545 // correctly produce an alpha value of 1 at all four corners. We take the mi
n of all the alphas. |
| 546 // The code below is a simplified version of the above that performs maxs on
the vector | 546 // The code below is a simplified version of the above that performs maxs on
the vector |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 730 if (rrect.isNinePatch()) { | 730 if (rrect.isNinePatch()) { |
| 731 return EllipticalRRectEffect::Create(edgeType, rrect); | 731 return EllipticalRRectEffect::Create(edgeType, rrect); |
| 732 } | 732 } |
| 733 return NULL; | 733 return NULL; |
| 734 } | 734 } |
| 735 } | 735 } |
| 736 } | 736 } |
| 737 | 737 |
| 738 return NULL; | 738 return NULL; |
| 739 } | 739 } |
| OLD | NEW |