summaryrefslogtreecommitdiff
path: root/libs/hwui/jni/android_graphics_RenderNode.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'libs/hwui/jni/android_graphics_RenderNode.cpp')
-rw-r--r--libs/hwui/jni/android_graphics_RenderNode.cpp86
1 files changed, 59 insertions, 27 deletions
diff --git a/libs/hwui/jni/android_graphics_RenderNode.cpp b/libs/hwui/jni/android_graphics_RenderNode.cpp
index 5131c646c4a4..a096ed0c63bb 100644
--- a/libs/hwui/jni/android_graphics_RenderNode.cpp
+++ b/libs/hwui/jni/android_graphics_RenderNode.cpp
@@ -572,11 +572,13 @@ static void android_view_RenderNode_requestPositionUpdates(JNIEnv* env, jobject,
info.damageAccumulator->computeCurrentTransform(&transform);
const RenderProperties& props = node.properties();
- if (info.stretchEffectCount) {
- handleStretchEffect(info, transform);
+ uirenderer::Rect bounds(props.getWidth(), props.getHeight());
+ bool useStretchShader =
+ Properties::stretchEffectBehavior != StretchEffectBehavior::UniformScale;
+ if (useStretchShader && info.stretchEffectCount) {
+ handleStretchEffect(info, bounds);
}
- uirenderer::Rect bounds(props.getWidth(), props.getHeight());
transform.mapRect(bounds);
if (CC_LIKELY(transform.isPureTranslate())) {
@@ -639,7 +641,33 @@ static void android_view_RenderNode_requestPositionUpdates(JNIEnv* env, jobject,
return env;
}
- void handleStretchEffect(const TreeInfo& info, const Matrix4& transform) {
+ void stretchTargetBounds(const StretchEffect& stretchEffect,
+ float width, float height,
+ const SkRect& childRelativeBounds,
+ uirenderer::Rect& bounds) {
+ float normalizedLeft = childRelativeBounds.left() / width;
+ float normalizedTop = childRelativeBounds.top() / height;
+ float normalizedRight = childRelativeBounds.right() / width;
+ float normalizedBottom = childRelativeBounds.bottom() / height;
+ float reverseLeft = width *
+ (stretchEffect.computeStretchedPositionX(normalizedLeft) -
+ normalizedLeft);
+ float reverseTop = height *
+ (stretchEffect.computeStretchedPositionY(normalizedTop) -
+ normalizedTop);
+ float reverseRight = width *
+ (stretchEffect.computeStretchedPositionX(normalizedRight) -
+ normalizedLeft);
+ float reverseBottom = height *
+ (stretchEffect.computeStretchedPositionY(normalizedBottom) -
+ normalizedTop);
+ bounds.left = reverseLeft;
+ bounds.top = reverseTop;
+ bounds.right = reverseRight;
+ bounds.bottom = reverseBottom;
+ }
+
+ void handleStretchEffect(const TreeInfo& info, uirenderer::Rect& targetBounds) {
// Search up to find the nearest stretcheffect parent
const DamageAccumulator::StretchResult result =
info.damageAccumulator->findNearestStretchEffect();
@@ -649,31 +677,35 @@ static void android_view_RenderNode_requestPositionUpdates(JNIEnv* env, jobject,
}
const auto& childRelativeBounds = result.childRelativeBounds;
-
- JNIEnv* env = jnienv();
-
- jobject localref = env->NewLocalRef(mWeakRef);
- if (CC_UNLIKELY(!localref)) {
- env->DeleteWeakGlobalRef(mWeakRef);
- mWeakRef = nullptr;
- return;
- }
+ stretchTargetBounds(*effect, result.width, result.height,
+ childRelativeBounds,targetBounds);
+
+ if (Properties::stretchEffectBehavior == StretchEffectBehavior::Shader) {
+ JNIEnv* env = jnienv();
+
+ jobject localref = env->NewLocalRef(mWeakRef);
+ if (CC_UNLIKELY(!localref)) {
+ env->DeleteWeakGlobalRef(mWeakRef);
+ mWeakRef = nullptr;
+ return;
+ }
#ifdef __ANDROID__ // Layoutlib does not support CanvasContext
- SkVector stretchDirection = effect->getStretchDirection();
- env->CallVoidMethod(localref, gPositionListener_ApplyStretchMethod,
- info.canvasContext.getFrameNumber(),
- result.width,
- result.height,
- stretchDirection.fX,
- stretchDirection.fY,
- effect->maxStretchAmountX,
- effect->maxStretchAmountY,
- childRelativeBounds.left(),
- childRelativeBounds.top(),
- childRelativeBounds.right(),
- childRelativeBounds.bottom());
+ SkVector stretchDirection = effect->getStretchDirection();
+ env->CallVoidMethod(localref, gPositionListener_ApplyStretchMethod,
+ info.canvasContext.getFrameNumber(),
+ result.width,
+ result.height,
+ stretchDirection.fX,
+ stretchDirection.fY,
+ effect->maxStretchAmountX,
+ effect->maxStretchAmountY,
+ childRelativeBounds.left(),
+ childRelativeBounds.top(),
+ childRelativeBounds.right(),
+ childRelativeBounds.bottom());
#endif
- env->DeleteLocalRef(localref);
+ env->DeleteLocalRef(localref);
+ }
}
void doUpdatePositionAsync(jlong frameNumber, jint left, jint top,