Add convenience function on GrDrawState to set state bit based on a bool.

R=robertphillips@google.com
Review URL: https://codereview.appspot.com/6615044

git-svn-id: http://skia.googlecode.com/svn/trunk@5815 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/gpu/GrClipMaskManager.cpp b/src/gpu/GrClipMaskManager.cpp
index 5ca714a..f40c265 100644
--- a/src/gpu/GrClipMaskManager.cpp
+++ b/src/gpu/GrClipMaskManager.cpp
@@ -785,11 +785,7 @@
             drawState->disableState(GrGpu::kModifyStencilClip_StateBit);
             // if the target is MSAA then we want MSAA enabled when the clip is soft
             if (rt->isMultisampled()) {
-                if (clip->fDoAA) {
-                    drawState->enableState(GrDrawState::kHWAntialias_StateBit);
-                } else {
-                    drawState->disableState(GrDrawState::kHWAntialias_StateBit);
-                }
+                drawState->setState(GrDrawState::kHWAntialias_StateBit, clip->fDoAA);
             }
 
             // Can the clip element be drawn directly to the stencil buffer
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index 26bef45..b038a9d 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -570,11 +570,7 @@
 void GrContext::setClip(const GrClipData* clipData) {
     fGpu->setClip(clipData);
 
-    if (clipData->fClipStack->isWideOpen()) {
-        fDrawState->disableState(GrDrawState::kClip_StateBit);
-    } else {
-        fDrawState->enableState(GrDrawState::kClip_StateBit);
-    }
+    fDrawState->setState(GrDrawState::kClip_StateBit, !clipData->fClipStack->isWideOpen());
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -1618,16 +1614,9 @@
 
     fDrawState->setColor(paint.fColor);
 
-    if (paint.fDither) {
-        fDrawState->enableState(GrDrawState::kDither_StateBit);
-    } else {
-        fDrawState->disableState(GrDrawState::kDither_StateBit);
-    }
-    if (paint.fAntiAlias) {
-        fDrawState->enableState(GrDrawState::kHWAntialias_StateBit);
-    } else {
-        fDrawState->disableState(GrDrawState::kHWAntialias_StateBit);
-    }
+    fDrawState->setState(GrDrawState::kDither_StateBit, paint.fDither);
+    fDrawState->setState(GrDrawState::kHWAntialias_StateBit, paint.fAntiAlias);
+
     if (paint.fColorMatrixEnabled) {
         fDrawState->enableState(GrDrawState::kColorMatrix_StateBit);
         fDrawState->setColorMatrix(paint.fColorMatrix);
diff --git a/src/gpu/GrDrawState.h b/src/gpu/GrDrawState.h
index b38a177..05da3df 100644
--- a/src/gpu/GrDrawState.h
+++ b/src/gpu/GrDrawState.h
@@ -674,7 +674,7 @@
     /**
      * Enable render state settings.
      *
-     * @param flags   bitfield of StateBits specifing the states to enable
+     * @param stateBits bitfield of StateBits specifing the states to enable
      */
     void enableState(uint32_t stateBits) {
         fFlagBits |= stateBits;
@@ -683,12 +683,26 @@
     /**
      * Disable render state settings.
      *
-     * @param flags   bitfield of StateBits specifing the states to disable
+     * @param stateBits bitfield of StateBits specifing the states to disable
      */
     void disableState(uint32_t stateBits) {
         fFlagBits &= ~(stateBits);
     }
 
+    /**
+     * Enable or disable stateBits based on a boolean.
+     *
+     * @param stateBits bitfield of StateBits to enable or disablt
+     * @param enable    if true enable stateBits, otherwise disable
+     */
+    void setState(uint32_t stateBits, bool enable) {
+        if (enable) {
+            this->enableState(stateBits);
+        } else {
+            this->disableState(stateBits);
+        }
+    }
+
     bool isDitherState() const {
         return 0 != (fFlagBits & kDither_StateBit);
     }