Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(585)

Unified Diff: src/gpu/gl/builders/GrGLSkiaProgramBuilder.cpp

Issue 611653002: Cleanup of shader building system (Closed) Base URL: https://skia.googlesource.com/skia.git@solo_gp
Patch Set: more cleanup Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/gpu/gl/builders/GrGLSkiaProgramBuilder.cpp
diff --git a/src/gpu/gl/builders/GrGLSkiaProgramBuilder.cpp b/src/gpu/gl/builders/GrGLSkiaProgramBuilder.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..262af30921cfe421778947f11c85afa447890490
--- /dev/null
+++ b/src/gpu/gl/builders/GrGLSkiaProgramBuilder.cpp
@@ -0,0 +1,76 @@
+/*
+ * Copyright 2014 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "GrGLSkiaProgramBuilder.h"
+#include "../GrGLProgram.h"
+
+GrGLSkiaProgramBuilder::GrGLSkiaProgramBuilder(GrGpuGL* gpu,
+ const GrGLProgramDesc& desc)
+ : INHERITED(gpu, desc) {
+}
+
+void GrGLSkiaProgramBuilder::emitTransforms(const GrProcessorStage& effectStage,
+ GrGLProcessor::TransformedCoordsArray* outCoords,
+ GrGLInstalledProcessors* installedProcessors) {
+ SkTArray<GrGLInstalledProcessors::Transform, true>& transforms =
+ installedProcessors->addTransforms();
+ const GrProcessor* effect = effectStage.getProcessor();
+ int numTransforms = effect->numTransforms();
+ transforms.push_back_n(numTransforms);
+
+ for (int t = 0; t < numTransforms; t++) {
+ const char* uniName = "StageMatrix";
+ GrSLType varyingType =
+ effectStage.isPerspectiveCoordTransform(t, fVS.hasExplicitLocalCoords()) ?
+ kVec3f_GrSLType :
+ kVec2f_GrSLType;
+
+ SkString suffixedUniName;
+ if (0 != t) {
+ suffixedUniName.append(uniName);
+ suffixedUniName.appendf("_%i", t);
+ uniName = suffixedUniName.c_str();
+ }
+ transforms[t].fHandle = this->addUniform(GrGLProgramBuilder::kVertex_Visibility,
+ kMat33f_GrSLType,
+ uniName,
+ &uniName).toShaderBuilderIndex();
+
+ const char* varyingName = "MatrixCoord";
+ SkString suffixedVaryingName;
+ if (0 != t) {
+ suffixedVaryingName.append(varyingName);
+ suffixedVaryingName.appendf("_%i", t);
+ varyingName = suffixedVaryingName.c_str();
+ }
+ const char* vsVaryingName;
+ const char* fsVaryingName;
+ this->addVarying(varyingType, varyingName, &vsVaryingName, &fsVaryingName);
+
+ const GrGLShaderVar& coords =
+ kPosition_GrCoordSet == effect->coordTransform(t).sourceCoords() ?
+ fVS.positionAttribute() :
+ fVS.localCoordsAttribute();
+
+ // varying = matrix * coords (logically)
+ SkASSERT(kVec2f_GrSLType == varyingType || kVec3f_GrSLType == varyingType);
+ if (kVec2f_GrSLType == varyingType) {
+ fVS.codeAppendf("%s = (%s * vec3(%s, 1)).xy;",
+ vsVaryingName, uniName, coords.c_str());
+ } else {
+ fVS.codeAppendf("%s = %s * vec3(%s, 1);",
+ vsVaryingName, uniName, coords.c_str());
+ }
+ SkNEW_APPEND_TO_TARRAY(outCoords, GrGLProcessor::TransformedCoords,
+ (SkString(fsVaryingName), varyingType));
+ }
+}
+
+GrGLProgram* GrGLSkiaProgramBuilder::createProgram(GrGLuint programID) {
+ return SkNEW_ARGS(GrGLSkiaProgram, (fGpu, fDesc, fUniformHandles, programID, fUniforms,
+ fGeometryProcessor, fColorEffects, fCoverageEffects));
+}

Powered by Google App Engine
This is Rietveld 408576698