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

Commit 08828204 authored by John Reck's avatar John Reck
Browse files

Align SurfaceView better to overscroll stretch

Bug: 419836766
Flag: com.android.graphics.hwui.flags.surfaceview_stretch_alignment
Test: manual; hwtests "Scrolling Stretched SurfaceView"
Change-Id: I3a4ef2df370e4f1dd513fbdb95ec0ab50054fadb
parent 41995c9d
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -224,3 +224,13 @@ flag {
    purpose: PURPOSE_BUGFIX
  }
}

flag {
  name: "surfaceview_stretch_alignment"
  namespace: "core_graphics"
  description: "Fix SurfaceView alignment when overscroll stretch is occurring"
  bug: "419836766"
  metadata {
    purpose: PURPOSE_BUGFIX
  }
}
+55 −26
Original line number Diff line number Diff line
@@ -15,6 +15,9 @@
 */

#define ATRACE_TAG ATRACE_TAG_VIEW
#ifdef __linux__
#include <com_android_graphics_hwui_flags.h>
#endif
#include <Animator.h>
#include <DamageAccumulator.h>
#include <Matrix.h>
@@ -36,6 +39,14 @@ using namespace uirenderer;
        ? (reinterpret_cast<RenderNode*>(renderNodePtr)->setPropertyFieldsDirty(dirtyFlag), true) \
        : false)

bool surfaceview_stretch_alignment() {
#ifdef __linux__
    return com::android::graphics::hwui::flags::surfaceview_stretch_alignment();
#else
    return true;
#endif
}

// ----------------------------------------------------------------------------
// DisplayList view properties
// ----------------------------------------------------------------------------
@@ -708,6 +719,23 @@ static void android_view_RenderNode_requestPositionUpdates(JNIEnv* env, jobject,
                info.damageAccumulator->findNearestStretchEffect();
            const StretchEffect* effect = result.stretchEffect;
            if (effect) {
                if (surfaceview_stretch_alignment()) {
                    auto& parentBounds = result.parentBounds;
                    auto parentWidth = parentBounds.width();
                    auto parentHeight = parentBounds.height();
                    float normalized;
                    normalized = targetBounds.top / parentHeight;
                    targetBounds.top = effect->computeStretchedPositionY(normalized) * parentHeight;
                    normalized = targetBounds.bottom / parentHeight;
                    targetBounds.bottom =
                            effect->computeStretchedPositionY(normalized) * parentHeight;

                    normalized = targetBounds.left / parentWidth;
                    targetBounds.left = effect->computeStretchedPositionX(normalized) * parentWidth;
                    normalized = targetBounds.right / parentWidth;
                    targetBounds.right =
                            effect->computeStretchedPositionX(normalized) * parentWidth;
                } else {
                    // Compute the number of pixels that the stretching container
                    // scales by.
                    // Then compute the scale factor that the child would need
@@ -734,6 +762,7 @@ static void android_view_RenderNode_requestPositionUpdates(JNIEnv* env, jobject,
                    targetBounds.top = dst.top();
                    targetBounds.right = dst.right();
                    targetBounds.bottom = dst.bottom();
                }
            } else {
                return;
            }