blob: 0d7a2996c4cfb7ca26ead0bc8630fa2683c195d1 [file] [log] [blame]
Ethan Nicholas58430122020-04-14 09:54:02 -04001/*
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
Michael Ludwige88320b2020-06-24 09:04:56 -040013GrShaderVar GrGLSLUniformHandler::getUniformMapping(const GrFragmentProcessor& owner,
14 SkString rawName) const {
Ethan Nicholas58430122020-04-14 09:54:02 -040015 for (int i = this->numUniforms() - 1; i >= 0; i--) {
Michael Ludwige88320b2020-06-24 09:04:56 -040016 const UniformInfo& u = this->uniform(i);
17 if (u.fOwner == &owner && u.fRawName == rawName) {
18 return u.fVariable;
Ethan Nicholas58430122020-04-14 09:54:02 -040019 }
20 }
Michael Ludwige88320b2020-06-24 09:04:56 -040021 return GrShaderVar();
22}
23
24GrShaderVar 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 const/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();
Ethan Nicholas58430122020-04-14 09:54:02 -040037}