aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/GrProcessorAnalysis.h
diff options
context:
space:
mode:
authorGravatar Brian Salomon <bsalomon@google.com>2017-03-30 08:21:32 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-03-30 15:19:53 +0000
commita811b1200cc0b5e3819c89f62def23ec203d4b5a (patch)
treea09fe4fd05dd1246c2e5c9b364a0f8fb498f9d56 /src/gpu/GrProcessorAnalysis.h
parent13071c5c7aa51b9e57dbe88c1fce0575780985aa (diff)
Renames of processor analysis-related classes and method.
GrProcesserSet::FragmentProcessorAnalysis->GrProcessorSet::Analysis GrPipelineAnalysisColor->GrProcessorAnalysisColor GrPipelineAnalysisCoverage->GrProcessorAnalysisCoverage GrMeshDrawOp::getFragmentProcessorAnalysisInputs->GrMeshDrawOp::getProcessorAnalysisInputs Change-Id: I28ad19dfab5f4ac1788c4eacdec5e1af2a701dd0 Reviewed-on: https://skia-review.googlesource.com/10747 Reviewed-by: Greg Daniel <egdaniel@google.com> Commit-Queue: Brian Salomon <bsalomon@google.com>
Diffstat (limited to 'src/gpu/GrProcessorAnalysis.h')
-rw-r--r--src/gpu/GrProcessorAnalysis.h172
1 files changed, 172 insertions, 0 deletions
diff --git a/src/gpu/GrProcessorAnalysis.h b/src/gpu/GrProcessorAnalysis.h
new file mode 100644
index 0000000000..ad56ab4e2d
--- /dev/null
+++ b/src/gpu/GrProcessorAnalysis.h
@@ -0,0 +1,172 @@
+/*
+ * Copyright 2014 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef GrProcessorAnalysis_DEFINED
+#define GrProcessorAnalysis_DEFINED
+
+#include "GrColor.h"
+
+class GrDrawOp;
+class GrFragmentProcessor;
+class GrPrimitiveProcessor;
+
+class GrProcessorAnalysisColor {
+public:
+ enum class Opaque {
+ kNo,
+ kYes,
+ };
+
+ GrProcessorAnalysisColor(Opaque opaque = Opaque::kNo)
+ : fFlags(opaque == Opaque::kYes ? kIsOpaque_Flag : 0) {}
+
+ GrProcessorAnalysisColor(GrColor color) { this->setToConstant(color); }
+
+ void setToConstant(GrColor color) {
+ fColor = color;
+ if (GrColorIsOpaque(color)) {
+ fFlags = kColorIsKnown_Flag | kIsOpaque_Flag;
+ } else {
+ fFlags = kColorIsKnown_Flag;
+ }
+ }
+
+ void setToUnknown() { fFlags = 0; }
+
+ void setToUnknownOpaque() { fFlags = kIsOpaque_Flag; }
+
+ bool isOpaque() const { return SkToBool(kIsOpaque_Flag & fFlags); }
+
+ bool isConstant(GrColor* color = nullptr) const {
+ if (kColorIsKnown_Flag & fFlags) {
+ if (color) {
+ *color = fColor;
+ }
+ return true;
+ }
+ return false;
+ }
+
+ bool operator==(const GrProcessorAnalysisColor& that) const {
+ if (fFlags != that.fFlags) {
+ return false;
+ }
+ return (kColorIsKnown_Flag & fFlags) ? fColor == that.fColor : true;
+ }
+
+ /** The returned value reflects the common properties of the two inputs. */
+ static GrProcessorAnalysisColor Combine(const GrProcessorAnalysisColor& a,
+ const GrProcessorAnalysisColor& b) {
+ GrProcessorAnalysisColor result;
+ uint32_t commonFlags = a.fFlags & b.fFlags;
+ if ((kColorIsKnown_Flag & commonFlags) && a.fColor == b.fColor) {
+ result.fColor = a.fColor;
+ result.fFlags = a.fFlags;
+ } else if (kIsOpaque_Flag & commonFlags) {
+ result.fFlags = kIsOpaque_Flag;
+ }
+ return result;
+ }
+
+private:
+ enum Flags {
+ kColorIsKnown_Flag = 0x1,
+ kIsOpaque_Flag = 0x2,
+ };
+ uint32_t fFlags;
+ GrColor fColor;
+};
+
+enum class GrProcessorAnalysisCoverage { kNone, kSingleChannel, kLCD };
+
+/**
+ * GrColorFragmentProcessorAnalysis gathers invariant data from a set of color fragment processor.
+ * It is used to recognize optimizations that can simplify the generated shader or make blending
+ * more effecient.
+ */
+class GrColorFragmentProcessorAnalysis {
+public:
+ GrColorFragmentProcessorAnalysis() = default;
+
+ GrColorFragmentProcessorAnalysis(const GrProcessorAnalysisColor& input)
+ : GrColorFragmentProcessorAnalysis() {
+ fAllProcessorsCompatibleWithCoverageAsAlpha = true;
+ fIsOpaque = input.isOpaque();
+ GrColor color;
+ if (input.isConstant(&color)) {
+ fLastKnownOutputColor = GrColor4f::FromGrColor(color);
+ fProcessorsVisitedWithKnownOutput = 0;
+ }
+ }
+
+ void reset(const GrProcessorAnalysisColor& input) {
+ *this = GrColorFragmentProcessorAnalysis(input);
+ }
+
+ /**
+ * Runs through a series of processors and updates calculated values. This can be called
+ * repeatedly for cases when the sequence of processors is not in a contiguous array.
+ */
+ void analyzeProcessors(const GrFragmentProcessor* const* processors, int cnt);
+
+ bool isOpaque() const { return fIsOpaque; }
+
+ /**
+ * Are all the fragment processors compatible with conflating coverage with color prior to the
+ * the first fragment processor. This result does not consider processors that should be
+ * eliminated as indicated by initialProcessorsToEliminate().
+ */
+ bool allProcessorsCompatibleWithCoverageAsAlpha() const {
+ return fAllProcessorsCompatibleWithCoverageAsAlpha;
+ }
+
+ /**
+ * Do any of the fragment processors require local coords. This result does not consider
+ * processors that should be eliminated as indicated by initialProcessorsToEliminate().
+ */
+ bool usesLocalCoords() const { return fUsesLocalCoords; }
+
+ /**
+ * If we detected that the result after the first N processors is a known color then we
+ * eliminate those N processors and replace the GrDrawOp's color input to the GrPipeline with
+ * the known output of the Nth processor, so that the Nth+1 fragment processor (or the XP if
+ * there are only N processors) sees its expected input. If this returns 0 then there are no
+ * processors to eliminate.
+ */
+ int initialProcessorsToEliminate(GrColor* newPipelineInputColor) const {
+ if (fProcessorsVisitedWithKnownOutput > 0) {
+ *newPipelineInputColor = fLastKnownOutputColor.toGrColor();
+ }
+ return SkTMax(0, fProcessorsVisitedWithKnownOutput);
+ }
+
+ int initialProcessorsToEliminate(GrColor4f* newPipelineInputColor) const {
+ if (fProcessorsVisitedWithKnownOutput > 0) {
+ *newPipelineInputColor = fLastKnownOutputColor;
+ }
+ return SkTMax(0, fProcessorsVisitedWithKnownOutput);
+ }
+
+ GrProcessorAnalysisColor outputColor() const {
+ if (fProcessorsVisitedWithKnownOutput != fTotalProcessorsVisited) {
+ return GrProcessorAnalysisColor(fIsOpaque ? GrProcessorAnalysisColor::Opaque::kYes
+ : GrProcessorAnalysisColor::Opaque::kNo);
+ }
+ return GrProcessorAnalysisColor(fLastKnownOutputColor.toGrColor());
+ }
+
+private:
+ int fTotalProcessorsVisited = 0;
+ // negative one means even the color is unknown before adding the first processor.
+ int fProcessorsVisitedWithKnownOutput = -1;
+ bool fIsOpaque = false;
+ bool fAllProcessorsCompatibleWithCoverageAsAlpha = true;
+ bool fUsesLocalCoords = false;
+ GrColor4f fLastKnownOutputColor;
+};
+
+#endif