Android4.4 webview chromium implements the chromium kernel structure of hardware Rendering

Source: Internet
Author: User

Here we only focus on several classes different from the native chromium.
1. DrawGLFunctor
The hardware rendering of android4.4 webview chromium is a collaboration between the android ui System and the chromium kernel.
Completed. The android ui system is responsible for triggering web page rendering (calling WebView. onDraw () and providing
The final destination of the webpage content (HardwareCanvas); The chromium Kernel provides specific rendering behavior.
The DrawGLFunctor structure is introduced here.
DrawGLFunctor. java/draw_gl_functor.cpp
Draw_gl_functor.cpp provides an interface for the chromium kernel to register its own DrawGL function.
DrawGLFunctor is a function pointer, which calls WebView. onDraw () in the system ()
Is passed to the android ui system and called in the android ui system,
The operator () of DrawGLFunctor calls the DrawGL function registered by the chromium kernel.
Because the operator () of DrawGLFunctor is called by the android ui system
After the DrawGlInfo structure of the android ui is converted to the AwDrawGLInfo structure of chromium,
Call the DrawGL function registered by the chromium kernel, and update the android ui after the call.
The DrawGlInfo structure of the system.
First, let's look at the process of registering the DrawGL function of chromium TO draw_gl_functor.cpp.

The global function is defined in draw_gl_functor.cpp:
Void SetChromiumAwDrawGLFunction (){
G_aw_drawgl_function = reinterpret_cast (draw_function );
}
Set to draw_gl_functZ limit? Http://www.bkjia.com/kf/ware/vc/ "target =" _ blank "class =" keylink "> vci5jcHC1xMirvtax5MG/cores + Cs7Sw8e/cores + Cn08YnI + cores" C "{
Static AwDrawGLFunction DrawGLFunction;
Static void DrawGLFunction (int view_context,
AwDrawGLInfo * draw_info,
Void * spare ){
// | View_context | is the value that was returned from the java
// AwContents. onPrepareDrawGL; this cast must match the code there.
Reinterpret_cast (view_context)-> DrawGL (
Draw_info );
}
}
So what we get from GetAwDrawGLFunction () in aw_contents.cc is
Android_webview: InProcessViewRenderer: DrawGL () function address.
The global variable g_aw_drawgl_function set to draw_gl_functor.cpp is
Android_webview: InProcessViewRenderer: DrawGL ().
Next, let's take a look at the calling process of DrawGLFunctor () defined by draw_gl_functor.cpp by the android ui system.

Draw_gl_functor.cpp
Virtual status_t operator () (int what, void * data ){
G_aw_drawgl_function (view_context _, & aw_info, NULL );
}
The previous analysis shows that the global variable g_aw_drawgl_function defined by draw_gl_functor.cpp points
Android_webview: InProcessViewRenderer: DrawGL ().
Therefore, DrawGLFunctor () calls android_webview: InProcessViewRenderer: DrawGL ().
Ii. SynchronousCompositorImpl
Structure of SynchronousCompositorImpl:

The creation process of SynchronousCompositorImpl:

Call SynchronousCompositorImpl: CreateForWebContents ()
Actually called:
WebContentsUserData: CreateForWebContents (){
DCHECK (contents );
If (! FromWebContents (contents ))
Contents-> SetUserData (UserDataKey (), new T (contents ));
}
After SynchronousCompositorImpl is created, it is set to WebContents UserData.
SynchronousCompositorImpl SynchronousCompositor APIs are called in InProcessViewRenderer.
SynchronousCompositorImpl's SynchronousCompositor interface is transferred to SynchronousCompositorOutputSurface.
SynchronousCompositorImpl SynchronousCompositorOutputSurfaceDelegate interfaces are all called in SynchronousCompositorOutputSurface;
SynchronousCompositorImpl SynchronousCompositorOutputSurfaceDelegate interface is transferred
SynchronousCompositorClient is InProcessViewRenderer.
So SynchronousCompositorImpl is just SynchronousCompositorOutputSurface
Intermediate Class for collaboration with InProcessViewRenderer.
3. WebGraphicsContext3DInProcessCommandBufferImpl and GLInProcessContextImpl
The structure of WebGraphicsContext3DInProcessCommandBufferImpl is as follows:

The WebGraphicsContext3DInProcessCommandBufferImpl instance has been created twice.
A scoped_ptr stored in the ContextProviderInProcess instance In the context3d _ variable,
The ContextProviderInProcess instance is saved in scoped_refptr of ResourceProvider. Offscreen_context_provider _ variable.
Another WebGraphicsContext3DInProcessCommandBufferImpl instance is saved in scoped_ptr of OututSurface. Context3d _ variable.
The following describes how to create a WebGraphicsContext3DInProcessCommandBufferImpl instance:

Void InProcessViewRenderer: DrawGL () is called before the first execution.
Bool InProcessViewRenderer: InitializeHwDraw (). class initialization required for hardware rendering is triggered.
Webkit: gpu: ContextProviderInProcess: CreateOffscreen () Create inclusion
The ContextProviderInProcess instance of WebGraphicsContext3DInProcessCommandBufferImpl.
SynchronousCompositorOutputSurface: InitializeHwDraw () call CreateWebGraphicsContext3D () to create
The instance of WebGraphicsContext3DInProcessCommandBufferImpl.
The ContextProviderInProcess instance and the instance of WebGraphicsContext3DInProcessCommandBufferImpl are passed as parameters.
OutputSurface: InitializeAndSetContext3D ().
The GLInProcessContext parameter is required in the WebGraphicsContext3DInProcessCommandBufferImpl constructor.
The ContextProviderInProcess instance uses OutputSurface: InitializeAndSetContext3D ()
The call LayerTreeHostImpl: DeferredInitialize () is finally passed to the ResourceProvider: offscreen_context_provider _ variable.
The WebGraphicsContext3DInProcessCommandBufferImpl instance uses OutputSurface: InitializeAndSetContext3D ()
Call OutputSurface: SetContext3D () and save it to scoped_ptr of OututSurface. Context3d _ variable.
ResourceProvider: The WebGraphicsContext3DInProcessCommandBufferImpl contained in the offscreen_context_provider _ variable
GLInProcessContext is null. In WebGraphicsContext3DInProcessCommandBufferImpl: MaybeInitializeGL (),
GLInProcessContext: CreateContext.
4. InProcessCommandBuffer and CommandBufferService

GLInProcessContextImpl: Initialize () trigger process:

Synchronous_compositor_output_surface.cpp defines global functions:
Scoped_ptr CreateWebGraphicsContext3D ()
GLInProcessContextImpl: Initialize () created
InProcessCommandBuffer, GLES2CmdHelper, and GLES2Implementation instances.
InProcessCommandBuffer: InitializeOnGpuThread () created
CommandBufferService, GLES2DecoderImpl instance.
Unlike the GPU process structure of multi-process native chromium, CommandBufferProxy is not required here.
GLES2Implementation writes data to CommandBuffer through GLES2CmdHelper.
SharedMemory indirectly contained by CommandBufferService.
GLES2DecoderImpl still reads data from CommandBuffer under GpuScheduler scheduling and calls the gl operation in the command.
Finally, we will summarize the chromium kernel structure related to rendering.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.