| OLD | NEW | 
|    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 "GrBitmapTextGeoProc.h" |    8 #include "GrBitmapTextGeoProc.h" | 
|    9 #include "GrInvariantOutput.h" |    9 #include "GrInvariantOutput.h" | 
|   10 #include "GrTexture.h" |   10 #include "GrTexture.h" | 
|   11 #include "glsl/GrGLSLFragmentShaderBuilder.h" |   11 #include "glsl/GrGLSLFragmentShaderBuilder.h" | 
|   12 #include "glsl/GrGLSLGeometryProcessor.h" |   12 #include "glsl/GrGLSLGeometryProcessor.h" | 
|   13 #include "glsl/GrGLSLProgramBuilder.h" |   13 #include "glsl/GrGLSLProgramBuilder.h" | 
|   14 #include "glsl/GrGLSLProgramDataManager.h" |   14 #include "glsl/GrGLSLProgramDataManager.h" | 
|   15 #include "glsl/GrGLSLVertexShaderBuilder.h" |   15 #include "glsl/GrGLSLVertexShaderBuilder.h" | 
|   16  |   16  | 
|   17 class GrGLBitmapTextGeoProc : public GrGLSLGeometryProcessor { |   17 class GrGLBitmapTextGeoProc : public GrGLSLGeometryProcessor { | 
|   18 public: |   18 public: | 
|   19     GrGLBitmapTextGeoProc() : fColor(GrColor_ILLEGAL) {} |   19     GrGLBitmapTextGeoProc() : fColor(GrColor_ILLEGAL) {} | 
|   20  |   20  | 
|   21     void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override { |   21     void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override { | 
|   22         const GrBitmapTextGeoProc& cte = args.fGP.cast<GrBitmapTextGeoProc>(); |   22         const GrBitmapTextGeoProc& cte = args.fGP.cast<GrBitmapTextGeoProc>(); | 
|   23  |   23  | 
|   24         GrGLSLGPBuilder* pb = args.fPB; |   24         GrGLSLGPBuilder* pb = args.fPB; | 
|   25         GrGLSLVertexBuilder* vsBuilder = pb->getVertexShaderBuilder(); |   25         GrGLSLVertexBuilder* vertBuilder = args.fVertBuilder; | 
|   26  |   26  | 
|   27         // emit attributes |   27         // emit attributes | 
|   28         vsBuilder->emitAttributes(cte); |   28         vertBuilder->emitAttributes(cte); | 
|   29  |   29  | 
|   30         // compute numbers to be hardcoded to convert texture coordinates from i
     nt to float |   30         // compute numbers to be hardcoded to convert texture coordinates from i
     nt to float | 
|   31         SkASSERT(cte.numTextures() == 1); |   31         SkASSERT(cte.numTextures() == 1); | 
|   32         GrTexture* atlas = cte.textureAccess(0).getTexture(); |   32         GrTexture* atlas = cte.textureAccess(0).getTexture(); | 
|   33         SkASSERT(atlas && SkIsPow2(atlas->width()) && SkIsPow2(atlas->height()))
     ; |   33         SkASSERT(atlas && SkIsPow2(atlas->width()) && SkIsPow2(atlas->height()))
     ; | 
|   34         SkScalar recipWidth = 1.0f / atlas->width(); |   34         SkScalar recipWidth = 1.0f / atlas->width(); | 
|   35         SkScalar recipHeight = 1.0f / atlas->height(); |   35         SkScalar recipHeight = 1.0f / atlas->height(); | 
|   36  |   36  | 
|   37         GrGLSLVertToFrag v(kVec2f_GrSLType); |   37         GrGLSLVertToFrag v(kVec2f_GrSLType); | 
|   38         pb->addVarying("TextureCoords", &v); |   38         pb->addVarying("TextureCoords", &v); | 
|   39         vsBuilder->codeAppendf("%s = vec2(%.*f, %.*f) * %s;", v.vsOut(), |   39         vertBuilder->codeAppendf("%s = vec2(%.*f, %.*f) * %s;", v.vsOut(), | 
|   40                                GR_SIGNIFICANT_POW2_DECIMAL_DIG, recipWidth, |   40                                  GR_SIGNIFICANT_POW2_DECIMAL_DIG, recipWidth, | 
|   41                                GR_SIGNIFICANT_POW2_DECIMAL_DIG, recipHeight, |   41                                  GR_SIGNIFICANT_POW2_DECIMAL_DIG, recipHeight, | 
|   42                                cte.inTextureCoords()->fName); |   42                                  cte.inTextureCoords()->fName); | 
|   43  |   43  | 
 |   44         GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; | 
|   44         // Setup pass through color |   45         // Setup pass through color | 
|   45         if (!cte.colorIgnored()) { |   46         if (!cte.colorIgnored()) { | 
|   46             if (cte.hasVertexColor()) { |   47             if (cte.hasVertexColor()) { | 
|   47                 pb->addPassThroughAttribute(cte.inColor(), args.fOutputColor); |   48                 pb->addPassThroughAttribute(cte.inColor(), args.fOutputColor); | 
|   48             } else { |   49             } else { | 
|   49                 this->setupUniformColor(pb, args.fOutputColor, &fColorUniform); |   50                 this->setupUniformColor(pb, fragBuilder, args.fOutputColor, &fCo
     lorUniform); | 
|   50             } |   51             } | 
|   51         } |   52         } | 
|   52  |   53  | 
|   53         // Setup position |   54         // Setup position | 
|   54         this->setupPosition(pb, gpArgs, cte.inPosition()->fName); |   55         this->setupPosition(pb, vertBuilder, gpArgs, cte.inPosition()->fName); | 
|   55  |   56  | 
|   56         // emit transforms |   57         // emit transforms | 
|   57         this->emitTransforms(args.fPB, gpArgs->fPositionVar, cte.inPosition()->f
     Name, |   58         this->emitTransforms(args.fPB, | 
|   58                              cte.localMatrix(), args.fTransformsIn, args.fTransf
     ormsOut); |   59                              vertBuilder, | 
 |   60                              gpArgs->fPositionVar, | 
 |   61                              cte.inPosition()->fName, | 
 |   62                              cte.localMatrix(), | 
 |   63                              args.fTransformsIn, | 
 |   64                              args.fTransformsOut); | 
|   59  |   65  | 
|   60         GrGLSLFragmentBuilder* fsBuilder = pb->getFragmentShaderBuilder(); |  | 
|   61         if (cte.maskFormat() == kARGB_GrMaskFormat) { |   66         if (cte.maskFormat() == kARGB_GrMaskFormat) { | 
|   62             fsBuilder->codeAppendf("%s = ", args.fOutputColor); |   67             fragBuilder->codeAppendf("%s = ", args.fOutputColor); | 
|   63             fsBuilder->appendTextureLookupAndModulate(args.fOutputColor, |   68             fragBuilder->appendTextureLookupAndModulate(args.fOutputColor, | 
|   64                                                       args.fSamplers[0], |   69                                                         args.fSamplers[0], | 
|   65                                                       v.fsIn(), |   70                                                         v.fsIn(), | 
|   66                                                       kVec2f_GrSLType); |   71                                                         kVec2f_GrSLType); | 
|   67             fsBuilder->codeAppend(";"); |   72             fragBuilder->codeAppend(";"); | 
|   68             fsBuilder->codeAppendf("%s = vec4(1);", args.fOutputCoverage); |   73             fragBuilder->codeAppendf("%s = vec4(1);", args.fOutputCoverage); | 
|   69         } else { |   74         } else { | 
|   70             fsBuilder->codeAppendf("%s = ", args.fOutputCoverage); |   75             fragBuilder->codeAppendf("%s = ", args.fOutputCoverage); | 
|   71             fsBuilder->appendTextureLookup(args.fSamplers[0], v.fsIn(), kVec2f_G
     rSLType); |   76             fragBuilder->appendTextureLookup(args.fSamplers[0], v.fsIn(), kVec2f
     _GrSLType); | 
|   72             fsBuilder->codeAppend(";"); |   77             fragBuilder->codeAppend(";"); | 
|   73             if (cte.maskFormat() == kA565_GrMaskFormat) { |   78             if (cte.maskFormat() == kA565_GrMaskFormat) { | 
|   74                 // set alpha to be max of rgb coverage |   79                 // set alpha to be max of rgb coverage | 
|   75                 fsBuilder->codeAppendf("%s.a = max(max(%s.r, %s.g), %s.b);", |   80                 fragBuilder->codeAppendf("%s.a = max(max(%s.r, %s.g), %s.b);", | 
|   76                                        args.fOutputCoverage, args.fOutputCoverag
     e, |   81                                          args.fOutputCoverage, args.fOutputCover
     age, | 
|   77                                        args.fOutputCoverage, args.fOutputCoverag
     e); |   82                                          args.fOutputCoverage, args.fOutputCover
     age); | 
|   78             } |   83             } | 
|   79         } |   84         } | 
|   80     } |   85     } | 
|   81  |   86  | 
|   82     void setData(const GrGLSLProgramDataManager& pdman, const GrPrimitiveProcess
     or& gp) override { |   87     void setData(const GrGLSLProgramDataManager& pdman, const GrPrimitiveProcess
     or& gp) override { | 
|   83         const GrBitmapTextGeoProc& btgp = gp.cast<GrBitmapTextGeoProc>(); |   88         const GrBitmapTextGeoProc& btgp = gp.cast<GrBitmapTextGeoProc>(); | 
|   84         if (btgp.color() != fColor && !btgp.hasVertexColor()) { |   89         if (btgp.color() != fColor && !btgp.hasVertexColor()) { | 
|   85             float c[4]; |   90             float c[4]; | 
|   86             GrColorToRGBAFloat(btgp.color(), c); |   91             GrColorToRGBAFloat(btgp.color(), c); | 
|   87             pdman.set4fv(fColorUniform, 1, c); |   92             pdman.set4fv(fColorUniform, 1, c); | 
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  184             break; |  189             break; | 
|  185         case 2: |  190         case 2: | 
|  186             format = kARGB_GrMaskFormat; |  191             format = kARGB_GrMaskFormat; | 
|  187             break; |  192             break; | 
|  188     } |  193     } | 
|  189  |  194  | 
|  190     return GrBitmapTextGeoProc::Create(GrRandomColor(d->fRandom), d->fTextures[t
     exIdx], params, |  195     return GrBitmapTextGeoProc::Create(GrRandomColor(d->fRandom), d->fTextures[t
     exIdx], params, | 
|  191                                        format, GrTest::TestMatrix(d->fRandom), |  196                                        format, GrTest::TestMatrix(d->fRandom), | 
|  192                                        d->fRandom->nextBool()); |  197                                        d->fRandom->nextBool()); | 
|  193 } |  198 } | 
| OLD | NEW |