Cache IWindow in InputWindowHandle
Converting IBinder to IWindow is inefficient so instead cache IWindow object directly. When calling native to Java, the IWindow object may not be populated yet so we lazy cache it when getWindow is called. Test: atest WindowAddRemovePerfTest Fixes: 197219430 Change-Id: I15f7d7cd9775592a5545ddaf276c1b1db2777ac9
This commit is contained in:
@@ -49,6 +49,11 @@ public final class InputWindowHandle {
|
||||
*/
|
||||
@Nullable
|
||||
private IBinder windowToken;
|
||||
/**
|
||||
* Used to cache IWindow from the windowToken so we don't need to convert every time getWindow
|
||||
* is called.
|
||||
*/
|
||||
private IWindow window;
|
||||
|
||||
// The window name.
|
||||
public String name;
|
||||
@@ -151,7 +156,7 @@ public final class InputWindowHandle {
|
||||
.append(", visible=").append(visible)
|
||||
.append(", scaleFactor=").append(scaleFactor)
|
||||
.append(", transform=").append(transform)
|
||||
.append(", windowToken=").append(getWindow())
|
||||
.append(", windowToken=").append(windowToken)
|
||||
.toString();
|
||||
|
||||
}
|
||||
@@ -186,9 +191,14 @@ public final class InputWindowHandle {
|
||||
|
||||
public void setWindowToken(IWindow iwindow) {
|
||||
windowToken = iwindow.asBinder();
|
||||
window = iwindow;
|
||||
}
|
||||
|
||||
public IWindow getWindow() {
|
||||
return IWindow.Stub.asInterface(windowToken);
|
||||
if (window != null) {
|
||||
return window;
|
||||
}
|
||||
window = IWindow.Stub.asInterface(windowToken);
|
||||
return window;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user