Chromium for Android v34 2dCanvas hardware drawing and hardware rendering implementation analysis

Source: Internet
Author: User
Tags skia

The htmlcanvaselement corresponds to the H5 canvas element.
Parsing a Web page encounters a canvas element creates a htmlcanvaselement instance.
Canvas can support drawing of 2d and 3d graphics.
Htmlcanvaselement provides the GetContext () interface, which returns the context object of the drawing,
The CANVASRENDERINGCONTEXT2D is returned for 2d graphics.
CANVASRENDERINGCONTEXT2D provides all the drawing actions that a Web page can invoke.
All drawing commands for the CANVASRENDERINGCONTEXT2D are forwarded to the
Htmlcanvaselement: The drawing context provided by the:d Rawingcontext ().
Htmlcanvaselement is the entire canvas implementation of the portal.
Let's start with the 2dCanvas hardware rendering and hardware render architecture.
A Implementation structure of hardware drawing
Hardware drawing refers to the drawing action of a Web page call, through Htmlcanvaselement
To the Skia library, the Skia library completes the actual drawing operation by invoking the GPU command.
Software drawing means that the Skia library completes the drawing operation on the CPU.
To complete the hardware drawing:
1. Establish the connection between the Htmlcanvaselement and the Skia Library's Grcontext (Skia hardware drawing context).
2. Establish the connection between the Skia library Grcontext and the GPU.
3. Create a texture that saves hardware drawing results.
To complete these 3 things, the Web page calls Htmlcanvaselement's draw command via the Skia library
The actual GPU operation is drawn to the texture that holds the drawing results.
1. Establishes the connection between the Htmlcanvaselement and the Grcontext (Hardware drawing context) of the Skia library.
The Skia Grcontext is encapsulated in the WEBKIT::GPU:: Grcontextforwebgraphicscontext3d class.

The creation process is as follows:


Grcontext is created in Canvas2dlayerbridge::create and saved in Skgpudevice.
Grcontext the class diagram involved in the creation process:


Grcontext is created in Canvas2dlayerbridge::create and saved in Skgpudevice.
Grcontext the class diagram grcontextwrap.jpg involved in the creation process.
The process of canvasrenderingcontext2d the drawing action to the grcontext you just created
(Take Canvasrenderingcontext2d's FillRect () as an example), can be divided into three steps (A,B,C):
A.canvasrenderingcontext2d::fillrect ()--->canvas2dlayerbridge::create ()
The Skdeferredcanvas created in::d Rawrect ().


CANVASRENDERINGCONTEXT2D's FillRect () by htmlcanvaselement::d Rawingcontext ()
Passed to the Graphicscontext,graphiccontext created in Imagebuffer and further called
It contains the Skcanvas::d rawrect (). Graphiccontext contains the Skcanvas is
The Skdeferredcanvas created in Canvas2dlayerbridge.
The class diagram involved in this process:


B.skdeferredcanvas::d rawrect ()--->deferreddevice:: Fimmediatecanvas::d rawrect ()
Skdeferredcanvas::d rawrect () is called in Deferreddevice created by Skdefferdcanvas
Contains the member variable skcanvas* Fimmediatecanvas of the DrawRect (). We look at the source of this fimmediatecanvas.


Skdefferdcanvas the SKSURFACE_GPU instance as a parameter when it was created.
The Deferreddevice is created with the Sksurface_gpu parameter in Skdeferredcanvas::create ().
and pass this deferreddevice to Skcanvas. Can be Skcanvas by GetDevice ()
interface to get Deferreddevice instances. So the Deferreddevice member variable skcanvas* Fimmediatecanvas is
The Skcanvas that was created in Sksurface_gpu::onnewcanvas () and passed in Skgpudevice as a parameter.

This process involves a class diagram:


C.deferreddevice:: Fimmediatecanvas::d rawrect ()--->skcanvas::d rawrect ().
Next look at the execution flow of the Skcanvas DrawRect () created with the Skgpudevice parameter.


To this, finally see, Canvasrenderingcontext2d's drawing action to the Grcontext.

2. Establish the connection between the Skia library Grcontext and the GPU.

The creation process by grcontext we know that Grcontetxt is encapsulated in Grcontextforwebgraphicscontext3d instances.
The Grcontextforwebgraphicscontext3d constructor passed in the
Webgraphicscontext3dcommandbufferimpl instance.

Chromium for Android GPU process structure analysis we know that

Webgraphicscontext3dcommandbufferimpl is the portal for communicating with the GPU process (thread).
In the Grcontextforwebgraphicscontext3d constructor
The Association of Grcontext with Webgraphicscontext3dcommandbufferimpl was established through Grglinterface.
The grglinterface contains the interface that corresponds to OpenGL es.
Webgraphicscontext3dcommandbufferimpl::creategrglinterface () call
Skia_bindings::createcommandbufferskiaglbinding () generates Grglinterface,
and binds the grglinterface contained interfaces to the Webgraphicscontext3dcommandbufferimpl corresponding interfaces.
Grglinterface was passed to Grcontext. This action is called by Grglinterface in Grcontext
The actual call is Webgraphicscontext3dcommandbufferimpl's GL operation,
and called by Webgraphicscontext3dcommandbufferimpl through the commandbuffer structure to the
Real GL operations that are referred to in the actual GPU process (threads). See chromium for Android GPU process structure analysis.
is Grcontext::d rawrect () calls the process of the GL operation to Webgraphicscontext3dcommandbufferimpl:


3. Create a texture that saves hardware drawing results.
The following are the specific creation procedures:


This texture is called by grgpugl::oncreatetexture () Webgraphicscontext3dcommandbufferimpl
The interface Gentextures () is generated and saved in the Grgltexture instance.


Two. 2dcanvas Hardware rendering architecture

Chromium for Android v34 2dCanvas hardware drawing and hardware rendering implementation analysis

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.