当前位置:网站首页>Viewrootimpl and windowmanagerservice notes
Viewrootimpl and windowmanagerservice notes
2022-07-05 20:53:00 【Full stack programmer webmaster】
Hello everyone , I meet you again , I'm the king of the whole stack , I've prepared for you today Idea Registration code .
1、 Of each form ViewRootImpl There is one. mWindowAttributes Form properties , This attribute in WindowManagerGlobal.updateViewLayout()->ViewRootImpl.setView() and WindowManagerGlobal.updateViewLayout->ViewRootImpl.setLayoutParams() Assignment in . At the same time ViewRootImpl.mWindowAttributesChanged It will also be set to true Indicates that the form properties have changed . When form properties change .surfaceChanged It will also be set to true
if (mWindowAttributesChanged) {
mWindowAttributesChanged = false;
surfaceChanged = true;
params = lp;
}
When surfaceChanged Set to true when , The following code will call
if (surfaceChanged) {
mSurfaceHolderCallback.surfaceChanged(mSurfaceHolder,
lp.format, mWidth, mHeight);
SurfaceHolder.Callback callbacks[] = mSurfaceHolder.getCallbacks();
if (callbacks != null) {
for (SurfaceHolder.Callback c : callbacks) {
c.surfaceChanged(mSurfaceHolder, lp.format,
mWidth, mHeight);
}
}
}
Call callback function , Indicates the current form Surface There are updates .
2、 stay WMS in Stackbox、TaskStack、Task、AppWindowToken The relationship between :
3、relayoutWindow() Function for visible wallpaper 、 typewriting 、activity Wait for the window to be handled as follows :
if (viewVisibility == View.VISIBLE &&
(win.mAppToken == null || !win.mAppToken.clientHidden)) {
toBeDisplayed = !win.isVisibleLw();
if (win.mExiting) {
winAnimator.cancelExitAnimationForNextAnimationLocked();
win.mExiting = false;
}
if (win.mDestroying) {
win.mDestroying = false;
mDestroySurface.remove(win);
}
if (oldVisibility == View.GONE) {
winAnimator.mEnterAnimationPending = true;
}
if (toBeDisplayed) {
if (win.isDrawnLw() && okToDisplay()) {
winAnimator.applyEnterAnimationLocked();
}
if ((win.mAttrs.flags
& WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) {
if (DEBUG_VISIBILITY) Slog.v(TAG,
"Relayout window turning screen on: " + win);
win.mTurnOnScreen = true;
}
if (win.isConfigChanged()) {
if (DEBUG_CONFIGURATION) Slog.i(TAG, "Window " + win
+ " visible with new config: " + mCurConfiguration);
outConfig.setTo(mCurConfiguration);
}
}
if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) {
// To change the format, we need to re-build the surface.
winAnimator.destroySurfaceLocked();
toBeDisplayed = true;
surfaceChanged = true;
}
try {
if (!win.mHasSurface) {
surfaceChanged = true;
}
SurfaceControl surfaceControl = winAnimator.createSurfaceLocked();
if (surfaceControl != null) {
outSurface.copyFrom(surfaceControl);
if (SHOW_TRANSACTIONS) Slog.i(TAG,
" OUT SURFACE " + outSurface + ": copied");
} else {
// For some reason there isn't a surface. Clear the
// caller's object so they see the same state.
outSurface.release();
}
} catch (Exception e) {
mInputMonitor.updateInputWindowsLw(true /*force*/);
Slog.w(TAG, "Exception thrown when creating surface for client "
+ client + " (" + win.mAttrs.getTitle() + ")",
e);
Binder.restoreCallingIdentity(origId);
return 0;
}
if (toBeDisplayed) {
focusMayChange = isDefaultDisplay;
}
if (win.mAttrs.type == TYPE_INPUT_METHOD
&& mInputMethodWindow == null) {
mInputMethodWindow = win;
imMayMove = true;
}
if (win.mAttrs.type == TYPE_BASE_APPLICATION
&& win.mAppToken != null
&& win.mAppToken.startingWindow != null) {
// Special handling of starting window over the base
// window of the app: propagate lock screen flags to it,
// to provide the correct semantics while starting.
final int mask =
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
| WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
| WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs;
sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask);
}
}
Assume that the current form is exiting (win.mExiting==true), Just call cancelExitAnimationForNextAnimationLocked() Cancel exit animation . Suppose the form is being destroyed (win.mDestroying). Just change the form from mDestroySurface Remove ,mDestroySurface What is saved in is to be destroyed surface Form . Suppose a state on the form is invisible , That is, from invisible to visible ,winAnimator.mEnterAnimationPending = true; Indicates waiting to enter the animation ;
void applyEnterAnimationLocked() {
final int transit;
if (mEnterAnimationPending) {
mEnterAnimationPending = false;
transit = WindowManagerPolicy.TRANSIT_ENTER;
} else {
transit = WindowManagerPolicy.TRANSIT_SHOW;
}
applyAnimationLocked(transit, true);
//TODO (multidisplay): Magnification is supported only for the default display.
if (mService.mDisplayMagnifier != null
&& mWin.getDisplayId() == Display.DEFAULT_DISPLAY) {
mService.mDisplayMagnifier.onWindowTransitionLocked(mWin, transit);
}
}
mEnterAnimationPending =true when . call applyAnimationLocked() The parameter passed in by the function is WindowManagerPolicy.TRANSIT_ENTER Indicates that the form enters the animation .
boolean applyAnimationLocked(int transit, boolean isEntrance) {
if (mLocalAnimating && mAnimationIsEntrance == isEntrance) {
// If we are trying to apply an animation, but already running
// an animation of the same type, then just leave that one alone.
return true;
}
// Only apply an animation if the display isn't frozen. If it is
// frozen, there is no reason to animate and it can cause strange
// artifacts when we unfreeze the display if some different animation
// is running.
if (mService.okToDisplay()) {
int anim = mPolicy.selectAnimationLw(mWin, transit);
int attr = -1;
Animation a = null;
if (anim != 0) {
a = anim != -1 ? AnimationUtils.loadAnimation(mContext, anim) : null;
} else {
switch (transit) {
case WindowManagerPolicy.TRANSIT_ENTER:
attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation;
break;
case WindowManagerPolicy.TRANSIT_EXIT:
attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation;
break;
case WindowManagerPolicy.TRANSIT_SHOW:
attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation;
break;
case WindowManagerPolicy.TRANSIT_HIDE:
attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation;
break;
}
if (attr >= 0) {
a = mService.mAppTransition.loadAnimation(mWin.mAttrs, attr);
}
}
if (WindowManagerService.DEBUG_ANIM) Slog.v(TAG,
"applyAnimation: win=" + this
+ " anim=" + anim + " attr=0x" + Integer.toHexString(attr)
+ " a=" + a
+ " transit=" + transit
+ " isEntrance=" + isEntrance + " Callers " + Debug.getCallers(3));
if (a != null) {
if (WindowManagerService.DEBUG_ANIM) {
RuntimeException e = null;
if (!WindowManagerService.HIDE_STACK_CRAWLS) {
e = new RuntimeException();
e.fillInStackTrace();
}
Slog.v(TAG, "Loaded animation " + a + " for " + this, e);
}
setAnimation(a);
mAnimationIsEntrance = isEntrance;
}
} else {
clearAnimation();
}
return mAnimation != null;
}
applyAnimationLocked() Function , For the status bar 、 The navigation bar ( Three virtual keys )selectAnimationLw() Return to the corresponding animation resources id, For general forms, return 0. For general application forms , Yes “ Window entry ” Animation 、“ Form exit ” Animation 、“ Form display ” Animation 、“ The form is hidden ” Animation . Find the corresponding form animation resources . And then call mService.mAppTransition.loadAnimation(mWin.mAttrs, attr) Load animation .
Call after loading successfully setAnimation(a) To animate the current form .mAppTransition It's a AppTransition Class object ,AppTransition Is a transition animation state management class , There is one in this class mAppTransitionState Variable . This variable is specially used to save the current transition animation state ;AppTransition Class has two functions to create animation , One is to create enlarged animation createScaleUpAnimationLocked, One is to create a zoom out animation createThumbnailAnimationLocked().
Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) {
int anim = 0;
Context context = mContext;
if (animAttr >= 0) {
AttributeCache.Entry ent = getCachedAnimations(lp);
if (ent != null) {
context = ent.context;
anim = ent.array.getResourceId(animAttr, 0);
}
}
if (anim != 0) {
return AnimationUtils.loadAnimation(context, anim);
}
return null;
}
This function calls the animation tool class AnimationUtils.loadAnimation() function . Parameters anim Animation resources id,AnimationUtils.loadAnimation() Called in createAnimationFromXml(context, parser); Static functions ,parser It's a XmlResourceParser object , Animation resources id Save in this object .createAnimationFromXml() From the name can be seen from xml The file parses out a Animation come out
private static Animation createAnimationFromXml(Context c, XmlPullParser parser,
AnimationSet parent, AttributeSet attrs) throws XmlPullParserException, IOException {
Animation anim = null;
// Make sure we are on a start tag.
int type;
int depth = parser.getDepth();
while (((type=parser.next()) != XmlPullParser.END_TAG || parser.getDepth() > depth)
&& type != XmlPullParser.END_DOCUMENT) {
if (type != XmlPullParser.START_TAG) {
continue;
}
String name = parser.getName();
if (name.equals("set")) {
anim = new AnimationSet(c, attrs);
createAnimationFromXml(c, parser, (AnimationSet)anim, attrs);
} else if (name.equals("alpha")) {
anim = new AlphaAnimation(c, attrs);
} else if (name.equals("scale")) {
anim = new ScaleAnimation(c, attrs);
} else if (name.equals("rotate")) {
anim = new RotateAnimation(c, attrs);
} else if (name.equals("translate")) {
anim = new TranslateAnimation(c, attrs);
} else {
throw new RuntimeException("Unknown animation name: " + parser.getName());
}
if (parent != null) {
parent.addAnimation(anim);
}
}
return anim;
}
while The loop follows a certain format ( Animation format ) analysis xml, According to different animations, create corresponding Animation object , Then return .
about AnimationSet Animation ( Animation combination mechanism ). Recursively call createAnimationFromXml() function , Save animations in a queue , Finally, return to the first animation . See from the source code android Provides composite animation 、 Gradient animation 、 Zoom animation 、 Rotate animation 、 Transition animation ( Moving animation effect . Picture browsing sliding effect ).
go back to applyAnimationLocked() Function . from xml The file parses a corresponding Animation after , Call again setAnimation(a)
public void setAnimation(Animation anim) {
if (localLOGV) Slog.v(TAG, "Setting animation in " + this + ": " + anim);
mAnimating = false;
mLocalAnimating = false;
mAnimation = anim;
mAnimation.restrictDuration(WindowManagerService.MAX_ANIMATION_DURATION);
mAnimation.scaleCurrentDuration(mService.mWindowAnimationScale);
// Start out animation gone if window is gone, or visible if window is visible.
mTransformation.clear();
mTransformation.setAlpha(mLastHidden ? 0 : 1); mHasLocalTransformation = true; }
This function is very easy, Set up mAnimating、mLocalAnimating by false, Take what you got in the last step Animation Object to save to WindowStateAnimator.mAnimation in .
3、WindowManagerService in Configuration Class object mCurConfiguration The current configuration information is saved in .setNewConfiguration() Responsible for updating this object .setNewConfiguration() By ActivityManagerService.updateConfigurationLocked() call .AMS call WMS Of updateConfigurationLocked() Function configuration The object is AMS Medium mConfiguration, that AMS And WMS Keep the same configuration Configuration information .
Copyright notice : This article is an original blog article , Blog , Without consent , Shall not be reproduced .
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/117641.html Link to the original text :https://javaforall.cn
边栏推荐
- Abnova CRISPR spcas9 polyclonal antibody protocol
- Maker education infiltrating the transformation of maker spirit and culture
- sql系列(基础)-第二章 限制和排序数据
- IC popular science article: those things about Eco
- CADD course learning (7) -- Simulation of target and small molecule interaction (semi flexible docking autodock)
- MySQL InnoDB架构原理
- 教你自己训练的pytorch模型转caffe(一)
- Abnova丨血液总核酸纯化试剂盒预装相关说明书
- 2.<tag-哈希表, 字符串>补充: 剑指 Offer 50. 第一个只出现一次的字符 dbc
- 当用户登录,经常会有实时的下拉框,例如,输入邮箱,将会@qq.com,@163.com,@sohu.com
猜你喜欢
Mathematical analysis_ Notes_ Chapter 9: curve integral and surface integral
Research and development efficiency improvement practice of large insurance groups with 10000 + code base and 3000 + R & D personnel
MySQL InnoDB架构原理
Duchefa MS medium contains vitamin instructions
Abnova e (diii) (WNV) recombinant protein Chinese and English instructions
phpstudy小皮的mysql点击启动后迅速闪退,已解决
解析五育融合之下的steam教育模式
Abnova DNA marker high quality control test program
请查收.NET MAUI 的最新学习资源
Analyze the knowledge transfer and sharing spirit of maker Education
随机推荐
Specification of protein quantitative kit for abbkine BCA method
How to open an account online for futures? Is it safe?
Material Design组件 - 使用BottomSheet展现扩展内容(二)
Applet page navigation
Monorepo management methodology and dependency security
haas506 2.0开发教程 - 阿里云ota - pac 固件升级(仅支持2.2以上版本)
Redis唯一ID生成器的实现
挖财商学院给的证券账户安全吗?可以开户吗?
学习机器人无从下手?带你体会当下机器人热门研究方向有哪些
Interpreting the daily application functions of cooperative robots
IC popular science article: those things about Eco
培养机器人教育创造力的前沿科技
matplotlib绘图润色(如何形成高质量的图,例如设如何置字体等)
Abnova 环孢素A单克隆抗体,及其研究工具
Use of thread pool
NPDP如何续证?操作指南来了!
Web Service简单入门示例
Duchefa丨P1001植物琼脂中英文说明书
Abnova CRISPR spcas9 polyclonal antibody protocol
Norgen AAV extractant box instructions (including features)