| 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 |
| 11 #include "GrProcessor.h" | 11 #include "GrProcessor.h" |
| 12 | 12 |
| 13 class GrCoordTransform; | 13 class GrCoordTransform; |
| 14 class GrGLCaps; | 14 class GrGLCaps; |
| 15 class GrGLFragmentProcessor; | 15 class GrGLFragmentProcessor; |
| 16 class GrProcessorKeyBuilder; | 16 class GrProcessorKeyBuilder; |
| 17 | 17 |
| 18 /** Provides custom fragment shader code. Fragment processors receive an input c
olor (vec4f) and | 18 /** Provides custom fragment shader code. Fragment processors receive an input c
olor (vec4f) and |
| 19 produce an output color. They may reference textures and uniforms. They may
use | 19 produce an output color. They may reference textures and uniforms. They may
use |
| 20 GrCoordTransforms to receive a transformation of the local coordinates that
map from local space | 20 GrCoordTransforms to receive a transformation of the local coordinates that
map from local space |
| 21 to the fragment being processed. | 21 to the fragment being processed. |
| 22 */ | 22 */ |
| 23 class GrFragmentProcessor : public GrProcessor { | 23 class GrFragmentProcessor : public GrProcessor { |
| 24 public: | 24 public: |
| 25 GrFragmentProcessor() | 25 GrFragmentProcessor() |
| 26 : INHERITED() | 26 : INHERITED() |
| 27 , fWillReadDstColor(false) | 27 , fWillReadDstColor(false) |
| 28 , fWillUseInputColor(true) {} | 28 , fWillUseInputColor(true) |
| 29 , fUsesLocalCoords(false) {} |
| 29 | 30 |
| 30 /** Implemented using GLFragmentProcessor::GenKey as described in this class
's comment. */ | 31 /** Implemented using GLFragmentProcessor::GenKey as described in this class
's comment. */ |
| 31 virtual void getGLProcessorKey(const GrGLCaps& caps, | 32 virtual void getGLProcessorKey(const GrGLCaps& caps, |
| 32 GrProcessorKeyBuilder* b) const = 0; | 33 GrProcessorKeyBuilder* b) const = 0; |
| 33 | 34 |
| 34 /** Returns a new instance of the appropriate *GL* implementation class | 35 /** Returns a new instance of the appropriate *GL* implementation class |
| 35 for the given GrFragmentProcessor; caller is responsible for deleting | 36 for the given GrFragmentProcessor; caller is responsible for deleting |
| 36 the object. */ | 37 the object. */ |
| 37 virtual GrGLFragmentProcessor* createGLInstance() const = 0; | 38 virtual GrGLFragmentProcessor* createGLInstance() const = 0; |
| 38 | 39 |
| 39 /** Human-meaningful string to identify this GrFragmentProcessor; may be emb
edded | 40 /** Human-meaningful string to identify this GrFragmentProcessor; may be emb
edded |
| 40 in generated shader code. */ | 41 in generated shader code. */ |
| 41 virtual const char* name() const = 0; | 42 virtual const char* name() const = 0; |
| 42 | 43 |
| 43 int numTransforms() const { return fCoordTransforms.count(); } | 44 int numTransforms() const { return fCoordTransforms.count(); } |
| 44 | 45 |
| 45 /** Returns the coordinate transformation at index. index must be valid acco
rding to | 46 /** Returns the coordinate transformation at index. index must be valid acco
rding to |
| 46 numTransforms(). */ | 47 numTransforms(). */ |
| 47 const GrCoordTransform& coordTransform(int index) const { return *fCoordTran
sforms[index]; } | 48 const GrCoordTransform& coordTransform(int index) const { return *fCoordTran
sforms[index]; } |
| 48 | 49 |
| 49 /** Will this prceossor read the destination pixel value? */ | 50 /** Will this prceossor read the destination pixel value? */ |
| 50 bool willReadDstColor() const { return fWillReadDstColor; } | 51 bool willReadDstColor() const { return fWillReadDstColor; } |
| 51 | 52 |
| 52 /** Will this prceossor read the source color value? */ | 53 /** Will this prceossor read the source color value? */ |
| 53 bool willUseInputColor() const { return fWillUseInputColor; } | 54 bool willUseInputColor() const { return fWillUseInputColor; } |
| 54 | 55 |
| 56 /** Do any of the coordtransforms for this processor require local coords? *
/ |
| 57 bool usesLocalCoords() const { return fUsesLocalCoords; } |
| 58 |
| 55 /** Returns true if this and other processor conservatively draw identically
. It can only return | 59 /** Returns true if this and other processor conservatively draw identically
. It can only return |
| 56 true when the two processor are of the same subclass (i.e. they return t
he same object from | 60 true when the two processor are of the same subclass (i.e. they return t
he same object from |
| 57 from getFactory()). | 61 from getFactory()). |
| 58 | 62 |
| 59 A return value of true from isEqual() should not be used to test whether
the processor would | 63 A return value of true from isEqual() should not be used to test whether
the processor would |
| 60 generate the same shader code. To test for identical code generation use
getGLProcessorKey*/ | 64 generate the same shader code. To test for identical code generation use
getGLProcessorKey*/ |
| 61 bool isEqual(const GrFragmentProcessor& that) const { | 65 bool isEqual(const GrFragmentProcessor& that) const { |
| 62 if (this->classID() != that.classID() || | 66 if (this->classID() != that.classID() || |
| 63 !this->hasSameTransforms(that) || | 67 !this->hasSameTransforms(that) || |
| 64 !this->hasSameTextureAccesses(that)) { | 68 !this->hasSameTextureAccesses(that)) { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 * getFactory()). The processor subclass should not compare its coord transf
orms as that will | 127 * getFactory()). The processor subclass should not compare its coord transf
orms as that will |
| 124 * be performed automatically in the non-virtual isEqual(). | 128 * be performed automatically in the non-virtual isEqual(). |
| 125 */ | 129 */ |
| 126 virtual bool onIsEqual(const GrFragmentProcessor&) const = 0; | 130 virtual bool onIsEqual(const GrFragmentProcessor&) const = 0; |
| 127 | 131 |
| 128 bool hasSameTransforms(const GrFragmentProcessor&) const; | 132 bool hasSameTransforms(const GrFragmentProcessor&) const; |
| 129 | 133 |
| 130 SkSTArray<4, const GrCoordTransform*, true> fCoordTransforms; | 134 SkSTArray<4, const GrCoordTransform*, true> fCoordTransforms; |
| 131 bool fWillReadDstColor; | 135 bool fWillReadDstColor; |
| 132 bool fWillUseInputColor; | 136 bool fWillUseInputColor; |
| 137 bool fUsesLocalCoords; |
| 133 | 138 |
| 134 typedef GrProcessor INHERITED; | 139 typedef GrProcessor INHERITED; |
| 135 }; | 140 }; |
| 136 | 141 |
| 137 #endif | 142 #endif |
| OLD | NEW |