Debian Codegraph @

src/gpu/ganesh/glsl/GrGLSLProgramDataManager.h

raw
1 /*
2 * Copyright 2015 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 #ifndef GrGLSLProgramDataManager_DEFINED
9 #define GrGLSLProgramDataManager_DEFINED
10
11 #include "include/core/SkSpan.h"
12 #include "include/core/SkTypes.h"
13 #include "include/effects/SkRuntimeEffect.h"
14 #include "include/private/base/SkNoncopyable.h"
15 #include "src/gpu/ganesh/GrResourceHandle.h"
16
17 #include <cstdint>
18
19 class SkM44;
20 class SkMatrix;
21
22 /** Manages the resources used by a shader program.
23 * The resources are objects the program uses to communicate with the
24 * application code.
25 */
26 class GrGLSLProgramDataManager {
27 public:
28 GR_DEFINE_RESOURCE_HANDLE_CLASS(UniformHandle)
29
30 virtual ~GrGLSLProgramDataManager() {}
31
32 /** Functions for uploading uniform values. The varities ending in v can be used to upload to an
33 * array of uniforms. arrayCount must be <= the array count of the uniform.
34 */
35 virtual void set1i(UniformHandle, int32_t) const = 0;
36 virtual void set1iv(UniformHandle, int arrayCount, const int v[]) const = 0;
37 virtual void set1f(UniformHandle, float v0) const = 0;
38 virtual void set1fv(UniformHandle, int arrayCount, const float v[]) const = 0;
39 virtual void set2i(UniformHandle, int32_t, int32_t) const = 0;
40 virtual void set2iv(UniformHandle, int arrayCount, const int v[]) const = 0;
41 virtual void set2f(UniformHandle, float, float) const = 0;
42 virtual void set2fv(UniformHandle, int arrayCount, const float v[]) const = 0;
43 virtual void set3i(UniformHandle, int32_t, int32_t, int32_t) const = 0;
44 virtual void set3iv(UniformHandle, int arrayCount, const int v[]) const = 0;
45 virtual void set3f(UniformHandle, float, float, float) const = 0;
46 virtual void set3fv(UniformHandle, int arrayCount, const float v[]) const = 0;
47 virtual void set4i(UniformHandle, int32_t, int32_t, int32_t, int32_t) const = 0;
48 virtual void set4iv(UniformHandle, int arrayCount, const int v[]) const = 0;
49 virtual void set4f(UniformHandle, float, float, float, float) const = 0;
50 virtual void set4fv(UniformHandle, int arrayCount, const float v[]) const = 0;
51 // matrices are column-major, the first three upload a single matrix, the latter three upload
52 // arrayCount matrices into a uniform array.
53 virtual void setMatrix2f(UniformHandle, const float matrix[]) const = 0;
54 virtual void setMatrix3f(UniformHandle, const float matrix[]) const = 0;
55 virtual void setMatrix4f(UniformHandle, const float matrix[]) const = 0;
56 virtual void setMatrix2fv(UniformHandle, int arrayCount, const float matrices[]) const = 0;
57 virtual void setMatrix3fv(UniformHandle, int arrayCount, const float matrices[]) const = 0;
58 virtual void setMatrix4fv(UniformHandle, int arrayCount, const float matrices[]) const = 0;
59
60 // convenience method for uploading a SkMatrix to a 3x3 matrix uniform
61 void setSkMatrix(UniformHandle, const SkMatrix&) const;
62 // convenience method for uploading a SkMatrix to a 4x4 matrix uniform
63 void setSkM44(UniformHandle, const SkM44&) const;
64
65 enum class Specialized : bool { kNo = false, kYes = true };
66
67 /**
68 * Sets runtime effect uniform values. The Specialized span is optional. If it is non-empty
69 * then it should be the same size as the Uniform span. Uniforms for which the Specialized value
70 * is kYes will be skipped and the UniformHandle span should have an entry for each
71 * kNo value. If Specialized is empty then the Uniform and UniformHandle spans should have the
72 * same size.
73 */
74 void setRuntimeEffectUniforms(SkSpan<const SkRuntimeEffect::Uniform>,
75 SkSpan<const UniformHandle>,
76 SkSpan<const Specialized>,
77 const void* src) const;
78
79 void setRuntimeEffectUniforms(SkSpan<const SkRuntimeEffect::Uniform> uniforms,
80 SkSpan<const UniformHandle> handles,
81 const void* src) const {
82 this->setRuntimeEffectUniforms(uniforms, handles, {}, src);
83 }
84
85 protected:
86 GrGLSLProgramDataManager() {}
87
88 private:
89 GrGLSLProgramDataManager(const GrGLSLProgramDataManager&) = delete;
90 GrGLSLProgramDataManager& operator=(const GrGLSLProgramDataManager&) = delete;
91
92 using INHERITED = SkNoncopyable;
93 };
94
95 #endif