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

Commit 63644d34 authored by Nader Jawad's avatar Nader Jawad
Browse files

Updated SkiaGLRenderEngine to no longer adjust stretch bounds

Because the stretch region for surfaces is now calculated
within HWUI as part of the transformation matrix, remove
the position logic to adjust the drawing bounds for a
surface with stretch applied to it. Also disabled
the stretch shader within render engine as
the approximate stretch from the matrix transformation
provides reasonable results.

For consistency update the shader within SkiaGLRenderEngine
to match easing changes from cubic to linear.

Bug: 179047472
Test: manual

Change-Id: I66170ba4e3168186b3d3e4e27ef6a26b4637bc18
parent 88fceed4
Loading
Loading
Loading
Loading
+6 −39
Original line number Diff line number Diff line
@@ -560,7 +560,11 @@ sk_sp<SkShader> SkiaGLRenderEngine::createRuntimeEffectShader(
        const LayerSettings* layer, const DisplaySettings& display, bool undoPremultipliedAlpha,
        bool requiresLinearEffect) {
    const auto stretchEffect = layer->stretchEffect;
    if (stretchEffect.hasEffect()) {
    // The given surface will be stretched by HWUI via matrix transformation
    // which gets similar results for most surfaces
    // Determine later on if we need to leverage the stertch shader within
    // surface flinger
    if (stretchEffect.hasEffect() && /* DISABLES CODE */ (false)) {
        const auto targetBuffer = layer->source.buffer.buffer;
        const auto graphicsBuffer = targetBuffer ? targetBuffer->getBuffer() : nullptr;
        if (graphicsBuffer && shader) {
@@ -653,33 +657,6 @@ private:
    int mSaveCount;
};

void drawStretch(const SkRect& bounds, const StretchEffect& stretchEffect,
                 SkCanvas* canvas, const SkPaint& paint) {
    float top = bounds.top();
    float left = bounds.left();
    float bottom = bounds.bottom();
    float right = bounds.right();
    // Adjust the drawing bounds based on the stretch itself.
    float stretchOffsetX =
        round(bounds.width() * stretchEffect.getStretchWidthMultiplier());
    float stretchOffsetY =
        round(bounds.height() * stretchEffect.getStretchHeightMultiplier());
    if (stretchEffect.vectorY < 0.f) {
        top -= stretchOffsetY;
    } else if (stretchEffect.vectorY > 0.f){
        bottom += stretchOffsetY;
    }

    if (stretchEffect.vectorX < 0.f) {
        left -= stretchOffsetX;
    } else if (stretchEffect.vectorX > 0.f) {
        right += stretchOffsetX;
    }

    auto stretchBounds = SkRect::MakeLTRB(left, top, right, bottom);
    canvas->drawRect(stretchBounds, paint);
}

static SkRRect getBlurRRect(const BlurRegion& region) {
    const auto rect = SkRect::MakeLTRB(region.left, region.top, region.right, region.bottom);
    const SkVector radii[4] = {SkVector::Make(region.cornerRadiusTL, region.cornerRadiusTL),
@@ -1055,19 +1032,9 @@ status_t SkiaGLRenderEngine::drawLayers(const DisplaySettings& display,
        if (!bounds.isRect()) {
            paint.setAntiAlias(true);
            canvas->drawRRect(bounds, paint);
        } else {
            auto& stretchEffect = layer->stretchEffect;
            // TODO (njawad) temporarily disable manipulation of geometry
            //  the layer bounds will be updated in HWUI instead of RenderEngine
            //  in a subsequent CL
            // Keep the method call in a dead code path to make -Werror happy
            // with unused methods
            if (stretchEffect.hasEffect() && /* DISABLES CODE */ (false)) {
                drawStretch(bounds.rect(), stretchEffect, canvas, paint);
        } else {
            canvas->drawRect(bounds.rect(), paint);
        }
        }
        if (kFlushAfterEveryLayer) {
            ATRACE_NAME("flush surface");
            activeSurface->flush();
+4 −5
Original line number Diff line number Diff line
@@ -69,9 +69,8 @@ static const SkString stretchShader = SkString(R"(
    // and the other way around.
    uniform float uInterpolationStrength;

    float easeInCubic(float t, float d) {
        float tmp = t * d;
        return tmp * tmp * tmp;
    float easeIn(float t, float d) {
        return t * d;
    }

    float computeOverscrollStart(
@@ -84,7 +83,7 @@ static const SkString stretchShader = SkString(R"(
    ) {
        float offsetPos = uStretchAffectedDist - inPos;
        float posBasedVariation = mix(
                1. ,easeInCubic(offsetPos, uInverseStretchAffectedDist), interpolationStrength);
                1. ,easeIn(offsetPos, uInverseStretchAffectedDist), interpolationStrength);
        float stretchIntensity = overscroll * posBasedVariation;
        return distanceStretched - (offsetPos / (1. + stretchIntensity));
    }
@@ -100,7 +99,7 @@ static const SkString stretchShader = SkString(R"(
    ) {
        float offsetPos = inPos - reverseStretchDist;
        float posBasedVariation = mix(
                1. ,easeInCubic(offsetPos, uInverseStretchAffectedDist), interpolationStrength);
                1. ,easeIn(offsetPos, uInverseStretchAffectedDist), interpolationStrength);
        float stretchIntensity = (-overscroll) * posBasedVariation;
        return 1 - (distanceStretched - (offsetPos / (1. + stretchIntensity)));
    }