aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar bungeman <bungeman@google.com>2015-08-25 12:05:55 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-08-25 12:05:55 -0700
commitafd7c749724ccceb88761c52c196ba371be5fb1c (patch)
treeda1a738adc327f84a289bb61f5ebdcaa65cf4e27 /src
parent0fe04a240b4346f42199ff657c97126913ba3e74 (diff)
Remove SK_OFFSETOF from SkTypes, clean up offsetof usage.
The motivation for this was to remove SK_OFFSETOF from SkTypes, but this CL is mostly about cleaning up our use of offsetof generally. SK_OFFSETOF is removed to SkTypes and added to the two places it is actually used (for the non standard behavior of finding the offset of fields in types which are not standard layout). Older versions of gcc required POD for offsetof to be used without warning. Newer versions require the more relaxed standard layout. Now that we no longer build on older versions of gcc, remove the old warning suppressions. PODMatrix is renamed to AggregateMatrix. SkMatrix is already POD (trivial and standard layout). The PODMatrix name implies that the POD-ness is needed for the offsetof, but it is actually the aggregate attribute which is needed for compile time constant initialization. This makes it more obvious that this can be revisited after we can rely on constexpr constructors. This also adds skstd::declval since this allows removal of existing awkward code which casts a constant to a pointer to find the size of a field. TBR=reed@google.com No API change, only removes unused macro. Review URL: https://codereview.chromium.org/1309523003
Diffstat (limited to 'src')
-rw-r--r--src/animator/SkDisplayInclude.cpp7
-rw-r--r--src/animator/SkMemberInfo.h9
-rw-r--r--src/core/SkMatrix.cpp23
3 files changed, 19 insertions, 20 deletions
diff --git a/src/animator/SkDisplayInclude.cpp b/src/animator/SkDisplayInclude.cpp
index 860264eb6f..023b3913a5 100644
--- a/src/animator/SkDisplayInclude.cpp
+++ b/src/animator/SkDisplayInclude.cpp
@@ -11,13 +11,6 @@
#include "SkAnimateMaker.h"
#include "SkAnimator.h"
-#if 0
-#undef SK_MEMBER
-#define SK_MEMBER(_member, _type) \
- { #_member, SK_OFFSETOF(BASE_CLASS::_A, _member), SkType_##_type, \
- sizeof(((BASE_CLASS::_A*) 0)->_member) / sizeof(SkScalar) }
-#endif
-
#if SK_USE_CONDENSED_INFO == 0
const SkMemberInfo SkInclude::fInfo[] = {
diff --git a/src/animator/SkMemberInfo.h b/src/animator/SkMemberInfo.h
index e07c32270d..3588da2515 100644
--- a/src/animator/SkMemberInfo.h
+++ b/src/animator/SkMemberInfo.h
@@ -104,13 +104,18 @@ struct SkMemberInfo {
// static bool SetValue(void* value, const char* name, SkDisplayTypes , int count);
};
+#ifndef SK_OFFSETOF
+ // This is offsetof for types which are not standard layout.
+ #define SK_OFFSETOF(type, field) (size_t)((char*)&(((type*)1024)->field) - (char*)1024)
+#endif
+
#define SK_MEMBER(_member, _type) \
{ #_member, SK_OFFSETOF(BASE_CLASS, _member), SkType_##_type, \
- sizeof(((BASE_CLASS*) 1)->_member) / sizeof(SkScalar) }
+ sizeof(skstd::declval<BASE_CLASS>()._member) / sizeof(SkScalar) }
#define SK_MEMBER_ALIAS(_member, _alias, _type) \
{ #_member, SK_OFFSETOF(BASE_CLASS, _alias), SkType_##_type, \
- sizeof(((BASE_CLASS*) 1)->_alias) / sizeof(SkScalar) }
+ sizeof(skstd::declval<BASE_CLASS>()._alias) / sizeof(SkScalar) }
#define SK_MEMBER_ARRAY(_member, _type) \
{ #_member, SK_OFFSETOF(BASE_CLASS, _member), SkType_Array, \
diff --git a/src/core/SkMatrix.cpp b/src/core/SkMatrix.cpp
index e030560626..f5e4e803f2 100644
--- a/src/core/SkMatrix.cpp
+++ b/src/core/SkMatrix.cpp
@@ -1586,33 +1586,34 @@ bool SkMatrix::getMinMaxScales(SkScalar scaleFactors[2]) const {
namespace {
-struct PODMatrix {
+// SkMatrix is C++11 POD (trivial and standard-layout), but not aggregate (it has private fields).
+struct AggregateMatrix {
SkScalar matrix[9];
uint32_t typemask;
const SkMatrix& asSkMatrix() const { return *reinterpret_cast<const SkMatrix*>(this); }
};
-static_assert(sizeof(PODMatrix) == sizeof(SkMatrix), "PODMatrixSizeMismatch");
+static_assert(sizeof(AggregateMatrix) == sizeof(SkMatrix), "AggregateMatrix size mismatch.");
} // namespace
const SkMatrix& SkMatrix::I() {
- static_assert(offsetof(SkMatrix, fMat) == offsetof(PODMatrix, matrix), "BadfMat");
- static_assert(offsetof(SkMatrix, fTypeMask) == offsetof(PODMatrix, typemask), "BadfTypeMask");
+ static_assert(offsetof(SkMatrix,fMat) == offsetof(AggregateMatrix,matrix), "fMat");
+ static_assert(offsetof(SkMatrix,fTypeMask) == offsetof(AggregateMatrix,typemask), "fTypeMask");
- static const PODMatrix identity = { {SK_Scalar1, 0, 0,
- 0, SK_Scalar1, 0,
- 0, 0, SK_Scalar1 },
- kIdentity_Mask | kRectStaysRect_Mask};
+ static const AggregateMatrix identity = { {SK_Scalar1, 0, 0,
+ 0, SK_Scalar1, 0,
+ 0, 0, SK_Scalar1 },
+ kIdentity_Mask | kRectStaysRect_Mask};
SkASSERT(identity.asSkMatrix().isIdentity());
return identity.asSkMatrix();
}
const SkMatrix& SkMatrix::InvalidMatrix() {
- static_assert(offsetof(SkMatrix, fMat) == offsetof(PODMatrix, matrix), "BadfMat");
- static_assert(offsetof(SkMatrix, fTypeMask) == offsetof(PODMatrix, typemask), "BadfTypeMask");
+ static_assert(offsetof(SkMatrix,fMat) == offsetof(AggregateMatrix,matrix), "fMat");
+ static_assert(offsetof(SkMatrix,fTypeMask) == offsetof(AggregateMatrix,typemask), "fTypeMask");
- static const PODMatrix invalid =
+ static const AggregateMatrix invalid =
{ {SK_ScalarMax, SK_ScalarMax, SK_ScalarMax,
SK_ScalarMax, SK_ScalarMax, SK_ScalarMax,
SK_ScalarMax, SK_ScalarMax, SK_ScalarMax },