当前位置:   article > 正文

【framework】DisplayContent简介

displaycontent

1 前言

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

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

        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)类定义

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

        (2)主要属性

  1. private final int mDisplayId
  2. boolean isDefaultDisplay
  3. ActivityDisplay mAcitvityDisplay
  4. //apps (Activities) 容器
  5. private final TaskStackContainers mTaskStackContainers = new TaskStackContainers(mWmService)
  6. //顶部容器(如:Status bar 等)
  7. private final AboveAppWindowContainers mAboveAppWindowsContainers = new AboveAppWindowContainers("mAboveAppWindowsContainers", mWmService)
  8. //底部容器(如:Wallpaper、Navigation bar 等)
  9. private final NonAppWindowContainers mBelowAppWindowsContainers = new NonAppWindowContainers("mBelowAppWindowsContainers", mWmService)
  10. //输入法容器
  11. private final NonAppWindowContainers mImeWindowsContainers = new NonAppWindowContainers("mImeWindowsContainers", mWmService)
  12. final ArraySet<AppWindowToken> mOpeningApps = new ArraySet<>()
  13. final ArraySet<AppWindowToken> mClosingApps = new ArraySet<>()
  14. final ArraySet<AppWindowToken> mChangingApps = new ArraySet<>()
  15. private final HashMap<IBinder, WindowToken> mTokenMap = new HashMap()
  16. int mInitialDisplayWidth = 0
  17. int mInitialDisplayHeight = 0
  18. int mInitialDisplayDensity = 0
  19. int mBaseDisplayWidth = 0
  20. int mBaseDisplayHeight = 0
  21. int mBaseDisplayDensity = 0
  22. private final DisplayInfo mDisplayInfo = new DisplayInfo()
  23. private final Display mDisplay
  24. private final DisplayMetrics mDisplayMetrics = new DisplayMetrics()
  25. private final DisplayPolicy mDisplayPolicy
  26. private DisplayRotation mDisplayRotation
  27. DisplayFrames mDisplayFrames
  28. final DisplayMetrics mRealDisplayMetrics = new DisplayMetrics();
  29. private final DisplayMetrics mTmpDisplayMetrics = new DisplayMetrics();
  30. private final DisplayMetrics mCompatDisplayMetrics = new DisplayMetrics()
  31. float mCompatibleScreenScale
  32. private int mRotation = 0
  33. private int mLastOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
  34. private int mLastWindowForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
  35. private int mLastKeyguardForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
  36. private Rect mBaseDisplayRect = new Rect()
  37. final ArrayList<WindowToken> mExitingTokens = new ArrayList<>()
  38. final TaskTapPointerEventListener mTapDetector
  39. final DockedStackDividerController mDividerControllerLocked
  40. final PinnedStackController mPinnedStackControllerLocked
  41. WallpaperController mWallpaperController
  42. private final SurfaceSession mSession = new SurfaceSession()
  43. WindowState mCurrentFocus = null;
  44. WindowState mLastFocus = null
  45. ArrayList<WindowState> mLosingFocus = new ArrayList<>()
  46. AppWindowToken mFocusedApp = null
  47. private SurfaceControl mOverlayLayer;
  48. private SurfaceControl mWindowingLayer
  49. private InputMonitor mInputMonitor
  50. private boolean mLastHasContent
  51. WindowState mInputMethodWindow
  52. WindowState mInputMethodTarget
  53. boolean mInputMethodTargetWaitingAnim
  54. private final PointerEventDispatcher mPointerEventDispatcher
  55. private final InsetsStateController mInsetsStateController
  56. private WindowState mParentWindow
  57. private Point mLocationInParentWindow = new Point()
  58. private SurfaceControl mParentSurfaceControl
  59. private InputWindowHandle mPortalWindowHandle
  60. private final float mWindowCornerRadius

        (3)构造方法

  1. DisplayContent(Display display, WindowManagerService service, ActivityDisplay activityDisplay) {
  2. //Display相关
  3. mDisplay = display
  4. mDisplayId = display.getDisplayId()
  5. display.getDisplayInfo(mDisplayInfo)
  6. display.getMetrics(mDisplayMetrics)
  7. //壁纸
  8. mWallpaperController = new WallpaperController(mWmService, this)
  9. //输入相关(点击、触摸等)
  10. final InputChannel inputChannel = mWmService.mInputManager.monitorInput("PointerEventDispatcher" + mDisplayId, mDisplayId)
  11. mInputMonitor = new InputMonitor(service, mDisplayId)
  12. mPointerEventDispatcher = new PointerEventDispatcher(inputChannel)
  13. mTapDetector = new TaskTapPointerEventListener(mWmService, this);
  14. registerPointerEventListener(mTapDetector);
  15. registerPointerEventListener(mWmService.mMousePositionTracker)
  16. //策略
  17. mDisplayPolicy = new DisplayPolicy(service, this)
  18. mDisplayRotation = new DisplayRotation(service, this)
  19. //添加子容器
  20. super.addChild(mBelowAppWindowsContainers, null)
  21. super.addChild(mTaskStackContainers, null)
  22. super.addChild(mAboveAppWindowsContainers, null)
  23. super.addChild(mImeWindowsContainers, null)
  24. //将该对象添加到根容器中
  25. mWmService.mRoot.addChild(this, null)
  26. }

        (4)获取/注入属性

  1. //mDisplayId
  2. int getDisplayId()
  3. //mWindowCornerRadius
  4. float getWindowCornerRadius()
  5. //mTokenMap.get(binder)
  6. WindowToken getWindowToken(IBinder binder)
  7. //mDisplay
  8. public Display getDisplay()
  9. //mDisplayInfo
  10. DisplayInfo getDisplayInfo()
  11. //mDisplayMetrics
  12. DisplayMetrics getDisplayMetrics()
  13. //mDisplayPolicy
  14. DisplayPolicy getDisplayPolicy()
  15. //mInsetsStateController
  16. InsetsStateController getInsetsStateController()
  17. //mDisplayRotation
  18. public DisplayRotation getDisplayRotation()
  19. //mDisplayRotation = displayRotation
  20. void setDisplayRotation(DisplayRotation displayRotation)
  21. //mRotation
  22. int getRotation()
  23. //mRotation = newRotation
  24. //mDisplayRotation.setRotation(newRotation)
  25. void setRotation(int newRotation)
  26. //mLastOrientation
  27. int getLastOrientation()
  28. //mLastWindowForcedOrientation
  29. int getLastWindowForcedOrientation()

        (5)消费者

  1. //w 为 WindowState 类型
  2. private final Consumer<WindowState> mUpdateWindowsForAnimator = w -> {
  3. //mWmService.mWindowPlacerLocked.debugLayoutRepeats("updateWindowsAndWallpaperLocked 5", pendingLayoutChanges)
  4. }
  5. private final Consumer<WindowState> mUpdateWallpaperForAnimator = w -> {
  6. //final AnimationAdapter anim = w.mAppToken != null ? w.mAppToken.getAnimation() : w.getAnimation()
  7. //final TaskStack stack = w.getStack()
  8. //stack.setAnimationBackground(winAnimator, color)
  9. }
  10. private final Consumer<WindowState> mScheduleToastTimeout = w -> {
  11. //final Handler handler = mWmService.mH
  12. //handler.sendMessageDelayed(handler.obtainMessage(WINDOW_HIDE_TIMEOUT, w), w.mAttrs.hideTimeoutMilliseconds)
  13. }
  14. private final Consumer<WindowState> mPerformLayout = w -> {
  15. //w.resetContentChanged()
  16. //w.prelayout()
  17. //mDisplayPolicy.layoutWindowLw(w, null, mDisplayFrames)
  18. //w.updateLastInsetValues()
  19. //w.mAppToken.layoutLetterbox(w)
  20. }
  21. private final Consumer<WindowState> mPerformLayoutAttached = w -> {
  22. //w.resetContentChanged()
  23. //w.prelayout()
  24. //mDisplayPolicy.layoutWindowLw(w, w.getParentWindow(), mDisplayFrames)
  25. }
  26. private final Consumer<WindowState> mApplyPostLayoutPolicy = w -> {
  27. //mDisplayPolicy.applyPostLayoutPolicyLw(w, w.mAttrs, w.getParentWindow(), mInputMethodTarget)
  28. }
  29. private final Consumer<WindowState> mApplySurfaceChangesTransaction = w -> {
  30. //mWallpaperController.updateWallpaperVisibility()
  31. //w.handleWindowMovedIfNeeded()
  32. //w.resetContentChanged()
  33. //mWmService.mH.obtainMessage(REPORT_LOSING_FOCUS, this).sendToTarget()
  34. //w.updateResizingWindowIfNeeded()
  35. }

        其中,Consumer 类如下:

  1. public interface Consumer<T> {
  2. void accept(T t);
  3. default Consumer<T> andThen(Consumer<? super T> after) {
  4. Objects.requireNonNull(after);
  5. return (T t) -> { accept(t); after.accept(t); };
  6. }
  7. }

        (6)谓词

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

        其中,Predicate 接口如下:

  1. public interface Predicate<T> {
  2. boolean test(T t);
  3. //与运算:return (t) -> test(t) && other.test(t)
  4. default Predicate<T> and(Predicate<? super T> other)
  5. //非运算:return (t) -> !test(t)
  6. default Predicate<T> negate()
  7. //或运算:return (t) -> test(t) || other.test(t)
  8. default Predicate<T> or(Predicate<? super T> other)
  9. //判等运算:return object -> targetRef.equals(object)
  10. static <T> Predicate<T> isEqual(Object targetRef)
  11. }

        (7)函数

  1. private final ToBooleanFunction<WindowState> mFindFocusedWindow = w -> {
  2. //mTmpWindow = w
  3. }

        其中,ToBooleanFunction 接口如下: 

  1. public interface ToBooleanFunction<T> {
  2. boolean apply(T value);
  3. }

        (8)Token 相关

  1. //getWindowToken(binder).asAppWindowToken()
  2. AppWindowToken getAppWindowToken(IBinder binder)
  3. //final WindowToken token = removeWindowToken(binder)
  4. //final AppWindowToken appToken = token.asAppWindowToken()
  5. //appToken.onRemovedFromDisplay()
  6. void removeAppToken(IBinder binder)
  7. //final WindowToken token = mTokenMap.remove(binder)
  8. WindowToken removeWindowToken(IBinder binder)
  9. //addWindowToken(token.token, token)
  10. void reParentWindowToken(WindowToken token)

        (9)Orientation 相关

  1. //mDisplayRotation.respectAppRequestedOrientation()
  2. boolean handlesOrientationChangeFromDescendant()
  3. //updateOrientationFromAppTokens(false)
  4. boolean updateOrientationFromAppTokens()
  5. //updateOrientationFromAppTokens(forceUpdate)
  6. //computeScreenConfiguration(config)
  7. Configuration updateOrientationFromAppTokens(Configuration currentConfig, IBinder freezeDisplayToken, boolean forceUpdate)

        (10)Rotation 相关

  1. //updateRotationAndSendNewConfigIfNeeded()
  2. void resumeRotationLocked()
  3. //final int rotation = mDisplayRotation.rotationForOrientation(lastOrientation, oldRotation)
  4. boolean rotationNeedsUpdate()
  5. //sendNewConfiguration()
  6. boolean updateRotationAndSendNewConfigIfNeeded()
  7. //updateRotationUnchecked(false)
  8. boolean updateRotationUnchecked()
  9. //final int rotation = mDisplayRotation.rotationForOrientation(lastOrientation, oldRotation)
  10. //mWmService.mH.sendNewMessageDelayed(WindowManagerService.H.WINDOW_FREEZE_TIMEOUT, this, WINDOW_FREEZE_TIMEOUT_DURATION)
  11. //setLayoutNeeded()
  12. boolean updateRotationUnchecked(boolean forceUpdate)
  13. //mDisplayRotation.setRotation(rotation)
  14. //updateDisplayAndOrientation(getConfiguration().uiMode, null)
  15. void applyRotationLocked(final int oldRotation, final int rotation)

        (11)其他方法

  1. //mWmService.mDisplayReady && mDisplayReady
  2. boolean isReady()
  3. //mWmService.mH.obtainMessage(SEND_NEW_CONFIGURATION, this).sendToTarget()
  4. void sendNewConfiguration()
  5. //mDisplayPolicy.updateConfigurationAndScreenSizeDependentBehaviors();
  6. //mDisplayRotation.configure(width, height, shortSizeDp, longSizeDp);
  7. //mDisplayFrames.onDisplayInfoUpdated(mDisplayInfo, calculateDisplayCutoutForRotation(mDisplayInfo.rotation))
  8. void configureDisplayPolicy()
  9. //mWmService.mPolicy.adjustConfigurationLw(config, keyboardPresence, navigationPresence)
  10. void computeScreenConfiguration(Configuration config)

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号