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
This commit is contained in:
mtklein 2015-11-24 05:35:58 -08:00 committed by Commit bot
parent d14c39eff2
commit b68ce74bd1
4 changed files with 19 additions and 3 deletions

View File

@ -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

View File

@ -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

View File

@ -287,6 +287,16 @@ static inline bool SkIsU16(long x) {
template <typename T, size_t N> 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))

View File

@ -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