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