The creation process of Activity's Window and WindowManager (3)

page9
Here we analyze the implementation of DisplayManager's getDisplay function:
    1 public Display getDisplay(int displayId) {
    2 synchronized (mLock) {
    3 return getOrCreateDisplayLocked(displayId, false /*assumeValid*/);
    4 }
    5 }
    Line 2( DisplayManager->getDisplay) actually uses a lock, is it not afraid of being stuck? Why should it be protected?
    Line 3 (DisplayManager->getDisplay) will call the getOrCreateDisplayLocked function. The definition of the getOrCreateDisplayLocked function is as follows:
    1 private Display getOrCreateDisplayLocked(int displayId, boolean assumeValid ) {
    2 Display display = mDisplays.get(displayId);
    3 if (display == null) {
    4 display = mGlobal.getCompatibleDisplay(displayId,
    5 mContext.getCompatibilityInfo(displayId));
    6 if (display != null) {
    7 mDisplays.put(displayId, display);
    8 }
    9 } else if (!assumeValid && !display.isValid()) {
    10 display = null ;
    11 }
    12 return display;
    13 }
    Line 2 (DisplayManager->getOrCreateDisplayLocked) will try to get it in the cache.
    Line 4 (DisplayManager->getOrCreateDisplayLocked) will call the getCompatibleDisplay function of DisplayManagerGlobal,
    where the second parameter passed in is passed It is obtained by calling the getCompatibilityInfo function of ContextImpl. The definition of the getCompatibilityInfo function is as follows:
        @Override
        public CompatibilityInfoHolder getCompatibilityInfo(int displayId) {
            return displayId == Display.DEFAULT_DISPLAY ? mPackageInfo.mCompatibilityInfo : null;
        }
    For a detailed analysis of DisplayManagerGlobal's getCompatibleDisplay function, please refer to the page10 file.
    Line 12 (DisplayManager->getOrCreateDisplayLocked) returns the Display object. The definition of the getCompatibleDisplay function of
page10 DisplayManagerGlobal is as follows: 1 public Display getCompatibleDisplay(int displayId, CompatibilityInfoHolder cih) {     2 DisplayInfo displayInfo = getDisplayInfo(displayId);     3 if (displayInfo == null) {     4 return null;     5 }






    6 return new Display(this, displayId, displayInfo, cih);
    7 }
    The second line (DisplayManagerGlobal->getCompatibleDisplay) will call the getDisplayInfo function to obtain the DisplayInfo of the current display device.
    The definition of the getDisplayInfo function is as follows:
        public DisplayInfo getDisplayInfo(int displayId) {
            try {
                synchronized (mLock) {
                    DisplayInfo info;
                    if (USE_CACHE) {
                        info = mDisplayInfoCache.get(displayId);
                        if (info != null) {
                            return info;
                        }
                    }

                    info = mDm.getDisplayInfo(displayId);
                    if (info == null) {
                        return null;
                    }

                    if (USE_CACHE) {
                        mDisplayInfoCache.put(displayId, info);
                    }
                    registerCallbackIfNeededLocked();

                    if (DEBUG) {
                        Log.d(TAG, "getDisplayInfo: displayId=" + displayId + ", info=" + info);
                    }
                    return info;
                }
            } catch (RemoteException ex) {
                Log.e(TAG, "Could not get display information from display manager.", ex);
                return null;
            }
        }
    The main logic of the getDisplayInfo function is to obtain the DisplayInfo information through the Binder through the DisplayManager service, and return the DisplayInfo object.

    Line 6 (DisplayManagerGlobal->getCompatibleDisplay) will use the DisplayInfo object just obtained to construct a Display, let's take a look at the Display's How the constructor is defined:
        public Display(DisplayManagerGlobal global,
                int displayId, DisplayInfo displayInfo /*not null*/,
                CompatibilityInfoHolder compatibilityInfo) {
            mGlobal = global;
            mDisplayId = displayId;
            mDisplayInfo = displayInfo;
            mCompatibilityInfo = compatibilityInfo;
            mIsValid = true;

            / / Cache properties that cannot change as long as the display is valid.
            mLayerStack = displayInfo.layerStack;
            mFlags = displayInfo.flags; mType
            = displayInfo.type; mAddress
            = displayInfo.address;
        }
    The constructor does nothing but initialize member variables. Implementation: public final void setContainer(Window container) {         super.setContainer(container);     }     Because PhoneWindow inherits from Window, it will call Window's setContainer function. The definition of Window's setContainer function is as follows:         public void setContainer(Window container) {             mContainer = container;             if (container != null) {                 // Embedded screens never have a title.










                mFeatures |= 1<<FEATURE_NO_TITLE;
                mLocalFeatures |= 1<<FEATURE_NO_TITLE;
                container.mHasChildren = true;
            }
        }
    The main logic of Window's setContainer function is to set container's mHasChildren to true

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326173548&siteId=291194637