Make GrGLShaderBuilder::TextureSampler extract only required info from GrTextureAccess.

This will make it possible to init a TextureSampler without a texture or a specific config.

Also unify two separate bitfields of color components in GPU code.
Review URL: https://codereview.chromium.org/13121002

git-svn-id: http://skia.googlecode.com/svn/trunk@8428 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/include/gpu/GrColor.h b/include/gpu/GrColor.h
index af12ac6..43d932b 100644
--- a/include/gpu/GrColor.h
+++ b/include/gpu/GrColor.h
@@ -67,4 +67,44 @@
     rgba[3] = GrColorUnpackA(color) * ONE_OVER_255;
 }
 
+/**
+ * Flags used for bitfields of color components. They are defined so that the bit order reflects the
+ * GrColor shift order.
+ */
+enum GrColorComponentFlags {
+    kR_GrColorComponentFlag = 1 << (GrColor_SHIFT_R / 8),
+    kG_GrColorComponentFlag = 1 << (GrColor_SHIFT_G / 8),
+    kB_GrColorComponentFlag = 1 << (GrColor_SHIFT_B / 8),
+    kA_GrColorComponentFlag = 1 << (GrColor_SHIFT_A / 8),
+
+    kRGB_GrColorComponentFlags = (kR_GrColorComponentFlag | kG_GrColorComponentFlag |
+                                  kB_GrColorComponentFlag),
+
+    kRGBA_GrColorComponentFlags = (kR_GrColorComponentFlag | kG_GrColorComponentFlag |
+                                   kB_GrColorComponentFlag | kA_GrColorComponentFlag)
+};
+
+static inline uint32_t GrPixelConfigComponentMask(GrPixelConfig config) {
+    GrAssert(config >= 0 && config < kGrPixelConfigCnt);
+    static const uint32_t kFlags[] = {
+        0,                              // kUnknown_GrPixelConfig
+        kA_GrColorComponentFlag,        // kAlpha_8_GrPixelConfig
+        kRGBA_GrColorComponentFlags,    // kIndex_8_GrPixelConfig
+        kRGB_GrColorComponentFlags,     // kRGB_565_GrPixelConfig
+        kRGBA_GrColorComponentFlags,    // kRGBA_4444_GrPixelConfig
+        kRGBA_GrColorComponentFlags,    // kRGBA_8888_GrPixelConfig
+        kRGBA_GrColorComponentFlags,    // kBGRA_8888_GrPixelConfig
+    };
+    return kFlags[config];
+
+    GR_STATIC_ASSERT(0 == kUnknown_GrPixelConfig);
+    GR_STATIC_ASSERT(1 == kAlpha_8_GrPixelConfig);
+    GR_STATIC_ASSERT(2 == kIndex_8_GrPixelConfig);
+    GR_STATIC_ASSERT(3 == kRGB_565_GrPixelConfig);
+    GR_STATIC_ASSERT(4 == kRGBA_4444_GrPixelConfig);
+    GR_STATIC_ASSERT(5 == kRGBA_8888_GrPixelConfig);
+    GR_STATIC_ASSERT(6 == kBGRA_8888_GrPixelConfig);
+    GR_STATIC_ASSERT(SK_ARRAY_COUNT(kFlags) == kGrPixelConfigCnt);
+}
+
 #endif
diff --git a/include/gpu/GrEffect.h b/include/gpu/GrEffect.h
index 8834386..de4b2a1 100644
--- a/include/gpu/GrEffect.h
+++ b/include/gpu/GrEffect.h
@@ -87,24 +87,11 @@
     virtual ~GrEffect();
 
     /**
-     * Flags for getConstantColorComponents. They are defined so that the bit order reflects the
-     * GrColor shift order.
-     */
-    enum ValidComponentFlags {
-        kR_ValidComponentFlag = 1 << (GrColor_SHIFT_R / 8),
-        kG_ValidComponentFlag = 1 << (GrColor_SHIFT_G / 8),
-        kB_ValidComponentFlag = 1 << (GrColor_SHIFT_B / 8),
-        kA_ValidComponentFlag = 1 << (GrColor_SHIFT_A / 8),
-
-        kAll_ValidComponentFlags = (kR_ValidComponentFlag | kG_ValidComponentFlag |
-                                    kB_ValidComponentFlag | kA_ValidComponentFlag)
-    };
-
-    /**
      * This function is used to perform optimizations. When called the color and validFlags params
-     * indicate whether the input components to this effect in the FS will have known values. The
-     * function updates both params to indicate known values of its output. A component of the color
-     * param only has meaning if the corresponding bit in validFlags is set.
+     * indicate whether the input components to this effect in the FS will have known values.
+     * validFlags is a bitfield of GrColorComponentFlags. The function updates both params to
+     * indicate known values of its output. A component of the color param only has meaning if the
+     * corresponding bit in validFlags is set.
      */
     virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags) const = 0;
 
diff --git a/include/gpu/GrTextureAccess.h b/include/gpu/GrTextureAccess.h
index b03e6e6..e5ea535 100644
--- a/include/gpu/GrTextureAccess.h
+++ b/include/gpu/GrTextureAccess.h
@@ -162,16 +162,8 @@
      */
     const char* getSwizzle() const { return fSwizzle; }
 
-    enum {
-        kR_SwizzleFlag = 0x1,
-        kG_SwizzleFlag = 0x2,
-        kB_SwizzleFlag = 0x4,
-        kA_SwizzleFlag = 0x8,
-
-        kRGB_SwizzleMask = (kR_SwizzleFlag |  kG_SwizzleFlag | kB_SwizzleFlag),
-    };
-
-    /** Returns a mask indicating which components are referenced in the swizzle. */
+    /** Returns a mask indicating which components are referenced in the swizzle. The return
+        is a bitfield of GrColorComponentFlags. */
     uint32_t swizzleMask() const { return fSwizzleMask; }
 
     const GrTextureParams& getParams() const { return fParams; }
diff --git a/include/gpu/GrTypes.h b/include/gpu/GrTypes.h
index f0153df..5e48dac 100644
--- a/include/gpu/GrTypes.h
+++ b/include/gpu/GrTypes.h
@@ -284,8 +284,9 @@
      */
     kBGRA_8888_GrPixelConfig,
 
-    kGrPixelConfigCount
+    kLast_GrPixelConfig = kBGRA_8888_GrPixelConfig
 };
+static const int kGrPixelConfigCnt = kLast_GrPixelConfig + 1;
 
 // Aliases for pixel configs that match skia's byte order.
 #ifndef SK_CPU_LENDIAN