Fuse GrPrimitiveProcessor & GrGeometryProcessor into a new GrGeometryProcessor
With the removal of NVPR we no longer need this distinction.
Bug: skia:11760
Change-Id: I225a4feb764395fb72aca3ffc8b6d05396bf0b1e
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/386890
Commit-Queue: Robert Phillips <robertphillips@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
Reviewed-by: Michael Ludwig <michaelludwig@google.com>
diff --git a/src/gpu/GrGeometryProcessor.cpp b/src/gpu/GrGeometryProcessor.cpp
new file mode 100644
index 0000000..18f772a
--- /dev/null
+++ b/src/gpu/GrGeometryProcessor.cpp
@@ -0,0 +1,85 @@
+/*
+ * 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 "src/gpu/GrGeometryProcessor.h"
+
+#include "src/gpu/GrFragmentProcessor.h"
+
+/**
+ * We specialize the vertex or fragment coord transform code for these matrix types, and where
+ * the transform code is applied.
+ */
+enum SampleFlag {
+ kExplicitlySampled_Flag = 0b0001, // GrFP::isSampledWithExplicitCoords()
+
+ kNone_SampleMatrix_Flag = 0b0010, // GrFP::sampleUsage()::hasMatrix() == false
+ kUniform_SampleMatrix_Flag = 0b0100, // GrFP::sampleUsage()::hasUniformMatrix()
+ kVariable_SampleMatrix_Flag = 0b0110, // GrFP::sampleUsage()::hasVariableMatrix()
+
+ // Currently, sample(matrix) only specializes on no-perspective or general.
+ // FIXME add new flags as more matrix types are supported.
+ kPersp_Matrix_Flag = 0b1000, // GrFP::sampleUsage()::fHasPerspective
+};
+
+GrGeometryProcessor::GrGeometryProcessor(ClassID classID) : GrProcessor(classID) {}
+
+const GrGeometryProcessor::TextureSampler& GrGeometryProcessor::textureSampler(int i) const {
+ SkASSERT(i >= 0 && i < this->numTextureSamplers());
+ return this->onTextureSampler(i);
+}
+
+uint32_t GrGeometryProcessor::ComputeCoordTransformsKey(const GrFragmentProcessor& fp) {
+ // This is highly coupled with the code in GrGLSLGeometryProcessor::collectTransforms().
+
+ uint32_t key = 0;
+ if (fp.isSampledWithExplicitCoords()) {
+ key |= kExplicitlySampled_Flag;
+ }
+
+ switch(fp.sampleUsage().fKind) {
+ case SkSL::SampleUsage::Kind::kNone:
+ key |= kNone_SampleMatrix_Flag;
+ break;
+ case SkSL::SampleUsage::Kind::kUniform:
+ key |= kUniform_SampleMatrix_Flag;
+ break;
+ case SkSL::SampleUsage::Kind::kVariable:
+ key |= kVariable_SampleMatrix_Flag;
+ break;
+ }
+ if (fp.sampleUsage().fHasPerspective) {
+ key |= kPersp_Matrix_Flag;
+ }
+
+ return key;
+}
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+static inline GrSamplerState::Filter clamp_filter(GrTextureType type,
+ GrSamplerState::Filter requestedFilter) {
+ if (GrTextureTypeHasRestrictedSampling(type)) {
+ return std::min(requestedFilter, GrSamplerState::Filter::kLinear);
+ }
+ return requestedFilter;
+}
+
+GrGeometryProcessor::TextureSampler::TextureSampler(GrSamplerState samplerState,
+ const GrBackendFormat& backendFormat,
+ const GrSwizzle& swizzle) {
+ this->reset(samplerState, backendFormat, swizzle);
+}
+
+void GrGeometryProcessor::TextureSampler::reset(GrSamplerState samplerState,
+ const GrBackendFormat& backendFormat,
+ const GrSwizzle& swizzle) {
+ fSamplerState = samplerState;
+ fSamplerState.setFilterMode(clamp_filter(backendFormat.textureType(), samplerState.filter()));
+ fBackendFormat = backendFormat;
+ fSwizzle = swizzle;
+ fIsInitialized = true;
+}