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

Commit d333c921 authored by Nader Jawad's avatar Nader Jawad Committed by Automerger Merge Worker
Browse files

Merge "Add a linear variant of the stretch effect" into sc-dev am: 020efbc1

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/14488483

Change-Id: Idf7ce13661dd28a2f977d0c49b52fb4e03c9c119
parents d321459a 020efbc1
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -150,9 +150,19 @@ static inline void applyMatrix(const SkMatrix* transform, SkRect* rect) {
    }
}

static inline void applyMatrix(const SkMatrix& transform, SkRect* rect) {
    return applyMatrix(&transform, rect);
}

static inline void mapRect(const RenderProperties& props, const SkRect& in, SkRect* out) {
    if (in.isEmpty()) return;
    SkRect temp(in);
    if (Properties::stretchEffectBehavior == StretchEffectBehavior::LinearScale) {
        const StretchEffect& stretch = props.layerProperties().getStretchEffect();
        if (!stretch.isEmpty()) {
            applyMatrix(stretch.makeLinearStretch(props.getWidth(), props.getHeight()), &temp);
        }
    }
    applyMatrix(props.getTransformMatrix(), &temp);
    if (props.getStaticMatrix()) {
        applyMatrix(props.getStaticMatrix(), &temp);
+6 −0
Original line number Diff line number Diff line
@@ -84,6 +84,8 @@ float Properties::defaultSdrWhitePoint = 200.f;
bool Properties::useHintManager = true;
int Properties::targetCpuTimePercentage = 70;

StretchEffectBehavior Properties::stretchEffectBehavior = StretchEffectBehavior::Shader;

bool Properties::load() {
    bool prevDebugLayersUpdates = debugLayersUpdates;
    bool prevDebugOverdraw = debugOverdraw;
@@ -135,6 +137,10 @@ bool Properties::load() {
    targetCpuTimePercentage = base::GetIntProperty(PROPERTY_TARGET_CPU_TIME_PERCENTAGE, 70);
    if (targetCpuTimePercentage <= 0 || targetCpuTimePercentage > 100) targetCpuTimePercentage = 70;

    int stretchType = base::GetIntProperty(PROPERTY_STRETCH_EFFECT_TYPE, 0);
    stretchType = std::clamp(stretchType, 0, static_cast<int>(StretchEffectBehavior::LinearScale));
    stretchEffectBehavior = static_cast<StretchEffectBehavior>(stretchType);

    return (prevDebugLayersUpdates != debugLayersUpdates) || (prevDebugOverdraw != debugOverdraw);
}

+9 −0
Original line number Diff line number Diff line
@@ -171,6 +171,8 @@ enum DebugLevel {
 */
#define PROPERTY_TARGET_CPU_TIME_PERCENTAGE "debug.hwui.target_cpu_time_percent"

#define PROPERTY_STRETCH_EFFECT_TYPE "debug.hwui.stretch_mode"

/**
 * Property for whether this is running in the emulator.
 */
@@ -197,6 +199,11 @@ enum class OverdrawColorSet { Default = 0, Deuteranomaly };

enum class RenderPipelineType { SkiaGL, SkiaVulkan, NotInitialized = 128 };

enum class StretchEffectBehavior {
    Shader,
    LinearScale,
};

/**
 * Renderthread-only singleton which manages several static rendering properties. Most of these
 * are driven by system properties which are queried once at initialization, and again if init()
@@ -270,6 +277,8 @@ public:
    static bool useHintManager;
    static int targetCpuTimePercentage;

    static StretchEffectBehavior stretchEffectBehavior;

private:
    static ProfileType sProfileType;
    static bool sDisableProfileBars;
+8 −0
Original line number Diff line number Diff line
@@ -477,6 +477,14 @@ void RenderNode::applyViewPropertyTransforms(mat4& matrix, bool true3dTransform)
            }
        }
    }

    if (Properties::stretchEffectBehavior == StretchEffectBehavior::LinearScale) {
        const StretchEffect& stretch = properties().layerProperties().getStretchEffect();
        if (!stretch.isEmpty()) {
            matrix.multiply(
                    stretch.makeLinearStretch(properties().getWidth(), properties().getHeight()));
        }
    }
}

const SkPath* RenderNode::getClippedOutline(const SkRect& clipRect) const {
+9 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@

#include <SkImage.h>
#include <SkImageFilter.h>
#include <SkMatrix.h>
#include <SkPoint.h>
#include <SkRect.h>
#include <SkRuntimeEffect.h>
@@ -99,6 +100,14 @@ public:

    const SkVector getStretchDirection() const { return mStretchDirection; }

    SkMatrix makeLinearStretch(float width, float height) const {
        SkMatrix matrix;
        auto [sX, sY] = getStretchDirection();
        matrix.setScale(1 + std::abs(sX), 1 + std::abs(sY), sX > 0 ? 0 : width,
                        sY > 0 ? 0 : height);
        return matrix;
    }

private:
    static sk_sp<SkRuntimeEffect> getStretchEffect();
    mutable SkVector mStretchDirection{0, 0};
Loading