aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/core/SkFontStyle.h
diff options
context:
space:
mode:
authorGravatar Ben Wagner <bungeman@google.com>2017-07-31 15:41:14 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-07-31 20:24:47 +0000
commit0500ebafec1879a7c5f76fe40ee30bdab17ac3db (patch)
tree09c6bb735ae81e3ebc16f64eadc6d46209182350 /include/core/SkFontStyle.h
parent49f58a3825ca7f7745d7f311baa2b65c5eb46c02 (diff)
Remove union from SkFontStyle.
This is prompted by a bug in vc++ reported at https://developercommunity.visualstudio.com/content/problem/86829/constexpr-initializing-struct-in-union-only-zero-i.html Visual C++ will not properly constexpr initialize a struct inside a union. Removing this construct also allows us to avoid writing and reading from different members of a union. Change-Id: I76e069ecce77ef21b7ad3821bf9c29e1b0843618 Reviewed-on: https://skia-review.googlesource.com/28300 Commit-Queue: Mike Klein <mtklein@chromium.org> Reviewed-by: Brian Salomon <bsalomon@google.com> Reviewed-by: Mike Klein <mtklein@chromium.org>
Diffstat (limited to 'include/core/SkFontStyle.h')
-rw-r--r--include/core/SkFontStyle.h29
1 files changed, 11 insertions, 18 deletions
diff --git a/include/core/SkFontStyle.h b/include/core/SkFontStyle.h
index 306895d78f..a5e3034e1d 100644
--- a/include/core/SkFontStyle.h
+++ b/include/core/SkFontStyle.h
@@ -44,23 +44,23 @@ public:
kOblique_Slant,
};
- SkFontStyle();
+ constexpr SkFontStyle(int weight, int width, Slant slant) : fValue(
+ (SkTPin<int>(weight, kInvisible_Weight, kExtraBlack_Weight)) +
+ (SkTPin<int>(width, kUltraCondensed_Width, kUltraExpanded_Width) << 16) +
+ (SkTPin<int>(slant, kUpright_Slant, kOblique_Slant) << 24)
+ ) { }
- constexpr SkFontStyle(int weight, int width, Slant slant) : fUnion {{
- static_cast<uint16_t>(SkTPin<int>(weight, kInvisible_Weight, kExtraBlack_Weight)),
- static_cast<uint8_t >(SkTPin<int>(width, kUltraCondensed_Width, kUltraExpanded_Width)),
- static_cast<uint8_t >(SkTPin<int>(slant, kUpright_Slant, kOblique_Slant))
- }} { }
+ constexpr SkFontStyle() : SkFontStyle{kNormal_Weight, kNormal_Width, kUpright_Slant} { }
static SkFontStyle FromOldStyle(unsigned oldStyle);
bool operator==(const SkFontStyle& rhs) const {
- return fUnion.fU32 == rhs.fUnion.fU32;
+ return fValue == rhs.fValue;
}
- int weight() const { return fUnion.fR.fWeight; }
- int width() const { return fUnion.fR.fWidth; }
- Slant slant() const { return (Slant)fUnion.fR.fSlant; }
+ int weight() const { return fValue & 0xFFFF; }
+ int width() const { return (fValue >> 16) & 0xFF; }
+ Slant slant() const { return (Slant)((fValue >> 24) & 0xFF); }
static constexpr SkFontStyle Normal() {
return SkFontStyle(kNormal_Weight, kNormal_Width, kUpright_Slant);
@@ -76,14 +76,7 @@ public:
}
private:
- union {
- struct {
- uint16_t fWeight; // 100 .. 900
- uint8_t fWidth; // 1 .. 9
- uint8_t fSlant; // 0 .. 2
- } fR;
- uint32_t fU32;
- } fUnion;
+ uint32_t fValue;
};
#endif