Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1b9910ef authored by Dominik Laskowski's avatar Dominik Laskowski Committed by Automerger Merge Worker
Browse files

Merge "FTL: Pull Flags into namespace" into tm-dev am: ffe62451 am: eeee8bf6

parents 98e1b73d eeee8bf6
Loading
Loading
Loading
Loading
+12 −12
Original line number Diff line number Diff line
@@ -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>
@@ -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 {
@@ -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);
@@ -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) {
@@ -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
+1 −1
Original line number Diff line number Diff line
@@ -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",
+3 −2
Original line number Diff line number Diff line
@@ -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 };

+1 −1
Original line number Diff line number Diff line
@@ -821,7 +821,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);
+5 −7
Original line number Diff line number Diff line
@@ -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>

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