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

Commit d2a93632 authored by John Reck's avatar John Reck Committed by Android (Google) Code Review
Browse files

Merge "clamp & round alpha" into lmp-dev

parents 52ab18bc 3b52c03f
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -209,7 +209,7 @@ public:
    }

    bool setAlpha(float alpha) {
        alpha = fminf(1.0f, fmaxf(0.0f, alpha));
        alpha = MathUtils::clampAlpha(alpha);
        return RP_SET(mPrimitiveFields.mAlpha, alpha);
    }

+11 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ namespace android {
namespace uirenderer {

#define NON_ZERO_EPSILON (0.001f)
#define ALPHA_EPSILON (0.001f)

class MathUtils {
public:
@@ -34,6 +35,16 @@ public:
        return value >= NON_ZERO_EPSILON;
    }

    inline static float clampAlpha(float alpha) {
        if (alpha <= ALPHA_EPSILON) {
            return 0;
        } else if (alpha >= (1 - ALPHA_EPSILON)) {
            return 1;
        } else {
            return alpha;
        }
    }

    inline static bool areEqual(float valueA, float valueB) {
        return isZero(valueA - valueB);
    }