• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package android.window;
18 
19 import android.graphics.Matrix;
20 import android.util.Pair;
21 import android.util.Size;
22 import android.view.InputWindowHandle;
23 
24 import libcore.util.NativeAllocationRegistry;
25 
26 /**
27  * Listener for getting {@link InputWindowHandle} updates from SurfaceFlinger.
28  * @hide
29  */
30 public abstract class WindowInfosListener {
31     private final long mNativeListener;
32 
WindowInfosListener()33     public WindowInfosListener() {
34         NativeAllocationRegistry registry = NativeAllocationRegistry.createMalloced(
35                 WindowInfosListener.class.getClassLoader(), nativeGetFinalizer());
36 
37         mNativeListener = nativeCreate(this);
38         registry.registerNativeAllocation(this, mNativeListener);
39     }
40 
41     /**
42      * Called when WindowInfos in SurfaceFlinger have changed.
43      * @param windowHandles Reverse Z ordered array of window information that was on screen,
44      *                      where the first value is the topmost window.
45      */
onWindowInfosChanged(InputWindowHandle[] windowHandles, DisplayInfo[] displayInfos)46     public abstract void onWindowInfosChanged(InputWindowHandle[] windowHandles,
47             DisplayInfo[] displayInfos);
48 
49     /**
50      * Register the WindowInfosListener.
51      *
52      * @return The cached values for InputWindowHandles and DisplayInfos. This is the last updated
53      * value that was sent from SurfaceFlinger to this particular process. If there was nothing
54      * registered previously, then the data can be empty.
55      */
register()56     public Pair<InputWindowHandle[], DisplayInfo[]> register() {
57         return nativeRegister(mNativeListener);
58     }
59 
60     /**
61      * Unregisters the WindowInfosListener.
62      */
unregister()63     public void unregister() {
64         nativeUnregister(mNativeListener);
65     }
66 
nativeCreate(WindowInfosListener thiz)67     private static native long nativeCreate(WindowInfosListener thiz);
nativeRegister(long ptr)68     private static native Pair<InputWindowHandle[], DisplayInfo[]> nativeRegister(long ptr);
nativeUnregister(long ptr)69     private static native void nativeUnregister(long ptr);
nativeGetFinalizer()70     private static native long nativeGetFinalizer();
71 
72     /**
73      * Describes information about a display that can have windows in it.
74      */
75     public static final class DisplayInfo {
76         public final int mDisplayId;
77 
78         /**
79          * Logical display dimensions.
80          */
81         public final Size mLogicalSize;
82 
83         /**
84          * The display transform. This takes display coordinates to logical display coordinates.
85          */
86         public final Matrix mTransform;
87 
DisplayInfo(int displayId, int logicalWidth, int logicalHeight, Matrix transform)88         private DisplayInfo(int displayId, int logicalWidth, int logicalHeight, Matrix transform) {
89             mDisplayId = displayId;
90             mLogicalSize = new Size(logicalWidth, logicalHeight);
91             mTransform = transform;
92         }
93 
94         @Override
toString()95         public String toString() {
96             return "displayId=" + mDisplayId
97                     + ", mLogicalSize=" + mLogicalSize
98                     + ", mTransform=" + mTransform;
99         }
100     }
101 }
102