| 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 "gl/GrGLFragmentProcessor.h" | 11 #include "gl/GrGLFragmentProcessor.h" |
| 12 #include "gl/GrGLTexture.h" | 12 #include "gl/GrGLTexture.h" |
| 13 #include "gl/GrGLGeometryProcessor.h" | 13 #include "gl/GrGLGeometryProcessor.h" |
| 14 #include "gl/builders/GrGLProgramBuilder.h" | 14 #include "glsl/GrGLSLFragmentShaderBuilder.h" |
| 15 #include "glsl/GrGLSLProgramBuilder.h" |
| 15 #include "glsl/GrGLSLProgramDataManager.h" | 16 #include "glsl/GrGLSLProgramDataManager.h" |
| 17 #include "glsl/GrGLSLVertexShaderBuilder.h" |
| 16 | 18 |
| 17 class GrGLBitmapTextGeoProc : public GrGLGeometryProcessor { | 19 class GrGLBitmapTextGeoProc : public GrGLGeometryProcessor { |
| 18 public: | 20 public: |
| 19 GrGLBitmapTextGeoProc() : fColor(GrColor_ILLEGAL) {} | 21 GrGLBitmapTextGeoProc() : fColor(GrColor_ILLEGAL) {} |
| 20 | 22 |
| 21 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override { | 23 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override { |
| 22 const GrBitmapTextGeoProc& cte = args.fGP.cast<GrBitmapTextGeoProc>(); | 24 const GrBitmapTextGeoProc& cte = args.fGP.cast<GrBitmapTextGeoProc>(); |
| 23 | 25 |
| 24 GrGLSLGPBuilder* pb = args.fPB; | 26 GrGLSLGPBuilder* pb = args.fPB; |
| 25 GrGLVertexBuilder* vsBuilder = pb->getVertexShaderBuilder(); | 27 GrGLSLVertexBuilder* vsBuilder = pb->getVertexShaderBuilder(); |
| 26 | 28 |
| 27 // emit attributes | 29 // emit attributes |
| 28 vsBuilder->emitAttributes(cte); | 30 vsBuilder->emitAttributes(cte); |
| 29 | 31 |
| 30 // compute numbers to be hardcoded to convert texture coordinates from i
nt to float | 32 // compute numbers to be hardcoded to convert texture coordinates from i
nt to float |
| 31 SkASSERT(cte.numTextures() == 1); | 33 SkASSERT(cte.numTextures() == 1); |
| 32 GrTexture* atlas = cte.textureAccess(0).getTexture(); | 34 GrTexture* atlas = cte.textureAccess(0).getTexture(); |
| 33 SkASSERT(atlas && SkIsPow2(atlas->width()) && SkIsPow2(atlas->height()))
; | 35 SkASSERT(atlas && SkIsPow2(atlas->width()) && SkIsPow2(atlas->height()))
; |
| 34 SkScalar recipWidth = 1.0f / atlas->width(); | 36 SkScalar recipWidth = 1.0f / atlas->width(); |
| 35 SkScalar recipHeight = 1.0f / atlas->height(); | 37 SkScalar recipHeight = 1.0f / atlas->height(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 50 } | 52 } |
| 51 } | 53 } |
| 52 | 54 |
| 53 // Setup position | 55 // Setup position |
| 54 this->setupPosition(pb, gpArgs, cte.inPosition()->fName); | 56 this->setupPosition(pb, gpArgs, cte.inPosition()->fName); |
| 55 | 57 |
| 56 // emit transforms | 58 // emit transforms |
| 57 this->emitTransforms(args.fPB, gpArgs->fPositionVar, cte.inPosition()->f
Name, | 59 this->emitTransforms(args.fPB, gpArgs->fPositionVar, cte.inPosition()->f
Name, |
| 58 cte.localMatrix(), args.fTransformsIn, args.fTransf
ormsOut); | 60 cte.localMatrix(), args.fTransformsIn, args.fTransf
ormsOut); |
| 59 | 61 |
| 60 GrGLFragmentBuilder* fsBuilder = pb->getFragmentShaderBuilder(); | 62 GrGLSLFragmentBuilder* fsBuilder = pb->getFragmentShaderBuilder(); |
| 61 if (cte.maskFormat() == kARGB_GrMaskFormat) { | 63 if (cte.maskFormat() == kARGB_GrMaskFormat) { |
| 62 fsBuilder->codeAppendf("%s = ", args.fOutputColor); | 64 fsBuilder->codeAppendf("%s = ", args.fOutputColor); |
| 63 fsBuilder->appendTextureLookupAndModulate(args.fOutputColor, | 65 fsBuilder->appendTextureLookupAndModulate(args.fOutputColor, |
| 64 args.fSamplers[0], | 66 args.fSamplers[0], |
| 65 v.fsIn(), | 67 v.fsIn(), |
| 66 kVec2f_GrSLType); | 68 kVec2f_GrSLType); |
| 67 fsBuilder->codeAppend(";"); | 69 fsBuilder->codeAppend(";"); |
| 68 fsBuilder->codeAppendf("%s = vec4(1);", args.fOutputCoverage); | 70 fsBuilder->codeAppendf("%s = vec4(1);", args.fOutputCoverage); |
| 69 } else { | 71 } else { |
| 70 fsBuilder->codeAppendf("%s = ", args.fOutputCoverage); | 72 fsBuilder->codeAppendf("%s = ", args.fOutputCoverage); |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 break; | 185 break; |
| 184 case 2: | 186 case 2: |
| 185 format = kARGB_GrMaskFormat; | 187 format = kARGB_GrMaskFormat; |
| 186 break; | 188 break; |
| 187 } | 189 } |
| 188 | 190 |
| 189 return GrBitmapTextGeoProc::Create(GrRandomColor(d->fRandom), d->fTextures[t
exIdx], params, | 191 return GrBitmapTextGeoProc::Create(GrRandomColor(d->fRandom), d->fTextures[t
exIdx], params, |
| 190 format, GrTest::TestMatrix(d->fRandom), | 192 format, GrTest::TestMatrix(d->fRandom), |
| 191 d->fRandom->nextBool()); | 193 d->fRandom->nextBool()); |
| 192 } | 194 } |
| OLD | NEW |