Chinaunix首页 | 论坛 | 博客
  • 博客访问: 257576
  • 博文数量: 69
  • 博客积分: 1400
  • 博客等级: 上尉
  • 技术积分: 900
  • 用 户 组: 普通用户
  • 注册时间: 2007-12-07 16:35
文章分类

全部博文(69)

文章存档

2011年(1)

2010年(68)

我的朋友

分类: LINUX

2010-08-02 22:09:44

声明本文转载于http://hi.baidu.com/leowenj/blog/item/3fe59f740a6fee17b051b991.html

流程分析

      根据前面的介绍,surfaceflinger作为一个server process,上层的应用程序(作为client)通过Binder方式与其进行通信。Surfaceflinger作为一个thread,这里把它分为3个部分,如下:

1、 Thread本身处理部分,包括初始化以及thread loop

2、 Binder部分,负责接收上层应用的各个设置和命令,并反馈状态标志给上层。

3、 与底层的交互,负责调用底层接口(HAL)。

结构图如下:



注释:

a、 Binder接收到应用程序的命令(如创建surface、设置参数等),传递给flinger

b、 Flinger完成对应命令后将相关结果状态反馈给上层。

c、 在处理上层命令过程中,根据需要设置event(主要和显示有关),通知Thread Loop进行处理。

d、 Flinger根据上层命令通知底层进行处理(主要是设置一些参数,Layerposition等)

e、 Thread Loop中进行surface的合成并通知底层进行显示(Post buffer)。

f、   DisplayHardware层根据flinger命令调用HAL进行HW的操作。

下面来具体分析一些SurfaceFlinger中重要的处理函数以及surfaceLayer的属性

1)、readToRun

   SurfaceFlinger thread的初始化函数,主要任务是分配内存和设置底层接口(EGL&HAL)

status_t SurfaceFlinger::readyToRun()

mServerHeap = new MemoryDealer(4096, MemoryDealer::READ_ONLY);//IPC分配共享内存

mSurfaceHeapManager = new SurfaceHeapManager(this, 8 << 20);//flinger分配heap,大小为8M,存放具体的显示数据

    {

       // initialize the main display

        GraphicPlane& plane(graphicPlane(dpy));

        DisplayHardware* const hw = new DisplayHardware(this, dpy);

        plane.setDisplayHardware(hw);//保存显示接口

}

//获取显示相关参数

    const GraphicPlane& plane(graphicPlane(dpy));

    const DisplayHardware& hw = plane.displayHardware();

    const uint32_t w = hw.getWidth();

    const uint32_t h = hw.getHeight();

    const uint32_t f = hw.getFormat();

    // Initialize OpenGL|ES

    glActiveTexture(GL_TEXTURE0);

    glBindTexture(GL_TEXTURE_2D, 0);

    glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);

    glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

    glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

2)、ThreadLoop

Surfaceflingerloop函数,主要是等待其他接口发送的event,进行显示数据的合成以及显示。

bool SurfaceFlinger::threadLoop()

{

    waitForEvent();//等待其他接口的signal event

    // post surfaces (if needed)

    handlePageFlip();//处理翻页机制

    const DisplayHardware& hw(graphicPlane(0).displayHardware());

    if (LIKELY(hw.canDraw()))

   {

        // repaint the framebuffer (if needed)

        handleRepaint();//合并所有layer并填充到buffer中去

        postFramebuffer();//互换front bufferback buffer,调用EGL接口进行显示

    }

}

3)、createSurface

提供给应用程序的主要接口,该接口可以创建一个surface,底层会根据参数创建layer以及分配内存,surface相关参数会反馈给上层

sp SurfaceFlinger::createSurface(ClientID clientId, int pid,

        ISurfaceFlingerClient::surface_data_t* params,

        DisplayID d, uint32_t w, uint32_t h, PixelFormat format,

        uint32_t flags)

    int32_t id = c->generateId(pid);

    if (uint32_t(id) >= NUM_LAYERS_MAX) //NUM_LAYERS_MAX=31

    {

        LOGE("createSurface() failed, generateId = %d", id);

        return

    }

layer = createNormalSurfaceLocked(c, d, id, w, h, format, flags);//创建layer,根据参数(宽高格式)分配内存(共2bufferfront/back buffer

    if (layer)

    {

        setTransactionFlags(eTransactionNeeded);

        surfaceHandle = layer->getSurface();//创建surface

        if (surfaceHandle != 0)

            surfaceHandle->getSurfaceData(params);//创建的surface参数反馈给应用层

    }

待续。。。

阅读(1764) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~