renderthread是什么_RenderThread学习笔记

文章记录自己对RenderThread学习过程,供日后回顾。

我们知道5.0上为每个进程新增了一个RenderThread线程,这是一个附加的UI线程?我们通过学习这块代码来熟悉它。

第一部分:RenderThread线程的启动

RenderThread线程的启动过程如下图所示。

涉及相关的类关系如下图:

有两个注意点:①每一个窗口对应一个ViewRootImpl,每个ViewRootImpl都对应唯一的一个ThreadedRenderer、一个RootRenderNode、一个RenderProxy对象。②一个拥有窗口的进程,必然有且只有一个RenderThread子线程。

第二部分:RenderThread.threadLoop()分析

代码在 frameworks\base\libs\hwui\renderthread\RenderThread.cpp中。

bool RenderThread::threadLoop() {

setpriority(PRIO_PROCESS, 0, PRIORITY_DISPLAY);

initThreadLocals(); //初始化必要的环境信息。

int timeoutMillis = -1;

for (;;) {

int result = mLooper->pollOnce(timeoutMillis);

LOG_ALWAYS_FATAL_IF(result == Looper::POLL_ERROR,

"RenderThread Looper POLL_ERROR!");

nsecs_t nextWakeup;

// Process our queue, if we have anything

while (RenderTask* task = nextTask(&nextWakeup)) {

task->run();

// task may have deleted itself, do not reference it again

}

if (nextWakeup == LLONG_MAX) {

timeoutMillis = -1;

} else {

nsecs_t timeoutNanos = nextWakeup - systemTime(SYSTEM_TIME_MONOTONIC);

timeoutMillis = nanoseconds_to_milliseconds(timeoutNanos);

if (timeoutMillis < 0) {

timeoutMillis = 0;

}

}

if (mPendingRegistrationFrameCallbacks.size() && !mFrameCallbackTaskPending) {

drainDisplayEventQueue();

mFrameCallbacks.insert(

mPendingRegistrationFrameCallbacks.begin(), mPendingRegistrationFrameCallbacks.end());

mPendingRegistrationFrameCallbacks.clear();

requestVsync();

}

if (!mFrameCallbackTaskPending && !mVsyncRequested && mFrameCallbacks.size()) {

// TODO: Clean this up. This is working around an issue where a combination

// of bad timing and slow drawing can result in dropping a stale vsync

// on the floor (correct!) but fails to schedule to listen for the

// next vsync (oops), so none of the callbacks are run.

requestVsync();

}

}

return false;

}

initThreadLocals()函数主要做一些初始化工作,调用流程如下如。主要包括与SurfaceFlinger的EventThread线程建立起连接、构建出一个接收Display Event事件框架、通过Looper.addFd()添加一个Display Event事件处理函数RenderThread::displayEventReceiverCallback()等工作。

涉及相关的类关系如下:

待续。

原文:http://blog.csdn.net/guoqifa29/article/details/45131099

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值