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

Commit f8dcf141 authored by Dominik Laskowski's avatar Dominik Laskowski Committed by Android (Google) Code Review
Browse files

Merge "SF: Remove StrongTyping in favor of FTL mixins" into main

parents 8b789ffa 43baf905
Loading
Loading
Loading
Loading
+9 −4
Original line number Diff line number Diff line
@@ -21,17 +21,17 @@

#include <android-base/stringprintf.h>
#include <android/configuration.h>
#include <ftl/mixins.h>
#include <ftl/small_map.h>
#include <ui/DisplayId.h>
#include <ui/DisplayMode.h>
#include <ui/Size.h>
#include <utils/Timers.h>

#include <common/FlagManager.h>
#include <scheduler/Fps.h>

#include <common/FlagManager.h>
#include "DisplayHardware/Hal.h"
#include "Scheduler/StrongTyping.h"

namespace android {

@@ -46,7 +46,12 @@ bool operator>(const DisplayModePtr&, const DisplayModePtr&) = delete;
bool operator<=(const DisplayModePtr&, const DisplayModePtr&) = delete;
bool operator>=(const DisplayModePtr&, const DisplayModePtr&) = delete;

using DisplayModeId = StrongTyping<ui::DisplayModeId, struct DisplayModeIdTag, Compare>;
struct DisplayModeId : ftl::DefaultConstructible<DisplayModeId, ui::DisplayModeId>,
                       ftl::Incrementable<DisplayModeId>,
                       ftl::Equatable<DisplayModeId>,
                       ftl::Orderable<DisplayModeId> {
    using DefaultConstructible::DefaultConstructible;
};

using DisplayModes = ftl::SmallMap<DisplayModeId, DisplayModePtr, 3>;
using DisplayModeIterator = DisplayModes::const_iterator;
@@ -185,7 +190,7 @@ inline bool equalsExceptDisplayModeId(const DisplayMode& lhs, const DisplayMode&
inline std::string to_string(const DisplayMode& mode) {
    return base::StringPrintf("{id=%d, hwcId=%d, resolution=%dx%d, vsyncRate=%s, "
                              "dpi=%.2fx%.2f, group=%d, vrrConfig=%s}",
                              mode.getId().value(), mode.getHwcId(), mode.getWidth(),
                              ftl::to_underlying(mode.getId()), mode.getHwcId(), mode.getWidth(),
                              mode.getHeight(), to_string(mode.getVsyncRate()).c_str(),
                              mode.getDpi().x, mode.getDpi().y, mode.getGroup(),
                              to_string(mode.getVrrConfig()).c_str());
+1 −1
Original line number Diff line number Diff line
@@ -148,7 +148,7 @@ DisplayEventReceiver::Event makeModeChanged(const scheduler::FrameRateMode& mode
    DisplayEventReceiver::Event event;
    event.header = {DisplayEventReceiver::DISPLAY_EVENT_MODE_CHANGE,
                    mode.modePtr->getPhysicalDisplayId(), systemTime()};
    event.modeChange.modeId = mode.modePtr->getId().value();
    event.modeChange.modeId = ftl::to_underlying(mode.modePtr->getId());
    event.modeChange.vsyncPeriod = mode.fps.getPeriodNsecs();
    return event;
}
+2 −1
Original line number Diff line number Diff line
@@ -286,7 +286,8 @@ struct RefreshRateSelector::RefreshRateScoreComparator {
std::string RefreshRateSelector::Policy::toString() const {
    return base::StringPrintf("{defaultModeId=%d, allowGroupSwitching=%s"
                              ", primaryRanges=%s, appRequestRanges=%s}",
                              defaultMode.value(), allowGroupSwitching ? "true" : "false",
                              ftl::to_underlying(defaultMode),
                              allowGroupSwitching ? "true" : "false",
                              to_string(primaryRanges).c_str(),
                              to_string(appRequestRanges).c_str());
}
+0 −1
Original line number Diff line number Diff line
@@ -31,7 +31,6 @@

#include "DisplayHardware/DisplayMode.h"
#include "Scheduler/OneShotTimer.h"
#include "Scheduler/StrongTyping.h"
#include "ThreadContext.h"
#include "Utils/Dumper.h"

+0 −89
Original line number Diff line number Diff line
/*
 * Copyright 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#pragma once
namespace android {

template <typename T, template <typename> class AbilityType>
struct Ability {
    T& base() { return static_cast<T&>(*this); }
    T const& base() const { return static_cast<T const&>(*this); }
};

template <typename T>
struct Add : Ability<T, Add> {
    inline T operator+(T const& other) const { return T(this->base().value() + other.value()); }
    inline T& operator++() {
        ++this->base().value();
        return this->base();
    };
    inline T operator++(int) {
        T tmp(this->base());
        operator++();
        return tmp;
    };
    inline T& operator+=(T const& other) {
        this->base().value() += other.value();
        return this->base();
    };
};

template <typename T>
struct Compare : Ability<T, Compare> {
    inline bool operator==(T const& other) const { return this->base().value() == other.value(); };
    inline bool operator<(T const& other) const { return this->base().value() < other.value(); }
    inline bool operator<=(T const& other) const { return (*this < other) || (*this == other); }
    inline bool operator!=(T const& other) const { return !(*this == other); }
    inline bool operator>=(T const& other) const { return !(*this < other); }
    inline bool operator>(T const& other) const { return !(*this < other || *this == other); }
};

template <typename T>
struct Hash : Ability<T, Hash> {
    [[nodiscard]] std::size_t hash() const {
        return std::hash<typename std::remove_const<
                typename std::remove_reference<decltype(this->base().value())>::type>::type>{}(
                this->base().value());
    }
};

template <typename T, typename W, template <typename> class... Ability>
struct StrongTyping : Ability<StrongTyping<T, W, Ability...>>... {
    constexpr StrongTyping() = default;
    constexpr explicit StrongTyping(T const& value) : mValue(value) {}
    StrongTyping(StrongTyping const&) = default;
    StrongTyping& operator=(StrongTyping const&) = default;
    explicit inline operator T() const { return mValue; }
    T const& value() const { return mValue; }
    T& value() { return mValue; }

    friend std::ostream& operator<<(std::ostream& os, const StrongTyping<T, W, Ability...>& value) {
        return os << value.value();
    }

private:
    T mValue{0};
};
} // namespace android

namespace std {
template <typename T, typename W, template <typename> class... Ability>
struct hash<android::StrongTyping<T, W, Ability...>> {
    std::size_t operator()(android::StrongTyping<T, W, Ability...> const& k) const {
        return k.hash();
    }
};
} // namespace std
Loading