Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright 2014 Google Inc. | |
| 3 * | |
| 4 * Use of this source code is governed by a BSD-style license that can be | |
| 5 * found in the LICENSE file. | |
| 6 */ | |
| 7 | |
| 8 #include "GrDefaultGeoProcFactory.h" | |
| 9 | |
| 10 #include "gl/builders/GrGLProgramBuilder.h" | |
| 11 #include "gl/GrGLGeometryProcessor.h" | |
| 12 #include "GrDrawState.h" | |
| 13 #include "GrTBackendProcessorFactory.h" | |
| 14 | |
| 15 /* | |
| 16 * The default Geometry Processor simply takes position and multiplies it by the uniform view matrix | |
| 17 * . It also leaves coverage untouched. Behind the scenes, we may add per vert ex color or local | |
|
bsalomon
2014/10/27 13:43:43
odd wrapping here
| |
| 18 * coords. | |
| 19 */ | |
| 20 class DefaultGeoProc : public GrGeometryProcessor { | |
| 21 public: | |
| 22 static GrGeometryProcessor* Create() { | |
| 23 GR_CREATE_STATIC_PROCESSOR(gDefaultGeoProc, DefaultGeoProc, ()); | |
| 24 return SkRef(gDefaultGeoProc); | |
| 25 } | |
| 26 | |
| 27 static const char* Name() { return "DefaultGeometryProcessor"; } | |
| 28 | |
| 29 virtual const GrBackendGeometryProcessorFactory& getFactory() const SK_OVERR IDE { | |
| 30 return GrTBackendGeometryProcessorFactory<DefaultGeoProc>::getInstance() ; | |
| 31 } | |
| 32 | |
| 33 class GLProcessor : public GrGLGeometryProcessor { | |
| 34 public: | |
| 35 GLProcessor(const GrBackendProcessorFactory& factory, const GrProcessor& ) | |
| 36 : INHERITED (factory) {} | |
| 37 | |
| 38 virtual void emitCode(const EmitArgs& args) SK_OVERRIDE { | |
| 39 const DefaultGeoProc& gp = args.fGP.cast<DefaultGeoProc>(); | |
| 40 GrGLVertexBuilder* vs = args.fPB->getVertexShaderBuilder(); | |
| 41 | |
| 42 // setup position varying | |
| 43 vs->codeAppendf("vec3 pos3 = %s * vec3(%s, 1);", gp.uViewM(), gp.inP osition()); | |
| 44 vs->transformPositionToDeviceSpace("pos3"); | |
| 45 | |
| 46 // output coverage in FS(pass through) | |
| 47 GrGLGPFragmentBuilder* fs = args.fPB->getFragmentShaderBuilder(); | |
| 48 fs->codeAppendf("%s = %s;", args.fOutput, GrGLSLExpr4(args.fInput).c _str()); | |
| 49 } | |
| 50 | |
| 51 static inline void GenKey(const GrProcessor&, const GrGLCaps&, GrProcess orKeyBuilder*) {} | |
| 52 | |
| 53 virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_OVERRIDE {} | |
| 54 | |
| 55 private: | |
| 56 typedef GrGLGeometryProcessor INHERITED; | |
| 57 }; | |
| 58 | |
| 59 private: | |
| 60 DefaultGeoProc() {} | |
| 61 | |
| 62 virtual bool onIsEqual(const GrGeometryProcessor& other) const SK_OVERRIDE { | |
| 63 return true; | |
| 64 } | |
| 65 | |
| 66 virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERR IDE { | |
| 67 inout->mulByUnknownAlpha(); | |
| 68 } | |
| 69 | |
| 70 GR_DECLARE_GEOMETRY_PROCESSOR_TEST; | |
| 71 | |
| 72 typedef GrFragmentProcessor INHERITED; | |
| 73 }; | |
| 74 | |
| 75 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(DefaultGeoProc); | |
| 76 | |
| 77 GrGeometryProcessor* DefaultGeoProc::TestCreate(SkRandom* random, | |
| 78 GrContext*, | |
| 79 const GrDrawTargetCaps& caps, | |
| 80 GrTexture*[]) { | |
| 81 return DefaultGeoProc::Create(); | |
| 82 } | |
| 83 | |
| 84 // We use these arrays to customize our default GP. We only need 4 because we o mit coverage if | |
| 85 // coverage is not requested in the flags to the create function. | |
| 86 GrVertexAttrib kDefaultPositionGeoProc[] = { | |
| 87 { kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBindi ng }, | |
| 88 { kVec4ub_GrVertexAttribType, sizeof(SkPoint), kCoverage_GrVertexAttribBindi ng }, | |
| 89 }; | |
| 90 | |
| 91 GrVertexAttrib kDefaultPosColorGeoProc[] = { | |
| 92 { kVec2f_GrVertexAttribType, 0, kPosition_G rVertexAttribBinding }, | |
| 93 { kVec4ub_GrVertexAttribType, sizeof(SkPoint), kColor_GrVe rtexAttribBinding }, | |
| 94 { kVec4ub_GrVertexAttribType, sizeof(SkPoint) + sizeof(GrColor), kCoverage_G rVertexAttribBinding }, | |
| 95 }; | |
| 96 | |
| 97 GrVertexAttrib kDefaultPosUVGeoProc[] = { | |
| 98 { kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribB inding }, | |
| 99 { kVec2f_GrVertexAttribType, sizeof(SkPoint), kLocalCoord_GrVertexAttri bBinding }, | |
| 100 { kVec4ub_GrVertexAttribType, 2 * sizeof(SkPoint), kCoverage_GrVertexAttribB inding }, | |
| 101 }; | |
| 102 | |
| 103 GrVertexAttrib kDefaultPosColUVGeoProc[] = { | |
| 104 { kVec2f_GrVertexAttribType, 0, kPositi on_GrVertexAttribBinding }, | |
| 105 { kVec4ub_GrVertexAttribType, sizeof(SkPoint), kColor_ GrVertexAttribBinding }, | |
| 106 { kVec2f_GrVertexAttribType, sizeof(SkPoint) + sizeof(GrColor), kLocalC oord_GrVertexAttribBinding }, | |
| 107 { kVec4ub_GrVertexAttribType, 2 * sizeof(SkPoint) + sizeof(GrColor), kCovera ge_GrVertexAttribBinding }, | |
| 108 }; | |
| 109 | |
| 110 static size_t get_size(GrDefaultGeoProcFactory::GPType flag) { | |
| 111 switch (flag) { | |
| 112 case GrDefaultGeoProcFactory::kPosition_GPType: | |
| 113 return GrVertexAttribTypeSize(kVec2f_GrVertexAttribType); | |
| 114 case GrDefaultGeoProcFactory::kColor_GPType: | |
| 115 return GrVertexAttribTypeSize(kVec4ub_GrVertexAttribType); | |
| 116 case GrDefaultGeoProcFactory::kUV_GPType: | |
| 117 return GrVertexAttribTypeSize(kVec2f_GrVertexAttribType); | |
| 118 case GrDefaultGeoProcFactory::kCoverage_GPType: | |
| 119 return GrVertexAttribTypeSize(kVec4ub_GrVertexAttribType); | |
| 120 default: | |
| 121 SkFAIL("Should never get here"); | |
| 122 return 0; | |
| 123 } | |
| 124 } | |
| 125 | |
| 126 const GrGeometryProcessor* | |
| 127 GrDefaultGeoProcFactory::CreateAndSetAttribs(GrDrawState* ds, uint32_t gpTypeFla gs) { | |
| 128 SkASSERT(ds); | |
| 129 // always atleast position in the GP | |
| 130 size_t size = get_size(kPosition_GPType); | |
| 131 int count = 1; | |
| 132 | |
| 133 bool hasColor = gpTypeFlags & kColor_GPType; | |
| 134 bool hasUV = gpTypeFlags & kUV_GPType; | |
| 135 bool hasCoverage = gpTypeFlags & kCoverage_GPType; | |
| 136 | |
| 137 if (hasColor) { | |
| 138 size += get_size(kColor_GPType); | |
| 139 count++; | |
| 140 if (hasUV) { | |
| 141 size += get_size(kUV_GPType); | |
| 142 count++; | |
| 143 if (hasCoverage) { | |
| 144 size += get_size(kCoverage_GPType); | |
| 145 count++; | |
| 146 ds->setVertexAttribs<kDefaultPosColUVGeoProc>(count, size); | |
| 147 } else { | |
| 148 ds->setVertexAttribs<kDefaultPosColUVGeoProc>(count, size); | |
| 149 | |
| 150 } | |
| 151 } else { | |
| 152 if (hasCoverage) { | |
| 153 size += get_size(kCoverage_GPType); | |
| 154 count++; | |
| 155 ds->setVertexAttribs<kDefaultPosColorGeoProc>(count, size); | |
| 156 } else { | |
| 157 ds->setVertexAttribs<kDefaultPosColorGeoProc>(count, size); | |
| 158 } | |
| 159 } | |
| 160 } else if (hasUV) { | |
| 161 size += get_size(kUV_GPType); | |
| 162 count++; | |
| 163 if (hasCoverage) { | |
| 164 size += get_size(kCoverage_GPType); | |
| 165 count++; | |
| 166 ds->setVertexAttribs<kDefaultPosUVGeoProc>(count, size); | |
| 167 } else { | |
| 168 ds->setVertexAttribs<kDefaultPosUVGeoProc>(count, size); | |
| 169 } | |
| 170 } else if (hasCoverage) { | |
| 171 size += get_size(kCoverage_GPType); | |
| 172 count++; | |
| 173 ds->setVertexAttribs<kDefaultPositionGeoProc>(count, size); | |
| 174 } else { | |
| 175 // Just position | |
| 176 ds->setVertexAttribs<kDefaultPositionGeoProc>(count, size); | |
| 177 } | |
| 178 return DefaultGeoProc::Create(); | |
| 179 } | |
| 180 | |
| 181 const GrGeometryProcessor* GrDefaultGeoProcFactory::Create() { | |
| 182 return DefaultGeoProc::Create(); | |
| 183 } | |
| OLD | NEW |