当前位置:网站首页>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
边栏推荐
- Make Jar, Not War
- 当用户登录,经常会有实时的下拉框,例如,输入邮箱,将会@qq.com,@163.com,@sohu.com
- Propping of resources
- Abbkine丨TraKine F-actin染色试剂盒(绿色荧光)方案
- IC popular science article: those things about Eco
- Abnova 环孢素A单克隆抗体,及其研究工具
- 教你自己训练的pytorch模型转caffe(三)
- 基于AVFoundation实现视频录制的两种方式
- PHP deserialization +md5 collision
- Which securities is better for securities account opening? Is online account opening safe?
猜你喜欢
解析创客教育的知识迁移和分享精神
PHP deserialization +md5 collision
从架构上详解技术(SLB,Redis,Mysql,Kafka,Clickhouse)的各类热点问题
解读协作型机器人的日常应用功能
Abnova fluorescent dye 620-m streptavidin scheme
Duchefa丨MS培养基含维生素说明书
When steam education enters personalized information technology courses
Open source SPL eliminates tens of thousands of database intermediate tables
当Steam教育进入个性化信息技术课程
Abnova丨培养细胞总 RNA 纯化试剂盒中英文说明书
随机推荐
Abnova fluorescent dye 620-m streptavidin scheme
AI 从代码中自动生成注释文档
挖财商学院给的证券账户安全吗?可以开户吗?
Redis唯一ID生成器的实现
Use of thread pool
概率论机器学习的先验知识(上)
ClickHouse 复制粘贴多行sql语句报错
Duchefa MS medium contains vitamin instructions
台风来袭!建筑工地该如何防范台风!
haas506 2.0开发教程 - 阿里云ota - pac 固件升级(仅支持2.2以上版本)
获取前一天的js(时间戳转换)
ts 之 泛型
Careercup its 1.8 serial shift includes problems
实现浏览页面时校验用户是否已经完成登录的功能
CareerCup它1.8 串移包括问题
请查收.NET MAUI 的最新学习资源
Graph embedding learning notes
Abnova CD81 monoclonal antibody related parameters and Applications
Make Jar, Not War
Duchefa p1001 plant agar Chinese and English instructions