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

Commit f47a43ac authored by Chavi Weingarten's avatar Chavi Weingarten
Browse files

Use rect instead of four int frame values for WindowInfo

Test: Builds
Bug: 290795410
Change-Id: I7f6282df796af370c94b6a75094413be0768d7f2
parent 53a70ac4
Loading
Loading
Loading
Loading
+4 −10
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package android.view;
import android.annotation.IntDef;
import android.annotation.Nullable;
import android.graphics.Matrix;
import android.graphics.Rect;
import android.graphics.Region;
import android.gui.TouchOcclusionMode;
import android.os.IBinder;
@@ -103,10 +104,7 @@ public final class InputWindowHandle {
    public long dispatchingTimeoutMillis;

    // Window frame.
    public int frameLeft;
    public int frameTop;
    public int frameRight;
    public int frameBottom;
    public final Rect frame = new Rect();

    public int surfaceInset;

@@ -184,10 +182,7 @@ public final class InputWindowHandle {
        layoutParamsFlags = other.layoutParamsFlags;
        layoutParamsType = other.layoutParamsType;
        dispatchingTimeoutMillis = other.dispatchingTimeoutMillis;
        frameLeft = other.frameLeft;
        frameTop = other.frameTop;
        frameRight = other.frameRight;
        frameBottom = other.frameBottom;
        frame.set(other.frame);
        surfaceInset = other.surfaceInset;
        scaleFactor = other.scaleFactor;
        touchableRegion.set(other.touchableRegion);
@@ -209,8 +204,7 @@ public final class InputWindowHandle {
    @Override
    public String toString() {
        return new StringBuilder(name != null ? name : "")
                .append(", frame=[").append(frameLeft).append(",").append(frameTop).append(",")
                        .append(frameRight).append(",").append(frameBottom).append("]")
                .append(", frame=[").append(frame).append("]")
                .append(", touchableRegion=").append(touchableRegion)
                .append(", scaleFactor=").append(scaleFactor)
                .append(", transform=").append(transform)
+1 −3
Original line number Diff line number Diff line
@@ -161,10 +161,8 @@ public class WindowInfosListenerForTest {
    private static List<WindowInfo> buildWindowInfos(InputWindowHandle[] windowHandles) {
        var windowInfos = new ArrayList<WindowInfo>(windowHandles.length);
        for (var handle : windowHandles) {
            var bounds = new Rect(handle.frameLeft, handle.frameTop, handle.frameRight,
                    handle.frameBottom);
            windowInfos.add(new WindowInfo(handle.getWindowToken(), handle.name, handle.displayId,
                    bounds, handle.inputConfig, handle.transform));
                    handle.frame, handle.inputConfig, handle.transform));
        }
        return windowInfos;
    }
+11 −30
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@
#include "android_util_Binder.h"
#include "core_jni_helpers.h"
#include "jni.h"
#include "jni_common.h"

namespace android {

@@ -57,10 +58,7 @@ static struct {
    jfieldID layoutParamsFlags;
    jfieldID layoutParamsType;
    jfieldID dispatchingTimeoutMillis;
    jfieldID frameLeft;
    jfieldID frameTop;
    jfieldID frameRight;
    jfieldID frameBottom;
    jfieldID frame;
    jfieldID surfaceInset;
    jfieldID scaleFactor;
    jfieldID touchableRegion;
@@ -128,14 +126,11 @@ bool NativeInputWindowHandle::updateInfo() {

    mInfo.dispatchingTimeout = std::chrono::milliseconds(
            env->GetLongField(obj, gInputWindowHandleClassInfo.dispatchingTimeoutMillis));
    mInfo.frameLeft = env->GetIntField(obj,
            gInputWindowHandleClassInfo.frameLeft);
    mInfo.frameTop = env->GetIntField(obj,
            gInputWindowHandleClassInfo.frameTop);
    mInfo.frameRight = env->GetIntField(obj,
            gInputWindowHandleClassInfo.frameRight);
    mInfo.frameBottom = env->GetIntField(obj,
            gInputWindowHandleClassInfo.frameBottom);

    ScopedLocalRef<jobject> frameObj(env,
                                     env->GetObjectField(obj, gInputWindowHandleClassInfo.frame));
    mInfo.frame = JNICommon::rectFromObj(env, frameObj.get());

    mInfo.surfaceInset = env->GetIntField(obj,
            gInputWindowHandleClassInfo.surfaceInset);
    mInfo.globalScaleFactor = env->GetFloatField(obj,
@@ -283,13 +278,9 @@ jobject android_view_InputWindowHandle_fromWindowInfo(JNIEnv* env, gui::WindowIn
                      std::chrono::duration_cast<std::chrono::milliseconds>(
                              windowInfo.dispatchingTimeout)
                              .count());
    env->SetIntField(inputWindowHandle, gInputWindowHandleClassInfo.frameLeft,
                     windowInfo.frameLeft);
    env->SetIntField(inputWindowHandle, gInputWindowHandleClassInfo.frameTop, windowInfo.frameTop);
    env->SetIntField(inputWindowHandle, gInputWindowHandleClassInfo.frameRight,
                     windowInfo.frameRight);
    env->SetIntField(inputWindowHandle, gInputWindowHandleClassInfo.frameBottom,
                     windowInfo.frameBottom);
    ScopedLocalRef<jobject> rectObj(env, JNICommon::objFromRect(env, windowInfo.frame));
    env->SetObjectField(inputWindowHandle, gInputWindowHandleClassInfo.frame, rectObj.get());

    env->SetIntField(inputWindowHandle, gInputWindowHandleClassInfo.surfaceInset,
                     windowInfo.surfaceInset);
    env->SetFloatField(inputWindowHandle, gInputWindowHandleClassInfo.scaleFactor,
@@ -400,17 +391,7 @@ int register_android_view_InputWindowHandle(JNIEnv* env) {
    GET_FIELD_ID(gInputWindowHandleClassInfo.dispatchingTimeoutMillis, clazz,
                 "dispatchingTimeoutMillis", "J");

    GET_FIELD_ID(gInputWindowHandleClassInfo.frameLeft, clazz,
            "frameLeft", "I");

    GET_FIELD_ID(gInputWindowHandleClassInfo.frameTop, clazz,
            "frameTop", "I");

    GET_FIELD_ID(gInputWindowHandleClassInfo.frameRight, clazz,
            "frameRight", "I");

    GET_FIELD_ID(gInputWindowHandleClassInfo.frameBottom, clazz,
            "frameBottom", "I");
    GET_FIELD_ID(gInputWindowHandleClassInfo.frame, clazz, "frame", "Landroid/graphics/Rect;");

    GET_FIELD_ID(gInputWindowHandleClassInfo.surfaceInset, clazz,
            "surfaceInset", "I");
+9 −0
Original line number Diff line number Diff line
@@ -26,6 +26,8 @@
namespace android {

static struct {
    jclass clazz;
    jmethodID ctor;
    jfieldID bottom;
    jfieldID left;
    jfieldID right;
@@ -40,8 +42,15 @@ Rect JNICommon::rectFromObj(JNIEnv* env, jobject rectObj) {
    return Rect(left, top, right, bottom);
}

jobject JNICommon::objFromRect(JNIEnv* env, Rect rect) {
    return env->NewObject(gRectClassInfo.clazz, gRectClassInfo.ctor, rect.left, rect.top,
                          rect.right, rect.bottom);
}

int register_jni_common(JNIEnv* env) {
    jclass rectClazz = FindClassOrDie(env, "android/graphics/Rect");
    gRectClassInfo.clazz = MakeGlobalRefOrDie(env, rectClazz);
    gRectClassInfo.ctor = GetMethodIDOrDie(env, rectClazz, "<init>", "(IIII)V");
    gRectClassInfo.bottom = GetFieldIDOrDie(env, rectClazz, "bottom", "I");
    gRectClassInfo.left = GetFieldIDOrDie(env, rectClazz, "left", "I");
    gRectClassInfo.right = GetFieldIDOrDie(env, rectClazz, "right", "I");
+1 −0
Original line number Diff line number Diff line
@@ -22,5 +22,6 @@ class Rect;
class JNICommon {
public:
    static Rect rectFromObj(JNIEnv* env, jobject rectObj);
    static jobject objFromRect(JNIEnv* env, Rect rect);
};
} // namespace android
 No newline at end of file
Loading