Use explicitly-sized enums in GrGLProgramDesc::KeyHeader
authorcommit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>
Tue, 1 Oct 2013 18:43:29 +0000 (18:43 +0000)
committercommit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>
Tue, 1 Oct 2013 18:43:29 +0000 (18:43 +0000)
Uses enums explicitly sized to 8 bits in GrGLProgramDesc::KeyHeader,
instead of storing them as uint8_t values. This avoids the need to
static_cast them.

R=bsalomon@google.com

Author: cdalton@nvidia.com

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

git-svn-id: http://skia.googlecode.com/svn/trunk@11560 2bbb7eff-a529-9590-31e7-b0007b416f81

src/gpu/gl/GrGLProgram.cpp
src/gpu/gl/GrGLProgramDesc.h
tests/GLProgramsTest.cpp

index f10e895..2f8e807 100644 (file)
@@ -228,7 +228,7 @@ bool GrGLProgram::genProgram(const GrEffectStage* colorStages[],
     SkXfermode::Coeff colorCoeff;
     SkXfermode::Coeff filterColorCoeff;
     SkAssertResult(
-        SkXfermode::ModeAsCoeff(static_cast<SkXfermode::Mode>(header.fColorFilterXfermode),
+        SkXfermode::ModeAsCoeff(header.fColorFilterXfermode,
                                 &filterColorCoeff,
                                 &colorCoeff));
     bool needColor, needFilterColor;
@@ -311,9 +311,7 @@ bool GrGLProgram::genProgram(const GrEffectStage* colorStages[],
         }
     }
 
-    GrGLProgramDesc::CoverageOutput coverageOutput =
-        static_cast<GrGLProgramDesc::CoverageOutput>(header.fCoverageOutput);
-    if (GrGLProgramDesc::CoverageOutputUsesSecondaryOutput(coverageOutput)) {
+    if (GrGLProgramDesc::CoverageOutputUsesSecondaryOutput(header.fCoverageOutput)) {
         const char* secondaryOutputName = builder.enableSecondaryOutput();
 
         // default coeff to ones for kCoverage_DualSrcOutput
@@ -333,7 +331,7 @@ bool GrGLProgram::genProgram(const GrEffectStage* colorStages[],
                                                  kOnes_GrSLConstantVec,
                                                  knownColorValue,
                                                  true);
-        } else if (GrGLProgramDesc::kSecondaryCoverageISC_CoverageOutput == coverageOutput) {
+        } else if (GrGLProgramDesc::kSecondaryCoverageISC_CoverageOutput == header.fCoverageOutput) {
             // Get (1-RGBA) into coeff
             knownCoeffValue = GrGLSLSubtractf<4>(&coeff,
                                                  NULL,
@@ -365,7 +363,7 @@ bool GrGLProgram::genProgram(const GrEffectStage* colorStages[],
                                                              knownCoverageValue,
                                                              true);
     // Now tack on "+(1-coverage)dst onto the frag color if we were asked to do so.
-    if (GrGLProgramDesc::kCombineWithDst_CoverageOutput == coverageOutput) {
+    if (GrGLProgramDesc::kCombineWithDst_CoverageOutput == header.fCoverageOutput) {
         SkString dstCoeff;
         GrSLConstantVec knownDstCoeffValue = GrGLSLSubtractf<4>(&dstCoeff,
                                                                 NULL,
index 308b0c7..e160438 100644 (file)
@@ -154,13 +154,13 @@ private:
         // should the FS discard if the coverage is zero (to avoid stencil manipulation)
         SkBool8                     fDiscardIfZeroCoverage;
 
-        uint8_t                     fColorInput;            // casts to enum ColorInput
-        uint8_t                     fCoverageInput;         // casts to enum ColorInput
-        uint8_t                     fCoverageOutput;        // casts to enum CoverageOutput
+        ColorInput                  fColorInput : 8;
+        ColorInput                  fCoverageInput : 8;
+        CoverageOutput              fCoverageOutput : 8;
 
         SkBool8                     fHasVertexCode;
         SkBool8                     fEmitsPointSize;
-        uint8_t                     fColorFilterXfermode;   // casts to enum SkXfermode::Mode
+        SkXfermode::Mode            fColorFilterXfermode : 8;
 
         // To enable experimental geometry shader code (not for use in
         // production)
index 10380f7..fe17f88 100644 (file)
@@ -44,7 +44,8 @@ void GrGLProgramDesc::setRandom(SkRandom* random,
     // if the effects have used up all off the available attributes,
     // don't try to use color or coverage attributes as input
     do {
-        header->fColorInput = random->nextULessThan(kColorInputCnt);
+        header->fColorInput = static_cast<GrGLProgramDesc::ColorInput>(
+                                  random->nextULessThan(kColorInputCnt));
     } while (GrDrawState::kMaxVertexAttribCnt <= currAttribIndex &&
              kAttribute_ColorInput == header->fColorInput);
     header->fColorAttributeIndex = (header->fColorInput == kAttribute_ColorInput) ?
@@ -52,14 +53,16 @@ void GrGLProgramDesc::setRandom(SkRandom* random,
                                         -1;
 
     do {
-        header->fCoverageInput = random->nextULessThan(kColorInputCnt);
+        header->fCoverageInput = static_cast<GrGLProgramDesc::ColorInput>(
+                                     random->nextULessThan(kColorInputCnt));
     } while (GrDrawState::kMaxVertexAttribCnt <= currAttribIndex  &&
              kAttribute_ColorInput == header->fCoverageInput);
     header->fCoverageAttributeIndex = (header->fCoverageInput == kAttribute_ColorInput) ?
                                         currAttribIndex++ :
                                         -1;
 
-    header->fColorFilterXfermode = random->nextULessThan(SkXfermode::kLastCoeffMode + 1);
+    header->fColorFilterXfermode = static_cast<SkXfermode::Mode>(
+                                       random->nextULessThan(SkXfermode::kLastCoeffMode + 1));
 
 #if GR_GL_EXPERIMENTAL_GS
     header->fExperimentalGS = gpu->caps()->geometryShaderSupport() && random->nextBool();