| 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 GrFragmentProcessor_DEFINED | 8 #ifndef GrFragmentProcessor_DEFINED |
| 9 #define GrFragmentProcessor_DEFINED | 9 #define GrFragmentProcessor_DEFINED |
| 10 | 10 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 class GrFragmentProcessor : public GrProcessor { | 24 class GrFragmentProcessor : public GrProcessor { |
| 25 public: | 25 public: |
| 26 /** | 26 /** |
| 27 * In many instances (e.g. SkShader::asFragmentProcessor() implementations)
it is desirable to | 27 * In many instances (e.g. SkShader::asFragmentProcessor() implementations)
it is desirable to |
| 28 * only consider the input color's alpha. However, there is a competing desi
re to have reusable | 28 * only consider the input color's alpha. However, there is a competing desi
re to have reusable |
| 29 * GrFragmentProcessor subclasses that can be used in other scenarios where
the entire input | 29 * GrFragmentProcessor subclasses that can be used in other scenarios where
the entire input |
| 30 * color is considered. This function exists to filter the input color and p
ass it to a FP. It | 30 * color is considered. This function exists to filter the input color and p
ass it to a FP. It |
| 31 * does so by returning a parent FP that multiplies the passed in FPs output
by the parent's | 31 * does so by returning a parent FP that multiplies the passed in FPs output
by the parent's |
| 32 * input alpha. The passed in FP will not receive an input color. | 32 * input alpha. The passed in FP will not receive an input color. |
| 33 */ | 33 */ |
| 34 static const GrFragmentProcessor* MulOutputByInputAlpha(const GrFragmentProc
essor*); | 34 static sk_sp<GrFragmentProcessor> MulOutputByInputAlpha(sk_sp<GrFragmentProc
essor>); |
| 35 | 35 |
| 36 /** | 36 /** |
| 37 * Similar to the above but it modulates the output r,g,b of the child proc
essor by the input | 37 * Similar to the above but it modulates the output r,g,b of the child proc
essor by the input |
| 38 * rgb and then multiplies all the components by the input alpha. This effe
ctively modulates | 38 * rgb and then multiplies all the components by the input alpha. This effe
ctively modulates |
| 39 * the child processor's premul color by a unpremul'ed input and produces a
premul output | 39 * the child processor's premul color by a unpremul'ed input and produces a
premul output |
| 40 */ | 40 */ |
| 41 static const GrFragmentProcessor* MulOutputByInputUnpremulColor(const GrFrag
mentProcessor*); | 41 static sk_sp<GrFragmentProcessor> MulOutputByInputUnpremulColor(sk_sp<GrFrag
mentProcessor>); |
| 42 | 42 |
| 43 /** | 43 /** |
| 44 * Returns a parent fragment processor that adopts the passed fragment proc
essor as a child. | 44 * Returns a parent fragment processor that adopts the passed fragment proc
essor as a child. |
| 45 * The parent will ignore its input color and instead feed the passed in co
lor as input to the | 45 * The parent will ignore its input color and instead feed the passed in co
lor as input to the |
| 46 * child. | 46 * child. |
| 47 */ | 47 */ |
| 48 static const GrFragmentProcessor* OverrideInput(const GrFragmentProcessor*,
GrColor); | 48 static sk_sp<GrFragmentProcessor> OverrideInput(sk_sp<GrFragmentProcessor>,
GrColor); |
| 49 | 49 |
| 50 /** | 50 /** |
| 51 * Returns a fragment processor that runs the passed in array of fragment pr
ocessors in a | 51 * Returns a fragment processor that runs the passed in array of fragment pr
ocessors in a |
| 52 * series. The original input is passed to the first, the first's output is
passed to the | 52 * series. The original input is passed to the first, the first's output is
passed to the |
| 53 * second, etc. The output of the returned processor is the output of the la
st processor of the | 53 * second, etc. The output of the returned processor is the output of the la
st processor of the |
| 54 * series. | 54 * series. |
| 55 * |
| 56 * The array elements with be moved. |
| 55 */ | 57 */ |
| 56 static const GrFragmentProcessor* RunInSeries(const GrFragmentProcessor*[],
int cnt); | 58 static sk_sp<GrFragmentProcessor> RunInSeries(sk_sp<GrFragmentProcessor>*, i
nt cnt); |
| 57 | 59 |
| 58 GrFragmentProcessor() | 60 GrFragmentProcessor() |
| 59 : INHERITED() | 61 : INHERITED() |
| 60 , fUsesLocalCoords(false) | 62 , fUsesLocalCoords(false) |
| 61 , fNumTexturesExclChildren(0) | 63 , fNumTexturesExclChildren(0) |
| 62 , fNumBuffersExclChildren(0) | 64 , fNumBuffersExclChildren(0) |
| 63 , fNumTransformsExclChildren(0) {} | 65 , fNumTransformsExclChildren(0) {} |
| 64 | 66 |
| 65 ~GrFragmentProcessor() override; | 67 ~GrFragmentProcessor() override; |
| 66 | 68 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 | 150 |
| 149 /** | 151 /** |
| 150 * FragmentProcessor subclasses call this from their constructor to register
any child | 152 * FragmentProcessor subclasses call this from their constructor to register
any child |
| 151 * FragmentProcessors they have. This must be called AFTER all texture acces
ses and coord | 153 * FragmentProcessors they have. This must be called AFTER all texture acces
ses and coord |
| 152 * transforms have been added. | 154 * transforms have been added. |
| 153 * This is for processors whose shader code will be composed of nested proce
ssors whose output | 155 * This is for processors whose shader code will be composed of nested proce
ssors whose output |
| 154 * colors will be combined somehow to produce its output color. Registering
these child | 156 * colors will be combined somehow to produce its output color. Registering
these child |
| 155 * processors will allow the ProgramBuilder to automatically handle their tr
ansformed coords and | 157 * processors will allow the ProgramBuilder to automatically handle their tr
ansformed coords and |
| 156 * texture accesses and mangle their uniform and output color names. | 158 * texture accesses and mangle their uniform and output color names. |
| 157 */ | 159 */ |
| 158 int registerChildProcessor(const GrFragmentProcessor* child); | 160 int registerChildProcessor(sk_sp<GrFragmentProcessor> child); |
| 159 | 161 |
| 160 /** | 162 /** |
| 161 * Subclass implements this to support getConstantColorComponents(...). | 163 * Subclass implements this to support getConstantColorComponents(...). |
| 162 * | 164 * |
| 163 * Note: it's up to the subclass implementation to do any recursive call to
compute the child | 165 * Note: it's up to the subclass implementation to do any recursive call to
compute the child |
| 164 * procs' output invariants; computeInvariantOutput will not be recursive. | 166 * procs' output invariants; computeInvariantOutput will not be recursive. |
| 165 */ | 167 */ |
| 166 virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const = 0; | 168 virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const = 0; |
| 167 | 169 |
| 168 private: | 170 private: |
| (...skipping 11 matching lines...) Expand all Loading... |
| 180 /** | 182 /** |
| 181 * Subclass implements this to support isEqual(). It will only be called if
it is known that | 183 * Subclass implements this to support isEqual(). It will only be called if
it is known that |
| 182 * the two processors are of the same subclass (i.e. they return the same ob
ject from | 184 * the two processors are of the same subclass (i.e. they return the same ob
ject from |
| 183 * getFactory()). The processor subclass should not compare its coord transf
orms as that will | 185 * getFactory()). The processor subclass should not compare its coord transf
orms as that will |
| 184 * be performed automatically in the non-virtual isEqual(). | 186 * be performed automatically in the non-virtual isEqual(). |
| 185 */ | 187 */ |
| 186 virtual bool onIsEqual(const GrFragmentProcessor&) const = 0; | 188 virtual bool onIsEqual(const GrFragmentProcessor&) const = 0; |
| 187 | 189 |
| 188 bool hasSameTransforms(const GrFragmentProcessor&) const; | 190 bool hasSameTransforms(const GrFragmentProcessor&) const; |
| 189 | 191 |
| 190 bool fUsesLocalCoords; | 192 bool fUsesLocalCoords; |
| 191 | 193 |
| 192 /** | 194 /** |
| 193 * fCoordTransforms stores the transforms of this proc, followed by all the
transforms of this | 195 * fCoordTransforms stores the transforms of this proc, followed by all the
transforms of this |
| 194 * proc's children. In other words, each proc stores all the transforms of i
ts subtree as if | 196 * proc's children. In other words, each proc stores all the transforms of i
ts subtree as if |
| 195 * they were collected using preorder traversal. | 197 * they were collected using preorder traversal. |
| 196 * | 198 * |
| 197 * Example: | 199 * Example: |
| 198 * Suppose we have frag proc A, who has two children B and D. B has a child
C, and D has | 200 * Suppose we have frag proc A, who has two children B and D. B has a child
C, and D has |
| 199 * two children E and F. Suppose procs A, B, C, D, E, F have 1, 2, 1, 1, 3,
2 transforms | 201 * two children E and F. Suppose procs A, B, C, D, E, F have 1, 2, 1, 1, 3,
2 transforms |
| 200 * respectively. The following shows what the fCoordTransforms array of each
proc would contain: | 202 * respectively. The following shows what the fCoordTransforms array of each
proc would contain: |
| 201 * | 203 * |
| 202 * (A) | 204 * (A) |
| 203 * [a1,b1,b2,c1,d1,e1,e2,e3,f1,f2] | 205 * [a1,b1,b2,c1,d1,e1,e2,e3,f1,f2] |
| 204 * / \ | 206 * / \ |
| 205 * / \ | 207 * / \ |
| 206 * (B) (D) | 208 * (B) (D) |
| 207 * [b1,b2,c1] [d1,e1,e2,e3,f1,f2] | 209 * [b1,b2,c1] [d1,e1,e2,e3,f1,f2] |
| 208 * / / \ | 210 * / / \ |
| 209 * / / \ | 211 * / / \ |
| 210 * (C) (E) (F) | 212 * (C) (E) (F) |
| 211 * [c1] [e1,e2,e3] [f1,f2] | 213 * [c1] [e1,e2,e3] [f1,f2] |
| 212 * | 214 * |
| 213 * The same goes for fTextureAccesses with textures. | 215 * The same goes for fTextureAccesses with textures. |
| 214 */ | 216 */ |
| 215 SkSTArray<4, const GrCoordTransform*, true> fCoordTransforms; | 217 SkSTArray<4, const GrCoordTransform*, true> fCoordTransforms; |
| 216 int fNumTexturesExclChildren; | 218 int fNumTexturesExclChildren; |
| 217 int fNumBuffersExclChildren; | 219 int fNumBuffersExclChildren; |
| 218 int fNumTransformsExclChildren; | 220 int fNumTransformsExclChildren; |
| 219 SkSTArray<1, const GrFragmentProcessor*, true> fChildProcessors; | 221 |
| 222 /** |
| 223 * This is not SkSTArray<1, sk_sp<GrFragmentProcessor>> because this class h
olds strong |
| 224 * references until notifyRefCntIsZero and then it holds pending executions. |
| 225 */ |
| 226 SkSTArray<1, GrFragmentProcessor*, true> fChildProcessors; |
| 220 | 227 |
| 221 typedef GrProcessor INHERITED; | 228 typedef GrProcessor INHERITED; |
| 222 }; | 229 }; |
| 223 | 230 |
| 224 #endif | 231 #endif |
| OLD | NEW |