gui


hardware\qcom\display\libgralloc\gralloc.cpp

GRALLOC_HARDWARE_MODULE_ID
// Open Gralloc device
gralloc_device_open  //module->methods->open 调用,根据其ID打开gralloc设备或fb设备

hardware\libhardware\include\hardware\fb.h

static inline int framebuffer_open(const struct hw_module_t* module,
        struct framebuffer_device_t** device) {
    return module->methods->open(module,
            GRALLOC_HARDWARE_FB0, (struct hw_device_t**)device);
}

hardware\libhardware\include\hardware\gralloc.h

static inline int gralloc_open(const struct hw_module_t* module, 
        struct alloc_device_t** device) {
    return module->methods->open(module, 
            GRALLOC_HARDWARE_GPU0, (struct hw_device_t**)device);
}

一、

frameworks\native\libs\ui\Gralloc1.cpp

Loader
    mAdapter = std::make_unique<Gralloc1On0Adapter>(module);
    device = mAdapter->getDevice();

frameworks\native\libs\ui\Gralloc1On0Adapter.cpp

int error = ::gralloc_open(&(mModule->common), &mDevice);
二、

frameworks\native\services\surfaceflinger\DisplayHardware\HWComposer_hwc1.cpp

    int err = hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &module);
    return framebuffer_open(module, &mFbDev);


打开fb设备(负责打开framebuffer,配置,刷新等操作)

status = fb_device_open(module, name, device);

hardware\qcom\display\libgralloc\framebuffer.cpp

status = mapFrameBuffer((framebuffer_device_t*)dev); 

--> err = mapFrameBufferLocked(dev);

打开"/dev/graphics/fb%u" 或  "/dev/fb%u",
获取显示屏的参数
ioctl(fd, FBIOGET_FSCREENINFO, &finfo)
ioctl(fd, FBIOGET_VSCREENINFO, &info)  //ioctl(fb, FBIOPUT_VSCREENINFO, &info) //对底层fb进行配置
把fb设备映射到当前内存
void* vaddr = mmap(0, fbSize, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
module->framebuffer->base = uint64_t(vaddr);
memset(vaddr, 0, fbSize);
 

打开gralloc设备(图形缓冲区的分配与释放)

IAllocController* alloc_ctrl = IAllocController::getInstance();//分配一块空间

dev = new gpu_context_t(m, alloc_ctrl);

hardware\qcom\display\libgralloc\gpu.cpp

    alloc          = gralloc_alloc;
    free           = gralloc_free;

总结图:



本地窗口:

分为两类:面向管理者(SurfaceFlinger)   面向应用程序(Surface)


第一类改进的窗口系统,对于提供opengl es来完成复杂渲染界面,尤其是使用GLSurfaceView


第二类改进的窗口系统,是android SDK提供给应用程序设计者,相对简单


在老式的Android版本中有个专门的FramebufferNativeWindow用来实现ANativeWindow的功能,不过在最新的Android系统(Android 7)中,FramebufferNativeWindow已被移除,看到Android源码中有如下一条提交记录:

libui: Remove FramebufferNativeWindow
We no longer support the framebuffer device, so FramebufferNativeWindow is no longer relevant.

另一个本地窗口是Surface,针对应用程序,同样继承自ANativeWindow:

class Surface
    : public ANativeObjectBase<ANativeWindow, Surface, RefBase>

采用多缓冲机制:一边刷新显示,一边绘制


一、缓冲区空间向HAL层的gralloc申请


GraphicBufferAllocator.h (native\include\ui):    std::unique_ptr<Gralloc1::Device> mDevice;
GraphicBufferMapper.h (native\include\ui):    std::unique_ptr<Gralloc1::Device> mDevice;

根据请求分配的图形缓冲区的用途来选择不同的分配方式,图形缓冲区可以从系统帧缓冲区中分配,也可以直接从内存中分配,当请求分配的图形缓冲区的用途标志位被设置为GRALLOC_USAGE_HW_FB,表示该图形缓冲区从FrameBuffer系统帧缓冲区中分配。

/*
 * This implements the (main) framebuffer management. This class is used
 * mostly by SurfaceFlinger, but also by command line GL application.
 *
 */

frameworks\native\services\surfaceflinger\DisplayHardware\FramebufferSurface.cpp

    mName = "FramebufferSurface";
    mConsumer->setConsumerName(mName);
    mConsumer->setConsumerUsageBits(GRALLOC_USAGE_HW_FB | GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_COMPOSER);



本地窗口是Surface

frameworks\native\libs\gui\Surface.cpp

    // mSurfaceTexture is the interface to the surface texture server. All
    // operations on the surface texture client ultimately translate into
    // interactions with the server using this interface.
    // TODO: rename to mBufferProducer
核心:sp<IGraphicBufferProducer> mGraphicBufferProducer;

ISurfaceComposer --> ISurfaceComposerClient --> IGraphicBufferProducer


SurfaceComposerClient -->sp<ISurfaceComposer> sm(ComposerService::getComposerService());


SurfaceFlinger 实现了 ISurfaceComposer(class SurfaceFlinger : public BnSurfaceComposer)

class Client : public BnSurfaceComposerClient

class BufferQueueProducer : public BnGraphicBufferProducer


    // BufferQueue manages a pool of gralloc memory slots to be used by
    // producers and consumers. allocator is used to allocate all the
    // needed gralloc buffers.

    BufferQueue::createBufferQueue

   BufferSlot.h 中定义了各个状态:





Layer:  Z-Order

ISurface

SurfaceControl


上面是通过纵向(时序)角度来分析,可以试着从横向角度来分析。。。。


一个client可以有多个layer层(应用程序与layer是一对多的关系),而每个layer对应一个BufferQueue。




合成: OpenGL ES   HWC: 两种渲染方式

显示到屏幕: eglSwapBuffers



http://blog.csdn.net/jinzhuojun/article/details/39698317









评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值