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

Commit f9c21bbe authored by Chavi Weingarten's avatar Chavi Weingarten Committed by Android (Google) Code Review
Browse files

Merge "Add displayInfo to Java WindowInfosListener."

parents 772f18a1 51db10d9
Loading
Loading
Loading
Loading
+34 −1
Original line number Original line Diff line number Diff line
@@ -16,6 +16,8 @@


package android.window;
package android.window;


import android.graphics.Matrix;
import android.util.Size;
import android.view.InputWindowHandle;
import android.view.InputWindowHandle;


import libcore.util.NativeAllocationRegistry;
import libcore.util.NativeAllocationRegistry;
@@ -40,7 +42,8 @@ public abstract class WindowInfosListener {
     * @param windowHandles Reverse Z ordered array of window information that was on screen,
     * @param windowHandles Reverse Z ordered array of window information that was on screen,
     *                      where the first value is the topmost window.
     *                      where the first value is the topmost window.
     */
     */
    public abstract void onWindowInfosChanged(InputWindowHandle[] windowHandles);
    public abstract void onWindowInfosChanged(InputWindowHandle[] windowHandles,
            DisplayInfo[] displayInfos);


    /**
    /**
     * Register the WindowInfosListener.
     * Register the WindowInfosListener.
@@ -60,4 +63,34 @@ public abstract class WindowInfosListener {
    private static native void nativeRegister(long ptr);
    private static native void nativeRegister(long ptr);
    private static native void nativeUnregister(long ptr);
    private static native void nativeUnregister(long ptr);
    private static native long nativeGetFinalizer();
    private static native long nativeGetFinalizer();

    /**
     * Describes information about a display that can have windows in it.
     */
    public static final class DisplayInfo {
        public final int mDisplayId;

        /**
         * Logical display dimensions.
         */
        public final Size mLogicalSize;

        /**
         * The display transform. This takes display coordinates to logical display coordinates.
         */
        public final Matrix mTransform;

        private DisplayInfo(int displayId, int logicalWidth, int logicalHeight, Matrix transform) {
            mDisplayId = displayId;
            mLogicalSize = new Size(logicalWidth, logicalHeight);
            mTransform = transform;
        }

        @Override
        public String toString() {
            return "displayId=" + mDisplayId
                    + ", mLogicalSize=" + mLogicalSize
                    + ", mTransform=" + mTransform;
        }
    }
}
}
+35 −3
Original line number Original line Diff line number Diff line
@@ -16,8 +16,10 @@


#define LOG_TAG "WindowInfosListener"
#define LOG_TAG "WindowInfosListener"


#include <android/graphics/matrix.h>
#include <android_runtime/AndroidRuntime.h>
#include <android_runtime/AndroidRuntime.h>
#include <android_runtime/Log.h>
#include <android_runtime/Log.h>
#include <gui/DisplayInfo.h>
#include <gui/SurfaceComposerClient.h>
#include <gui/SurfaceComposerClient.h>
#include <nativehelper/JNIHelp.h>
#include <nativehelper/JNIHelp.h>
#include <utils/Log.h>
#include <utils/Log.h>
@@ -37,14 +39,30 @@ static struct {
    jmethodID onWindowInfosChanged;
    jmethodID onWindowInfosChanged;
} gListenerClassInfo;
} gListenerClassInfo;


static struct {
    jclass clazz;
    jmethodID ctor;
} gDisplayInfoClassInfo;

static jclass gInputWindowHandleClass;
static jclass gInputWindowHandleClass;


jobject fromDisplayInfo(JNIEnv* env, gui::DisplayInfo displayInfo) {
    float transformValues[9];
    for (int i = 0; i < 9; i++) {
        transformValues[i] = displayInfo.transform[i % 3][i / 3];
    }
    ScopedLocalRef<jobject> matrixObj(env, AMatrix_newInstance(env, transformValues));
    return env->NewObject(gDisplayInfoClassInfo.clazz, gDisplayInfoClassInfo.ctor,
                          displayInfo.displayId, displayInfo.logicalWidth,
                          displayInfo.logicalHeight, matrixObj.get());
}

struct WindowInfosListener : public gui::WindowInfosListener {
struct WindowInfosListener : public gui::WindowInfosListener {
    WindowInfosListener(JNIEnv* env, jobject listener)
    WindowInfosListener(JNIEnv* env, jobject listener)
          : mListener(env->NewWeakGlobalRef(listener)) {}
          : mListener(env->NewWeakGlobalRef(listener)) {}


    void onWindowInfosChanged(const std::vector<WindowInfo>& windowInfos,
    void onWindowInfosChanged(const std::vector<WindowInfo>& windowInfos,
                              const std::vector<DisplayInfo>& /*displayInfos*/) override {
                              const std::vector<DisplayInfo>& displayInfos) override {
        JNIEnv* env = AndroidRuntime::getJNIEnv();
        JNIEnv* env = AndroidRuntime::getJNIEnv();
        LOG_ALWAYS_FATAL_IF(env == nullptr, "Unable to retrieve JNIEnv in onWindowInfoChanged.");
        LOG_ALWAYS_FATAL_IF(env == nullptr, "Unable to retrieve JNIEnv in onWindowInfoChanged.");


@@ -64,7 +82,15 @@ struct WindowInfosListener : public gui::WindowInfosListener {
            env->SetObjectArrayElement(jWindowHandlesArray, i, jWindowHandle.get());
            env->SetObjectArrayElement(jWindowHandlesArray, i, jWindowHandle.get());
        }
        }


        env->CallVoidMethod(listener, gListenerClassInfo.onWindowInfosChanged, jWindowHandlesArray);
        jobjectArray jDisplayInfoArray =
                env->NewObjectArray(displayInfos.size(), gDisplayInfoClassInfo.clazz, nullptr);
        for (int i = 0; i < displayInfos.size(); i++) {
            ScopedLocalRef<jobject> jDisplayInfo(env, fromDisplayInfo(env, displayInfos[i]));
            env->SetObjectArrayElement(jDisplayInfoArray, i, jDisplayInfo.get());
        }

        env->CallVoidMethod(listener, gListenerClassInfo.onWindowInfosChanged, jWindowHandlesArray,
                            jDisplayInfoArray);
        env->DeleteGlobalRef(listener);
        env->DeleteGlobalRef(listener);


        if (env->ExceptionCheck()) {
        if (env->ExceptionCheck()) {
@@ -126,10 +152,16 @@ int register_android_window_WindowInfosListener(JNIEnv* env) {
    gListenerClassInfo.clazz = MakeGlobalRefOrDie(env, clazz);
    gListenerClassInfo.clazz = MakeGlobalRefOrDie(env, clazz);
    gListenerClassInfo.onWindowInfosChanged =
    gListenerClassInfo.onWindowInfosChanged =
            env->GetMethodID(gListenerClassInfo.clazz, "onWindowInfosChanged",
            env->GetMethodID(gListenerClassInfo.clazz, "onWindowInfosChanged",
                             "([Landroid/view/InputWindowHandle;)V");
                             "([Landroid/view/InputWindowHandle;[Landroid/window/"
                             "WindowInfosListener$DisplayInfo;)V");


    clazz = env->FindClass("android/view/InputWindowHandle");
    clazz = env->FindClass("android/view/InputWindowHandle");
    gInputWindowHandleClass = MakeGlobalRefOrDie(env, clazz);
    gInputWindowHandleClass = MakeGlobalRefOrDie(env, clazz);

    clazz = env->FindClass("android/window/WindowInfosListener$DisplayInfo");
    gDisplayInfoClassInfo.clazz = MakeGlobalRefOrDie(env, clazz);
    gDisplayInfoClassInfo.ctor = env->GetMethodID(gDisplayInfoClassInfo.clazz, "<init>",
                                                  "(IIILandroid/graphics/Matrix;)V");
    return 0;
    return 0;
}
}