//frameworks/native/services/surfaceflinger/BufferQueueLayer.cpp
sp<SurfaceFlinger>mFlinger;sp<BufferLayerConsumer>mConsumer;voidBufferQueueLayer::onFrameAvailable(constBufferItem&item){constint32_tlayerId=getSequence();constuint64_tbufferId=item.mGraphicBuffer->getId();mFlinger->mFrameTracer->traceTimestamp(layerId,bufferId,item.mFrameNumber,systemTime(),FrameTracer::FrameEvent::QUEUE);mFlinger->mFrameTracer->traceFence(layerId,bufferId,item.mFrameNumber,std::make_shared<FenceTime>(item.mFence),FrameTracer::FrameEvent::ACQUIRE_FENCE);ATRACE_CALL();// Add this buffer from our internal queue tracker
{// Autolock scope
constnsecs_tpresentTime=item.mIsAutoTimestamp?0:item.mTimestamp;usingLayerUpdateType=scheduler::LayerHistory::LayerUpdateType;mFlinger->mScheduler->recordLayerHistory(this,presentTime,LayerUpdateType::Buffer);Mutex::Autolocklock(mQueueItemLock);// Reset the frame number tracker when we receive the first buffer after
// a frame number reset
if(item.mFrameNumber==1){mLastFrameNumberReceived=0;}// Ensure that callbacks are handled in order
while(item.mFrameNumber!=mLastFrameNumberReceived+1){status_tresult=mQueueItemCondition.waitRelative(mQueueItemLock,ms2ns(500));if(result!=NO_ERROR){ALOGE("[%s] Timed out waiting on callback",getDebugName());break;}}autosurfaceFrame=createSurfaceFrameForBuffer(mFrameTimelineInfo,systemTime(),mName);mQueueItems.push_back({item,surfaceFrame});mQueuedFrames++;// Wake up any pending callbacks
mLastFrameNumberReceived=item.mFrameNumber;mQueueItemCondition.broadcast();}mFlinger->mInterceptor->saveBufferUpdate(layerId,item.mGraphicBuffer->getWidth(),item.mGraphicBuffer->getHeight(),item.mFrameNumber);mFlinger->onLayerUpdate();mConsumer->onBufferAvailable(item);}
//frameworks/native/services/surfaceflinger/Layer.cpp
sp<SurfaceFlinger>mFlinger;conststd::unique_ptr<frametimeline::FrameTimeline>mFrameTimeline;std::shared_ptr<frametimeline::SurfaceFrame>Layer::createSurfaceFrameForBuffer(constFrameTimelineInfo&info,nsecs_tqueueTime,std::stringdebugName){autosurfaceFrame=mFlinger->mFrameTimeline->createSurfaceFrameForToken(info,mOwnerPid,mOwnerUid,getSequence(),mName,debugName,/*isBuffer*/true,getGameMode());surfaceFrame->setActualStartTime(info.startTimeNanos);// For buffers, acquire fence time will set during latch.
surfaceFrame->setActualQueueTime(queueTime);constautofps=mFlinger->mScheduler->getFrameRateOverride(getOwnerUid());if(fps){surfaceFrame->setRenderRate(*fps);}// TODO(b/178542907): Implement onSurfaceFrameCreated for BQLayer as well.
onSurfaceFrameCreated(surfaceFrame);returnsurfaceFrame;}