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

Commit ee577653 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes from topic "sc_handles"

* changes:
  Remove SurfaceControl#getHandle from JAVA apis 2/2
  Remove SurfaceControl#getHandle from JAVA apis 1/2
parents 0b326518 bc9beab8
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -17,7 +17,6 @@
package android.view;

import android.graphics.Rect;
import android.os.IBinder;

import com.android.internal.util.Preconditions;

@@ -58,11 +57,12 @@ public abstract class CompositionSamplingListener {
     * Registers a sampling listener.
     */
    public static void register(CompositionSamplingListener listener,
            int displayId, IBinder stopLayer, Rect samplingArea) {
            int displayId, SurfaceControl stopLayer, Rect samplingArea) {
        Preconditions.checkArgument(displayId == Display.DEFAULT_DISPLAY,
                "default display only for now");
        nativeRegister(listener.mNativeListener, stopLayer, samplingArea.left, samplingArea.top,
                samplingArea.right, samplingArea.bottom);
        long nativeStopLayerObject = stopLayer != null ? stopLayer.mNativeObject : 0;
        nativeRegister(listener.mNativeListener, nativeStopLayerObject, samplingArea.left,
                samplingArea.top, samplingArea.right, samplingArea.bottom);
    }

    /**
@@ -84,7 +84,7 @@ public abstract class CompositionSamplingListener {

    private static native long nativeCreate(CompositionSamplingListener thiz);
    private static native void nativeDestroy(long ptr);
    private static native void nativeRegister(long ptr, IBinder stopLayer,
    private static native void nativeRegister(long ptr, long stopLayerObject,
            int samplingAreaLeft, int top, int right, int bottom);
    private static native void nativeUnregister(long ptr);
}
+3 −5
Original line number Diff line number Diff line
@@ -109,10 +109,10 @@ public final class InputWindowHandle {
     * bounds of a parent window. That is the window should receive touch events outside its
     * window but be limited to its stack bounds, such as in the case of split screen.
     */
    public WeakReference<IBinder> touchableRegionCropHandle = new WeakReference<>(null);
    public WeakReference<SurfaceControl> touchableRegionSurfaceControl = new WeakReference<>(null);

    /**
     * Replace {@link touchableRegion} with the bounds of {@link touchableRegionCropHandle}. If
     * Replace {@link touchableRegion} with the bounds of {@link touchableRegionSurfaceControl}. If
     * the handle is {@code null}, the bounds of the surface associated with this window is used
     * as the touchable region.
     */
@@ -164,8 +164,6 @@ public final class InputWindowHandle {
     * Crop the window touchable region to the bounds of the surface provided.
     */
    public void setTouchableRegionCrop(@Nullable SurfaceControl bounds) {
        if (bounds != null) {
            touchableRegionCropHandle = new WeakReference<>(bounds.getHandle());
        }
        touchableRegionSurfaceControl = new WeakReference<>(bounds);
    }
}
+25 −28
Original line number Diff line number Diff line
@@ -90,7 +90,7 @@ public final class SurfaceControl implements Parcelable {
            Rect sourceCrop, int width, int height, boolean useIdentityTransform, int rotation,
            boolean captureSecureLayers);
    private static native ScreenshotGraphicBuffer nativeCaptureLayers(IBinder displayToken,
            IBinder layerHandleToken, Rect sourceCrop, float frameScale, IBinder[] excludeLayers);
            long layerObject, Rect sourceCrop, float frameScale, long[] excludeLayerObjects);

    private static native long nativeCreateTransaction();
    private static native long nativeGetNativeTransactionFinalizer();
@@ -102,7 +102,7 @@ public final class SurfaceControl implements Parcelable {

    private static native void nativeSetLayer(long transactionObj, long nativeObject, int zorder);
    private static native void nativeSetRelativeLayer(long transactionObj, long nativeObject,
            IBinder relativeTo, int zorder);
            long relativeToObject, int zorder);
    private static native void nativeSetPosition(long transactionObj, long nativeObject,
            float x, float y);
    private static native void nativeSetGeometryAppliesWithResize(long transactionObj,
@@ -172,18 +172,17 @@ public final class SurfaceControl implements Parcelable {
    private static native void nativeSetDisplayPowerMode(
            IBinder displayToken, int mode);
    private static native void nativeDeferTransactionUntil(long transactionObj, long nativeObject,
            IBinder handle, long frame);
            long barrierObject, long frame);
    private static native void nativeDeferTransactionUntilSurface(long transactionObj,
            long nativeObject,
            long surfaceObject, long frame);
    private static native void nativeReparentChildren(long transactionObj, long nativeObject,
            IBinder handle);
            long newParentObject);
    private static native void nativeReparent(long transactionObj, long nativeObject,
            long newParentNativeObject);
    private static native void nativeSeverChildren(long transactionObj, long nativeObject);
    private static native void nativeSetOverrideScalingMode(long transactionObj, long nativeObject,
            int scalingMode);
    private static native IBinder nativeGetHandle(long nativeObject);
    private static native boolean nativeGetTransformToDisplayInverse(long nativeObject);

    private static native Display.HdrCapabilities nativeGetHdrCapabilities(IBinder displayToken);
@@ -1009,9 +1008,9 @@ public final class SurfaceControl implements Parcelable {
    /**
     * @hide
     */
    public void deferTransactionUntil(IBinder handle, long frame) {
    public void deferTransactionUntil(SurfaceControl barrier, long frame) {
        synchronized(SurfaceControl.class) {
            sGlobalTransaction.deferTransactionUntil(this, handle, frame);
            sGlobalTransaction.deferTransactionUntil(this, barrier, frame);
        }
    }

@@ -1027,9 +1026,9 @@ public final class SurfaceControl implements Parcelable {
    /**
     * @hide
     */
    public void reparentChildren(IBinder newParentHandle) {
    public void reparentChildren(SurfaceControl newParent) {
        synchronized(SurfaceControl.class) {
            sGlobalTransaction.reparentChildren(this, newParentHandle);
            sGlobalTransaction.reparentChildren(this, newParent);
        }
    }

@@ -1061,13 +1060,6 @@ public final class SurfaceControl implements Parcelable {
        }
    }

    /**
     * @hide
     */
    public IBinder getHandle() {
        return nativeGetHandle(mNativeObject);
    }

    /**
     * @hide
     */
@@ -1975,7 +1967,7 @@ public final class SurfaceControl implements Parcelable {
    /**
     * Captures a layer and its children and returns a {@link GraphicBuffer} with the content.
     *
     * @param layerHandleToken The root layer to capture.
     * @param layer            The root layer to capture.
     * @param sourceCrop       The portion of the root surface to capture; caller may pass in 'new
     *                         Rect()' or null if no cropping is desired.
     * @param frameScale       The desired scale of the returned buffer; the raw
@@ -1984,20 +1976,25 @@ public final class SurfaceControl implements Parcelable {
     * @return Returns a GraphicBuffer that contains the layer capture.
     * @hide
     */
    public static ScreenshotGraphicBuffer captureLayers(IBinder layerHandleToken, Rect sourceCrop,
    public static ScreenshotGraphicBuffer captureLayers(SurfaceControl layer, Rect sourceCrop,
            float frameScale) {
        final IBinder displayToken = SurfaceControl.getInternalDisplayToken();
        return nativeCaptureLayers(displayToken, layerHandleToken, sourceCrop, frameScale, null);
        return nativeCaptureLayers(displayToken, layer.mNativeObject, sourceCrop, frameScale, null);
    }

    /**
     * Like {@link captureLayers} but with an array of layer handles to exclude.
     * @hide
     */
    public static ScreenshotGraphicBuffer captureLayersExcluding(IBinder layerHandleToken,
            Rect sourceCrop, float frameScale, IBinder[] exclude) {
    public static ScreenshotGraphicBuffer captureLayersExcluding(SurfaceControl layer,
            Rect sourceCrop, float frameScale, SurfaceControl[] exclude) {
        final IBinder displayToken = SurfaceControl.getInternalDisplayToken();
        return nativeCaptureLayers(displayToken, layerHandleToken, sourceCrop, frameScale, exclude);
        long[] nativeExcludeObjects = new long[exclude.length];
        for (int i = 0; i < exclude.length; i++) {
            nativeExcludeObjects[i] = exclude[i].mNativeObject;
        }
        return nativeCaptureLayers(displayToken, layer.mNativeObject, sourceCrop, frameScale,
                nativeExcludeObjects);
    }

    /**
@@ -2214,8 +2211,7 @@ public final class SurfaceControl implements Parcelable {
         */
        public Transaction setRelativeLayer(SurfaceControl sc, SurfaceControl relativeTo, int z) {
            sc.checkNotReleased();
            nativeSetRelativeLayer(mNativeObject, sc.mNativeObject,
                    relativeTo.getHandle(), z);
            nativeSetRelativeLayer(mNativeObject, sc.mNativeObject, relativeTo.mNativeObject, z);
            return this;
        }

@@ -2402,13 +2398,14 @@ public final class SurfaceControl implements Parcelable {
         * @hide
         */
        @UnsupportedAppUsage
        public Transaction deferTransactionUntil(SurfaceControl sc, IBinder handle,
        public Transaction deferTransactionUntil(SurfaceControl sc, SurfaceControl barrier,
                long frameNumber) {
            if (frameNumber < 0) {
                return this;
            }
            sc.checkNotReleased();
            nativeDeferTransactionUntil(mNativeObject, sc.mNativeObject, handle, frameNumber);
            nativeDeferTransactionUntil(mNativeObject, sc.mNativeObject, barrier.mNativeObject,
                    frameNumber);
            return this;
        }

@@ -2430,9 +2427,9 @@ public final class SurfaceControl implements Parcelable {
        /**
         * @hide
         */
        public Transaction reparentChildren(SurfaceControl sc, IBinder newParentHandle) {
        public Transaction reparentChildren(SurfaceControl sc, SurfaceControl newParent) {
            sc.checkNotReleased();
            nativeReparentChildren(mNativeObject, sc.mNativeObject, newParentHandle);
            nativeReparentChildren(mNativeObject, sc.mNativeObject, newParent.mNativeObject);
            return this;
        }

+32 −16
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@
#include <utils/threads.h>

#include <android/graphics/Region.h>
#include <gui/SurfaceControl.h>
#include <ui/Region.h>

#include "android_hardware_input_InputWindowHandle.h"
@@ -32,8 +33,9 @@
namespace android {

struct WeakRefHandleField {
    jfieldID handle;
    jfieldID ctrl;
    jmethodID get;
    jfieldID mNativeObject;
};

static struct {
@@ -63,7 +65,7 @@ static struct {
    jfieldID displayId;
    jfieldID portalToDisplayId;
    jfieldID replaceTouchableRegionWithCrop;
    WeakRefHandleField touchableRegionCropHandle;
    WeakRefHandleField touchableRegionSurfaceControl;
} gInputWindowHandleClassInfo;

static Mutex gHandleMutex;
@@ -172,19 +174,27 @@ bool NativeInputWindowHandle::updateInfo() {
    mInfo.replaceTouchableRegionWithCrop = env->GetBooleanField(obj,
            gInputWindowHandleClassInfo.replaceTouchableRegionWithCrop);

    jobject handleObj = env->GetObjectField(obj,
            gInputWindowHandleClassInfo.touchableRegionCropHandle.handle);
    if (handleObj) {
    jobject weakSurfaceCtrl = env->GetObjectField(obj,
            gInputWindowHandleClassInfo.touchableRegionSurfaceControl.ctrl);
    bool touchableRegionCropHandleSet = false;
    if (weakSurfaceCtrl) {
        // Promote java weak reference.
        jobject strongHandleObj = env->CallObjectMethod(handleObj,
                gInputWindowHandleClassInfo.touchableRegionCropHandle.get);
        if (strongHandleObj) {
            mInfo.touchableRegionCropHandle = ibinderForJavaObject(env, strongHandleObj);
            env->DeleteLocalRef(strongHandleObj);
        } else {
            mInfo.touchableRegionCropHandle.clear();
        jobject strongSurfaceCtrl = env->CallObjectMethod(weakSurfaceCtrl,
                gInputWindowHandleClassInfo.touchableRegionSurfaceControl.get);
        if (strongSurfaceCtrl) {
            jlong mNativeObject = env->GetLongField(strongSurfaceCtrl,
                    gInputWindowHandleClassInfo.touchableRegionSurfaceControl.mNativeObject);
            if (mNativeObject) {
                auto ctrl = reinterpret_cast<SurfaceControl *>(mNativeObject);
                mInfo.touchableRegionCropHandle = ctrl->getHandle();
                touchableRegionCropHandleSet = true;
            }
        env->DeleteLocalRef(handleObj);
            env->DeleteLocalRef(strongSurfaceCtrl);
        }
        env->DeleteLocalRef(weakSurfaceCtrl);
    }
    if (!touchableRegionCropHandleSet) {
        mInfo.touchableRegionCropHandle.clear();
    }

    env->DeleteLocalRef(obj);
@@ -340,11 +350,17 @@ int register_android_view_InputWindowHandle(JNIEnv* env) {
    jclass weakRefClazz;
    FIND_CLASS(weakRefClazz, "java/lang/ref/Reference");

    GET_METHOD_ID(gInputWindowHandleClassInfo.touchableRegionCropHandle.get, weakRefClazz,
    GET_METHOD_ID(gInputWindowHandleClassInfo.touchableRegionSurfaceControl.get, weakRefClazz,
             "get", "()Ljava/lang/Object;")

    GET_FIELD_ID(gInputWindowHandleClassInfo.touchableRegionCropHandle.handle, clazz,
            "touchableRegionCropHandle", "Ljava/lang/ref/WeakReference;");
    GET_FIELD_ID(gInputWindowHandleClassInfo.touchableRegionSurfaceControl.ctrl, clazz,
            "touchableRegionSurfaceControl", "Ljava/lang/ref/WeakReference;");

    jclass surfaceControlClazz;
    FIND_CLASS(surfaceControlClazz, "android/view/SurfaceControl");
    GET_FIELD_ID(gInputWindowHandleClassInfo.touchableRegionSurfaceControl.mNativeObject,
        surfaceControlClazz, "mNativeObject", "J");

    return 0;
}

+4 −4
Original line number Diff line number Diff line
@@ -87,11 +87,11 @@ void nativeDestroy(JNIEnv* env, jclass clazz, jlong ptr) {
    listener->decStrong((void*)nativeCreate);
}

void nativeRegister(JNIEnv* env, jclass clazz, jlong ptr, jobject stopLayerTokenObj,
void nativeRegister(JNIEnv* env, jclass clazz, jlong ptr, jlong stopLayerObj,
        jint left, jint top, jint right, jint bottom) {
    sp<CompositionSamplingListener> listener = reinterpret_cast<CompositionSamplingListener*>(ptr);
    sp<IBinder> stopLayerHandle = ibinderForJavaObject(env, stopLayerTokenObj);

    auto stopLayer = reinterpret_cast<SurfaceControl*>(stopLayerObj);
    sp<IBinder> stopLayerHandle = stopLayer != nullptr ? stopLayer->getHandle() : nullptr;
    if (SurfaceComposerClient::addRegionSamplingListener(
            Rect(left, top, right, bottom), stopLayerHandle, listener) != OK) {
        constexpr auto error_msg = "Couldn't addRegionSamplingListener";
@@ -116,7 +116,7 @@ const JNINativeMethod gMethods[] = {
            (void*)nativeCreate },
    { "nativeDestroy", "(J)V",
            (void*)nativeDestroy },
    { "nativeRegister", "(JLandroid/os/IBinder;IIII)V",
    { "nativeRegister", "(JJIIII)V",
            (void*)nativeRegister },
    { "nativeUnregister", "(J)V",
            (void*)nativeUnregister }
Loading