Loading core/java/android/view/SurfaceControl.java +3 −3 Original line number Diff line number Diff line Loading @@ -3462,15 +3462,15 @@ public final class SurfaceControl implements Parcelable { * @return this This transaction for chaining * @hide */ public @NonNull Transaction setCrop(@NonNull SurfaceControl sc, float top, float left, float bottom, float right) { public @NonNull Transaction setCrop(@NonNull SurfaceControl sc, float left, float top, float right, float bottom) { checkPreconditions(sc); if (SurfaceControlRegistry.sCallStackDebuggingEnabled) { SurfaceControlRegistry.getProcessInstance().checkCallStackDebugging( "setCrop", this, sc, "crop={" + top + ", " + left + ", " + bottom + ", " + right + "}"); } nativeSetCrop(mNativeObject, sc.mNativeObject, top, left, bottom, right); nativeSetCrop(mNativeObject, sc.mNativeObject, left, top, right, bottom); return this; } Loading core/java/android/view/SurfaceView.java +26 −8 Original line number Diff line number Diff line Loading @@ -40,6 +40,7 @@ import android.graphics.Matrix; import android.graphics.Paint; import android.graphics.PixelFormat; import android.graphics.Rect; import android.graphics.RectF; import android.graphics.Region; import android.graphics.RenderNode; import android.hardware.input.InputManager; Loading Loading @@ -1666,7 +1667,7 @@ public class SurfaceView extends View implements ViewRootImpl.SurfaceChangedCall } private final Rect mRTLastReportedPosition = new Rect(); private final Rect mRTLastSetCrop = new Rect(); private final RectF mRTLastSetCrop = new RectF(); private class SurfaceViewPositionUpdateListener implements RenderNode.PositionUpdateListener { private final int mRtSurfaceWidth; Loading Loading @@ -1711,16 +1712,18 @@ public class SurfaceView extends View implements ViewRootImpl.SurfaceChangedCall @Override public void positionChanged(long frameNumber, int left, int top, int right, int bottom, int clipLeft, int clipTop, int clipRight, int clipBottom) { int clipLeft, int clipTop, int clipRight, int clipBottom, int nodeWidth, int nodeHeight) { try { if (DEBUG_POSITION) { Log.d(TAG, String.format( "%d updateSurfacePosition RenderWorker, frameNr = %d, " + "position = [%d, %d, %d, %d] clip = [%d, %d, %d, %d] " + "surfaceSize = %dx%d", + "surfaceSize = %dx%d renderNodeSize = %d%d", System.identityHashCode(SurfaceView.this), frameNumber, left, top, right, bottom, clipLeft, clipTop, clipRight, clipBottom, mRtSurfaceWidth, mRtSurfaceHeight)); mRtSurfaceWidth, mRtSurfaceHeight, nodeWidth, nodeHeight)); } synchronized (mSurfaceControlLock) { if (mSurfaceControl == null) return; Loading @@ -1735,14 +1738,29 @@ public class SurfaceView extends View implements ViewRootImpl.SurfaceChangedCall mRTLastReportedPosition.top /*positionTop*/, postScaleX, postScaleY); mRTLastSetCrop.set(clipLeft, clipTop, clipRight, clipBottom); // The computed crop is in view-relative dimensions, however we need it to be // in buffer-relative dimensions. So scale the crop by the ratio between // the view's unscaled width/height (nodeWidth/Height), and the surface's // width/height // That is, if the Surface has a fixed size of 50x50, the SurfaceView is laid // out to a size of 100x100, and the SurfaceView is ultimately scaled to // 1000x1000, then we need to scale the crop by just the 2x from surface // domain to SV domain. final float surfaceToNodeScaleX = (float) mRtSurfaceWidth / (float) nodeWidth; final float surfaceToNodeScaleY = (float) mRtSurfaceHeight / (float) nodeHeight; mRTLastSetCrop.set(clipLeft * surfaceToNodeScaleX, clipTop * surfaceToNodeScaleY, clipRight * surfaceToNodeScaleX, clipBottom * surfaceToNodeScaleY); if (DEBUG_POSITION) { Log.d(TAG, String.format("Setting layer crop = [%d, %d, %d, %d] " Log.d(TAG, String.format("Setting layer crop = [%f, %f, %f, %f] " + "from scale %f, %f", mRTLastSetCrop.left, mRTLastSetCrop.top, mRTLastSetCrop.right, mRTLastSetCrop.bottom, postScaleX, postScaleY)); surfaceToNodeScaleX, surfaceToNodeScaleY)); } mPositionChangedTransaction.setCrop(mSurfaceControl, mRTLastSetCrop); mPositionChangedTransaction.setCrop(mSurfaceControl, mRTLastSetCrop.left, mRTLastSetCrop.top, mRTLastSetCrop.right, mRTLastSetCrop.bottom); if (mRTLastSetCrop.isEmpty()) { mPositionChangedTransaction.hide(mSurfaceControl); } else { Loading graphics/java/android/graphics/RenderNode.java +8 −5 Original line number Diff line number Diff line Loading @@ -279,7 +279,8 @@ public final class RenderNode { * @hide */ default void positionChanged(long frameNumber, int left, int top, int right, int bottom, int clipLeft, int clipTop, int clipRight, int clipBottom) { int clipLeft, int clipTop, int clipRight, int clipBottom, int nodeWidth, int nodeHeight) { positionChanged(frameNumber, left, top, right, bottom); } Loading @@ -304,11 +305,12 @@ public final class RenderNode { * @hide */ static boolean callPositionChanged2(WeakReference<PositionUpdateListener> weakListener, long frameNumber, int left, int top, int right, int bottom, int clipLeft, int clipTop, int clipRight, int clipBottom) { int clipLeft, int clipTop, int clipRight, int clipBottom, int nodeWidth, int nodeHeight) { final PositionUpdateListener listener = weakListener.get(); if (listener != null) { listener.positionChanged(frameNumber, left, top, right, bottom, clipLeft, clipTop, clipRight, clipBottom); clipTop, clipRight, clipBottom, nodeWidth, nodeHeight); return true; } else { return false; Loading Loading @@ -401,10 +403,11 @@ public final class RenderNode { @Override public void positionChanged(long frameNumber, int left, int top, int right, int bottom, int clipLeft, int clipTop, int clipRight, int clipBottom) { int clipLeft, int clipTop, int clipRight, int clipBottom, int nodeWidth, int nodeHeight) { for (PositionUpdateListener pul : mListeners) { pul.positionChanged(frameNumber, left, top, right, bottom, clipLeft, clipTop, clipRight, clipBottom); clipRight, clipBottom, nodeWidth, nodeHeight); } } Loading libs/hwui/jni/android_graphics_RenderNode.cpp +5 −5 Original line number Diff line number Diff line Loading @@ -593,9 +593,9 @@ static void android_view_RenderNode_requestPositionUpdates(JNIEnv* env, jobject, Matrix4 transform; SkIRect clipBounds; if (enableClip) { uirenderer::Rect initialClipBounds; const auto clipFlags = props.getClippingFlags(); if (enableClip) { if (clipFlags) { props.getClippingRectForFlags(clipFlags, &initialClipBounds); } else { Loading Loading @@ -659,8 +659,8 @@ static void android_view_RenderNode_requestPositionUpdates(JNIEnv* env, jobject, static_cast<jint>(bounds.left), static_cast<jint>(bounds.top), static_cast<jint>(bounds.right), static_cast<jint>(bounds.bottom), static_cast<jint>(clipBounds.fLeft), static_cast<jint>(clipBounds.fTop), static_cast<jint>(clipBounds.fRight), static_cast<jint>(clipBounds.fBottom)); static_cast<jint>(clipBounds.fRight), static_cast<jint>(clipBounds.fBottom), static_cast<jint>(props.getWidth()), static_cast<jint>(props.getHeight())); } if (!keepListening) { env->DeleteGlobalRef(mListener); Loading Loading @@ -891,7 +891,7 @@ int register_android_view_RenderNode(JNIEnv* env) { gPositionListener.callPositionChanged = GetStaticMethodIDOrDie( env, clazz, "callPositionChanged", "(Ljava/lang/ref/WeakReference;JIIII)Z"); gPositionListener.callPositionChanged2 = GetStaticMethodIDOrDie( env, clazz, "callPositionChanged2", "(Ljava/lang/ref/WeakReference;JIIIIIIII)Z"); env, clazz, "callPositionChanged2", "(Ljava/lang/ref/WeakReference;JIIIIIIIIII)Z"); gPositionListener.callApplyStretch = GetStaticMethodIDOrDie( env, clazz, "callApplyStretch", "(Ljava/lang/ref/WeakReference;JFFFFFFFFFF)Z"); gPositionListener.callPositionLost = GetStaticMethodIDOrDie( Loading tests/graphics/HwAccelerationTest/AndroidManifest.xml +19 −1 Original line number Diff line number Diff line Loading @@ -409,6 +409,24 @@ </intent-filter> </activity> <activity android:name="ScrollingZAboveSurfaceView" android:label="SurfaceView/Z-Above scrolling" android:exported="true"> <intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="com.android.test.hwui.TEST"/> </intent-filter> </activity> <activity android:name="ScrollingZAboveScaledSurfaceView" android:label="SurfaceView/Z-Above scrolling, scaled surface" android:exported="true"> <intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="com.android.test.hwui.TEST"/> </intent-filter> </activity> <activity android:name="StretchySurfaceViewActivity" android:label="SurfaceView/Stretchy Movement" android:exported="true"> Loading Loading
core/java/android/view/SurfaceControl.java +3 −3 Original line number Diff line number Diff line Loading @@ -3462,15 +3462,15 @@ public final class SurfaceControl implements Parcelable { * @return this This transaction for chaining * @hide */ public @NonNull Transaction setCrop(@NonNull SurfaceControl sc, float top, float left, float bottom, float right) { public @NonNull Transaction setCrop(@NonNull SurfaceControl sc, float left, float top, float right, float bottom) { checkPreconditions(sc); if (SurfaceControlRegistry.sCallStackDebuggingEnabled) { SurfaceControlRegistry.getProcessInstance().checkCallStackDebugging( "setCrop", this, sc, "crop={" + top + ", " + left + ", " + bottom + ", " + right + "}"); } nativeSetCrop(mNativeObject, sc.mNativeObject, top, left, bottom, right); nativeSetCrop(mNativeObject, sc.mNativeObject, left, top, right, bottom); return this; } Loading
core/java/android/view/SurfaceView.java +26 −8 Original line number Diff line number Diff line Loading @@ -40,6 +40,7 @@ import android.graphics.Matrix; import android.graphics.Paint; import android.graphics.PixelFormat; import android.graphics.Rect; import android.graphics.RectF; import android.graphics.Region; import android.graphics.RenderNode; import android.hardware.input.InputManager; Loading Loading @@ -1666,7 +1667,7 @@ public class SurfaceView extends View implements ViewRootImpl.SurfaceChangedCall } private final Rect mRTLastReportedPosition = new Rect(); private final Rect mRTLastSetCrop = new Rect(); private final RectF mRTLastSetCrop = new RectF(); private class SurfaceViewPositionUpdateListener implements RenderNode.PositionUpdateListener { private final int mRtSurfaceWidth; Loading Loading @@ -1711,16 +1712,18 @@ public class SurfaceView extends View implements ViewRootImpl.SurfaceChangedCall @Override public void positionChanged(long frameNumber, int left, int top, int right, int bottom, int clipLeft, int clipTop, int clipRight, int clipBottom) { int clipLeft, int clipTop, int clipRight, int clipBottom, int nodeWidth, int nodeHeight) { try { if (DEBUG_POSITION) { Log.d(TAG, String.format( "%d updateSurfacePosition RenderWorker, frameNr = %d, " + "position = [%d, %d, %d, %d] clip = [%d, %d, %d, %d] " + "surfaceSize = %dx%d", + "surfaceSize = %dx%d renderNodeSize = %d%d", System.identityHashCode(SurfaceView.this), frameNumber, left, top, right, bottom, clipLeft, clipTop, clipRight, clipBottom, mRtSurfaceWidth, mRtSurfaceHeight)); mRtSurfaceWidth, mRtSurfaceHeight, nodeWidth, nodeHeight)); } synchronized (mSurfaceControlLock) { if (mSurfaceControl == null) return; Loading @@ -1735,14 +1738,29 @@ public class SurfaceView extends View implements ViewRootImpl.SurfaceChangedCall mRTLastReportedPosition.top /*positionTop*/, postScaleX, postScaleY); mRTLastSetCrop.set(clipLeft, clipTop, clipRight, clipBottom); // The computed crop is in view-relative dimensions, however we need it to be // in buffer-relative dimensions. So scale the crop by the ratio between // the view's unscaled width/height (nodeWidth/Height), and the surface's // width/height // That is, if the Surface has a fixed size of 50x50, the SurfaceView is laid // out to a size of 100x100, and the SurfaceView is ultimately scaled to // 1000x1000, then we need to scale the crop by just the 2x from surface // domain to SV domain. final float surfaceToNodeScaleX = (float) mRtSurfaceWidth / (float) nodeWidth; final float surfaceToNodeScaleY = (float) mRtSurfaceHeight / (float) nodeHeight; mRTLastSetCrop.set(clipLeft * surfaceToNodeScaleX, clipTop * surfaceToNodeScaleY, clipRight * surfaceToNodeScaleX, clipBottom * surfaceToNodeScaleY); if (DEBUG_POSITION) { Log.d(TAG, String.format("Setting layer crop = [%d, %d, %d, %d] " Log.d(TAG, String.format("Setting layer crop = [%f, %f, %f, %f] " + "from scale %f, %f", mRTLastSetCrop.left, mRTLastSetCrop.top, mRTLastSetCrop.right, mRTLastSetCrop.bottom, postScaleX, postScaleY)); surfaceToNodeScaleX, surfaceToNodeScaleY)); } mPositionChangedTransaction.setCrop(mSurfaceControl, mRTLastSetCrop); mPositionChangedTransaction.setCrop(mSurfaceControl, mRTLastSetCrop.left, mRTLastSetCrop.top, mRTLastSetCrop.right, mRTLastSetCrop.bottom); if (mRTLastSetCrop.isEmpty()) { mPositionChangedTransaction.hide(mSurfaceControl); } else { Loading
graphics/java/android/graphics/RenderNode.java +8 −5 Original line number Diff line number Diff line Loading @@ -279,7 +279,8 @@ public final class RenderNode { * @hide */ default void positionChanged(long frameNumber, int left, int top, int right, int bottom, int clipLeft, int clipTop, int clipRight, int clipBottom) { int clipLeft, int clipTop, int clipRight, int clipBottom, int nodeWidth, int nodeHeight) { positionChanged(frameNumber, left, top, right, bottom); } Loading @@ -304,11 +305,12 @@ public final class RenderNode { * @hide */ static boolean callPositionChanged2(WeakReference<PositionUpdateListener> weakListener, long frameNumber, int left, int top, int right, int bottom, int clipLeft, int clipTop, int clipRight, int clipBottom) { int clipLeft, int clipTop, int clipRight, int clipBottom, int nodeWidth, int nodeHeight) { final PositionUpdateListener listener = weakListener.get(); if (listener != null) { listener.positionChanged(frameNumber, left, top, right, bottom, clipLeft, clipTop, clipRight, clipBottom); clipTop, clipRight, clipBottom, nodeWidth, nodeHeight); return true; } else { return false; Loading Loading @@ -401,10 +403,11 @@ public final class RenderNode { @Override public void positionChanged(long frameNumber, int left, int top, int right, int bottom, int clipLeft, int clipTop, int clipRight, int clipBottom) { int clipLeft, int clipTop, int clipRight, int clipBottom, int nodeWidth, int nodeHeight) { for (PositionUpdateListener pul : mListeners) { pul.positionChanged(frameNumber, left, top, right, bottom, clipLeft, clipTop, clipRight, clipBottom); clipRight, clipBottom, nodeWidth, nodeHeight); } } Loading
libs/hwui/jni/android_graphics_RenderNode.cpp +5 −5 Original line number Diff line number Diff line Loading @@ -593,9 +593,9 @@ static void android_view_RenderNode_requestPositionUpdates(JNIEnv* env, jobject, Matrix4 transform; SkIRect clipBounds; if (enableClip) { uirenderer::Rect initialClipBounds; const auto clipFlags = props.getClippingFlags(); if (enableClip) { if (clipFlags) { props.getClippingRectForFlags(clipFlags, &initialClipBounds); } else { Loading Loading @@ -659,8 +659,8 @@ static void android_view_RenderNode_requestPositionUpdates(JNIEnv* env, jobject, static_cast<jint>(bounds.left), static_cast<jint>(bounds.top), static_cast<jint>(bounds.right), static_cast<jint>(bounds.bottom), static_cast<jint>(clipBounds.fLeft), static_cast<jint>(clipBounds.fTop), static_cast<jint>(clipBounds.fRight), static_cast<jint>(clipBounds.fBottom)); static_cast<jint>(clipBounds.fRight), static_cast<jint>(clipBounds.fBottom), static_cast<jint>(props.getWidth()), static_cast<jint>(props.getHeight())); } if (!keepListening) { env->DeleteGlobalRef(mListener); Loading Loading @@ -891,7 +891,7 @@ int register_android_view_RenderNode(JNIEnv* env) { gPositionListener.callPositionChanged = GetStaticMethodIDOrDie( env, clazz, "callPositionChanged", "(Ljava/lang/ref/WeakReference;JIIII)Z"); gPositionListener.callPositionChanged2 = GetStaticMethodIDOrDie( env, clazz, "callPositionChanged2", "(Ljava/lang/ref/WeakReference;JIIIIIIII)Z"); env, clazz, "callPositionChanged2", "(Ljava/lang/ref/WeakReference;JIIIIIIIIII)Z"); gPositionListener.callApplyStretch = GetStaticMethodIDOrDie( env, clazz, "callApplyStretch", "(Ljava/lang/ref/WeakReference;JFFFFFFFFFF)Z"); gPositionListener.callPositionLost = GetStaticMethodIDOrDie( Loading
tests/graphics/HwAccelerationTest/AndroidManifest.xml +19 −1 Original line number Diff line number Diff line Loading @@ -409,6 +409,24 @@ </intent-filter> </activity> <activity android:name="ScrollingZAboveSurfaceView" android:label="SurfaceView/Z-Above scrolling" android:exported="true"> <intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="com.android.test.hwui.TEST"/> </intent-filter> </activity> <activity android:name="ScrollingZAboveScaledSurfaceView" android:label="SurfaceView/Z-Above scrolling, scaled surface" android:exported="true"> <intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="com.android.test.hwui.TEST"/> </intent-filter> </activity> <activity android:name="StretchySurfaceViewActivity" android:label="SurfaceView/Stretchy Movement" android:exported="true"> Loading