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 { | |
bsalomon
2016/03/01 14:28:55
Why do we need both of these?
Chris Dalton
2016/03/01 20:37:47
The short answer is that it makes life easier for
| |
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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
146 | 163 |
147 GrGLSLFragmentShaderBuilder(GrGLSLProgramBuilder* program, uint8_t fragPosKe y); | 164 GrGLSLFragmentShaderBuilder(GrGLSLProgramBuilder* program, uint8_t fragPosKe y); |
148 | 165 |
149 // Shared GrGLSLFragmentBuilder interface. | 166 // Shared GrGLSLFragmentBuilder interface. |
150 bool enableFeature(GLSLFeature) override; | 167 bool enableFeature(GLSLFeature) override; |
151 virtual SkString ensureFSCoords2D(const GrGLSLTransformedCoordsArray& coords , | 168 virtual SkString ensureFSCoords2D(const GrGLSLTransformedCoordsArray& coords , |
152 int index) override; | 169 int index) override; |
153 const char* fragmentPosition() override; | 170 const char* fragmentPosition() override; |
154 | 171 |
155 // GrGLSLFPFragmentBuilder interface. | 172 // GrGLSLFPFragmentBuilder interface. |
173 void appendOffsetToSample(const char* sampleIdx, Coordinates) override; | |
156 void maskSampleCoverage(const char* mask, bool invert = false) override; | 174 void maskSampleCoverage(const char* mask, bool invert = false) override; |
157 void overrideSampleCoverage(const char* mask) override; | 175 void overrideSampleCoverage(const char* mask) override; |
158 const SkString& getMangleString() const override { return fMangleString; } | 176 const SkString& getMangleString() const override { return fMangleString; } |
159 void onBeforeChildProcEmitCode() override; | 177 void onBeforeChildProcEmitCode() override; |
160 void onAfterChildProcEmitCode() override; | 178 void onAfterChildProcEmitCode() override; |
161 | 179 |
162 // GrGLSLXPFragmentBuilder interface. | 180 // GrGLSLXPFragmentBuilder interface. |
163 bool hasCustomColorOutput() const override { return fHasCustomColorOutput; } | 181 bool hasCustomColorOutput() const override { return fHasCustomColorOutput; } |
164 bool hasSecondaryOutput() const override { return fHasSecondaryOutput; } | 182 bool hasSecondaryOutput() const override { return fHasSecondaryOutput; } |
165 const char* dstColor() override; | 183 const char* dstColor() override; |
166 void enableAdvancedBlendEquationIfNeeded(GrBlendEquation) override; | 184 void enableAdvancedBlendEquationIfNeeded(GrBlendEquation) override; |
167 | 185 |
168 private: | 186 private: |
169 bool hasFragmentPosition() const; | |
170 | |
171 // Private public interface, used by GrGLProgramBuilder to build a fragment shader | 187 // Private public interface, used by GrGLProgramBuilder to build a fragment shader |
172 void enableCustomOutput(); | 188 void enableCustomOutput(); |
173 void enableSecondaryOutput(); | 189 void enableSecondaryOutput(); |
174 const char* getPrimaryColorOutputName() const; | 190 const char* getPrimaryColorOutputName() const; |
175 const char* getSecondaryColorOutputName() const; | 191 const char* getSecondaryColorOutputName() const; |
192 void defineSampleOffsetArray(const char* name, const SkMatrix&); | |
176 | 193 |
177 #ifdef SK_DEBUG | 194 #ifdef SK_DEBUG |
178 // As GLSLProcessors emit code, there are some conditions we need to verify. We use the below | 195 // 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. | 196 // state to track this. The reset call is called per processor emitted. |
180 GrProcessor::RequiredFeatures usedProcessorFeatures() const { return fUsedPr ocessorFeatures; } | 197 GrProcessor::RequiredFeatures usedProcessorFeatures() const { return fUsedPr ocessorFeatures; } |
181 bool hasReadDstColor() const { return fHasReadDstColor; } | 198 bool hasReadDstColor() const { return fHasReadDstColor; } |
182 void resetVerification() { | 199 void resetVerification() { |
183 fUsedProcessorFeatures = GrProcessor::kNone_RequiredFeatures; | 200 fUsedProcessorFeatures = GrProcessor::kNone_RequiredFeatures; |
184 fHasReadDstColor = false; | 201 fHasReadDstColor = false; |
185 } | 202 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
217 /* | 234 /* |
218 * The mangle string is used to mangle the names of uniforms/functions emitt ed by the child | 235 * 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 | 236 * 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], | 237 * 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 | 238 * 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 | 239 * 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". | 240 * 1st child's 2nd child". |
224 */ | 241 */ |
225 SkString fMangleString; | 242 SkString fMangleString; |
226 | 243 |
227 bool fSetupFragPosition; | 244 bool fSetupFragPosition; |
228 bool fTopLeftFragPosRead; | 245 bool fTopLeftFragPosRead; |
229 bool fHasCustomColorOutput; | 246 bool fHasCustomColorOutput; |
230 int fCustomColorOutputIndex; | 247 int fCustomColorOutputIndex; |
231 bool fHasSecondaryOutput; | 248 bool fHasSecondaryOutput; |
232 bool fHasInitializedSampleMask; | 249 uint8_t fUsedSampleOffsetArrays; |
250 bool fHasInitializedSampleMask; | |
233 | 251 |
234 #ifdef SK_DEBUG | 252 #ifdef SK_DEBUG |
235 // some state to verify shaders and effects are consistent, this is reset be tween effects by | 253 // some state to verify shaders and effects are consistent, this is reset be tween effects by |
236 // the program creator | 254 // the program creator |
237 GrProcessor::RequiredFeatures fUsedProcessorFeatures; | 255 GrProcessor::RequiredFeatures fUsedProcessorFeatures; |
238 bool fHasReadDstColor; | 256 bool fHasReadDstColor; |
239 #endif | 257 #endif |
240 | 258 |
241 friend class GrGLSLProgramBuilder; | 259 friend class GrGLSLProgramBuilder; |
242 friend class GrGLProgramBuilder; | 260 friend class GrGLProgramBuilder; |
243 }; | 261 }; |
244 | 262 |
245 #endif | 263 #endif |
OLD | NEW |