Android 12(S) SurfaceView/SurfaceFlinger/BLASTBufferQueue 零星点记录,好烦
Android S 相对于Android R 在SurfaceView/SurfaceFlinger部分,代码有诸多改动,
创建SurfaceView时,调用到updateSurface
第一次需要创建时调用到createBlastSurfaceControls
在createBlastSurfaceControls中可以看到会去创建3个SurfaceControl:mSurfaceControl, mBlastSurfaceControl, mBackgroundControl
摘抄主要代码:
点击查看代码
mSurfaceControl = new SurfaceControl.Builder(mSurfaceSession)
.setName(name)
.setLocalOwnerView(this)
.setParent(viewRoot.getBoundsLayer())
.setCallsite("SurfaceView.updateSurface")
.setContainerLayer()
.build();
/////
mBlastSurfaceControl = new SurfaceControl.Builder(mSurfaceSession)
.setName(name + "(BLAST)")
.setLocalOwnerView(this)
.setParent(mSurfaceControl)
.setFlags(mSurfaceFlags)
.setHidden(false)
.setBLASTLayer()
.setCallsite("SurfaceView.updateSurface")
.build();
/////
private SurfaceControl createBackgroundControl(String name) {
return new SurfaceControl.Builder(mSurfaceSession)
.setName("Background for " + name)
.setLocalOwnerView(this)
.setOpaque(true)
.setColorLayer()
.setParent(mSurfaceControl)
.setCallsite("SurfaceView.updateSurface")
.build();
}
分别对应的Surface的name:
- "SurfaceView[" + viewRoot.getTitle().toString() + "]"
- "SurfaceView[" + viewRoot.getTitle().toString() + "]" + "(BLAST)"
- "Background for " + "SurfaceView[" + viewRoot.getTitle().toString() + "]"
关系:
- mSurfaceControl.setParent(viewRoot.getBoundsLayer())
- mBlastSurfaceControl.setParent(mSurfaceControl)
- mBackgroundControl.setParent(mSurfaceControl)
这里有个新东西,先随便瞧瞧吧
mBlastBufferQueue = new BLASTBufferQueue(name, mBlastSurfaceControl, mSurfaceWidth, mSurfaceHeight, mFormat);
再回到updateSurface函数里:
==>performSurfaceTransaction ==> setBufferSize == SurfaceView发生变化时这里会更新一些信息
==>performSurfaceTransaction ==> onSetSurfacePositionAndScaleRT == SurfaceView发生变化时这里会更新一些信息
记录下setBufferSize的过程(最近有用到)
SurfaceView::setBufferSize ==> BLASTBufferQueue::update ==> JNI nativeUpdate ==> BLASTBufferQueuw::update
如果在BLASTBufferQueuw::update中增加一个setSize流程,可以把信息传递到SurfaceFLinger ==>Layer,
if (mSurfaceControl != nullptr && outTransaction != nullptr) {
outTransaction->setSize(mSurfaceControl, newSize.getWidth(), newSize.getHeight());
}
SurfaceFlinger出就会收到信息
if (what & layer_state_t::eSizeChanged) {
if (layer->setSize(s.w, s.h)) {
flags |= eTraversalNeeded;
}
}
注意BufferStateLayer有override setSize方法,导致不生效
ACodec的一些流程调用栈
播放器dequeue一个buffer用于解码
查看代码
12-07 11:01:34.223 3133 3878 D Surface : Surface::hook_dequeueBuffer start
12-07 11:01:34.284 3133 3878 E Surface : stackdump:#00 pc 0009e513 /system/lib/libgui.so (android::Surface::hook_dequeueBuffer(ANativeWindow*, ANativeWindowBuffer**, int*)+70)
12-07 11:01:34.284 3133 3878 E Surface : stackdump:#01 pc 00065149 /system/lib/libstagefright.so (android::ACodec::dequeueBufferFromNativeWindow()+180)
12-07 11:01:34.284 3133 3878 E Surface : stackdump:#02 pc 00066d2f /system/lib/libstagefright.so (android::ACodec::BaseState::onOutputBufferDrained(android::sp<android::AMessage> const&)+986)
12-07 11:01:34.284 3133 3878 E Surface : stackdump:#03 pc 00068ab9 /system/lib/libstagefright.so (android::ACodec::BaseState::onMessageReceived(android::sp<android::AMessage> const&)+1248)
12-07 11:01:34.284 3133 3878 E Surface : stackdump:#04 pc 0008ae15 /system/lib/libstagefright.so (android::AHierarchicalStateMachine::handleMessage(android::sp<android::AMessage> const&)+208)
12-07 11:01:34.284 3133 3878 E Surface : stackdump:#05 pc 0001219b /system/lib/libstagefright_foundation.so (android::AHandler::deliverMessage(android::sp<android::AMessage> const&)+54)
12-07 11:01:34.284 3133 3878 E Surface : stackdump:#06 pc 00016157 /system/lib/libstagefright_foundation.so (android::AMessage::deliver()+138)
12-07 11:01:34.284 3133 3878 E Surface : stackdump:#07 pc 00012f45 /system/lib/libstagefright_foundation.so (android::ALooper::loop()+576)
12-07 11:01:34.284 3133 3878 E Surface : stackdump:#08 pc 0000d38f /system/lib/libutils.so (android::Thread::_threadLoop(void*)+302)
12-07 11:01:34.284 3133 3878 E Surface : stackdump:#09 pc 0000ce43 /system/lib/libutils.so (thread_data_t::trampoline(thread_data_t const*)+262)
12-07 11:01:34.284 3133 3878 E Surface : stackdump:#10 pc 00080e57 /apex/com.android.runtime/lib/bionic/libc.so (__pthread_start(void*)+40)
12-07 11:01:34.284 3133 3878 E Surface : stackdump:#11 pc 00039e33 /apex/com.android.runtime/lib/bionic/libc.so (__start_thread+30)
12-07 11:01:34.284 3133 3878 D Surface : Surface::hook_dequeueBuffer end
播放器解码一帧数据送去显示 queueBuffer
查看代码
12-07 11:01:33.743 3133 3878 D Surface : Surface::hook_queueBuffer start
12-07 11:01:33.813 3133 3878 E Surface : stackdump:#00 pc 0009e663 /system/lib/libgui.so (android::Surface::hook_queueBuffer(ANativeWindow*, ANativeWindowBuffer*, int)+70)
12-07 11:01:33.813 3133 3878 E Surface : stackdump:#01 pc 000675af /system/lib/libstagefright.so (android::ACodec::BaseState::onOutputBufferDrained(android::sp<android::AMessage> const&)+3162)
12-07 11:01:33.813 3133 3878 E Surface : stackdump:#02 pc 00068ab9 /system/lib/libstagefright.so (android::ACodec::BaseState::onMessageReceived(android::sp<android::AMessage> const&)+1248)
12-07 11:01:33.813 3133 3878 E Surface : stackdump:#03 pc 0008ae15 /system/lib/libstagefright.so (android::AHierarchicalStateMachine::handleMessage(android::sp<android::AMessage> const&)+208)
12-07 11:01:33.813 3133 3878 E Surface : stackdump:#04 pc 0001219b /system/lib/libstagefright_foundation.so (android::AHandler::deliverMessage(android::sp<android::AMessage> const&)+54)
12-07 11:01:33.813 3133 3878 E Surface : stackdump:#05 pc 00016157 /system/lib/libstagefright_foundation.so (android::AMessage::deliver()+138)
12-07 11:01:33.813 3133 3878 E Surface : stackdump:#06 pc 00012f45 /system/lib/libstagefright_foundation.so (android::ALooper::loop()+576)
12-07 11:01:33.813 3133 3878 E Surface : stackdump:#07 pc 0000d38f /system/lib/libutils.so (android::Thread::_threadLoop(void*)+302)
12-07 11:01:33.813 3133 3878 E Surface : stackdump:#08 pc 0000ce43 /system/lib/libutils.so (thread_data_t::trampoline(thread_data_t const*)+262)
12-07 11:01:33.813 3133 3878 E Surface : stackdump:#09 pc 00080e57 /apex/com.android.runtime/lib/bionic/libc.so (__pthread_start(void*)+40)
12-07 11:01:33.813 3133 3878 E Surface : stackdump:#10 pc 00039e33 /apex/com.android.runtime/lib/bionic/libc.so (__start_thread+30)
12-07 11:01:33.813 3133 3878 D Surface : Surface::hook_queueBuffer end
播放器停止时,MediaCodec::disconnectFromSurface
查看代码
12-07 11:01:34.505 3133 3877 D Surface : Surface::disconnect start
12-07 11:01:34.583 3133 3877 E Surface : stackdump:#00 pc 0009eb37 /system/lib/libgui.so (android::Surface::disconnect(int, android::IGraphicBufferProducer::DisconnectMode)+94)
12-07 11:01:34.583 3133 3877 E Surface : stackdump:#01 pc 0009e7f1 /system/lib/libgui.so (android::Surface::hook_perform(ANativeWindow*, int, ...)+128)
12-07 11:01:34.583 3133 3877 E Surface : stackdump:#02 pc 0010b9cd /system/lib/libstagefright.so (android::nativeWindowDisconnect(ANativeWindow*, char const*) (.cfi)+56)
12-07 11:01:34.583 3133 3877 E Surface : stackdump:#03 pc 000d7577 /system/lib/libstagefright.so (android::MediaCodec::disconnectFromSurface()+74)
12-07 11:01:34.583 3133 3877 E Surface : stackdump:#04 pc 000d6ee5 /system/lib/libstagefright.so (android::MediaCodec::handleSetSurface(android::sp<android::Surface> const&)+32)
12-07 11:01:34.583 3133 3877 E Surface : stackdump:#05 pc 000d2109 /system/lib/libstagefright.so (android::MediaCodec::setState(android::MediaCodec::State)+220)
12-07 11:01:34.583 3133 3877 E Surface : stackdump:#06 pc 000ced5f /system/lib/libstagefright.so (android::MediaCodec::onMessageReceived(android::sp<android::AMessage> const&)+11370)
12-07 11:01:34.583 3133 3877 E Surface : stackdump:#07 pc 0001219b /system/lib/libstagefright_foundation.so (android::AHandler::deliverMessage(android::sp<android::AMessage> const&)+54)
12-07 11:01:34.583 3133 3877 E Surface : stackdump:#08 pc 00016157 /system/lib/libstagefright_foundation.so (android::AMessage::deliver()+138)
12-07 11:01:34.583 3133 3877 E Surface : stackdump:#09 pc 00012f45 /system/lib/libstagefright_foundation.so (android::ALooper::loop()+576)
12-07 11:01:34.583 3133 3877 E Surface : stackdump:#10 pc 0000d38f /system/lib/libutils.so (android::Thread::_threadLoop(void*)+302)
12-07 11:01:34.583 3133 3877 E Surface : stackdump:#11 pc 0007eeaf /system/lib/libandroid_runtime.so (android::AndroidRuntime::javaThreadShell(void*)+86)
12-07 11:01:34.583 3133 3877 E Surface : stackdump:#12 pc 0000ce43 /system/lib/libutils.so (thread_data_t::trampoline(thread_data_t const*)+262)
12-07 11:01:34.583 3133 3877 E Surface : stackdump:#13 pc 00080e57 /apex/com.android.runtime/lib/bionic/libc.so (__pthread_start(void*)+40)
12-07 11:01:34.583 3133 3877 E Surface : stackdump:#14 pc 00039e33 /apex/com.android.runtime/lib/bionic/libc.so (__start_thread+30)
12-07 11:01:34.583 3133 3877 D GraphicBuffer: ~GraphicBuffer[126]
12-07 11:01:34.584 3133 3877 D GraphicBuffer: ~GraphicBuffer[126]
12-07 11:01:34.584 3133 3877 D GraphicBuffer: ~GraphicBuffer[126]
12-07 11:01:34.585 3133 3877 D GraphicBuffer: ~GraphicBuffer[126]
12-07 11:01:34.585 3133 3877 D GraphicBuffer: ~GraphicBuffer[126]
12-07 11:01:34.585 3133 3877 D BufferQueueProducer: disconnect [1387] onDisconnect() SurfaceView[com.google.android.youtube.tv/com.google.android.apps.youtube.tv.activity.MainActivity]#1(BLAST Consumer)1
12-07 11:01:34.585 3133 3877 D Surface : Surface::disconnect mScalingMode = NATIVE_WINDOW_SCALING_MODE_FREEZE
12-07 11:01:34.585 3133 3877 D Surface : Surface::disconnect end