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/src/gpu/gl/GrGLShaderBuilder.h b/src/gpu/gl/GrGLShaderBuilder.h
index 9d64143..d947771 100644
--- a/src/gpu/gl/GrGLShaderBuilder.h
+++ b/src/gpu/gl/GrGLShaderBuilder.h
@@ -10,6 +10,7 @@
 
 #include "GrAllocator.h"
 #include "GrBackendEffectFactory.h"
+#include "GrColor.h"
 #include "GrEffect.h"
 #include "gl/GrGLSL.h"
 #include "gl/GrGLUniformManager.h"
@@ -31,31 +32,40 @@
     class TextureSampler {
     public:
         TextureSampler()
-            : fTextureAccess(NULL)
-            , fSamplerUniform(GrGLUniformManager::kInvalidUniformHandle) {}
+            : fConfigComponentMask(0)
+            , fSamplerUniform(GrGLUniformManager::kInvalidUniformHandle) {
+            // we will memcpy the first 4 bytes from passed in swizzle. This ensures the string is
+            // terminated.
+            fSwizzle[4] = '\0';
+        }
 
         TextureSampler(const TextureSampler& other) { *this = other; }
 
         TextureSampler& operator= (const TextureSampler& other) {
-            GrAssert(NULL == fTextureAccess);
+            GrAssert(0 == fConfigComponentMask);
             GrAssert(GrGLUniformManager::kInvalidUniformHandle == fSamplerUniform);
 
-            fTextureAccess = other.fTextureAccess;
+            fConfigComponentMask = other.fConfigComponentMask;
             fSamplerUniform = other.fSamplerUniform;
             return *this;
         }
 
-        const GrTextureAccess* textureAccess() const { return fTextureAccess; }
+        // bitfield of GrColorComponentFlags present in the texture's config.
+        uint32_t configComponentMask() const { return fConfigComponentMask; }
+
+        const char* swizzle() const { return fSwizzle; }
 
     private:
         // The idx param is used to ensure multiple samplers within a single effect have unique
-        // uniform names.
-        void init(GrGLShaderBuilder* builder, const GrTextureAccess* access, int idx) {
-            GrAssert(NULL == fTextureAccess);
+        // uniform names. swizzle is a four char max string made up of chars 'r', 'g', 'b', and 'a'.
+        void init(GrGLShaderBuilder* builder,
+                  uint32_t configComponentMask,
+                  const char* swizzle,
+                  int idx) {
+            GrAssert(0 == fConfigComponentMask);
             GrAssert(GrGLUniformManager::kInvalidUniformHandle == fSamplerUniform);
 
             GrAssert(NULL != builder);
-            GrAssert(NULL != access);
             SkString name;
             name.printf("Sampler%d_", idx);
             fSamplerUniform = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
@@ -63,14 +73,23 @@
                                                   name.c_str());
             GrAssert(GrGLUniformManager::kInvalidUniformHandle != fSamplerUniform);
 
-            fTextureAccess = access;
+            fConfigComponentMask = configComponentMask;
+            memcpy(fSwizzle, swizzle, 4);
         }
 
-        const GrTextureAccess*            fTextureAccess;
+        void init(GrGLShaderBuilder* builder, const GrTextureAccess* access, int idx) {
+            GrAssert(NULL != access);
+            this->init(builder,
+                       GrPixelConfigComponentMask(access->getTexture()->config()),
+                       access->getSwizzle(),
+                       idx);
+        }
+
+        uint32_t                          fConfigComponentMask;
+        char                              fSwizzle[5];
         GrGLUniformManager::UniformHandle fSamplerUniform;
 
-        friend class GrGLShaderBuilder; // to access fSamplerUniform
-        friend class GrGLProgram;       // to construct these and access fSamplerUniform.
+        friend class GrGLShaderBuilder; // to call init().
     };
 
     typedef SkTArray<TextureSampler> TextureSamplerArray;