| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 GrGLSLFragmentShaderBuilder_DEFINED | 8 #ifndef GrGLSLFragmentShaderBuilder_DEFINED |
| 9 #define GrGLSLFragmentShaderBuilder_DEFINED | 9 #define GrGLSLFragmentShaderBuilder_DEFINED |
| 10 | 10 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 }; | 60 }; |
| 61 | 61 |
| 62 /* | 62 /* |
| 63 * This class is used by fragment processors to build their fragment code. | 63 * This class is used by fragment processors to build their fragment code. |
| 64 */ | 64 */ |
| 65 class GrGLSLFPFragmentBuilder : virtual public GrGLSLFragmentBuilder { | 65 class GrGLSLFPFragmentBuilder : virtual public GrGLSLFragmentBuilder { |
| 66 public: | 66 public: |
| 67 /** Appease the compiler; the derived class initializes GrGLSLFragmentBuilde
r. */ | 67 /** Appease the compiler; the derived class initializes GrGLSLFragmentBuilde
r. */ |
| 68 GrGLSLFPFragmentBuilder() : GrGLSLFragmentBuilder(nullptr) {} | 68 GrGLSLFPFragmentBuilder() : GrGLSLFragmentBuilder(nullptr) {} |
| 69 | 69 |
| 70 enum Coordinates { |
| 71 kSkiaDevice_Coordinates, |
| 72 kGLSLWindow_Coordinates, |
| 73 |
| 74 kLast_Coordinates = kGLSLWindow_Coordinates |
| 75 }; |
| 76 |
| 77 /** |
| 78 * Appends the offset from the center of the pixel to a specified sample. |
| 79 * |
| 80 * @param sampleIdx GLSL expression of the sample index. |
| 81 * @param Coordinates Coordinate space in which to emit the offset. |
| 82 * |
| 83 * A processor must call setWillUseSampleLocations in its constructor before
using this method. |
| 84 */ |
| 85 virtual void appendOffsetToSample(const char* sampleIdx, Coordinates) = 0; |
| 86 |
| 70 /** | 87 /** |
| 71 * Subtracts sample coverage from the fragment. Any sample whose correspondi
ng bit is not found | 88 * Subtracts sample coverage from the fragment. Any sample whose correspondi
ng bit is not found |
| 72 * in the mask will not be written out to the framebuffer. | 89 * in the mask will not be written out to the framebuffer. |
| 73 * | 90 * |
| 74 * @param mask int that contains the sample mask. Bit N corresponds to
the Nth sample. | 91 * @param mask int that contains the sample mask. Bit N corresponds to
the Nth sample. |
| 75 * @param invert perform a bit-wise NOT on the provided mask before apply
ing it? | 92 * @param invert perform a bit-wise NOT on the provided mask before apply
ing it? |
| 76 * | 93 * |
| 77 * Requires GLSL support for sample variables. | 94 * Requires GLSL support for sample variables. |
| 78 */ | 95 */ |
| 79 virtual void maskSampleCoverage(const char* mask, bool invert = false) = 0; | 96 virtual void maskSampleCoverage(const char* mask, bool invert = false) = 0; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 this shader. It is only legal to call this method with an advanced blend
equation, and only | 147 this shader. It is only legal to call this method with an advanced blend
equation, and only |
| 131 if these equations are supported. */ | 148 if these equations are supported. */ |
| 132 virtual void enableAdvancedBlendEquationIfNeeded(GrBlendEquation) = 0; | 149 virtual void enableAdvancedBlendEquationIfNeeded(GrBlendEquation) = 0; |
| 133 }; | 150 }; |
| 134 | 151 |
| 135 /* | 152 /* |
| 136 * This class implements the various fragment builder interfaces. | 153 * This class implements the various fragment builder interfaces. |
| 137 */ | 154 */ |
| 138 class GrGLSLFragmentShaderBuilder : public GrGLSLPPFragmentBuilder, public GrGLS
LXPFragmentBuilder { | 155 class GrGLSLFragmentShaderBuilder : public GrGLSLPPFragmentBuilder, public GrGLS
LXPFragmentBuilder { |
| 139 public: | 156 public: |
| 140 typedef uint8_t FragPosKey; | 157 /** Returns a nonzero key for a surface's origin. This should only be called
if a processor will |
| 158 use the fragment position and/or sample locations. */ |
| 159 static uint8_t KeyForSurfaceOrigin(GrSurfaceOrigin); |
| 141 | 160 |
| 142 /** Returns a key for reading the fragment location. This should only be cal
led if there is an | 161 GrGLSLFragmentShaderBuilder(GrGLSLProgramBuilder* program); |
| 143 effect that will requires the fragment position. If the fragment position
is not required, | |
| 144 the key is 0. */ | |
| 145 static FragPosKey KeyForFragmentPosition(const GrRenderTarget* dst); | |
| 146 | |
| 147 GrGLSLFragmentShaderBuilder(GrGLSLProgramBuilder* program, uint8_t fragPosKe
y); | |
| 148 | 162 |
| 149 // Shared GrGLSLFragmentBuilder interface. | 163 // Shared GrGLSLFragmentBuilder interface. |
| 150 bool enableFeature(GLSLFeature) override; | 164 bool enableFeature(GLSLFeature) override; |
| 151 virtual SkString ensureFSCoords2D(const GrGLSLTransformedCoordsArray& coords
, | 165 virtual SkString ensureFSCoords2D(const GrGLSLTransformedCoordsArray& coords
, |
| 152 int index) override; | 166 int index) override; |
| 153 const char* fragmentPosition() override; | 167 const char* fragmentPosition() override; |
| 154 | 168 |
| 155 // GrGLSLFPFragmentBuilder interface. | 169 // GrGLSLFPFragmentBuilder interface. |
| 170 void appendOffsetToSample(const char* sampleIdx, Coordinates) override; |
| 156 void maskSampleCoverage(const char* mask, bool invert = false) override; | 171 void maskSampleCoverage(const char* mask, bool invert = false) override; |
| 157 void overrideSampleCoverage(const char* mask) override; | 172 void overrideSampleCoverage(const char* mask) override; |
| 158 const SkString& getMangleString() const override { return fMangleString; } | 173 const SkString& getMangleString() const override { return fMangleString; } |
| 159 void onBeforeChildProcEmitCode() override; | 174 void onBeforeChildProcEmitCode() override; |
| 160 void onAfterChildProcEmitCode() override; | 175 void onAfterChildProcEmitCode() override; |
| 161 | 176 |
| 162 // GrGLSLXPFragmentBuilder interface. | 177 // GrGLSLXPFragmentBuilder interface. |
| 163 bool hasCustomColorOutput() const override { return fHasCustomColorOutput; } | 178 bool hasCustomColorOutput() const override { return fHasCustomColorOutput; } |
| 164 bool hasSecondaryOutput() const override { return fHasSecondaryOutput; } | 179 bool hasSecondaryOutput() const override { return fHasSecondaryOutput; } |
| 165 const char* dstColor() override; | 180 const char* dstColor() override; |
| 166 void enableAdvancedBlendEquationIfNeeded(GrBlendEquation) override; | 181 void enableAdvancedBlendEquationIfNeeded(GrBlendEquation) override; |
| 167 | 182 |
| 168 private: | 183 private: |
| 169 bool hasFragmentPosition() const; | |
| 170 | |
| 171 // Private public interface, used by GrGLProgramBuilder to build a fragment
shader | 184 // Private public interface, used by GrGLProgramBuilder to build a fragment
shader |
| 172 void enableCustomOutput(); | 185 void enableCustomOutput(); |
| 173 void enableSecondaryOutput(); | 186 void enableSecondaryOutput(); |
| 174 const char* getPrimaryColorOutputName() const; | 187 const char* getPrimaryColorOutputName() const; |
| 175 const char* getSecondaryColorOutputName() const; | 188 const char* getSecondaryColorOutputName() const; |
| 176 | 189 |
| 177 #ifdef SK_DEBUG | 190 #ifdef SK_DEBUG |
| 178 // As GLSLProcessors emit code, there are some conditions we need to verify.
We use the below | 191 // As GLSLProcessors emit code, there are some conditions we need to verify.
We use the below |
| 179 // state to track this. The reset call is called per processor emitted. | 192 // state to track this. The reset call is called per processor emitted. |
| 180 GrProcessor::RequiredFeatures usedProcessorFeatures() const { return fUsedPr
ocessorFeatures; } | 193 GrProcessor::RequiredFeatures usedProcessorFeatures() const { return fUsedPr
ocessorFeatures; } |
| 181 bool hasReadDstColor() const { return fHasReadDstColor; } | 194 bool hasReadDstColor() const { return fHasReadDstColor; } |
| 182 void resetVerification() { | 195 void resetVerification() { |
| 183 fUsedProcessorFeatures = GrProcessor::kNone_RequiredFeatures; | 196 fUsedProcessorFeatures = GrProcessor::kNone_RequiredFeatures; |
| 184 fHasReadDstColor = false; | 197 fHasReadDstColor = false; |
| 185 } | 198 } |
| 186 #endif | 199 #endif |
| 187 | 200 |
| 188 static const char* DeclaredColorOutputName() { return "fsColorOut"; } | 201 static const char* DeclaredColorOutputName() { return "fsColorOut"; } |
| 189 static const char* DeclaredSecondaryColorOutputName() { return "fsSecondaryC
olorOut"; } | 202 static const char* DeclaredSecondaryColorOutputName() { return "fsSecondaryC
olorOut"; } |
| 190 | 203 |
| 191 /* | 204 GrSurfaceOrigin getSurfaceOrigin() const; |
| 192 * An internal call for GrGLProgramBuilder to use to add varyings to the ver
tex shader | |
| 193 */ | |
| 194 void addVarying(GrGLSLVarying*, GrSLPrecision); | |
| 195 | 205 |
| 196 void onFinalize() override; | 206 void onFinalize() override; |
| 197 | 207 void defineSampleOffsetArray(const char* name, const SkMatrix&); |
| 198 // Interpretation of FragPosKey when generating code | |
| 199 enum { | |
| 200 kNoFragPosRead_FragPosKey = 0, // The fragment positition wil
l not be needed. | |
| 201 kTopLeftFragPosRead_FragPosKey = 0x1,// Read frag pos relative to t
op-left. | |
| 202 kBottomLeftFragPosRead_FragPosKey = 0x2,// Read frag pos relative to b
ottom-left. | |
| 203 }; | |
| 204 | 208 |
| 205 static const char* kDstTextureColorName; | 209 static const char* kDstTextureColorName; |
| 206 | 210 |
| 207 /* | 211 /* |
| 208 * State that tracks which child proc in the proc tree is currently emitting
code. This is | 212 * State that tracks which child proc in the proc tree is currently emitting
code. This is |
| 209 * used to update the fMangleString, which is used to mangle the names of un
iforms and functions | 213 * used to update the fMangleString, which is used to mangle the names of un
iforms and functions |
| 210 * emitted by the proc. fSubstageIndices is a stack: its count indicates ho
w many levels deep | 214 * emitted by the proc. fSubstageIndices is a stack: its count indicates ho
w many levels deep |
| 211 * we are in the tree, and its second-to-last value is the index of the chil
d proc at that | 215 * we are in the tree, and its second-to-last value is the index of the chil
d proc at that |
| 212 * level which is currently emitting code. For example, if fSubstageIndices
= [3, 1, 2, 0], that | 216 * level which is currently emitting code. For example, if fSubstageIndices
= [3, 1, 2, 0], that |
| 213 * means we're currently emitting code for the base proc's 3rd child's 1st c
hild's 2nd child. | 217 * means we're currently emitting code for the base proc's 3rd child's 1st c
hild's 2nd child. |
| 214 */ | 218 */ |
| 215 SkTArray<int> fSubstageIndices; | 219 SkTArray<int> fSubstageIndices; |
| 216 | 220 |
| 217 /* | 221 /* |
| 218 * The mangle string is used to mangle the names of uniforms/functions emitt
ed by the child | 222 * The mangle string is used to mangle the names of uniforms/functions emitt
ed by the child |
| 219 * procs so no duplicate uniforms/functions appear in the generated shader p
rogram. The mangle | 223 * procs so no duplicate uniforms/functions appear in the generated shader p
rogram. The mangle |
| 220 * string is simply based on fSubstageIndices. For example, if fSubstageIndi
ces = [3, 1, 2, 0], | 224 * string is simply based on fSubstageIndices. For example, if fSubstageIndi
ces = [3, 1, 2, 0], |
| 221 * then the manglestring will be "_c3_c1_c2", and any uniform/function emitt
ed by that proc will | 225 * then the manglestring will be "_c3_c1_c2", and any uniform/function emitt
ed by that proc will |
| 222 * have "_c3_c1_c2" appended to its name, which can be interpreted as "base
proc's 3rd child's | 226 * have "_c3_c1_c2" appended to its name, which can be interpreted as "base
proc's 3rd child's |
| 223 * 1st child's 2nd child". | 227 * 1st child's 2nd child". |
| 224 */ | 228 */ |
| 225 SkString fMangleString; | 229 SkString fMangleString; |
| 226 | 230 |
| 227 bool fSetupFragPosition; | 231 bool fSetupFragPosition; |
| 228 bool fTopLeftFragPosRead; | 232 bool fHasCustomColorOutput; |
| 229 bool fHasCustomColorOutput; | 233 int fCustomColorOutputIndex; |
| 230 int fCustomColorOutputIndex; | 234 bool fHasSecondaryOutput; |
| 231 bool fHasSecondaryOutput; | 235 uint8_t fUsedSampleOffsetArrays; |
| 232 bool fHasInitializedSampleMask; | 236 bool fHasInitializedSampleMask; |
| 233 | 237 |
| 234 #ifdef SK_DEBUG | 238 #ifdef SK_DEBUG |
| 235 // some state to verify shaders and effects are consistent, this is reset be
tween effects by | 239 // some state to verify shaders and effects are consistent, this is reset be
tween effects by |
| 236 // the program creator | 240 // the program creator |
| 237 GrProcessor::RequiredFeatures fUsedProcessorFeatures; | 241 GrProcessor::RequiredFeatures fUsedProcessorFeatures; |
| 238 bool fHasReadDstColor; | 242 bool fHasReadDstColor; |
| 239 #endif | 243 #endif |
| 240 | 244 |
| 241 friend class GrGLSLProgramBuilder; | 245 friend class GrGLSLProgramBuilder; |
| 242 friend class GrGLProgramBuilder; | 246 friend class GrGLProgramBuilder; |
| 243 }; | 247 }; |
| 244 | 248 |
| 245 #endif | 249 #endif |
| OLD | NEW |