From b68ce74bd197a9ca4becd53cbcfee825b8d08e0e Mon Sep 17 00:00:00 2001 From: mtklein Date: Tue, 24 Nov 2015 05:35:58 -0800 Subject: [PATCH] Add SK_BEGIN_REQUIRE_DENSE / SK_END_REQUIRE_DENSE. Use in on a few examples of things we hash. BUG=skia: Review URL: https://codereview.chromium.org/1468483002 --- include/core/SkMatrix.h | 6 ++++-- include/core/SkStrokeRec.h | 4 +++- include/core/SkTypes.h | 10 ++++++++++ src/core/SkGlyph.h | 2 ++ 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/include/core/SkMatrix.h b/include/core/SkMatrix.h index 6560cb5c2b..97a53505ef 100644 --- a/include/core/SkMatrix.h +++ b/include/core/SkMatrix.h @@ -22,6 +22,7 @@ class SkString; using either reset() - to construct an identity matrix, or one of the set functions (e.g. setTranslate, setRotate, etc.). */ +SK_BEGIN_REQUIRE_DENSE class SK_API SkMatrix { public: static SkMatrix SK_WARN_UNUSED_RESULT MakeScale(SkScalar sx, SkScalar sy) { @@ -29,13 +30,13 @@ public: m.setScale(sx, sy); return m; } - + static SkMatrix SK_WARN_UNUSED_RESULT MakeScale(SkScalar scale) { SkMatrix m; m.setScale(scale, scale); return m; } - + static SkMatrix SK_WARN_UNUSED_RESULT MakeTrans(SkScalar dx, SkScalar dy) { SkMatrix m; m.setTranslate(dx, dy); @@ -826,5 +827,6 @@ private: friend class SkPerspIter; }; +SK_END_REQUIRE_DENSE #endif diff --git a/include/core/SkStrokeRec.h b/include/core/SkStrokeRec.h index e92cb7ca88..32e5440563 100644 --- a/include/core/SkStrokeRec.h +++ b/include/core/SkStrokeRec.h @@ -12,6 +12,7 @@ class SkPath; +SK_BEGIN_REQUIRE_DENSE class SkStrokeRec { public: enum InitStyle { @@ -118,12 +119,13 @@ private: // 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 }; +SK_END_REQUIRE_DENSE #endif diff --git a/include/core/SkTypes.h b/include/core/SkTypes.h index d9254acf5f..5720c30970 100644 --- a/include/core/SkTypes.h +++ b/include/core/SkTypes.h @@ -287,6 +287,16 @@ static inline bool SkIsU16(long x) { template char (&SkArrayCountHelper(T (&array)[N]))[N]; #define SK_ARRAY_COUNT(array) (sizeof(SkArrayCountHelper(array))) +// Can be used to bracket data types that must be dense, e.g. hash keys. +#if defined(__clang__) // This should work on GCC too, but GCC diagnostic pop didn't seem to work! + #define SK_BEGIN_REQUIRE_DENSE _Pragma("GCC diagnostic push") \ + _Pragma("GCC diagnostic error \"-Wpadded\"") + #define SK_END_REQUIRE_DENSE _Pragma("GCC diagnostic pop") +#else + #define SK_BEGIN_REQUIRE_DENSE + #define SK_END_REQUIRE_DENSE +#endif + #define SkAlign2(x) (((x) + 1) >> 1 << 1) #define SkIsAlign2(x) (0 == ((x) & 1)) diff --git a/src/core/SkGlyph.h b/src/core/SkGlyph.h index c747995ed0..92f974bc2c 100644 --- a/src/core/SkGlyph.h +++ b/src/core/SkGlyph.h @@ -22,6 +22,7 @@ class SkGlyphCache; #define kMaxGlyphWidth (1<<13) +SK_BEGIN_REQUIRE_DENSE class SkGlyph { enum { kSubBits = 2, @@ -182,5 +183,6 @@ class SkGlyph { #endif uint32_t fID; }; +SK_END_REQUIRE_DENSE #endif