tomhudson@google.com | f9ad886 | 2012-05-11 20:38:48 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "gl/GrGLShaderBuilder.h" |
tomhudson@google.com | 5259814 | 2012-05-24 17:44:30 +0000 | [diff] [blame] | 9 | #include "gl/GrGLProgram.h" |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 10 | #include "gl/GrGLUniformHandle.h" |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame^] | 11 | #include "GrDrawEffect.h" |
twiz@google.com | a5e65ec | 2012-08-02 15:15:16 +0000 | [diff] [blame] | 12 | #include "GrTexture.h" |
tomhudson@google.com | f9ad886 | 2012-05-11 20:38:48 +0000 | [diff] [blame] | 13 | |
tomhudson@google.com | f9ad886 | 2012-05-11 20:38:48 +0000 | [diff] [blame] | 14 | // number of each input/output type in a single allocation block |
bsalomon@google.com | eb715c8 | 2012-07-11 15:03:31 +0000 | [diff] [blame] | 15 | static const int kVarsPerBlock = 8; |
tomhudson@google.com | f9ad886 | 2012-05-11 20:38:48 +0000 | [diff] [blame] | 16 | |
| 17 | // except FS outputs where we expect 2 at most. |
bsalomon@google.com | eb715c8 | 2012-07-11 15:03:31 +0000 | [diff] [blame] | 18 | static const int kMaxFSOutputs = 2; |
tomhudson@google.com | f9ad886 | 2012-05-11 20:38:48 +0000 | [diff] [blame] | 19 | |
bsalomon@google.com | d7727ce | 2012-07-12 16:40:03 +0000 | [diff] [blame] | 20 | // ES2 FS only guarantees mediump and lowp support |
| 21 | static const GrGLShaderVar::Precision kDefaultFragmentPrecision = GrGLShaderVar::kMedium_Precision; |
| 22 | |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 23 | typedef GrGLUniformManager::UniformHandle UniformHandle; |
| 24 | /////////////////////////////////////////////////////////////////////////////// |
| 25 | |
bsalomon@google.com | 34bcb9f | 2012-08-28 18:20:18 +0000 | [diff] [blame] | 26 | namespace { |
twiz@google.com | a5e65ec | 2012-08-02 15:15:16 +0000 | [diff] [blame] | 27 | |
bsalomon@google.com | 2b1b8c0 | 2013-02-28 22:06:02 +0000 | [diff] [blame] | 28 | inline const char* sample_function_name(GrSLType type, GrGLSLGeneration glslGen) { |
bsalomon@google.com | 34bcb9f | 2012-08-28 18:20:18 +0000 | [diff] [blame] | 29 | if (kVec2f_GrSLType == type) { |
bsalomon@google.com | 2b1b8c0 | 2013-02-28 22:06:02 +0000 | [diff] [blame] | 30 | return glslGen >= k130_GrGLSLGeneration ? "texture" : "texture2D"; |
bsalomon@google.com | 34bcb9f | 2012-08-28 18:20:18 +0000 | [diff] [blame] | 31 | } else { |
| 32 | GrAssert(kVec3f_GrSLType == type); |
bsalomon@google.com | 2b1b8c0 | 2013-02-28 22:06:02 +0000 | [diff] [blame] | 33 | return glslGen >= k130_GrGLSLGeneration ? "textureProj" : "texture2DProj"; |
bsalomon@google.com | 34bcb9f | 2012-08-28 18:20:18 +0000 | [diff] [blame] | 34 | } |
twiz@google.com | a5e65ec | 2012-08-02 15:15:16 +0000 | [diff] [blame] | 35 | } |
| 36 | |
bsalomon@google.com | 6d003d1 | 2012-09-11 15:45:20 +0000 | [diff] [blame] | 37 | /** |
| 38 | * Do we need to either map r,g,b->a or a->r. |
| 39 | */ |
| 40 | inline bool swizzle_requires_alpha_remapping(const GrGLCaps& caps, |
| 41 | const GrTextureAccess& access) { |
| 42 | if (GrPixelConfigIsAlphaOnly(access.getTexture()->config())) { |
| 43 | if (caps.textureRedSupport() && (GrTextureAccess::kA_SwizzleFlag & access.swizzleMask())) { |
| 44 | return true; |
| 45 | } |
| 46 | if (GrTextureAccess::kRGB_SwizzleMask & access.swizzleMask()) { |
| 47 | return true; |
twiz@google.com | a5e65ec | 2012-08-02 15:15:16 +0000 | [diff] [blame] | 48 | } |
| 49 | } |
bsalomon@google.com | 6d003d1 | 2012-09-11 15:45:20 +0000 | [diff] [blame] | 50 | return false; |
| 51 | } |
twiz@google.com | a5e65ec | 2012-08-02 15:15:16 +0000 | [diff] [blame] | 52 | |
bsalomon@google.com | 6d003d1 | 2012-09-11 15:45:20 +0000 | [diff] [blame] | 53 | void append_swizzle(SkString* outAppend, |
| 54 | const GrTextureAccess& access, |
| 55 | const GrGLCaps& caps) { |
| 56 | const char* swizzle = access.getSwizzle(); |
| 57 | char mangledSwizzle[5]; |
| 58 | |
| 59 | // The swizzling occurs using texture params instead of shader-mangling if ARB_texture_swizzle |
| 60 | // is available. |
| 61 | if (!caps.textureSwizzleSupport() && GrPixelConfigIsAlphaOnly(access.getTexture()->config())) { |
| 62 | char alphaChar = caps.textureRedSupport() ? 'r' : 'a'; |
| 63 | int i; |
| 64 | for (i = 0; '\0' != swizzle[i]; ++i) { |
| 65 | mangledSwizzle[i] = alphaChar; |
| 66 | } |
| 67 | mangledSwizzle[i] ='\0'; |
| 68 | swizzle = mangledSwizzle; |
| 69 | } |
bsalomon@google.com | 73d5b2f | 2012-10-04 13:26:32 +0000 | [diff] [blame] | 70 | // For shader prettiness we omit the swizzle rather than appending ".rgba". |
| 71 | if (memcmp(swizzle, "rgba", 4)) { |
| 72 | outAppend->appendf(".%s", swizzle); |
| 73 | } |
twiz@google.com | a5e65ec | 2012-08-02 15:15:16 +0000 | [diff] [blame] | 74 | } |
| 75 | |
bsalomon@google.com | 34bcb9f | 2012-08-28 18:20:18 +0000 | [diff] [blame] | 76 | } |
| 77 | |
twiz@google.com | a5e65ec | 2012-08-02 15:15:16 +0000 | [diff] [blame] | 78 | /////////////////////////////////////////////////////////////////////////////// |
| 79 | |
tomhudson@google.com | 9c639a4 | 2012-05-14 19:58:06 +0000 | [diff] [blame] | 80 | // Architectural assumption: always 2-d input coords. |
| 81 | // Likely to become non-constant and non-static, perhaps even |
| 82 | // varying by stage, if we use 1D textures for gradients! |
| 83 | //const int GrGLShaderBuilder::fCoordDims = 2; |
| 84 | |
skia.committer@gmail.com | 631cdcb | 2013-03-01 12:12:55 +0000 | [diff] [blame] | 85 | GrGLShaderBuilder::GrGLShaderBuilder(const GrGLContextInfo& ctxInfo, |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame^] | 86 | GrGLUniformManager& uniformManager, |
| 87 | bool explicitLocalCoords) |
bsalomon@google.com | 032b221 | 2012-07-16 13:36:18 +0000 | [diff] [blame] | 88 | : fUniforms(kVarsPerBlock) |
bsalomon@google.com | eb715c8 | 2012-07-11 15:03:31 +0000 | [diff] [blame] | 89 | , fVSAttrs(kVarsPerBlock) |
| 90 | , fVSOutputs(kVarsPerBlock) |
| 91 | , fGSInputs(kVarsPerBlock) |
| 92 | , fGSOutputs(kVarsPerBlock) |
| 93 | , fFSInputs(kVarsPerBlock) |
bsalomon@google.com | eb715c8 | 2012-07-11 15:03:31 +0000 | [diff] [blame] | 94 | , fFSOutputs(kMaxFSOutputs) |
tomhudson@google.com | 040c41a | 2012-05-18 14:57:40 +0000 | [diff] [blame] | 95 | , fUsesGS(false) |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 96 | , fCtxInfo(ctxInfo) |
bsalomon@google.com | 777c3aa | 2012-07-25 20:58:20 +0000 | [diff] [blame] | 97 | , fUniformManager(uniformManager) |
bsalomon@google.com | 08283af | 2012-10-26 13:01:20 +0000 | [diff] [blame] | 98 | , fCurrentStageIdx(kNonStageIdx) |
bsalomon@google.com | 706f668 | 2012-10-23 14:53:55 +0000 | [diff] [blame] | 99 | , fSetupFragPosition(false) |
bsalomon@google.com | dbe49f7 | 2012-11-05 16:36:02 +0000 | [diff] [blame] | 100 | , fRTHeightUniform(GrGLUniformManager::kInvalidUniformHandle) { |
skia.committer@gmail.com | e862d16 | 2012-10-31 02:01:18 +0000 | [diff] [blame] | 101 | |
bsalomon@google.com | 17504f5 | 2012-10-30 12:34:25 +0000 | [diff] [blame] | 102 | fPositionVar = &fVSAttrs.push_back(); |
| 103 | fPositionVar->set(kVec2f_GrSLType, GrGLShaderVar::kAttribute_TypeModifier, "aPosition"); |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame^] | 104 | if (explicitLocalCoords) { |
| 105 | fLocalCoordsVar = &fVSAttrs.push_back(); |
| 106 | fLocalCoordsVar->set(kVec2f_GrSLType, |
| 107 | GrGLShaderVar::kAttribute_TypeModifier, |
| 108 | "aLocalCoords"); |
| 109 | } else { |
| 110 | fLocalCoordsVar = fPositionVar; |
| 111 | } |
tomhudson@google.com | f9ad886 | 2012-05-11 20:38:48 +0000 | [diff] [blame] | 112 | } |
| 113 | |
bsalomon@google.com | f910d3b | 2013-03-07 17:06:57 +0000 | [diff] [blame] | 114 | void GrGLShaderBuilder::codeAppendf(ShaderType type, const char format[], va_list args) { |
sugoi@google.com | 9c55f80 | 2013-03-07 20:52:59 +0000 | [diff] [blame] | 115 | SkString* string = NULL; |
bsalomon@google.com | f910d3b | 2013-03-07 17:06:57 +0000 | [diff] [blame] | 116 | switch (type) { |
| 117 | case kVertex_ShaderType: |
| 118 | string = &fVSCode; |
| 119 | break; |
| 120 | case kGeometry_ShaderType: |
| 121 | string = &fGSCode; |
| 122 | break; |
| 123 | case kFragment_ShaderType: |
| 124 | string = &fFSCode; |
| 125 | break; |
| 126 | default: |
| 127 | GrCrash("Invalid shader type"); |
| 128 | } |
| 129 | string->appendf(format, args); |
| 130 | } |
| 131 | |
| 132 | void GrGLShaderBuilder::codeAppend(ShaderType type, const char* str) { |
sugoi@google.com | 9c55f80 | 2013-03-07 20:52:59 +0000 | [diff] [blame] | 133 | SkString* string = NULL; |
bsalomon@google.com | f910d3b | 2013-03-07 17:06:57 +0000 | [diff] [blame] | 134 | switch (type) { |
| 135 | case kVertex_ShaderType: |
| 136 | string = &fVSCode; |
| 137 | break; |
| 138 | case kGeometry_ShaderType: |
| 139 | string = &fGSCode; |
| 140 | break; |
| 141 | case kFragment_ShaderType: |
| 142 | string = &fFSCode; |
| 143 | break; |
| 144 | default: |
| 145 | GrCrash("Invalid shader type"); |
| 146 | } |
| 147 | string->append(str); |
| 148 | } |
| 149 | |
bsalomon@google.com | 868a8e7 | 2012-08-30 19:11:34 +0000 | [diff] [blame] | 150 | void GrGLShaderBuilder::appendTextureLookup(SkString* out, |
bsalomon@google.com | f06df1b | 2012-09-06 20:22:31 +0000 | [diff] [blame] | 151 | const GrGLShaderBuilder::TextureSampler& sampler, |
bsalomon@google.com | 868a8e7 | 2012-08-30 19:11:34 +0000 | [diff] [blame] | 152 | const char* coordName, |
| 153 | GrSLType varyingType) const { |
bsalomon@google.com | 2d8edaf | 2012-09-07 14:47:31 +0000 | [diff] [blame] | 154 | GrAssert(NULL != sampler.textureAccess()); |
bsalomon@google.com | dbe49f7 | 2012-11-05 16:36:02 +0000 | [diff] [blame] | 155 | GrAssert(NULL != coordName); |
bsalomon@google.com | 2d8edaf | 2012-09-07 14:47:31 +0000 | [diff] [blame] | 156 | |
bsalomon@google.com | 6d003d1 | 2012-09-11 15:45:20 +0000 | [diff] [blame] | 157 | out->appendf("%s(%s, %s)", |
bsalomon@google.com | 2b1b8c0 | 2013-02-28 22:06:02 +0000 | [diff] [blame] | 158 | sample_function_name(varyingType, fCtxInfo.glslGeneration()), |
bsalomon@google.com | f06df1b | 2012-09-06 20:22:31 +0000 | [diff] [blame] | 159 | this->getUniformCStr(sampler.fSamplerUniform), |
bsalomon@google.com | 6d003d1 | 2012-09-11 15:45:20 +0000 | [diff] [blame] | 160 | coordName); |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 161 | append_swizzle(out, *sampler.textureAccess(), fCtxInfo.caps()); |
tomhudson@google.com | 5259814 | 2012-05-24 17:44:30 +0000 | [diff] [blame] | 162 | } |
| 163 | |
bsalomon@google.com | f910d3b | 2013-03-07 17:06:57 +0000 | [diff] [blame] | 164 | void GrGLShaderBuilder::appendTextureLookup(ShaderType type, |
| 165 | const GrGLShaderBuilder::TextureSampler& sampler, |
| 166 | const char* coordName, |
| 167 | GrSLType varyingType) { |
| 168 | GrAssert(kFragment_ShaderType == type); |
| 169 | this->appendTextureLookup(&fFSCode, sampler, coordName, varyingType); |
| 170 | } |
| 171 | |
bsalomon@google.com | f06df1b | 2012-09-06 20:22:31 +0000 | [diff] [blame] | 172 | void GrGLShaderBuilder::appendTextureLookupAndModulate( |
bsalomon@google.com | f910d3b | 2013-03-07 17:06:57 +0000 | [diff] [blame] | 173 | ShaderType type, |
bsalomon@google.com | f06df1b | 2012-09-06 20:22:31 +0000 | [diff] [blame] | 174 | const char* modulation, |
| 175 | const GrGLShaderBuilder::TextureSampler& sampler, |
| 176 | const char* coordName, |
bsalomon@google.com | f910d3b | 2013-03-07 17:06:57 +0000 | [diff] [blame] | 177 | GrSLType varyingType) { |
| 178 | GrAssert(kFragment_ShaderType == type); |
bsalomon@google.com | 868a8e7 | 2012-08-30 19:11:34 +0000 | [diff] [blame] | 179 | SkString lookup; |
bsalomon@google.com | f06df1b | 2012-09-06 20:22:31 +0000 | [diff] [blame] | 180 | this->appendTextureLookup(&lookup, sampler, coordName, varyingType); |
bsalomon@google.com | f910d3b | 2013-03-07 17:06:57 +0000 | [diff] [blame] | 181 | GrGLSLModulate4f(&fFSCode, modulation, lookup.c_str()); |
tomhudson@google.com | 5259814 | 2012-05-24 17:44:30 +0000 | [diff] [blame] | 182 | } |
| 183 | |
bsalomon@google.com | 2eaaefd | 2012-10-29 19:51:22 +0000 | [diff] [blame] | 184 | GrBackendEffectFactory::EffectKey GrGLShaderBuilder::KeyForTextureAccess( |
| 185 | const GrTextureAccess& access, |
| 186 | const GrGLCaps& caps) { |
| 187 | GrBackendEffectFactory::EffectKey key = 0; |
bsalomon@google.com | d472620 | 2012-08-03 14:34:46 +0000 | [diff] [blame] | 188 | |
twiz@google.com | a5e65ec | 2012-08-02 15:15:16 +0000 | [diff] [blame] | 189 | // Assume that swizzle support implies that we never have to modify a shader to adjust |
| 190 | // for texture format/swizzle settings. |
bsalomon@google.com | 6d003d1 | 2012-09-11 15:45:20 +0000 | [diff] [blame] | 191 | if (!caps.textureSwizzleSupport() && swizzle_requires_alpha_remapping(caps, access)) { |
twiz@google.com | a5e65ec | 2012-08-02 15:15:16 +0000 | [diff] [blame] | 192 | key = 1; |
| 193 | } |
bsalomon@google.com | 73d5b2f | 2012-10-04 13:26:32 +0000 | [diff] [blame] | 194 | #if GR_DEBUG |
| 195 | // Assert that key is set iff the swizzle will be modified. |
| 196 | SkString origString(access.getSwizzle()); |
| 197 | origString.prepend("."); |
| 198 | SkString modifiedString; |
| 199 | append_swizzle(&modifiedString, access, caps); |
| 200 | if (!modifiedString.size()) { |
| 201 | modifiedString = ".rgba"; |
| 202 | } |
| 203 | GrAssert(SkToBool(key) == (modifiedString != origString)); |
| 204 | #endif |
twiz@google.com | a5e65ec | 2012-08-02 15:15:16 +0000 | [diff] [blame] | 205 | return key; |
| 206 | } |
| 207 | |
bsalomon@google.com | 6d003d1 | 2012-09-11 15:45:20 +0000 | [diff] [blame] | 208 | const GrGLenum* GrGLShaderBuilder::GetTexParamSwizzle(GrPixelConfig config, const GrGLCaps& caps) { |
| 209 | if (caps.textureSwizzleSupport() && GrPixelConfigIsAlphaOnly(config)) { |
| 210 | if (caps.textureRedSupport()) { |
| 211 | static const GrGLenum gRedSmear[] = { GR_GL_RED, GR_GL_RED, GR_GL_RED, GR_GL_RED }; |
| 212 | return gRedSmear; |
| 213 | } else { |
| 214 | static const GrGLenum gAlphaSmear[] = { GR_GL_ALPHA, GR_GL_ALPHA, |
| 215 | GR_GL_ALPHA, GR_GL_ALPHA }; |
| 216 | return gAlphaSmear; |
| 217 | } |
| 218 | } else { |
| 219 | static const GrGLenum gStraight[] = { GR_GL_RED, GR_GL_GREEN, GR_GL_BLUE, GR_GL_ALPHA }; |
| 220 | return gStraight; |
| 221 | } |
| 222 | } |
| 223 | |
bsalomon@google.com | 777c3aa | 2012-07-25 20:58:20 +0000 | [diff] [blame] | 224 | GrGLUniformManager::UniformHandle GrGLShaderBuilder::addUniformArray(uint32_t visibility, |
| 225 | GrSLType type, |
| 226 | const char* name, |
| 227 | int count, |
| 228 | const char** outName) { |
tomhudson@google.com | 242ed6f | 2012-05-30 17:38:57 +0000 | [diff] [blame] | 229 | GrAssert(name && strlen(name)); |
humper@google.com | 0e51577 | 2013-01-07 19:54:40 +0000 | [diff] [blame] | 230 | SkDEBUGCODE(static const uint32_t kVisibilityMask = kVertex_ShaderType | kFragment_ShaderType); |
bsalomon@google.com | eb715c8 | 2012-07-11 15:03:31 +0000 | [diff] [blame] | 231 | GrAssert(0 == (~kVisibilityMask & visibility)); |
| 232 | GrAssert(0 != visibility); |
tomhudson@google.com | 242ed6f | 2012-05-30 17:38:57 +0000 | [diff] [blame] | 233 | |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 234 | BuilderUniform& uni = fUniforms.push_back(); |
bsalomon@google.com | 032b221 | 2012-07-16 13:36:18 +0000 | [diff] [blame] | 235 | UniformHandle h = index_to_handle(fUniforms.count() - 1); |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 236 | GR_DEBUGCODE(UniformHandle h2 =) |
| 237 | fUniformManager.appendUniform(type, count); |
| 238 | // We expect the uniform manager to initially have no uniforms and that all uniforms are added |
| 239 | // by this function. Therefore, the handles should match. |
| 240 | GrAssert(h2 == h); |
bsalomon@google.com | 032b221 | 2012-07-16 13:36:18 +0000 | [diff] [blame] | 241 | uni.fVariable.setType(type); |
| 242 | uni.fVariable.setTypeModifier(GrGLShaderVar::kUniform_TypeModifier); |
bsalomon@google.com | 777c3aa | 2012-07-25 20:58:20 +0000 | [diff] [blame] | 243 | SkString* uniName = uni.fVariable.accessName(); |
bsalomon@google.com | 08283af | 2012-10-26 13:01:20 +0000 | [diff] [blame] | 244 | if (kNonStageIdx == fCurrentStageIdx) { |
bsalomon@google.com | 777c3aa | 2012-07-25 20:58:20 +0000 | [diff] [blame] | 245 | uniName->printf("u%s", name); |
| 246 | } else { |
bsalomon@google.com | 08283af | 2012-10-26 13:01:20 +0000 | [diff] [blame] | 247 | uniName->printf("u%s%d", name, fCurrentStageIdx); |
tomhudson@google.com | 242ed6f | 2012-05-30 17:38:57 +0000 | [diff] [blame] | 248 | } |
bsalomon@google.com | 032b221 | 2012-07-16 13:36:18 +0000 | [diff] [blame] | 249 | uni.fVariable.setArrayCount(count); |
| 250 | uni.fVisibility = visibility; |
tomhudson@google.com | 242ed6f | 2012-05-30 17:38:57 +0000 | [diff] [blame] | 251 | |
bsalomon@google.com | 032b221 | 2012-07-16 13:36:18 +0000 | [diff] [blame] | 252 | // If it is visible in both the VS and FS, the precision must match. |
| 253 | // We declare a default FS precision, but not a default VS. So set the var |
| 254 | // to use the default FS precision. |
bsalomon@google.com | eb715c8 | 2012-07-11 15:03:31 +0000 | [diff] [blame] | 255 | if ((kVertex_ShaderType | kFragment_ShaderType) == visibility) { |
bsalomon@google.com | d7727ce | 2012-07-12 16:40:03 +0000 | [diff] [blame] | 256 | // the fragment and vertex precisions must match |
bsalomon@google.com | 032b221 | 2012-07-16 13:36:18 +0000 | [diff] [blame] | 257 | uni.fVariable.setPrecision(kDefaultFragmentPrecision); |
tomhudson@google.com | 242ed6f | 2012-05-30 17:38:57 +0000 | [diff] [blame] | 258 | } |
| 259 | |
bsalomon@google.com | 777c3aa | 2012-07-25 20:58:20 +0000 | [diff] [blame] | 260 | if (NULL != outName) { |
| 261 | *outName = uni.fVariable.c_str(); |
| 262 | } |
| 263 | |
bsalomon@google.com | 032b221 | 2012-07-16 13:36:18 +0000 | [diff] [blame] | 264 | return h; |
| 265 | } |
| 266 | |
| 267 | const GrGLShaderVar& GrGLShaderBuilder::getUniformVariable(UniformHandle u) const { |
| 268 | return fUniforms[handle_to_index(u)].fVariable; |
tomhudson@google.com | 242ed6f | 2012-05-30 17:38:57 +0000 | [diff] [blame] | 269 | } |
tomhudson@google.com | 23cb229 | 2012-05-30 18:26:03 +0000 | [diff] [blame] | 270 | |
commit-bot@chromium.org | ff6ea26 | 2013-03-12 12:26:08 +0000 | [diff] [blame] | 271 | bool GrGLShaderBuilder::addAttribute(GrSLType type, |
| 272 | const char* name) { |
| 273 | for (int i = 0; i < fVSAttrs.count(); ++i) { |
| 274 | const GrGLShaderVar& attr = fVSAttrs[i]; |
| 275 | // if attribute already added, don't add it again |
| 276 | if (attr.getName().equals(name)) { |
| 277 | GrAssert(attr.getType() == type); |
| 278 | return false; |
| 279 | } |
| 280 | } |
| 281 | fVSAttrs.push_back().set(type, |
| 282 | GrGLShaderVar::kAttribute_TypeModifier, |
| 283 | name); |
| 284 | return true; |
| 285 | } |
| 286 | |
tomhudson@google.com | 23cb229 | 2012-05-30 18:26:03 +0000 | [diff] [blame] | 287 | void GrGLShaderBuilder::addVarying(GrSLType type, |
| 288 | const char* name, |
| 289 | const char** vsOutName, |
| 290 | const char** fsInName) { |
| 291 | fVSOutputs.push_back(); |
| 292 | fVSOutputs.back().setType(type); |
| 293 | fVSOutputs.back().setTypeModifier(GrGLShaderVar::kOut_TypeModifier); |
bsalomon@google.com | 08283af | 2012-10-26 13:01:20 +0000 | [diff] [blame] | 294 | if (kNonStageIdx == fCurrentStageIdx) { |
bsalomon@google.com | 777c3aa | 2012-07-25 20:58:20 +0000 | [diff] [blame] | 295 | fVSOutputs.back().accessName()->printf("v%s", name); |
| 296 | } else { |
bsalomon@google.com | 08283af | 2012-10-26 13:01:20 +0000 | [diff] [blame] | 297 | fVSOutputs.back().accessName()->printf("v%s%d", name, fCurrentStageIdx); |
bsalomon@google.com | 777c3aa | 2012-07-25 20:58:20 +0000 | [diff] [blame] | 298 | } |
tomhudson@google.com | 23cb229 | 2012-05-30 18:26:03 +0000 | [diff] [blame] | 299 | if (vsOutName) { |
| 300 | *vsOutName = fVSOutputs.back().getName().c_str(); |
| 301 | } |
| 302 | // input to FS comes either from VS or GS |
bsalomon@google.com | f0a104e | 2012-07-10 17:51:07 +0000 | [diff] [blame] | 303 | const SkString* fsName; |
tomhudson@google.com | 23cb229 | 2012-05-30 18:26:03 +0000 | [diff] [blame] | 304 | if (fUsesGS) { |
| 305 | // if we have a GS take each varying in as an array |
| 306 | // and output as non-array. |
| 307 | fGSInputs.push_back(); |
| 308 | fGSInputs.back().setType(type); |
| 309 | fGSInputs.back().setTypeModifier(GrGLShaderVar::kIn_TypeModifier); |
| 310 | fGSInputs.back().setUnsizedArray(); |
| 311 | *fGSInputs.back().accessName() = fVSOutputs.back().getName(); |
| 312 | fGSOutputs.push_back(); |
| 313 | fGSOutputs.back().setType(type); |
| 314 | fGSOutputs.back().setTypeModifier(GrGLShaderVar::kOut_TypeModifier); |
bsalomon@google.com | 08283af | 2012-10-26 13:01:20 +0000 | [diff] [blame] | 315 | if (kNonStageIdx == fCurrentStageIdx) { |
bsalomon@google.com | d472620 | 2012-08-03 14:34:46 +0000 | [diff] [blame] | 316 | fGSOutputs.back().accessName()->printf("g%s", name); |
| 317 | } else { |
bsalomon@google.com | 08283af | 2012-10-26 13:01:20 +0000 | [diff] [blame] | 318 | fGSOutputs.back().accessName()->printf("g%s%d", name, fCurrentStageIdx); |
bsalomon@google.com | d472620 | 2012-08-03 14:34:46 +0000 | [diff] [blame] | 319 | } |
tomhudson@google.com | 23cb229 | 2012-05-30 18:26:03 +0000 | [diff] [blame] | 320 | fsName = fGSOutputs.back().accessName(); |
| 321 | } else { |
| 322 | fsName = fVSOutputs.back().accessName(); |
| 323 | } |
| 324 | fFSInputs.push_back(); |
| 325 | fFSInputs.back().setType(type); |
| 326 | fFSInputs.back().setTypeModifier(GrGLShaderVar::kIn_TypeModifier); |
| 327 | fFSInputs.back().setName(*fsName); |
| 328 | if (fsInName) { |
| 329 | *fsInName = fsName->c_str(); |
| 330 | } |
| 331 | } |
| 332 | |
bsalomon@google.com | 706f668 | 2012-10-23 14:53:55 +0000 | [diff] [blame] | 333 | const char* GrGLShaderBuilder::fragmentPosition() { |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 334 | #if 1 |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 335 | if (fCtxInfo.caps().fragCoordConventionsSupport()) { |
bsalomon@google.com | 706f668 | 2012-10-23 14:53:55 +0000 | [diff] [blame] | 336 | if (!fSetupFragPosition) { |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 337 | if (fCtxInfo.glslGeneration() < k150_GrGLSLGeneration) { |
| 338 | fFSHeader.append("#extension GL_ARB_fragment_coord_conventions: require\n"); |
| 339 | } |
bsalomon@google.com | 5fa2107 | 2012-10-25 14:57:46 +0000 | [diff] [blame] | 340 | fFSInputs.push_back().set(kVec4f_GrSLType, |
| 341 | GrGLShaderVar::kIn_TypeModifier, |
| 342 | "gl_FragCoord", |
| 343 | GrGLShaderVar::kDefault_Precision, |
| 344 | GrGLShaderVar::kUpperLeft_Origin); |
bsalomon@google.com | 706f668 | 2012-10-23 14:53:55 +0000 | [diff] [blame] | 345 | fSetupFragPosition = true; |
| 346 | } |
skia.committer@gmail.com | 1e34ff7 | 2012-10-24 02:01:24 +0000 | [diff] [blame] | 347 | return "gl_FragCoord"; |
bsalomon@google.com | 706f668 | 2012-10-23 14:53:55 +0000 | [diff] [blame] | 348 | } else { |
| 349 | static const char* kCoordName = "fragCoordYDown"; |
| 350 | if (!fSetupFragPosition) { |
| 351 | GrAssert(GrGLUniformManager::kInvalidUniformHandle == fRTHeightUniform); |
| 352 | const char* rtHeightName; |
skia.committer@gmail.com | 1e34ff7 | 2012-10-24 02:01:24 +0000 | [diff] [blame] | 353 | |
bsalomon@google.com | 706f668 | 2012-10-23 14:53:55 +0000 | [diff] [blame] | 354 | // temporarily change the stage index because we're inserting a uniform whose name |
| 355 | // shouldn't be mangled to be stage-specific. |
bsalomon@google.com | 08283af | 2012-10-26 13:01:20 +0000 | [diff] [blame] | 356 | int oldStageIdx = fCurrentStageIdx; |
| 357 | fCurrentStageIdx = kNonStageIdx; |
bsalomon@google.com | 706f668 | 2012-10-23 14:53:55 +0000 | [diff] [blame] | 358 | fRTHeightUniform = this->addUniform(kFragment_ShaderType, |
| 359 | kFloat_GrSLType, |
| 360 | "RTHeight", |
| 361 | &rtHeightName); |
bsalomon@google.com | 08283af | 2012-10-26 13:01:20 +0000 | [diff] [blame] | 362 | fCurrentStageIdx = oldStageIdx; |
skia.committer@gmail.com | 1e34ff7 | 2012-10-24 02:01:24 +0000 | [diff] [blame] | 363 | |
bsalomon@google.com | 706f668 | 2012-10-23 14:53:55 +0000 | [diff] [blame] | 364 | this->fFSCode.prependf("\tvec4 %s = vec4(gl_FragCoord.x, %s - gl_FragCoord.y, gl_FragCoord.zw);\n", |
| 365 | kCoordName, rtHeightName); |
| 366 | fSetupFragPosition = true; |
| 367 | } |
| 368 | GrAssert(GrGLUniformManager::kInvalidUniformHandle != fRTHeightUniform); |
| 369 | return kCoordName; |
| 370 | } |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 371 | #else |
| 372 | // This is the path we'll need to use once we have support for TopLeft |
| 373 | // render targets. |
| 374 | if (!fSetupFragPosition) { |
| 375 | fFSInputs.push_back().set(kVec4f_GrSLType, |
| 376 | GrGLShaderVar::kIn_TypeModifier, |
| 377 | "gl_FragCoord", |
| 378 | GrGLShaderVar::kDefault_Precision); |
| 379 | fSetupFragPosition = true; |
| 380 | } |
| 381 | return "gl_FragCoord"; |
| 382 | #endif |
bsalomon@google.com | 706f668 | 2012-10-23 14:53:55 +0000 | [diff] [blame] | 383 | } |
| 384 | |
| 385 | |
bsalomon@google.com | a1bf0ff | 2012-08-07 17:36:29 +0000 | [diff] [blame] | 386 | void GrGLShaderBuilder::emitFunction(ShaderType shader, |
| 387 | GrSLType returnType, |
| 388 | const char* name, |
| 389 | int argCnt, |
| 390 | const GrGLShaderVar* args, |
| 391 | const char* body, |
| 392 | SkString* outName) { |
| 393 | GrAssert(kFragment_ShaderType == shader); |
| 394 | fFSFunctions.append(GrGLShaderVar::TypeString(returnType)); |
bsalomon@google.com | 08283af | 2012-10-26 13:01:20 +0000 | [diff] [blame] | 395 | if (kNonStageIdx != fCurrentStageIdx) { |
| 396 | outName->printf(" %s_%d", name, fCurrentStageIdx); |
bsalomon@google.com | a1bf0ff | 2012-08-07 17:36:29 +0000 | [diff] [blame] | 397 | } else { |
| 398 | *outName = name; |
| 399 | } |
| 400 | fFSFunctions.append(*outName); |
| 401 | fFSFunctions.append("("); |
| 402 | for (int i = 0; i < argCnt; ++i) { |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 403 | args[i].appendDecl(fCtxInfo, &fFSFunctions); |
bsalomon@google.com | a1bf0ff | 2012-08-07 17:36:29 +0000 | [diff] [blame] | 404 | if (i < argCnt - 1) { |
| 405 | fFSFunctions.append(", "); |
| 406 | } |
| 407 | } |
| 408 | fFSFunctions.append(") {\n"); |
| 409 | fFSFunctions.append(body); |
| 410 | fFSFunctions.append("}\n\n"); |
| 411 | } |
tomhudson@google.com | 23cb229 | 2012-05-30 18:26:03 +0000 | [diff] [blame] | 412 | |
bsalomon@google.com | ad5e937 | 2012-07-11 18:11:27 +0000 | [diff] [blame] | 413 | namespace { |
bsalomon@google.com | d7727ce | 2012-07-12 16:40:03 +0000 | [diff] [blame] | 414 | |
| 415 | inline void append_default_precision_qualifier(GrGLShaderVar::Precision p, |
| 416 | GrGLBinding binding, |
| 417 | SkString* str) { |
| 418 | // Desktop GLSL has added precision qualifiers but they don't do anything. |
| 419 | if (kES2_GrGLBinding == binding) { |
| 420 | switch (p) { |
| 421 | case GrGLShaderVar::kHigh_Precision: |
| 422 | str->append("precision highp float;\n"); |
| 423 | break; |
| 424 | case GrGLShaderVar::kMedium_Precision: |
| 425 | str->append("precision mediump float;\n"); |
| 426 | break; |
| 427 | case GrGLShaderVar::kLow_Precision: |
| 428 | str->append("precision lowp float;\n"); |
| 429 | break; |
| 430 | case GrGLShaderVar::kDefault_Precision: |
| 431 | GrCrash("Default precision now allowed."); |
| 432 | default: |
| 433 | GrCrash("Unknown precision value."); |
| 434 | } |
| 435 | } |
| 436 | } |
bsalomon@google.com | 032b221 | 2012-07-16 13:36:18 +0000 | [diff] [blame] | 437 | } |
bsalomon@google.com | d7727ce | 2012-07-12 16:40:03 +0000 | [diff] [blame] | 438 | |
bsalomon@google.com | 032b221 | 2012-07-16 13:36:18 +0000 | [diff] [blame] | 439 | void GrGLShaderBuilder::appendDecls(const VarArray& vars, SkString* out) const { |
bsalomon@google.com | ad5e937 | 2012-07-11 18:11:27 +0000 | [diff] [blame] | 440 | for (int i = 0; i < vars.count(); ++i) { |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 441 | vars[i].appendDecl(fCtxInfo, out); |
bsalomon@google.com | a1bf0ff | 2012-08-07 17:36:29 +0000 | [diff] [blame] | 442 | out->append(";\n"); |
bsalomon@google.com | ad5e937 | 2012-07-11 18:11:27 +0000 | [diff] [blame] | 443 | } |
| 444 | } |
bsalomon@google.com | 032b221 | 2012-07-16 13:36:18 +0000 | [diff] [blame] | 445 | |
| 446 | void GrGLShaderBuilder::appendUniformDecls(ShaderType stype, SkString* out) const { |
| 447 | for (int i = 0; i < fUniforms.count(); ++i) { |
| 448 | if (fUniforms[i].fVisibility & stype) { |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 449 | fUniforms[i].fVariable.appendDecl(fCtxInfo, out); |
bsalomon@google.com | a1bf0ff | 2012-08-07 17:36:29 +0000 | [diff] [blame] | 450 | out->append(";\n"); |
bsalomon@google.com | 032b221 | 2012-07-16 13:36:18 +0000 | [diff] [blame] | 451 | } |
| 452 | } |
bsalomon@google.com | ad5e937 | 2012-07-11 18:11:27 +0000 | [diff] [blame] | 453 | } |
| 454 | |
| 455 | void GrGLShaderBuilder::getShader(ShaderType type, SkString* shaderStr) const { |
| 456 | switch (type) { |
| 457 | case kVertex_ShaderType: |
| 458 | *shaderStr = fHeader; |
bsalomon@google.com | 032b221 | 2012-07-16 13:36:18 +0000 | [diff] [blame] | 459 | this->appendUniformDecls(kVertex_ShaderType, shaderStr); |
| 460 | this->appendDecls(fVSAttrs, shaderStr); |
| 461 | this->appendDecls(fVSOutputs, shaderStr); |
bsalomon@google.com | d7bafb7 | 2012-10-22 14:30:50 +0000 | [diff] [blame] | 462 | shaderStr->append("void main() {\n"); |
bsalomon@google.com | ad5e937 | 2012-07-11 18:11:27 +0000 | [diff] [blame] | 463 | shaderStr->append(fVSCode); |
bsalomon@google.com | d7bafb7 | 2012-10-22 14:30:50 +0000 | [diff] [blame] | 464 | shaderStr->append("}\n"); |
bsalomon@google.com | ad5e937 | 2012-07-11 18:11:27 +0000 | [diff] [blame] | 465 | break; |
| 466 | case kGeometry_ShaderType: |
| 467 | if (fUsesGS) { |
| 468 | *shaderStr = fHeader; |
| 469 | shaderStr->append(fGSHeader); |
bsalomon@google.com | 032b221 | 2012-07-16 13:36:18 +0000 | [diff] [blame] | 470 | this->appendDecls(fGSInputs, shaderStr); |
| 471 | this->appendDecls(fGSOutputs, shaderStr); |
bsalomon@google.com | d7bafb7 | 2012-10-22 14:30:50 +0000 | [diff] [blame] | 472 | shaderStr->append("void main() {\n"); |
bsalomon@google.com | ad5e937 | 2012-07-11 18:11:27 +0000 | [diff] [blame] | 473 | shaderStr->append(fGSCode); |
bsalomon@google.com | d7bafb7 | 2012-10-22 14:30:50 +0000 | [diff] [blame] | 474 | shaderStr->append("}\n"); |
bsalomon@google.com | ad5e937 | 2012-07-11 18:11:27 +0000 | [diff] [blame] | 475 | } else { |
| 476 | shaderStr->reset(); |
| 477 | } |
| 478 | break; |
| 479 | case kFragment_ShaderType: |
| 480 | *shaderStr = fHeader; |
bsalomon@google.com | d7727ce | 2012-07-12 16:40:03 +0000 | [diff] [blame] | 481 | append_default_precision_qualifier(kDefaultFragmentPrecision, |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 482 | fCtxInfo.binding(), |
bsalomon@google.com | d7727ce | 2012-07-12 16:40:03 +0000 | [diff] [blame] | 483 | shaderStr); |
bsalomon@google.com | 706f668 | 2012-10-23 14:53:55 +0000 | [diff] [blame] | 484 | shaderStr->append(fFSHeader); |
bsalomon@google.com | 032b221 | 2012-07-16 13:36:18 +0000 | [diff] [blame] | 485 | this->appendUniformDecls(kFragment_ShaderType, shaderStr); |
| 486 | this->appendDecls(fFSInputs, shaderStr); |
bsalomon@google.com | ad5e937 | 2012-07-11 18:11:27 +0000 | [diff] [blame] | 487 | // We shouldn't have declared outputs on 1.10 |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 488 | GrAssert(k110_GrGLSLGeneration != fCtxInfo.glslGeneration() || fFSOutputs.empty()); |
bsalomon@google.com | 032b221 | 2012-07-16 13:36:18 +0000 | [diff] [blame] | 489 | this->appendDecls(fFSOutputs, shaderStr); |
bsalomon@google.com | ad5e937 | 2012-07-11 18:11:27 +0000 | [diff] [blame] | 490 | shaderStr->append(fFSFunctions); |
bsalomon@google.com | d7bafb7 | 2012-10-22 14:30:50 +0000 | [diff] [blame] | 491 | shaderStr->append("void main() {\n"); |
bsalomon@google.com | ad5e937 | 2012-07-11 18:11:27 +0000 | [diff] [blame] | 492 | shaderStr->append(fFSCode); |
bsalomon@google.com | d7bafb7 | 2012-10-22 14:30:50 +0000 | [diff] [blame] | 493 | shaderStr->append("}\n"); |
bsalomon@google.com | ad5e937 | 2012-07-11 18:11:27 +0000 | [diff] [blame] | 494 | break; |
| 495 | } |
bsalomon@google.com | ad5e937 | 2012-07-11 18:11:27 +0000 | [diff] [blame] | 496 | } |
bsalomon@google.com | d7727ce | 2012-07-12 16:40:03 +0000 | [diff] [blame] | 497 | |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 498 | void GrGLShaderBuilder::finished(GrGLuint programID) { |
| 499 | fUniformManager.getUniformLocations(programID, fUniforms); |
| 500 | } |
bsalomon@google.com | 34cccde | 2013-01-04 18:34:30 +0000 | [diff] [blame] | 501 | |
| 502 | GrGLEffect* GrGLShaderBuilder::createAndEmitGLEffect( |
| 503 | const GrEffectStage& stage, |
| 504 | GrGLEffect::EffectKey key, |
| 505 | const char* fsInColor, |
| 506 | const char* fsOutColor, |
bsalomon@google.com | 34cccde | 2013-01-04 18:34:30 +0000 | [diff] [blame] | 507 | SkTArray<GrGLUniformManager::UniformHandle, true>* samplerHandles) { |
| 508 | GrAssert(NULL != stage.getEffect()); |
| 509 | |
bsalomon@google.com | 6340a41 | 2013-01-22 19:55:59 +0000 | [diff] [blame] | 510 | const GrEffectRef& effect = *stage.getEffect(); |
| 511 | int numTextures = effect->numTextures(); |
bsalomon@google.com | 34cccde | 2013-01-04 18:34:30 +0000 | [diff] [blame] | 512 | SkSTArray<8, GrGLShaderBuilder::TextureSampler> textureSamplers; |
| 513 | textureSamplers.push_back_n(numTextures); |
| 514 | for (int i = 0; i < numTextures; ++i) { |
bsalomon@google.com | 6340a41 | 2013-01-22 19:55:59 +0000 | [diff] [blame] | 515 | textureSamplers[i].init(this, &effect->textureAccess(i), i); |
bsalomon@google.com | 34cccde | 2013-01-04 18:34:30 +0000 | [diff] [blame] | 516 | samplerHandles->push_back(textureSamplers[i].fSamplerUniform); |
| 517 | } |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame^] | 518 | GrDrawEffect drawEffect(stage, this->hasExplicitLocalCoords()); |
bsalomon@google.com | 34cccde | 2013-01-04 18:34:30 +0000 | [diff] [blame] | 519 | |
commit-bot@chromium.org | ff6ea26 | 2013-03-12 12:26:08 +0000 | [diff] [blame] | 520 | int numAttributes = stage.getVertexAttribIndexCount(); |
| 521 | const int* attributeIndices = stage.getVertexAttribIndices(); |
| 522 | SkSTArray<GrEffect::kMaxVertexAttribs, SkString> attributeNames; |
| 523 | for (int i = 0; i < numAttributes; ++i) { |
| 524 | SkString attributeName("aAttr"); |
| 525 | attributeName.appendS32(attributeIndices[i]); |
| 526 | |
| 527 | if (this->addAttribute(effect->vertexAttribType(i), attributeName.c_str())) { |
| 528 | fEffectAttributes.push_back().set(attributeIndices[i], attributeName); |
| 529 | } |
| 530 | } |
| 531 | |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame^] | 532 | GrGLEffect* glEffect = effect->getFactory().createGLInstance(drawEffect); |
bsalomon@google.com | 34cccde | 2013-01-04 18:34:30 +0000 | [diff] [blame] | 533 | |
| 534 | // Enclose custom code in a block to avoid namespace conflicts |
| 535 | this->fVSCode.appendf("\t{ // %s\n", glEffect->name()); |
| 536 | this->fFSCode.appendf("\t{ // %s \n", glEffect->name()); |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame^] | 537 | |
bsalomon@google.com | 34cccde | 2013-01-04 18:34:30 +0000 | [diff] [blame] | 538 | glEffect->emitCode(this, |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame^] | 539 | drawEffect, |
bsalomon@google.com | 34cccde | 2013-01-04 18:34:30 +0000 | [diff] [blame] | 540 | key, |
bsalomon@google.com | 34cccde | 2013-01-04 18:34:30 +0000 | [diff] [blame] | 541 | fsOutColor, |
| 542 | fsInColor, |
| 543 | textureSamplers); |
| 544 | this->fVSCode.appendf("\t}\n"); |
| 545 | this->fFSCode.appendf("\t}\n"); |
| 546 | |
| 547 | return glEffect; |
| 548 | } |
commit-bot@chromium.org | ff6ea26 | 2013-03-12 12:26:08 +0000 | [diff] [blame] | 549 | |
| 550 | const SkString* GrGLShaderBuilder::getEffectAttributeName(int attributeIndex) const { |
| 551 | const AttributePair* attribEnd = this->getEffectAttributes().end(); |
skia.committer@gmail.com | 91274b9 | 2013-03-13 07:01:04 +0000 | [diff] [blame] | 552 | for (const AttributePair* attrib = this->getEffectAttributes().begin(); |
commit-bot@chromium.org | ff6ea26 | 2013-03-12 12:26:08 +0000 | [diff] [blame] | 553 | attrib != attribEnd; |
| 554 | ++attrib) { |
| 555 | if (attrib->fIndex == attributeIndex) { |
| 556 | return &attrib->fName; |
| 557 | } |
skia.committer@gmail.com | 91274b9 | 2013-03-13 07:01:04 +0000 | [diff] [blame] | 558 | } |
commit-bot@chromium.org | ff6ea26 | 2013-03-12 12:26:08 +0000 | [diff] [blame] | 559 | |
| 560 | return NULL; |
| 561 | } |