Mark when effects and programs have vertex code

Adds a 'hasVertexCode' method to GrEffect and a 'fHasVertexCode' field
to GrGLProgramDesc::KeyHeader. Also adds a GrVertexEffect class that
effects have to inherit from in order to set the 'hasVertexCode' flag
and be able to emit vertex code, and updates the existing effects to
use it as needed.

R=bsalomon@google.com

Author: cdalton@nvidia.com

Review URL: https://codereview.chromium.org/23653059

git-svn-id: http://skia.googlecode.com/svn/trunk@11537 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/gpu/effects/GrBezierEffect.cpp b/src/gpu/effects/GrBezierEffect.cpp
index c7eadb7..b3e9f62 100644
--- a/src/gpu/effects/GrBezierEffect.cpp
+++ b/src/gpu/effects/GrBezierEffect.cpp
@@ -128,7 +128,7 @@
     return GrTBackendEffectFactory<GrConicEffect>::getInstance();
 }
 
-GrConicEffect::GrConicEffect(GrBezierEdgeType edgeType) : GrEffect() {
+GrConicEffect::GrConicEffect(GrBezierEdgeType edgeType) : GrVertexEffect() {
     this->addVertexAttrib(kVec4f_GrSLType);
     fEdgeType = edgeType;
 }
@@ -260,7 +260,7 @@
     return GrTBackendEffectFactory<GrQuadEffect>::getInstance();
 }
 
-GrQuadEffect::GrQuadEffect(GrBezierEdgeType edgeType) : GrEffect() {
+GrQuadEffect::GrQuadEffect(GrBezierEdgeType edgeType) : GrVertexEffect() {
     this->addVertexAttrib(kVec4f_GrSLType);
     fEdgeType = edgeType;
 }
@@ -403,7 +403,7 @@
     return GrTBackendEffectFactory<GrCubicEffect>::getInstance();
 }
 
-GrCubicEffect::GrCubicEffect(GrBezierEdgeType edgeType) : GrEffect() {
+GrCubicEffect::GrCubicEffect(GrBezierEdgeType edgeType) : GrVertexEffect() {
     this->addVertexAttrib(kVec4f_GrSLType);
     fEdgeType = edgeType;
 }
diff --git a/src/gpu/effects/GrBezierEffect.h b/src/gpu/effects/GrBezierEffect.h
index d31cd7e..5de7b80 100644
--- a/src/gpu/effects/GrBezierEffect.h
+++ b/src/gpu/effects/GrBezierEffect.h
@@ -8,8 +8,9 @@
 #ifndef GrBezierEffect_DEFINED
 #define GrBezierEffect_DEFINED
 
-#include "GrEffect.h"
 #include "GrDrawTargetCaps.h"
+#include "GrEffect.h"
+#include "GrVertexEffect.h"
 
 enum GrBezierEdgeType {
     kFillAA_GrBezierEdgeType,
@@ -67,7 +68,7 @@
  */
 class GrGLConicEffect;
 
-class GrConicEffect : public GrEffect {
+class GrConicEffect : public GrVertexEffect {
 public:
     static GrEffectRef* Create(const GrBezierEdgeType edgeType, const GrDrawTargetCaps& caps) {
         GR_CREATE_STATIC_EFFECT(gConicFillAA, GrConicEffect, (kFillAA_GrBezierEdgeType));
@@ -117,7 +118,7 @@
 
     GR_DECLARE_EFFECT_TEST;
 
-    typedef GrEffect INHERITED;
+    typedef GrVertexEffect INHERITED;
 };
 
 ///////////////////////////////////////////////////////////////////////////////
@@ -131,7 +132,7 @@
  */
 class GrGLQuadEffect;
 
-class GrQuadEffect : public GrEffect {
+class GrQuadEffect : public GrVertexEffect {
 public:
     static GrEffectRef* Create(const GrBezierEdgeType edgeType, const GrDrawTargetCaps& caps) {
         GR_CREATE_STATIC_EFFECT(gQuadFillAA, GrQuadEffect, (kFillAA_GrBezierEdgeType));
@@ -181,7 +182,7 @@
 
     GR_DECLARE_EFFECT_TEST;
 
-    typedef GrEffect INHERITED;
+    typedef GrVertexEffect INHERITED;
 };
 
 //////////////////////////////////////////////////////////////////////////////
@@ -197,7 +198,7 @@
  */
 class GrGLCubicEffect;
 
-class GrCubicEffect : public GrEffect {
+class GrCubicEffect : public GrVertexEffect {
 public:
     static GrEffectRef* Create(const GrBezierEdgeType edgeType, const GrDrawTargetCaps& caps) {
         GR_CREATE_STATIC_EFFECT(gCubicFillAA, GrCubicEffect, (kFillAA_GrBezierEdgeType));
@@ -247,7 +248,7 @@
 
     GR_DECLARE_EFFECT_TEST;
 
-    typedef GrEffect INHERITED;
+    typedef GrVertexEffect INHERITED;
 };
 
 #endif
diff --git a/src/gpu/effects/GrCustomCoordsTextureEffect.h b/src/gpu/effects/GrCustomCoordsTextureEffect.h
index fad35c8..1caecf2 100644
--- a/src/gpu/effects/GrCustomCoordsTextureEffect.h
+++ b/src/gpu/effects/GrCustomCoordsTextureEffect.h
@@ -9,6 +9,7 @@
 #define GrCustomCoordsTextureEffect_DEFINED
 
 #include "GrEffect.h"
+#include "GrVertexEffect.h"
 
 class GrGLCustomCoordsTextureEffect;
 
@@ -17,7 +18,7 @@
  * It allows explicit specification of the filtering and wrap modes (GrTextureParams). The input
  * coords are a custom attribute.
  */
-class GrCustomCoordsTextureEffect : public GrEffect {
+class GrCustomCoordsTextureEffect : public GrVertexEffect {
 public:
     static GrEffectRef* Create(GrTexture* tex, const GrTextureParams& p) {
         AutoEffectUnref effect(SkNEW_ARGS(GrCustomCoordsTextureEffect, (tex, p)));
@@ -43,7 +44,7 @@
 
     GR_DECLARE_EFFECT_TEST;
 
-    typedef GrEffect INHERITED;
+    typedef GrVertexEffect INHERITED;
 };
 
 #endif
diff --git a/src/gpu/effects/GrVertexEffect.h b/src/gpu/effects/GrVertexEffect.h
new file mode 100644
index 0000000..387ec7a
--- /dev/null
+++ b/src/gpu/effects/GrVertexEffect.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2013 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef GrVertexEffect_DEFINED
+#define GrVertexEffect_DEFINED
+
+#include "GrEffect.h"
+
+/**
+ * If an effect needs specialized vertex shader code, then it must inherit from this class.
+ * Otherwise it won't be able to add vertex attribs, and it might be given a vertexless shader
+ * program in emitCode.
+ */
+class GrVertexEffect : public GrEffect {
+public:
+    GrVertexEffect() { fHasVertexCode = true; }
+
+protected:
+    /**
+     * Subclasses call this from their constructor to register vertex attributes (at most
+     * kMaxVertexAttribs). This must only be called from the constructor because GrEffects are
+     * immutable.
+     */
+    void addVertexAttrib(GrSLType type) {
+        SkASSERT(fVertexAttribTypes.count() < kMaxVertexAttribs);
+        fVertexAttribTypes.push_back(type);
+    }
+
+private:
+    typedef GrEffect INHERITED;
+};
+
+#endif