Remove srgb flags from GrProcessorSet

Bug: skia:
Change-Id: Icbb1b2f39cac70c9d74603514786d76b46d0afd9
Reviewed-on: https://skia-review.googlesource.com/14603
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
diff --git a/src/gpu/GrPipeline.cpp b/src/gpu/GrPipeline.cpp
index ac1360d..1471b57 100644
--- a/src/gpu/GrPipeline.cpp
+++ b/src/gpu/GrPipeline.cpp
@@ -36,12 +36,6 @@
     if (args.fProcessors->usesDistanceVectorField()) {
         fFlags |= kUsesDistanceVectorField_Flag;
     }
-    if (args.fProcessors->disableOutputConversionToSRGB()) {
-        fFlags |= kDisableOutputConversionToSRGB_Flag;
-    }
-    if (args.fProcessors->allowSRGBInputs()) {
-        fFlags |= kAllowSRGBInputs_Flag;
-    }
     if (!args.fUserStencil->isDisabled(fFlags & kHasStencilClip_Flag)) {
         fFlags |= kStencilEnabled_Flag;
     }
diff --git a/src/gpu/GrPipeline.h b/src/gpu/GrPipeline.h
index 76e9f2e..01d375e 100644
--- a/src/gpu/GrPipeline.h
+++ b/src/gpu/GrPipeline.h
@@ -46,13 +46,27 @@
          * the 3D API.
          */
         kHWAntialias_Flag = 0x1,
-
         /**
          * Modifies the vertex shader so that vertices will be positioned at pixel centers.
          */
         kSnapVerticesToPixelCenters_Flag = 0x2,
+        /** Disables conversion to sRGB from linear when writing to a sRGB destination. */
+        kDisableOutputConversionToSRGB_Flag = 0x4,
+        /** Allows conversion from sRGB to linear when reading from processor's sRGB texture. */
+        kAllowSRGBInputs_Flag = 0x8,
     };
 
+    static uint32_t SRGBFlagsFromPaint(const GrPaint& paint) {
+        uint32_t flags = 0;
+        if (paint.getAllowSRGBInputs()) {
+            flags |= kAllowSRGBInputs_Flag;
+        }
+        if (paint.getDisableOutputConversionToSRGB()) {
+            flags |= kDisableOutputConversionToSRGB_Flag;
+        }
+        return flags;
+    }
+
     struct InitArgs {
         uint32_t fFlags = 0;
         GrDrawFace fDrawFace = GrDrawFace::kBoth;
@@ -217,8 +231,6 @@
 private:
     /** This is a continuation of the public "Flags" enum. */
     enum PrivateFlags {
-        kDisableOutputConversionToSRGB_Flag = 0x4,
-        kAllowSRGBInputs_Flag = 0x8,
         kUsesDistanceVectorField_Flag = 0x10,
         kHasStencilClip_Flag = 0x20,
         kStencilEnabled_Flag = 0x40,
diff --git a/src/gpu/GrPipelineBuilder.h b/src/gpu/GrPipelineBuilder.h
index 78aead0..ef84f5b 100644
--- a/src/gpu/GrPipelineBuilder.h
+++ b/src/gpu/GrPipelineBuilder.h
@@ -29,7 +29,7 @@
      * which is unmodified by this function and clipping which will be enabled.
      */
     GrPipelineBuilder(GrPaint&& paint, GrAAType aaType)
-            : fFlags(0x0)
+            : fFlags(GrPipeline::SRGBFlagsFromPaint(paint))
             , fDrawFace(GrDrawFace::kBoth)
             , fUserStencilSettings(&GrUserStencilSettings::kUnused)
             , fProcessors(std::move(paint)) {
diff --git a/src/gpu/GrProcessorSet.cpp b/src/gpu/GrProcessorSet.cpp
index a76a10b8..69fa69a 100644
--- a/src/gpu/GrProcessorSet.cpp
+++ b/src/gpu/GrProcessorSet.cpp
@@ -30,12 +30,6 @@
         SkDebugf("Insane number of color fragment processors in paint. Dropping all processors.");
         fColorFragmentProcessorCnt = 0;
     }
-    if (paint.getDisableOutputConversionToSRGB()) {
-        fFlags |= kDisableOutputConversionToSRGB_Flag;
-    }
-    if (paint.getAllowSRGBInputs()) {
-        fFlags |= kAllowSRGBInputs_Flag;
-    }
 }
 
 GrProcessorSet::~GrProcessorSet() {
diff --git a/src/gpu/GrProcessorSet.h b/src/gpu/GrProcessorSet.h
index a632aa6..6ebb00b 100644
--- a/src/gpu/GrProcessorSet.h
+++ b/src/gpu/GrProcessorSet.h
@@ -49,10 +49,6 @@
     }
 
     bool usesDistanceVectorField() const { return SkToBool(fFlags & kUseDistanceVectorField_Flag); }
-    bool disableOutputConversionToSRGB() const {
-        return SkToBool(fFlags & kDisableOutputConversionToSRGB_Flag);
-    }
-    bool allowSRGBInputs() const { return SkToBool(fFlags & kAllowSRGBInputs_Flag); }
 
     /** Comparisons are only legal on finalized processor sets. */
     bool operator==(const GrProcessorSet& that) const;
@@ -130,12 +126,7 @@
     // This absurdly large limit allows Analysis and this to pack fields together.
     static constexpr int kMaxColorProcessors = UINT8_MAX;
 
-    enum Flags : uint16_t {
-        kUseDistanceVectorField_Flag = 0x1,
-        kDisableOutputConversionToSRGB_Flag = 0x2,
-        kAllowSRGBInputs_Flag = 0x4,
-        kFinalized_Flag = 0x8
-    };
+    enum Flags : uint16_t { kUseDistanceVectorField_Flag = 0x1, kFinalized_Flag = 0x2 };
 
     union XP {
         XP(const GrXPFactory* factory) : fFactory(factory) {}
diff --git a/src/gpu/instanced/InstancedOp.cpp b/src/gpu/instanced/InstancedOp.cpp
index 1ebb0b5..83a10da 100644
--- a/src/gpu/instanced/InstancedOp.cpp
+++ b/src/gpu/instanced/InstancedOp.cpp
@@ -17,13 +17,15 @@
 
 InstancedOp::InstancedOp(uint32_t classID, GrPaint&& paint, OpAllocator* alloc)
         : INHERITED(classID)
-        , fAllocator(alloc)
-        , fInstancedRendering(nullptr)
-        , fProcessors(std::move(paint))
         , fIsTracked(false)
         , fRequiresBarrierOnOverlap(false)
+        , fAllowsSRGBInputs(paint.getAllowSRGBInputs())
+        , fDisableSRGBOutputConversion(paint.getDisableOutputConversionToSRGB())
         , fNumDraws(1)
-        , fNumChangesInGeometry(0) {
+        , fNumChangesInGeometry(0)
+        , fAllocator(alloc)
+        , fInstancedRendering(nullptr)
+        , fProcessors(std::move(paint)) {
     fHeadDraw = fTailDraw = alloc->allocateDraw();
 #ifdef SK_DEBUG
     fHeadDraw->fGeometry = {-1, 0};
@@ -173,6 +175,10 @@
         return false;
     }
 
+    if (fAllowsSRGBInputs != that->fAllowsSRGBInputs ||
+        fDisableSRGBOutputConversion != that->fDisableSRGBOutputConversion) {
+        return false;
+    }
     SkASSERT(fRequiresBarrierOnOverlap == that->fRequiresBarrierOnOverlap);
     if (fRequiresBarrierOnOverlap && this->bounds().intersects(that->bounds())) {
         return false;
@@ -225,6 +231,12 @@
     args.fCaps = &state->caps();
     args.fProcessors = &fProcessors;
     args.fFlags = GrAATypeIsHW(fInfo.aaType()) ? GrPipeline::kHWAntialias_Flag : 0;
+    if (fAllowsSRGBInputs) {
+        args.fFlags |= GrPipeline::kAllowSRGBInputs_Flag;
+    }
+    if (fDisableSRGBOutputConversion) {
+        args.fFlags |= GrPipeline::kDisableOutputConversionToSRGB_Flag;
+    }
     args.fRenderTarget = state->drawOpArgs().fRenderTarget;
     args.fDstTexture = state->drawOpArgs().fDstTexture;
     pipeline.init(args);
diff --git a/src/gpu/instanced/InstancedOp.h b/src/gpu/instanced/InstancedOp.h
index 55cb82f..7848eff 100644
--- a/src/gpu/instanced/InstancedOp.h
+++ b/src/gpu/instanced/InstancedOp.h
@@ -72,18 +72,20 @@
 protected:
     InstancedOp(uint32_t classID, GrPaint&&, OpAllocator*);
 
+    bool fIsTracked : 1;
+    bool fRequiresBarrierOnOverlap : 1;
+    bool fAllowsSRGBInputs : 1;
+    bool fDisableSRGBOutputConversion : 1;
+    int fNumDraws;
+    int fNumChangesInGeometry;
+    Draw* fHeadDraw;
+    Draw* fTailDraw;
     OpAllocator* fAllocator;
     InstancedRendering* fInstancedRendering;
     OpInfo fInfo;
     SkScalar fPixelLoad;
     GrProcessorSet fProcessors;
     SkSTArray<5, ParamsTexel, true> fParams;
-    bool fIsTracked : 1;
-    bool fRequiresBarrierOnOverlap : 1;
-    int fNumDraws;
-    int fNumChangesInGeometry;
-    Draw* fHeadDraw;
-    Draw* fTailDraw;
 
 private:
     bool onCombineIfPossible(GrOp* other, const GrCaps& caps) override;
diff --git a/src/gpu/ops/GrDrawPathOp.cpp b/src/gpu/ops/GrDrawPathOp.cpp
index 3632787..ccb12bf 100644
--- a/src/gpu/ops/GrDrawPathOp.cpp
+++ b/src/gpu/ops/GrDrawPathOp.cpp
@@ -16,11 +16,10 @@
         : INHERITED(classID)
         , fViewMatrix(viewMatrix)
         , fInputColor(paint.getColor())
-        , fProcessorSet(std::move(paint))
         , fFillType(fill)
-        , fAAType(aaType) {
-    SkASSERT(fAAType != GrAAType::kCoverage);
-}
+        , fAAType(aaType)
+        , fPipelineSRGBFlags(GrPipeline::SRGBFlagsFromPaint(paint))
+        , fProcessorSet(std::move(paint)) {}
 
 SkString GrDrawPathOp::dumpInfo() const {
     SkString string;
@@ -41,7 +40,10 @@
     };
     GrPipeline::InitArgs args;
     args.fProcessors = &this->processors();
-    args.fFlags = GrAATypeIsHW(fAAType) ? GrPipeline::kHWAntialias_Flag : 0;
+    args.fFlags = fPipelineSRGBFlags;
+    if (GrAATypeIsHW(fAAType)) {
+        args.fFlags |= GrPipeline::kHWAntialias_Flag;
+    }
     args.fUserStencil = &kCoverPass;
     args.fAppliedClip = state.drawOpArgs().fAppliedClip;
     args.fRenderTarget = state.drawOpArgs().fRenderTarget;
@@ -113,6 +115,9 @@
     if (this->processors() != that->processors()) {
         return false;
     }
+    if (this->pipelineSRGBFlags() != that->pipelineSRGBFlags()) {
+        return false;
+    }
     switch (fDraws.head()->fInstanceData->transformType()) {
         case GrPathRendering::kNone_PathTransformType:
             if (this->fDraws.head()->fX != that->fDraws.head()->fX ||
diff --git a/src/gpu/ops/GrDrawPathOp.h b/src/gpu/ops/GrDrawPathOp.h
index 8995de4..40db6ef 100644
--- a/src/gpu/ops/GrDrawPathOp.h
+++ b/src/gpu/ops/GrDrawPathOp.h
@@ -40,6 +40,7 @@
     GrColor color() const { return fInputColor; }
     GrPathRendering::FillType fillType() const { return fFillType; }
     const GrProcessorSet& processors() const { return fProcessorSet; }
+    uint32_t pipelineSRGBFlags() const { return fPipelineSRGBFlags; }
     void initPipeline(const GrOpFlushState&, GrPipeline*);
     const GrProcessorSet::Analysis& doProcessorAnalysis(const GrCaps& caps,
                                                         const GrAppliedClip* clip) {
@@ -58,10 +59,11 @@
 
     SkMatrix fViewMatrix;
     GrColor fInputColor;
-    GrProcessorSet fProcessorSet;
     GrProcessorSet::Analysis fAnalysis;
     GrPathRendering::FillType fFillType;
     GrAAType fAAType;
+    uint32_t fPipelineSRGBFlags;
+    GrProcessorSet fProcessorSet;
 
     typedef GrDrawOp INHERITED;
 };