Flutter Engine
The Flutter Engine
GrGLProgram.h
Go to the documentation of this file.
1/*
2 * Copyright 2011 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
9#ifndef GrGLProgram_DEFINED
10#define GrGLProgram_DEFINED
11
18
19#include <vector>
20
21class GrPipeline;
23class GrProgramInfo;
24class GrRenderTarget;
25class GrTextureProxy;
26
27/**
28 * This class manages a GPU program and records per-program information. It also records the vertex
29 * and instance attribute layouts that are to be used with the program.
30 */
31class GrGLProgram : public SkRefCnt {
32public:
33 /**
34 * This class has its own Attribute representation as it does not need the name and we don't
35 * want to worry about copying the name string to memory with life time of GrGLProgram.
36 * Additionally, these store the attribute location.
37 */
38 struct Attribute {
41 size_t fOffset;
43 };
44
45 using UniformHandle = GrGLSLProgramDataManager::UniformHandle;
48
49 /**
50 * The attribute array consists of vertexAttributeCnt + instanceAttributeCnt elements with
51 * the vertex attributes preceding the instance attributes.
52 */
54 GrGLGpu*,
57 const UniformInfoArray& uniforms,
58 const UniformInfoArray& textureSamplers,
59 std::unique_ptr<GrGeometryProcessor::ProgramImpl>,
60 std::unique_ptr<GrXferProcessor::ProgramImpl>,
61 std::vector<std::unique_ptr<GrFragmentProcessor::ProgramImpl>> fps,
62 std::unique_ptr<Attribute[]>,
63 int vertexAttributeCnt,
64 int instanceAttributeCnt,
65 int vertexStride,
66 int instanceStride);
67
68 ~GrGLProgram() override;
69
70 /**
71 * Call to abandon GL objects owned by this program.
72 */
73 void abandon();
74
75 /**
76 * Gets the GL program ID for this program.
77 */
78 GrGLuint programID() const { return fProgramID; }
79
80 /**
81 * We use the RT's size and origin to adjust from Skia device space to OpenGL normalized device
82 * space and to make device space positions have the correct origin for processors that require
83 * them.
84 */
88
90 void invalidate() {
91 fRenderTargetSize.fWidth = -1;
94 }
95 };
96
97 /**
98 * This function uploads uniforms and calls each GrGLSL*Processor's setData.
99 *
100 * It is the caller's responsibility to ensure the program is bound before calling.
101 */
102 void updateUniforms(const GrRenderTarget*, const GrProgramInfo&);
103
104 /**
105 * Binds all geometry processor and fragment processor textures.
106 */
108 const GrSurfaceProxy* const geomProcTextures[],
109 const GrPipeline&);
110
111 int vertexStride() const { return fVertexStride; }
112 int instanceStride() const { return fInstanceStride; }
113
114 int numVertexAttributes() const { return fVertexAttributeCnt; }
115 const Attribute& vertexAttribute(int i) const {
116 SkASSERT(i >= 0 && i < fVertexAttributeCnt);
117 return fAttributes[i];
118 }
119
120 int numInstanceAttributes() const { return fInstanceAttributeCnt; }
121 const Attribute& instanceAttribute(int i) const {
122 SkASSERT(i >= 0 && i < fInstanceAttributeCnt);
123 return fAttributes[i + fVertexAttributeCnt];
124 }
125
126private:
130 const UniformInfoArray& uniforms,
131 const UniformInfoArray& textureSamplers,
132 std::unique_ptr<GrGeometryProcessor::ProgramImpl>,
133 std::unique_ptr<GrXferProcessor::ProgramImpl>,
134 std::vector<std::unique_ptr<GrFragmentProcessor::ProgramImpl>> fpImpls,
135 std::unique_ptr<Attribute[]>,
136 int vertexAttributeCnt,
137 int instanceAttributeCnt,
138 int vertexStride,
139 int instanceStride);
140
141 // Helper for setData() that sets the view matrix and loads the render target height uniform
142 void setRenderTargetState(const GrRenderTarget*, GrSurfaceOrigin, const GrGeometryProcessor&);
143
144 // these reflect the current values of uniforms (GL uniform values travel with program)
145 RenderTargetState fRenderTargetState;
146 GrGLSLBuiltinUniformHandles fBuiltinUniformHandles;
147 GrGLuint fProgramID;
148
149 // the installed effects
150 std::unique_ptr<GrGeometryProcessor::ProgramImpl> fGPImpl;
151 std::unique_ptr<GrXferProcessor::ProgramImpl> fXPImpl;
152 std::vector<std::unique_ptr<GrFragmentProcessor::ProgramImpl>> fFPImpls;
153
154 std::unique_ptr<Attribute[]> fAttributes;
155 int fVertexAttributeCnt;
156 int fInstanceAttributeCnt;
157 int fVertexStride;
158 int fInstanceStride;
159
160 GrGLGpu* fGpu;
161 GrGLProgramDataManager fProgramDataManager;
162
163 int fNumTextureSamplers;
164
165 using INHERITED = SkRefCnt;
166};
167
168#endif
unsigned int GrGLuint
Definition: GrGLTypes.h:113
int GrGLint
Definition: GrGLTypes.h:108
GrVertexAttribType
Definition: GrTypesPriv.h:312
GrSurfaceOrigin
Definition: GrTypes.h:147
#define SkASSERT(cond)
Definition: SkAssert.h:116
SkSLType
SkTBlockList< GLUniformInfo > UniformInfoArray
SkTBlockList< VaryingInfo > VaryingInfoArray
GrGLSLProgramDataManager::UniformHandle UniformHandle
Definition: GrGLProgram.h:45
int numVertexAttributes() const
Definition: GrGLProgram.h:114
int instanceStride() const
Definition: GrGLProgram.h:112
GrGLuint programID() const
Definition: GrGLProgram.h:78
const Attribute & vertexAttribute(int i) const
Definition: GrGLProgram.h:115
GrGLProgramDataManager::UniformInfoArray UniformInfoArray
Definition: GrGLProgram.h:46
int vertexStride() const
Definition: GrGLProgram.h:111
void bindTextures(const GrGeometryProcessor &, const GrSurfaceProxy *const geomProcTextures[], const GrPipeline &)
void abandon()
Definition: GrGLProgram.cpp:93
int numInstanceAttributes() const
Definition: GrGLProgram.h:120
void updateUniforms(const GrRenderTarget *, const GrProgramInfo &)
Definition: GrGLProgram.cpp:99
const Attribute & instanceAttribute(int i) const
Definition: GrGLProgram.h:121
~GrGLProgram() override
Definition: GrGLProgram.cpp:87
static sk_sp< GrGLProgram > Make(GrGLGpu *, const GrGLSLBuiltinUniformHandles &, GrGLuint programID, const UniformInfoArray &uniforms, const UniformInfoArray &textureSamplers, std::unique_ptr< GrGeometryProcessor::ProgramImpl >, std::unique_ptr< GrXferProcessor::ProgramImpl >, std::vector< std::unique_ptr< GrFragmentProcessor::ProgramImpl > > fps, std::unique_ptr< Attribute[]>, int vertexAttributeCnt, int instanceAttributeCnt, int vertexStride, int instanceStride)
Definition: GrGLProgram.cpp:27
GrVertexAttribType fCPUType
Definition: GrGLProgram.h:39
GrSurfaceOrigin fRenderTargetOrigin
Definition: GrGLProgram.h:87
Definition: SkSize.h:16
int32_t fHeight
Definition: SkSize.h:18
int32_t fWidth
Definition: SkSize.h:17