Android P 显示流程分析(四)---界面刷新

上篇分析到SurfaceFlinger.signalRefresh()里会调用到SurfaceFlinger里的handleMessageRefresh(), 现在这里面开始涉及到图层合成了,这里面涉及的流程。

handleMessageRefresh()

void SurfaceFlinger::handleMessageRefresh() {
   
   
    mRefreshPending = false;
    nsecs_t refreshStartTime = systemTime(SYSTEM_TIME_MONOTONIC);
	//合成图像前的准备工作,设置各种状态
    preComposition(refreshStartTime);
    //重建可见区域的所有图层
    rebuildLayerStacks();
    //启动硬件图像合成
    setUpHWComposer();
    //调试信息
    doDebugFlashRegions();
    doTracing("handleRefresh");
    logLayerStats();
    //合成处理
    doComposition();
    //更新状态与下次合成时间
    postComposition(refreshStartTime);
}

上面重点的就是两块,一个setupHWComposer() 启动硬件图像合成, 另一个是doComposition()合成处理。

setUpHWComposer()

void SurfaceFlinger::setUpHWComposer() {
   
   
...
    if (CC_UNLIKELY(mGeometryInvalid)) {
   
   
        mGeometryInvalid = false;
        //遍历所有的显示设备
        for (size_t dpy=0 ; dpy<mDisplays.size() ; dpy++) {
   
   
            sp<const DisplayDevice> displayDevice(mDisplays[dpy]);
            const auto hwcId = displayDevice->getHwcDisplayId();
            if (hwcId >= 0) {
   
   
                const Vector<sp<Layer>>& currentLayers(
                        displayDevice->getVisibleLayersSortedByZ());
                //遍历当前显示设备的所有图层
                for (size_t i = 0; i < currentLayers.size(); i++) {
   
   
                    const auto& layer = currentLayers[i];
                    if (!layer->hasHwcLayer(hwcId)) {
   
   
                    	//如果没有硬件图层,则创建一个硬件图层
                        if (!layer->createHwcLayer(getBE().mHwc.get(), hwcId)) {
   
   
                            layer->forceClientComposition(hwcId);
                            continue;
                        }
                    }
					//设置图层大小,坐标
                    layer->setGeometry(displayDevice, i);
                    if (mDebugDisableHWC || mDebugRegion) {
   
   
                        layer->forceClientComposition(hwcId);
                    }
                }
            }
        }
    // Set the per-frame data
    //遍历所有显示屏
    for (size_t displayId = 0; displayId < mDisplays.size(); ++displayId) {
   
   
        auto& displayDevice = mDisplays[displayId];
        const auto hwcId = displayDevice->getHwcDisplayId();

        if (hwcId < 0) {
   
   
            continue;
        }
        //更新颜色变化
        if (mDrawingState.colorMatrixChanged) {
   
   
            displayDevice->setColorTransform(mDrawingState.colorMatrix);
            status_t result = getBE().mHwc->setColorTransform(hwcId, mDrawingState.colorMatrix);
            ALOGE_IF(result != NO_ERROR, "Failed to set color transform on "
                    "display %zd: %d", displayId, result);
        }
        //遍历当前显示屏的所有图层
        for (auto& layer : displayDevice->getVisibleLayersSortedByZ()) {
   
   
        	//设置数据存储格式
            if (layer->isHdrY410()) {
   
   
                layer->forceClientComposition(hwcId);
            } else if (
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值