Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

Commit

Permalink
Merge "Screen magnifier should handle window rebuilds correctly." int…
Browse files Browse the repository at this point in the history
…o jb-mr1-dev
  • Loading branch information
sganov authored and Android (Google) Code Review committed Sep 11, 2012
2 parents 85cf4a1 + 9b4125e commit 0bb4d07
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 18 deletions.
32 changes: 27 additions & 5 deletions core/java/android/view/WindowInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,15 @@ public class WindowInfo implements Parcelable {

public final Rect touchableRegion = new Rect();

public int type;
public int type = UNDEFINED;

public float compatibilityScale;
public float compatibilityScale = UNDEFINED;

public boolean visible;

public int displayId;
public int displayId = UNDEFINED;

public int layer = UNDEFINED;

private WindowInfo() {
/* do nothing - reduce visibility */
Expand All @@ -71,6 +73,7 @@ public void writeToParcel(Parcel parcel, int flags) {
parcel.writeFloat(compatibilityScale);
parcel.writeInt(visible ? 1 : 0);
parcel.writeInt(displayId);
parcel.writeInt(layer);
recycle();
}

Expand All @@ -82,6 +85,7 @@ private void initFromParcel(Parcel parcel) {
compatibilityScale = parcel.readFloat();
visible = (parcel.readInt() == 1);
displayId = parcel.readInt();
layer = parcel.readInt();
}

public static WindowInfo obtain(WindowInfo other) {
Expand All @@ -90,9 +94,10 @@ public static WindowInfo obtain(WindowInfo other) {
info.frame.set(other.frame);
info.touchableRegion.set(other.touchableRegion);
info.type = other.type;
info.displayId = other.displayId;
info.compatibilityScale = other.compatibilityScale;
info.visible = other.visible;
info.displayId = other.displayId;
info.layer = other.layer;
return info;
}

Expand Down Expand Up @@ -131,8 +136,25 @@ private void clear() {
frame.setEmpty();
touchableRegion.setEmpty();
type = UNDEFINED;
displayId = UNDEFINED;
compatibilityScale = UNDEFINED;
visible = false;
displayId = UNDEFINED;
layer = UNDEFINED;
}

@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("Window [token:").append((token != null) ? token.hashCode() : null);
builder.append(", displayId:").append(displayId);
builder.append(", type:").append(type);
builder.append(", visible:").append(visible);
builder.append(", layer:").append(layer);
builder.append(", compatibilityScale:").append(compatibilityScale);
builder.append(", frame:").append(frame);
builder.append(", touchableRegion:").append(touchableRegion);
builder.append("]");
return builder.toString();
}

/**
Expand Down
84 changes: 71 additions & 13 deletions services/java/com/android/server/accessibility/ScreenMagnifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@
import com.android.internal.os.SomeArgs;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

/**
* This class handles the screen magnification when accessibility is enabled.
Expand Down Expand Up @@ -1020,7 +1022,9 @@ private void handleOnWindowTransition(int transition, WindowInfo info) {
}
if (info.type == WindowManager.LayoutParams.TYPE_NAVIGATION_BAR
|| info.type == WindowManager.LayoutParams.TYPE_INPUT_METHOD
|| info.type == WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG) {
|| info.type == WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG
|| info.type == WindowManager.LayoutParams.TYPE_KEYGUARD
|| info.type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG) {
switch (transition) {
case WindowManagerPolicy.TRANSIT_ENTER:
case WindowManagerPolicy.TRANSIT_SHOW:
Expand Down Expand Up @@ -1473,7 +1477,9 @@ private static final class Viewport {

private final ArrayList<WindowInfo> mTempWindowInfoList = new ArrayList<WindowInfo>();

private final Rect mTempRect = new Rect();
private final Rect mTempRect1 = new Rect();
private final Rect mTempRect2 = new Rect();
private final Rect mTempRect3 = new Rect();

private final IWindowManager mWindowManagerService;
private final DisplayProvider mDisplayProvider;
Expand Down Expand Up @@ -1542,31 +1548,83 @@ public Rect evaluate(float fraction, Rect fromFrame, Rect toFrame) {
recomputeBounds(false);
}

private final Comparator<WindowInfo> mWindowInfoInverseComparator =
new Comparator<WindowInfo>() {
@Override
public int compare(WindowInfo lhs, WindowInfo rhs) {
if (lhs.layer != rhs.layer) {
return rhs.layer - lhs.layer;
}
if (lhs.touchableRegion.top != rhs.touchableRegion.top) {
return rhs.touchableRegion.top - lhs.touchableRegion.top;
}
if (lhs.touchableRegion.left != rhs.touchableRegion.left) {
return rhs.touchableRegion.left - lhs.touchableRegion.left;
}
if (lhs.touchableRegion.right != rhs.touchableRegion.right) {
return rhs.touchableRegion.right - lhs.touchableRegion.right;
}
if (lhs.touchableRegion.bottom != rhs.touchableRegion.bottom) {
return rhs.touchableRegion.bottom - lhs.touchableRegion.bottom;
}
return 0;
}
};

public void recomputeBounds(boolean animate) {
Rect frame = mTempRect;
frame.set(0, 0, mDisplayProvider.getDisplayInfo().logicalWidth,
mDisplayProvider.getDisplayInfo().logicalHeight);
Rect magnifiedFrame = mTempRect1;
magnifiedFrame.set(0, 0, 0, 0);

Rect notMagnifiedFrame = mTempRect2;
notMagnifiedFrame.set(0, 0, 0, 0);

ArrayList<WindowInfo> infos = mTempWindowInfoList;
infos.clear();
int windowCount = 0;
try {
mWindowManagerService.getVisibleWindowsForDisplay(
mDisplayProvider.getDisplay().getDisplayId(), infos);
final int windowCount = infos.size();
Collections.sort(infos, mWindowInfoInverseComparator);
windowCount = infos.size();
for (int i = 0; i < windowCount; i++) {
WindowInfo info = infos.get(i);
if (info.type == WindowManager.LayoutParams.TYPE_NAVIGATION_BAR
|| info.type == WindowManager.LayoutParams.TYPE_INPUT_METHOD
|| info.type == WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG) {
subtract(frame, info.touchableRegion);
if (info.type == WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY) {
continue;
}
if (isWindowMagnified(info.type)) {
Rect clippedFrame = mTempRect3;
clippedFrame.set(info.touchableRegion);
subtract(clippedFrame, notMagnifiedFrame);
magnifiedFrame.union(clippedFrame);
} else {
Rect clippedFrame = mTempRect3;
clippedFrame.set(info.touchableRegion);
subtract(clippedFrame, magnifiedFrame);
notMagnifiedFrame.union(clippedFrame);
}
if (magnifiedFrame.bottom >= notMagnifiedFrame.top) {
break;
}
info.recycle();
}
} catch (RemoteException re) {
/* ignore */
} finally {
infos.clear();
for (int i = windowCount - 1; i >= 0; i--) {
infos.remove(i).recycle();
}
}
resize(frame, animate);

final int displayWidth = mDisplayProvider.getDisplayInfo().logicalWidth;
final int displayHeight = mDisplayProvider.getDisplayInfo().logicalHeight;
magnifiedFrame.intersect(0, 0, displayWidth, displayHeight);

resize(magnifiedFrame, animate);
}

private boolean isWindowMagnified(int type) {
return (type != WindowManager.LayoutParams.TYPE_NAVIGATION_BAR
&& type != WindowManager.LayoutParams.TYPE_INPUT_METHOD
&& type != WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG);
}

public void rotationChanged() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3153,6 +3153,7 @@ private WindowInfo getWindowInfoForWindowStateLocked(WindowState window) {
info.compatibilityScale = window.mGlobalScale;
info.visible = window.isVisibleLw()
|| info.type == WindowManager.LayoutParams.TYPE_UNIVERSE_BACKGROUND;
info.layer = window.mLayer;
window.getTouchableRegion(mTempRegion);
mTempRegion.getBounds(info.touchableRegion);
return info;
Expand Down

0 comments on commit 0bb4d07

Please sign in to comment.