The client of the GPU process (the browser process, the render process) will create a
An instance of Webgraphicscontext3dcommandbufferimpl that encapsulates communication with the GPU process.
So we started out with WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL the structure of the GPU process.
I. Creation of the WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL.
The Webgraphicscontext3d exposed interface is basically the same as the OpenGL ES 2.0 API.
Webgraphicscontext3dcommandbufferimpl is the implementation class of Webgraphicscontext3d.
The browser process creates an instance of Webgraphicscontext3dcommandbufferimpl that occurs in the
Compositorimpl::createoutputsurface ().
Compositorimpl::createoutputsurface () in creating
The Webgraphicscontext3dcommandbufferimpl instance is passed in surface_id.
SURFACE_ID identifies the Android standard controls used in the browser app Surfaceview corresponding
A piece of buffer for the local window.
The render process creates an instance of Webgraphicscontext3dcommandbufferimpl that occurs in the
Renderwidget::createoutputsurface ()
Renderwidget::creategraphicscontext3d ().
Renderwidget::creategraphicscontext3d () in creating
The Webgraphicscontext3dcommandbufferimpl instance is passed in surface_id.
SURFACE_ID is Renderwidgethostimpl::renderwidgethostimpl ()
obtained by calling Gpusurfacetracker::get ()->addsurfaceforrenderer ().
Passed to renderwidget::surface_id_ through the following path.
Two. member variables contained in Webgraphicscontext3dcommandbufferimpl that are related to GPU process communication:
Scoped_refptr<gpuchannelhost> Host_;
commandbufferproxyimpl* Command_buffer_;
gpu::gles2::gles2cmdhelper* Gles2_helper_;
gpu::transferbuffer* Transfer_buffer_;
Gpu::gles2::gles2interface* Gl_;
The role of these member variables is described below.
The creation and function of scoped_refptr<gpuchannelhost> host_.
The browser process and the render process are transmitted when the Webgraphicscontext3dcommandbufferimpl instance is created
Into the Gpuchannelhostfactory instance.
The browser process passed in the browsergpuchannelhostfactory.
The render process is passing in the Renderthreadimpl.
Browsergpuchannelhostfactory and Renderthreadimpl inherit from Gpuchannelhostfactory.
Gpuchannelhostfactory.jpg
Webgraphicscontext3dcommandbufferimpl::initialize () {
Host_ = Factory_->establishgpuchannelsync (cause);
}
Webgraphicscontext3dcommandbufferimpl::initialize () call passed in
The Gpuchannelhostfactory instance generates an Gpuchannelhost instance.
Gpuchannelhost encapsulates the IPC channel between the client and the GPU process.
A corresponding Gpuchannel instance is generated in the GPU process.
The process of establishing the IPC channel between the browser process and the GPU process.
Browsergpuchannelhostfactory::establishgpuchannelsync () calls the following 3 functions:
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 () triggers the GPU process creation gpuchannel.
Gpuchannelcreated.jpg
2.browsergpuchannelhostfactory::establishgpuchannelsync () After the GPU process has finished creating Gpuchannel,
Creates a Gpuchannelhost instance in the browser process corresponding to the Gpuchannel.
3. Call Gpuchannelhost::connect () to connect the browser process Gpuchannelhost with the GPU process Gpuchannel.
The process of establishing the IPC channel between the render process and the GPU process.
Renderwidget::creategraphicscontext3d ()
Webgraphicscontext3dcommandbufferimpl::initialize ()
Renderthreadimpl::establishgpuchannelsync ()
Renderthreadimpl::establishgpuchannelsync () has called the following 3 functions:
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 ()) triggers the creation of Gpuchannel in the GPU process.
Gpumessagefilter::onmessagereceived ()
Gpumessagefilter::onestablishgpuchannel ()
Gpuprocesshost::establishgpuchannel ()
The next process is for the browser process to send messages that trigger the creation of Gpuchannel in the GPU process.
So the gpuchannel corresponding to the render process is created by triggering the GPU process with the browser process.
2.renderthreadimpl::establishgpuchannelsync () After creating the Gpuchannel instance through the browser process, create
The Gpuchannelhost instance in the render process corresponding to the Gpuchannel.
3. Call Gpuchannelhost::connect () to connect the Gpuchannelhost instance of the render process to the Gpuchannel instance in the GPU process.
The creation and function of browser process commandbufferproxyimpl* Command_buffer_
Commandbufferproxyimpl is the GPU process client Agent that synchronizes messages to the corresponding gpucommandbufferstub in the GPU process.
The gpucommandbufferstub corresponds to Commandbufferproxyimpl one by one in the GPU process.
The browser process first triggers the GPU process to create the Gpucommandbufferstub instance, and then creates the Commandbufferproxyimpl.
The process for creating an instance of Gpucommandbufferstub is as follows.
Gpuchannelhost::createviewcommandbuffer () After triggering the GPU process to create an instance of Gpucommandbufferstub,
Created a commandbufferproxyimpl corresponding to the gpucommandbufferstub.
The creation process for the render process commandbufferproxyimpl* Command_buffer_ is as follows.
Rendercommandbuffercreated.jpg
gpu::gles2::gles2cmdhelper* Gles2_helper_;
Gpu::gles2::gles2cmdhelper helper class to help write to GL command buffer.
gpu::transferbuffer* Transfer_buffer_;
Gpu::transferbuffer the class that manages transfer buffer.
Gpu::gles2::gles2interface* Gl_;
Gl_ the actual instance that points to gles2implementation.
Gles2implementation simulates GLES2 on command buffers.
The client of the GPU process uses gles2implementation.
The gles2implementation encapsulates the handling of shared memory and the management of command buffer.
Both Gles2_helper_ and Transfer_buffer_ are set to Gl_, and are used in class gles2implementation.
The process by which the GPU process client communicates with the GPU process is:
Webgraphicscontext3dcommandbufferimpl calls the corresponding interface of the gles2implementation,
Gles2implementation calls Gles2cmdhelper the command that will be sent to the GPU process to write Commandbuffer
Included in the sharedmemory, this sharedmemory is also mapped to the GPU process.
The Gles2decoderimpl in the GPU process is responsible for handling commands sent by gles2implementation.
Commandbuffer contains sharedmemory that are mapped to the GPU process and managed by Commandbufferservice.
So gles2decoderimpl to get command-related data by manipulating Commandbufferservice.
Commandbufferproxyimpl sends messages through the IPC to the GPU process, synchronizing the operations in the GPU process.
The IPC messages sent by the GPU process client via Commandbufferproxyimpl are prefixed with gpucommandbuffermsg_.
The GPU process that accepts this type of message is gpucommandbufferstub.
Gpucommandbufferstub calls Commandbufferservice to complete the actual message processing.
GPU process client and GPU process structures such as:
Three. The Gpumainthread class is defined in the creation of the GPU process
gpu_process_host.cc. The
Gpumainthread::init () function creates a GPU process, or
creates a GPU thread when a musk person is IN-PROCESS-GPU or single-process. The
GPU process is a child process of the browser process. Will only be created once in the browser process.