summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Colin Cross <ccross@android.com> 2016-09-30 17:24:06 -0700
committer Colin Cross <ccross@android.com> 2016-10-05 09:55:41 -0700
commitb1f30bae12a0df810a62f819ab3ac680b00768b9 (patch)
treef1eff573c55bee67297d56241853f74ea4aa1186
parentc72b9a3ce4e6aebdbd59e5e98450856213dc3b8b (diff)
Fix anonymous struct and union warnings
gui/BufferItem.h and android/sensor.h uses anymous structs and nested anonymous unions, which are GNU extensions. sensor.h uses them as part of its API, so disable the warnings in libgui, the only module that tries to use it with -Weverything. BufferItem.h only uses the unioned fields inside libgui, remove the union and do the 64-bit to 32-bit slicing manually so libvulkan doesn't need the warnings disabled. Bug: 31752268 Test: m -j Change-Id: I92d59b1202f4d6e5419edaa6d27b6e1c50ac0042
-rw-r--r--include/gui/BufferItem.h16
-rw-r--r--libs/gui/Android.mk3
-rw-r--r--libs/gui/BufferItem.cpp44
3 files changed, 37 insertions, 26 deletions
diff --git a/include/gui/BufferItem.h b/include/gui/BufferItem.h
index 3ab63d0632..5232d0f69e 100644
--- a/include/gui/BufferItem.h
+++ b/include/gui/BufferItem.h
@@ -74,13 +74,7 @@ class BufferItem : public Flattenable<BufferItem> {
// to set by queueBuffer each time this slot is queued. This value
// is guaranteed to be monotonically increasing for each newly
// acquired buffer.
- union {
- int64_t mTimestamp;
- struct {
- uint32_t mTimestampLo;
- uint32_t mTimestampHi;
- };
- };
+ int64_t mTimestamp;
// mIsAutoTimestamp indicates whether mTimestamp was generated
// automatically when the buffer was queued.
@@ -92,13 +86,7 @@ class BufferItem : public Flattenable<BufferItem> {
android_dataspace mDataSpace;
// mFrameNumber is the number of the queued frame for this slot.
- union {
- uint64_t mFrameNumber;
- struct {
- uint32_t mFrameNumberLo;
- uint32_t mFrameNumberHi;
- };
- };
+ uint64_t mFrameNumber;
// mSlot is the slot index of this buffer (default INVALID_BUFFER_SLOT).
int mSlot;
diff --git a/libs/gui/Android.mk b/libs/gui/Android.mk
index 799b2b5b08..b497cb1a2a 100644
--- a/libs/gui/Android.mk
+++ b/libs/gui/Android.mk
@@ -36,6 +36,9 @@ LOCAL_CPPFLAGS += -Wno-gnu-zero-variadic-macro-arguments
# Don't warn about struct padding
LOCAL_CPPFLAGS += -Wno-padded
+# android/sensors.h uses nested anonymous unions and anonymous structs
+LOCAL_CPPFLAGS += -Wno-nested-anon-types -Wno-gnu-anonymous-struct
+
LOCAL_CPPFLAGS += -DDEBUG_ONLY_CODE=$(if $(filter userdebug eng,$(TARGET_BUILD_VARIANT)),1,0)
LOCAL_SRC_FILES := \
diff --git a/libs/gui/BufferItem.cpp b/libs/gui/BufferItem.cpp
index 5e3924a7ee..1357a4aa1a 100644
--- a/libs/gui/BufferItem.cpp
+++ b/libs/gui/BufferItem.cpp
@@ -23,6 +23,21 @@
namespace android {
+template<typename T>
+static inline constexpr uint32_t low32(const T n) {
+ return static_cast<uint32_t>(static_cast<uint64_t>(n));
+}
+
+template<typename T>
+static inline constexpr uint32_t high32(const T n) {
+ return static_cast<uint32_t>(static_cast<uint64_t>(n)>>32);
+}
+
+template<typename T>
+static inline constexpr T to64(const uint32_t lo, const uint32_t hi) {
+ return static_cast<T>(static_cast<uint64_t>(hi)<<32 | lo);
+}
+
BufferItem::BufferItem() :
mGraphicBuffer(NULL),
mFence(NULL),
@@ -56,12 +71,12 @@ size_t BufferItem::getPodSize() const {
addAligned(size, mCrop);
addAligned(size, mTransform);
addAligned(size, mScalingMode);
- addAligned(size, mTimestampLo);
- addAligned(size, mTimestampHi);
+ addAligned(size, low32(mTimestamp));
+ addAligned(size, high32(mTimestamp));
addAligned(size, mIsAutoTimestamp);
addAligned(size, mDataSpace);
- addAligned(size, mFrameNumberLo);
- addAligned(size, mFrameNumberHi);
+ addAligned(size, low32(mFrameNumber));
+ addAligned(size, high32(mFrameNumber));
addAligned(size, mSlot);
addAligned(size, mIsDroppable);
addAligned(size, mAcquireCalled);
@@ -141,12 +156,12 @@ status_t BufferItem::flatten(
writeAligned(buffer, size, mCrop);
writeAligned(buffer, size, mTransform);
writeAligned(buffer, size, mScalingMode);
- writeAligned(buffer, size, mTimestampLo);
- writeAligned(buffer, size, mTimestampHi);
+ writeAligned(buffer, size, low32(mTimestamp));
+ writeAligned(buffer, size, high32(mTimestamp));
writeAligned(buffer, size, mIsAutoTimestamp);
writeAligned(buffer, size, mDataSpace);
- writeAligned(buffer, size, mFrameNumberLo);
- writeAligned(buffer, size, mFrameNumberHi);
+ writeAligned(buffer, size, low32(mFrameNumber));
+ writeAligned(buffer, size, high32(mFrameNumber));
writeAligned(buffer, size, mSlot);
writeAligned(buffer, size, mIsDroppable);
writeAligned(buffer, size, mAcquireCalled);
@@ -194,15 +209,20 @@ status_t BufferItem::unflatten(
return NO_MEMORY;
}
+ uint32_t timestampLo = 0, timestampHi = 0;
+ uint32_t frameNumberLo = 0, frameNumberHi = 0;
+
readAligned(buffer, size, mCrop);
readAligned(buffer, size, mTransform);
readAligned(buffer, size, mScalingMode);
- readAligned(buffer, size, mTimestampLo);
- readAligned(buffer, size, mTimestampHi);
+ readAligned(buffer, size, timestampLo);
+ readAligned(buffer, size, timestampHi);
+ mTimestamp = to64<int64_t>(timestampLo, timestampHi);
readAligned(buffer, size, mIsAutoTimestamp);
readAligned(buffer, size, mDataSpace);
- readAligned(buffer, size, mFrameNumberLo);
- readAligned(buffer, size, mFrameNumberHi);
+ readAligned(buffer, size, frameNumberLo);
+ readAligned(buffer, size, frameNumberHi);
+ mFrameNumber = to64<uint64_t>(frameNumberLo, frameNumberHi);
readAligned(buffer, size, mSlot);
readAligned(buffer, size, mIsDroppable);
readAligned(buffer, size, mAcquireCalled);