首页 > 其他分享 >【framework】DisplayContent简介

【framework】DisplayContent简介

时间:2023-03-19 17:25:01浏览次数:42  
标签:int 简介 DisplayContent private framework boolean mWmService new final

1 前言

​ DisplayContent 用于管理屏幕,一块屏幕对应一个 DisplayContent 对象,虽然手机只有一个显示屏,但是可以创建多个 DisplayContent 对象,如投屏时,可以创建一个虚拟的 DisplayContent。

​ 关于其父类及祖父类的介绍,见 → WindowContainer简介ConfigurationContainer简介,其父容器的介绍见 → RootWindowContainer简介

img

​ DisplayContent 的子容器类型为 DisplayChildWindowContainer,其子类有:TaskStackContainers、AboveAppWindowContainers、NonAppWindowContainers。实现的对象有:

  • mTaskStackContainers:apps (Activities) 容器
  • mAboveAppWindowsContainers:顶部容器(如:Status bar 等)
  • mBelowAppWindowsContainers:NonAppWindowContainers 类型,底部容器(如:Wallpaper、Navigation bar 等)
  • mImeWindowsContainers:NonAppWindowContainers 类型,输入法容器

2 源码

​ 源码地址→/frameworks/base/services/core/java/com/android/server/wm/DisplayContent.java

(1)类定义

//DisplayChildWindowContainer 为子节点类型
class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowContainer> implements WindowManagerPolicy.DisplayContentInfo

(2)主要属性

private final int mDisplayId

boolean isDefaultDisplay

ActivityDisplay mAcitvityDisplay

//apps (Activities) 容器
private final TaskStackContainers mTaskStackContainers = new TaskStackContainers(mWmService)

//顶部容器(如:Status bar 等)
private final AboveAppWindowContainers mAboveAppWindowsContainers = new AboveAppWindowContainers("mAboveAppWindowsContainers", mWmService)

//底部容器(如:Wallpaper、Navigation bar 等)
private final NonAppWindowContainers mBelowAppWindowsContainers = new NonAppWindowContainers("mBelowAppWindowsContainers", mWmService)

//输入法容器
private final NonAppWindowContainers mImeWindowsContainers = new NonAppWindowContainers("mImeWindowsContainers", mWmService)

final ArraySet<AppWindowToken> mOpeningApps = new ArraySet<>()

final ArraySet<AppWindowToken> mClosingApps = new ArraySet<>()

final ArraySet<AppWindowToken> mChangingApps = new ArraySet<>()

private final HashMap<IBinder, WindowToken> mTokenMap = new HashMap()

int mInitialDisplayWidth = 0

int mInitialDisplayHeight = 0

int mInitialDisplayDensity = 0

int mBaseDisplayWidth = 0

int mBaseDisplayHeight = 0

int mBaseDisplayDensity = 0

private final DisplayInfo mDisplayInfo = new DisplayInfo()

private final Display mDisplay

private final DisplayMetrics mDisplayMetrics = new DisplayMetrics()

private final DisplayPolicy mDisplayPolicy

private DisplayRotation mDisplayRotation

DisplayFrames mDisplayFrames

final DisplayMetrics mRealDisplayMetrics = new DisplayMetrics();

private final DisplayMetrics mTmpDisplayMetrics = new DisplayMetrics();

private final DisplayMetrics mCompatDisplayMetrics = new DisplayMetrics()

float mCompatibleScreenScale

private int mRotation = 0

private int mLastOrientation = SCREEN_ORIENTATION_UNSPECIFIED;

private int mLastWindowForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED;

private int mLastKeyguardForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED;

private Rect mBaseDisplayRect = new Rect()

final ArrayList<WindowToken> mExitingTokens = new ArrayList<>()

final TaskTapPointerEventListener mTapDetector

final DockedStackDividerController mDividerControllerLocked

final PinnedStackController mPinnedStackControllerLocked

WallpaperController mWallpaperController

private final SurfaceSession mSession = new SurfaceSession()

WindowState mCurrentFocus = null;

WindowState mLastFocus = null

ArrayList<WindowState> mLosingFocus = new ArrayList<>()

AppWindowToken mFocusedApp = null

private SurfaceControl mOverlayLayer;

private SurfaceControl mWindowingLayer

private InputMonitor mInputMonitor

private boolean mLastHasContent

WindowState mInputMethodWindow

WindowState mInputMethodTarget

boolean mInputMethodTargetWaitingAnim

private final PointerEventDispatcher mPointerEventDispatcher

private final InsetsStateController mInsetsStateController

private WindowState mParentWindow

private Point mLocationInParentWindow = new Point()

private SurfaceControl mParentSurfaceControl

private InputWindowHandle mPortalWindowHandle

private final float mWindowCornerRadius

(3)构造方法

DisplayContent(Display display, WindowManagerService service, ActivityDisplay activityDisplay) {
    //Display相关
    mDisplay = display
    mDisplayId = display.getDisplayId()
    display.getDisplayInfo(mDisplayInfo)
    display.getMetrics(mDisplayMetrics)
    //壁纸
    mWallpaperController = new WallpaperController(mWmService, this)
    //输入相关(点击、触摸等)
    final InputChannel inputChannel =        mWmService.mInputManager.monitorInput("PointerEventDispatcher" + mDisplayId, mDisplayId)
    mInputMonitor = new InputMonitor(service, mDisplayId)
    mPointerEventDispatcher = new PointerEventDispatcher(inputChannel)
    mTapDetector = new TaskTapPointerEventListener(mWmService, this);
    registerPointerEventListener(mTapDetector);
    registerPointerEventListener(mWmService.mMousePositionTracker)
    //策略
    mDisplayPolicy = new DisplayPolicy(service, this)
    mDisplayRotation = new DisplayRotation(service, this)
    //添加子容器
    super.addChild(mBelowAppWindowsContainers, null)
    super.addChild(mTaskStackContainers, null)
    super.addChild(mAboveAppWindowsContainers, null)
    super.addChild(mImeWindowsContainers, null)
    //将该对象添加到根容器中
    mWmService.mRoot.addChild(this, null)
}

(4)获取/注入属性

//mDisplayId
int getDisplayId()

//mWindowCornerRadius
float getWindowCornerRadius()

//mTokenMap.get(binder)
WindowToken getWindowToken(IBinder binder)

//mDisplay
public Display getDisplay()

//mDisplayInfo
DisplayInfo getDisplayInfo()

//mDisplayMetrics
DisplayMetrics getDisplayMetrics()

//mDisplayPolicy
DisplayPolicy getDisplayPolicy()

//mInsetsStateController
InsetsStateController getInsetsStateController()

//mDisplayRotation
public DisplayRotation getDisplayRotation()

//mDisplayRotation = displayRotation
void setDisplayRotation(DisplayRotation displayRotation)

//mRotation
int getRotation()

//mRotation = newRotation
//mDisplayRotation.setRotation(newRotation)
void setRotation(int newRotation)

//mLastOrientation
int getLastOrientation()

//mLastWindowForcedOrientation
int getLastWindowForcedOrientation()

(5)消费者

//w 为 WindowState 类型
private final Consumer<WindowState> mUpdateWindowsForAnimator = w -> {
    //mWmService.mWindowPlacerLocked.debugLayoutRepeats("updateWindowsAndWallpaperLocked 5", pendingLayoutChanges)
}

private final Consumer<WindowState> mUpdateWallpaperForAnimator = w -> {
    //final AnimationAdapter anim = w.mAppToken != null ? w.mAppToken.getAnimation() : w.getAnimation()
    //final TaskStack stack = w.getStack()
    //stack.setAnimationBackground(winAnimator, color)
}

private final Consumer<WindowState> mScheduleToastTimeout = w -> {
    //final Handler handler = mWmService.mH
    //handler.sendMessageDelayed(handler.obtainMessage(WINDOW_HIDE_TIMEOUT, w), w.mAttrs.hideTimeoutMilliseconds)
}

private final Consumer<WindowState> mPerformLayout = w -> {
    //w.resetContentChanged()
    //w.prelayout()
    //mDisplayPolicy.layoutWindowLw(w, null, mDisplayFrames)
    //w.updateLastInsetValues()
    //w.mAppToken.layoutLetterbox(w)
}

private final Consumer<WindowState> mPerformLayoutAttached = w -> {
    //w.resetContentChanged()
    //w.prelayout()
    //mDisplayPolicy.layoutWindowLw(w, w.getParentWindow(), mDisplayFrames)
}

private final Consumer<WindowState> mApplyPostLayoutPolicy = w -> { 
    //mDisplayPolicy.applyPostLayoutPolicyLw(w, w.mAttrs, w.getParentWindow(), mInputMethodTarget)
}

private final Consumer<WindowState> mApplySurfaceChangesTransaction = w -> {
    //mWallpaperController.updateWallpaperVisibility()
    //w.handleWindowMovedIfNeeded()
    //w.resetContentChanged()
    //mWmService.mH.obtainMessage(REPORT_LOSING_FOCUS, this).sendToTarget()
    //w.updateResizingWindowIfNeeded()
}

​ 其中,Consumer 类如下:

public interface Consumer<T> {
    void accept(T t);
 
    default Consumer<T> andThen(Consumer<? super T> after) {
        Objects.requireNonNull(after);
        return (T t) -> { accept(t); after.accept(t); };
    }
}

(6)谓词

//w 为 WindowState 类型
private final Predicate<WindowState> mComputeImeTargetPredicate = w -> {
    //return w.canBeImeTarget()
}

​ 其中,Predicate 接口如下:

public interface Predicate<T> {
    boolean test(T t);
    
    //与运算:return (t) -> test(t) && other.test(t)
    default Predicate<T> and(Predicate<? super T> other)
    
    //非运算:return (t) -> !test(t)
    default Predicate<T> negate()
    
    //或运算:return (t) -> test(t) || other.test(t)
    default Predicate<T> or(Predicate<? super T> other)
 
    //判等运算:return object -> targetRef.equals(object)
    static <T> Predicate<T> isEqual(Object targetRef)
}

(7)函数

private final ToBooleanFunction<WindowState> mFindFocusedWindow = w -> {
    //mTmpWindow = w
}

​ 其中,ToBooleanFunction 接口如下:

public interface ToBooleanFunction<T> {
    boolean apply(T value);
}

(8)Token 相关

//getWindowToken(binder).asAppWindowToken()
AppWindowToken getAppWindowToken(IBinder binder)

//final WindowToken token = removeWindowToken(binder)
//final AppWindowToken appToken = token.asAppWindowToken()
//appToken.onRemovedFromDisplay()
void removeAppToken(IBinder binder)

//final WindowToken token = mTokenMap.remove(binder)
WindowToken removeWindowToken(IBinder binder)

//addWindowToken(token.token, token)
void reParentWindowToken(WindowToken token)

(9)Orientation 相关

//mDisplayRotation.respectAppRequestedOrientation()
boolean handlesOrientationChangeFromDescendant()

//updateOrientationFromAppTokens(false)
boolean updateOrientationFromAppTokens()

//updateOrientationFromAppTokens(forceUpdate)
//computeScreenConfiguration(config)
Configuration updateOrientationFromAppTokens(Configuration currentConfig, IBinder freezeDisplayToken, boolean forceUpdate)

(10)Rotation 相关

//updateRotationAndSendNewConfigIfNeeded()
void resumeRotationLocked()

//final int rotation = mDisplayRotation.rotationForOrientation(lastOrientation, oldRotation)
boolean rotationNeedsUpdate()

//sendNewConfiguration()
boolean updateRotationAndSendNewConfigIfNeeded()

//updateRotationUnchecked(false)
boolean updateRotationUnchecked()

//final int rotation = mDisplayRotation.rotationForOrientation(lastOrientation, oldRotation)
//mWmService.mH.sendNewMessageDelayed(WindowManagerService.H.WINDOW_FREEZE_TIMEOUT, this, WINDOW_FREEZE_TIMEOUT_DURATION)
//setLayoutNeeded()
boolean updateRotationUnchecked(boolean forceUpdate)

//mDisplayRotation.setRotation(rotation)
//updateDisplayAndOrientation(getConfiguration().uiMode, null)
void applyRotationLocked(final int oldRotation, final int rotation)

(11)其他方法

//mWmService.mDisplayReady && mDisplayReady
boolean isReady()

//mWmService.mH.obtainMessage(SEND_NEW_CONFIGURATION, this).sendToTarget()
void sendNewConfiguration()

//mDisplayPolicy.updateConfigurationAndScreenSizeDependentBehaviors();
//mDisplayRotation.configure(width, height, shortSizeDp, longSizeDp);
//mDisplayFrames.onDisplayInfoUpdated(mDisplayInfo, calculateDisplayCutoutForRotation(mDisplayInfo.rotation))
void configureDisplayPolicy()

//mWmService.mPolicy.adjustConfigurationLw(config, keyboardPresence, navigationPresence)
void computeScreenConfiguration(Configuration config)

​ 声明:本文转自【framework】DisplayContent简介

标签:int,简介,DisplayContent,private,framework,boolean,mWmService,new,final
From: https://www.cnblogs.com/zhyan8/p/17233666.html

相关文章

  • 【framework】WMS启动流程
    1前言​WMS是WindowManagerService的简称。(1)WMS主要职责窗口管理:负责启动、添加、删除窗口,管理窗口大小、层级,核心成员有:WindowContainer、RootWindowContain......
  • 【framework】View添加过程
    1前言WMS启动流程中介绍了WindowManagerService的启动流程,本文将介绍View的添加流程,按照进程分为以下2步:应用进程:介绍从WindowManagerImpl(addView方法)到Se......
  • 【framework】Activity启动流程
    1前言ATMS启动流程介绍了ActivityTaskManagerService(ATMS)的启动和初始化流程,本文将介绍Activity的启动流程。由于Activity启动流程复杂,本文按进程将其拆分为3......
  • 【framework】AMS启动流程
    1前言​AMS即ActivityManagerService,负责Activy、Service、Broadcast、ContentProvider四大组件的生命周期管理。本文主要介绍AMS的启动流程和初始化过程。AMS......
  • 【framework】ATMS启动流程
    1前言​ATMS即ActivityTaskManagerService,用于管理Activity及其容器(任务、堆栈、显示等)。ATMS在Android10中才出现,由原来的AMS(ActivityManagerService)分离......
  • 【framework】IMS启动流程
    1前言​IMS是InputManagerService的简称,主要负责输入事件管理。1.1基本概念输入设备:屏幕、电源/音量、键鼠、充电口、蓝牙、wifi等设备节点:当输入设备可用......
  • 【framework】应用进程启动流程
    1前言Activity启动流程中介绍了从点击桌面上应用快捷方式到Activity的onCreate()方法调用流程,本将介绍应用进程的启动流程。由于应用进程启动流程复杂,本文按进......
  • 【framework】InputChannel创建流程
    1前言IMS启动流程中介绍了IMS在Java层和Native层的初始化流程,以及创建NativeInputManager、InputManager、InputReader、InputDispatcher、EventHub等对象......
  • 【framework】surfaceflinger启动流程
    1前言​surfaceflinger的作用是合成来自WMS的Surface数据,并发送到显示设备。​SurfaceFlinger服务不同于AMS、WMS、IMP、PMS、DMS等服务,主要区别如下:......
  • 【RabbitMQ消息中间件】1.RabbitMQ简介
    一、什么是MQ?MQ为MessageQueue,即是“消息队列”,它是应用程序和应用程序之间的同新方法。遵循MessageQueue规则开发出来的,具有消息队列特点的产品,都可以称之为“消息中间......