| 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 GrGLGeometryProcessor_DEFINED | 8 #ifndef GrGLGeometryProcessor_DEFINED |
| 9 #define GrGLGeometryProcessor_DEFINED | 9 #define GrGLGeometryProcessor_DEFINED |
| 10 | 10 |
| 11 #include "GrGLProcessor.h" | 11 #include "GrGLPrimitiveProcessor.h" |
| 12 | 12 |
| 13 class GrBatchTracker; | 13 class GrGLVertexBuilder; |
| 14 class GrFragmentProcessor; | |
| 15 class GrGLGPBuilder; | |
| 16 | 14 |
| 17 class GrGLPrimitiveProcessor { | |
| 18 public: | |
| 19 GrGLPrimitiveProcessor() : fViewMatrixName(NULL) { fViewMatrix = SkMatrix::I
nvalidMatrix(); } | |
| 20 virtual ~GrGLPrimitiveProcessor() {} | |
| 21 | |
| 22 typedef GrGLProgramDataManager::UniformHandle UniformHandle; | |
| 23 typedef GrGLProcessor::TextureSamplerArray TextureSamplerArray; | |
| 24 | |
| 25 typedef SkSTArray<2, const GrCoordTransform*, true> ProcCoords; | |
| 26 typedef SkSTArray<8, ProcCoords> TransformsIn; | |
| 27 typedef SkSTArray<8, GrGLProcessor::TransformedCoordsArray> TransformsOut; | |
| 28 | |
| 29 struct EmitArgs { | |
| 30 EmitArgs(GrGLGPBuilder* pb, | |
| 31 const GrPrimitiveProcessor& gp, | |
| 32 const GrBatchTracker& bt, | |
| 33 const char* outputColor, | |
| 34 const char* outputCoverage, | |
| 35 const TextureSamplerArray& samplers, | |
| 36 const TransformsIn& transformsIn, | |
| 37 TransformsOut* transformsOut) | |
| 38 : fPB(pb) | |
| 39 , fGP(gp) | |
| 40 , fBT(bt) | |
| 41 , fOutputColor(outputColor) | |
| 42 , fOutputCoverage(outputCoverage) | |
| 43 , fSamplers(samplers) | |
| 44 , fTransformsIn(transformsIn) | |
| 45 , fTransformsOut(transformsOut) {} | |
| 46 GrGLGPBuilder* fPB; | |
| 47 const GrPrimitiveProcessor& fGP; | |
| 48 const GrBatchTracker& fBT; | |
| 49 const char* fOutputColor; | |
| 50 const char* fOutputCoverage; | |
| 51 const TextureSamplerArray& fSamplers; | |
| 52 const TransformsIn& fTransformsIn; | |
| 53 TransformsOut* fTransformsOut; | |
| 54 }; | |
| 55 | |
| 56 /** | |
| 57 * This is similar to emitCode() in the base class, except it takes a full s
hader builder. | |
| 58 * This allows the effect subclass to emit vertex code. | |
| 59 */ | |
| 60 virtual void emitCode(EmitArgs&) = 0; | |
| 61 | |
| 62 | |
| 63 /** A GrGLPrimitiveProcessor instance can be reused with any GrGLPrimitivePr
ocessor that | |
| 64 produces the same stage key; this function reads data from a GrGLPrimiti
veProcessor and | |
| 65 uploads any uniform variables required by the shaders created in emitCo
de(). The | |
| 66 GrPrimitiveProcessor parameter is guaranteed to be of the same type that
created this | |
| 67 GrGLPrimitiveProcessor and to have an identical processor key as the one
that created this | |
| 68 GrGLPrimitiveProcessor. */ | |
| 69 virtual void setData(const GrGLProgramDataManager&, | |
| 70 const GrPrimitiveProcessor&, | |
| 71 const GrBatchTracker&) = 0; | |
| 72 | |
| 73 static SkMatrix GetTransformMatrix(const SkMatrix& localMatrix, const GrCoor
dTransform&); | |
| 74 | |
| 75 protected: | |
| 76 /** a helper which can setup vertex, constant, or uniform color depending on
inputType. | |
| 77 * This function will only do the minimum required to emit the correct shad
er code. If | |
| 78 * inputType == attribute, then colorAttr must not be NULL. Likewise, if i
nputType == Uniform | |
| 79 * then colorUniform must not be NULL. | |
| 80 */ | |
| 81 void setupColorPassThrough(GrGLGPBuilder* pb, | |
| 82 GrGPInput inputType, | |
| 83 const char* inputName, | |
| 84 const GrGeometryProcessor::Attribute* colorAttr, | |
| 85 UniformHandle* colorUniform); | |
| 86 | |
| 87 const char* uViewM() const { return fViewMatrixName; } | |
| 88 | |
| 89 /** a helper function to setup the uniform handle for the uniform view matri
x */ | |
| 90 void addUniformViewMatrix(GrGLGPBuilder*); | |
| 91 | |
| 92 | |
| 93 /** a helper function to upload a uniform viewmatrix. | |
| 94 * TODO we can remove this function when we have deferred geometry in place | |
| 95 */ | |
| 96 void setUniformViewMatrix(const GrGLProgramDataManager&, | |
| 97 const SkMatrix& viewMatrix); | |
| 98 | |
| 99 class ShaderVarHandle { | |
| 100 public: | |
| 101 bool isValid() const { return fHandle > -1; } | |
| 102 ShaderVarHandle() : fHandle(-1) {} | |
| 103 ShaderVarHandle(int value) : fHandle(value) { SkASSERT(this->isValid());
} | |
| 104 int handle() const { SkASSERT(this->isValid()); return fHandle; } | |
| 105 UniformHandle convertToUniformHandle() { | |
| 106 SkASSERT(this->isValid()); | |
| 107 return GrGLProgramDataManager::UniformHandle::CreateFromUniformIndex
(fHandle); | |
| 108 } | |
| 109 | |
| 110 private: | |
| 111 int fHandle; | |
| 112 }; | |
| 113 | |
| 114 struct Transform { | |
| 115 Transform() : fType(kVoid_GrSLType) { fCurrentValue = SkMatrix::InvalidM
atrix(); } | |
| 116 ShaderVarHandle fHandle; | |
| 117 SkMatrix fCurrentValue; | |
| 118 GrSLType fType; | |
| 119 }; | |
| 120 | |
| 121 SkSTArray<8, SkSTArray<2, Transform, true> > fInstalledTransforms; | |
| 122 | |
| 123 private: | |
| 124 UniformHandle fViewMatrixUniform; | |
| 125 SkMatrix fViewMatrix; | |
| 126 const char* fViewMatrixName; | |
| 127 }; | |
| 128 | |
| 129 class GrGLPathRendering; | |
| 130 class GrGLVertexBuilder; | |
| 131 /** | 15 /** |
| 132 * If a GL effect needs a GrGLFullShaderBuilder* object to emit vertex code, the
n it must inherit | 16 * If a GL effect needs a GrGLFullShaderBuilder* object to emit vertex code, the
n it must inherit |
| 133 * from this class. Since paths don't have vertices, this class is only meant to
be used internally | 17 * from this class. Since paths don't have vertices, this class is only meant to
be used internally |
| 134 * by skia, for special cases. | 18 * by skia, for special cases. |
| 135 */ | 19 */ |
| 136 class GrGLGeometryProcessor : public GrGLPrimitiveProcessor { | 20 class GrGLGeometryProcessor : public GrGLPrimitiveProcessor { |
| 137 public: | 21 public: |
| 138 /* Any general emit code goes in the base class emitCode. Subclasses overri
de onEmitCode */ | 22 /* Any general emit code goes in the base class emitCode. Subclasses overri
de onEmitCode */ |
| 139 void emitCode(EmitArgs&) SK_OVERRIDE; | 23 void emitCode(EmitArgs&) SK_OVERRIDE; |
| 140 | 24 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 return 0x02; | 66 return 0x02; |
| 183 } | 67 } |
| 184 } | 68 } |
| 185 | 69 |
| 186 private: | 70 private: |
| 187 virtual void onEmitCode(EmitArgs&, GrGPArgs*) = 0; | 71 virtual void onEmitCode(EmitArgs&, GrGPArgs*) = 0; |
| 188 | 72 |
| 189 typedef GrGLPrimitiveProcessor INHERITED; | 73 typedef GrGLPrimitiveProcessor INHERITED; |
| 190 }; | 74 }; |
| 191 | 75 |
| 192 class GrGLGpu; | |
| 193 | |
| 194 class GrGLPathProcessor : public GrGLPrimitiveProcessor { | |
| 195 public: | |
| 196 GrGLPathProcessor(const GrPathProcessor&, const GrBatchTracker&); | |
| 197 | |
| 198 static void GenKey(const GrPathProcessor&, | |
| 199 const GrBatchTracker& bt, | |
| 200 const GrGLCaps&, | |
| 201 GrProcessorKeyBuilder* b); | |
| 202 | |
| 203 void emitCode(EmitArgs&) SK_OVERRIDE; | |
| 204 | |
| 205 virtual void emitTransforms(GrGLGPBuilder*, const TransformsIn&, TransformsO
ut*) = 0; | |
| 206 | |
| 207 virtual void resolveSeparableVaryings(GrGLGpu* gpu, GrGLuint programId) {} | |
| 208 | |
| 209 void setData(const GrGLProgramDataManager&, | |
| 210 const GrPrimitiveProcessor&, | |
| 211 const GrBatchTracker&) SK_OVERRIDE; | |
| 212 | |
| 213 virtual void setTransformData(const GrPrimitiveProcessor&, | |
| 214 int index, | |
| 215 const SkTArray<const GrCoordTransform*, true>&
transforms, | |
| 216 GrGLPathRendering*, | |
| 217 GrGLuint programID) = 0; | |
| 218 | |
| 219 virtual void didSetData(GrGLPathRendering*) {} | |
| 220 | |
| 221 private: | |
| 222 UniformHandle fColorUniform; | |
| 223 GrColor fColor; | |
| 224 | |
| 225 typedef GrGLPrimitiveProcessor INHERITED; | |
| 226 }; | |
| 227 | |
| 228 #endif | 76 #endif |
| OLD | NEW |