Pack and align SkStrokeRec to 4-byte boundary.

The new key for the distance field path cache will contain an
SkStrokeRec. This change guarantees that we don't have any hidden
padding that has garbage values, thereby preventing apparently
equal keys from hashing to two different values. This also has
the nice effect of reducing the size of SkStrokeRec from 24 bytes
to 16 bytes.

Review URL: https://codereview.chromium.org/1465773003
diff --git a/include/core/SkStrokeRec.h b/include/core/SkStrokeRec.h
index 50810f7..e92cb7c 100644
--- a/include/core/SkStrokeRec.h
+++ b/include/core/SkStrokeRec.h
@@ -35,8 +35,8 @@
     Style getStyle() const;
     SkScalar getWidth() const { return fWidth; }
     SkScalar getMiter() const { return fMiterLimit; }
-    SkPaint::Cap getCap() const { return fCap; }
-    SkPaint::Join getJoin() const { return fJoin; }
+    SkPaint::Cap getCap() const { return (SkPaint::Cap)fCap; }
+    SkPaint::Join getJoin() const { return (SkPaint::Join)fJoin; }
 
     bool isHairlineStyle() const {
         return kHairline_Style == this->getStyle();
@@ -115,9 +115,15 @@
     SkScalar        fResScale;
     SkScalar        fWidth;
     SkScalar        fMiterLimit;
-    SkPaint::Cap    fCap;
-    SkPaint::Join   fJoin;
-    bool            fStrokeAndFill;
+    // The following three members are packed together into a single u32.
+    // This is to avoid unnecessary padding and ensure binary equality for
+    // hashing (because the padded areas might contain garbage values).
+    // 
+    // fCap and fJoin are larger than needed to avoid having to initialize
+    // any pad values
+    uint32_t        fCap : 16;             // SkPaint::Cap
+    uint32_t        fJoin : 15;            // SkPaint::Join
+    uint32_t        fStrokeAndFill : 1;    // bool
 };
 
 #endif
diff --git a/src/core/SkStrokeRec.cpp b/src/core/SkStrokeRec.cpp
index 764794e..6c975b4 100644
--- a/src/core/SkStrokeRec.cpp
+++ b/src/core/SkStrokeRec.cpp
@@ -108,8 +108,8 @@
     }
 
     SkStroke stroker;
-    stroker.setCap(fCap);
-    stroker.setJoin(fJoin);
+    stroker.setCap((SkPaint::Cap)fCap);
+    stroker.setJoin((SkPaint::Join)fJoin);
     stroker.setMiterLimit(fMiterLimit);
     stroker.setWidth(fWidth);
     stroker.setDoFill(fStrokeAndFill);
@@ -131,6 +131,6 @@
     paint->setStyle(fStrokeAndFill ? SkPaint::kStrokeAndFill_Style : SkPaint::kStroke_Style);
     paint->setStrokeWidth(fWidth);
     paint->setStrokeMiter(fMiterLimit);
-    paint->setStrokeCap(fCap);
-    paint->setStrokeJoin(fJoin);
+    paint->setStrokeCap((SkPaint::Cap)fCap);
+    paint->setStrokeJoin((SkPaint::Join)fJoin);
 }