blob: fd1d6c8041d4f39c6e2fd44f35f5e8182c9a42f2 [file] [log] [blame]
joshualitt30ba4362014-08-21 20:18:45 -07001/*
2 * Copyright 2014 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 GrGLProgramBuilder_DEFINED
9#define GrGLProgramBuilder_DEFINED
10
joshualitt30ba4362014-08-21 20:18:45 -070011#include "GrGLFragmentShaderBuilder.h"
12#include "GrGLGeometryShaderBuilder.h"
13#include "GrGLVertexShaderBuilder.h"
joshualitt47bb3822014-10-07 16:43:25 -070014#include "../GrGLProgramDataManager.h"
15#include "../GrGLUniformHandle.h"
joshualitta5305a12014-10-10 17:47:00 -070016#include "../GrGLGeometryProcessor.h"
egdanielc2304142014-12-11 13:15:13 -080017#include "../GrGLXferProcessor.h"
bsalomon04ddf892014-11-19 12:36:22 -080018#include "../../GrOptDrawState.h"
bsalomonae59b772014-11-19 08:23:49 -080019#include "../../GrPendingFragmentStage.h"
joshualitt89c7a2e2014-10-10 14:11:59 -070020
joshualitt47bb3822014-10-07 16:43:25 -070021/*
22 * This is the base class for a series of interfaces. This base class *MUST* remain abstract with
23 * NO data members because it is used in multiple interface inheritance.
24 * Heirarchy:
25 * GrGLUniformBuilder
26 * / \
27 * GrGLFPBuilder GrGLGPBuilder
28 * \ /
29 * GrGLProgramBuilder(internal use only)
30 */
31class GrGLUniformBuilder {
joshualitt30ba4362014-08-21 20:18:45 -070032public:
33 enum ShaderVisibility {
bsalomon17168df2014-12-09 09:00:49 -080034 kVertex_Visibility = 1 << kVertex_GrShaderType,
35 kGeometry_Visibility = 1 << kGeometry_GrShaderType,
36 kFragment_Visibility = 1 << kFragment_GrShaderType,
joshualitt30ba4362014-08-21 20:18:45 -070037 };
38
joshualitt47bb3822014-10-07 16:43:25 -070039 virtual ~GrGLUniformBuilder() {}
40
joshualitt30ba4362014-08-21 20:18:45 -070041 typedef GrGLProgramDataManager::UniformHandle UniformHandle;
joshualitt47bb3822014-10-07 16:43:25 -070042
43 /** Add a uniform variable to the current program, that has visibility in one or more shaders.
44 visibility is a bitfield of ShaderVisibility values indicating from which shaders the
45 uniform should be accessible. At least one bit must be set. Geometry shader uniforms are not
46 supported at this time. The actual uniform name will be mangled. If outName is not NULL then
47 it will refer to the final uniform name after return. Use the addUniformArray variant to add
48 an array of uniforms. */
bsalomon422f56f2014-12-09 10:18:12 -080049 UniformHandle addUniform(uint32_t visibility,
50 GrSLType type,
51 GrSLPrecision precision,
52 const char* name,
53 const char** outName = NULL) {
54 return this->addUniformArray(visibility, type, precision, name, 0, outName);
55 }
56
57 virtual UniformHandle addUniformArray(
58 uint32_t visibility,
59 GrSLType type,
60 GrSLPrecision precision,
61 const char* name,
62 int arrayCount,
63 const char** outName = NULL) = 0;
joshualitt47bb3822014-10-07 16:43:25 -070064
65 virtual const GrGLShaderVar& getUniformVariable(UniformHandle u) const = 0;
66
67 /**
68 * Shortcut for getUniformVariable(u).c_str()
69 */
70 virtual const char* getUniformCStr(UniformHandle u) const = 0;
71
72 virtual const GrGLContextInfo& ctxInfo() const = 0;
73
bsalomon861e1032014-12-16 07:33:49 -080074 virtual GrGLGpu* gpu() const = 0;
joshualitt47bb3822014-10-07 16:43:25 -070075
76 /*
77 * *NOTE* NO MEMBERS ALLOWED, MULTIPLE INHERITANCE
78 */
79};
80
joshualitt74077b92014-10-24 11:26:03 -070081// TODO move this into GrGLGPBuilder and move them both out of this file
82class GrGLVarying {
83public:
84 bool vsVarying() const { return kVertToFrag_Varying == fVarying ||
85 kVertToGeo_Varying == fVarying; }
86 bool fsVarying() const { return kVertToFrag_Varying == fVarying ||
87 kGeoToFrag_Varying == fVarying; }
88 const char* vsOut() const { return fVsOut; }
89 const char* gsIn() const { return fGsIn; }
90 const char* gsOut() const { return fGsOut; }
91 const char* fsIn() const { return fFsIn; }
92
93protected:
94 enum Varying {
95 kVertToFrag_Varying,
96 kVertToGeo_Varying,
97 kGeoToFrag_Varying,
98 };
99
100 GrGLVarying(GrSLType type, Varying varying)
101 : fVarying(varying), fType(type), fVsOut(NULL), fGsIn(NULL), fGsOut(NULL),
102 fFsIn(NULL) {}
103
104 Varying fVarying;
105
106private:
107 GrSLType fType;
108 const char* fVsOut;
109 const char* fGsIn;
110 const char* fGsOut;
111 const char* fFsIn;
112
113 friend class GrGLVertexBuilder;
114 friend class GrGLGeometryBuilder;
egdanielc2304142014-12-11 13:15:13 -0800115 friend class GrGLXferBuilder;
joshualitt74077b92014-10-24 11:26:03 -0700116 friend class GrGLFragmentShaderBuilder;
117};
118
119struct GrGLVertToFrag : public GrGLVarying {
120 GrGLVertToFrag(GrSLType type)
121 : GrGLVarying(type, kVertToFrag_Varying) {}
122};
123
124struct GrGLVertToGeo : public GrGLVarying {
125 GrGLVertToGeo(GrSLType type)
126 : GrGLVarying(type, kVertToGeo_Varying) {}
127};
128
129struct GrGLGeoToFrag : public GrGLVarying {
130 GrGLGeoToFrag(GrSLType type)
131 : GrGLVarying(type, kGeoToFrag_Varying) {}
132};
133
joshualitt47bb3822014-10-07 16:43:25 -0700134/* a specialization of the above for GPs. Lets the user add uniforms, varyings, and VS / FS code */
135class GrGLGPBuilder : public virtual GrGLUniformBuilder {
136public:
joshualitt2dd1ae02014-12-03 06:24:10 -0800137 /*
138 * addVarying allows fine grained control for setting up varyings between stages. If you just
139 * need to take an attribute and pass it through to an output value in a fragment shader, use
140 * addPassThroughAttribute.
141 * TODO convert most uses of addVarying to addPassThroughAttribute
142 */
joshualitt74077b92014-10-24 11:26:03 -0700143 virtual void addVarying(const char* name,
144 GrGLVarying*,
bsalomonc0bd6482014-12-09 10:04:14 -0800145 GrSLPrecision fsPrecision = kDefault_GrSLPrecision) = 0;
joshualitt47bb3822014-10-07 16:43:25 -0700146
joshualitt2dd1ae02014-12-03 06:24:10 -0800147 /*
148 * This call can be used by GP to pass an attribute through all shaders directly to 'output' in
149 * the fragment shader. Though this call effects both the vertex shader and fragment shader,
150 * it expects 'output' to be defined in the fragment shader before this call is made.
151 * TODO it might be nicer behavior to have a flag to declare output inside this call
152 */
153 virtual void addPassThroughAttribute(const GrGeometryProcessor::GrAttribute*,
154 const char* output) = 0;
155
joshualitt47bb3822014-10-07 16:43:25 -0700156 // TODO rename getFragmentBuilder
157 virtual GrGLGPFragmentBuilder* getFragmentShaderBuilder() = 0;
158 virtual GrGLVertexBuilder* getVertexShaderBuilder() = 0;
159
160 /*
161 * *NOTE* NO MEMBERS ALLOWED, MULTIPLE INHERITANCE
162 */
163};
164
165/* a specializations for FPs. Lets the user add uniforms and FS code */
166class GrGLFPBuilder : public virtual GrGLUniformBuilder {
167public:
168 virtual GrGLFPFragmentBuilder* getFragmentShaderBuilder() = 0;
169
170 /*
171 * *NOTE* NO MEMBERS ALLOWED, MULTIPLE INHERITANCE
172 */
173};
174
egdanielc2304142014-12-11 13:15:13 -0800175/* a specializations for XPs. Lets the user add uniforms and FS code */
176class GrGLXPBuilder : public virtual GrGLUniformBuilder {
177public:
178 virtual GrGLFPFragmentBuilder* getFragmentShaderBuilder() = 0;
179
180 /*
181 * *NOTE* NO MEMBERS ALLOWED, MULTIPLE INHERITANCE
182 */
183};
joshualitta5305a12014-10-10 17:47:00 -0700184struct GrGLInstalledProc;
185struct GrGLInstalledGeoProc;
egdanielc2304142014-12-11 13:15:13 -0800186struct GrGLInstalledXferProc;
joshualitta5305a12014-10-10 17:47:00 -0700187struct GrGLInstalledFragProc;
188struct GrGLInstalledFragProcs;
189
joshualitt47bb3822014-10-07 16:43:25 -0700190/*
191 * Please note - no diamond problems because of virtual inheritance. Also, both base classes
192 * are pure virtual with no data members. This is the base class for program building.
193 * Subclasses are nearly identical but each has their own way of emitting transforms. State for
194 * each of the elements of the shader pipeline, ie vertex, fragment, geometry, etc, lives in those
195 * respective builders
196*/
197class GrGLProgramBuilder : public GrGLGPBuilder,
egdanielc2304142014-12-11 13:15:13 -0800198 public GrGLFPBuilder,
199 public GrGLXPBuilder {
joshualitt47bb3822014-10-07 16:43:25 -0700200public:
201 /** Generates a shader program.
202 *
203 * The program implements what is specified in the stages given as input.
204 * After successful generation, the builder result objects are available
205 * to be used.
206 * @return true if generation was successful.
207 */
bsalomon861e1032014-12-16 07:33:49 -0800208 static GrGLProgram* CreateProgram(const GrOptDrawState&, GrGLGpu*);
joshualitt47bb3822014-10-07 16:43:25 -0700209
bsalomon422f56f2014-12-09 10:18:12 -0800210 UniformHandle addUniformArray(uint32_t visibility,
211 GrSLType type,
212 GrSLPrecision precision,
213 const char* name,
214 int arrayCount,
215 const char** outName) SK_OVERRIDE;
joshualitt47bb3822014-10-07 16:43:25 -0700216
bsalomon422f56f2014-12-09 10:18:12 -0800217 const GrGLShaderVar& getUniformVariable(UniformHandle u) const SK_OVERRIDE {
joshualitt47bb3822014-10-07 16:43:25 -0700218 return fUniforms[u.toShaderBuilderIndex()].fVariable;
219 }
220
bsalomon422f56f2014-12-09 10:18:12 -0800221 const char* getUniformCStr(UniformHandle u) const SK_OVERRIDE {
joshualitt47bb3822014-10-07 16:43:25 -0700222 return this->getUniformVariable(u).c_str();
223 }
224
bsalomon422f56f2014-12-09 10:18:12 -0800225 const GrGLContextInfo& ctxInfo() const SK_OVERRIDE;
joshualitt47bb3822014-10-07 16:43:25 -0700226
bsalomon861e1032014-12-16 07:33:49 -0800227 GrGLGpu* gpu() const SK_OVERRIDE { return fGpu; }
joshualitt47bb3822014-10-07 16:43:25 -0700228
bsalomon422f56f2014-12-09 10:18:12 -0800229 GrGLFPFragmentBuilder* getFragmentShaderBuilder() SK_OVERRIDE { return &fFS; }
230 GrGLVertexBuilder* getVertexShaderBuilder() SK_OVERRIDE { return &fVS; }
joshualitt47bb3822014-10-07 16:43:25 -0700231
bsalomon422f56f2014-12-09 10:18:12 -0800232 void addVarying(
joshualitta5305a12014-10-10 17:47:00 -0700233 const char* name,
joshualitt74077b92014-10-24 11:26:03 -0700234 GrGLVarying*,
bsalomonc0bd6482014-12-09 10:04:14 -0800235 GrSLPrecision fsPrecision = kDefault_GrSLPrecision) SK_OVERRIDE;
joshualitt30ba4362014-08-21 20:18:45 -0700236
bsalomon422f56f2014-12-09 10:18:12 -0800237 void addPassThroughAttribute(const GrGeometryProcessor::GrAttribute*,
joshualitt2dd1ae02014-12-03 06:24:10 -0800238 const char* output) SK_OVERRIDE;
239
240
joshualitt30ba4362014-08-21 20:18:45 -0700241 // Handles for program uniforms (other than per-effect uniforms)
242 struct BuiltinUniformHandles {
joshualitt30ba4362014-08-21 20:18:45 -0700243 UniformHandle fRTAdjustmentUni;
joshualitt30ba4362014-08-21 20:18:45 -0700244
245 // We use the render target height to provide a y-down frag coord when specifying
246 // origin_upper_left is not supported.
247 UniformHandle fRTHeightUni;
248
249 // Uniforms for computing texture coords to do the dst-copy lookup
250 UniformHandle fDstCopyTopLeftUni;
251 UniformHandle fDstCopyScaleUni;
252 UniformHandle fDstCopySamplerUni;
253 };
254
joshualittdb0d3ca2014-10-07 12:42:26 -0700255protected:
joshualitta5305a12014-10-10 17:47:00 -0700256 typedef GrGLProgramDataManager::UniformInfo UniformInfo;
257 typedef GrGLProgramDataManager::UniformInfoArray UniformInfoArray;
258
joshualitt79f8fae2014-10-28 17:59:26 -0700259 static GrGLProgramBuilder* CreateProgramBuilder(const GrOptDrawState&,
joshualitt47bb3822014-10-07 16:43:25 -0700260 bool hasGeometryProcessor,
bsalomon861e1032014-12-16 07:33:49 -0800261 GrGLGpu*);
joshualitt47bb3822014-10-07 16:43:25 -0700262
bsalomon861e1032014-12-16 07:33:49 -0800263 GrGLProgramBuilder(GrGLGpu*, const GrOptDrawState&);
joshualitt30ba4362014-08-21 20:18:45 -0700264
egdaniel307796b2014-10-06 12:13:54 -0700265 const GrOptDrawState& optState() const { return fOptState; }
joshualitt79f8fae2014-10-28 17:59:26 -0700266 const GrProgramDesc& desc() const { return fDesc; }
267 const GrProgramDesc::KeyHeader& header() const { return fDesc.header(); }
joshualitt23e280d2014-09-18 12:26:38 -0700268
joshualitt30ba4362014-08-21 20:18:45 -0700269 // Generates a name for a variable. The generated string will be name prefixed by the prefix
270 // char (unless the prefix is '\0'). It also mangles the name to be stage-specific if we're
271 // generating stage code.
272 void nameVariable(SkString* out, char prefix, const char* name);
joshualitt2dd1ae02014-12-03 06:24:10 -0800273 // Generates a possibly mangled name for a stage variable and writes it to the fragment shader.
274 // If GrGLSLExpr4 has a valid name then it will use that instead
275 void nameExpression(GrGLSLExpr4*, const char* baseName);
joshualitt4973d9d2014-11-08 09:24:25 -0800276 void emitAndInstallProcs(GrGLSLExpr4* inputColor,
joshualitta5305a12014-10-10 17:47:00 -0700277 GrGLSLExpr4* inputCoverage);
278 void emitAndInstallFragProcs(int procOffset, int numProcs, GrGLSLExpr4* inOut);
joshualitt2dd1ae02014-12-03 06:24:10 -0800279 void emitAndInstallProc(const GrPendingFragmentStage&,
joshualitta5305a12014-10-10 17:47:00 -0700280 int index,
joshualitta5305a12014-10-10 17:47:00 -0700281 const GrGLSLExpr4& input,
282 GrGLSLExpr4* output);
283
joshualitt9b989322014-12-15 14:16:27 -0800284 void emitAndInstallProc(const GrPrimitiveProcessor&,
joshualitt2dd1ae02014-12-03 06:24:10 -0800285 GrGLSLExpr4* outputColor,
286 GrGLSLExpr4* outputCoverage);
287
joshualitta5305a12014-10-10 17:47:00 -0700288 // these emit functions help to keep the createAndEmitProcessors template general
bsalomonae59b772014-11-19 08:23:49 -0800289 void emitAndInstallProc(const GrPendingFragmentStage&,
joshualitta5305a12014-10-10 17:47:00 -0700290 const char* outColor,
291 const char* inColor);
joshualitt9b989322014-12-15 14:16:27 -0800292 void emitAndInstallProc(const GrPrimitiveProcessor&,
joshualitt2dd1ae02014-12-03 06:24:10 -0800293 const char* outColor,
294 const char* outCoverage);
egdanielc2304142014-12-11 13:15:13 -0800295 void emitAndInstallXferProc(const GrXferProcessor&,
296 const GrGLSLExpr4& colorIn,
297 const GrGLSLExpr4& coverageIn);
joshualitt2dd1ae02014-12-03 06:24:10 -0800298
joshualitt9b989322014-12-15 14:16:27 -0800299 void verify(const GrPrimitiveProcessor&);
egdanielc2304142014-12-11 13:15:13 -0800300 void verify(const GrXferProcessor&);
joshualitt47bb3822014-10-07 16:43:25 -0700301 void verify(const GrFragmentProcessor&);
302 void emitSamplers(const GrProcessor&,
303 GrGLProcessor::TextureSamplerArray* outSamplers,
joshualitta5305a12014-10-10 17:47:00 -0700304 GrGLInstalledProc*);
joshualitt30ba4362014-08-21 20:18:45 -0700305
joshualitt47bb3822014-10-07 16:43:25 -0700306 // each specific program builder has a distinct transform and must override this function
bsalomonae59b772014-11-19 08:23:49 -0800307 virtual void emitTransforms(const GrPendingFragmentStage&,
joshualitt47bb3822014-10-07 16:43:25 -0700308 GrGLProcessor::TransformedCoordsArray* outCoords,
joshualitta5305a12014-10-10 17:47:00 -0700309 GrGLInstalledFragProc*);
joshualitt47bb3822014-10-07 16:43:25 -0700310 GrGLProgram* finalize();
311 void bindUniformLocations(GrGLuint programID);
312 bool checkLinkStatus(GrGLuint programID);
313 void resolveUniformLocations(GrGLuint programID);
joshualitt47bb3822014-10-07 16:43:25 -0700314 void cleanupProgram(GrGLuint programID, const SkTDArray<GrGLuint>& shaderIDs);
315 void cleanupShaders(const SkTDArray<GrGLuint>& shaderIDs);
joshualitt30ba4362014-08-21 20:18:45 -0700316
joshualitt47bb3822014-10-07 16:43:25 -0700317 // Subclasses create different programs
318 virtual GrGLProgram* createProgram(GrGLuint programID);
319
joshualitt30ba4362014-08-21 20:18:45 -0700320 void appendUniformDecls(ShaderVisibility, SkString*) const;
321
joshualitt47bb3822014-10-07 16:43:25 -0700322 // reset is called by program creator between each processor's emit code. It increments the
323 // stage offset for variable name mangling, and also ensures verfication variables in the
324 // fragment shader are cleared.
325 void reset() {
326 this->enterStage();
327 this->addStage();
328 fFS.reset();
329 }
330 void addStage() { fStageIndex++; }
331
332 // This simple class exits the stage and then restores the stage when it goes out of scope
333 class AutoStageRestore {
joshualitt30ba4362014-08-21 20:18:45 -0700334 public:
joshualitt47bb3822014-10-07 16:43:25 -0700335 AutoStageRestore(GrGLProgramBuilder* pb)
336 : fPB(pb), fOutOfStage(pb->fOutOfStage) { pb->exitStage(); }
337 ~AutoStageRestore() { fPB->fOutOfStage = fOutOfStage; }
joshualittb0a8a372014-09-23 09:50:21 -0700338 private:
joshualitt47bb3822014-10-07 16:43:25 -0700339 GrGLProgramBuilder* fPB;
340 bool fOutOfStage;
joshualittb0a8a372014-09-23 09:50:21 -0700341 };
joshualitt47bb3822014-10-07 16:43:25 -0700342 class AutoStageAdvance {
joshualittdb0d3ca2014-10-07 12:42:26 -0700343 public:
joshualitt47bb3822014-10-07 16:43:25 -0700344 AutoStageAdvance(GrGLProgramBuilder* pb) : fPB(pb) { fPB->reset(); }
345 ~AutoStageAdvance() { fPB->exitStage(); }
joshualittdb0d3ca2014-10-07 12:42:26 -0700346 private:
joshualitt47bb3822014-10-07 16:43:25 -0700347 GrGLProgramBuilder* fPB;
348 };
349 void exitStage() { fOutOfStage = true; }
350 void enterStage() { fOutOfStage = false; }
351 int stageIndex() const { return fStageIndex; }
352
joshualitt4973d9d2014-11-08 09:24:25 -0800353 struct TransformVarying {
joshualitt16b27892014-12-18 07:47:16 -0800354 TransformVarying(const GrGLVarying& v, const char* uniName, GrCoordSet coordSet)
355 : fV(v), fUniName(uniName), fCoordSet(coordSet) {}
joshualitt4973d9d2014-11-08 09:24:25 -0800356 GrGLVarying fV;
357 SkString fUniName;
joshualitt16b27892014-12-18 07:47:16 -0800358 GrCoordSet fCoordSet;
joshualitt4973d9d2014-11-08 09:24:25 -0800359 };
360
joshualitt4973d9d2014-11-08 09:24:25 -0800361 const char* rtAdjustment() const { return "rtAdjustment"; }
362
joshualitt47bb3822014-10-07 16:43:25 -0700363 // number of each input/output type in a single allocation block, used by many builders
364 static const int kVarsPerBlock;
365
366 BuiltinUniformHandles fUniformHandles;
367 GrGLVertexBuilder fVS;
368 GrGLGeometryBuilder fGS;
369 GrGLFragmentShaderBuilder fFS;
370 bool fOutOfStage;
371 int fStageIndex;
372
joshualitta5305a12014-10-10 17:47:00 -0700373 GrGLInstalledGeoProc* fGeometryProcessor;
egdanielc2304142014-12-11 13:15:13 -0800374 GrGLInstalledXferProc* fXferProcessor;
joshualitta5305a12014-10-10 17:47:00 -0700375 SkAutoTUnref<GrGLInstalledFragProcs> fFragmentProcessors;
joshualitt47bb3822014-10-07 16:43:25 -0700376
377 const GrOptDrawState& fOptState;
joshualitt79f8fae2014-10-28 17:59:26 -0700378 const GrProgramDesc& fDesc;
bsalomon861e1032014-12-16 07:33:49 -0800379 GrGLGpu* fGpu;
joshualitt47bb3822014-10-07 16:43:25 -0700380 UniformInfoArray fUniforms;
joshualitt4973d9d2014-11-08 09:24:25 -0800381 SkSTArray<16, TransformVarying, true> fCoordVaryings;
joshualitt47bb3822014-10-07 16:43:25 -0700382
383 friend class GrGLShaderBuilder;
384 friend class GrGLVertexBuilder;
385 friend class GrGLFragmentShaderBuilder;
386 friend class GrGLGeometryBuilder;
387};
388
389/**
joshualitta5305a12014-10-10 17:47:00 -0700390 * The below structs represent processors installed in programs. All processors can have texture
391 * samplers, but only frag processors have coord transforms, hence the need for different structs
joshualitt47bb3822014-10-07 16:43:25 -0700392 */
joshualitta5305a12014-10-10 17:47:00 -0700393struct GrGLInstalledProc {
394 typedef GrGLProgramDataManager::UniformHandle UniformHandle;
joshualitt47bb3822014-10-07 16:43:25 -0700395
joshualitta5305a12014-10-10 17:47:00 -0700396 struct Sampler {
397 SkDEBUGCODE(Sampler() : fTextureUnit(-1) {})
398 UniformHandle fUniform;
399 int fTextureUnit;
400 };
401 SkSTArray<4, Sampler, true> fSamplers;
402};
joshualitt47bb3822014-10-07 16:43:25 -0700403
joshualitta5305a12014-10-10 17:47:00 -0700404struct GrGLInstalledGeoProc : public GrGLInstalledProc {
405 SkAutoTDelete<GrGLGeometryProcessor> fGLProc;
406};
joshualitt47bb3822014-10-07 16:43:25 -0700407
egdanielc2304142014-12-11 13:15:13 -0800408struct GrGLInstalledXferProc : public GrGLInstalledProc {
409 SkAutoTDelete<GrGLXferProcessor> fGLProc;
410};
411
joshualitta5305a12014-10-10 17:47:00 -0700412struct GrGLInstalledFragProc : public GrGLInstalledProc {
joshualitt2dd1ae02014-12-03 06:24:10 -0800413 GrGLInstalledFragProc() : fGLProc(NULL) {}
joshualitt47bb3822014-10-07 16:43:25 -0700414 class ShaderVarHandle {
415 public:
416 bool isValid() const { return fHandle > -1; }
417 ShaderVarHandle() : fHandle(-1) {}
418 ShaderVarHandle(int value) : fHandle(value) { SkASSERT(this->isValid()); }
419 int handle() const { SkASSERT(this->isValid()); return fHandle; }
420 UniformHandle convertToUniformHandle() {
421 SkASSERT(this->isValid());
422 return GrGLProgramDataManager::UniformHandle::CreateFromUniformIndex(fHandle);
423 }
joshualittdb0d3ca2014-10-07 12:42:26 -0700424
joshualitt47bb3822014-10-07 16:43:25 -0700425 private:
426 int fHandle;
427 };
joshualittdb0d3ca2014-10-07 12:42:26 -0700428
joshualitt47bb3822014-10-07 16:43:25 -0700429 struct Transform {
430 Transform() : fType(kVoid_GrSLType) { fCurrentValue = SkMatrix::InvalidMatrix(); }
431 ShaderVarHandle fHandle;
432 SkMatrix fCurrentValue;
433 GrSLType fType;
434 };
joshualittdb0d3ca2014-10-07 12:42:26 -0700435
joshualitta5305a12014-10-10 17:47:00 -0700436 SkAutoTDelete<GrGLFragmentProcessor> fGLProc;
437 SkSTArray<2, Transform, true> fTransforms;
joshualitta5305a12014-10-10 17:47:00 -0700438};
joshualittdb0d3ca2014-10-07 12:42:26 -0700439
joshualitta5305a12014-10-10 17:47:00 -0700440struct GrGLInstalledFragProcs : public SkRefCnt {
441 virtual ~GrGLInstalledFragProcs();
442 SkSTArray<8, GrGLInstalledFragProc*, true> fProcs;
joshualitt30ba4362014-08-21 20:18:45 -0700443};
444
joshualitt30ba4362014-08-21 20:18:45 -0700445#endif