




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、Android6.0 亮屏灭屏流程(DisplayPowerControler、WMS)(二)亮度设置从这个函数开始分析,主要分析下亮度的设置流程。cpp view plain copy 在CODE上查看代码片派生到我的代码片public void setScreenState(int state) if (mScreenState != state) if (DEBUG) Slog.d(TAG, "setScreenState: state=" + state); mScreenState = state; mScreenReady = false; scheduleSc
2、reenUpdate(); scheduleScreenUpdate主要通过消息方式,最后调用到下面函数。当我们屏幕刚要点亮,这个时候mScreenBrightness为0,所以这个时候调用mPhotonicModulator.setState设置state是点亮,但是brightness是0的。cpp view plain copy 在CODE上查看代码片派生到我的代码片private final Runnable mScreenUpdateRunnable = new Runnable() Override public void run() mScreenUpdatePending =
3、false; int brightness = mScreenState != Display.STATE_OFF && mColorFadeLevel > 0f ? mScreenBrightness : 0; if (mPhotonicModulator.setState(mScreenState, brightness) if (DEBUG) Slog.d(TAG, "Screen ready"); mScreenReady = true; invokeCleanListenerIfNeeded(); else if (DEBUG) Slog.d
4、(TAG, "Screen not ready"); ; DisplayPowerState的设置亮度状态逻辑分析mPhotonicModulator.setState应该要PhotonicModulator的run函数结合一起看。cpp view plain copy 在CODE上查看代码片派生到我的代码片public boolean setState(int state, int backlight) synchronized (mLock) boolean stateChanged = state != mPendingState; boolean backlight
5、Changed = 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
6、 = mStateChangeInProgress | mBacklightChangeInProgress; mStateChangeInProgress = stateChanged; mBacklightChangeInProgress = backlightChanged; if (!changeInProgress) Slog.d(TAG,"notify set backlight thread run"); mLock.notifyAll(); return !mStateChangeInProgress; 两者结合看先setState设置了状态,只有状态改变时
7、,我们才能重新设置状态(设置到mpendingState和mPendingBacklight)。而在run函数中,当设置的状态mPendingState、mPendingBacklight和mActualState、mActualBacklight(真正设置到背光的状态、亮度)不一样时,才会调用mBlanker.requestDisplayState设置亮度。否则状态没有改变,就会把mStateChangeInProgress 和mBacklightChangeInProgress 设置为false,然后线程就wait住。而此时setState重新设置下来的话,这个时候把亮度和状态设置到mPe
8、ndingState 和mPendingBacklight 。然后这时mStateChangeInProgress 和 mBacklightChangeInProgress都是false。这样就可以调用mLock的notifyAll函数重新唤醒线程,这样就把把前面setState设置下来的mPendingState和mPendingBacklight再通过mBlanker.requestDisplayState设置到背光设备中去。cpp view plain copy 在CODE上查看代码片派生到我的代码片Override public void run() for (;) / Get pen
9、ding 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) / S
10、tate changed applied, notify outer class. postScreenUpdateThreadSafe(); mStateChangeInProgress = false; if (!backlightChanged) mBacklightChangeInProgress = false; if (!stateChanged && !backlightChanged) try mLock.wait(); catch (InterruptedException ex) continue; mActualState = state; mActual
11、Backlight = backlight; / Apply pending change. if (true) Slog.d(TAG, "Updating screen state: state=" + Display.stateToString(state) + ", backlight=" + backlight); mBlanker.requestDisplayState(state, backlight); Slog.d(TAG, "kangchen Updating screen state: state="); 设置亮度
12、、状态到背光设备DisplayBlanker的requestDisplayState如下,主要调用requestGlobalDisplayStateInternal函数。cpp view plain copy 在CODE上查看代码片派生到我的代码片DisplayBlanker blanker = new DisplayBlanker() Override public void requestDisplayState(int state, int brightness) / The order of operations is important for legacy reasons. if
13、(state = Display.STATE_OFF) requestGlobalDisplayStateInternal(state, brightness); callbacks.onDisplayStateChange(state); if (state != Display.STATE_OFF) requestGlobalDisplayStateInternal(state, brightness); ; requestGlobalDisplayStateInternal函数先是对state和brightness的处理,然后把这个两个变量放在mGlobalDisplayState 和m
14、GlobalDisplayBrightness成员变量中。紧接着调用applyGlobalDisplayStateLocked函数mTempDisplayStateWorkQueue作为参数。最后再调用mTempDisplayStateWorkQueue各个成员的run函数(这里返回的是Runnable接口,这里就会设置状态和亮度到设备中去)。cpp view plain copy 在CODE上查看代码片派生到我的代码片private void requestGlobalDisplayStateInternal(int state, int brightness) if (state = Di
15、splay.STATE_UNKNOWN) state = Display.STATE_ON; if (state = Display.STATE_OFF) brightness = PowerManager.BRIGHTNESS_OFF; else if (brightness < 0) brightness = PowerManager.BRIGHTNESS_DEFAULT; else if (brightness > PowerManager.BRIGHTNESS_ON) brightness = PowerManager.BRIGHTNESS_ON; synchronized
16、 (mTempDisplayStateWorkQueue) try synchronized (mSyncRoot) if (mGlobalDisplayState = state && mGlobalDisplayBrightness = brightness) return; / no change mGlobalDisplayState = state; mGlobalDisplayBrightness = brightness; applyGlobalDisplayStateLocked(mTempDisplayStateWorkQueue); / Setting th
17、e display power state can take hundreds of milliseconds / to complete so we defer the most expensive part of the work until / after we have exited the critical section to avoid blocking other / threads for a long time. for (int i = 0; i < mTempDisplayStateWorkQueue.size(); i+) mTempDisplayStateWo
18、rkQueue.get(i).run();/设置亮度、状态到设备 finally mTempDisplayStateWorkQueue.clear(); applyGlobalDisplayStateLocked函数会遍历各个显示设备(多显示),然后调用updateDisplayStateLocked函数返回一个Runnable,最后把这个Runnable放入之前传入的mTempDisplayStateWorkQueue队列中。cpp view plain copy 在CODE上查看代码片派生到我的代码片private void applyGlobalDisplayStateLocked(Li
19、st<Runnable> workQueue) final int count = mDisplayDevices.size(); for (int i = 0; i < count; i+) DisplayDevice device = mDisplayDevices.get(i); Runnable runnable = updateDisplayStateLocked(device); if (runnable != null) workQueue.add(runnable); 那下面我们看下updateDisplayStateLocked函数,主要是调用了Displa
20、yDevice的requestDisplayStateLocked函数,当然mGlobalDisplayState和mGlobalDisplayBrightness作为参数。cpp view plain copy 在CODE上查看代码片派生到我的代码片private Runnable updateDisplayStateLocked(DisplayDevice device) / Blank or unblank the display immediately to match the state requested / by the display power controller (if
21、known). DisplayDeviceInfo info = device.getDisplayDeviceInfoLocked(); if (info.flags & DisplayDeviceInfo.FLAG_NEVER_BLANK) = 0) return device.requestDisplayStateLocked(mGlobalDisplayState, mGlobalDisplayBrightness); return null; 这里的DisplayDevice的requestDisplayStateLocked函数,是在LocalDisplayAdapter中
22、实现的,这里吧state和brightness保存在mState和mBrightness中,然后返回Runnable接口,最后在Runnable接口中设置亮度和状态。cpp view plain copy 在CODE上查看代码片派生到我的代码片public Runnable requestDisplayStateLocked(final int state, final int brightness) / Assume that the brightness is off if the display is being turned off. assert state != Display.S
23、TATE_OFF | brightness = PowerManager.BRIGHTNESS_OFF; final boolean stateChanged = (mState != state); final boolean brightnessChanged = (mBrightness != brightness) && mBacklight != null; if (stateChanged | brightnessChanged) final int displayId = mBuiltInDisplayId; final IBinder token = getDi
24、splayTokenLocked(); final int oldState = mState; if (stateChanged) mState = state;/保存state updateDeviceInfoLocked(); if (brightnessChanged) mBrightness = brightness;/保存brightness / Defer actually setting the display state until after we have exited / the critical section since it can take hundreds o
25、f milliseconds / to complete. return new Runnable() /返回Runnable Override public void run() / Exit a suspended state before making any changes. int currentState = oldState; if (Display.isSuspendedState(oldState) | oldState = Display.STATE_UNKNOWN) if (!Display.isSuspendedState(state) setDisplayState(
26、state); currentState = state; else if (state = Display.STATE_DOZE_SUSPEND | oldState = Display.STATE_DOZE_SUSPEND) setDisplayState(Display.STATE_DOZE); currentState = Display.STATE_DOZE; else return; / old state and new state is off / Apply brightness changes given that we are in a non-suspended sta
27、te. if (brightnessChanged) Slog.d(TAG, "kangchen setDisplayBrightnessbrightness1=" + brightness); setDisplayBrightness(brightness); Slog.d(TAG, "kangchen setDisplayBrightnessbrightness2=" + brightness); / Enter the final desired state, possibly suspended. if (state != currentStat
28、e) setDisplayState(state); private void setDisplayState(int state) if (DEBUG) Slog.d(TAG, "setDisplayState(" + "id=" + displayId + ", state=" + Display.stateToString(state) + ")"); try final int mode = getPowerModeForState(state); SurfaceControl.setDisplayPowe
29、rMode(token, mode);/到SurfaceControl设置状态 finally Trace.traceEnd(Trace.TRACE_TAG_POWER); private void setDisplayBrightness(int brightness) try mBacklight.setBrightness(brightness);/设置亮度 finally Trace.traceEnd(Trace.TRACE_TAG_POWER); ; return null; DisplayPowerControl设置亮度逻辑(根据VSync信号将亮度慢慢变亮)上面在DisplayP
30、owerState中仅仅是设置状态,比如刚点亮屏幕这个时候其实设置的brightness为0,我们继续分析DisplayPowerState的updatePowerState函数。在updatePowerState函数中,当设置亮度时会调用如下代码:cpp view plain copy 在CODE上查看代码片派生到我的代码片if (!mPendingScreenOff) if (state = Display.STATE_ON | state = Display.STATE_DOZE) animateScreenBrightness(brightness, slowChange ? BRIG
31、HTNESS_RAMP_RATE_SLOW : BRIGHTNESS_RAMP_RATE_FAST); else animateScreenBrightness(brightness, 0); 我们注意到这里有一个BRIGHTNESS_RAMP_RATE_SLOW 和BRIGHTNESS_RAMP_RATE_FAST(这里涉及到亮度显示原理我们后面分析),先看animateScreenBrightness函数。这里函数主要调用了mScreenBrightnessRampAnimator.animateTo函数。cpp view plain copy 在CODE上查看代码片派生到我的代码片pri
32、vate void animateScreenBrightness(int target, int rate) if (mScreenBrightnessRampAnimator.animateTo(target, rate) try mBatteryStats.noteScreenBrightness(target); catch (RemoteException ex) / same process 我们再来看mScreenBrightnessRampAnimator 对象的创建cpp view plain copy 在CODE上查看代码片派生到我的代码片mScreenBrightness
33、RampAnimator = new RampAnimator<DisplayPowerState>( mPowerState, DisplayPowerState.SCREEN_BRIGHTNESS); 我们注意一个参数是DisplayPowerState对象mPowerState,另一个参数是DisplayPowerState.SCREEN_BRIGHTNESScpp view plain copy 在CODE上查看代码片派生到我的代码片public static final IntProperty<DisplayPowerState> SCREEN_BRIGHTN
34、ESS = new IntProperty<DisplayPowerState>("screenBrightness") Override public void setValue(DisplayPowerState object, int value) object.setScreenBrightness(value); Override public Integer get(DisplayPowerState object) return object.getScreenBrightness(); ; RampAnimator的构造函数。cpp view p
35、lain copy 在CODE上查看代码片派生到我的代码片public RampAnimator(T object, IntProperty<T> property) mObject = object; mProperty = property; mChoreographer = Choreographer.getInstance(); 我们结合RampAnimator的构造函数,再来分析RampAnimator的animateTo函数。1. 当rate<=0时,这个时候,我们直接调用mProperty.setValue。就是调用DisplayPowerState的setSc
36、reenBrightness函数。这个setScreenBrightness函数我们后面分析。2. 当rate>0时,这个时候会调用postAnimationCallback函数(这个函数根据VSync信号过来,把亮度慢慢上升的一个过程),而且mAnimating置为true。cpp view plain copy 在CODE上查看代码片派生到我的代码片public boolean animateTo(int target, int rate) / Immediately jump to the target the first time. if (mFirstTime | rate &
37、lt;= 0) if (mFirstTime | target != mCurrentValue) mFirstTime = false; mRate = 0; mTargetValue = target; mCurrentValue = target; mProperty.setValue(mObject, target);/设置值 if (mAnimating) mAnimating = false; cancelAnimationCallback(); if (mListener != null) mListener.onAnimationEnd(); return true; retu
38、rn false; / Adjust the rate based on the closest target. / If a faster rate is specified, then use the new rate so that we converge / more rapidly based on he new request. / If a slower rate is specified, then use the new rate only if the current / value is somewhere in between the new and the old t
39、arget meaning that / we will be ramping in a different direction to get there. / Otherwise, continue at the previous rate. if (!mAnimating | rate > mRate | (target <= mCurrentValue && mCurrentValue <= mTargetValue) | (mTargetValue <= mCurrentValue && mCurrentValue <= t
40、arget) mRate = rate; final boolean changed = (mTargetValue != target); mTargetValue = target; / Start animating. if (!mAnimating && target != mCurrentValue) mAnimating = true; mAnimatedValue = mCurrentValue; mLastFrameTimeNanos = System.nanoTime(); postAnimationCallback(); return changed; 下面
41、我们先分析postAnimationCallback函数,这个和之前分析WMS的VSync信号类似,当VSync信号过来时,会调用mAnimationCallback函数。(可以看之前博客cpp view plain copy 在CODE上查看代码片派生到我的代码片private void postAnimationCallback() mChoreographer.postCallback(Choreographer.CALLBACK_ANIMATION, mAnimationCallback, null); 那我们继续看mAnimationCallback 的run函数,这个函数当当前值和
42、上一次值不一样,我们就调用DisplayPowerState的setScreenBrightness来设置亮度。而且当前值不是目标值,我们就继续调用postAnimationCallback函数,来设置VSync回调。最后当亮度变成目标值后,将mAnimating 置为false,代表亮度变化的动画结束了。cpp view plain copy 在CODE上查看代码片派生到我的代码片private final Runnable mAnimationCallback = new Runnable() Override / Choreographer callback public void un
43、() final long frameTimeNanos = mChoreographer.getFrameTimeNanos(); final float timeDelta = (frameTimeNanos - mLastFrameTimeNanos) * 0.000000001f; mLastFrameTimeNanos = frameTimeNanos; final float scale = ValueAnimator.getDurationScale(); if (scale = 0) / Animation off. mAnimatedValue = mTargetValue; else final float amount = timeDelta * mRate / scale; if (mTargetValue > mCurrentValue) mAnimatedValue = Math.min(mAnimatedValue + amount, mTargetValue); else mAnimatedValue = Math.max(m
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 重大自然灾害中档案应急管理机制研究
- 主动脉夹层诊断与护理
- 零售行业代收货款服务条款协议
- 文化创意产业财产抵押贷款协议
- 菜园种植与城市垃圾分类回收合同
- 茶楼茶艺与茶文化主题酒店合作合同范本
- 车库租赁与停车场综合管理合同
- 拆迁安置补偿居间服务协议书
- 电视剧拍摄现场制片助理劳务合作协议
- 彩钢房仓储物流合作项目承包协议
- 基层医院护理课件
- 贵州省贵阳市2022-2023学年七年级下学期语文期末试卷(含答案)
- 法律职业伦理试题及答案
- 2025年国家公务员考录《申论》真题及参考答案(行政执法卷)
- 2024珠海农商银行社会招聘笔试历年典型考题及考点剖析附带答案详解
- 2025年公路水运工程重大事故隐患判定标准
- 综合实践:画数学连环画(大单元教学设计)一年级数学下册北师大版2025
- 车间物料员员试题及答案
- 2025国内外虚拟电厂实践经验分析及高质量发展相关建议报告-国网能源院
- 锚杆锚固质量无损检测技术规程
- 老年痴呆健康知识讲座课件
评论
0/150
提交评论