1 | /* |
---|---|
2 | * Copyright 2020 Google LLC |
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 "src/gpu/glsl/GrGLSLUniformHandler.h" |
9 | |
10 | #include "src/gpu/glsl/GrGLSL.h" |
11 | #include "src/gpu/glsl/GrGLSLShaderBuilder.h" |
12 | |
13 | GrShaderVar GrGLSLUniformHandler::getUniformMapping(const GrFragmentProcessor& owner, |
14 | SkString rawName) const { |
15 | for (int i = this->numUniforms() - 1; i >= 0; i--) { |
16 | const UniformInfo& u = this->uniform(i); |
17 | if (u.fOwner == &owner && u.fRawName == rawName) { |
18 | return u.fVariable; |
19 | } |
20 | } |
21 | return GrShaderVar(); |
22 | } |
23 | |
24 | GrShaderVar GrGLSLUniformHandler::liftUniformToVertexShader(const GrFragmentProcessor& owner, |
25 | SkString rawName) { |
26 | for (int i = this->numUniforms() - 1; i >= 0; i--) { |
27 | UniformInfo& u = this->uniform(i); |
28 | if (u.fOwner == &owner && u.fRawName == rawName) { |
29 | u.fVisibility |= kVertex_GrShaderFlag; |
30 | return u.fVariable; |
31 | } |
32 | } |
33 | // Uniform not found; it's better to return a void variable than to assert because sample |
34 | // matrices that are uniform are treated the same for most of the code. When the sample |
35 | // matrix expression can't be found as a uniform, we can infer it's a constant. |
36 | return GrShaderVar(); |
37 | } |
38 |