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

Commit 98365d76 authored by Jeff Brown's avatar Jeff Brown
Browse files

Refactor for multi-display support.

Split WindowManagerImpl into two parts, the WindowManager
interface implementation remains where it is but the global
communications with the window manager are now handled by
the WindowManagerGlobal class.  This change greatly simplifies
the challenge of having separate WindowManager instances
for each Context.

Removed WindowManagerImpl.getDefault().  This represents the
bulk of this change.  Most of the usages of this method were
either to perform global functions (now handled by WindowManagerGlobal)
or to obtain the default display (now handled by DisplayManager).

Explicitly associate each new window with a display and make
the Display object available to the View hierarchy.

Add stubs for some new display manager API features.

Start to split apart the concepts of display id and layer stack.
since they operate at different layers of abstraction.
While it's true that each logical display uniquely corresponds to a
surface flinger layer stack, it is not necessarily the case that
they must use the same ids.  Added Display.getLayerStack()
and started using it in places where it was relatively easy to do.

Change-Id: I29ed909114dec86807c4d3a5059c3fa0358bea61
parent 848c2dc9
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -9981,6 +9981,15 @@ package android.hardware {
package android.hardware.display {
  public final class DisplayManager {
    method public android.view.Display getDisplay(int, android.content.Context);
    method public void registerDisplayListener(android.hardware.display.DisplayManager.DisplayListener, android.os.Handler);
    method public void unregisterDisplayListener(android.hardware.display.DisplayManager.DisplayListener);
  }
  public static abstract interface DisplayManager.DisplayListener {
    method public abstract void onDisplayAdded(int);
    method public abstract void onDisplayChanged(int);
    method public abstract void onDisplayRemoved(int);
  }
}
@@ -24579,6 +24588,7 @@ package android.view {
    method public final android.content.Context getContext();
    method protected android.view.ContextMenu.ContextMenuInfo getContextMenuInfo();
    method public static int getDefaultSize(int, int);
    method public android.view.Display getDisplay();
    method public final int[] getDrawableState();
    method public android.graphics.Bitmap getDrawingCache();
    method public android.graphics.Bitmap getDrawingCache(boolean);
+6 −4
Original line number Diff line number Diff line
@@ -74,7 +74,7 @@ import android.view.ViewGroup.LayoutParams;
import android.view.ViewManager;
import android.view.Window;
import android.view.WindowManager;
import android.view.WindowManagerImpl;
import android.view.WindowManagerGlobal;
import android.view.accessibility.AccessibilityEvent;
import android.widget.AdapterView;

@@ -5018,7 +5018,9 @@ public class Activity extends ContextThemeWrapper
        mEmbeddedID = id;
        mLastNonConfigurationInstances = lastNonConfigurationInstances;

        mWindow.setWindowManager(null, mToken, mComponent.flattenToString(),
        mWindow.setWindowManager(
                (WindowManager)context.getSystemService(Context.WINDOW_SERVICE),
                mToken, mComponent.flattenToString(),
                (info.flags & ActivityInfo.FLAG_HARDWARE_ACCELERATED) != 0);
        if (mParent != null) {
            mWindow.setContainer(mParent.getWindow());
@@ -5065,7 +5067,7 @@ public class Activity extends ContextThemeWrapper
        if (mStopped) {
            mStopped = false;
            if (mToken != null && mParent == null) {
                WindowManagerImpl.getDefault().setStoppedState(mToken, false);
                WindowManagerGlobal.getInstance().setStoppedState(mToken, false);
            }

            synchronized (mManagedCursors) {
@@ -5165,7 +5167,7 @@ public class Activity extends ContextThemeWrapper
            }

            if (mToken != null && mParent == null) {
                WindowManagerImpl.getDefault().setStoppedState(mToken, true);
                WindowManagerGlobal.getInstance().setStoppedState(mToken, true);
            }
            
            mFragments.dispatchStop();
+4 −1
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Point;
import android.hardware.display.DisplayManager;
import android.os.Binder;
import android.os.Bundle;
import android.os.Debug;
@@ -366,7 +367,7 @@ public class ActivityManager {
     * (which tends to consume a lot more RAM).
     * @hide
     */
    static public boolean isHighEndGfx(Display display) {
    static public boolean isHighEndGfx() {
        MemInfoReader reader = new MemInfoReader();
        reader.readMemInfo();
        if (reader.getTotalSize() >= (512*1024*1024)) {
@@ -374,6 +375,8 @@ public class ActivityManager {
            // we can afford the overhead of graphics acceleration.
            return true;
        }

        Display display = DisplayManager.getInstance().getRealDisplay(Display.DEFAULT_DISPLAY);
        Point p = new Point();
        display.getRealSize(p);
        int pixels = p.x * p.y;
+12 −12
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ import android.database.sqlite.SQLiteDebug;
import android.database.sqlite.SQLiteDebug.DbStats;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.hardware.display.DisplayManager;
import android.net.IConnectivityManager;
import android.net.Proxy;
import android.net.ProxyProperties;
@@ -79,7 +80,7 @@ import android.view.ViewManager;
import android.view.ViewRootImpl;
import android.view.Window;
import android.view.WindowManager;
import android.view.WindowManagerImpl;
import android.view.WindowManagerGlobal;
import android.renderscript.RenderScript;

import com.android.internal.os.BinderInternal;
@@ -1055,7 +1056,7 @@ public final class ActivityThread {
        @Override
        public void dumpGfxInfo(FileDescriptor fd, String[] args) {
            dumpGraphicsInfo(fd);
            WindowManagerImpl.getDefault().dumpGfxInfo(fd);
            WindowManagerGlobal.getInstance().dumpGfxInfo(fd);
        }

        @Override
@@ -1569,7 +1570,7 @@ public final class ActivityThread {

        CompatibilityInfoHolder cih = new CompatibilityInfoHolder();
        cih.set(ci);
        Display d = WindowManagerImpl.getDefault().makeCompatible(cih).getDefaultDisplay();
        Display d = displayManager.getCompatibleDisplay(Display.DEFAULT_DISPLAY, cih);
        d.getMetrics(dm);
        //Slog.i("foo", "New metrics: w=" + metrics.widthPixels + " h="
        //        + metrics.heightPixels + " den=" + metrics.density
@@ -2641,7 +2642,7 @@ public final class ActivityThread {
            r.mPendingRemoveWindowManager.removeViewImmediate(r.mPendingRemoveWindow);
            IBinder wtoken = r.mPendingRemoveWindow.getWindowToken();
            if (wtoken != null) {
                WindowManagerImpl.getDefault().closeAll(wtoken,
                WindowManagerGlobal.getInstance().closeAll(wtoken,
                        r.activity.getClass().getName(), "Activity");
            }
        }
@@ -3176,7 +3177,7 @@ public final class ActivityThread {
            apk.mCompatibilityInfo.set(data.info);
        }
        handleConfigurationChanged(mConfiguration, data.info);
        WindowManagerImpl.getDefault().reportNewConfiguration(mConfiguration);
        WindowManagerGlobal.getInstance().reportNewConfiguration(mConfiguration);
    }

    private void deliverResults(ActivityClientRecord r, List<ResultInfo> results) {
@@ -3365,7 +3366,7 @@ public final class ActivityThread {
                    }
                }
                if (wtoken != null && r.mPendingRemoveWindow == null) {
                    WindowManagerImpl.getDefault().closeAll(wtoken,
                    WindowManagerGlobal.getInstance().closeAll(wtoken,
                            r.activity.getClass().getName(), "Activity");
                }
                r.activity.mDecor = null;
@@ -3377,7 +3378,7 @@ public final class ActivityThread {
                // by the app will leak.  Well we try to warning them a lot
                // about leaking windows, because that is a bug, so if they are
                // using this recreate facility then they get to live with leaks.
                WindowManagerImpl.getDefault().closeAll(token,
                WindowManagerGlobal.getInstance().closeAll(token,
                        r.activity.getClass().getName(), "Activity");
            }

@@ -3805,7 +3806,7 @@ public final class ActivityThread {
        }
        
        // Cleanup hardware accelerated stuff
        WindowManagerImpl.getDefault().trimLocalMemory();
        WindowManagerGlobal.getInstance().trimLocalMemory();

        freeTextLayoutCachesIfNeeded(configDiff);

@@ -3945,7 +3946,7 @@ public final class ActivityThread {
    final void handleTrimMemory(int level) {
        if (DEBUG_MEMORY_TRIM) Slog.v(TAG, "Trimming memory to level: " + level);

        final WindowManagerImpl windowManager = WindowManagerImpl.getDefault();
        final WindowManagerGlobal windowManager = WindowManagerGlobal.getInstance();
        windowManager.startTrimMemory(level);

        ArrayList<ComponentCallbacks2> callbacks;
@@ -4011,8 +4012,7 @@ public final class ActivityThread {
            // Persistent processes on low-memory devices do not get to
            // use hardware accelerated drawing, since this can add too much
            // overhead to the process.
            final Display display = WindowManagerImpl.getDefault().getDefaultDisplay();
            if (!ActivityManager.isHighEndGfx(display)) {
            if (!ActivityManager.isHighEndGfx()) {
                HardwareRenderer.disable(false);
            }
        }
+9 −2
Original line number Diff line number Diff line
@@ -95,7 +95,9 @@ import android.telephony.TelephonyManager;
import android.content.ClipboardManager;
import android.util.AndroidRuntimeException;
import android.util.Log;
import android.view.CompatibilityInfoHolder;
import android.view.ContextThemeWrapper;
import android.view.Display;
import android.view.WindowManagerImpl;
import android.view.accessibility.AccessibilityManager;
import android.view.inputmethod.InputMethodManager;
@@ -499,8 +501,8 @@ class ContextImpl extends Context {

        registerService(WINDOW_SERVICE, new ServiceFetcher() {
                public Object getService(ContextImpl ctx) {
                    return WindowManagerImpl.getDefault().makeCompatible(
                            ctx.mPackageInfo.mCompatibilityInfo);
                    return new WindowManagerImpl(ctx.getOuterContext(),
                            Display.DEFAULT_DISPLAY);
                }});

        registerService(USER_SERVICE, new ServiceFetcher() {
@@ -1609,6 +1611,11 @@ class ContextImpl extends Context {
        return mRestricted;
    }

    @Override
    public CompatibilityInfoHolder getCompatibilityInfo() {
        return mPackageInfo.mCompatibilityInfo;
    }

    private File getDataDirFile() {
        if (mPackageInfo != null) {
            return mPackageInfo.getDataDirFile();
Loading