Android surface&&overlay
类:
class LayerBuffer : public LayerBaseClient
内部类class OverlayChannel : public BnOverlay
class OverlayRef : public LightRefBase<OverlayRef>
sp<IOverlay> mOverlayChannel;//继承BpOverlay,从而访问LayerBuffer中的OverlayChannel
/*显示系统HAL初始化*/
SurfaceFlinger::readyToRun()
{
// initialize the main display
GraphicPlane& plane(graphicPlane(dpy));
DisplayHardware* const hw = new DisplayHardware(this, dpy);
plane.setDisplayHardware(hw);//mHw = hw;
}
DisplayHardware::DisplayHardware()
{
init()
}
/*获取overlay_control_device_t* mOverlayEngine*/
DisplayHardware::init(uint32_t dpy)
{
mNativeWindow = new FramebufferNativeWindow();
framebuffer_device_t const * fbDev = mNativeWindow->getDevice();
mDpiX = mNativeWindow->xdpi;
mDpiY = mNativeWindow->ydpi;
mRefreshRate = fbDev->fps;
mOverlayEngine = NULL;
hw_module_t const* module;
if (hw_get_module(OVERLAY_HARDWARE_MODULE_ID, &module) == 0) {
overlay_control_open(module, &mOverlayEngine);
}
《调用关系》
Overlay框架:
@1打开显示设备模块,overlay是叠加在framebuffer之上的视频显示层(Surfaceflinger.cpp)
SurfaceFlinger::readyToRun()
|
new DisplayHardware(const sp<SurfaceFlinger>& flinger,uint32_t dpy)
|
DisplayHardware::init
|
new FramebufferNativeWindow()///打开framebuffer驱动设备
hw_get_module(OVERLAY_HARDWARE_MODULE_ID, &module)///打开overlay模块库
load-->/system/lib/hw/overlay/overlay.default.so /vendor/lib/hw/ %s/%s.default.so
|
HMI-->HAL_MODULE_INFO_SYM-->overlay_module_methods-->open: overlay_device_open-->overlay_device_open-->OVERLAY_HARDWARE_CONTROL||OVERLAY_HARDWARE_DATA
|
overlay_data_open(module, &mOverlayData)-->overlay_device_open&&OVERLAY_HARDWARE_DATA
|
overlay_control_open(module, &mOverlayEngine)
@2获取overlay 打开overlay驱动(surfaceflinger.cpp)
ref = mISurface->createOverlay(mDecodedWidth, mDecodedHeight, OVERLAY_FORMAT_CbYCrY_422_I, 0);(TIHardwareRenderer)
BpSurface::createOverlay
|
Binder
|
LayerBaseClient::Surface::onTransact--BnSurface::onTransact--case CREATE_OVERLAY
LayerBuffer::SurfaceLayerBuffer::createOverlay
-->LayerBuffer::createOverlay
-->LayerBuffer::OverlaySource::OverlaySource
-->获取已打开的overlay硬件模块:overlay_control_device_t* overlay_dev = getFlinger()->getOverlayEngine()--SurfaceFlinger::getOverlayEngine()--GraphicPlane::displayHardware().getOverlayEngine()--mHw.getOverlayEngine--mOverlayEngine控制设备
-->创建对象overlay_object打开驱动设备:overlay_t* overlay = overlay_dev->createOverlay(overlay_dev, w, h, format);--overlay_createOverlay--create_shared_data--create_shared_data&&open&&overlay=new overlay_object
-->取句柄:mOverlayHandle = overlay->getHandleRef(overlay);--overlay_object::getHandleRef--return &(static_cast<overlay_object *>(overlay)->mHandle)--mHandle
-->设置层:sp<OverlayChannel> channel = new OverlayChannel(&layer)
-->*overlayRef = new OverlayRef(mOverlayHandle, channel,mWidth, mHeight, mFormat, mWidthStride, mHeightStride);
@3操作overlay
mOverlay = new Overlay(ref)(系统API:base/libs/ui/Overlay.cpp)
|
hw_get_module(OVERLAY_HARDWARE_MODULE_ID, &module)(Hardware.c)
load-->/system/lib/hw/overlay/overlay.default.so /vendor/lib/hw/ %s/%s.default.so
|
HMI-->HAL_MODULE_INFO_SYM-->overlay_module_methods-->open: overlay_device_open-->overlay_device_open-->OVERLAY_HARDWARE_CONTROL||OVERLAY_HARDWARE_DATA
|
overlay_data_open(module, &mOverlayData)-->overlay_device_open&&OVERLAY_HARDWARE_DATA
@4overlay显示(cameraservice应用:base/libs/ui/Overlay.cpp)
overlay->dequeueBuffer(&buffer);-->overlay_dequeueBuffer
|
void* address = overlay->getBufferAddress(buffer);-->overlay_getBufferAddress
|
memcpy(address,"hello overlay",15)///错--这里应该是送入YUV数据
|
overlay->queueBuffer(buffer);-->overlay_queueBuffer-->ioctl(ctx->ctl_fd, OVERLAY_QUEUE_BUFFER, &(ctx->phy_buffers[(int)buffer]))