G_LIKELY 和G_UNLIKELY

  1. #define G_LIKELY(expr) (__builtin_expect (_G_BOOLEAN_EXPR(expr), 1))  
  2. #define G_UNLIKELY(expr) (__builtin_expect (_G_BOOLEAN_EXPR(expr), 0))  
if (__builtin_expect (x, 0))的目的只是告诉编译器我们期望表达式x的值为0,这样其实是告诉编译器我们不期望if 紧接着的语句被执行,而是期望else后面的语句被执行,这样编译器就会帮我们把else后面的语句优化到if语句的后面
同理if (__builtin_expect (x, 1))的目的只是告诉编译器我们期望表达式x的值为1,即期望if紧接着的语句被执行。
void DrawFrameTask::run() { 136 const int64_t vsyncId = mFrameInfo[static_cast<int>(FrameInfoIndex::FrameTimelineVsyncId)]; 137 ATRACE_FORMAT("DrawFrames %" PRId64, vsyncId); 138 139 mContext->setSyncDelayDuration(systemTime(SYSTEM_TIME_MONOTONIC) - mSyncQueued); 140 mContext->setTargetSdrHdrRatio(mRenderSdrHdrRatio); 141 142 auto hardwareBufferParams = mHardwareBufferParams; 143 mContext->setHardwareBufferRenderParams(hardwareBufferParams); 144 IRenderPipeline* pipeline = mContext->getRenderPipeline(); 145 bool canUnblockUiThread; 146 bool canDrawThisFrame; 147 bool solelyTextureViewUpdates; 148 { 149 TreeInfo info(TreeInfo::MODE_FULL, *mContext); 150 info.forceDrawFrame = mForceDrawFrame; 151 mForceDrawFrame = false; 152 canUnblockUiThread = syncFrameState(info); 153 canDrawThisFrame = !info.out.skippedFrameReason.has_value(); 154 solelyTextureViewUpdates = info.out.solelyTextureViewUpdates; 155 156 if (mFrameCommitCallback) { 157 mContext->addFrameCommitListener(std::move(mFrameCommitCallback)); 158 mFrameCommitCallback = nullptr; 159 } 160 } 161 162 // Grab a copy of everything we need 163 CanvasContext* context = mContext; 164 std::function<std::function<void(bool)>(int32_t, int64_t)> frameCallback = 165 std::move(mFrameCallback); 166 std::function<void()> frameCompleteCallback = std::move(mFrameCompleteCallback); 167 mFrameCallback = nullptr; 168 mFrameCompleteCallback = nullptr; 169 170 // From this point on anything in "this" is *UNSAFE TO ACCESS* 171 if (canUnblockUiThread) { 172 unblockUiThread(); 173 } 174 175 // Even if we aren't drawing this vsync pulse the next frame number will still be accurate 176 if (CC_UNLIKELY(frameCallback)) { 177 context->enqueueFrameWork([frameCallback, context, syncResult = mSyncResult, 178 frameNr = context->getFrameNumber()]() { 179 auto frameCommitCallback = frameCallback(syncResult, frameNr); 180 if (frameCommitCallback) { 181 context->addFrameCommitListener(std::move(frameCommitCallback)); 182 } 183 }); 184 } 185 186 if (CC_LIKELY(canDrawThisFrame)) { 187 context->draw(solelyTextureViewUpdates); 188 } else { 189 #ifdef __ANDROID__ 190 // Do a flush in case syncFrameState performed any texture uploads. Since we skipped 191 // the draw() call, those uploads (or deletes) will end up sitting in the queue. 192 // Do them now 193 if (GrDirectContext* grContext = mRenderThread->getGrContext()) { 194 grContext->flushAndSubmit(); 195 } 196 #endif 197 // wait on fences so tasks don't overlap next frame 198 context->waitOnFences(); 199 } 200 201 if (CC_UNLIKELY(frameCompleteCallback)) { 202 std::invoke(frameCompleteCallback); 203 } 204 205 if (!canUnblockUiThread) { 206 unblockUiThread(); 207 } 208 #ifdef MTK_ONLY_CHANGES 209 #ifdef MTK_SBE_RESCUE 210 //@MTK: add rescue frame complete hint 211 notifySbeRescue(mRenderThreadId, 0, 0, vsyncId); 212 //@ End of add 213 #endif /* MTK_SBE_RESCUE */ 214 #endif /* MTK_ONLY_CHANGES */ 215 216 if (pipeline->hasHardwareBuffer()) { 217 auto fence = pipeline->flush(); 218 hardwareBufferParams.invokeRenderCallback(std::move(fence), 0); 219 } 220 } 这是上述void DrawFrameTask::run() 函数的具体操作,请告诉我这段代码的作用,详细
最新发布
08-13
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值