| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef GrGLSLFragmentProcessor_DEFINED | 8 #ifndef GrGLSLFragmentProcessor_DEFINED |
| 9 #define GrGLSLFragmentProcessor_DEFINED | 9 #define GrGLSLFragmentProcessor_DEFINED |
| 10 | 10 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 | 26 |
| 27 virtual ~GrGLSLFragmentProcessor() { | 27 virtual ~GrGLSLFragmentProcessor() { |
| 28 for (int i = 0; i < fChildProcessors.count(); ++i) { | 28 for (int i = 0; i < fChildProcessors.count(); ++i) { |
| 29 delete fChildProcessors[i]; | 29 delete fChildProcessors[i]; |
| 30 } | 30 } |
| 31 } | 31 } |
| 32 | 32 |
| 33 typedef GrGLSLProgramDataManager::UniformHandle UniformHandle; | 33 typedef GrGLSLProgramDataManager::UniformHandle UniformHandle; |
| 34 typedef GrGLSLProgramDataManager::UniformHandle SamplerHandle; | 34 typedef GrGLSLProgramDataManager::UniformHandle SamplerHandle; |
| 35 | 35 |
| 36 /** | |
| 37 * When building a program from a GrPipeline this is used to provide the GrS
haderVars that | |
| 38 * contain the resulting transformed coords from each of a GrFragmentProcess
or's | |
| 39 * GrCoordTransforms. This allows the GrFragmentProcessor subclasses to refe
r to the transformed | |
| 40 * coords in fragment code. | |
| 41 */ | |
| 42 class TransformedCoordVars { | |
| 43 public: | |
| 44 TransformedCoordVars(const GrFragmentProcessor* fp, const GrShaderVar* v
ars) | |
| 45 : fFP(fp) | |
| 46 , fTransformedVars(vars) {} | |
| 47 | |
| 48 const GrShaderVar& operator[] (int i) const { | |
| 49 SkASSERT(i >= 0 && i < fFP->numCoordTransforms()); | |
| 50 return fTransformedVars[i]; | |
| 51 } | |
| 52 | |
| 53 TransformedCoordVars childTransforms(int childIdx) const; | |
| 54 | |
| 55 private: | |
| 56 const GrFragmentProcessor* fFP; | |
| 57 const GrShaderVar* fTransformedVars; | |
| 58 }; | |
| 59 | |
| 60 /** Called when the program stage should insert its code into the shaders. T
he code in each | 36 /** Called when the program stage should insert its code into the shaders. T
he code in each |
| 61 shader will be in its own block ({}) and so locally scoped names will no
t collide across | 37 shader will be in its own block ({}) and so locally scoped names will no
t collide across |
| 62 stages. | 38 stages. |
| 63 | 39 |
| 64 @param fragBuilder Interface used to emit code in the shaders. | 40 @param fragBuilder Interface used to emit code in the shaders. |
| 65 @param fp The processor that generated this program stage
. | 41 @param fp The processor that generated this program stage
. |
| 66 @param key The key that was computed by GenKey() from the
generating | 42 @param key The key that was computed by GenKey() from the
generating |
| 67 GrProcessor. | 43 GrProcessor. |
| 68 @param outputColor A predefined vec4 in the FS in which the stage
should place its | 44 @param outputColor A predefined vec4 in the FS in which the stage
should place its |
| 69 output color (or coverage). | 45 output color (or coverage). |
| 70 @param inputColor A vec4 that holds the input color to the stage
in the FS. This may | 46 @param inputColor A vec4 that holds the input color to the stage
in the FS. This may |
| 71 be nullptr in which case the implied input is s
olid white (all | 47 be nullptr in which case the implied input is s
olid white (all |
| 72 ones). TODO: Better system for communicating op
timization info | 48 ones). TODO: Better system for communicating op
timization info |
| 73 (e.g. input color is solid white, trans black,
known to be opaque, | 49 (e.g. input color is solid white, trans black,
known to be opaque, |
| 74 etc.) that allows the processor to communicate
back similar known | 50 etc.) that allows the processor to communicate
back similar known |
| 75 info about its output. | 51 info about its output. |
| 76 @param transformedCoords Fragment shader variables containing the coords
computed using | 52 @param transformedCoords Fragment shader variables containing the coords
computed using |
| 77 each of the GrFragmentProcessor's GrCoordTransf
orms. | 53 each of the GrFragmentProcessor's Coord Transfo
rms. |
| 78 @param texSamplers Contains one entry for each GrTextureAccess of
the GrProcessor. | 54 @param texSamplers Contains one entry for each GrTextureAccess of
the GrProcessor. |
| 79 These can be passed to the builder to emit text
ure reads in the | 55 These can be passed to the builder to emit text
ure reads in the |
| 80 generated code. | 56 generated code. |
| 81 @param bufferSamplers Contains one entry for each GrBufferAccess of t
he GrProcessor. | 57 @param bufferSamplers Contains one entry for each GrBufferAccess of t
he GrProcessor. |
| 82 These can be passed to the builder to emit buff
er reads in the | 58 These can be passed to the builder to emit buff
er reads in the |
| 83 generated code. | 59 generated code. |
| 84 */ | 60 */ |
| 85 struct EmitArgs { | 61 struct EmitArgs { |
| 86 EmitArgs(GrGLSLFPFragmentBuilder* fragBuilder, | 62 EmitArgs(GrGLSLFPFragmentBuilder* fragBuilder, |
| 87 GrGLSLUniformHandler* uniformHandler, | 63 GrGLSLUniformHandler* uniformHandler, |
| 88 const GrGLSLCaps* caps, | 64 const GrGLSLCaps* caps, |
| 89 const GrFragmentProcessor& fp, | 65 const GrFragmentProcessor& fp, |
| 90 const char* outputColor, | 66 const char* outputColor, |
| 91 const char* inputColor, | 67 const char* inputColor, |
| 92 const TransformedCoordVars& transformedCoordVars, | 68 const SkTArray<GrShaderVar>& transformedCoords, |
| 93 const SamplerHandle* texSamplers, | 69 const SamplerHandle* texSamplers, |
| 94 const SamplerHandle* bufferSamplers, | 70 const SamplerHandle* bufferSamplers, |
| 95 bool gpImplementsDistanceVector) | 71 bool gpImplementsDistanceVector) |
| 96 : fFragBuilder(fragBuilder) | 72 : fFragBuilder(fragBuilder) |
| 97 , fUniformHandler(uniformHandler) | 73 , fUniformHandler(uniformHandler) |
| 98 , fGLSLCaps(caps) | 74 , fGLSLCaps(caps) |
| 99 , fFp(fp) | 75 , fFp(fp) |
| 100 , fOutputColor(outputColor) | 76 , fOutputColor(outputColor) |
| 101 , fInputColor(inputColor) | 77 , fInputColor(inputColor) |
| 102 , fTransformedCoords(transformedCoordVars) | 78 , fTransformedCoords(transformedCoords) |
| 103 , fTexSamplers(texSamplers) | 79 , fTexSamplers(texSamplers) |
| 104 , fBufferSamplers(bufferSamplers) | 80 , fBufferSamplers(bufferSamplers) |
| 105 , fGpImplementsDistanceVector(gpImplementsDistanceVector) {} | 81 , fGpImplementsDistanceVector(gpImplementsDistanceVector) {} |
| 106 GrGLSLFPFragmentBuilder* fFragBuilder; | 82 GrGLSLFPFragmentBuilder* fFragBuilder; |
| 107 GrGLSLUniformHandler* fUniformHandler; | 83 GrGLSLUniformHandler* fUniformHandler; |
| 108 const GrGLSLCaps* fGLSLCaps; | 84 const GrGLSLCaps* fGLSLCaps; |
| 109 const GrFragmentProcessor& fFp; | 85 const GrFragmentProcessor& fFp; |
| 110 const char* fOutputColor; | 86 const char* fOutputColor; |
| 111 const char* fInputColor; | 87 const char* fInputColor; |
| 112 const TransformedCoordVars& fTransformedCoords; | 88 const SkTArray<GrShaderVar>& fTransformedCoords; |
| 113 const SamplerHandle* fTexSamplers; | 89 const SamplerHandle* fTexSamplers; |
| 114 const SamplerHandle* fBufferSamplers; | 90 const SamplerHandle* fBufferSamplers; |
| 115 bool fGpImplementsDistanceVector; | 91 bool fGpImplementsDistanceVector; |
| 116 }; | 92 }; |
| 117 | 93 |
| 118 virtual void emitCode(EmitArgs&) = 0; | 94 virtual void emitCode(EmitArgs&) = 0; |
| 119 | 95 |
| 120 void setData(const GrGLSLProgramDataManager& pdman, const GrFragmentProcesso
r& processor); | 96 void setData(const GrGLSLProgramDataManager& pdman, const GrFragmentProcesso
r& processor); |
| 121 | 97 |
| 122 static void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessorKeyBuil
der*) {} | 98 static void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessorKeyBuil
der*) {} |
| (...skipping 29 matching lines...) Expand all Loading... |
| 152 | 128 |
| 153 private: | 129 private: |
| 154 void internalEmitChild(int, const char*, const char*, EmitArgs&); | 130 void internalEmitChild(int, const char*, const char*, EmitArgs&); |
| 155 | 131 |
| 156 SkTArray<GrGLSLFragmentProcessor*, true> fChildProcessors; | 132 SkTArray<GrGLSLFragmentProcessor*, true> fChildProcessors; |
| 157 | 133 |
| 158 friend class GrFragmentProcessor; | 134 friend class GrFragmentProcessor; |
| 159 }; | 135 }; |
| 160 | 136 |
| 161 #endif | 137 #endif |
| OLD | NEW |