Android 12(S) SurfaceView/SurfaceFlinger/BLASTBufferQueue 零星点记录,好烦
Android S 相对于Android R 在SurfaceView/SurfaceFlinger部分,代码有诸多改动,
创建SurfaceView时,调用到updateSurface
http://aosp.opersys.com/xref/android-12.0.0_r2/xref/frameworks/base/core/java/android/view/SurfaceView.java#1065
第一次需要创建时调用到createBlastSurfaceControls
http://aosp.opersys.com/xref/android-12.0.0_r2/xref/frameworks/base/core/java/android/view/SurfaceView.java#1326
在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);
http://aosp.opersys.com/xref/android-12.0.0_r2/xref/frameworks/base/core/java/android/view/SurfaceView.java#1367
再回到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方法,导致不生效
http://aosp.opersys.com/xref/android-12.0.0_r2/xref/frameworks/native/services/surfaceflinger/BufferStateLayer.h#76