Android R WindowManagerService模块(3) Window的relayout过程

// 根据flag是否发生变化做出对应响应,略…

}

// 根据应用请求设置宽高,获取窗口缩放比例
win.setWindowScale(win.mRequestedWidth, win.mRequestedHeight);
// 窗口此时的可见状态
final int oldVisibility = win.mViewVisibility;
// 窗口是否要由不可见状态转变为可见状态
final boolean becameVisible =
(oldVisibility == View.INVISIBLE || oldVisibility == View.GONE)
&& viewVisibility == View.VISIBLE;
// 是否需要移除IME窗口
boolean imMayMove = (flagChanges & (FLAG_ALT_FOCUSABLE_IM | FLAG_NOT_FOCUSABLE)) != 0
|| becameVisible;
// 确定是否需要更新focus状态,第一次执行relayout时,mRelayoutCalled为false
boolean focusMayChange = win.mViewVisibility != viewVisibility
|| ((flagChanges & FLAG_NOT_FOCUSABLE) != 0)
|| (!win.mRelayoutCalled);
// 如果窗口可见性发生变化,且该窗口允许显示在壁纸之上,则对壁纸窗口进行处理
boolean wallpaperMayMove = win.mViewVisibility != viewVisibility
&& (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0;
wallpaperMayMove |= (flagChanges & FLAG_SHOW_WALLPAPER) != 0;

win.mRelayoutCalled = true; // 设置WindowState#mRelayoutCalled为true
win.mInRelayout = true; // 设置WindowState#mInRelayout为true,表示在relayout过程中,relayout完毕后,重置为false
// 更新窗口的可见性
win.setViewVisibility(viewVisibility);
// 通知DisplayContent,需要进行重新布局
win.setDisplayLayoutNeeded();
// 表示是否在等待设置Inset
win.mGivenInsetsPending = (flags & WindowManagerGlobal.RELAYOUT_INSETS_PENDING) != 0;

// 如果窗口可见,进行重新布局
final boolean shouldRelayout = viewVisibility == View.VISIBLE &&
(win.mActivityRecord == null || win.mAttrs.type == TYPE_APPLICATION_STARTING
|| win.mActivityRecord.isClientVisible());
// 执行一遍刷新操作
mWindowPlacerLocked.performSurfacePlacement(true /* force */);

// 是否需要进行relayout操作
if (shouldRelayout) {
// 布局
result = win.relayoutVisibleWindow(result, attrChanges);
try {
// 创建Surface
result = createSurfaceControl(outSurfaceControl, outBLASTSurfaceControl,
result, win, winAnimator);
} catch (Exception e) {
return 0;
}
// 如果是第一次relayout操作,需要focusMayChange
if ((result & WindowManagerGlobal.RELAYOUT_RES_FIRST_TIME) != 0) {
focusMayChange = true;
}
// 输入法窗口的特殊处理
if (win.mAttrs.type == TYPE_INPUT_METHOD
&& displayContent.mInputMethodWindow == null) {
displayContent.setInputMethodWindowLocked(win);
imMayMove = true;
}
} else {

}
// 更新FocusWindow
if (focusMayChange) {
if (updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /updateInputWindows/)) {
imMayMove = false;
}
}
// 是否首次更新
boolean toBeDisplayed = (result & WindowManagerGlobal.RELAYOUT_RES_FIRST_TIME) != 0;
// 更新屏幕显示方向
configChanged = displayContent.updateOrientation();
// 对壁纸窗口的特殊处理,更新偏移量

你可能感兴趣的:(程序员,面试,移动开发,android)