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