Android6.0 亮屏灭屏流程(DisplayPowerControler、WMS)(二)亮度设置
从这个函数开始分析,主要分析下亮度的设置流程。
[cpp] view plain copy 在CODE上查看代码片派生到我的代码片
public void tScreenState(int state) {
if (mScreenState != state) {
if (DEBUG) {
Slog.d(TAG, "tScreenState: state=" + state);
}
mScreenState = state;
mScreenReady = fal;
scheduleScreenUpdate();
}
}
scheduleScreenUpdate主要通过消息方式,最后调用到下面函数。当我们屏幕刚要点亮,这个时候mScreenBrightness为0,所以这个时候调用mPhotonicModulator.tState设置state是点亮,但是brightness是0的。
交通安全的宣传语[cpp] view plain copy 在CODE上查看代码片派生到我的代码片
private final Runnable mScreenUpdateRunnable = new Runnable() {
季节怎么读英语 @Override
public void run() {
mScreenUpdatePending = fal;
int brightness = mScreenState != Display.STATE_OFF
&& mColorFadeLevel > 0f ? mScreenBrightness : 0;
if (mPhotonicModulator.tState(mScreenState, brightness)) {
if (DEBUG) {
Slog.d(TAG, "Screen ready");
}
mScreenReady = true;
invokeCleanListenerIfNeeded();
} el {
if (DEBUG) {
Slog.d(TAG, "Screen not ready");
}
珠海海岛 }
}
};
DisplayPowerState的设置亮度状态逻辑分析
mPhotonicModulator.tState应该要PhotonicModulator的run函数结合一起看。
[cpp] view plain copy 在CODE上查看代码片派生到我的代码片
public boolean tState(int state, int backlight) {
小学班务工作计划 synchronized (mLock) {
boolean stateChanged = state != mPendingState;
boolean backlightChanged = backlight != mPendingBacklight;
if (stateChanged || backlightChanged) {
if (DEBUG) {
Slog.d(TAG, "Requesting new screen state: state="
带面字的成语 + Display.stateToString(state) + ", backlight=" + backlight);
}
mPendingState = state;
mPendingBacklight = backlight;
boolean changeInProgress = mStateChangeInProgress || mBacklightChangeInProgress;
mStateChangeInProgress = stateChanged;
mBacklightChangeInProgress = backlightChanged;
if (!changeInProgress) {
Slog.d(TAG,"notify t backlight thread run");
ifyAll();
} 小学教案
}
return !mStateChangeInProgress;
}
}
两者结合看先tState设置了状态,只有状态改变时,我们才能重新设置状态(设置到mpendingState和mPendingBacklight)。而在run函数中,当设置的状态mPendingState、mPendingBacklight和mActualState、mActualBacklight(真正设置到背光的状态、亮度)不一样时,才会调用questDisplayState设置亮度。否则状态没有改变,就会把mStateChangeInProgress 和mBacklightChangeInProgress 设置为fal,然后线程就wait住。
高中班主任工作总结而此时tState重新设置下来的话,这个时候把亮度和状态设置到mPendingState 和mPendingBacklight 。然后这时mStateChangeInProgress 和 mBacklightChangeInProgress都是fal。这样就可以调用mLock的notifyAll函数重新唤醒线程,这样就把把前面tState设置下来的mPendingState和mPendingBacklight再通过questDisplayState设置到背光设备中去。
[cpp] view plain copy 在CODE上查看代码片派生到我的代码片
@Override
public void run() {
for (;;) {
// Get pending change.
final int state;
final boolean stateChanged;
final int backlight;
final boolean backlightChanged;
synchronized (mLock) {
state = mPendingState;
stateChanged = (state != mActualState);
backlight = mPendingBacklight;
backlightChanged = (backlight != mActualBacklight);
if (!stateChanged) {
// State changed applied, notify outer class.
postScreenUpdateThreadSafe();
mStateChangeInProgress = fal;
}
if (!backlightChanged) {
mBacklightChangeInProgress = fal;
}
if (!stateChanged && !backlightChanged) {
try {
mLock.wait();
} catch (InterruptedException ex) { }
continue;
}
铂金密度 mActualState = state;
mActualBacklight = backlight;
}
// Apply pending change.
if (true) {
Slog.d(TAG, "Updating screen state: state="
+ Display.stateToString(state) + ", backlight=" + backlight);
}
questDisplayState(state, backlight);
Slog.d(TAG, "kangchen Updating screen state: state=");