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