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 "gl/builders/GrGLProgramBuilder.h" |
15 | 15 |
16 class GrGLBitmapTextGeoProc : public GrGLGeometryProcessor { | 16 class GrGLBitmapTextGeoProc : public GrGLGeometryProcessor { |
17 public: | 17 public: |
18 GrGLBitmapTextGeoProc(const GrGeometryProcessor&, const GrBatchTracker&) | 18 GrGLBitmapTextGeoProc() : fColor(GrColor_ILLEGAL) {} |
19 : fColor(GrColor_ILLEGAL) {} | |
20 | 19 |
21 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{ | 20 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override { |
22 const GrBitmapTextGeoProc& cte = args.fGP.cast<GrBitmapTextGeoProc>(); | 21 const GrBitmapTextGeoProc& cte = args.fGP.cast<GrBitmapTextGeoProc>(); |
23 | 22 |
24 GrGLGPBuilder* pb = args.fPB; | 23 GrGLGPBuilder* pb = args.fPB; |
25 GrGLVertexBuilder* vsBuilder = pb->getVertexShaderBuilder(); | 24 GrGLVertexBuilder* vsBuilder = pb->getVertexShaderBuilder(); |
26 | 25 |
27 // emit attributes | 26 // emit attributes |
28 vsBuilder->emitAttributes(cte); | 27 vsBuilder->emitAttributes(cte); |
29 | 28 |
30 // compute numbers to be hardcoded to convert texture coordinates from i
nt to float | 29 // compute numbers to be hardcoded to convert texture coordinates from i
nt to float |
31 SkASSERT(cte.numTextures() == 1); | 30 SkASSERT(cte.numTextures() == 1); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 kVec2f_GrSLType); | 65 kVec2f_GrSLType); |
67 fsBuilder->codeAppend(";"); | 66 fsBuilder->codeAppend(";"); |
68 fsBuilder->codeAppendf("%s = vec4(1);", args.fOutputCoverage); | 67 fsBuilder->codeAppendf("%s = vec4(1);", args.fOutputCoverage); |
69 } else { | 68 } else { |
70 fsBuilder->codeAppendf("%s = ", args.fOutputCoverage); | 69 fsBuilder->codeAppendf("%s = ", args.fOutputCoverage); |
71 fsBuilder->appendTextureLookup(args.fSamplers[0], v.fsIn(), kVec2f_G
rSLType); | 70 fsBuilder->appendTextureLookup(args.fSamplers[0], v.fsIn(), kVec2f_G
rSLType); |
72 fsBuilder->codeAppend(";"); | 71 fsBuilder->codeAppend(";"); |
73 } | 72 } |
74 } | 73 } |
75 | 74 |
76 virtual void setData(const GrGLProgramDataManager& pdman, | 75 void setData(const GrGLProgramDataManager& pdman, const GrPrimitiveProcessor
& gp) override { |
77 const GrPrimitiveProcessor& gp, | |
78 const GrBatchTracker& bt) override { | |
79 const GrBitmapTextGeoProc& btgp = gp.cast<GrBitmapTextGeoProc>(); | 76 const GrBitmapTextGeoProc& btgp = gp.cast<GrBitmapTextGeoProc>(); |
80 if (btgp.color() != fColor && !btgp.hasVertexColor()) { | 77 if (btgp.color() != fColor && !btgp.hasVertexColor()) { |
81 GrGLfloat c[4]; | 78 GrGLfloat c[4]; |
82 GrColorToRGBAFloat(btgp.color(), c); | 79 GrColorToRGBAFloat(btgp.color(), c); |
83 pdman.set4fv(fColorUniform, 1, c); | 80 pdman.set4fv(fColorUniform, 1, c); |
84 fColor = btgp.color(); | 81 fColor = btgp.color(); |
85 } | 82 } |
86 } | 83 } |
87 | 84 |
88 void setTransformData(const GrPrimitiveProcessor& primProc, | 85 void setTransformData(const GrPrimitiveProcessor& primProc, |
89 const GrGLProgramDataManager& pdman, | 86 const GrGLProgramDataManager& pdman, |
90 int index, | 87 int index, |
91 const SkTArray<const GrCoordTransform*, true>& transfo
rms) override { | 88 const SkTArray<const GrCoordTransform*, true>& transfo
rms) override { |
92 this->setTransformDataHelper<GrBitmapTextGeoProc>(primProc, pdman, index
, transforms); | 89 this->setTransformDataHelper<GrBitmapTextGeoProc>(primProc, pdman, index
, transforms); |
93 } | 90 } |
94 | 91 |
95 static inline void GenKey(const GrGeometryProcessor& proc, | 92 static inline void GenKey(const GrGeometryProcessor& proc, |
96 const GrBatchTracker& bt, | |
97 const GrGLSLCaps&, | 93 const GrGLSLCaps&, |
98 GrProcessorKeyBuilder* b) { | 94 GrProcessorKeyBuilder* b) { |
99 const GrBitmapTextGeoProc& gp = proc.cast<GrBitmapTextGeoProc>(); | 95 const GrBitmapTextGeoProc& gp = proc.cast<GrBitmapTextGeoProc>(); |
100 uint32_t key = 0; | 96 uint32_t key = 0; |
101 key |= gp.usesLocalCoords() && gp.localMatrix().hasPerspective() ? 0x1 :
0x0; | 97 key |= gp.usesLocalCoords() && gp.localMatrix().hasPerspective() ? 0x1 :
0x0; |
102 key |= gp.colorIgnored() ? 0x2 : 0x0; | 98 key |= gp.colorIgnored() ? 0x2 : 0x0; |
103 key |= gp.maskFormat() << 3; | 99 key |= gp.maskFormat() << 3; |
104 b->add32(key); | 100 b->add32(key); |
105 | 101 |
106 // Currently we hardcode numbers to convert atlas coordinates to normali
zed floating point | 102 // Currently we hardcode numbers to convert atlas coordinates to normali
zed floating point |
(...skipping 29 matching lines...) Expand all Loading... |
136 // we don't do text positioning in batch, so we can't quite do that yet. | 132 // we don't do text positioning in batch, so we can't quite do that yet. |
137 bool hasVertexColor = kA8_GrMaskFormat == fMaskFormat; | 133 bool hasVertexColor = kA8_GrMaskFormat == fMaskFormat; |
138 if (hasVertexColor) { | 134 if (hasVertexColor) { |
139 fInColor = &this->addVertexAttrib(Attribute("inColor", kVec4ub_GrVertexA
ttribType)); | 135 fInColor = &this->addVertexAttrib(Attribute("inColor", kVec4ub_GrVertexA
ttribType)); |
140 } | 136 } |
141 fInTextureCoords = &this->addVertexAttrib(Attribute("inTextureCoords", | 137 fInTextureCoords = &this->addVertexAttrib(Attribute("inTextureCoords", |
142 kVec2s_GrVertexAttribTyp
e)); | 138 kVec2s_GrVertexAttribTyp
e)); |
143 this->addTextureAccess(&fTextureAccess); | 139 this->addTextureAccess(&fTextureAccess); |
144 } | 140 } |
145 | 141 |
146 void GrBitmapTextGeoProc::getGLProcessorKey(const GrBatchTracker& bt, | 142 void GrBitmapTextGeoProc::getGLProcessorKey(const GrGLSLCaps& caps,GrProcessorKe
yBuilder* b) const { |
147 const GrGLSLCaps& caps, | 143 GrGLBitmapTextGeoProc::GenKey(*this, caps, b); |
148 GrProcessorKeyBuilder* b) const { | |
149 GrGLBitmapTextGeoProc::GenKey(*this, bt, caps, b); | |
150 } | 144 } |
151 | 145 |
152 GrGLPrimitiveProcessor* | 146 GrGLPrimitiveProcessor* GrBitmapTextGeoProc::createGLInstance(const GrGLSLCaps&
caps) const { |
153 GrBitmapTextGeoProc::createGLInstance(const GrBatchTracker& bt, | 147 return new GrGLBitmapTextGeoProc(); |
154 const GrGLSLCaps& caps) const { | |
155 return new GrGLBitmapTextGeoProc(*this, bt); | |
156 } | 148 } |
157 | 149 |
158 /////////////////////////////////////////////////////////////////////////////// | 150 /////////////////////////////////////////////////////////////////////////////// |
159 | 151 |
160 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrBitmapTextGeoProc); | 152 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrBitmapTextGeoProc); |
161 | 153 |
162 const GrGeometryProcessor* GrBitmapTextGeoProc::TestCreate(GrProcessorTestData*
d) { | 154 const GrGeometryProcessor* GrBitmapTextGeoProc::TestCreate(GrProcessorTestData*
d) { |
163 int texIdx = d->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx
: | 155 int texIdx = d->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx
: |
164 GrProcessorUnitTest::kAlphaTextureIdx; | 156 GrProcessorUnitTest::kAlphaTextureIdx; |
165 static const SkShader::TileMode kTileModes[] = { | 157 static const SkShader::TileMode kTileModes[] = { |
(...skipping 18 matching lines...) Expand all Loading... |
184 break; | 176 break; |
185 case 2: | 177 case 2: |
186 format = kARGB_GrMaskFormat; | 178 format = kARGB_GrMaskFormat; |
187 break; | 179 break; |
188 } | 180 } |
189 | 181 |
190 return GrBitmapTextGeoProc::Create(GrRandomColor(d->fRandom), d->fTextures[t
exIdx], params, | 182 return GrBitmapTextGeoProc::Create(GrRandomColor(d->fRandom), d->fTextures[t
exIdx], params, |
191 format, GrTest::TestMatrix(d->fRandom), | 183 format, GrTest::TestMatrix(d->fRandom), |
192 d->fRandom->nextBool()); | 184 d->fRandom->nextBool()); |
193 } | 185 } |
OLD | NEW |