zoukankan      html  css  js  c++  java
  • chromium for android GPU进程结构分析

    版权声明:本文为博主原创文章。未经博主同意不得转载。

    https://blog.csdn.net/jaylinzhou/article/details/27517471

    GPU进程的client(Browser进程,Render进程)都会创建一个
    WebGraphicsContext3DCommandBufferImpl的实例,用于封装与GPU进程的通信。


    所以我们从WebGraphicsContext3DCommandBufferImpl開始引出GPU进程的结构。


    一.WebGraphicsContext3DCommandBufferImpl的创建。


    WebGraphicsContext3D暴露的接口基本与OpenGL ES 2.0 API相应。
    WebGraphicsContext3DCommandBufferImpl是WebGraphicsContext3D的实现类。


    Browser进程创建WebGraphicsContext3DCommandBufferImpl的实例发生在
    CompositorImpl::CreateOutputSurface()。
    CompositorImpl::CreateOutputSurface()在创建
    WebGraphicsContext3DCommandBufferImpl实例时传入了surface_id。
    surface_id标识Browser应用中使用的android标准控件SurfaceView相应的
    本地窗体的一块buffer。


    Render进程创建WebGraphicsContext3DCommandBufferImpl的实例发生在
    RenderWidget::CreateOutputSurface()
    RenderWidget::CreateGraphicsContext3D()。
    RenderWidget::CreateGraphicsContext3D()在创建
    WebGraphicsContext3DCommandBufferImpl实例时传入了surface_id。


    surface_id是RenderWidgetHostImpl::RenderWidgetHostImpl()
    通过调用GpuSurfaceTracker::Get()->AddSurfaceForRenderer()得到的。

    通过以下路径传递给RenderWidget::surface_id_。

    二.WebGraphicsContext3DCommandBufferImpl中包括的与GPU进程通信相关的成员变量:
    scoped_refptr<GpuChannelHost> host_;
    CommandBufferProxyImpl* command_buffer_;
    gpu::gles2::GLES2CmdHelper* gles2_helper_;
    gpu::TransferBuffer* transfer_buffer_;
    gpu::gles2::GLES2Interface* gl_;
    以下一一介绍这些成员变量的作用。


    scoped_refptr<GpuChannelHost> host_的创建及其作用。
    Browser进程和Render进程在创建WebGraphicsContext3DCommandBufferImpl实例时都传
    入了GpuChannelHostFactory实例。


    Browser进程传入的是BrowserGpuChannelHostFactory。
    Render进程传入的是RenderThreadImpl。
    BrowserGpuChannelHostFactory与RenderThreadImpl继承自GpuChannelHostFactory。

    WebGraphicsContext3DCommandBufferImpl::Initialize(){
     host_ = factory_->EstablishGpuChannelSync(cause);
    }
    WebGraphicsContext3DCommandBufferImpl::Initialize()调用传递进来的
    GpuChannelHostFactory实例生成GpuChannelHost实例。
    GpuChannelHost封装client和GPU进程之间的IPC通道。


    GPU进程中会产生一个相应的GpuChannel实例。
    Browser进程与GPU进程之间IPC Channel的建立过程。

    BrowserGpuChannelHostFactory::EstablishGpuChannelSync()先后调用例如以下3个函数:
    1.BrowserGpuChannelHostFactory::EstablishGpuChannelOnIO()
    2.gpu_channel_ = new GpuChannelHost(this, request.gpu_host_id, gpu_client_id_);
    3.gpu_channel_->Connect(request.channel_handle);
    1.BrowserGpuChannelHostFactory::EstablishGpuChannelOnIO()会触发GPU进程创建GpuChannel。

    2.BrowserGpuChannelHostFactory::EstablishGpuChannelSync()在GPU进程创建完GpuChannel后,
    创建与GpuChannel相相应的Browser进程中的GpuChannelHost实例。
    3.调用GpuChannelHost::Connect()连接Browser进程GpuChannelHost与GPU进程GpuChannel。
    Render进程与GPU进程之间IPC Channel的建立过程。
    RenderWidget::CreateGraphicsContext3D()
    WebGraphicsContext3DCommandBufferImpl::Initialize()
    RenderThreadImpl::EstablishGpuChannelSync()
    RenderThreadImpl::EstablishGpuChannelSync()先后调用了例如以下3个函数:
    1.RenderThreadImpl::Send(new GpuHostMsg_EstablishGpuChannel());
    2.gpu_channel_ = new GpuChannelHost(this, request.gpu_host_id, gpu_client_id_);
    3.gpu_channel_->Connect(request.channel_handle);
    1.RenderThreadImpl::Send(new GpuHostMsg_EstablishGpuChannel())会触发GPU进程中GpuChannel的创建。


    GpuMessageFilter::OnMessageReceived()
    GpuMessageFilter::OnEstablishGpuChannel()
    GpuProcessHost::EstablishGpuChannel()
    接下来的流程就是Browser进程发送消息触发GPU进程中GpuChannel的创建。
    所以Render进程相应的GpuChannel是通过Browser进程触发GPU进程创建的。
    2.RenderThreadImpl::EstablishGpuChannelSync()在通过Browser进程创建完GpuChannel实例后,创建
    与GpuChannel相相应的Render进程中的GpuChannelHost实例。
    3.调用GpuChannelHost::Connect()连接Render进程的GpuChannelHost实例与GPU进程中的GpuChannel实例。
    Browser进程CommandBufferProxyImpl* command_buffer_的创建及其作用
    CommandBufferProxyImpl是GPU进程client代理,负责将消息同步给GPU进程中相应的GpuCommandBufferStub。
    GpuCommandBufferStub与GPU进程中的CommandBufferProxyImpl一一相应。
    Browser进程先触发GPU进程创建GpuCommandBufferStub的实例后,再创建CommandBufferProxyImpl。
    GpuCommandBufferStub的实例的创建步骤例如以下。

    GpuChannelHost::CreateViewCommandBuffer()在触发GPU进程创建GpuCommandBufferStub的实例后,
    创建了与GpuCommandBufferStub相相应的CommandBufferProxyImpl。


    Render进程CommandBufferProxyImpl* command_buffer_的创建流程例如以下。

    gpu::gles2::GLES2CmdHelper* gles2_helper_;
    gpu::gles2::GLES2CmdHelper帮助写入GL command buffer的辅助类。
    gpu::TransferBuffer* transfer_buffer_;
    gpu::TransferBuffer管理transfer buffer的类。
    gpu::gles2::GLES2Interface* gl_;
    gl_实际指向GLES2Implementation的实例。
    GLES2Implementation在command buffers之上模拟GLES2。
    GPU进程的client使用GLES2Implementation。


    GLES2Implementation封装了shared memory的处理和command buffer的管理。
    gles2_helper_和 transfer_buffer_都设置给gl_,在类GLES2Implementation中使用。


    GPU进程client与GPU进程通信的流程是:
    WebGraphicsContext3DCommandBufferImpl调用GLES2Implementation的相应接口,
    GLES2Implementation调用GLES2CmdHelper将要发送给GPU进程的命令写入CommandBuffer
    包括的SharedMemory中。这块SharedMemory也被映射到GPU进程中。
    GPU进程中GLES2DecoderImpl负责处理GLES2Implementation发送的命令。


    CommandBuffer包括的SharedMemory被映射到GPU进程中由CommandBufferService管理。
    所以GLES2DecoderImpl通过操作CommandBufferService来取得命令相关的数据。
    CommandBufferProxyImpl通过IPC发送消息给GPU进程,同步GPU进程中的操作。
    GPU进程client通过CommandBufferProxyImpl发送的IPC消息是以GpuCommandBufferMsg_为前缀的。
    GPU进程中接受这类消息的是GpuCommandBufferStub。
    GpuCommandBufferStub调用CommandBufferService完毕实际的消息处理。


    Gpu进程client和Gpu进程结构例如以下图:

    三.GPU进程的创建
    gpu_process_host.cc中定义了GpuMainThread类。


    GpuMainThread::init()函数中创建GPU进程,或者在设置了in-process-gpu或single-process时。
    创建GPU线程。
    GPU进程是Browser进程的子进程。仅仅会在Browser进程中创建一次。


查看全文
  • 相关阅读:
    shutdown(0)和shutdown(1)
    MAC Pro 同时安装 Python2 和 Python3
    Linux常用命令大全(非常全!!!)
    ReentrantLock和synchronized的区别
    ReentrantLock和synchronized的区别
    ReentrantLock和synchronized的区别
    ReentrantLock和synchronized的区别
    Java反射与注解
    Java反射与注解
    Java反射与注解
  • 原文地址:https://www.cnblogs.com/ldxsuanfa/p/10958366.html
  • Copyright © 2011-2022 走看看