Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(401)

Side by Side Diff: src/gpu/effects/GrDistanceFieldGeoProc.cpp

Issue 1441683008: Move GrGLPrimitive/GeometryProc to GLSL (Closed) Base URL: https://skia.googlesource.com/skia.git@xferProcs
Patch Set: nits Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/effects/GrDistanceFieldGeoProc.h ('k') | src/gpu/gl/GrGLGeometryProcessor.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2013 Google Inc. 2 * Copyright 2013 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 "GrDistanceFieldGeoProc.h" 8 #include "GrDistanceFieldGeoProc.h"
9 #include "GrInvariantOutput.h" 9 #include "GrInvariantOutput.h"
10 #include "GrTexture.h" 10 #include "GrTexture.h"
11 11
12 #include "SkDistanceFieldGen.h" 12 #include "SkDistanceFieldGen.h"
13 13
14 #include "gl/GrGLGeometryProcessor.h"
15 #include "glsl/GrGLSLFragmentProcessor.h"
16 #include "glsl/GrGLSLFragmentShaderBuilder.h" 14 #include "glsl/GrGLSLFragmentShaderBuilder.h"
15 #include "glsl/GrGLSLGeometryProcessor.h"
17 #include "glsl/GrGLSLProgramBuilder.h" 16 #include "glsl/GrGLSLProgramBuilder.h"
18 #include "glsl/GrGLSLProgramDataManager.h" 17 #include "glsl/GrGLSLProgramDataManager.h"
19 #include "glsl/GrGLSLVertexShaderBuilder.h" 18 #include "glsl/GrGLSLVertexShaderBuilder.h"
20 #include "glsl/GrGLSLUtil.h" 19 #include "glsl/GrGLSLUtil.h"
21 20
22 // Assuming a radius of a little less than the diagonal of the fragment 21 // Assuming a radius of a little less than the diagonal of the fragment
23 #define SK_DistanceFieldAAFactor "0.65" 22 #define SK_DistanceFieldAAFactor "0.65"
24 23
25 class GrGLDistanceFieldA8TextGeoProc : public GrGLGeometryProcessor { 24 class GrGLDistanceFieldA8TextGeoProc : public GrGLSLGeometryProcessor {
26 public: 25 public:
27 GrGLDistanceFieldA8TextGeoProc() 26 GrGLDistanceFieldA8TextGeoProc()
28 : fViewMatrix(SkMatrix::InvalidMatrix()) 27 : fViewMatrix(SkMatrix::InvalidMatrix())
29 , fColor(GrColor_ILLEGAL) 28 , fColor(GrColor_ILLEGAL)
30 #ifdef SK_GAMMA_APPLY_TO_A8 29 #ifdef SK_GAMMA_APPLY_TO_A8
31 , fDistanceAdjust(-1.0f) 30 , fDistanceAdjust(-1.0f)
32 #endif 31 #endif
33 {} 32 {}
34 33
35 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{ 34 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 private: 192 private:
194 SkMatrix fViewMatrix; 193 SkMatrix fViewMatrix;
195 GrColor fColor; 194 GrColor fColor;
196 UniformHandle fColorUniform; 195 UniformHandle fColorUniform;
197 UniformHandle fViewMatrixUniform; 196 UniformHandle fViewMatrixUniform;
198 #ifdef SK_GAMMA_APPLY_TO_A8 197 #ifdef SK_GAMMA_APPLY_TO_A8
199 float fDistanceAdjust; 198 float fDistanceAdjust;
200 UniformHandle fDistanceAdjustUni; 199 UniformHandle fDistanceAdjustUni;
201 #endif 200 #endif
202 201
203 typedef GrGLGeometryProcessor INHERITED; 202 typedef GrGLSLGeometryProcessor INHERITED;
204 }; 203 };
205 204
206 /////////////////////////////////////////////////////////////////////////////// 205 ///////////////////////////////////////////////////////////////////////////////
207 206
208 GrDistanceFieldA8TextGeoProc::GrDistanceFieldA8TextGeoProc(GrColor color, 207 GrDistanceFieldA8TextGeoProc::GrDistanceFieldA8TextGeoProc(GrColor color,
209 const SkMatrix& viewM atrix, 208 const SkMatrix& viewM atrix,
210 GrTexture* texture, 209 GrTexture* texture,
211 const GrTextureParams & params, 210 const GrTextureParams & params,
212 #ifdef SK_GAMMA_APPLY_TO_A8 211 #ifdef SK_GAMMA_APPLY_TO_A8
213 float distanceAdjust, 212 float distanceAdjust,
(...skipping 19 matching lines...) Expand all
233 fInTextureCoords = &this->addVertexAttrib(Attribute("inTextureCoords", 232 fInTextureCoords = &this->addVertexAttrib(Attribute("inTextureCoords",
234 kVec2s_GrVertexAttribT ype)); 233 kVec2s_GrVertexAttribT ype));
235 this->addTextureAccess(&fTextureAccess); 234 this->addTextureAccess(&fTextureAccess);
236 } 235 }
237 236
238 void GrDistanceFieldA8TextGeoProc::getGLProcessorKey(const GrGLSLCaps& caps, 237 void GrDistanceFieldA8TextGeoProc::getGLProcessorKey(const GrGLSLCaps& caps,
239 GrProcessorKeyBuilder* b) c onst { 238 GrProcessorKeyBuilder* b) c onst {
240 GrGLDistanceFieldA8TextGeoProc::GenKey(*this, caps, b); 239 GrGLDistanceFieldA8TextGeoProc::GenKey(*this, caps, b);
241 } 240 }
242 241
243 GrGLPrimitiveProcessor* GrDistanceFieldA8TextGeoProc::createGLInstance(const GrG LSLCaps&) const { 242 GrGLSLPrimitiveProcessor* GrDistanceFieldA8TextGeoProc::createGLInstance(const G rGLSLCaps&) const {
244 return new GrGLDistanceFieldA8TextGeoProc(); 243 return new GrGLDistanceFieldA8TextGeoProc();
245 } 244 }
246 245
247 /////////////////////////////////////////////////////////////////////////////// 246 ///////////////////////////////////////////////////////////////////////////////
248 247
249 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrDistanceFieldA8TextGeoProc); 248 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrDistanceFieldA8TextGeoProc);
250 249
251 const GrGeometryProcessor* GrDistanceFieldA8TextGeoProc::TestCreate(GrProcessorT estData* d) { 250 const GrGeometryProcessor* GrDistanceFieldA8TextGeoProc::TestCreate(GrProcessorT estData* d) {
252 int texIdx = d->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx : 251 int texIdx = d->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx :
253 GrProcessorUnitTest::kAlphaTextureIdx; 252 GrProcessorUnitTest::kAlphaTextureIdx;
(...skipping 15 matching lines...) Expand all
269 #ifdef SK_GAMMA_APPLY_TO_A8 268 #ifdef SK_GAMMA_APPLY_TO_A8
270 d->fRandom->nextF(), 269 d->fRandom->nextF(),
271 #endif 270 #endif
272 d->fRandom->nextBool() ? 271 d->fRandom->nextBool() ?
273 kSimilarity_DistanceFieldEff ectFlag : 0, 272 kSimilarity_DistanceFieldEff ectFlag : 0,
274 d->fRandom->nextBool()); 273 d->fRandom->nextBool());
275 } 274 }
276 275
277 /////////////////////////////////////////////////////////////////////////////// 276 ///////////////////////////////////////////////////////////////////////////////
278 277
279 class GrGLDistanceFieldPathGeoProc : public GrGLGeometryProcessor { 278 class GrGLDistanceFieldPathGeoProc : public GrGLSLGeometryProcessor {
280 public: 279 public:
281 GrGLDistanceFieldPathGeoProc() 280 GrGLDistanceFieldPathGeoProc()
282 : fViewMatrix(SkMatrix::InvalidMatrix()) 281 : fViewMatrix(SkMatrix::InvalidMatrix())
283 , fColor(GrColor_ILLEGAL) 282 , fColor(GrColor_ILLEGAL)
284 , fTextureSize(SkISize::Make(-1, -1)) {} 283 , fTextureSize(SkISize::Make(-1, -1)) {}
285 284
286 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{ 285 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{
287 const GrDistanceFieldPathGeoProc& dfTexEffect = args.fGP.cast<GrDistance FieldPathGeoProc>(); 286 const GrDistanceFieldPathGeoProc& dfTexEffect = args.fGP.cast<GrDistance FieldPathGeoProc>();
288 287
289 GrGLSLGPBuilder* pb = args.fPB; 288 GrGLSLGPBuilder* pb = args.fPB;
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 } 414 }
416 415
417 private: 416 private:
418 UniformHandle fColorUniform; 417 UniformHandle fColorUniform;
419 UniformHandle fTextureSizeUni; 418 UniformHandle fTextureSizeUni;
420 UniformHandle fViewMatrixUniform; 419 UniformHandle fViewMatrixUniform;
421 SkMatrix fViewMatrix; 420 SkMatrix fViewMatrix;
422 GrColor fColor; 421 GrColor fColor;
423 SkISize fTextureSize; 422 SkISize fTextureSize;
424 423
425 typedef GrGLGeometryProcessor INHERITED; 424 typedef GrGLSLGeometryProcessor INHERITED;
426 }; 425 };
427 426
428 /////////////////////////////////////////////////////////////////////////////// 427 ///////////////////////////////////////////////////////////////////////////////
429 428
430 GrDistanceFieldPathGeoProc::GrDistanceFieldPathGeoProc( 429 GrDistanceFieldPathGeoProc::GrDistanceFieldPathGeoProc(
431 GrColor color, 430 GrColor color,
432 const SkMatrix& viewMatrix, 431 const SkMatrix& viewMatrix,
433 GrTexture* texture, 432 GrTexture* texture,
434 const GrTextureParams& params, 433 const GrTextureParams& params,
435 uint32_t flags, 434 uint32_t flags,
(...skipping 14 matching lines...) Expand all
450 fInTextureCoords = &this->addVertexAttrib(Attribute("inTextureCoords", 449 fInTextureCoords = &this->addVertexAttrib(Attribute("inTextureCoords",
451 kVec2f_GrVertexAttribTyp e)); 450 kVec2f_GrVertexAttribTyp e));
452 this->addTextureAccess(&fTextureAccess); 451 this->addTextureAccess(&fTextureAccess);
453 } 452 }
454 453
455 void GrDistanceFieldPathGeoProc::getGLProcessorKey(const GrGLSLCaps& caps, 454 void GrDistanceFieldPathGeoProc::getGLProcessorKey(const GrGLSLCaps& caps,
456 GrProcessorKeyBuilder* b) con st { 455 GrProcessorKeyBuilder* b) con st {
457 GrGLDistanceFieldPathGeoProc::GenKey(*this, caps, b); 456 GrGLDistanceFieldPathGeoProc::GenKey(*this, caps, b);
458 } 457 }
459 458
460 GrGLPrimitiveProcessor* GrDistanceFieldPathGeoProc::createGLInstance(const GrGLS LCaps&) const { 459 GrGLSLPrimitiveProcessor* GrDistanceFieldPathGeoProc::createGLInstance(const GrG LSLCaps&) const {
461 return new GrGLDistanceFieldPathGeoProc(); 460 return new GrGLDistanceFieldPathGeoProc();
462 } 461 }
463 462
464 /////////////////////////////////////////////////////////////////////////////// 463 ///////////////////////////////////////////////////////////////////////////////
465 464
466 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrDistanceFieldPathGeoProc); 465 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrDistanceFieldPathGeoProc);
467 466
468 const GrGeometryProcessor* GrDistanceFieldPathGeoProc::TestCreate(GrProcessorTes tData* d) { 467 const GrGeometryProcessor* GrDistanceFieldPathGeoProc::TestCreate(GrProcessorTes tData* d) {
469 int texIdx = d->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx 468 int texIdx = d->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx
470 : GrProcessorUnitTest::kAlphaTextureIdx; 469 : GrProcessorUnitTest::kAlphaTextureIdx;
(...skipping 13 matching lines...) Expand all
484 GrTest::TestMatrix(d->fRandom), 483 GrTest::TestMatrix(d->fRandom),
485 d->fTextures[texIdx], 484 d->fTextures[texIdx],
486 params, 485 params,
487 d->fRandom->nextBool() ? 486 d->fRandom->nextBool() ?
488 kSimilarity_DistanceFieldE ffectFlag : 0, 487 kSimilarity_DistanceFieldE ffectFlag : 0,
489 d->fRandom->nextBool()); 488 d->fRandom->nextBool());
490 } 489 }
491 490
492 /////////////////////////////////////////////////////////////////////////////// 491 ///////////////////////////////////////////////////////////////////////////////
493 492
494 class GrGLDistanceFieldLCDTextGeoProc : public GrGLGeometryProcessor { 493 class GrGLDistanceFieldLCDTextGeoProc : public GrGLSLGeometryProcessor {
495 public: 494 public:
496 GrGLDistanceFieldLCDTextGeoProc() 495 GrGLDistanceFieldLCDTextGeoProc()
497 : fViewMatrix(SkMatrix::InvalidMatrix()), fColor(GrColor_ILLEGAL) { 496 : fViewMatrix(SkMatrix::InvalidMatrix()), fColor(GrColor_ILLEGAL) {
498 fDistanceAdjust = GrDistanceFieldLCDTextGeoProc::DistanceAdjust::Make(1. 0f, 1.0f, 1.0f); 497 fDistanceAdjust = GrDistanceFieldLCDTextGeoProc::DistanceAdjust::Make(1. 0f, 1.0f, 1.0f);
499 } 498 }
500 499
501 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{ 500 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{
502 const GrDistanceFieldLCDTextGeoProc& dfTexEffect = 501 const GrDistanceFieldLCDTextGeoProc& dfTexEffect =
503 args.fGP.cast<GrDistanceFieldLCDTextGeoProc>(); 502 args.fGP.cast<GrDistanceFieldLCDTextGeoProc>();
504 GrGLSLGPBuilder* pb = args.fPB; 503 GrGLSLGPBuilder* pb = args.fPB;
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
690 } 689 }
691 690
692 private: 691 private:
693 SkMatrix fViewMatrix; 692 SkMatrix fViewMatrix;
694 GrColor fColor; 693 GrColor fColor;
695 UniformHandle fViewMatrixUniform; 694 UniformHandle fViewMatrixUniform;
696 UniformHandle fColorUniform; 695 UniformHandle fColorUniform;
697 GrDistanceFieldLCDTextGeoProc::DistanceAdjust fDistanceAdjust; 696 GrDistanceFieldLCDTextGeoProc::DistanceAdjust fDistanceAdjust;
698 UniformHandle fDistanceAdjustUni; 697 UniformHandle fDistanceAdjustUni;
699 698
700 typedef GrGLGeometryProcessor INHERITED; 699 typedef GrGLSLGeometryProcessor INHERITED;
701 }; 700 };
702 701
703 /////////////////////////////////////////////////////////////////////////////// 702 ///////////////////////////////////////////////////////////////////////////////
704 703
705 GrDistanceFieldLCDTextGeoProc::GrDistanceFieldLCDTextGeoProc( 704 GrDistanceFieldLCDTextGeoProc::GrDistanceFieldLCDTextGeoProc(
706 GrColor color, const SkMatrix& viewMatrix, 705 GrColor color, const SkMatrix& viewMatrix,
707 GrTexture* texture, const GrTe xtureParams& params, 706 GrTexture* texture, const GrTe xtureParams& params,
708 DistanceAdjust distanceAdjust, 707 DistanceAdjust distanceAdjust,
709 uint32_t flags, bool usesLocal Coords) 708 uint32_t flags, bool usesLocal Coords)
710 : fColor(color) 709 : fColor(color)
711 , fViewMatrix(viewMatrix) 710 , fViewMatrix(viewMatrix)
712 , fTextureAccess(texture, params) 711 , fTextureAccess(texture, params)
713 , fDistanceAdjust(distanceAdjust) 712 , fDistanceAdjust(distanceAdjust)
714 , fFlags(flags & kLCD_DistanceFieldEffectMask) 713 , fFlags(flags & kLCD_DistanceFieldEffectMask)
715 , fUsesLocalCoords(usesLocalCoords) { 714 , fUsesLocalCoords(usesLocalCoords) {
716 SkASSERT(!(flags & ~kLCD_DistanceFieldEffectMask) && (flags & kUseLCD_Distan ceFieldEffectFlag)); 715 SkASSERT(!(flags & ~kLCD_DistanceFieldEffectMask) && (flags & kUseLCD_Distan ceFieldEffectFlag));
717 this->initClassID<GrDistanceFieldLCDTextGeoProc>(); 716 this->initClassID<GrDistanceFieldLCDTextGeoProc>();
718 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex AttribType, 717 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex AttribType,
719 kHigh_GrSLPrecision)); 718 kHigh_GrSLPrecision));
720 fInTextureCoords = &this->addVertexAttrib(Attribute("inTextureCoords", 719 fInTextureCoords = &this->addVertexAttrib(Attribute("inTextureCoords",
721 kVec2s_GrVertexAttribTyp e)); 720 kVec2s_GrVertexAttribTyp e));
722 this->addTextureAccess(&fTextureAccess); 721 this->addTextureAccess(&fTextureAccess);
723 } 722 }
724 723
725 void GrDistanceFieldLCDTextGeoProc::getGLProcessorKey(const GrGLSLCaps& caps, 724 void GrDistanceFieldLCDTextGeoProc::getGLProcessorKey(const GrGLSLCaps& caps,
726 GrProcessorKeyBuilder* b) const { 725 GrProcessorKeyBuilder* b) const {
727 GrGLDistanceFieldLCDTextGeoProc::GenKey(*this, caps, b); 726 GrGLDistanceFieldLCDTextGeoProc::GenKey(*this, caps, b);
728 } 727 }
729 728
730 GrGLPrimitiveProcessor* GrDistanceFieldLCDTextGeoProc::createGLInstance(const Gr GLSLCaps&) const { 729 GrGLSLPrimitiveProcessor* GrDistanceFieldLCDTextGeoProc::createGLInstance(const GrGLSLCaps&) const {
731 return new GrGLDistanceFieldLCDTextGeoProc(); 730 return new GrGLDistanceFieldLCDTextGeoProc();
732 } 731 }
733 732
734 /////////////////////////////////////////////////////////////////////////////// 733 ///////////////////////////////////////////////////////////////////////////////
735 734
736 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrDistanceFieldLCDTextGeoProc); 735 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrDistanceFieldLCDTextGeoProc);
737 736
738 const GrGeometryProcessor* GrDistanceFieldLCDTextGeoProc::TestCreate(GrProcessor TestData* d) { 737 const GrGeometryProcessor* GrDistanceFieldLCDTextGeoProc::TestCreate(GrProcessor TestData* d) {
739 int texIdx = d->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx : 738 int texIdx = d->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx :
740 GrProcessorUnitTest::kAlphaTextureIdx; 739 GrProcessorUnitTest::kAlphaTextureIdx;
(...skipping 12 matching lines...) Expand all
753 uint32_t flags = kUseLCD_DistanceFieldEffectFlag; 752 uint32_t flags = kUseLCD_DistanceFieldEffectFlag;
754 flags |= d->fRandom->nextBool() ? kUniformScale_DistanceFieldEffectMask : 0; 753 flags |= d->fRandom->nextBool() ? kUniformScale_DistanceFieldEffectMask : 0;
755 flags |= d->fRandom->nextBool() ? kBGR_DistanceFieldEffectFlag : 0; 754 flags |= d->fRandom->nextBool() ? kBGR_DistanceFieldEffectFlag : 0;
756 return GrDistanceFieldLCDTextGeoProc::Create(GrRandomColor(d->fRandom), 755 return GrDistanceFieldLCDTextGeoProc::Create(GrRandomColor(d->fRandom),
757 GrTest::TestMatrix(d->fRandom), 756 GrTest::TestMatrix(d->fRandom),
758 d->fTextures[texIdx], params, 757 d->fTextures[texIdx], params,
759 wa, 758 wa,
760 flags, 759 flags,
761 d->fRandom->nextBool()); 760 d->fRandom->nextBool());
762 } 761 }
OLDNEW
« no previous file with comments | « src/gpu/effects/GrDistanceFieldGeoProc.h ('k') | src/gpu/gl/GrGLGeometryProcessor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698