Revert of move program descriptor generation to flush (patchset #7 id:120001 of https://codereview.chromium.org/777673003/)

Reason for revert:
breaking linux build

Original issue's description:
> move program descriptor generation to flush
>
> BUG=skia:
>
> Committed: https://skia.googlesource.com/skia/+/829e1b80b1020b17f2078020c990e079b70c077c

TBR=egdaniel@google.com,bsalomon@google.com,joshualitt@chromium.org
NOTREECHECKS=true
NOTRY=true
BUG=skia:

Review URL: https://codereview.chromium.org/776243005
diff --git a/src/gpu/GrGpu.cpp b/src/gpu/GrGpu.cpp
index ac76e15..d97809f 100644
--- a/src/gpu/GrGpu.cpp
+++ b/src/gpu/GrGpu.cpp
@@ -277,7 +277,7 @@
 
 void GrGpu::draw(const GrOptDrawState& ds, const GrDrawTarget::DrawInfo& info) {
     this->handleDirtyContext();
-    if (!this->flushGraphicsState(ds)) {
+    if (!this->flushGraphicsState(ds, PrimTypeToDrawType(info.primitiveType()))) {
         return;
     }
     this->onDraw(ds, info);
@@ -288,7 +288,7 @@
                         const GrStencilSettings& stencilSettings) {
     this->handleDirtyContext();
 
-    if (!this->flushGraphicsState(ds)) {
+    if (!this->flushGraphicsState(ds, kStencilPath_DrawType)) {
         return;
     }
 
@@ -301,7 +301,7 @@
                      const GrStencilSettings& stencilSettings) {
     this->handleDirtyContext();
 
-    if (!this->flushGraphicsState(ds)) {
+    if (!this->flushGraphicsState(ds, kDrawPath_DrawType)) {
         return;
     }
 
@@ -318,7 +318,7 @@
                       const GrStencilSettings& stencilSettings) {
     this->handleDirtyContext();
 
-    if (!this->flushGraphicsState(ds)) {
+    if (!this->flushGraphicsState(ds, kDrawPaths_DrawType)) {
         return;
     }
 
diff --git a/src/gpu/GrGpu.h b/src/gpu/GrGpu.h
index c88e1c8..d0bff30 100644
--- a/src/gpu/GrGpu.h
+++ b/src/gpu/GrGpu.h
@@ -469,7 +469,7 @@
     // deltas from previous state at draw time. This function does the
     // backend-specific flush of the state.
     // returns false if current state is unsupported.
-    virtual bool flushGraphicsState(const GrOptDrawState&) = 0;
+    virtual bool flushGraphicsState(const GrOptDrawState&, DrawType) = 0;
 
     // clears target's entire stencil buffer to 0
     virtual void clearStencil(GrRenderTarget* target) = 0;
diff --git a/src/gpu/GrInOrderDrawBuffer.cpp b/src/gpu/GrInOrderDrawBuffer.cpp
index 83b9701..5533174 100644
--- a/src/gpu/GrInOrderDrawBuffer.cpp
+++ b/src/gpu/GrInOrderDrawBuffer.cpp
@@ -394,7 +394,7 @@
 
     // Updated every time we find a set state cmd to reflect the current state in the playback
     // stream.
-    GrOptDrawState* currentOptState = NULL;
+    const GrOptDrawState* currentOptState = NULL;
 
     while (iter.next()) {
         GrGpuTraceMarker newMarker("", -1);
@@ -409,7 +409,6 @@
         if (kSetState_Cmd == strip_trace_bit(iter->fType)) {
             SetState* ss = reinterpret_cast<SetState*>(iter.get());
             currentOptState = &ss->fState;
-            currentOptState->finalize(this->getGpu());
         } else {
             iter->execute(this, currentOptState);
         }
@@ -487,8 +486,7 @@
                                                    const GrClipMaskManager::ScissorState& scissor,
                                                    const GrDeviceCoordTexture* dstCopy) {
     SetState* ss = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, SetState,
-                                            (ds, *this->getGpu()->caps(), scissor, dstCopy,
-                                             drawType));
+                                            (ds, this->getGpu(), scissor, dstCopy, drawType));
     if (ss->fState.mustSkip()) {
         fCmdBuffer.pop_back();
         return false;
diff --git a/src/gpu/GrInOrderDrawBuffer.h b/src/gpu/GrInOrderDrawBuffer.h
index 01e560a..532842a 100644
--- a/src/gpu/GrInOrderDrawBuffer.h
+++ b/src/gpu/GrInOrderDrawBuffer.h
@@ -171,15 +171,15 @@
     };
 
     struct SetState : public Cmd {
-        SetState(const GrDrawState& drawState, const GrDrawTargetCaps& caps,
-                 const ScissorState& scissor, const GrDeviceCoordTexture* dstCopy,
-                 GrGpu::DrawType drawType)
+        SetState(const GrDrawState& drawState, GrGpu* gpu, const ScissorState& scissor,
+                 const GrDeviceCoordTexture* dstCopy, GrGpu::DrawType drawType)
         : Cmd(kSetState_Cmd)
-        , fState(drawState, caps, scissor, dstCopy, drawType) {}
+        , fState(drawState, gpu, scissor, dstCopy, drawType) {}
 
         void execute(GrInOrderDrawBuffer*, const GrOptDrawState*) SK_OVERRIDE;
 
-        GrOptDrawState          fState;
+        const GrOptDrawState    fState;
+        GrGpu::DrawType         fDrawType;
     };
 
     typedef void* TCmdAlign; // This wouldn't be enough align if a command used long double.
diff --git a/src/gpu/GrOptDrawState.cpp b/src/gpu/GrOptDrawState.cpp
index 6eee0c2..6f6f0af 100644
--- a/src/gpu/GrOptDrawState.cpp
+++ b/src/gpu/GrOptDrawState.cpp
@@ -13,12 +13,11 @@
 #include "GrProcOptInfo.h"
 
 GrOptDrawState::GrOptDrawState(const GrDrawState& drawState,
-                               const GrDrawTargetCaps& caps,
+                               GrGpu* gpu,
                                const ScissorState& scissorState,
                                const GrDeviceCoordTexture* dstCopy,
-                               GrGpu::DrawType drawType)
-    : fFinalized(false) {
-    fDrawType = drawType;
+                               GrGpu::DrawType drawType) {
+
     GrBlendCoeff optSrcCoeff;
     GrBlendCoeff optDstCoeff;
     GrDrawState::BlendOpt blendOpt = drawState.getBlendOpt(false, &optSrcCoeff, &optDstCoeff);
@@ -53,6 +52,8 @@
         fDstCopy = *dstCopy;
     }
 
+    GrProgramDesc::DescInfo descInfo;
+
     fFlags = 0;
     if (drawState.isHWAntialias()) {
         fFlags |= kHWAA_Flag;
@@ -64,33 +65,34 @@
         fFlags |= kDither_Flag;
     }
 
-    fDescInfo.fHasVertexColor = drawState.hasGeometryProcessor() &&
-                                drawState.getGeometryProcessor()->hasVertexColor();
+    descInfo.fHasVertexColor = drawState.hasGeometryProcessor() &&
+                               drawState.getGeometryProcessor()->hasVertexColor();
 
-    fDescInfo.fHasVertexCoverage = drawState.hasGeometryProcessor() &&
-                                   drawState.getGeometryProcessor()->hasVertexCoverage();
+    descInfo.fHasVertexCoverage = drawState.hasGeometryProcessor() &&
+                                 drawState.getGeometryProcessor()->hasVertexCoverage();
 
     bool hasLocalCoords = drawState.hasGeometryProcessor() &&
                           drawState.getGeometryProcessor()->hasLocalCoords();
 
     const GrProcOptInfo& colorPOI = drawState.colorProcInfo();
     int firstColorStageIdx = colorPOI.firstEffectiveStageIndex();
-    fDescInfo.fInputColorIsUsed = colorPOI.inputColorIsUsed();
+    descInfo.fInputColorIsUsed = colorPOI.inputColorIsUsed();
     fColor = colorPOI.inputColorToEffectiveStage();
     if (colorPOI.removeVertexAttrib()) {
-        fDescInfo.fHasVertexColor = false;
+        descInfo.fHasVertexColor = false;
     }
 
     // TODO: Once we can handle single or four channel input into coverage stages then we can use
     // drawState's coverageProcInfo (like color above) to set this initial information.
     int firstCoverageStageIdx = 0;
-    fDescInfo.fInputCoverageIsUsed = true;
+    descInfo.fInputCoverageIsUsed = true;
     fCoverage = drawState.getCoverage();
 
-    this->adjustProgramForBlendOpt(drawState, blendOpt, &firstColorStageIdx,
+    this->adjustProgramForBlendOpt(drawState, blendOpt, &descInfo, &firstColorStageIdx,
                                    &firstCoverageStageIdx);
 
-    this->getStageStats(drawState, firstColorStageIdx, firstCoverageStageIdx, hasLocalCoords);
+    this->getStageStats(drawState, firstColorStageIdx, firstCoverageStageIdx, hasLocalCoords,
+                        &descInfo);
 
     // Copy GeometryProcesssor from DS or ODS
     SkASSERT(GrGpu::IsPathRenderingDrawType(drawType) ||
@@ -116,15 +118,19 @@
                                (drawState.fCoverageStages[i], hasLocalCoords));
     }
 
-    this->setOutputStateInfo(drawState, blendOpt, caps);
+    this->setOutputStateInfo(drawState, blendOpt, *gpu->caps(), &descInfo);
+
+    // now create a key
+    gpu->buildProgramDesc(*this, descInfo, drawType, &fDesc);
 };
 
 void GrOptDrawState::setOutputStateInfo(const GrDrawState& ds,
                                         GrDrawState::BlendOpt blendOpt,
-                                        const GrDrawTargetCaps& caps) {
+                                        const GrDrawTargetCaps& caps,
+                                        GrProgramDesc::DescInfo* descInfo) {
     // Set this default and then possibly change our mind if there is coverage.
-    fDescInfo.fPrimaryOutputType = GrProgramDesc::kModulate_PrimaryOutputType;
-    fDescInfo.fSecondaryOutputType = GrProgramDesc::kNone_SecondaryOutputType;
+    descInfo->fPrimaryOutputType = GrProgramDesc::kModulate_PrimaryOutputType;
+    descInfo->fSecondaryOutputType = GrProgramDesc::kNone_SecondaryOutputType;
 
     // Determine whether we should use dual source blending or shader code to keep coverage
     // separate from color.
@@ -134,27 +140,28 @@
         if (caps.dualSourceBlendingSupport()) {
             if (kZero_GrBlendCoeff == fDstBlend) {
                 // write the coverage value to second color
-                fDescInfo.fSecondaryOutputType = GrProgramDesc::kCoverage_SecondaryOutputType;
+                descInfo->fSecondaryOutputType = GrProgramDesc::kCoverage_SecondaryOutputType;
                 fDstBlend = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff;
             } else if (kSA_GrBlendCoeff == fDstBlend) {
                 // SA dst coeff becomes 1-(1-SA)*coverage when dst is partially covered.
-                fDescInfo.fSecondaryOutputType = GrProgramDesc::kCoverageISA_SecondaryOutputType;
+                descInfo->fSecondaryOutputType = GrProgramDesc::kCoverageISA_SecondaryOutputType;
                 fDstBlend = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff;
             } else if (kSC_GrBlendCoeff == fDstBlend) {
                 // SA dst coeff becomes 1-(1-SA)*coverage when dst is partially covered.
-                fDescInfo.fSecondaryOutputType = GrProgramDesc::kCoverageISC_SecondaryOutputType;
+                descInfo->fSecondaryOutputType = GrProgramDesc::kCoverageISC_SecondaryOutputType;
                 fDstBlend = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff;
             }
-        } else if (fDescInfo.fReadsDst &&
+        } else if (descInfo->fReadsDst &&
                    kOne_GrBlendCoeff == fSrcBlend &&
                    kZero_GrBlendCoeff == fDstBlend) {
-            fDescInfo.fPrimaryOutputType = GrProgramDesc::kCombineWithDst_PrimaryOutputType;
+            descInfo->fPrimaryOutputType = GrProgramDesc::kCombineWithDst_PrimaryOutputType;
         }
     }
 }
 
 void GrOptDrawState::adjustProgramForBlendOpt(const GrDrawState& ds,
                                               GrDrawState::BlendOpt blendOpt,
+                                              GrProgramDesc::DescInfo* descInfo,
                                               int* firstColorStageIdx,
                                               int* firstCoverageStageIdx) {
     switch (blendOpt) {
@@ -164,19 +171,19 @@
             break;
         case GrDrawState::kEmitCoverage_BlendOpt:
             fColor = 0xffffffff;
-            fDescInfo.fInputColorIsUsed = true;
+            descInfo->fInputColorIsUsed = true;
             *firstColorStageIdx = ds.numColorStages();
-            fDescInfo.fHasVertexColor = false;
+            descInfo->fHasVertexColor = false;
             break;
         case GrDrawState::kEmitTransBlack_BlendOpt:
             fColor = 0;
             fCoverage = 0xff;
-            fDescInfo.fInputColorIsUsed = true;
-            fDescInfo.fInputCoverageIsUsed = true;
+            descInfo->fInputColorIsUsed = true;
+            descInfo->fInputCoverageIsUsed = true;
             *firstColorStageIdx = ds.numColorStages();
             *firstCoverageStageIdx = ds.numCoverageStages();
-            fDescInfo.fHasVertexColor = false;
-            fDescInfo.fHasVertexCoverage = false;
+            descInfo->fHasVertexColor = false;
+            descInfo->fHasVertexCoverage = false;
             break;
     }
 }
@@ -191,57 +198,46 @@
 }
 
 void GrOptDrawState::getStageStats(const GrDrawState& ds, int firstColorStageIdx,
-                                   int firstCoverageStageIdx, bool hasLocalCoords) {
+                                   int firstCoverageStageIdx, bool hasLocalCoords,
+                                   GrProgramDesc::DescInfo* descInfo) {
     // We will need a local coord attrib if there is one currently set on the optState and we are
     // actually generating some effect code
-    fDescInfo.fRequiresLocalCoordAttrib = hasLocalCoords &&
+    descInfo->fRequiresLocalCoordAttrib = hasLocalCoords &&
         ds.numTotalStages() - firstColorStageIdx - firstCoverageStageIdx > 0;
 
-    fDescInfo.fReadsDst = false;
-    fDescInfo.fReadsFragPosition = false;
+    descInfo->fReadsDst = false;
+    descInfo->fReadsFragPosition = false;
 
     for (int s = firstColorStageIdx; s < ds.numColorStages(); ++s) {
         const GrFragmentStage& stage = ds.getColorStage(s);
-        get_stage_stats(stage, &fDescInfo.fReadsDst, &fDescInfo.fReadsFragPosition);
+        get_stage_stats(stage, &descInfo->fReadsDst, &descInfo->fReadsFragPosition);
     }
     for (int s = firstCoverageStageIdx; s < ds.numCoverageStages(); ++s) {
         const GrFragmentStage& stage = ds.getCoverageStage(s);
-        get_stage_stats(stage, &fDescInfo.fReadsDst, &fDescInfo.fReadsFragPosition);
+        get_stage_stats(stage, &descInfo->fReadsDst, &descInfo->fReadsFragPosition);
     }
     if (ds.hasGeometryProcessor()) {
         const GrGeometryProcessor& gp = *ds.getGeometryProcessor();
-        fDescInfo.fReadsFragPosition = fDescInfo.fReadsFragPosition || gp.willReadFragmentPosition();
+        descInfo->fReadsFragPosition = descInfo->fReadsFragPosition || gp.willReadFragmentPosition();
     }
 }
 
-void GrOptDrawState::finalize(GrGpu* gpu) {
-    gpu->buildProgramDesc(*this, fDescInfo, fDrawType, &fDesc);
-    fFinalized = true;
-}
-
 ////////////////////////////////////////////////////////////////////////////////
 
 bool GrOptDrawState::operator== (const GrOptDrawState& that) const {
-    if (!fDescInfo.fHasVertexColor && this->fColor != that.fColor) {
+    if (this->fDesc != that.fDesc) {
+        return false;
+    }
+    bool hasVertexColors = this->fDesc.header().fColorInput == GrProgramDesc::kAttribute_ColorInput;
+    if (!hasVertexColors && this->fColor != that.fColor) {
         return false;
     }
 
     if (this->getRenderTarget() != that.getRenderTarget() ||
-        this->fFragmentStages.count() != that.fFragmentStages.count() ||
-        this->fNumColorStages != that.fNumColorStages ||
         this->fScissorState != that.fScissorState ||
         !this->fViewMatrix.cheapEqualTo(that.fViewMatrix) ||
         this->fSrcBlend != that.fSrcBlend ||
         this->fDstBlend != that.fDstBlend ||
-        this->fDrawType != that.fDrawType ||
-        fDescInfo.fInputColorIsUsed != that.fDescInfo.fInputColorIsUsed ||
-        fDescInfo.fInputCoverageIsUsed != that.fDescInfo.fInputCoverageIsUsed ||
-        fDescInfo.fReadsDst != that.fDescInfo.fReadsDst ||
-        fDescInfo.fReadsFragPosition != that.fDescInfo.fReadsFragPosition ||
-        fDescInfo.fRequiresLocalCoordAttrib != that.fDescInfo.fRequiresLocalCoordAttrib ||
-        fDescInfo.fPrimaryOutputType != that.fDescInfo.fPrimaryOutputType ||
-        fDescInfo.fSecondaryOutputType != that.fDescInfo.fSecondaryOutputType ||
-        this->fScissorState != that.fScissorState ||
         this->fBlendConstant != that.fBlendConstant ||
         this->fFlags != that.fFlags ||
         this->fStencilSettings != that.fStencilSettings ||
@@ -250,7 +246,9 @@
         return false;
     }
 
-    if (!fDescInfo.fHasVertexCoverage && this->fCoverage != that.fCoverage) {
+    bool hasVertexCoverage =
+            this->fDesc.header().fCoverageInput == GrProgramDesc::kAttribute_ColorInput;
+    if (!hasVertexCoverage && this->fCoverage != that.fCoverage) {
         return false;
     }
 
diff --git a/src/gpu/GrOptDrawState.h b/src/gpu/GrOptDrawState.h
index 25a3a49..ac7ec16 100644
--- a/src/gpu/GrOptDrawState.h
+++ b/src/gpu/GrOptDrawState.h
@@ -30,7 +30,7 @@
 
     typedef GrClipMaskManager::ScissorState ScissorState;
 
-    GrOptDrawState(const GrDrawState& drawState, const GrDrawTargetCaps&, const ScissorState&,
+    GrOptDrawState(const GrDrawState& drawState, GrGpu*, const ScissorState&,
                    const GrDeviceCoordTexture* dstCopy, GrGpu::DrawType);
 
     bool operator== (const GrOptDrawState& that) const;
@@ -180,20 +180,33 @@
 
     ///////////////////////////////////////////////////////////////////////////
 
-    GrGpu::DrawType drawType() const { return fDrawType; }
-
     const GrDeviceCoordTexture* getDstCopy() const { return fDstCopy.texture() ? &fDstCopy : NULL; }
 
-    // Finalize *MUST* be called before programDesc()
-    void finalize(GrGpu*);
-
-    const GrProgramDesc& programDesc() const { SkASSERT(fFinalized); return fDesc; }
+    const GrProgramDesc& programDesc() const { return fDesc; }
 
 private:
     /**
+     * Loops through all the color stage effects to check if the stage will ignore color input or
+     * always output a constant color. In the ignore color input case we can ignore all previous
+     * stages. In the constant color case, we can ignore all previous stages and
+     * the current one and set the state color to the constant color.
+     */
+    void computeEffectiveColorStages(const GrDrawState& ds, GrProgramDesc::DescInfo*,
+                                     int* firstColorStageIdx, uint8_t* fixFunctionVAToRemove);
+
+    /**
+     * Loops through all the coverage stage effects to check if the stage will ignore color input.
+     * If a coverage stage will ignore input, then we can ignore all coverage stages before it. We
+     * loop to determine the first effective coverage stage.
+     */
+    void computeEffectiveCoverageStages(const GrDrawState& ds, GrProgramDesc::DescInfo* descInfo,
+                                        int* firstCoverageStageIdx);
+
+    /**
      * Alter the program desc and inputs (attribs and processors) based on the blend optimization.
      */
     void adjustProgramForBlendOpt(const GrDrawState& ds, GrDrawState::BlendOpt,
+                                  GrProgramDesc::DescInfo*,
                                   int* firstColorStageIdx, int* firstCoverageStageIdx);
 
     /**
@@ -201,14 +214,15 @@
      * shaders they require.
      */
     void getStageStats(const GrDrawState& ds, int firstColorStageIdx, int firstCoverageStageIdx,
-                       bool hasLocalCoords);
+                       bool hasLocalCoords, GrProgramDesc::DescInfo*);
 
     /**
      * Calculates the primary and secondary output types of the shader. For certain output types
      * the function may adjust the blend coefficients. After this function is called the src and dst
      * blend coeffs will represent those used by backend API.
      */
-    void setOutputStateInfo(const GrDrawState& ds, GrDrawState::BlendOpt, const GrDrawTargetCaps&);
+    void setOutputStateInfo(const GrDrawState& ds, GrDrawState::BlendOpt, const GrDrawTargetCaps&,
+                            GrProgramDesc::DescInfo*);
 
     enum Flags {
         kDither_Flag            = 0x1,
@@ -235,9 +249,6 @@
     ProgramGeometryProcessor            fGeometryProcessor;
     ProgramXferProcessor                fXferProcessor;
     FragmentStageArray                  fFragmentStages;
-    GrGpu::DrawType                     fDrawType;
-    GrProgramDesc::DescInfo             fDescInfo;
-    bool                                fFinalized;
 
     // This function is equivalent to the offset into fFragmentStages where coverage stages begin.
     int                                 fNumColorStages;
diff --git a/src/gpu/GrProgramDesc.h b/src/gpu/GrProgramDesc.h
index b51da04..655254f 100644
--- a/src/gpu/GrProgramDesc.h
+++ b/src/gpu/GrProgramDesc.h
@@ -103,6 +103,8 @@
                                                    // effects that read the fragment position.
                                                    // Otherwise, 0.
 
+        SkBool8                     fEmitsPointSize;
+
         ColorInput                  fColorInput : 8;
         ColorInput                  fCoverageInput : 8;
 
diff --git a/src/gpu/GrTest.cpp b/src/gpu/GrTest.cpp
index 7038c10..48f72a7 100644
--- a/src/gpu/GrTest.cpp
+++ b/src/gpu/GrTest.cpp
@@ -140,7 +140,7 @@
         return false;
     }
 
-    bool flushGraphicsState(const GrOptDrawState&) SK_OVERRIDE { return false; }
+    bool flushGraphicsState(const GrOptDrawState&, DrawType) SK_OVERRIDE { return false; }
 
     void clearStencil(GrRenderTarget* target) SK_OVERRIDE  {}
 
diff --git a/src/gpu/gl/GrGLProgram.cpp b/src/gpu/gl/GrGLProgram.cpp
index 3b04edb..63cb9da 100644
--- a/src/gpu/gl/GrGLProgram.cpp
+++ b/src/gpu/gl/GrGLProgram.cpp
@@ -123,13 +123,13 @@
 
 ///////////////////////////////////////////////////////////////////////////////
 
-void GrGLProgram::setData(const GrOptDrawState& optState) {
+void GrGLProgram::setData(const GrOptDrawState& optState, GrGpu::DrawType drawType) {
     GrColor color = optState.getColor();
     uint8_t coverage = optState.getCoverage();
 
     this->setColor(optState, color);
     this->setCoverage(optState, coverage);
-    this->setMatrixAndRenderTargetHeight(optState);
+    this->setMatrixAndRenderTargetHeight(drawType, optState);
 
     const GrDeviceCoordTexture* dstCopy = optState.getDstCopy();
     if (dstCopy) {
@@ -164,7 +164,7 @@
     this->setFragmentData(optState);
 
     // Some of GrGLProgram subclasses need to update state here
-    this->didSetData(optState.drawType());
+    this->didSetData(drawType);
 }
 
 void GrGLProgram::setFragmentData(const GrOptDrawState& optState) {
@@ -241,7 +241,8 @@
     }
 }
 
-void GrGLProgram::setMatrixAndRenderTargetHeight(const GrOptDrawState& optState) {
+void GrGLProgram::setMatrixAndRenderTargetHeight(GrGpu::DrawType drawType,
+                                                 const GrOptDrawState& optState) {
     // Load the RT height uniform if it is needed to y-flip gl_FragCoord.
     if (fBuiltinUniformHandles.fRTHeightUni.isValid() &&
         fMatrixState.fRenderTargetSize.fHeight != optState.getRenderTarget()->height()) {
@@ -250,10 +251,11 @@
     }
 
     // call subclasses to set the actual view matrix
-    this->onSetMatrixAndRenderTargetHeight(optState);
+    this->onSetMatrixAndRenderTargetHeight(drawType, optState);
 }
 
-void GrGLProgram::onSetMatrixAndRenderTargetHeight(const GrOptDrawState& optState) {
+void GrGLProgram::onSetMatrixAndRenderTargetHeight(GrGpu::DrawType drawType,
+                                                   const GrOptDrawState& optState) {
     const GrRenderTarget* rt = optState.getRenderTarget();
     SkISize size;
     size.set(rt->width(), rt->height());
@@ -287,8 +289,9 @@
     : INHERITED(gpu, desc, builtinUniforms, programID, uniforms, NULL, fragmentProcessors) {
 }
 
-void GrGLNvprProgramBase::onSetMatrixAndRenderTargetHeight(const GrOptDrawState& optState) {
-    SkASSERT(GrGpu::IsPathRenderingDrawType(optState.drawType()));
+void GrGLNvprProgramBase::onSetMatrixAndRenderTargetHeight(GrGpu::DrawType drawType,
+                                                           const GrOptDrawState& optState) {
+    SkASSERT(GrGpu::IsPathRenderingDrawType(drawType));
     const GrRenderTarget* rt = optState.getRenderTarget();
     SkISize size;
     size.set(rt->width(), rt->height());
diff --git a/src/gpu/gl/GrGLProgram.h b/src/gpu/gl/GrGLProgram.h
index 36bf860..a273a03 100644
--- a/src/gpu/gl/GrGLProgram.h
+++ b/src/gpu/gl/GrGLProgram.h
@@ -129,7 +129,7 @@
      * GrGpuGL object to bind the textures required by the GrGLProcessors. The color and coverage
      * stages come from GrGLProgramDesc::Build().
      */
-    void setData(const GrOptDrawState&);
+    void setData(const GrOptDrawState&, GrGpu::DrawType);
 
 protected:
     typedef GrGLProgramDataManager::UniformHandle UniformHandle;
@@ -167,8 +167,8 @@
     virtual void didSetData(GrGpu::DrawType);
 
     // Helper for setData() that sets the view matrix and loads the render target height uniform
-    void setMatrixAndRenderTargetHeight(const GrOptDrawState&);
-    virtual void onSetMatrixAndRenderTargetHeight(const GrOptDrawState&);
+    void setMatrixAndRenderTargetHeight(GrGpu::DrawType, const GrOptDrawState&);
+    virtual void onSetMatrixAndRenderTargetHeight(GrGpu::DrawType, const GrOptDrawState&);
 
     // these reflect the current values of uniforms (GL uniform values travel with program)
     MatrixState fMatrixState;
@@ -206,7 +206,7 @@
                         GrGLuint programID,
                         const UniformInfoArray&,
                         GrGLInstalledFragProcs* fragmentProcessors);
-    virtual void onSetMatrixAndRenderTargetHeight(const GrOptDrawState&);
+    virtual void onSetMatrixAndRenderTargetHeight(GrGpu::DrawType, const GrOptDrawState&);
 
     typedef GrGLProgram INHERITED;
 };
diff --git a/src/gpu/gl/GrGLProgramDesc.cpp b/src/gpu/gl/GrGLProgramDesc.cpp
index f8dbbc2..74f669f 100644
--- a/src/gpu/gl/GrGLProgramDesc.cpp
+++ b/src/gpu/gl/GrGLProgramDesc.cpp
@@ -196,6 +196,8 @@
 
     header->fHasGeometryProcessor = optState.hasGeometryProcessor();
 
+    header->fEmitsPointSize = GrGpu::kDrawPoints_DrawType == drawType;
+
     bool isPathRendering = GrGpu::IsPathRenderingDrawType(drawType);
     if (gpu->caps()->pathRenderingSupport() && isPathRendering) {
         header->fUseNvpr = true;
diff --git a/src/gpu/gl/GrGpuGL.cpp b/src/gpu/gl/GrGpuGL.cpp
index 383427d..df35d2c 100644
--- a/src/gpu/gl/GrGpuGL.cpp
+++ b/src/gpu/gl/GrGpuGL.cpp
@@ -1894,14 +1894,14 @@
     }
 }
 
-void GrGpuGL::flushAAState(const GrOptDrawState& optState) {
+void GrGpuGL::flushAAState(const GrOptDrawState& optState, DrawType type) {
 // At least some ATI linux drivers will render GL_LINES incorrectly when MSAA state is enabled but
 // the target is not multisampled. Single pixel wide lines are rendered thicker than 1 pixel wide.
 #if 0
     // Replace RT_HAS_MSAA with this definition once this driver bug is no longer a relevant concern
     #define RT_HAS_MSAA rt->isMultisampled()
 #else
-    #define RT_HAS_MSAA (rt->isMultisampled() || kDrawLines_DrawType == optState.drawType())
+    #define RT_HAS_MSAA (rt->isMultisampled() || kDrawLines_DrawType == type)
 #endif
 
     const GrRenderTarget* rt = optState.getRenderTarget();
diff --git a/src/gpu/gl/GrGpuGL.h b/src/gpu/gl/GrGpuGL.h
index 8a60988..4224ba6 100644
--- a/src/gpu/gl/GrGpuGL.h
+++ b/src/gpu/gl/GrGpuGL.h
@@ -155,7 +155,7 @@
 
 
     virtual void clearStencil(GrRenderTarget*) SK_OVERRIDE;
-    virtual bool flushGraphicsState(const GrOptDrawState&) SK_OVERRIDE;
+    virtual bool flushGraphicsState(const GrOptDrawState&, DrawType) SK_OVERRIDE;
 
     // GrDrawTarget overrides
     virtual void didAddGpuTraceMarker() SK_OVERRIDE;
@@ -188,7 +188,7 @@
         ~ProgramCache();
 
         void abandon();
-        GrGLProgram* getProgram(const GrOptDrawState&);
+        GrGLProgram* getProgram(const GrOptDrawState&, DrawType);
 
     private:
         enum {
@@ -248,7 +248,7 @@
     void flushRenderTarget(GrGLRenderTarget*, const SkIRect* bounds);
 
     void flushStencil(const GrStencilSettings&, DrawType);
-    void flushAAState(const GrOptDrawState&);
+    void flushAAState(const GrOptDrawState&, DrawType);
 
     bool configToGLFormats(GrPixelConfig config,
                            bool getSizedInternal,
diff --git a/src/gpu/gl/GrGpuGL_program.cpp b/src/gpu/gl/GrGpuGL_program.cpp
index a808aa8..cb8810c 100644
--- a/src/gpu/gl/GrGpuGL_program.cpp
+++ b/src/gpu/gl/GrGpuGL_program.cpp
@@ -91,7 +91,7 @@
     return SkTSearch(fEntries, fCount, desc, sizeof(Entry*), less);
 }
 
-GrGLProgram* GrGpuGL::ProgramCache::getProgram(const GrOptDrawState& optState) {
+GrGLProgram* GrGpuGL::ProgramCache::getProgram(const GrOptDrawState& optState, DrawType type) {
 #ifdef PROGRAM_CACHE_STATS
     ++fTotalRequests;
 #endif
@@ -126,7 +126,7 @@
 #ifdef PROGRAM_CACHE_STATS
         ++fCacheMisses;
 #endif
-        GrGLProgram* program = GrGLProgramBuilder::CreateProgram(optState, fGpu);
+        GrGLProgram* program = GrGLProgramBuilder::CreateProgram(optState, type, fGpu);
         if (NULL == program) {
             return NULL;
         }
@@ -201,11 +201,11 @@
 
 #define GL_CALL(X) GR_GL_CALL(this->glInterface(), X)
 
-bool GrGpuGL::flushGraphicsState(const GrOptDrawState& optState) {
+bool GrGpuGL::flushGraphicsState(const GrOptDrawState& optState, DrawType type) {
     // GrGpu::setupClipAndFlushState should have already checked this and bailed if not true.
     SkASSERT(optState.getRenderTarget());
 
-    if (kStencilPath_DrawType == optState.drawType()) {
+    if (kStencilPath_DrawType == type) {
         const GrRenderTarget* rt = optState.getRenderTarget();
         SkISize size;
         size.set(rt->width(), rt->height());
@@ -216,7 +216,7 @@
         GrBlendCoeff srcCoeff = optState.getSrcBlendCoeff();
         GrBlendCoeff dstCoeff = optState.getDstBlendCoeff();
 
-        fCurrentProgram.reset(fProgramCache->getProgram(optState));
+        fCurrentProgram.reset(fProgramCache->getProgram(optState, type));
         if (NULL == fCurrentProgram.get()) {
             SkDEBUGFAIL("Failed to create program!");
             return false;
@@ -230,15 +230,15 @@
             fHWProgramID = programID;
         }
 
-        this->flushBlend(optState, kDrawLines_DrawType == optState.drawType(), srcCoeff, dstCoeff);
+        this->flushBlend(optState, kDrawLines_DrawType == type, srcCoeff, dstCoeff);
 
-        fCurrentProgram->setData(optState);
+        fCurrentProgram->setData(optState, type);
     }
 
     GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(optState.getRenderTarget());
-    this->flushStencil(optState.getStencil(), optState.drawType());
+    this->flushStencil(optState.getStencil(), type);
     this->flushScissor(optState.getScissorState(), glRT->getViewport(), glRT->origin());
-    this->flushAAState(optState);
+    this->flushAAState(optState, type);
 
     // This must come after textures are flushed because a texture may need
     // to be msaa-resolved (which will modify bound FBO state).
diff --git a/src/gpu/gl/builders/GrGLGeometryShaderBuilder.cpp b/src/gpu/gl/builders/GrGLGeometryShaderBuilder.cpp
index ef8d1a2..f35c9ba 100644
--- a/src/gpu/gl/builders/GrGLGeometryShaderBuilder.cpp
+++ b/src/gpu/gl/builders/GrGLGeometryShaderBuilder.cpp
@@ -48,7 +48,9 @@
     geomShaderSrc.append("void main() {\n");
     geomShaderSrc.append("\tfor (int i = 0; i < 3; ++i) {\n"
                          "\t\tgl_Position = gl_in[i].gl_Position;\n");
-    geomShaderSrc.append("\t\tgl_PointSize = 1.0;\n");
+    if (fProgramBuilder->desc().header().fEmitsPointSize) {
+        geomShaderSrc.append("\t\tgl_PointSize = 1.0;\n");
+    }
     SkASSERT(fInputs.count() == fOutputs.count());
     for (int i = 0; i < fInputs.count(); ++i) {
         geomShaderSrc.appendf("\t\t%s = %s[i];\n",
diff --git a/src/gpu/gl/builders/GrGLProgramBuilder.cpp b/src/gpu/gl/builders/GrGLProgramBuilder.cpp
index aa9e40c..64150a4 100644
--- a/src/gpu/gl/builders/GrGLProgramBuilder.cpp
+++ b/src/gpu/gl/builders/GrGLProgramBuilder.cpp
@@ -28,10 +28,13 @@
 
 const int GrGLProgramBuilder::kVarsPerBlock = 8;
 
-GrGLProgram* GrGLProgramBuilder::CreateProgram(const GrOptDrawState& optState, GrGpuGL* gpu) {
+GrGLProgram* GrGLProgramBuilder::CreateProgram(const GrOptDrawState& optState,
+                                               GrGpu::DrawType drawType,
+                                               GrGpuGL* gpu) {
     // create a builder.  This will be handed off to effects so they can use it to add
     // uniforms, varyings, textures, etc
     SkAutoTDelete<GrGLProgramBuilder> builder(CreateProgramBuilder(optState,
+                                                                   drawType,
                                                                    optState.hasGeometryProcessor(),
                                                                    gpu));
 
@@ -70,6 +73,7 @@
 
 GrGLProgramBuilder*
 GrGLProgramBuilder::CreateProgramBuilder(const GrOptDrawState& optState,
+                                         GrGpu::DrawType drawType,
                                          bool hasGeometryProcessor,
                                          GrGpuGL* gpu) {
     const GrProgramDesc& desc = optState.programDesc();
@@ -230,7 +234,9 @@
         fVS.setupUniformViewMatrix();
 
         const GrProgramDesc::KeyHeader& header = this->header();
-        fVS.codeAppend("gl_PointSize = 1.0;");
+        if (header.fEmitsPointSize) {
+            fVS.codeAppend("gl_PointSize = 1.0;");
+        }
 
         // Setup position
         // TODO it'd be possible to remove these from the vertexshader builder and have them
diff --git a/src/gpu/gl/builders/GrGLProgramBuilder.h b/src/gpu/gl/builders/GrGLProgramBuilder.h
index 973ae5e..76f7ae9 100644
--- a/src/gpu/gl/builders/GrGLProgramBuilder.h
+++ b/src/gpu/gl/builders/GrGLProgramBuilder.h
@@ -186,7 +186,7 @@
      * to be used.
      * @return true if generation was successful.
      */
-    static GrGLProgram* CreateProgram(const GrOptDrawState&, GrGpuGL*);
+    static GrGLProgram* CreateProgram(const GrOptDrawState&, GrGpu::DrawType, GrGpuGL*);
 
     virtual UniformHandle addUniform(uint32_t visibility,
                                      GrSLType type,
@@ -246,6 +246,7 @@
     typedef GrGLProgramDataManager::UniformInfoArray UniformInfoArray;
 
     static GrGLProgramBuilder* CreateProgramBuilder(const GrOptDrawState&,
+                                                    GrGpu::DrawType,
                                                     bool hasGeometryProcessor,
                                                     GrGpuGL*);
 
diff --git a/tests/GLProgramsTest.cpp b/tests/GLProgramsTest.cpp
index 7b73fdc..aa8359d 100644
--- a/tests/GLProgramsTest.cpp
+++ b/tests/GLProgramsTest.cpp
@@ -384,12 +384,11 @@
 
         // create optimized draw state, setup readDst texture if required, and build a descriptor
         // and program.  ODS creation can fail, so we have to check
-        GrOptDrawState ods(ds, *gpu->caps(), scissor, &dstCopy, drawType);
+        GrOptDrawState ods(ds, gpu, scissor, &dstCopy, drawType);
         if (ods.mustSkip()) {
             continue;
         }
-        ods.finalize(gpu);
-        SkAutoTUnref<GrGLProgram> program(GrGLProgramBuilder::CreateProgram(ods, gpu));
+        SkAutoTUnref<GrGLProgram> program(GrGLProgramBuilder::CreateProgram(ods, drawType, gpu));
         if (NULL == program.get()) {
             SkDebugf("Failed to create program!");
             return false;