Make GrGLShaderBuilder check whether GrEffect advertised that it would require the dst color or fragment position

R=senorblanco@chromium.org, robertphillips@google.com

Author: bsalomon@google.com

Review URL: https://chromiumcodereview.appspot.com/14998007

git-svn-id: http://skia.googlecode.com/svn/trunk@9074 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/gpu/GrAAHairLinePathRenderer.cpp b/src/gpu/GrAAHairLinePathRenderer.cpp
index a857dc4..4b10cea 100644
--- a/src/gpu/GrAAHairLinePathRenderer.cpp
+++ b/src/gpu/GrAAHairLinePathRenderer.cpp
@@ -666,6 +666,7 @@
 private:
     HairLineEdgeEffect() {
         this->addVertexAttrib(kVec4f_GrSLType);
+        this->setWillReadFragmentPosition();
     }
 
     virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE {
diff --git a/src/gpu/GrAARectRenderer.cpp b/src/gpu/GrAARectRenderer.cpp
index 28dae24..0b593b9 100644
--- a/src/gpu/GrAARectRenderer.cpp
+++ b/src/gpu/GrAARectRenderer.cpp
@@ -220,6 +220,7 @@
     GrRectEffect() : GrEffect() {
         this->addVertexAttrib(kVec4f_GrSLType);
         this->addVertexAttrib(kVec2f_GrSLType);
+        this->setWillReadFragmentPosition();
     }
 
     virtual bool onIsEqual(const GrEffect&) const SK_OVERRIDE { return true; }
diff --git a/src/gpu/GrDrawState.h b/src/gpu/GrDrawState.h
index e34e4ab..91a8723 100644
--- a/src/gpu/GrDrawState.h
+++ b/src/gpu/GrDrawState.h
@@ -453,7 +453,7 @@
      */
     bool willEffectReadDst() const {
         for (int s = 0; s < kNumStages; ++s) {
-            if (this->isStageEnabled(s) && (*this->getStage(s).getEffect())->willReadDst()) {
+            if (this->isStageEnabled(s) && (*this->getStage(s).getEffect())->willReadDstColor()) {
                 return true;
             }
         }
diff --git a/src/gpu/gl/GrGLProgramDesc.cpp b/src/gpu/gl/GrGLProgramDesc.cpp
index 1ae6aa6..a1cd85e 100644
--- a/src/gpu/gl/GrGLProgramDesc.cpp
+++ b/src/gpu/gl/GrGLProgramDesc.cpp
@@ -87,7 +87,7 @@
             const GrBackendEffectFactory& factory = effect->getFactory();
             GrDrawEffect drawEffect(drawState.getStage(s), requiresLocalCoordAttrib);
             desc->fEffectKeys[s] = factory.glEffectKey(drawEffect, gpu->glCaps());
-            if (effect->willReadDst()) {
+            if (effect->willReadDstColor()) {
                 readsDst = true;
             }
         } else {
diff --git a/src/gpu/gl/GrGLShaderBuilder.cpp b/src/gpu/gl/GrGLShaderBuilder.cpp
index c1732b2..98d7e4c 100644
--- a/src/gpu/gl/GrGLShaderBuilder.cpp
+++ b/src/gpu/gl/GrGLShaderBuilder.cpp
@@ -230,6 +230,14 @@
 }
 
 const char* GrGLShaderBuilder::dstColor() {
+    if (fCodeStage.inStageCode()) {
+        const GrEffectRef& effect = *fCodeStage.effectStage()->getEffect();
+        if (!effect->willReadDstColor()) {
+            GrDebugCrash("GrGLEffect asked for dst color but its generating GrEffect "
+                         "did not request access.");
+            return "";
+        }
+    }
     static const char kFBFetchColorName[] = "gl_LastFragData[0]";
     GrGLCaps::FBFetchType fetchType = fCtxInfo.caps()->fbFetchType();
     if (GrGLCaps::kEXT_FBFetchType == fetchType) {
@@ -241,7 +249,7 @@
     } else if (fDstCopySampler.isInitialized()) {
         return kDstCopyColorName;
     } else {
-        return NULL;
+        return "";
     }
 }
 
@@ -457,6 +465,14 @@
 }
 
 const char* GrGLShaderBuilder::fragmentPosition() {
+    if (fCodeStage.inStageCode()) {
+        const GrEffectRef& effect = *fCodeStage.effectStage()->getEffect();
+        if (!effect->willReadFragmentPosition()) {
+            GrDebugCrash("GrGLEffect asked for frag position but its generating GrEffect "
+                         "did not request access.");
+            return "";
+        }
+    }
 #if 1
     if (fCtxInfo.caps()->fragCoordConventionsSupport()) {
         if (!fSetupFragPosition) {