GraphicBuffer和Gralloc

    SurfaceFlinger::init初始化的时候,调用registerCallback通过hwbinder向hwcomposer进程注册回调,注册完成会调用SurfaceFlinger::onHotplugReceived,processDisplayHotplugEventsLocked收到DisplayDevice Connected事件,setupNewDisplayDeviceInternal调用nativeWindowSurface->preallocateBuffers(),然后调用为surface->allocateBuffers(),然后调用生产者mGraphicBufferProducer的allocateBuffers,在BufferQueueProducer::allocateBuffers分配GraphicBuffer。new GraphicBuffer,调用到GraphicBuffer::initWithSize,调用GraphicBufferAllocator::allocate,调用Allocator::allocate,此时mAllocator->allocate会通过hwbinder调用到grallocator进程的具体调用流程如下:

代码文件路径:frameworks/native/services/surfaceflinger/SurfaceFlinger.cpp

void SurfaceFlinger::init() {
    ......
    getBE().mRenderEngine =
            RE::impl::RenderEngine::create(HAL_PIXEL_FORMAT_RGBA_8888, hasWideColorDisplay? RE::RenderEngine::WIDE_COLOR_SUPPORT: 0);
    LOG_ALWAYS_FATAL_IF(getBE().mRenderEngine == nullptr, "couldn't create RenderEngine");

    LOG_ALWAYS_FATAL_IF(mVrFlingerRequestsDisplay,
            "Starting with vr flinger active is not currently supported.");
    getBE().mHwc.reset(
            new HWComposer(std::make_unique<Hwc2::impl::Composer>(getBE().mHwcServiceName)));


    getBE().mHwc->registerCallback(this, getBE().mComposerSequenceId);  //调用registerCallback通过hwbinder向hwcomposer进程注册回调, 注册的对象为SurfaceFlinger

    // Process any initial hotplug and resulting display changes.
    processDisplayHotplugEventsLocked();
    LOG_ALWAYS_FATAL_IF(!getBE().mHwc->isConnected(HWC_DISPLAY_PRIMARY),
            "Registered composer callback but didn't create the default primary display");

    // make the default display GLContext current so that we can create textures
    // when creating Layers (which may happens before we render something)
    getDefaultDisplayDeviceLocked()->makeCurrent();
    ......
}

    注册完成会调用SurfaceFlinger::onHotplugReceived

void SurfaceFlinger::onHotplugReceived(int32_t sequenceId, hwc2_display_t display, HWC2::Connection connection)

{

ConditionalLock lock(mStateLock, std::this_thread::get_id() != mMainThreadId);

mPendingHotplugEvents.emplace_back(HotplugEvent{display, connection});

if (std::this_thread::get_id() == mMainThreadId) {

    processDisplayHotplugEventsLocked();

}

setTransactionFlags(eDisplayTransactionNeeded);

}

}

void SurfaceFlinger::processDisplayHotplugEventsLocked() {

    processDisplayChangesLocked();

}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

薛文旺

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值