当前位置:网站首页>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
边栏推荐
- Who the final say whether the product is good or not? Sonar puts forward performance indicators for analysis to help you easily judge product performance and performance
- Abnova丨培养细胞总 RNA 纯化试剂盒中英文说明书
- Norgen AAV提取剂盒说明书(含特色)
- 重上吹麻滩——段芝堂创始人翟立冬游记
- Norgen AAV extractant box instructions (including features)
- 王老吉药业“关爱烈日下最可爱的人”公益活动在南京启动
- 挖财商学院给的证券账户安全吗?可以开户吗?
- Use of form text box (II) input filtering (synthetic event)
- Abbkine trakine F-actin Staining Kit (green fluorescence) scheme
- Abnova e (diii) (WNV) recombinant protein Chinese and English instructions
猜你喜欢
Abnova丨CRISPR SpCas9 多克隆抗体方案
教你自己训练的pytorch模型转caffe(一)
Return to blowing marshland -- travel notes of zhailidong, founder of duanzhitang
Mathematical analysis_ Notes_ Chapter 9: curve integral and surface integral
AI automatically generates annotation documents from code
王老吉药业“关爱烈日下最可爱的人”公益活动在南京启动
PHP反序列化+MD5碰撞
Promouvoir le développement de l'industrie culturelle et touristique par la recherche, l'apprentissage et l'enseignement pratique du tourisme
从架构上详解技术(SLB,Redis,Mysql,Kafka,Clickhouse)的各类热点问题
Abnova丨培养细胞总 RNA 纯化试剂盒中英文说明书
随机推荐
教你自己训练的pytorch模型转caffe(三)
ProSci LAG3抗体的化学性质和应用说明
获取前一天的js(时间戳转换)
Selenium element information
Duchefa丨MS培养基含维生素说明书
Popular science | does poor English affect the NPDP exam?
解读协作型机器人的日常应用功能
shell编程100例
渗透创客精神文化转化的创客教育
How to open an account online for futures? Is it safe?
研學旅遊實踐教育的開展助力文旅產業發展
中国的软件公司为什么做不出产品?00后抛弃互联网;B站开源的高性能API网关组件|码农周刊VIP会员专属邮件周报 Vol.097
Abnova丨DNA 标记高质量控制测试方案
mysql全面解析json/数组
如何让化工企业的ERP库存账目更准确
Typhoon is coming! How to prevent typhoons on construction sites!
LeetCode: Distinct Subsequences [115]
中国管理科学研究院凝聚行业专家,傅强荣获智库专家“十佳青年”称号
Implementation of redis unique ID generator
Duchefa丨D5124 MD5A 培养基中英文说明书