Loading include/ftl/Flags.h→include/ftl/flags.h +12 −12 Original line number Diff line number Diff line Loading @@ -25,9 +25,9 @@ #include <string> #include <type_traits> // TODO(b/185536303): Align with FTL style and namespace. // TODO(b/185536303): Align with FTL style. namespace android { namespace android::ftl { /* A class for handling flags defined by an enum or enum class in a type-safe way. */ template <typename F> Loading @@ -48,10 +48,10 @@ public: // should force them to be explicitly constructed from their underlying types to make full use // of the type checker. template <typename T = U> constexpr Flags(T t, std::enable_if_t<!ftl::is_scoped_enum_v<F>, T>* = nullptr) : mFlags(t) {} constexpr Flags(T t, std::enable_if_t<!is_scoped_enum_v<F>, T>* = nullptr) : mFlags(t) {} template <typename T = U> explicit constexpr Flags(T t, std::enable_if_t<ftl::is_scoped_enum_v<F>, T>* = nullptr) explicit constexpr Flags(T t, std::enable_if_t<is_scoped_enum_v<F>, T>* = nullptr) : mFlags(t) {} class Iterator { Loading Loading @@ -175,7 +175,7 @@ public: bool first = true; U unstringified = 0; for (const F f : *this) { if (const auto flagName = ftl::flag_name(f)) { if (const auto flagName = flag_name(f)) { appendFlag(result, flagName.value(), first); } else { unstringified |= static_cast<U>(f); Loading @@ -183,8 +183,8 @@ public: } if (unstringified != 0) { constexpr auto radix = sizeof(U) == 1 ? ftl::Radix::kBin : ftl::Radix::kHex; appendFlag(result, ftl::to_string(unstringified, radix), first); constexpr auto radix = sizeof(U) == 1 ? Radix::kBin : Radix::kHex; appendFlag(result, to_string(unstringified, radix), first); } if (first) { Loading @@ -211,15 +211,15 @@ private: // as flags. In order to use these, add them via a `using namespace` declaration. namespace flag_operators { template <typename F, typename = std::enable_if_t<ftl::is_scoped_enum_v<F>>> template <typename F, typename = std::enable_if_t<is_scoped_enum_v<F>>> inline Flags<F> operator~(F f) { return static_cast<F>(~ftl::to_underlying(f)); return static_cast<F>(~to_underlying(f)); } template <typename F, typename = std::enable_if_t<ftl::is_scoped_enum_v<F>>> template <typename F, typename = std::enable_if_t<is_scoped_enum_v<F>>> Flags<F> operator|(F lhs, F rhs) { return static_cast<F>(ftl::to_underlying(lhs) | ftl::to_underlying(rhs)); return static_cast<F>(to_underlying(lhs) | to_underlying(rhs)); } } // namespace flag_operators } // namespace android } // namespace android::ftl libs/ftl/Android.bp +1 −1 Original line number Diff line number Diff line Loading @@ -14,11 +14,11 @@ cc_test { address: true, }, srcs: [ "Flags_test.cpp", "cast_test.cpp", "concat_test.cpp", "enum_test.cpp", "fake_guard_test.cpp", "flags_test.cpp", "future_test.cpp", "small_map_test.cpp", "small_vector_test.cpp", Loading libs/ftl/Flags_test.cpp→libs/ftl/flags_test.cpp +3 −2 Original line number Diff line number Diff line Loading @@ -14,14 +14,15 @@ * limitations under the License. */ #include <ftl/flags.h> #include <gtest/gtest.h> #include <ftl/Flags.h> #include <type_traits> namespace android::test { using namespace android::flag_operators; using ftl::Flags; using namespace ftl::flag_operators; enum class TestFlags : uint8_t { ONE = 0x1, TWO = 0x2, THREE = 0x4 }; Loading libs/gui/LayerState.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -815,7 +815,7 @@ status_t BufferData::writeToParcel(Parcel* output) const { status_t BufferData::readFromParcel(const Parcel* input) { int32_t tmpInt32; SAFE_PARCEL(input->readInt32, &tmpInt32); flags = Flags<BufferDataChange>(tmpInt32); flags = ftl::Flags<BufferDataChange>(tmpInt32); bool tmpBool = false; SAFE_PARCEL(input->readBool, &tmpBool); Loading libs/gui/WindowInfo.cpp +5 −7 Original line number Diff line number Diff line Loading @@ -14,10 +14,11 @@ * limitations under the License. */ #include <type_traits> #define LOG_TAG "WindowInfo" #define LOG_NDEBUG 0 #include <type_traits> #include <binder/Parcel.h> #include <gui/WindowInfo.h> Loading @@ -25,8 +26,7 @@ namespace android::gui { // --- WindowInfo --- void WindowInfo::setInputConfig(Flags<InputConfig> config, bool value) { void WindowInfo::setInputConfig(ftl::Flags<InputConfig> config, bool value) { if (value) { inputConfig |= config; return; Loading Loading @@ -182,18 +182,16 @@ status_t WindowInfo::readFromParcel(const android::Parcel* parcel) { return status; } layoutParamsFlags = Flags<Flag>(lpFlags); layoutParamsFlags = ftl::Flags<Flag>(lpFlags); layoutParamsType = static_cast<Type>(lpType); transform.set({dsdx, dtdx, tx, dtdy, dsdy, ty, 0, 0, 1}); touchOcclusionMode = static_cast<TouchOcclusionMode>(touchOcclusionModeInt); inputConfig = Flags<InputConfig>(inputConfigInt); inputConfig = ftl::Flags<InputConfig>(inputConfigInt); touchableRegionCropHandle = touchableRegionCropHandleSp; return OK; } // --- WindowInfoHandle --- WindowInfoHandle::WindowInfoHandle() {} WindowInfoHandle::~WindowInfoHandle() {} Loading Loading
include/ftl/Flags.h→include/ftl/flags.h +12 −12 Original line number Diff line number Diff line Loading @@ -25,9 +25,9 @@ #include <string> #include <type_traits> // TODO(b/185536303): Align with FTL style and namespace. // TODO(b/185536303): Align with FTL style. namespace android { namespace android::ftl { /* A class for handling flags defined by an enum or enum class in a type-safe way. */ template <typename F> Loading @@ -48,10 +48,10 @@ public: // should force them to be explicitly constructed from their underlying types to make full use // of the type checker. template <typename T = U> constexpr Flags(T t, std::enable_if_t<!ftl::is_scoped_enum_v<F>, T>* = nullptr) : mFlags(t) {} constexpr Flags(T t, std::enable_if_t<!is_scoped_enum_v<F>, T>* = nullptr) : mFlags(t) {} template <typename T = U> explicit constexpr Flags(T t, std::enable_if_t<ftl::is_scoped_enum_v<F>, T>* = nullptr) explicit constexpr Flags(T t, std::enable_if_t<is_scoped_enum_v<F>, T>* = nullptr) : mFlags(t) {} class Iterator { Loading Loading @@ -175,7 +175,7 @@ public: bool first = true; U unstringified = 0; for (const F f : *this) { if (const auto flagName = ftl::flag_name(f)) { if (const auto flagName = flag_name(f)) { appendFlag(result, flagName.value(), first); } else { unstringified |= static_cast<U>(f); Loading @@ -183,8 +183,8 @@ public: } if (unstringified != 0) { constexpr auto radix = sizeof(U) == 1 ? ftl::Radix::kBin : ftl::Radix::kHex; appendFlag(result, ftl::to_string(unstringified, radix), first); constexpr auto radix = sizeof(U) == 1 ? Radix::kBin : Radix::kHex; appendFlag(result, to_string(unstringified, radix), first); } if (first) { Loading @@ -211,15 +211,15 @@ private: // as flags. In order to use these, add them via a `using namespace` declaration. namespace flag_operators { template <typename F, typename = std::enable_if_t<ftl::is_scoped_enum_v<F>>> template <typename F, typename = std::enable_if_t<is_scoped_enum_v<F>>> inline Flags<F> operator~(F f) { return static_cast<F>(~ftl::to_underlying(f)); return static_cast<F>(~to_underlying(f)); } template <typename F, typename = std::enable_if_t<ftl::is_scoped_enum_v<F>>> template <typename F, typename = std::enable_if_t<is_scoped_enum_v<F>>> Flags<F> operator|(F lhs, F rhs) { return static_cast<F>(ftl::to_underlying(lhs) | ftl::to_underlying(rhs)); return static_cast<F>(to_underlying(lhs) | to_underlying(rhs)); } } // namespace flag_operators } // namespace android } // namespace android::ftl
libs/ftl/Android.bp +1 −1 Original line number Diff line number Diff line Loading @@ -14,11 +14,11 @@ cc_test { address: true, }, srcs: [ "Flags_test.cpp", "cast_test.cpp", "concat_test.cpp", "enum_test.cpp", "fake_guard_test.cpp", "flags_test.cpp", "future_test.cpp", "small_map_test.cpp", "small_vector_test.cpp", Loading
libs/ftl/Flags_test.cpp→libs/ftl/flags_test.cpp +3 −2 Original line number Diff line number Diff line Loading @@ -14,14 +14,15 @@ * limitations under the License. */ #include <ftl/flags.h> #include <gtest/gtest.h> #include <ftl/Flags.h> #include <type_traits> namespace android::test { using namespace android::flag_operators; using ftl::Flags; using namespace ftl::flag_operators; enum class TestFlags : uint8_t { ONE = 0x1, TWO = 0x2, THREE = 0x4 }; Loading
libs/gui/LayerState.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -815,7 +815,7 @@ status_t BufferData::writeToParcel(Parcel* output) const { status_t BufferData::readFromParcel(const Parcel* input) { int32_t tmpInt32; SAFE_PARCEL(input->readInt32, &tmpInt32); flags = Flags<BufferDataChange>(tmpInt32); flags = ftl::Flags<BufferDataChange>(tmpInt32); bool tmpBool = false; SAFE_PARCEL(input->readBool, &tmpBool); Loading
libs/gui/WindowInfo.cpp +5 −7 Original line number Diff line number Diff line Loading @@ -14,10 +14,11 @@ * limitations under the License. */ #include <type_traits> #define LOG_TAG "WindowInfo" #define LOG_NDEBUG 0 #include <type_traits> #include <binder/Parcel.h> #include <gui/WindowInfo.h> Loading @@ -25,8 +26,7 @@ namespace android::gui { // --- WindowInfo --- void WindowInfo::setInputConfig(Flags<InputConfig> config, bool value) { void WindowInfo::setInputConfig(ftl::Flags<InputConfig> config, bool value) { if (value) { inputConfig |= config; return; Loading Loading @@ -182,18 +182,16 @@ status_t WindowInfo::readFromParcel(const android::Parcel* parcel) { return status; } layoutParamsFlags = Flags<Flag>(lpFlags); layoutParamsFlags = ftl::Flags<Flag>(lpFlags); layoutParamsType = static_cast<Type>(lpType); transform.set({dsdx, dtdx, tx, dtdy, dsdy, ty, 0, 0, 1}); touchOcclusionMode = static_cast<TouchOcclusionMode>(touchOcclusionModeInt); inputConfig = Flags<InputConfig>(inputConfigInt); inputConfig = ftl::Flags<InputConfig>(inputConfigInt); touchableRegionCropHandle = touchableRegionCropHandleSp; return OK; } // --- WindowInfoHandle --- WindowInfoHandle::WindowInfoHandle() {} WindowInfoHandle::~WindowInfoHandle() {} Loading