Skip to content

Commit d32460c

Browse files
author
Jeff Brown
committed
Refactor local window manager implementation.
The objective of this refactoring is to remove the reliance on WindowManager wrapper objects for compatibility mode and for managing sub-windows. Removed the WindowManager.isHardwareAccelerated() method since it is never used. Change-Id: I4840a6353121859a5e0c07d5cc307a437c595d63
1 parent 23e7c35 commit d32460c

File tree

7 files changed

+426
-494
lines changed

7 files changed

+426
-494
lines changed

core/java/android/app/ActivityThread.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
import android.util.LogPrinter;
7171
import android.util.PrintWriterPrinter;
7272
import android.util.Slog;
73+
import android.view.CompatibilityInfoHolder;
7374
import android.view.Display;
7475
import android.view.HardwareRenderer;
7576
import android.view.View;
@@ -1527,7 +1528,9 @@ DisplayMetrics getDisplayMetricsLocked(CompatibilityInfo ci, boolean forceUpdate
15271528
dm = new DisplayMetrics();
15281529
mDisplayMetrics.put(ci, dm);
15291530
}
1530-
Display d = WindowManagerImpl.getDefault(ci).getDefaultDisplay();
1531+
CompatibilityInfoHolder cih = new CompatibilityInfoHolder();
1532+
cih.set(ci);
1533+
Display d = WindowManagerImpl.getDefault().makeCompatible(cih).getDefaultDisplay();
15311534
d.getMetrics(dm);
15321535
//Slog.i("foo", "New metrics: w=" + metrics.widthPixels + " h="
15331536
// + metrics.heightPixels + " den=" + metrics.density

core/java/android/app/ContextImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,8 @@ public Object createService(ContextImpl ctx) {
489489

490490
registerService(WINDOW_SERVICE, new ServiceFetcher() {
491491
public Object getService(ContextImpl ctx) {
492-
return WindowManagerImpl.getDefault(ctx.mPackageInfo.mCompatibilityInfo);
492+
return WindowManagerImpl.getDefault().makeCompatible(
493+
ctx.mPackageInfo.mCompatibilityInfo);
493494
}});
494495
}
495496

core/java/android/view/Choreographer.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,9 @@ private Choreographer(Looper looper) {
164164
mHandler = new FrameHandler(looper);
165165
mDisplayEventReceiver = USE_VSYNC ? new FrameDisplayEventReceiver(looper) : null;
166166
mLastFrameTimeNanos = Long.MIN_VALUE;
167-
mFrameIntervalNanos = (long)(1000000000 /
168-
new Display(Display.DEFAULT_DISPLAY, null).getRefreshRate());
167+
168+
Display d = WindowManagerImpl.getDefault().getDefaultDisplay();
169+
mFrameIntervalNanos = (long)(1000000000 / d.getRefreshRate());
169170

170171
mCallbackQueues = new CallbackQueue[CALLBACK_LAST + 1];
171172
for (int i = 0; i <= CALLBACK_LAST; i++) {

core/java/android/view/Display.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -450,13 +450,5 @@ static IWindowManager getWindowManager() {
450450
private static final Object sStaticInit = new Object();
451451
private static boolean sInitialized = false;
452452
private static IWindowManager sWindowManager;
453-
454-
/**
455-
* Returns a display object which uses the metric's width/height instead.
456-
* @hide
457-
*/
458-
public static Display createCompatibleDisplay(int displayId, CompatibilityInfoHolder compat) {
459-
return new Display(displayId, compat);
460-
}
461453
}
462454

core/java/android/view/Window.java

Lines changed: 48 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import android.app.Application;
2020
import android.content.Context;
21-
import android.content.res.CompatibilityInfo;
2221
import android.content.res.Configuration;
2322
import android.content.res.TypedArray;
2423
import android.graphics.PixelFormat;
@@ -27,7 +26,6 @@
2726
import android.os.Bundle;
2827
import android.os.IBinder;
2928
import android.os.SystemProperties;
30-
import android.util.Slog;
3129
import android.view.accessibility.AccessibilityEvent;
3230

3331
/**
@@ -119,13 +117,16 @@ public abstract class Window {
119117
*/
120118
public static final int ID_ANDROID_CONTENT = com.android.internal.R.id.content;
121119

120+
private static final String PROPERTY_HARDWARE_UI = "persist.sys.ui.hw";
121+
122122
private final Context mContext;
123123

124124
private TypedArray mWindowStyle;
125125
private Callback mCallback;
126126
private WindowManager mWindowManager;
127127
private IBinder mAppToken;
128128
private String mAppName;
129+
private boolean mHardwareAccelerated;
129130
private Window mContainer;
130131
private Window mActiveChild;
131132
private boolean mIsActive = false;
@@ -471,80 +472,63 @@ public void setWindowManager(WindowManager wm, IBinder appToken, String appName,
471472
boolean hardwareAccelerated) {
472473
mAppToken = appToken;
473474
mAppName = appName;
475+
mHardwareAccelerated = hardwareAccelerated
476+
|| SystemProperties.getBoolean(PROPERTY_HARDWARE_UI, false);
474477
if (wm == null) {
475478
wm = WindowManagerImpl.getDefault();
476479
}
477-
mWindowManager = new LocalWindowManager(wm, hardwareAccelerated);
480+
mWindowManager = ((WindowManagerImpl)wm).makeLocal(this);
478481
}
479482

480-
static CompatibilityInfoHolder getCompatInfo(Context context) {
481-
Application app = (Application)context.getApplicationContext();
482-
return app != null ? app.mLoadedApk.mCompatibilityInfo : new CompatibilityInfoHolder();
483+
CompatibilityInfoHolder getCompatibilityInfo() {
484+
Application app = (Application)mContext.getApplicationContext();
485+
return app != null ? app.mLoadedApk.mCompatibilityInfo : null;
483486
}
484487

485-
private class LocalWindowManager extends WindowManagerImpl.CompatModeWrapper {
486-
private static final String PROPERTY_HARDWARE_UI = "persist.sys.ui.hw";
487-
488-
private final boolean mHardwareAccelerated;
489-
490-
LocalWindowManager(WindowManager wm, boolean hardwareAccelerated) {
491-
super(wm, getCompatInfo(mContext));
492-
mHardwareAccelerated = hardwareAccelerated ||
493-
SystemProperties.getBoolean(PROPERTY_HARDWARE_UI, false);
494-
}
495-
496-
public boolean isHardwareAccelerated() {
497-
return mHardwareAccelerated;
498-
}
499-
500-
public final void addView(View view, ViewGroup.LayoutParams params) {
501-
// Let this throw an exception on a bad params.
502-
WindowManager.LayoutParams wp = (WindowManager.LayoutParams)params;
503-
CharSequence curTitle = wp.getTitle();
504-
if (wp.type >= WindowManager.LayoutParams.FIRST_SUB_WINDOW &&
505-
wp.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
506-
if (wp.token == null) {
507-
View decor = peekDecorView();
508-
if (decor != null) {
509-
wp.token = decor.getWindowToken();
510-
}
488+
void adjustLayoutParamsForSubWindow(WindowManager.LayoutParams wp) {
489+
CharSequence curTitle = wp.getTitle();
490+
if (wp.type >= WindowManager.LayoutParams.FIRST_SUB_WINDOW &&
491+
wp.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
492+
if (wp.token == null) {
493+
View decor = peekDecorView();
494+
if (decor != null) {
495+
wp.token = decor.getWindowToken();
511496
}
512-
if (curTitle == null || curTitle.length() == 0) {
513-
String title;
514-
if (wp.type == WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA) {
515-
title="Media";
516-
} else if (wp.type == WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA_OVERLAY) {
517-
title="MediaOvr";
518-
} else if (wp.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) {
519-
title="Panel";
520-
} else if (wp.type == WindowManager.LayoutParams.TYPE_APPLICATION_SUB_PANEL) {
521-
title="SubPanel";
522-
} else if (wp.type == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG) {
523-
title="AtchDlg";
524-
} else {
525-
title=Integer.toString(wp.type);
526-
}
527-
if (mAppName != null) {
528-
title += ":" + mAppName;
529-
}
530-
wp.setTitle(title);
531-
}
532-
} else {
533-
if (wp.token == null) {
534-
wp.token = mContainer == null ? mAppToken : mContainer.mAppToken;
497+
}
498+
if (curTitle == null || curTitle.length() == 0) {
499+
String title;
500+
if (wp.type == WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA) {
501+
title="Media";
502+
} else if (wp.type == WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA_OVERLAY) {
503+
title="MediaOvr";
504+
} else if (wp.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) {
505+
title="Panel";
506+
} else if (wp.type == WindowManager.LayoutParams.TYPE_APPLICATION_SUB_PANEL) {
507+
title="SubPanel";
508+
} else if (wp.type == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG) {
509+
title="AtchDlg";
510+
} else {
511+
title=Integer.toString(wp.type);
535512
}
536-
if ((curTitle == null || curTitle.length() == 0)
537-
&& mAppName != null) {
538-
wp.setTitle(mAppName);
513+
if (mAppName != null) {
514+
title += ":" + mAppName;
539515
}
540-
}
541-
if (wp.packageName == null) {
542-
wp.packageName = mContext.getPackageName();
516+
wp.setTitle(title);
517+
}
518+
} else {
519+
if (wp.token == null) {
520+
wp.token = mContainer == null ? mAppToken : mContainer.mAppToken;
543521
}
544-
if (mHardwareAccelerated) {
545-
wp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
522+
if ((curTitle == null || curTitle.length() == 0)
523+
&& mAppName != null) {
524+
wp.setTitle(mAppName);
546525
}
547-
super.addView(view, params);
526+
}
527+
if (wp.packageName == null) {
528+
wp.packageName = mContext.getPackageName();
529+
}
530+
if (mHardwareAccelerated) {
531+
wp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
548532
}
549533
}
550534

core/java/android/view/WindowManager.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,7 @@ public BadTokenException(String name) {
6464
* @param view The view to be removed.
6565
*/
6666
public void removeViewImmediate(View view);
67-
68-
/**
69-
* Return true if this window manager is configured to request hardware
70-
* accelerated windows. This does <em>not</em> guarantee that they will
71-
* actually be accelerated, since that depends on the device supporting them.
72-
* @hide
73-
*/
74-
public boolean isHardwareAccelerated();
75-
67+
7668
public static class LayoutParams extends ViewGroup.LayoutParams
7769
implements Parcelable {
7870
/**

0 commit comments

Comments
 (0)