当前位置:网站首页>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
边栏推荐
- Open source SPL eliminates tens of thousands of database intermediate tables
- 示波器探头对测量带宽的影响
- 研学旅游实践教育的开展助力文旅产业发展
- 教你自己训练的pytorch模型转caffe(一)
- Abnova blood total nucleic acid purification kit pre installed relevant instructions
- ODPS 下一个map / reduce 准备
- 解析五育融合之下的steam教育模式
- shell编程100例
- ProSci LAG-3 重组蛋白说明书
- 概率论机器学习的先验知识(上)
猜你喜欢
Make Jar, Not War
Abnova maxpab mouse derived polyclonal antibody solution
Duchefa细胞分裂素丨二氢玉米素 (DHZ)说明书
学习机器人无从下手?带你体会当下机器人热门研究方向有哪些
研学旅游实践教育的开展助力文旅产业发展
解析五育融合之下的steam教育模式
Duchefa MS medium contains vitamin instructions
Chemical properties and application instructions of prosci Lag3 antibody
Write an interface based on flask
14、Transformer--VIT TNT BETR
随机推荐
Propping of resources
2. < tag hash table, string> supplement: Sword finger offer 50 The first character DBC that appears only once
中国的软件公司为什么做不出产品?00后抛弃互联网;B站开源的高性能API网关组件|码农周刊VIP会员专属邮件周报 Vol.097
Abnova CD81 monoclonal antibody related parameters and Applications
Abnova丨CRISPR SpCas9 多克隆抗体方案
Learning notes of SAS programming and data mining business case 19
PHP反序列化+MD5碰撞
Wanglaoji pharmaceutical's public welfare activity of "caring for the most lovely people under the scorching sun" was launched in Nanjing
MySQL ifnull usage function
PHP deserialization +md5 collision
Abnova total RNA Purification Kit for cultured cells Chinese and English instructions
ts 之 属性的修饰符public、private、protect
MySQL fully parses json/ arrays
CareerCup它1.8 串移包括问题
[UE4] unrealinsight obtains the real machine performance test report
LeetCode: Distinct Subsequences [115]
获取前一天的js(时间戳转换)
NPDP如何续证?操作指南来了!
MySQL InnoDB架构原理
Duchefa p1001 plant agar Chinese and English instructions